From 53f57bbd7f67ab3ebf1fc7509e929bb260fb36b9 Mon Sep 17 00:00:00 2001 From: "1020785391@qq.com" <1020785391@qq.com> Date: Tue, 15 Mar 2022 16:08:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3slt=E5=9B=BE=C2=B7?= =?UTF-8?q?=E9=9A=9C=E7=A2=8D=E7=89=A9=E7=B1=BB=E5=9E=8B=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chart_plugin/src/slt_space/slt_space_draw.cpp | 19 ++- chart_plugin/src/slt_space_display.cpp | 160 +++++------------- 2 files changed, 57 insertions(+), 122 deletions(-) diff --git a/chart_plugin/src/slt_space/slt_space_draw.cpp b/chart_plugin/src/slt_space/slt_space_draw.cpp index 83efdc8..a4efbf1 100755 --- a/chart_plugin/src/slt_space/slt_space_draw.cpp +++ b/chart_plugin/src/slt_space/slt_space_draw.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2020-2021, Huawei Technologies Co., Ltd +Copyright (c) 2020-2022, Huawei Technologies Co., Ltd All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the @@ -108,12 +108,23 @@ void SltSpaceDraw::DrawObjects(mglGraph *mglGraphPtr) const const auto sltObjectsMap = spaceDataPtr->GetObjectsMap(); const auto objectsIdType = spaceDataPtr->GetObjectsIdTypeMap(); - for (auto iter = sltObjectsMap.begin(); iter != sltObjectsMap.end(); iter++) { - vector objectData = iter.value(); + QList listType = objectsIdType.values(); + for (int i = 0; i < listType.count() - 1; i++) { + for (int j = i + 1; j < listType.count(); j++) { + if (listType.at(i) > listType.at(j)) { + int32_t type = listType.at(i); + listType[i] = listType.at(j); + listType[j] = type; + } + } + } + + for (auto type : listType) { + vector objectData = sltObjectsMap.value(objectsIdType.key(type)); if (objectData.size() != OBJECT_DATA_NUM_SIZE) { continue; } - QString objectId = iter.key(); + QString objectId = objectsIdType.key(type); int32_t type = objectsIdType.value(objectId); spaceDisplayPtr->SetObjectProperty(type); auto objectIdLegendIter = (spaceDisplayPtr->GetObjectsIdLegendMap()).find(objectId); diff --git a/chart_plugin/src/slt_space_display.cpp b/chart_plugin/src/slt_space_display.cpp index 6b3b2c9..f7c1484 100755 --- a/chart_plugin/src/slt_space_display.cpp +++ b/chart_plugin/src/slt_space_display.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2020-2021, Huawei Technologies Co., Ltd +Copyright (c) 2020-2022, Huawei Technologies Co., Ltd All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the @@ -75,36 +75,20 @@ void SltSpaceDisplay::ClearData() void SltSpaceDisplay::InitTitleProperty() { - plotTitleProperty = new (std::nothrow) + plotTitleProperty = new StringProperty("Chart Title", "SLT", "Chart title name property.", this, SLOT(UpdateMathglDraw()), this); - if (plotTitleProperty == nullptr) { - ROS_ERROR("Failed to create the plotTitleProperty."); - return; - } plotTitleProperty->setReadOnly(true); - xAxisTitleProperty = new (std::nothrow) + xAxisTitleProperty = new StringProperty("X Axis Title", "S[m]", "X Axis title name property.", this, SLOT(UpdateMathglDraw()), this); - if (xAxisTitleProperty == nullptr) { - ROS_ERROR("Failed to create the xAxisTitleProperty."); - return; - } xAxisTitleProperty->setReadOnly(true); - yAxisTitleProperty = new (std::nothrow) + yAxisTitleProperty = new StringProperty("Y Axis Title", "L[m]", "Y Axis title name property.", this, SLOT(UpdateMathglDraw()), this); - if (yAxisTitleProperty == nullptr) { - ROS_ERROR("Failed to create the yAxisTitleProperty."); - return; - } yAxisTitleProperty->setReadOnly(true); - zAxisTitleProperty = new (std::nothrow) + zAxisTitleProperty = new StringProperty("Z Axis Title", "T[s]", "Z Axis title name property.", this, SLOT(UpdateMathglDraw()), this); - if (zAxisTitleProperty == nullptr) { - ROS_ERROR("Failed to create the zAxisTitleProperty."); - return; - } zAxisTitleProperty->setReadOnly(true); } @@ -117,44 +101,24 @@ void SltSpaceDisplay::InitCurveProperty() const int32_t speedLimitCurveColorG = 0xFF; const int32_t speedLimitCurveColorB = 0xC1; - curveProperty = new (std::nothrow) + curveProperty = new EnumProperty("Curve", "Optimized Track", "Curve type setting selection.", this, SLOT(UpdateCurveChoice())); - if (curveProperty == nullptr) { - ROS_ERROR("Failed to create the curveProperty."); - return; - } curveProperty->addOption("Optimized Track", OPTIMIZED_TRACK_CURVE); curveProperty->addOption("Speed Limit", SPEED_LIMIT_CURVE); - optimizedCurveTitleProperty = new (std::nothrow) StringProperty("Optimized Title", "Optimized Track", + optimizedCurveTitleProperty = new StringProperty("Optimized Title", "Optimized Track", "Optimized curve title property setting.", curveProperty, SLOT(UpdateOptimizedCurveTitle()), this); - if (optimizedCurveTitleProperty == nullptr) { - ROS_ERROR("Failed to create the optimizedCurveTitleProperty."); - return; - } - optimizedCurveColorProperty = new (std::nothrow) + optimizedCurveColorProperty = new ColorProperty("Optimized Color", QColor(optimizedCurveColorR, optimizedCurveColorG, optimizedCurveColorB), "Color of the Optimized Slt Track Curve.", curveProperty, SLOT(UpdateOptimizedCurveColor()), this); - if (optimizedCurveColorProperty == nullptr) { - ROS_ERROR("Failed to create the optimizedCurveColorProperty."); - return; - } - speedLimitCurveTitleProperty = new (std::nothrow) StringProperty("Speed Title", "Speed Limit", + speedLimitCurveTitleProperty = new StringProperty("Speed Title", "Speed Limit", "Slt Speed Limit curve title property setting.", curveProperty, SLOT(UpdateSpeedLimitCurveTitle()), this); - if (speedLimitCurveTitleProperty == nullptr) { - ROS_ERROR("Failed to create the speedLimitCurveTitleProperty."); - return; - } - speedLimitCurveColorProperty = new (std::nothrow) + speedLimitCurveColorProperty = new ColorProperty("Speed Color", QColor(speedLimitCurveColorR, speedLimitCurveColorG, speedLimitCurveColorB), "Color of the Slt Speed Limit Curve.", curveProperty, SLOT(UpdateSpeedLimitCurveColor()), this); - if (speedLimitCurveColorProperty == nullptr) { - ROS_ERROR("Failed to create the speedLimitCurveColorProperty."); - return; - } } void SltSpaceDisplay::InitProperty() @@ -201,13 +165,9 @@ void SltSpaceDisplay::CreateObjectsTypeProperty(int32_t type) objectsTypeTotalVector.append(type); if (objectsTypeProperty == nullptr) { - objectsTypeProperty = new (std::nothrow) EnumProperty("Objects Type", typeName, + objectsTypeProperty = new EnumProperty("Objects Type", typeName, "Slt Objects Type setting selection.", this, SLOT(UpdateObjectsTypeChoice())); } - if (objectsTypeProperty == nullptr) { - ROS_ERROR("Failed to create the objectsTypeProperty."); - return; - } objectsTypeProperty->addOption(typeName, type); } @@ -269,12 +229,8 @@ void SltSpaceDisplay::CreateObjectProperty(const QString &propertyKey, const QSt int32_t green = colorChannelValue[1].toInt(); int32_t blue = colorChannelValue[2].toInt(); // 取colorChannelValue中第2个元素 QColor color = QColor(red, green, blue); - ColorProperty *objectsTypeColorPropertyPtr = new (std::nothrow) ColorProperty(propertyKey, color, + ColorProperty *objectsTypeColorPropertyPtr = new ColorProperty(propertyKey, color, "Objects type color setting.", objectsTypeProperty, SLOT(UpdateObjectsTypeColor()), this); - if (objectsTypeColorPropertyPtr == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeColorPropertyPtr of ColorProperty."); - return; - } SetObjectsTypeColor(type, red, green, blue); objectsTypeColorPropertyMap.insert(type, objectsTypeColorPropertyPtr); @@ -282,12 +238,8 @@ void SltSpaceDisplay::CreateObjectProperty(const QString &propertyKey, const QSt } if (keyList.contains("Title")) { - StringProperty *objectsTypeTitlePropertyPtr = new (std::nothrow) StringProperty(propertyKey, propertyValue, + StringProperty *objectsTypeTitlePropertyPtr = new StringProperty(propertyKey, propertyValue, "Objects type title setting.", objectsTypeProperty, SLOT(UpdateObjectsTypeTitle()), this); - if (objectsTypeTitlePropertyPtr == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeTitlePropertyPtr of StringProperty."); - return; - } objectsTypeTitlePropertyMap.insert(type, objectsTypeTitlePropertyPtr); } @@ -313,11 +265,7 @@ void SltSpaceDisplay::load(const rviz::Config &config) void SltSpaceDisplay::CreateOptimizedLegend() { if (optimizedCurveLegend == nullptr) { - optimizedCurveLegend = new (std::nothrow) QPushButton(ui.GetScrollAreaWidgetContents()); - if (optimizedCurveLegend == nullptr) { - ROS_ERROR("Failed to Create the optimizedCurveLegend of QPushButton."); - return; - } + optimizedCurveLegend = new QPushButton(ui.GetScrollAreaWidgetContents()); QObject::connect(optimizedCurveLegend, SIGNAL(toggled(bool)), this, SLOT(UpdateMathglDraw())); } @@ -333,11 +281,7 @@ void SltSpaceDisplay::CreateOptimizedLegend() void SltSpaceDisplay::CreateSpeedLegend() { if (speedLimitCurveLegend == nullptr) { - speedLimitCurveLegend = new (std::nothrow) QPushButton(ui.GetScrollAreaWidgetContents()); - if (speedLimitCurveLegend == nullptr) { - ROS_ERROR("Failed to Create the speedLimitCurveLegend of QPushButton."); - return; - } + speedLimitCurveLegend = new QPushButton(ui.GetScrollAreaWidgetContents()); QObject::connect(speedLimitCurveLegend, SIGNAL(toggled(bool)), this, SLOT(UpdateMathglDraw())); } @@ -489,7 +433,19 @@ void SltSpaceDisplay::UpdateGridLayoutItem() ui.GetGridLayout()->addItem(horizontalSpacerRight, 1, column - 1, 1, 1); const auto &objectsIdTypeMap = sltSpaceData.GetObjectsIdTypeMap(); - auto iter = objectsIdTypeMap.cbegin(); + + QList listType = objectsIdTypeMap.values(); + for (int32_t i = 0; i < listType.count() - 1; i++) { + for (int32_t j = i + 1; j < listType.count(); j++) { + if (listType.at(i) > listType.at(j)) { + int32_t type = listType.at(i); + listType[i] = listType.at(j); + listType[j] = type; + } + } + } + + int32_t k = 0; // 从第1行第1列位置开始放置图例按钮,遍历网格图例按钮放置区域(row - 2)行乘(column - 2)列个放置空间 for (int32_t i = 1; i <= row - 2; i++) { // 共有(column - 2)列是安置图例按钮的 @@ -502,15 +458,15 @@ void SltSpaceDisplay::UpdateGridLayoutItem() ui.GetGridLayout()->addWidget(speedLimitCurveLegend, i, j, 1, 1); speedLimitCurveLegend->show(); // 只有当整个障碍物图例按钮都还没有遍历安置完毕,网格布局器才安置图例按钮 - } else if (iter != objectsIdTypeMap.cend()) { - auto objectIdLegendIter = objectsIdLegendMap.find(iter.key()); + } else if (k < listType.count()) { + auto objectIdLegendIter = objectsIdLegendMap.find(objectsIdTypeMap.key(listType.at(k))); if ((objectIdLegendIter == objectsIdLegendMap.end()) || (objectIdLegendIter->second == nullptr)) { - iter++; + k++; continue; } - ui.GetGridLayout()->addWidget(objectsIdLegendMap[iter.key()].get(), i, j, 1, 1); - objectsIdLegendMap[iter.key()]->show(); - iter++; + ui.GetGridLayout()->addWidget(objectsIdLegendMap[objectsIdTypeMap.key(listType.at(k))].get(), i, j, 1, 1); + objectsIdLegendMap[objectsIdTypeMap.key(listType.at(k))]->show(); + k++; } } } @@ -531,36 +487,20 @@ void SltSpaceDisplay::InitLegendSpacerItem() const int32_t horizontalHeight = 20; verticalSpacerTop = - new (std::nothrow) QSpacerItem(verticalWidth, verticalHeightTop, QSizePolicy::Minimum, QSizePolicy::Expanding); - if (verticalSpacerTop == nullptr) { - ROS_ERROR("Failed to Create the verticalSpacerTop of QSpacerItem."); - return; - } + new QSpacerItem(verticalWidth, verticalHeightTop, QSizePolicy::Minimum, QSizePolicy::Expanding); ui.GetGridLayout()->addItem(verticalSpacerTop, 0, 1, 1, 1); - verticalSpacerBottom = new (std::nothrow) + verticalSpacerBottom = new QSpacerItem(verticalWidth, verticalHeightBottom, QSizePolicy::Minimum, QSizePolicy::Expanding); - if (verticalSpacerBottom == nullptr) { - ROS_ERROR("Failed to Create the verticalSpacerBottom of QSpacerItem."); - return; - } // 底部垂直弹簧放置第2行第1列,占据1行1列 ui.GetGridLayout()->addItem(verticalSpacerBottom, 2, 1, 1, 1); horizontalSpacerLeft = - new (std::nothrow) QSpacerItem(horizontalWidth, horizontalHeight, QSizePolicy::Expanding, QSizePolicy::Minimum); - if (horizontalSpacerLeft == nullptr) { - ROS_ERROR("Failed to Create the horizontalSpacerLeft of QSpacerItem."); - return; - } + new QSpacerItem(horizontalWidth, horizontalHeight, QSizePolicy::Expanding, QSizePolicy::Minimum); ui.GetGridLayout()->addItem(horizontalSpacerLeft, 1, 0, 1, 1); horizontalSpacerRight = - new (std::nothrow) QSpacerItem(horizontalWidth, horizontalHeight, QSizePolicy::Expanding, QSizePolicy::Minimum); - if (horizontalSpacerRight == nullptr) { - ROS_ERROR("Failed to Create the horizontalSpacerRight of QSpacerItem."); - return; - } + new QSpacerItem(horizontalWidth, horizontalHeight, QSizePolicy::Expanding, QSizePolicy::Minimum); // 默认安装位置为第1行第3列,占据1行1列 ui.GetGridLayout()->addItem(horizontalSpacerRight, 1, 3, 1, 1); @@ -603,11 +543,7 @@ void SltSpaceDisplay::onInitialize() graph.Clf(mglGraphColorR, mglGraphColorG, mglGraphColorB); ui.GetQMathGl()->setGraph(&graph); - SltSpaceDraw *spaceDraw = new (std::nothrow) SltSpaceDraw(this, &sltSpaceData); - if (spaceDraw == nullptr) { - ROS_ERROR("Failed to Create the spaceDraw of SltSpaceDraw."); - return; - } + SltSpaceDraw *spaceDraw = new SltSpaceDraw(this, &sltSpaceData); ui.GetQMathGl()->setDraw(spaceDraw); ui.GetQMathGl()->setDotsPreview(false); @@ -734,32 +670,20 @@ void SltSpaceDisplay::SetObjectProperty(int32_t objectType) objectsTypeTotalVector.append(objectType); if (objectsTypeProperty == nullptr) { - objectsTypeProperty = new (std::nothrow) EnumProperty("Object Type", QString("Type %1").arg(objectType), + objectsTypeProperty = new EnumProperty("Object Type", QString("Type %1").arg(objectType), "Slt Objects Type setting selection.", this, SLOT(UpdateObjectsTypeChoice())); - if (objectsTypeProperty == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeProperty of EnumProperty."); - return; - } } QString typeName = QString("Type %1").arg(objectType); objectsTypeProperty->addOption(typeName, objectType); StringProperty *objectsTypeTitlePropertyPtr = - new (std::nothrow) StringProperty(QString("Type %1 Title").arg(objectType), QString("Type %1").arg(objectType), + new StringProperty(QString("Type %1 Title").arg(objectType), QString("Type %1").arg(objectType), "Objects type title setting.", objectsTypeProperty, SLOT(UpdateObjectsTypeTitle()), this); - if (objectsTypeTitlePropertyPtr == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeTitlePropertyPtr of StringProperty."); - return; - } QColor color = GetObjectsTypeColor(objectType); ColorProperty *objectsTypeColorPropertyPtr = - new (std::nothrow) ColorProperty(QString("Type %1 Color").arg(objectType), color, "Objects type color setting.", + new ColorProperty(QString("Type %1 Color").arg(objectType), color, "Objects type color setting.", objectsTypeProperty, SLOT(UpdateObjectsTypeColor()), this); - if (objectsTypeColorPropertyPtr == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeColorPropertyPtr of ColorProperty."); - return; - } objectsTypeTitlePropertyMap.insert(objectType, objectsTypeTitlePropertyPtr); objectsTypeColorPropertyMap.insert(objectType, objectsTypeColorPropertyPtr); -- Gitee From 51500e17fac3c2e16a775866aa57c0f4b8086589 Mon Sep 17 00:00:00 2001 From: "1020785391@qq.com" <1020785391@qq.com> Date: Tue, 15 Mar 2022 17:29:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=B0=86=E6=8E=92=E5=BA=8F=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E6=94=B9=E4=B8=BAqSort()=E5=87=BD=E6=95=B0=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chart_plugin/src/slt_space/slt_space_draw.cpp | 10 +--------- chart_plugin/src/slt_space_display.cpp | 10 +--------- chart_plugin/src/st_space_display.cpp | 17 ++++------------- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/chart_plugin/src/slt_space/slt_space_draw.cpp b/chart_plugin/src/slt_space/slt_space_draw.cpp index a4efbf1..9ad398d 100755 --- a/chart_plugin/src/slt_space/slt_space_draw.cpp +++ b/chart_plugin/src/slt_space/slt_space_draw.cpp @@ -109,15 +109,7 @@ void SltSpaceDraw::DrawObjects(mglGraph *mglGraphPtr) const const auto sltObjectsMap = spaceDataPtr->GetObjectsMap(); const auto objectsIdType = spaceDataPtr->GetObjectsIdTypeMap(); QList listType = objectsIdType.values(); - for (int i = 0; i < listType.count() - 1; i++) { - for (int j = i + 1; j < listType.count(); j++) { - if (listType.at(i) > listType.at(j)) { - int32_t type = listType.at(i); - listType[i] = listType.at(j); - listType[j] = type; - } - } - } + qSort(listType.begin(), listType.end()); for (auto type : listType) { vector objectData = sltObjectsMap.value(objectsIdType.key(type)); diff --git a/chart_plugin/src/slt_space_display.cpp b/chart_plugin/src/slt_space_display.cpp index f7c1484..ee930e5 100755 --- a/chart_plugin/src/slt_space_display.cpp +++ b/chart_plugin/src/slt_space_display.cpp @@ -435,15 +435,7 @@ void SltSpaceDisplay::UpdateGridLayoutItem() const auto &objectsIdTypeMap = sltSpaceData.GetObjectsIdTypeMap(); QList listType = objectsIdTypeMap.values(); - for (int32_t i = 0; i < listType.count() - 1; i++) { - for (int32_t j = i + 1; j < listType.count(); j++) { - if (listType.at(i) > listType.at(j)) { - int32_t type = listType.at(i); - listType[i] = listType.at(j); - listType[j] = type; - } - } - } + qSort(listType.begin(), listType.end()); int32_t k = 0; // 从第1行第1列位置开始放置图例按钮,遍历网格图例按钮放置区域(row - 2)行乘(column - 2)列个放置空间 diff --git a/chart_plugin/src/st_space_display.cpp b/chart_plugin/src/st_space_display.cpp index a707382..0aec938 100755 --- a/chart_plugin/src/st_space_display.cpp +++ b/chart_plugin/src/st_space_display.cpp @@ -700,20 +700,11 @@ void StSpaceDisplay::ShowObjectsCurve(const QMap &objectsIdTyp stObjectsCurveMap.clear(); } - QStringList typeNames = stObjectsMap.keys(); - for (int32_t i = 0; i < typeNames.count() - 1; i++) { - for (int32_t j = i + 1; j < typeNames.count(); j++) { - if (objectsIdType.value(typeNames.at(i)) > objectsIdType.value(typeNames.at(j))) { - QString typeName = typeNames.at(i); - typeNames[i] = typeNames.at(j); - typeNames[j] = typeName; - } - } - } + QList listType = objectsIdType.values(); + qSort(listType.begin(), listType.end()); - for (auto typeName : typeNames) { - QString objectId = typeName; - int32_t type = objectsIdType.value(objectId); + for (auto type : listType) { + QString objectId = objectsIdType.key(type); SetObjectProperty(type); if (!objectsTypeTitleProperty.contains(type) || objectsTypeTitleProperty[type] == nullptr) { continue; -- Gitee From deae83b156847688ede9923d2df2e557c51133dd Mon Sep 17 00:00:00 2001 From: "1020785391@qq.com" <1020785391@qq.com> Date: Tue, 15 Mar 2022 17:51:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chart_plugin/src/slt_space/slt_space_draw.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/chart_plugin/src/slt_space/slt_space_draw.cpp b/chart_plugin/src/slt_space/slt_space_draw.cpp index 9ad398d..4d372ef 100755 --- a/chart_plugin/src/slt_space/slt_space_draw.cpp +++ b/chart_plugin/src/slt_space/slt_space_draw.cpp @@ -117,7 +117,6 @@ void SltSpaceDraw::DrawObjects(mglGraph *mglGraphPtr) const continue; } QString objectId = objectsIdType.key(type); - int32_t type = objectsIdType.value(objectId); spaceDisplayPtr->SetObjectProperty(type); auto objectIdLegendIter = (spaceDisplayPtr->GetObjectsIdLegendMap()).find(objectId); if (objectIdLegendIter != (spaceDisplayPtr->GetObjectsIdLegendMap()).end() && -- Gitee