diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index 3626198ba9..bccdde237e 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -851,12 +851,11 @@ void exec2LineCenterLine(Gui::Command* cmd) QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), QObject::tr("Selection is not a CenterLine.")); return; - } else { - Gui::Control().showDialog(new TaskDlgCenterLine(dvp, - page, - selectedEdges.front(), - true)); } + Gui::Control().showDialog(new TaskDlgCenterLine(dvp, + page, + selectedEdges.front(), + true)); } else { //not create, not edit, what is this??? QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), QObject::tr("Selection not understood.")); @@ -914,17 +913,17 @@ void exec2PointCenterLine(Gui::Command* cmd) std::vector selection = cmd->getSelection().getSelectionEx(); TechDraw::DrawViewPart* baseFeat = nullptr; - if (!selection.empty()) { - baseFeat = dynamic_cast(selection[0].getObject()); - if( baseFeat == nullptr ) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), - QObject::tr("No base View in Selection.")); - return; - } - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), - QObject::tr("You must select a base View for the line.")); - return; + if (selection.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("You must select a base View for the line.")); + return; + } + + baseFeat = dynamic_cast(selection[0].getObject()); + if( baseFeat == nullptr ) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("No base View in Selection.")); + return; } std::vector subNames; @@ -1030,28 +1029,28 @@ void execLine2Points(Gui::Command* cmd) TechDraw::DrawViewPart* baseFeat = nullptr; std::vector subNames2D; std::vector< std::pair > objs3D; - if (!selection.empty()) { - for (auto& so: selection) { - if (so.getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { - baseFeat = static_cast (so.getObject()); - subNames2D = so.getSubNames(); - } else if (so.getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) { - std::vector subNames3D = so.getSubNames(); - for (auto& sub3D: subNames3D) { - std::pair temp; - temp.first = static_cast(so.getObject()); - temp.second = sub3D; - objs3D.push_back(temp); - } - } else { - //garbage - } - } - } else { + if (selection.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), QObject::tr("Selection is empty.")); return; } + + for (auto& so: selection) { + if (so.getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + baseFeat = static_cast (so.getObject()); + subNames2D = so.getSubNames(); + } else if (so.getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) { + std::vector subNames3D = so.getSubNames(); + for (auto& sub3D: subNames3D) { + std::pair temp; + temp.first = static_cast(so.getObject()); + temp.second = sub3D; + objs3D.push_back(temp); + } + } else { + //garbage + } + } if (baseFeat == nullptr) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), @@ -1133,6 +1132,10 @@ void execLine2Points(Gui::Command* cmd) // TechDraw_CosmeticEraser //=========================================================================== +#define GEOMETRYEDGE 0 +#define COSMETICEDGE 1 +#define CENTERLINE 2 + DEF_STD_CMD_A(CmdTechDrawCosmeticEraser) CmdTechDrawCosmeticEraser::CmdTechDrawCosmeticEraser() @@ -1170,19 +1173,14 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg) return; } - bool selectionError = false; for (auto& s: selection) { TechDraw::DrawViewPart * objFeat = static_cast (s.getObject()); if (!objFeat->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { - selectionError = true; - break; + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("At least 1 object in selection is not a part view")); + return; } } - if (selectionError) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("At least 1 object in selection is not a part view")); - return; - } TechDraw::DrawViewPart * objFeat = nullptr; std::vector subNames; @@ -1207,9 +1205,9 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg) (bg->cosmetic) ) { int source = bg->source(); std::string tag = bg->getCosmeticTag(); - if (source == 1) { //this is a "CosmeticEdge" + if (source == COSMETICEDGE) { ce2Delete.push_back(tag); - } else if (source == 2) { //this is a "CenterLine" + } else if (source == CENTERLINE) { cl2Delete.push_back(tag); } else { Base::Console().Message( @@ -1218,16 +1216,15 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg) } } else if (geomType == "Vertex") { TechDraw::VertexPtr tdv = objFeat->getProjVertexByIndex(idx); - if (tdv != nullptr) { - std::string delTag = tdv->cosmeticTag; - if (!delTag.empty()) { - cv2Delete.push_back(delTag); - } else { - Base::Console().Warning("Vertex%d is not cosmetic! Can not erase.\n", idx); - } - } else { + if (tdv == nullptr) { Base::Console().Message("CMD::eraser - geom: %d not found!\n", idx); } + + std::string delTag = tdv->cosmeticTag; + if (delTag.empty()) { + Base::Console().Warning("Vertex%d is not cosmetic! Can not erase.\n", idx); + } + cv2Delete.push_back(delTag); } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Unknown object type in selection")); @@ -1292,17 +1289,17 @@ void CmdTechDrawDecorateLine::activated(int iMsg) std::vector selection = getSelection().getSelectionEx(); TechDraw::DrawViewPart* baseFeat = nullptr; - if (!selection.empty()) { - baseFeat = dynamic_cast(selection[0].getObject()); - if( baseFeat == nullptr ) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), - QObject::tr("No View in Selection.")); - return; - } - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), - QObject::tr("You must select a View and/or lines.")); - return; + if (selection.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("You must select a View and/or lines.")); + return; + } + + baseFeat = dynamic_cast(selection[0].getObject()); + if( baseFeat == nullptr ) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("No View in Selection.")); + return; } std::vector subNames; @@ -1370,19 +1367,19 @@ void CmdTechDrawShowAll::activated(int iMsg) std::vector selection = getSelection().getSelectionEx(); TechDraw::DrawViewPart* baseFeat = nullptr; - if (!selection.empty()) { - baseFeat = dynamic_cast(selection[0].getObject()); - if (baseFeat == nullptr) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No Part Views in this selection")); - return; - } - } else { //empty selection + if (selection.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Nothing selected")); return; } + baseFeat = dynamic_cast(selection[0].getObject()); + if (baseFeat == nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("No Part Views in this selection")); + return; + } + Gui::ViewProvider* vp = QGIView::getViewProvider(baseFeat); auto partVP = dynamic_cast(vp); if ( partVP != nullptr ) { diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp index 8039a2a694..e2474cffb1 100644 --- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -405,18 +405,12 @@ void CmdTechDrawDiameterDimension::activated(int iMsg) std::vector subs; int edgeType = _isValidSingleEdge(this); - if (edgeType == isCircle) { - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - } else if (edgeType == isEllipse) { + if (edgeType == isEllipse) { QMessageBox::StandardButton result = QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Ellipse Curve Warning"), QObject::tr("Selected edge is an Ellipse. Diameter will be approximate. Continue?"), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel); - if (result == QMessageBox::Ok) { - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - } else { + if (result != QMessageBox::Ok) { return; } } else if (edgeType == isBSplineCircle) { @@ -424,10 +418,7 @@ void CmdTechDrawDiameterDimension::activated(int iMsg) QMessageBox::warning(Gui::getMainWindow(), QObject::tr("BSpline Curve Warning"), QObject::tr("Selected edge is a BSpline. Diameter will be approximate. Continue?"), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel); - if (result == QMessageBox::Ok) { - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - } else { + if (result != QMessageBox::Ok) { return; } } else if (edgeType == isBSpline) { @@ -443,6 +434,9 @@ void CmdTechDrawDiameterDimension::activated(int iMsg) return; } + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + openCommand(QT_TRANSLATE_NOOP("Command", "Create Dimension")); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() @@ -827,16 +821,16 @@ void CmdTechDrawAngleDimension::activated(int iMsg) std::vector subs; int edgeType = _isValidEdgeToEdge(this); - if (edgeType == isAngle) { - objs.push_back(objFeat); - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - } else { + if (edgeType != isAngle) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), QObject::tr("Need two straight edges to make an Angle Dimension")); return; } + + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); openCommand(QT_TRANSLATE_NOOP("Command", "Create Dimension")); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); @@ -914,19 +908,19 @@ void CmdTechDraw3PtAngleDimension::activated(int iMsg) std::vector objs; std::vector subs; - if (_isValidVertexes(this, 3)) { - objs.push_back(objFeat); - objs.push_back(objFeat); - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - subs.push_back(SubNames[2]); - } else { + if (!_isValidVertexes(this, 3)) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), QObject::tr("Need three points to make a 3 point Angle Dimension")); return; } + objs.push_back(objFeat); + objs.push_back(objFeat); + objs.push_back(objFeat); + subs.push_back(SubNames[0]); + subs.push_back(SubNames[1]); + subs.push_back(SubNames[2]); + openCommand(QT_TRANSLATE_NOOP("Command", "Create Dimension")); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() @@ -1176,17 +1170,17 @@ void execHExtent(Gui::Command* cmd) std::vector selection = cmd->getSelection().getSelectionEx(); TechDraw::DrawViewPart* baseFeat = nullptr; - if (!selection.empty()) { - baseFeat = dynamic_cast(selection[0].getObject()); - if( baseFeat == nullptr ) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("No base View in Selection.")); - return; - } - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("Please select a View [and Edges].")); - return; + if (selection.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), + QObject::tr("Please select a View [and Edges].")); + return; + } + + baseFeat = dynamic_cast(selection[0].getObject()); + if( baseFeat == nullptr ) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), + QObject::tr("No base View in Selection.")); + return; } std::vector SubNames; @@ -1263,17 +1257,18 @@ void execVExtent(Gui::Command* cmd) std::vector selection = cmd->getSelection().getSelectionEx(); TechDraw::DrawViewPart* baseFeat = nullptr; - if (!selection.empty()) { - baseFeat = dynamic_cast(selection[0].getObject()); - if( baseFeat == nullptr ) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("No base View in Selection.")); - return; - } - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("Please select a View [and Edges].")); - return; + if (selection.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), + QObject::tr("Please select a View [and Edges].")); + return; + } + + + baseFeat = dynamic_cast(selection[0].getObject()); + if( baseFeat == nullptr ) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), + QObject::tr("No base View in Selection.")); + return; } std::vector SubNames; @@ -1475,7 +1470,6 @@ bool _checkPartFeature(Gui::Command* cmd) { //! verify that Selection contains a valid Geometry for a single Edge Dimension int _isValidSingleEdge(Gui::Command* cmd) { - auto edgeType( isInvalid ); auto selection( cmd->getSelection().getSelectionEx() ); auto objFeat( dynamic_cast(selection[0].getObject()) ); @@ -1484,65 +1478,68 @@ int _isValidSingleEdge(Gui::Command* cmd) { } const std::vector SubNames = selection[0].getSubNames(); - if (SubNames.size() == 1) { //only 1 subshape selected - if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { //the Name starts with "Edge" - int GeoId( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) ); - TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId); - if (!geom) { - Base::Console().Error("Logic Error: no geometry for GeoId: %d\n",GeoId); - return isInvalid; - } + if (SubNames.size() != 1 || + TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { + return isInvalid; + } - if(geom->geomType == TechDraw::GENERIC) { - TechDraw::GenericPtr gen1 = std::static_pointer_cast(geom); - if(gen1->points.size() > 2) { //the edge is a polyline - return isInvalid; - } - Base::Vector3d line = gen1->points.at(1) - gen1->points.at(0); - if(fabs(line.y) < FLT_EPSILON ) { - edgeType = isHorizontal; - } else if(fabs(line.x) < FLT_EPSILON) { - edgeType = isVertical; - } else { - edgeType = isDiagonal; - } - } else if (geom->geomType == TechDraw::CIRCLE || - geom->geomType == TechDraw::ARCOFCIRCLE ) { - edgeType = isCircle; - } else if (geom->geomType == TechDraw::ELLIPSE || - geom->geomType == TechDraw::ARCOFELLIPSE) { - edgeType = isEllipse; - } else if (geom->geomType == TechDraw::BSPLINE) { - TechDraw::BSplinePtr spline = static_pointer_cast (geom); - if (spline->isCircle()) { - edgeType = isBSplineCircle; - } else { - edgeType = isBSpline; - } - } else { - edgeType = isInvalid; - } + + //only 1 subshape selected + //the Name starts with "Edge" + int GeoId( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) ); + TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId); + if (!geom) { + Base::Console().Error("Logic Error: no geometry for GeoId: %d\n",GeoId); + return isInvalid; + } + + if(geom->geomType == TechDraw::GENERIC) { + TechDraw::GenericPtr gen1 = std::static_pointer_cast(geom); + if(gen1->points.size() > 2) { //the edge is a polyline + return isInvalid; + } + Base::Vector3d line = gen1->points.at(1) - gen1->points.at(0); + if(fabs(line.y) < FLT_EPSILON ) { + return isHorizontal; + } else if(fabs(line.x) < FLT_EPSILON) { + return isVertical; + } else { + return isDiagonal; + } + } else if (geom->geomType == TechDraw::CIRCLE || + geom->geomType == TechDraw::ARCOFCIRCLE ) { + return isCircle; + } else if (geom->geomType == TechDraw::ELLIPSE || + geom->geomType == TechDraw::ARCOFELLIPSE) { + return isEllipse; + } else if (geom->geomType == TechDraw::BSPLINE) { + TechDraw::BSplinePtr spline = static_pointer_cast (geom); + if (spline->isCircle()) { + return isBSplineCircle; + } else { + return isBSpline; } } - return edgeType; + + return isInvalid; } //! verify that Selection contains valid geometries for a Vertex based Dimensions bool _isValidVertexes(Gui::Command* cmd, int count) { std::vector selection = cmd->getSelection().getSelectionEx(); const std::vector SubNames = selection[0].getSubNames(); - bool isValid = true; - if(SubNames.size() == (unsigned) count) { - for (auto& s: SubNames) { - if (TechDraw::DrawUtil::getGeomTypeFromName(s) != "Vertex") { - isValid = false; - break; - } - } - } else { - isValid = false; + + if(SubNames.size() != (unsigned) count) { + return false; } - return isValid; + + for (auto& s: SubNames) { + if (TechDraw::DrawUtil::getGeomTypeFromName(s) != "Vertex") { + return false; + } + } + + return true; } //! verify that the Selection contains valid geometries for an Edge to Edge Dimension @@ -1556,115 +1553,113 @@ int _isValidEdgeToEdge(Gui::Command* cmd) { return isInvalid; } - int edgeType = isInvalid; const std::vector SubNames = selection[0].getSubNames(); - if(SubNames.size() == 2) { //there are 2 - if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && //they both start with "Edge" - TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") { - int GeoId0( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) ); - int GeoId1( TechDraw::DrawUtil::getIndexFromName(SubNames[1]) ); - TechDraw::BaseGeomPtr geom0 = objFeat0->getGeomByIndex(GeoId0); - TechDraw::BaseGeomPtr geom1 = objFeat0->getGeomByIndex(GeoId1); - if ((!geom0) || (!geom1)) { // missing gometry - Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",GeoId0,GeoId1); - return isInvalid; - } + //there has to be 2 + if(SubNames.size() != 2) { + return isInvalid; + } - if(geom0->geomType == TechDraw::GENERIC && - geom1->geomType == TechDraw::GENERIC) { - TechDraw::GenericPtr gen0 = std::static_pointer_cast (geom0); - TechDraw::GenericPtr gen1 = std::static_pointer_cast (geom1); - if(gen0->points.size() > 2 || - gen1->points.size() > 2) { //the edge is a polyline - return isInvalid; //not supported yet - } - Base::Vector3d line0 = gen0->points.at(1) - gen0->points.at(0); - Base::Vector3d line1 = gen1->points.at(1) - gen1->points.at(0); - double xprod = fabs(line0.x * line1.y - line0.y * line1.x); - if (xprod > FLT_EPSILON) { //edges are not parallel - return isAngle; //angle or distance - } else { - return isDiagonal; //distance || line - } - } else { - return isDiagonal; //two edges, not both straight lines - } - } //edges - } // 2 sub objects - return edgeType; + //they both start with "Edge" + if(TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && + TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") { + return isInvalid; + } + + int GeoId0( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) ); + int GeoId1( TechDraw::DrawUtil::getIndexFromName(SubNames[1]) ); + TechDraw::BaseGeomPtr geom0 = objFeat0->getGeomByIndex(GeoId0); + TechDraw::BaseGeomPtr geom1 = objFeat0->getGeomByIndex(GeoId1); + + if ((!geom0) || (!geom1)) { // missing gometry + Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",GeoId0,GeoId1); + return isInvalid; + } + + if(geom0->geomType == TechDraw::GENERIC && + geom1->geomType == TechDraw::GENERIC) { + TechDraw::GenericPtr gen0 = std::static_pointer_cast (geom0); + TechDraw::GenericPtr gen1 = std::static_pointer_cast (geom1); + if(gen0->points.size() > 2 || + gen1->points.size() > 2) { //the edge is a polyline + return isInvalid; //not supported yet + } + Base::Vector3d line0 = gen0->points.at(1) - gen0->points.at(0); + Base::Vector3d line1 = gen1->points.at(1) - gen1->points.at(0); + double xprod = fabs(line0.x * line1.y - line0.y * line1.x); + if (xprod > FLT_EPSILON) { //edges are not parallel + return isAngle; //angle or distance + } else { + return isDiagonal; //distance || line + } + } else { + return isDiagonal; //two edges, not both straight lines + } + + return isInvalid; } //! verify that the Selection contains valid geometries for a Vertex to Edge Dimension bool _isValidVertexToEdge(Gui::Command* cmd) { - bool result = false; std::vector selection = cmd->getSelection().getSelectionEx(); TechDraw::DrawViewPart* objFeat0 = static_cast(selection[0].getObject()); const std::vector SubNames = selection[0].getSubNames(); - if(SubNames.size() == 2) { //there are 2 - int eId,vId; - TechDraw::BaseGeomPtr e; - TechDraw::VertexPtr v; - if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && - TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") { - eId = TechDraw::DrawUtil::getIndexFromName(SubNames[0]); - vId = TechDraw::DrawUtil::getIndexFromName(SubNames[1]); - } else if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge" && - TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex") { - eId = TechDraw::DrawUtil::getIndexFromName(SubNames[1]); - vId = TechDraw::DrawUtil::getIndexFromName(SubNames[0]); - } else { - return false; - } - e = objFeat0->getGeomByIndex(eId); - v = objFeat0->getProjVertexByIndex(vId); - if ((!e) || (!v)) { - Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",eId,vId); - return false; - } - result = true; + + //there has to be 2 + if(SubNames.size() != 2) { + return false; } - return result; + + int eId,vId; + TechDraw::BaseGeomPtr e; + TechDraw::VertexPtr v; + if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && + TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") { + eId = TechDraw::DrawUtil::getIndexFromName(SubNames[0]); + vId = TechDraw::DrawUtil::getIndexFromName(SubNames[1]); + } else if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge" && + TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex") { + eId = TechDraw::DrawUtil::getIndexFromName(SubNames[1]); + vId = TechDraw::DrawUtil::getIndexFromName(SubNames[0]); + } else { + return false; + } + e = objFeat0->getGeomByIndex(eId); + v = objFeat0->getProjVertexByIndex(vId); + if ((!e) || (!v)) { + Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",eId,vId); + return false; + } + + return true; } char* _edgeTypeToText(int e) { - char* result; switch(e) { case isInvalid: - result = "invalid"; - break; + return "invalid"; case isHorizontal: - result = "horizontal"; - break; + return "horizontal"; case isVertical: - result = "vertical"; - break; + return "vertical"; case isDiagonal: - result = "diagonal"; - break; + return "diagonal"; case isCircle: - result = "circle"; - break; + return "circle"; case isEllipse: - result = "ellipse"; - break; + return "ellipse"; case isBSpline: - result = "bspline"; - break; + return "bspline"; case isBSplineCircle: - result = "circular bspline"; - break; + return "circular bspline"; case isAngle: - result = "angle"; - break; + return "angle"; case isAngle3Pt: - result = "angle3"; - break; + return "angle3"; default: - result = "unknown"; + return "unknown"; } - return result; } diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index bcf1c58f80..188d4a29bc 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -125,10 +125,10 @@ void CmdTechDrawHatch::activated(int iMsg) QObject::tr("Some Faces in selection are already hatched. Replace?")); if (rc == QMessageBox::StandardButton::NoButton) { return; - } else { - removeOld = true; - break; } + + removeOld = true; + break; } } @@ -276,17 +276,18 @@ void CmdTechDrawImage::activated(int iMsg) QString(), QString::fromUtf8(QT_TR_NOOP("Image (*.png *.jpg *.jpeg)"))); - if (!fileName.isEmpty()) - { - std::string FeatName = getUniqueObjectName("Image"); - fileName = Base::Tools::escapeEncodeFilename(fileName); - openCommand(QT_TRANSLATE_NOOP("Command", "Create Image")); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewImage','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.ImageFile = '%s'",FeatName.c_str(),fileName.toUtf8().constData()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - updateActive(); - commitCommand(); + if (fileName.isEmpty()) { + return; } + + std::string FeatName = getUniqueObjectName("Image"); + fileName = Base::Tools::escapeEncodeFilename(fileName); + openCommand(QT_TRANSLATE_NOOP("Command", "Create Image")); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewImage','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.ImageFile = '%s'",FeatName.c_str(),fileName.toUtf8().constData()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); } bool CmdTechDrawImage::isActive(void) @@ -325,13 +326,12 @@ void CmdTechDrawToggleFrame::activated(int iMsg) Gui::ViewProvider* vp = activeGui->getViewProvider(page); ViewProviderPage* vpp = dynamic_cast(vp); - if (vpp != nullptr) { - vpp->toggleFrameState(); - } else { + if (vpp == nullptr) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No TechDraw Page"), QObject::tr("Need a TechDraw Page for this command")); return; } + vpp->toggleFrameState(); } bool CmdTechDrawToggleFrame::isActive(void) diff --git a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp index 1781a2a0ec..f31e97ab5c 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp @@ -101,19 +101,21 @@ namespace TechDrawGui { void execInsertPrefixChar(Gui::Command* cmd, std::string prefixChar) { // insert a prefix character into the format specifier std::vector selection; - if (_checkSelection(cmd, selection, "TechDraw Insert Prefix")) { - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Insert Prefix")); - for (auto selected : selection) { - auto object = selected.getObject(); - if (object->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { - auto dim = static_cast(selected.getObject()); - std::string formatSpec = dim->FormatSpec.getStrValue(); - formatSpec = prefixChar + formatSpec; - dim->FormatSpec.setValue(formatSpec); - } - } - Gui::Command::commitCommand(); + if (!_checkSelection(cmd, selection, "TechDraw Insert Prefix")) { + return; } + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Insert Prefix")); + for (auto selected : selection) { + auto object = selected.getObject(); + if (object->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { + auto dim = static_cast(selected.getObject()); + std::string formatSpec = dim->FormatSpec.getStrValue(); + formatSpec = prefixChar + formatSpec; + dim->FormatSpec.setValue(formatSpec); + } + } + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionInsertDiameter) @@ -185,24 +187,26 @@ bool CmdTechDrawExtensionInsertSquare::isActive(void) void execRemovePrefixChar(Gui::Command* cmd) { // remove a prefix character from the format specifier std::vector selection; - if (_checkSelection(cmd, selection, "TechDraw Remove Prefix")) { - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Remove Prefix")); - for (auto selected : selection) - { - auto object = selected.getObject(); - if (object->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { - auto dim = static_cast(selected.getObject()); - std::string formatSpec = dim->FormatSpec.getStrValue(); - int pos = formatSpec.find("%."); - if (pos != 0) - { - formatSpec = formatSpec.substr(pos); - dim->FormatSpec.setValue(formatSpec); - } + if (!_checkSelection(cmd, selection, "TechDraw Remove Prefix")) { + return; + } + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Remove Prefix")); + for (auto selected : selection) + { + auto object = selected.getObject(); + if (object->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { + auto dim = static_cast(selected.getObject()); + std::string formatSpec = dim->FormatSpec.getStrValue(); + int pos = formatSpec.find("%."); + if (pos != 0) + { + formatSpec = formatSpec.substr(pos); + dim->FormatSpec.setValue(formatSpec); } } - Gui::Command::commitCommand(); } + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionRemovePrefixChar) @@ -355,28 +359,30 @@ bool CmdTechDrawExtensionInsertPrefixGroup::isActive(void) void execIncreaseDecreaseDecimal(Gui::Command* cmd, int delta) { // increase or decrease number of decimal places of a measure std::vector selection; - if (_checkSelection(cmd, selection, "TechDraw Increase/Decrease Decimal")) { - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Increase/Decrease Decimal")); - std::string numStr; - for (auto selected : selection) { - auto object = selected.getObject(); - if (object->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { - auto dim = static_cast(selected.getObject()); - std::string formatSpec = dim->FormatSpec.getStrValue(); - std::string searchStr("%."); - int numFound = formatSpec.find(searchStr) + 2; - numStr = formatSpec[numFound]; - int numInt = std::stoi(numStr, nullptr); - numInt = numInt + delta; - if (numInt >= 0 && numInt <= 9) { - numStr = std::to_string(numInt); - formatSpec.replace(numFound, 1, numStr); - dim->FormatSpec.setValue(formatSpec); - } + if (!_checkSelection(cmd, selection, "TechDraw Increase/Decrease Decimal")) { + return; + } + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Increase/Decrease Decimal")); + std::string numStr; + for (auto selected : selection) { + auto object = selected.getObject(); + if (object->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { + auto dim = static_cast(selected.getObject()); + std::string formatSpec = dim->FormatSpec.getStrValue(); + std::string searchStr("%."); + int numFound = formatSpec.find(searchStr) + 2; + numStr = formatSpec[numFound]; + int numInt = std::stoi(numStr, nullptr); + numInt = numInt + delta; + if (numInt >= 0 && numInt <= 9) { + numStr = std::to_string(numInt); + formatSpec.replace(numFound, 1, numStr); + dim->FormatSpec.setValue(formatSpec); } } - Gui::Command::commitCommand(); } + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionIncreaseDecimal) @@ -548,26 +554,28 @@ bool CmdTechDrawExtensionIncreaseDecreaseGroup::isActive(void) void execPosHorizChainDimension(Gui::Command* cmd) { // position a horizontal dimension chain std::vector selection; - if (_checkSelection(cmd, selection, "TechDraw PosHorizChainDimension")) { - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Pos Horiz Chain Dim")); - std::vector validDimension; - validDimension = _getDimensions(selection, "DistanceX"); - if (validDimension.empty()) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("TechDraw PosHorizChainDimension"), - QObject::tr("No horizontal dimensions selected")); - return; - } - float yMaster = validDimension[0]->Y.getValue(); - for (auto dim : validDimension) { - dim->Y.setValue(yMaster); - pointPair pp = dim->getLinearPoints(); - Base::Vector3d p1 = pp.first; - Base::Vector3d p2 = pp.second; - dim->X.setValue((p1.x + p2.x) / 2.0); - } - Gui::Command::commitCommand(); + if (!_checkSelection(cmd, selection, "TechDraw PosHorizChainDimension")) { + return; } + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Pos Horiz Chain Dim")); + std::vector validDimension; + validDimension = _getDimensions(selection, "DistanceX"); + if (validDimension.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("TechDraw PosHorizChainDimension"), + QObject::tr("No horizontal dimensions selected")); + return; + } + float yMaster = validDimension[0]->Y.getValue(); + for (auto dim : validDimension) { + dim->Y.setValue(yMaster); + pointPair pp = dim->getLinearPoints(); + Base::Vector3d p1 = pp.first; + Base::Vector3d p2 = pp.second; + dim->X.setValue((p1.x + p2.x) / 2.0); + } + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionPosHorizChainDimension) @@ -607,27 +615,29 @@ bool CmdTechDrawExtensionPosHorizChainDimension::isActive(void) void execPosVertChainDimension(Gui::Command* cmd) { // position a vertical dimension chain std::vector selection; - if (_checkSelection(cmd, selection, "TechDraw PosVertChainDimension")) { - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Pos Vert Chain Dim")); - std::vector validDimension; - validDimension = _getDimensions(selection, "DistanceY"); - if (validDimension.empty()) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("TechDraw PosVertChainDimension"), - QObject::tr("No vertical dimensions selected")); - return; - } - float xMaster = validDimension[0]->X.getValue(); - double fontSize = Preferences::dimFontSizeMM(); - for (auto dim : validDimension) { - dim->X.setValue(xMaster); - pointPair pp = dim->getLinearPoints(); - Base::Vector3d p1 = pp.first; - Base::Vector3d p2 = pp.second; - dim->Y.setValue((p1.y + p2.y) / -2.0 + 0.5 * fontSize); - } - Gui::Command::commitCommand(); + if (!_checkSelection(cmd, selection, "TechDraw PosVertChainDimension")) { + return; } + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Pos Vert Chain Dim")); + std::vector validDimension; + validDimension = _getDimensions(selection, "DistanceY"); + if (validDimension.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("TechDraw PosVertChainDimension"), + QObject::tr("No vertical dimensions selected")); + return; + } + float xMaster = validDimension[0]->X.getValue(); + double fontSize = Preferences::dimFontSizeMM(); + for (auto dim : validDimension) { + dim->X.setValue(xMaster); + pointPair pp = dim->getLinearPoints(); + Base::Vector3d p1 = pp.first; + Base::Vector3d p2 = pp.second; + dim->Y.setValue((p1.y + p2.y) / -2.0 + 0.5 * fontSize); + } + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionPosVertChainDimension) @@ -667,32 +677,34 @@ bool CmdTechDrawExtensionPosVertChainDimension::isActive(void) void execPosObliqueChainDimension(Gui::Command* cmd) { // position an oblique dimension chain std::vector selection; - if (_checkSelection(cmd, selection, "TechDraw PosObliqueChainDimension")) { - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Pos Oblique Chain Dim")); - std::vector validDimension; - validDimension = _getDimensions(selection, "Distance"); - if (validDimension.empty()) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("TechDraw PosObliqueChainDimension"), - QObject::tr("No oblique dimensions selected")); - return; - } - float xMaster = validDimension[0]->X.getValue(); - float yMaster = validDimension[0]->Y.getValue(); - Base::Vector3d pMaster(xMaster, yMaster, 0.0); - pointPair pp = validDimension[0]->getLinearPoints(); - Base::Vector3d dirMaster = pp.second - pp.first; - dirMaster.y = -dirMaster.y; - for (auto dim : validDimension) { - float xDim = dim->X.getValue(); - float yDim = dim->Y.getValue(); - Base::Vector3d pDim(xDim, yDim, 0.0); - Base::Vector3d p3 = _getTrianglePoint(pMaster, dirMaster, pDim); - dim->X.setValue(p3.x); - dim->Y.setValue(p3.y); - } - Gui::Command::commitCommand(); + if (!_checkSelection(cmd, selection, "TechDraw PosObliqueChainDimension")) { + return; } + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Pos Oblique Chain Dim")); + std::vector validDimension; + validDimension = _getDimensions(selection, "Distance"); + if (validDimension.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("TechDraw PosObliqueChainDimension"), + QObject::tr("No oblique dimensions selected")); + return; + } + float xMaster = validDimension[0]->X.getValue(); + float yMaster = validDimension[0]->Y.getValue(); + Base::Vector3d pMaster(xMaster, yMaster, 0.0); + pointPair pp = validDimension[0]->getLinearPoints(); + Base::Vector3d dirMaster = pp.second - pp.first; + dirMaster.y = -dirMaster.y; + for (auto dim : validDimension) { + float xDim = dim->X.getValue(); + float yDim = dim->Y.getValue(); + Base::Vector3d pDim(xDim, yDim, 0.0); + Base::Vector3d p3 = _getTrianglePoint(pMaster, dirMaster, pDim); + dim->X.setValue(p3.x); + dim->Y.setValue(p3.y); + } + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionPosObliqueChainDimension) @@ -851,30 +863,32 @@ bool CmdTechDrawExtensionPosChainDimensionGroup::isActive(void) void execCascadeHorizDimension(Gui::Command* cmd) { // cascade horizontal dimensions std::vector selection; - if (_checkSelection(cmd, selection, "TechDraw CascadeHorizDimension")) { - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cascade Horiz Dim")); - std::vector validDimension; - validDimension = _getDimensions(selection, "DistanceX"); - if (validDimension.empty()) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("TechDraw CascadeHorizDimension"), - QObject::tr("No horizontal dimensions selected")); - return; - } - float yMaster = validDimension[0]->Y.getValue(); - float dimDistance = activeDimAttributes.getCascadeSpacing(); - if (signbit(yMaster)) - dimDistance = -dimDistance; - for (auto dim : validDimension) { - dim->Y.setValue(yMaster); - pointPair pp = dim->getLinearPoints(); - Base::Vector3d p1 = pp.first; - Base::Vector3d p2 = pp.second; - dim->X.setValue((p1.x + p2.x) / 2.0); - yMaster = yMaster + dimDistance; - } - Gui::Command::commitCommand(); + if (!_checkSelection(cmd, selection, "TechDraw CascadeHorizDimension")) { + return; } + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cascade Horiz Dim")); + std::vector validDimension; + validDimension = _getDimensions(selection, "DistanceX"); + if (validDimension.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("TechDraw CascadeHorizDimension"), + QObject::tr("No horizontal dimensions selected")); + return; + } + float yMaster = validDimension[0]->Y.getValue(); + float dimDistance = activeDimAttributes.getCascadeSpacing(); + if (signbit(yMaster)) + dimDistance = -dimDistance; + for (auto dim : validDimension) { + dim->Y.setValue(yMaster); + pointPair pp = dim->getLinearPoints(); + Base::Vector3d p1 = pp.first; + Base::Vector3d p2 = pp.second; + dim->X.setValue((p1.x + p2.x) / 2.0); + yMaster = yMaster + dimDistance; + } + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionCascadeHorizDimension) @@ -915,31 +929,33 @@ bool CmdTechDrawExtensionCascadeHorizDimension::isActive(void) void execCascadeVertDimension(Gui::Command* cmd) { // cascade vertical dimensions std::vector selection; - if (_checkSelection(cmd, selection, "TechDraw CascadeVertDimension")) { - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cascade Vert Dim")); - std::vector validDimension; - validDimension = _getDimensions(selection, "DistanceY"); - if (validDimension.empty()) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("TechDraw CascadeVertDimension"), - QObject::tr("No vertical dimensions selected")); - return; - } - float xMaster = validDimension[0]->X.getValue(); - float dimDistance = activeDimAttributes.getCascadeSpacing(); - if (signbit(xMaster)) - dimDistance = -dimDistance; - double fontSize = Preferences::dimFontSizeMM(); - for (auto dim : validDimension) { - dim->X.setValue(xMaster); - pointPair pp = dim->getLinearPoints(); - Base::Vector3d p1 = pp.first; - Base::Vector3d p2 = pp.second; - dim->Y.setValue((p1.y + p2.y) / -2.0 + 0.5 * fontSize); - xMaster = xMaster + dimDistance; - } - Gui::Command::commitCommand(); + if (!_checkSelection(cmd, selection, "TechDraw CascadeVertDimension")) { + return; } + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cascade Vert Dim")); + std::vector validDimension; + validDimension = _getDimensions(selection, "DistanceY"); + if (validDimension.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("TechDraw CascadeVertDimension"), + QObject::tr("No vertical dimensions selected")); + return; + } + float xMaster = validDimension[0]->X.getValue(); + float dimDistance = activeDimAttributes.getCascadeSpacing(); + if (signbit(xMaster)) + dimDistance = -dimDistance; + double fontSize = Preferences::dimFontSizeMM(); + for (auto dim : validDimension) { + dim->X.setValue(xMaster); + pointPair pp = dim->getLinearPoints(); + Base::Vector3d p1 = pp.first; + Base::Vector3d p2 = pp.second; + dim->Y.setValue((p1.y + p2.y) / -2.0 + 0.5 * fontSize); + xMaster = xMaster + dimDistance; + } + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionCascadeVertDimension) @@ -980,39 +996,41 @@ bool CmdTechDrawExtensionCascadeVertDimension::isActive(void) void execCascadeObliqueDimension(Gui::Command* cmd) { // cascade oblique dimensions std::vector selection; - if (_checkSelection(cmd, selection, "TechDraw CascadeObliqueDimension")) { - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cascade Oblique Dim")); - std::vector validDimension; - validDimension = _getDimensions(selection, "Distance"); - if (validDimension.empty()) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("TechDraw CascadeObliqueDimension"), - QObject::tr("No oblique dimensions selected")); - return; - } - float xMaster = validDimension[0]->X.getValue(); - float yMaster = validDimension[0]->Y.getValue(); - Base::Vector3d pMaster(xMaster, yMaster, 0.0); - pointPair pp = validDimension[0]->getLinearPoints(); - Base::Vector3d dirMaster = pp.second - pp.first; - dirMaster.y = -dirMaster.y; - Base::Vector3d origin(0.0, 0.0, 0.0); - Base::Vector3d ipDelta = _getTrianglePoint(pMaster, dirMaster, origin); - float dimDistance = activeDimAttributes.getCascadeSpacing(); - Base::Vector3d delta = ipDelta.Normalize() * dimDistance; - int i = 0; - for (auto dim : validDimension) { - float xDim = dim->X.getValue(); - float yDim = dim->Y.getValue(); - Base::Vector3d pDim(xDim, yDim, 0.0); - Base::Vector3d p3 = _getTrianglePoint(pMaster, dirMaster, pDim); - p3 = p3 + delta * i; - dim->X.setValue(p3.x); - dim->Y.setValue(p3.y); - i = i + 1; - } - Gui::Command::commitCommand(); + if (!_checkSelection(cmd, selection, "TechDraw CascadeObliqueDimension")) { + return; } + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cascade Oblique Dim")); + std::vector validDimension; + validDimension = _getDimensions(selection, "Distance"); + if (validDimension.empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("TechDraw CascadeObliqueDimension"), + QObject::tr("No oblique dimensions selected")); + return; + } + float xMaster = validDimension[0]->X.getValue(); + float yMaster = validDimension[0]->Y.getValue(); + Base::Vector3d pMaster(xMaster, yMaster, 0.0); + pointPair pp = validDimension[0]->getLinearPoints(); + Base::Vector3d dirMaster = pp.second - pp.first; + dirMaster.y = -dirMaster.y; + Base::Vector3d origin(0.0, 0.0, 0.0); + Base::Vector3d ipDelta = _getTrianglePoint(pMaster, dirMaster, origin); + float dimDistance = activeDimAttributes.getCascadeSpacing(); + Base::Vector3d delta = ipDelta.Normalize() * dimDistance; + int i = 0; + for (auto dim : validDimension) { + float xDim = dim->X.getValue(); + float yDim = dim->Y.getValue(); + Base::Vector3d pDim(xDim, yDim, 0.0); + Base::Vector3d p3 = _getTrianglePoint(pMaster, dirMaster, pDim); + p3 = p3 + delta * i; + dim->X.setValue(p3.x); + dim->Y.setValue(p3.y); + i = i + 1; + } + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionCascadeObliqueDimension) @@ -1183,20 +1201,18 @@ void execCreateHorizChainDimension(Gui::Command* cmd) { const std::vector subNames = selection[0].getSubNames(); std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); - if (!allVertexes.empty()) { - if (allVertexes.size() > 1) { - std::sort(allVertexes.begin(), allVertexes.end(), sortX); - float yMaster = 0.0; - for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { - TechDraw::DrawViewDimension* dim; - dim = _createLinDimension(cmd, objFeat, allVertexes[n].name, allVertexes[n + 1].name, "DistanceX"); - TechDraw::pointPair pp = dim->getLinearPoints(); - Base::Vector3d mid = (pp.first + pp.second) / 2.0; - dim->X.setValue(mid.x); - if (n == 0) - yMaster = -mid.y; - dim->Y.setValue(yMaster); - } + if (!allVertexes.empty() && allVertexes.size() > 1) { + std::sort(allVertexes.begin(), allVertexes.end(), sortX); + float yMaster = 0.0; + for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { + TechDraw::DrawViewDimension* dim; + dim = _createLinDimension(cmd, objFeat, allVertexes[n].name, allVertexes[n + 1].name, "DistanceX"); + TechDraw::pointPair pp = dim->getLinearPoints(); + Base::Vector3d mid = (pp.first + pp.second) / 2.0; + dim->X.setValue(mid.x); + if (n == 0) + yMaster = -mid.y; + dim->Y.setValue(yMaster); } } objFeat->refreshCEGeoms(); @@ -1249,21 +1265,19 @@ void execCreateVertChainDimension(Gui::Command* cmd) { const std::vector subNames = selection[0].getSubNames(); std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); - if (!allVertexes.empty()) { - if (allVertexes.size() > 1) { - std::sort(allVertexes.begin(), allVertexes.end(), sortY); - float xMaster = 0.0; - double fontSize = Preferences::dimFontSizeMM(); - for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { - TechDraw::DrawViewDimension* dim; - dim = _createLinDimension(cmd, objFeat, allVertexes[n].name, allVertexes[n + 1].name, "DistanceY"); - TechDraw::pointPair pp = dim->getLinearPoints(); - Base::Vector3d mid = (pp.first + pp.second) / 2.0; - if (n == 0) - xMaster = mid.x; - dim->X.setValue(xMaster); - dim->Y.setValue(-mid.y + 0.5 * fontSize); - } + if (!allVertexes.empty() && allVertexes.size() > 1) { + std::sort(allVertexes.begin(), allVertexes.end(), sortY); + float xMaster = 0.0; + double fontSize = Preferences::dimFontSizeMM(); + for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { + TechDraw::DrawViewDimension* dim; + dim = _createLinDimension(cmd, objFeat, allVertexes[n].name, allVertexes[n + 1].name, "DistanceY"); + TechDraw::pointPair pp = dim->getLinearPoints(); + Base::Vector3d mid = (pp.first + pp.second) / 2.0; + if (n == 0) + xMaster = mid.x; + dim->X.setValue(xMaster); + dim->Y.setValue(-mid.y + 0.5 * fontSize); } } objFeat->refreshCEGeoms(); @@ -1315,47 +1329,45 @@ void execCreateObliqueChainDimension(Gui::Command* cmd) { const std::vector subNames = selection[0].getSubNames(); std::vector allVertexes, carrierVertexes; allVertexes = _getVertexInfo(objFeat, subNames); - if (!allVertexes.empty()) { - if (allVertexes.size() > 1) { - Base::Vector3d pMaster = allVertexes[0].point; - Base::Vector3d dirMaster = pMaster - allVertexes[1].point; - Base::Vector3d origin(0.0, 0.0, 0.0); - Base::Vector3d delta = _getTrianglePoint(pMaster, dirMaster, origin); - float dimDistance = activeDimAttributes.getCascadeSpacing(); - delta = delta.Normalize() * dimDistance; - double scale = objFeat->getScale(); - for (dimVertex oldVertex : allVertexes) { - Base::Vector3d nextPoint = _getTrianglePoint(pMaster, dirMaster, oldVertex.point); - nextPoint.y = -nextPoint.y; - oldVertex.point.y = -oldVertex.point.y; - if ((oldVertex.point - nextPoint).Length() > 0.01) { - std::string vertTag = objFeat->addCosmeticVertex(nextPoint / scale); - int vertNumber = objFeat->add1CVToGV(vertTag); - std::stringstream ss; - ss << "Vertex" << vertNumber; - dimVertex newVertex; - newVertex.name = ss.str(); - newVertex.point = nextPoint; - carrierVertexes.push_back(newVertex); - std::string edgeTag = objFeat->addCosmeticEdge(oldVertex.point / scale, nextPoint / scale); - auto edge = objFeat->getCosmeticEdge(edgeTag); - edge->m_format.m_style = 1; - edge->m_format.m_weight = 0.15; - edge->m_format.m_color = App::Color(0.0f, 0.0f, 0.0f); - } - else - carrierVertexes.push_back(oldVertex); - } - std::sort(carrierVertexes.begin(), carrierVertexes.end(), sortX); - double fontSize = Preferences::dimFontSizeMM(); - for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { - TechDraw::DrawViewDimension* dim; - dim = _createLinDimension(cmd, objFeat, carrierVertexes[n].name, carrierVertexes[n + 1].name, "Distance"); - TechDraw::pointPair pp = dim->getLinearPoints(); - Base::Vector3d mid = (pp.first + pp.second) / 2.0 + delta; - dim->X.setValue(mid.x); - dim->Y.setValue(-mid.y + 0.5 * fontSize); + if (!allVertexes.empty() && allVertexes.size() > 1) { + Base::Vector3d pMaster = allVertexes[0].point; + Base::Vector3d dirMaster = pMaster - allVertexes[1].point; + Base::Vector3d origin(0.0, 0.0, 0.0); + Base::Vector3d delta = _getTrianglePoint(pMaster, dirMaster, origin); + float dimDistance = activeDimAttributes.getCascadeSpacing(); + delta = delta.Normalize() * dimDistance; + double scale = objFeat->getScale(); + for (dimVertex oldVertex : allVertexes) { + Base::Vector3d nextPoint = _getTrianglePoint(pMaster, dirMaster, oldVertex.point); + nextPoint.y = -nextPoint.y; + oldVertex.point.y = -oldVertex.point.y; + if ((oldVertex.point - nextPoint).Length() > 0.01) { + std::string vertTag = objFeat->addCosmeticVertex(nextPoint / scale); + int vertNumber = objFeat->add1CVToGV(vertTag); + std::stringstream ss; + ss << "Vertex" << vertNumber; + dimVertex newVertex; + newVertex.name = ss.str(); + newVertex.point = nextPoint; + carrierVertexes.push_back(newVertex); + std::string edgeTag = objFeat->addCosmeticEdge(oldVertex.point / scale, nextPoint / scale); + auto edge = objFeat->getCosmeticEdge(edgeTag); + edge->m_format.m_style = 1; + edge->m_format.m_weight = 0.15; + edge->m_format.m_color = App::Color(0.0f, 0.0f, 0.0f); } + else + carrierVertexes.push_back(oldVertex); + } + std::sort(carrierVertexes.begin(), carrierVertexes.end(), sortX); + double fontSize = Preferences::dimFontSizeMM(); + for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { + TechDraw::DrawViewDimension* dim; + dim = _createLinDimension(cmd, objFeat, carrierVertexes[n].name, carrierVertexes[n + 1].name, "Distance"); + TechDraw::pointPair pp = dim->getLinearPoints(); + Base::Vector3d mid = (pp.first + pp.second) / 2.0 + delta; + dim->X.setValue(mid.x); + dim->Y.setValue(-mid.y + 0.5 * fontSize); } objFeat->refreshCEGeoms(); objFeat->requestPaint(); @@ -1523,26 +1535,24 @@ void execCreateHorizCoordDimension(Gui::Command* cmd) { const std::vector subNames = selection[0].getSubNames(); std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); - if (!allVertexes.empty()) { - if (allVertexes.size() > 1) { - dimVertex firstVertex = allVertexes[0]; - dimVertex secondVertex = allVertexes[1]; - std::sort(allVertexes.begin(), allVertexes.end(), sortX); - if (firstVertex.point.x > secondVertex.point.x) { - std::reverse(allVertexes.begin(), allVertexes.end()); - } - float dimDistance = activeDimAttributes.getCascadeSpacing(); - float yMaster = allVertexes[0].point.y - dimDistance; - if (signbit(yMaster)) - dimDistance = -dimDistance; - for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { - TechDraw::DrawViewDimension* dim; - dim = _createLinDimension(cmd, objFeat, allVertexes[0].name, allVertexes[n + 1].name, "DistanceX"); - TechDraw::pointPair pp = dim->getLinearPoints(); - Base::Vector3d mid = (pp.first + pp.second) / 2.0; - dim->X.setValue(mid.x); - dim->Y.setValue(-yMaster - dimDistance * n); - } + if (!allVertexes.empty() && allVertexes.size() > 1) { + dimVertex firstVertex = allVertexes[0]; + dimVertex secondVertex = allVertexes[1]; + std::sort(allVertexes.begin(), allVertexes.end(), sortX); + if (firstVertex.point.x > secondVertex.point.x) { + std::reverse(allVertexes.begin(), allVertexes.end()); + } + float dimDistance = activeDimAttributes.getCascadeSpacing(); + float yMaster = allVertexes[0].point.y - dimDistance; + if (signbit(yMaster)) + dimDistance = -dimDistance; + for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { + TechDraw::DrawViewDimension* dim; + dim = _createLinDimension(cmd, objFeat, allVertexes[0].name, allVertexes[n + 1].name, "DistanceX"); + TechDraw::pointPair pp = dim->getLinearPoints(); + Base::Vector3d mid = (pp.first + pp.second) / 2.0; + dim->X.setValue(mid.x); + dim->Y.setValue(-yMaster - dimDistance * n); } } objFeat->refreshCEGeoms(); @@ -1596,27 +1606,25 @@ void execCreateVertCoordDimension(Gui::Command* cmd) { const std::vector subNames = selection[0].getSubNames(); std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); - if (!allVertexes.empty()) { - if (allVertexes.size() > 1) { - dimVertex firstVertex = allVertexes[0]; - dimVertex secondVertex = allVertexes[1]; - std::sort(allVertexes.begin(), allVertexes.end(), sortY); - if (firstVertex.point.y > secondVertex.point.y) { - std::reverse(allVertexes.begin(), allVertexes.end()); - } - float dimDistance = activeDimAttributes.getCascadeSpacing(); - float xMaster = allVertexes[0].point.x + dimDistance; - if (signbit(xMaster)) - dimDistance = -dimDistance; - double fontSize = Preferences::dimFontSizeMM(); - for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { - TechDraw::DrawViewDimension* dim; - dim = _createLinDimension(cmd, objFeat, allVertexes[0].name, allVertexes[n + 1].name, "DistanceY"); - TechDraw::pointPair pp = dim->getLinearPoints(); - Base::Vector3d mid = (pp.first + pp.second) / 2.0; - dim->X.setValue(xMaster + dimDistance * n); - dim->Y.setValue(-mid.y + 0.5 * fontSize); - } + if (!allVertexes.empty() && allVertexes.size() > 1) { + dimVertex firstVertex = allVertexes[0]; + dimVertex secondVertex = allVertexes[1]; + std::sort(allVertexes.begin(), allVertexes.end(), sortY); + if (firstVertex.point.y > secondVertex.point.y) { + std::reverse(allVertexes.begin(), allVertexes.end()); + } + float dimDistance = activeDimAttributes.getCascadeSpacing(); + float xMaster = allVertexes[0].point.x + dimDistance; + if (signbit(xMaster)) + dimDistance = -dimDistance; + double fontSize = Preferences::dimFontSizeMM(); + for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { + TechDraw::DrawViewDimension* dim; + dim = _createLinDimension(cmd, objFeat, allVertexes[0].name, allVertexes[n + 1].name, "DistanceY"); + TechDraw::pointPair pp = dim->getLinearPoints(); + Base::Vector3d mid = (pp.first + pp.second) / 2.0; + dim->X.setValue(xMaster + dimDistance * n); + dim->Y.setValue(-mid.y + 0.5 * fontSize); } } objFeat->refreshCEGeoms(); @@ -1670,58 +1678,56 @@ void execCreateObliqueCoordDimension(Gui::Command* cmd) { const std::vector subNames = selection[0].getSubNames(); std::vector allVertexes, carrierVertexes; allVertexes = _getVertexInfo(objFeat, subNames); - if (!allVertexes.empty()) { - if (allVertexes.size() > 1) { - Base::Vector3d pMaster = allVertexes[0].point; - Base::Vector3d dirMaster = pMaster - allVertexes[1].point; - Base::Vector3d origin(0.0, 0.0, 0.0); - Base::Vector3d delta = _getTrianglePoint(pMaster, dirMaster, origin); - float dimDistance = activeDimAttributes.getCascadeSpacing(); - delta = delta.Normalize() * dimDistance; - double scale = objFeat->getScale(); - for (dimVertex oldVertex : allVertexes) { - Base::Vector3d nextPoint = _getTrianglePoint(pMaster, dirMaster, oldVertex.point); - nextPoint.y = -nextPoint.y; - oldVertex.point.y = -oldVertex.point.y; - if ((oldVertex.point - nextPoint).Length() > 0.01) { - std::string vertTag = objFeat->addCosmeticVertex(nextPoint / scale); - int vertNumber = objFeat->add1CVToGV(vertTag); - std::stringstream ss; - ss << "Vertex" << vertNumber; - dimVertex newVertex; - newVertex.name = ss.str(); - newVertex.point = nextPoint; - carrierVertexes.push_back(newVertex); - std::string edgeTag = objFeat->addCosmeticEdge(oldVertex.point / scale, nextPoint / scale); - auto edge = objFeat->getCosmeticEdge(edgeTag); - edge->m_format.m_style = 1; - edge->m_format.m_weight = 0.15; - edge->m_format.m_color = App::Color(0.0f, 0.0f, 0.0f); - } - else - carrierVertexes.push_back(oldVertex); - } - dimVertex firstVertex = carrierVertexes[0]; - dimVertex secondVertex = carrierVertexes[1]; - std::sort(carrierVertexes.begin(), carrierVertexes.end(), sortX); - if (firstVertex.point.x > secondVertex.point.x) { - std::reverse(carrierVertexes.begin(), carrierVertexes.end()); - } - double fontSize = Preferences::dimFontSizeMM(); - for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { - TechDraw::DrawViewDimension* dim; - dim = _createLinDimension(cmd, objFeat, carrierVertexes[0].name, carrierVertexes[n + 1].name, "Distance"); - TechDraw::pointPair pp = dim->getLinearPoints(); - Base::Vector3d mid = (pp.first + pp.second) / 2.0 + delta * (n + 1); - dim->X.setValue(mid.x); - dim->Y.setValue(-mid.y + 0.5 * fontSize); + if (!allVertexes.empty() && allVertexes.size() > 1) { + Base::Vector3d pMaster = allVertexes[0].point; + Base::Vector3d dirMaster = pMaster - allVertexes[1].point; + Base::Vector3d origin(0.0, 0.0, 0.0); + Base::Vector3d delta = _getTrianglePoint(pMaster, dirMaster, origin); + float dimDistance = activeDimAttributes.getCascadeSpacing(); + delta = delta.Normalize() * dimDistance; + double scale = objFeat->getScale(); + for (dimVertex oldVertex : allVertexes) { + Base::Vector3d nextPoint = _getTrianglePoint(pMaster, dirMaster, oldVertex.point); + nextPoint.y = -nextPoint.y; + oldVertex.point.y = -oldVertex.point.y; + if ((oldVertex.point - nextPoint).Length() > 0.01) { + std::string vertTag = objFeat->addCosmeticVertex(nextPoint / scale); + int vertNumber = objFeat->add1CVToGV(vertTag); + std::stringstream ss; + ss << "Vertex" << vertNumber; + dimVertex newVertex; + newVertex.name = ss.str(); + newVertex.point = nextPoint; + carrierVertexes.push_back(newVertex); + std::string edgeTag = objFeat->addCosmeticEdge(oldVertex.point / scale, nextPoint / scale); + auto edge = objFeat->getCosmeticEdge(edgeTag); + edge->m_format.m_style = 1; + edge->m_format.m_weight = 0.15; + edge->m_format.m_color = App::Color(0.0f, 0.0f, 0.0f); } + else + carrierVertexes.push_back(oldVertex); + } + dimVertex firstVertex = carrierVertexes[0]; + dimVertex secondVertex = carrierVertexes[1]; + std::sort(carrierVertexes.begin(), carrierVertexes.end(), sortX); + if (firstVertex.point.x > secondVertex.point.x) { + std::reverse(carrierVertexes.begin(), carrierVertexes.end()); + } + double fontSize = Preferences::dimFontSizeMM(); + for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) { + TechDraw::DrawViewDimension* dim; + dim = _createLinDimension(cmd, objFeat, carrierVertexes[0].name, carrierVertexes[n + 1].name, "Distance"); + TechDraw::pointPair pp = dim->getLinearPoints(); + Base::Vector3d mid = (pp.first + pp.second) / 2.0 + delta * (n + 1); + dim->X.setValue(mid.x); + dim->Y.setValue(-mid.y + 0.5 * fontSize); } - objFeat->refreshCEGeoms(); - objFeat->requestPaint(); - cmd->getSelection().clearSelection(); - Gui::Command::commitCommand(); } + objFeat->refreshCEGeoms(); + objFeat->requestPaint(); + cmd->getSelection().clearSelection(); + Gui::Command::commitCommand(); } DEF_STD_CMD_A(CmdTechDrawExtensionCreateObliqueCoordDimension) @@ -1893,28 +1899,26 @@ void execCreateHorizChamferDimension(Gui::Command* cmd) { const std::vector subNames = selection[0].getSubNames(); std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); - if (!allVertexes.empty()) { - if (allVertexes.size() > 1) { - const auto Pi180 = 180.0 / M_PI; - TechDraw::DrawViewDimension* dim; - dim = _createLinDimension(cmd, objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceX"); - float yMax = std::max(abs(allVertexes[0].point.y), abs(allVertexes[1].point.y)) + 7.0; - if (signbit(allVertexes[0].point.y)) - yMax = -yMax; - TechDraw::pointPair pp = dim->getLinearPoints(); - Base::Vector3d mid = (pp.first + pp.second) / 2.0; - dim->X.setValue(mid.x); - dim->Y.setValue(-yMax); - float dx = allVertexes[0].point.x - allVertexes[1].point.x; - float dy = allVertexes[0].point.y - allVertexes[1].point.y; - float alpha = round(abs(atan(dy / dx)) * Pi180); - std::string sAlpha = std::to_string((int)alpha); - std::string formatSpec = dim->FormatSpec.getStrValue(); - formatSpec = formatSpec + " x" + sAlpha + "°"; - dim->FormatSpec.setValue(formatSpec); - objFeat->requestPaint(); - cmd->getSelection().clearSelection(); - } + if (!allVertexes.empty() && allVertexes.size() > 1) { + const auto Pi180 = 180.0 / M_PI; + TechDraw::DrawViewDimension* dim; + dim = _createLinDimension(cmd, objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceX"); + float yMax = std::max(abs(allVertexes[0].point.y), abs(allVertexes[1].point.y)) + 7.0; + if (signbit(allVertexes[0].point.y)) + yMax = -yMax; + TechDraw::pointPair pp = dim->getLinearPoints(); + Base::Vector3d mid = (pp.first + pp.second) / 2.0; + dim->X.setValue(mid.x); + dim->Y.setValue(-yMax); + float dx = allVertexes[0].point.x - allVertexes[1].point.x; + float dy = allVertexes[0].point.y - allVertexes[1].point.y; + float alpha = round(abs(atan(dy / dx)) * Pi180); + std::string sAlpha = std::to_string((int)alpha); + std::string formatSpec = dim->FormatSpec.getStrValue(); + formatSpec = formatSpec + " x" + sAlpha + "°"; + dim->FormatSpec.setValue(formatSpec); + objFeat->requestPaint(); + cmd->getSelection().clearSelection(); } Gui::Command::commitCommand(); } @@ -1962,28 +1966,26 @@ void execCreateVertChamferDimension(Gui::Command* cmd) { const std::vector subNames = selection[0].getSubNames(); std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); - if (!allVertexes.empty()) { - if (allVertexes.size() > 1) { - const auto Pi180 = 180.0 / M_PI; - TechDraw::DrawViewDimension* dim; - dim = _createLinDimension(cmd, objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceY"); - float xMax = std::max(abs(allVertexes[0].point.x), abs(allVertexes[1].point.x)) + 7.0; - if (signbit(allVertexes[0].point.x)) - xMax = -xMax; - TechDraw::pointPair pp = dim->getLinearPoints(); - Base::Vector3d mid = (pp.first + pp.second) / 2.0; - dim->X.setValue(xMax); - dim->Y.setValue(-mid.y); - float dx = allVertexes[0].point.x - allVertexes[1].point.x; - float dy = allVertexes[0].point.y - allVertexes[1].point.y; - float alpha = round(abs(atan(dx / dy)) * Pi180); - std::string sAlpha = std::to_string((int)alpha); - std::string formatSpec = dim->FormatSpec.getStrValue(); - formatSpec = formatSpec + " x" + sAlpha + "°"; - dim->FormatSpec.setValue(formatSpec); - objFeat->requestPaint(); - cmd->getSelection().clearSelection(); - } + if (!allVertexes.empty() && allVertexes.size() > 1) { + const auto Pi180 = 180.0 / M_PI; + TechDraw::DrawViewDimension* dim; + dim = _createLinDimension(cmd, objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceY"); + float xMax = std::max(abs(allVertexes[0].point.x), abs(allVertexes[1].point.x)) + 7.0; + if (signbit(allVertexes[0].point.x)) + xMax = -xMax; + TechDraw::pointPair pp = dim->getLinearPoints(); + Base::Vector3d mid = (pp.first + pp.second) / 2.0; + dim->X.setValue(xMax); + dim->Y.setValue(-mid.y); + float dx = allVertexes[0].point.x - allVertexes[1].point.x; + float dy = allVertexes[0].point.y - allVertexes[1].point.y; + float alpha = round(abs(atan(dx / dy)) * Pi180); + std::string sAlpha = std::to_string((int)alpha); + std::string formatSpec = dim->FormatSpec.getStrValue(); + formatSpec = formatSpec + " x" + sAlpha + "°"; + dim->FormatSpec.setValue(formatSpec); + objFeat->requestPaint(); + cmd->getSelection().clearSelection(); } Gui::Command::commitCommand(); } @@ -2149,41 +2151,39 @@ void CmdTechDrawExtensionCreateLengthArc::activated(int iMsg) { int geoId = TechDraw::DrawUtil::getIndexFromName(subNames[0]); TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(geoId); std::string geoType = TechDraw::DrawUtil::getGeomTypeFromName(subNames[0]); - if (geoType == "Edge") { - if (geom->geomType == TechDraw::ARCOFCIRCLE) { - TechDraw::AOCPtr arcTag = std::static_pointer_cast(geom); - float radius = arcTag->radius; - Base::Vector3d centerPt = arcTag->center; - centerPt.y = -centerPt.y; - Base::Vector3d startPt = arcTag->startPnt; - startPt.y = -startPt.y; - Base::Vector3d endPt = arcTag->endPnt; - endPt.y = -endPt.y; - std::stringstream startName, endName, formatSpec; - double scale = objFeat->getScale(); - std::string startVertTag = objFeat->addCosmeticVertex(startPt / scale); - int startVertNumber = objFeat->add1CVToGV(startVertTag); - startName << "Vertex" << startVertNumber; - std::string endVertTag = objFeat->addCosmeticVertex(endPt / scale); - int endVertNumber = objFeat->add1CVToGV(endVertTag); - endName << "Vertex" << endVertNumber; - TechDraw::DrawViewDimension* dim; - dim = _createLinDimension(this, objFeat, startName.str(), endName.str(), "Distance"); - TechDraw::pointPair pp = dim->getLinearPoints(); - Base::Vector3d mid = (pp.first + pp.second) / 2.0; - dim->X.setValue(mid.x); - dim->Y.setValue(-mid.y); - Base::Vector3d radVec1 = startPt - centerPt; - Base::Vector3d radVec2 = endPt - centerPt; - float alpha = acos((radVec1 * radVec2) / (radVec1.Length() * radVec2.Length())); - float arcLength = alpha * radius / scale; - dim->Arbitrary.setValue(true); - formatSpec << "◠ " << arcLength; - dim->FormatSpec.setValue(formatSpec.str()); - objFeat->refreshCEGeoms(); - objFeat->requestPaint(); - getSelection().clearSelection(); - } + if (geoType == "Edge" && geom->geomType == TechDraw::ARCOFCIRCLE) { + TechDraw::AOCPtr arcTag = std::static_pointer_cast(geom); + float radius = arcTag->radius; + Base::Vector3d centerPt = arcTag->center; + centerPt.y = -centerPt.y; + Base::Vector3d startPt = arcTag->startPnt; + startPt.y = -startPt.y; + Base::Vector3d endPt = arcTag->endPnt; + endPt.y = -endPt.y; + std::stringstream startName, endName, formatSpec; + double scale = objFeat->getScale(); + std::string startVertTag = objFeat->addCosmeticVertex(startPt / scale); + int startVertNumber = objFeat->add1CVToGV(startVertTag); + startName << "Vertex" << startVertNumber; + std::string endVertTag = objFeat->addCosmeticVertex(endPt / scale); + int endVertNumber = objFeat->add1CVToGV(endVertTag); + endName << "Vertex" << endVertNumber; + TechDraw::DrawViewDimension* dim; + dim = _createLinDimension(this, objFeat, startName.str(), endName.str(), "Distance"); + TechDraw::pointPair pp = dim->getLinearPoints(); + Base::Vector3d mid = (pp.first + pp.second) / 2.0; + dim->X.setValue(mid.x); + dim->Y.setValue(-mid.y); + Base::Vector3d radVec1 = startPt - centerPt; + Base::Vector3d radVec2 = endPt - centerPt; + float alpha = acos((radVec1 * radVec2) / (radVec1.Length() * radVec2.Length())); + float arcLength = alpha * radius / scale; + dim->Arbitrary.setValue(true); + formatSpec << "◠ " << arcLength; + dim->FormatSpec.setValue(formatSpec.str()); + objFeat->refreshCEGeoms(); + objFeat->requestPaint(); + getSelection().clearSelection(); } Gui::Command::commitCommand(); } @@ -2243,15 +2243,14 @@ namespace TechDrawGui { std::vector& selection, std::string message) { // check selection of getSelectionEx() - bool OK = true; selection = cmd->getSelection().getSelectionEx(); if (selection.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr(message.c_str()), QObject::tr("Selection is empty")); - OK = false; + return false; } - return OK; + return true; } bool _checkSelAndObj(Gui::Command* cmd, @@ -2259,18 +2258,16 @@ namespace TechDrawGui { TechDraw::DrawViewPart*& objFeat, std::string message) { // check selection of getSelectionEx() and selection[0].getObject() - bool OK = true; - OK = _checkSelection(cmd, selection, message); - if (OK) { + if (_checkSelection(cmd, selection, message)) { objFeat = dynamic_cast(selection[0].getObject()); if (objFeat == nullptr) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr(message.c_str()), QObject::tr("No object selected")); - OK = false; + return false; } } - return OK; + return true; } TechDraw::DrawViewDimension* _createLinDimension(Gui::Command* cmd, diff --git a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp index d7cf2c4814..1a77370f18 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp @@ -1901,24 +1901,23 @@ namespace TechDrawGui { TechDraw::DrawViewPart*& objFeat, std::string message) { // check selection of getSelectionEx() and selection[0].getObject() - bool OK = true; selection = cmd->getSelection().getSelectionEx(); if (selection.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr(message.c_str()), QObject::tr("Selection is empty")); - OK = false; + return false; } - if (OK) { - objFeat = dynamic_cast(selection[0].getObject()); - if (objFeat == nullptr) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr(message.c_str()), - QObject::tr("No object selected")); - OK = false; - } + + objFeat = dynamic_cast(selection[0].getObject()); + if (objFeat == nullptr) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr(message.c_str()), + QObject::tr("No object selected")); + return false; } - return OK; + + return true; } std::vector _getVertexPoints(std::vector SubNames, TechDraw::DrawViewPart* objFeat) { @@ -1964,17 +1963,16 @@ namespace TechDrawGui { int GeoId = TechDraw::DrawUtil::getIndexFromName(Name); TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId); std::string GeoType = TechDraw::DrawUtil::getGeomTypeFromName(Name); - if (GeoType == "Edge") { - if (geom->geomType == TechDraw::CIRCLE) { - TechDraw::CirclePtr cgen = std::static_pointer_cast (geom); - Base::Vector3d center = cgen->center; - float radius = cgen->radius; - TechDraw::BaseGeomPtr threadArc = - std::make_shared(center / scale, radius * factor / scale, 255.0, 165.0); - std::string arcTag = objFeat->addCosmeticEdge(threadArc); - TechDraw::CosmeticEdge* arc = objFeat->getCosmeticEdge(arcTag); - _setLineAttributes(arc); - } + + if (GeoType == "Edge" && geom->geomType == TechDraw::CIRCLE) { + TechDraw::CirclePtr cgen = std::static_pointer_cast (geom); + Base::Vector3d center = cgen->center; + float radius = cgen->radius; + TechDraw::BaseGeomPtr threadArc = + std::make_shared(center / scale, radius * factor / scale, 255.0, 165.0); + std::string arcTag = objFeat->addCosmeticEdge(threadArc); + TechDraw::CosmeticEdge* arc = objFeat->getCosmeticEdge(arcTag); + _setLineAttributes(arc); } } @@ -1988,39 +1986,38 @@ namespace TechDrawGui { int GeoId1 = TechDraw::DrawUtil::getIndexFromName(SubNames[1]); TechDraw::BaseGeomPtr geom0 = objFeat->getGeomByIndex(GeoId0); TechDraw::BaseGeomPtr geom1 = objFeat->getGeomByIndex(GeoId1); - if ((geom0->geomType == TechDraw::GENERIC) && (geom1->geomType == TechDraw::GENERIC)) { - TechDraw::GenericPtr line0 = std::static_pointer_cast (geom0); - TechDraw::GenericPtr line1 = std::static_pointer_cast (geom1); - Base::Vector3d start0 = line0->points.at(0); - Base::Vector3d end0 = line0->points.at(1); - Base::Vector3d start1 = line1->points.at(0); - Base::Vector3d end1 = line1->points.at(1); - if (DrawUtil::circulation(start0, end0, start1) != DrawUtil::circulation(end0, end1, start1)) { - Base::Vector3d help1 = start1; - Base::Vector3d help2 = end1; - start1 = help2; - end1 = help1; - } - start0.y = -start0.y; - end0.y = -end0.y; - start1.y = -start1.y; - end1.y = -end1.y; - float kernelDiam = (start1 - start0).Length(); - float kernelFactor = (kernelDiam * factor - kernelDiam) / 2; - Base::Vector3d delta = (start1 - start0).Normalize() * kernelFactor; - std::string line0Tag = objFeat->addCosmeticEdge((start0 - delta) / scale, (end0 - delta) / scale); - std::string line1Tag = objFeat->addCosmeticEdge((start1 + delta) / scale, (end1 + delta) / scale); - TechDraw::CosmeticEdge* cosTag0 = objFeat->getCosmeticEdge(line0Tag); - TechDraw::CosmeticEdge* cosTag1 = objFeat->getCosmeticEdge(line1Tag); - _setLineAttributes(cosTag0); - _setLineAttributes(cosTag1); - } - else { + if (geom0->geomType != TechDraw::GENERIC || geom1->geomType != TechDraw::GENERIC) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("TechDraw Thread Hole Side"), QObject::tr("Please select two straight lines")); return; } + + TechDraw::GenericPtr line0 = std::static_pointer_cast (geom0); + TechDraw::GenericPtr line1 = std::static_pointer_cast (geom1); + Base::Vector3d start0 = line0->points.at(0); + Base::Vector3d end0 = line0->points.at(1); + Base::Vector3d start1 = line1->points.at(0); + Base::Vector3d end1 = line1->points.at(1); + if (DrawUtil::circulation(start0, end0, start1) != DrawUtil::circulation(end0, end1, start1)) { + Base::Vector3d help1 = start1; + Base::Vector3d help2 = end1; + start1 = help2; + end1 = help1; + } + start0.y = -start0.y; + end0.y = -end0.y; + start1.y = -start1.y; + end1.y = -end1.y; + float kernelDiam = (start1 - start0).Length(); + float kernelFactor = (kernelDiam * factor - kernelDiam) / 2; + Base::Vector3d delta = (start1 - start0).Normalize() * kernelFactor; + std::string line0Tag = objFeat->addCosmeticEdge((start0 - delta) / scale, (end0 - delta) / scale); + std::string line1Tag = objFeat->addCosmeticEdge((start1 + delta) / scale, (end1 + delta) / scale); + TechDraw::CosmeticEdge* cosTag0 = objFeat->getCosmeticEdge(line0Tag); + TechDraw::CosmeticEdge* cosTag1 = objFeat->getCosmeticEdge(line1Tag); + _setLineAttributes(cosTag0); + _setLineAttributes(cosTag1); } }