From 08ba104d87d5a689309fe7db4ffc37ce51262e25 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Thu, 27 Aug 2020 09:01:40 -0400 Subject: [PATCH] [TD]remove restrictions on Edge-Edge Dims --- src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 318 ++++++++------------- 1 file changed, 126 insertions(+), 192 deletions(-) diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp index e4729dc775b2..2d1dcdd56186 100644 --- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -131,103 +131,103 @@ CmdTechDrawDimension::CmdTechDrawDimension() void CmdTechDrawDimension::activated(int iMsg) { Q_UNUSED(iMsg); - bool result = _checkSelection(this,2); - if (!result) - return; - result = _checkDrawViewPart(this); - if (!result) - return; - -//do we still need to pick DVPs out of selection? or should we complain about junk? - std::vector selection = getSelection().getSelectionEx(); - TechDraw::DrawViewPart* objFeat = 0; - std::vector SubNames; - std::vector::iterator itSel = selection.begin(); - for (; itSel != selection.end(); itSel++) { - if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { - objFeat = static_cast ((*itSel).getObject()); - SubNames = (*itSel).getSubNames(); - } - } - TechDraw::DrawPage* page = objFeat->findParentPage(); - std::string PageName = page->getNameInDocument(); - - TechDraw::DrawViewDimension *dim = 0; - std::string FeatName = getUniqueObjectName("Dimension"); - std::string dimType; - - std::vector objs; - std::vector subs; - - int edgeType = _isValidSingleEdge(this); - - if (edgeType) { - if (edgeType < isCircle) { - dimType = "Distance"; - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - } else if (edgeType == isCircle) { - dimType = "Radius"; - } else { - dimType = "Radius"; - } - } else if (_isValidVertexes(this)) { - dimType = "Distance"; - objs.push_back(objFeat); - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - } else if (_isValidEdgeToEdge(this)) { - int edgeCase = _isValidEdgeToEdge(this); - objs.push_back(objFeat); - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - switch (edgeCase) { - case isHorizontal: - dimType = "DistanceX"; - break; - case isVertical: - dimType = "DistanceY"; - break; - case isDiagonal: - dimType = "Distance"; - break; - case isAngle: - dimType = "Angle"; - default: - break; - } - } else if (_isValidVertexToEdge(this)) { - dimType = "Distance"; - objs.push_back(objFeat); - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), - QObject::tr("Can not make a Dimension from this selection")); - return; - } +// bool result = _checkSelection(this,2); +// if (!result) +// return; +// result = _checkDrawViewPart(this); +// if (!result) +// return; + +////do we still need to pick DVPs out of selection? or should we complain about junk? +// std::vector selection = getSelection().getSelectionEx(); +// TechDraw::DrawViewPart* objFeat = 0; +// std::vector SubNames; +// std::vector::iterator itSel = selection.begin(); +// for (; itSel != selection.end(); itSel++) { +// if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { +// objFeat = static_cast ((*itSel).getObject()); +// SubNames = (*itSel).getSubNames(); +// } +// } +// TechDraw::DrawPage* page = objFeat->findParentPage(); +// std::string PageName = page->getNameInDocument(); + +// TechDraw::DrawViewDimension *dim = 0; +// std::string FeatName = getUniqueObjectName("Dimension"); +// std::string dimType; + +// std::vector objs; +// std::vector subs; + +// int edgeType = _isValidSingleEdge(this); + +// if (edgeType) { +// if (edgeType < isCircle) { +// dimType = "Distance"; +// objs.push_back(objFeat); +// subs.push_back(SubNames[0]); +// } else if (edgeType == isCircle) { +// dimType = "Radius"; +// } else { +// dimType = "Radius"; +// } +// } else if (_isValidVertexes(this)) { +// dimType = "Distance"; +// objs.push_back(objFeat); +// objs.push_back(objFeat); +// subs.push_back(SubNames[0]); +// subs.push_back(SubNames[1]); +// } else if (_isValidEdgeToEdge(this)) { +// int edgeCase = _isValidEdgeToEdge(this); +// objs.push_back(objFeat); +// objs.push_back(objFeat); +// subs.push_back(SubNames[0]); +// subs.push_back(SubNames[1]); +// switch (edgeCase) { +// case isHorizontal: +// dimType = "DistanceX"; +// break; +// case isVertical: +// dimType = "DistanceY"; +// break; +// case isDiagonal: +// dimType = "Distance"; +// break; +// case isAngle: +// dimType = "Angle"; +// default: +// break; +// } +// } else if (_isValidVertexToEdge(this)) { +// dimType = "Distance"; +// objs.push_back(objFeat); +// objs.push_back(objFeat); +// subs.push_back(SubNames[0]); +// subs.push_back(SubNames[1]); +// } else { +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), +// QObject::tr("Can not make a Dimension from this selection")); +// return; +// } - openCommand("Create Dimension"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() - ,dimType.c_str()); +// openCommand("Create Dimension"); +// doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str()); +// doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str() +// ,dimType.c_str()); - dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); - if (!dim) { - throw Base::TypeError("CmdTechDrawNewDimension - dim not found\n"); - } - dim->References2D.setValues(objs, subs); +// dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); +// if (!dim) { +// throw Base::TypeError("CmdTechDrawNewDimension - dim not found\n"); +// } +// dim->References2D.setValues(objs, subs); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - commitCommand(); - dim->recomputeFeature(); +// doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); +// commitCommand(); +// dim->recomputeFeature(); - //Horrible hack to force Tree update - double x = objFeat->X.getValue(); - objFeat->X.setValue(x); +// //Horrible hack to force Tree update +// double x = objFeat->X.getValue(); +// objFeat->X.setValue(x); } bool CmdTechDrawDimension::isActive(void) @@ -529,34 +529,21 @@ void CmdTechDrawLengthDimension::activated(int iMsg) std::vector objs; std::vector subs; - int edgeType = _isValidSingleEdge(this); - if ((edgeType == isHorizontal) || - (edgeType == isVertical) || - (edgeType == isDiagonal)) { - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - } else if (_isValidVertexes(this)) { - objs.push_back(objFeat); - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - } else if ((_isValidEdgeToEdge(this) == isHorizontal) || - (_isValidEdgeToEdge(this) == isVertical) || - (_isValidEdgeToEdge(this) == isDiagonal) || - (_isValidEdgeToEdge(this) == isAngle)) { - edgeType = _isValidEdgeToEdge(this); - objs.push_back(objFeat); + if (_isValidSingleEdge(this) ) { objs.push_back(objFeat); subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - } else if (_isValidVertexToEdge(this)) { + } else if ( _isValidVertexes(this) || + (_isValidEdgeToEdge(this) == isVertical) || + (_isValidEdgeToEdge(this) == isHorizontal) || + (_isValidEdgeToEdge(this) == isDiagonal) || + (_isValidVertexToEdge(this)) ) { objs.push_back(objFeat); objs.push_back(objFeat); subs.push_back(SubNames[0]); subs.push_back(SubNames[1]); } else { std::stringstream edgeMsg; - edgeMsg << "Need 2 Vertexes, 1 straight Edge, 1 Vertex/1 straight edge or 2 straight Edges for length Dimension (edge type: " << _edgeTypeToText(edgeType) << ")"; + edgeMsg << "Need 2 Vertexes, 2 Edges or 1 Vertex and 1 Edge for Distance Dimension"; QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), QObject::tr(edgeMsg.str().c_str())); return; @@ -643,33 +630,21 @@ void CmdTechDrawHorizontalDimension::activated(int iMsg) std::vector objs; std::vector subs; - int edgeType = _isValidSingleEdge(this); - if ((edgeType == isHorizontal) || - (edgeType == isDiagonal)) { + if (_isValidSingleEdge(this) ) { objs.push_back(objFeat); subs.push_back(SubNames[0]); - } else if (_isValidVertexes(this)) { - objs.push_back(objFeat); - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - } else if ((_isValidEdgeToEdge(this) == isHorizontal) || - (_isValidEdgeToEdge(this) == isVertical) || - (_isValidEdgeToEdge(this) == isDiagonal) || - (_isValidEdgeToEdge(this) == isAngle)) { - edgeType = _isValidEdgeToEdge(this); - objs.push_back(objFeat); - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - } else if (_isValidVertexToEdge(this)) { + } else if ( _isValidVertexes(this) || + (_isValidEdgeToEdge(this) == isVertical) || + (_isValidEdgeToEdge(this) == isHorizontal) || + (_isValidEdgeToEdge(this) == isDiagonal) || + (_isValidVertexToEdge(this)) ) { objs.push_back(objFeat); objs.push_back(objFeat); subs.push_back(SubNames[0]); subs.push_back(SubNames[1]); } else { std::stringstream edgeMsg; - edgeMsg << "Need 2 Vertexes, 1 straight Edge, 1 Vertex/1 straight edge or 2 straight Edges for Horizontal Dimension (edge type: " << _edgeTypeToText(edgeType) << ")"; + edgeMsg << "Need 2 Vertexes, 2 Edges or 1 Vertex and 1 Edge for Horizontal Dimension"; QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), QObject::tr(edgeMsg.str().c_str())); return; @@ -757,33 +732,21 @@ void CmdTechDrawVerticalDimension::activated(int iMsg) std::vector objs; std::vector subs; - int edgeType = _isValidSingleEdge(this); - if ((edgeType == isVertical) || - (edgeType == isDiagonal)) { - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - } else if (_isValidVertexes(this)) { - objs.push_back(objFeat); + if (_isValidSingleEdge(this) ) { objs.push_back(objFeat); subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - } else if ((_isValidEdgeToEdge(this) == isVertical) || - (_isValidEdgeToEdge(this) == isHorizontal) || - (_isValidEdgeToEdge(this) == isDiagonal) || - (_isValidEdgeToEdge(this) == isAngle)) { - edgeType = _isValidEdgeToEdge(this); - objs.push_back(objFeat); - objs.push_back(objFeat); - subs.push_back(SubNames[0]); - subs.push_back(SubNames[1]); - } else if (_isValidVertexToEdge(this)) { + } else if ( _isValidVertexes(this) || + (_isValidEdgeToEdge(this) == isVertical) || + (_isValidEdgeToEdge(this) == isHorizontal) || + (_isValidEdgeToEdge(this) == isDiagonal) || + (_isValidVertexToEdge(this)) ) { objs.push_back(objFeat); objs.push_back(objFeat); subs.push_back(SubNames[0]); subs.push_back(SubNames[1]); } else { std::stringstream edgeMsg; - edgeMsg << "Need 2 Vertexes, 1 straight Edge, 1 Vertex/1 straight edge or 2 straight Edges for Horizontal Dimension (edge type: " << _edgeTypeToText(edgeType) << ")"; + edgeMsg << "Need 2 Vertexes, 2 Edges or 1 Vertex and 1 Edge for Vertical Dimension"; QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), QObject::tr(edgeMsg.str().c_str())); return; @@ -1590,7 +1553,6 @@ bool _isValidVertexes(Gui::Command* cmd, int count) { //! verify that the Selection contains valid geometries for an Edge to Edge Dimension int _isValidEdgeToEdge(Gui::Command* cmd) { -//TODO: can the edges be in 2 different features?? std::vector selection = cmd->getSelection().getSelectionEx(); auto objFeat0( dynamic_cast(selection[0].getObject()) ); @@ -1602,14 +1564,15 @@ int _isValidEdgeToEdge(Gui::Command* cmd) { 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" + 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::BaseGeom* geom0 = objFeat0->getGeomByIndex(GeoId0); TechDraw::BaseGeom* geom1 = objFeat0->getGeomByIndex(GeoId1); - if ((!geom0) || (!geom1)) { + + if ((!geom0) || (!geom1)) { // missing gometry Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",GeoId0,GeoId1); return isInvalid; } @@ -1620,26 +1583,21 @@ int _isValidEdgeToEdge(Gui::Command* cmd) { TechDraw::Generic *gen1 = static_cast(geom1); if(gen0->points.size() > 2 || gen1->points.size() > 2) { //the edge is a polyline - return isInvalid; + 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; - } - if(fabs(line0.x) < FLT_EPSILON && fabs(line1.x) < FLT_EPSILON) { //both horizontal - edgeType = isHorizontal; - } else if(fabs(line0.y) < FLT_EPSILON && fabs(line1.y) < FLT_EPSILON) { //both vertical - edgeType = isVertical; + if (xprod > FLT_EPSILON) { //edges are not parallel + return isAngle; //angle or distance } else { - edgeType = isDiagonal; + return isDiagonal; //distance || line } } else { - return isInvalid; + return isDiagonal; //two edges, not both straight lines } - } - } + } //edges + } // 2 sub objects return edgeType; } @@ -1648,7 +1606,6 @@ bool _isValidVertexToEdge(Gui::Command* cmd) { bool result = false; std::vector selection = cmd->getSelection().getSelectionEx(); TechDraw::DrawViewPart* objFeat0 = static_cast(selection[0].getObject()); - //TechDraw::DrawViewPart* objFeat1 = static_castt(selection[1].getObject()); const std::vector SubNames = selection[0].getSubNames(); if(SubNames.size() == 2) { //there are 2 int eId,vId; @@ -1671,9 +1628,6 @@ bool _isValidVertexToEdge(Gui::Command* cmd) { Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",eId,vId); return false; } - if (e->geomType != TechDraw::GENERIC) { //only vertex-line for now. - return false; - } result = true; } return result; @@ -1719,24 +1673,4 @@ char* _edgeTypeToText(int e) return result; } -//bool _checkActive(Gui::Command* cmd, Base::Type classType, bool needSubs) -//{ -// //need a page, a selected classType and [a subelement] -// bool active = false; -// if (cmd->hasActiveDocument()) { -// auto drawPageType( TechDraw::DrawPage::getClassTypeId() ); -// auto selPages = cmd->getDocument()->getObjectsOfType(drawPageType); -// if (!selPages.empty()) { -// std::vector selection = cmd->getSelection().getSelectionEx(); -// for (auto& s:selection) { -// if (s.getObject()->isDerivedFrom(classType)) { -// if (needSubs && !(s.getSubNames().empty())) { -// active = true; -// break; -// } -// } -// } -// } -// } -// return active; -//} +