From 919d17a50a62bec2ff77fa80fa7d9d3a9dd38591 Mon Sep 17 00:00:00 2001 From: logari81 Date: Mon, 2 Jan 2012 21:25:03 +0000 Subject: [PATCH 1/2] + improve handling of external geometries and sketch axes in constraints + tidy up and avoid code duplication git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5380 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 336 ++++++++++---------- 1 file changed, 170 insertions(+), 166 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index f6f77b7e6..8a00a501e 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -68,7 +68,9 @@ void updateDatumDistance(Gui::Document *doc, Constraint *constr) bool checkBothExternal(int GeoId1, int GeoId2) { - if (GeoId1 < 0 && GeoId2 < 0) { + if (GeoId1 == Constraint::GeoUndef || GeoId2 == Constraint::GeoUndef) + return false; + else if (GeoId1 < 0 && GeoId2 < 0) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Cannot add a constraint between two external geometries!")); return true; @@ -77,6 +79,23 @@ bool checkBothExternal(int GeoId1, int GeoId2) return false; } +void getIdsFromName(const std::string &name, int &GeoId, int &VtId) +{ + GeoId = Constraint::GeoUndef; + VtId = -1; + if (name.size() > 4 && name.substr(0,4) == "Edge") + GeoId = std::atoi(name.substr(4,4000).c_str()); + else if (name.size() == 6 && name.substr(0,6) == "H_Axis") + GeoId = -1; + else if (name.size() == 6 && name.substr(0,6) == "V_Axis") + GeoId = -2; + else if (name.size() > 12 && name.substr(0,12) == "ExternalEdge") + GeoId = -3 - std::atoi(name.substr(12,4000).c_str()); + else if (name.size() > 6 && name.substr(0,6) == "Vertex") + VtId = std::atoi(name.substr(6,4000).c_str()); +} + + namespace SketcherGui { struct SketchSelection{ @@ -202,9 +221,9 @@ void CmdSketcherConstrainHorizontal::activated(int iMsg) for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { // only handle edges if (it->size() > 4 && it->substr(0,4) == "Edge") { - int index=std::atoi(it->substr(4,4000).c_str()); + int GeoId=std::atoi(it->substr(4,4000).c_str()); - const Part::Geometry *geo = Obj->getGeometry(index); + const Part::Geometry *geo = Obj->getGeometry(GeoId); if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Impossible constraint"), QObject::tr("The selected edge is not a line segment")); @@ -214,18 +233,18 @@ void CmdSketcherConstrainHorizontal::activated(int iMsg) // check if the edge has already a Horizontal or Vertical constraint for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); it != vals.end(); ++it) { - if ((*it)->Type == Sketcher::Horizontal && (*it)->First == index){ + if ((*it)->Type == Sketcher::Horizontal && (*it)->First == GeoId){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Double constraint"), QObject::tr("The selected edge has already a horizontal constraint!")); return; } - if ((*it)->Type == Sketcher::Vertical && (*it)->First == index) { + if ((*it)->Type == Sketcher::Vertical && (*it)->First == GeoId) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Impossible constraint"), QObject::tr("The selected edge has already a vertical constraint!")); return; } } - ids.push_back(index); + ids.push_back(GeoId); } } @@ -545,33 +564,47 @@ void CmdSketcherConstrainDistance::activated(int iMsg) int GeoId1=Constraint::GeoUndef, VtId1=-1, GeoId2=Constraint::GeoUndef, VtId2=-1; if (SubNames.size() >= 1) { - if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") - GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str()); - else if (SubNames[0].size() > 12 && SubNames[0].substr(0,12) == "ExternalEdge") - GeoId1 = -3 - std::atoi(SubNames[0].substr(12,4000).c_str()); - else if (SubNames[0].size() > 6 && SubNames[0].substr(0,6) == "Vertex") - VtId1 = std::atoi(SubNames[0].substr(6,4000).c_str()); - } - if (SubNames.size() == 2) { - if (SubNames[1].size() > 4 && SubNames[1].substr(0,4) == "Edge") - GeoId2 = std::atoi(SubNames[1].substr(4,4000).c_str()); - else if (SubNames[1].size() > 12 && SubNames[1].substr(0,12) == "ExternalEdge") - GeoId2 = -3 - std::atoi(SubNames[1].substr(12,4000).c_str()); - else if (SubNames[1].size() > 6 && SubNames[1].substr(0,6) == "Vertex") - VtId2 = std::atoi(SubNames[1].substr(6,4000).c_str()); + getIdsFromName(SubNames[0], GeoId1, VtId1); + if (SubNames.size() == 2) + getIdsFromName(SubNames[1], GeoId2, VtId2); } - if (VtId1 >= 0 && VtId2 >= 0) { // point to point distance + if (checkBothExternal(GeoId1, GeoId2)) + return; + else if ((GeoId2 == -2 || GeoId2 == -1) && GeoId1 == Constraint::GeoUndef) { + std::swap(GeoId1,GeoId2); + std::swap(VtId1,VtId2); + } + + if ((GeoId1 == -2 || GeoId1 == -1 || VtId1 >= 0) && VtId2 >= 0) { // point to point distance Sketcher::PointPos PosId1,PosId2; - Obj->getGeoVertexIndex(VtId1,GeoId1,PosId1); + if (GeoId1 == -2 || GeoId1 == -1) + PosId1 = Sketcher::start; + else + Obj->getGeoVertexIndex(VtId1,GeoId1,PosId1); + Obj->getGeoVertexIndex(VtId2,GeoId2,PosId2); Base::Vector3d pnt1 = Obj->getPoint(GeoId1,PosId1); Base::Vector3d pnt2 = Obj->getPoint(GeoId2,PosId2); - openCommand("add point to point distance constraint"); - Gui::Command::doCommand( - Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%d,%f)) ", - selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,(pnt2-pnt1).Length()); + if (GeoId1 == -1) { + openCommand("add distance from horizontal axis constraint"); + Gui::Command::doCommand( + Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%d,%d,%f)) ", + selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,pnt2.y); + } + else if (GeoId1 == -2) { + openCommand("add distance from vertical axis constraint"); + Gui::Command::doCommand( + Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%d,%d,%f)) ", + selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,pnt2.x); + } + else { + openCommand("add point to point distance constraint"); + Gui::Command::doCommand( + Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Distance',%d,%d,%d,%d,%f)) ", + selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,(pnt2-pnt1).Length()); + } commitCommand(); // Get the latest constraint @@ -700,24 +733,15 @@ void CmdSketcherConstrainPointOnObject::activated(int iMsg) } int GeoId1=Constraint::GeoUndef, VtId1=-1, GeoId2=Constraint::GeoUndef, VtId2=-1; - if (SubNames.size() >= 1) { - if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") - GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str()); - else if (SubNames[0].size() > 12 && SubNames[0].substr(0,12) == "ExternalEdge") - GeoId1 = -3 - std::atoi(SubNames[0].substr(12,4000).c_str()); - else if (SubNames[0].size() > 6 && SubNames[0].substr(0,6) == "Vertex") - VtId1 = std::atoi(SubNames[0].substr(6,4000).c_str()); - } - if (SubNames.size() == 2) { - if (SubNames[1].size() > 4 && SubNames[1].substr(0,4) == "Edge") - GeoId2 = std::atoi(SubNames[1].substr(4,4000).c_str()); - else if (SubNames[1].size() > 12 && SubNames[1].substr(0,12) == "ExternalEdge") - GeoId2 = -3 - std::atoi(SubNames[1].substr(12,4000).c_str()); - else if (SubNames[1].size() > 6 && SubNames[1].substr(0,6) == "Vertex") - VtId2 = std::atoi(SubNames[1].substr(6,4000).c_str()); + getIdsFromName(SubNames[0], GeoId1, VtId1); + if (SubNames.size() == 2) + getIdsFromName(SubNames[1], GeoId2, VtId2); } + if (checkBothExternal(GeoId1, GeoId2)) + return; + if ((VtId1 >= 0 && GeoId2 != Constraint::GeoUndef) || (VtId2 >= 0 && GeoId1 != Constraint::GeoUndef)) { if (VtId2 >= 0 && GeoId1 != Constraint::GeoUndef) { @@ -799,22 +823,19 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg) int GeoId1=Constraint::GeoUndef, VtId1=-1, GeoId2=Constraint::GeoUndef, VtId2=-1; if (SubNames.size() >= 1) { - if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") - GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str()); - else if (SubNames[0].size() == 6 && SubNames[0].substr(0,6) == "V_Axis") - GeoId1 = -2; - else if (SubNames[0].size() > 6 && SubNames[0].substr(0,6) == "Vertex") - VtId1 = std::atoi(SubNames[0].substr(6,4000).c_str()); + getIdsFromName(SubNames[0], GeoId1, VtId1); + if (GeoId1 == -1) // reject horizontal axis from selection + GeoId1 = Constraint::GeoUndef; + if (SubNames.size() == 2) { + getIdsFromName(SubNames[1], GeoId2, VtId2); + if (GeoId2 == -1) // reject horizontal axis from selection + GeoId2 = Constraint::GeoUndef; + } } - if (SubNames.size() == 2) { - if (SubNames[1].size() > 4 && SubNames[1].substr(0,4) == "Edge") - GeoId2 = std::atoi(SubNames[1].substr(4,4000).c_str()); - else if (SubNames[1].size() == 6 && SubNames[0].substr(0,6) == "V_Axis") - GeoId2 = -2; - else if (SubNames[1].size() > 6 && SubNames[1].substr(0,6) == "Vertex") - VtId2 = std::atoi(SubNames[1].substr(6,4000).c_str()); - } - if (GeoId2 == -2 && GeoId1 == Constraint::GeoUndef) { + + if (checkBothExternal(GeoId1, GeoId2)) + return; + else if (GeoId2 == -2 && GeoId1 == Constraint::GeoUndef) { std::swap(GeoId1,GeoId2); std::swap(VtId1,VtId2); } @@ -952,22 +973,19 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg) int GeoId1=Constraint::GeoUndef, VtId1=-1, GeoId2=Constraint::GeoUndef, VtId2=-1; if (SubNames.size() >= 1) { - if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") - GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str()); - else if (SubNames[0].size() == 6 && SubNames[0].substr(0,6) == "H_Axis") - GeoId1 = -1; - else if (SubNames[0].size() > 6 && SubNames[0].substr(0,6) == "Vertex") - VtId1 = std::atoi(SubNames[0].substr(6,4000).c_str()); + getIdsFromName(SubNames[0], GeoId1, VtId1); + if (GeoId1 == -2) // reject vertical axis from selection + GeoId1 = Constraint::GeoUndef; + if (SubNames.size() == 2) { + getIdsFromName(SubNames[1], GeoId2, VtId2); + if (GeoId2 == -2) // reject vertical axis from selection + GeoId2 = Constraint::GeoUndef; + } } - if (SubNames.size() == 2) { - if (SubNames[1].size() > 4 && SubNames[1].substr(0,4) == "Edge") - GeoId2 = std::atoi(SubNames[1].substr(4,4000).c_str()); - else if (SubNames[1].size() == 6 && SubNames[0].substr(0,6) == "H_Axis") - GeoId2 = -1; - else if (SubNames[1].size() > 6 && SubNames[1].substr(0,6) == "Vertex") - VtId2 = std::atoi(SubNames[1].substr(6,4000).c_str()); - } - if (GeoId2 == -1 && GeoId1 == Constraint::GeoUndef) { + + if (checkBothExternal(GeoId1, GeoId2)) + return; + else if (GeoId2 == -1 && GeoId1 == Constraint::GeoUndef) { std::swap(GeoId1,GeoId2); std::swap(VtId1,VtId2); } @@ -1106,27 +1124,33 @@ void CmdSketcherConstrainParallel::activated(int iMsg) } std::vector ids; + bool hasAlreadyExternal=false; for (std::vector::const_iterator it=SubNames.begin();it!=SubNames.end();++it) { - int index; - std::string subName = *it; - if (subName.size() > 4 && subName.substr(0,4) == "Edge") - index = std::atoi(subName.substr(4,4000).c_str()); - else if (subName.size() > 12 && subName.substr(0,12) == "ExternalEdge") - index = -3 - std::atoi(subName.substr(12,4000).c_str()); - else { + int GeoId, VtId; + getIdsFromName(*it, GeoId, VtId); + + if (GeoId == Constraint::GeoUndef) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select a valid line")); return; } + else if (GeoId < 0) { + if (hasAlreadyExternal) { + checkBothExternal(-1,-2); // just for printing the error message + return; + } + else + hasAlreadyExternal = true; + } // Check that the curve is a line segment - const Part::Geometry *geo = Obj->getGeometry(index); + const Part::Geometry *geo = Obj->getGeometry(GeoId); if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("The selected edge is not a valid line")); return; } - ids.push_back(index); + ids.push_back(GeoId); } // undo command open @@ -1188,29 +1212,17 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) return; } - int GeoId1,GeoId2; - if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") - GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str()); - else if (SubNames[0].size() > 12 && SubNames[0].substr(0,12) == "ExternalEdge") - GeoId1 = -3 - std::atoi(SubNames[0].substr(12,4000).c_str()); - else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly two lines from the sketch.")); - return; - } - - if (SubNames[1].size() > 4 && SubNames[1].substr(0,4) == "Edge") - GeoId2 = std::atoi(SubNames[1].substr(4,4000).c_str()); - else if (SubNames[1].size() > 12 && SubNames[1].substr(0,12) == "ExternalEdge") - GeoId2 = -3 - std::atoi(SubNames[1].substr(12,4000).c_str()); - else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly two lines from the sketch.")); - return; - } + int GeoId1, VtId1, GeoId2, VtId2; + getIdsFromName(SubNames[0], GeoId1, VtId1); + getIdsFromName(SubNames[1], GeoId2, VtId2); if (checkBothExternal(GeoId1, GeoId2)) return; + else if (GeoId1 == Constraint::GeoUndef || GeoId2 == Constraint::GeoUndef) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly two lines from the sketch.")); + return; + } const Part::Geometry *geo1 = Obj->getGeometry(GeoId1); const Part::Geometry *geo2 = Obj->getGeometry(GeoId2); @@ -1281,20 +1293,9 @@ void CmdSketcherConstrainTangent::activated(int iMsg) return; } - int GeoId1=Constraint::GeoUndef, VtId1=-1, GeoId2=Constraint::GeoUndef, VtId2=-1; - if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") - GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str()); - else if (SubNames[0].size() > 12 && SubNames[0].substr(0,12) == "ExternalEdge") - GeoId1 = -3 - std::atoi(SubNames[0].substr(12,4000).c_str()); - else if (SubNames[0].size() > 6 && SubNames[0].substr(0,6) == "Vertex") - VtId1 = std::atoi(SubNames[0].substr(6,4000).c_str()); - - if (SubNames[1].size() > 4 && SubNames[1].substr(0,4) == "Edge") - GeoId2 = std::atoi(SubNames[1].substr(4,4000).c_str()); - else if (SubNames[1].size() > 12 && SubNames[1].substr(0,12) == "ExternalEdge") - GeoId2 = -3 - std::atoi(SubNames[1].substr(12,4000).c_str()); - else if (SubNames[1].size() > 6 && SubNames[1].substr(0,6) == "Vertex") - VtId2 = std::atoi(SubNames[1].substr(6,4000).c_str()); + int GeoId1, VtId1, GeoId2, VtId2; + getIdsFromName(SubNames[0], GeoId1, VtId1); + getIdsFromName(SubNames[1], GeoId2, VtId2); Sketcher::PointPos PosId1,PosId2; if (VtId1 >= 0 && VtId2 >= 0) { // tangency at common point @@ -1475,28 +1476,24 @@ void CmdSketcherConstrainAngle::activated(int iMsg) if (SubNames.size() < 1 || SubNames.size() > 2) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one or two lines from the sketch.")); + QObject::tr("Select one or two lines from the sketch.")); return; } - int GeoId1=Constraint::GeoUndef, GeoId2=Constraint::GeoUndef; - if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") - GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str()); - else if (SubNames[0].size() > 12 && SubNames[0].substr(0,12) == "ExternalEdge") - GeoId1 = -3 - std::atoi(SubNames[0].substr(12,4000).c_str()); + int GeoId1, VtId1, GeoId2=Constraint::GeoUndef, VtId2=-1; + getIdsFromName(SubNames[0], GeoId1, VtId1); + if (SubNames.size() == 2) + getIdsFromName(SubNames[1], GeoId2, VtId2); - if (SubNames.size() == 2) { - if (SubNames[1].size() > 4 && SubNames[1].substr(0,4) == "Edge") - GeoId2 = std::atoi(SubNames[1].substr(4,4000).c_str()); - else if (SubNames[1].size() > 12 && SubNames[1].substr(0,12) == "ExternalEdge") - GeoId2 = -3 - std::atoi(SubNames[1].substr(12,4000).c_str()); + if (checkBothExternal(GeoId1, GeoId2)) + return; + else if (GeoId1 == Constraint::GeoUndef && GeoId2 != Constraint::GeoUndef) { + std::swap(GeoId1,GeoId2); + std::swap(VtId1,VtId2); } if (GeoId2 != Constraint::GeoUndef) { // line to line angle - if (checkBothExternal(GeoId1, GeoId2)) - return; - const Part::Geometry *geom1 = Obj->getGeometry(GeoId1); const Part::Geometry *geom2 = Obj->getGeometry(GeoId2); if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() && @@ -1642,38 +1639,51 @@ void CmdSketcherConstrainEqual::activated(int iMsg) } std::vector ids; - bool lineSel = false, arcSel = false, circSel = false; + bool lineSel = false, arcSel = false, circSel = false, hasAlreadyExternal = false; for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { - int index; - std::string subName = *it; - if (subName.size() > 4 && subName.substr(0,4) == "Edge") - index = std::atoi(subName.substr(4,4000).c_str()); + + int GeoId, VtId; + getIdsFromName(*it, GeoId, VtId); + + if (GeoId == Constraint::GeoUndef) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select two or more compatible edges")); + return; + } + else if (GeoId < 0) { + if (GeoId == -1 || GeoId == -2) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Sketch axes cannot be used in equality constraints")); + return; + } + else if (hasAlreadyExternal) { + checkBothExternal(-1,-2); // just for printing the error message + return; + } + else + hasAlreadyExternal = true; + } + + const Part::Geometry *geo = Obj->getGeometry(GeoId); + if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) + lineSel = true; + else if (geo->getTypeId() != Part::GeomArcOfCircle::getClassTypeId()) + arcSel = true; + else if (geo->getTypeId() != Part::GeomCircle::getClassTypeId()) + circSel = true; else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly two same geometries")); + QObject::tr("Select two or more edges of similar type")); return; } - const Part::Geometry *geo = Obj->getGeometry(index); - if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { - lineSel = true; - } else if (geo->getTypeId() != Part::GeomArcOfCircle::getClassTypeId()) { - arcSel = true; - } else if (geo->getTypeId() != Part::GeomCircle::getClassTypeId()) { - circSel = true; - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select valid geometries")); - return; - } - - ids.push_back(index); + ids.push_back(GeoId); } if (lineSel && (arcSel || circSel)) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select geometry of similar type")); + QObject::tr("Select two or more edges of similar type")); return; } @@ -1735,23 +1745,10 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) return; } - int GeoId1=Constraint::GeoUndef, VtId1=-1, - GeoId2=Constraint::GeoUndef, VtId2=-1, - GeoId3=Constraint::GeoUndef, VtId3=-1; - if (SubNames.size() >= 1) { - if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") - GeoId1 = std::atoi(SubNames[0].substr(4,4000).c_str()); - else if (SubNames[0].size() > 6 && SubNames[0].substr(0,6) == "Vertex") - VtId1 = std::atoi(SubNames[0].substr(6,4000).c_str()); - if (SubNames[1].size() > 4 && SubNames[1].substr(0,4) == "Edge") - GeoId2 = std::atoi(SubNames[1].substr(4,4000).c_str()); - else if (SubNames[1].size() > 6 && SubNames[1].substr(0,6) == "Vertex") - VtId2 = std::atoi(SubNames[1].substr(6,4000).c_str()); - if (SubNames[2].size() > 4 && SubNames[2].substr(0,4) == "Edge") - GeoId3 = std::atoi(SubNames[2].substr(4,4000).c_str()); - else if (SubNames[2].size() > 6 && SubNames[2].substr(0,6) == "Vertex") - VtId3 = std::atoi(SubNames[2].substr(6,4000).c_str()); - } + int GeoId1, VtId1, GeoId2, VtId2, GeoId3, VtId3; + getIdsFromName(SubNames[0], GeoId1, VtId1); + getIdsFromName(SubNames[1], GeoId2, VtId2); + getIdsFromName(SubNames[2], GeoId3, VtId3); if (GeoId1 != Constraint::GeoUndef && GeoId3 == Constraint::GeoUndef) { std::swap(GeoId1,GeoId3); @@ -1766,6 +1763,13 @@ void CmdSketcherConstrainSymmetric::activated(int iMsg) Sketcher::PointPos PosId1,PosId2; Obj->getGeoVertexIndex(VtId1,GeoId1,PosId1); Obj->getGeoVertexIndex(VtId2,GeoId2,PosId2); + + if ((GeoId1 < 0 && GeoId2 < 0) || (GeoId1 < 0 && GeoId3 < 0) || (GeoId2 < 0 && GeoId3 < 0)) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Cannot add a constraint between external geometries!")); + return; + } + const Part::Geometry *geom = Obj->getGeometry(GeoId3); if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { // undo command open From 908125ad9495198b81b5d61cbc5ccd3791edeb1d Mon Sep 17 00:00:00 2001 From: jriegel Date: Tue, 3 Jan 2012 09:34:20 +0100 Subject: [PATCH 2/2] Change some scripts licenses to LGPL --- src/Tools/MakeApp.py | 2 +- src/Tools/MakeNewBuildNbr.py | 2 +- src/Tools/MemoryLeaks.py | 2 +- src/Tools/SubWCRev.py | 2 +- src/Tools/WixFileTool.py | 2 +- src/Tools/pythondoc.py | 2 +- src/Tools/qembed.py | 2 +- src/Tools/updatets.py | 2 +- src/Tools/wiki2chm.py | 2 +- src/Tools/wiki2qhelp.py | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Tools/MakeApp.py b/src/Tools/MakeApp.py index 2280d599d..350b06163 100644 --- a/src/Tools/MakeApp.py +++ b/src/Tools/MakeApp.py @@ -9,7 +9,7 @@ #* This file is part of the FreeCAD CAx development system. * #* * #* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU General Public License (GPL) * +#* it under the terms of the GNU Lirary General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * diff --git a/src/Tools/MakeNewBuildNbr.py b/src/Tools/MakeNewBuildNbr.py index 2a7f420fd..9c4285b52 100644 --- a/src/Tools/MakeNewBuildNbr.py +++ b/src/Tools/MakeNewBuildNbr.py @@ -9,7 +9,7 @@ #* This file is part of the FreeCAD CAx development system. * #* * #* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU General Public License (GPL) * +#* it under the terms of the GNU Library General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * diff --git a/src/Tools/MemoryLeaks.py b/src/Tools/MemoryLeaks.py index 5646a5a9c..7eac371b2 100755 --- a/src/Tools/MemoryLeaks.py +++ b/src/Tools/MemoryLeaks.py @@ -8,7 +8,7 @@ #* This file is part of the FreeCAD CAx development system. * #* * #* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU General Public License (GPL) * +#* it under the terms of the GNU Library General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * diff --git a/src/Tools/SubWCRev.py b/src/Tools/SubWCRev.py index ec456ec30..e3c715ea3 100644 --- a/src/Tools/SubWCRev.py +++ b/src/Tools/SubWCRev.py @@ -11,7 +11,7 @@ #* This file is part of the FreeCAD CAx development system. * #* * #* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU General Public License (GPL) * +#* it under the terms of the GNU Library General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * diff --git a/src/Tools/WixFileTool.py b/src/Tools/WixFileTool.py index 14bd7b50b..9665354b4 100644 --- a/src/Tools/WixFileTool.py +++ b/src/Tools/WixFileTool.py @@ -1,5 +1,5 @@ #! python -# (c) 2005 Juergen Riegel +# (c) 2005 Juergen Riegel LGPL Usage = """ WIX file lister diff --git a/src/Tools/pythondoc.py b/src/Tools/pythondoc.py index 69bbb4546..e2e7d9746 100644 --- a/src/Tools/pythondoc.py +++ b/src/Tools/pythondoc.py @@ -7,7 +7,7 @@ #* This file is part of the FreeCAD CAx development system. * #* * #* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU General Public License (GPL) * +#* it under the terms of the GNU Library General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * diff --git a/src/Tools/qembed.py b/src/Tools/qembed.py index ef01b622c..182cb442a 100644 --- a/src/Tools/qembed.py +++ b/src/Tools/qembed.py @@ -10,7 +10,7 @@ #* This file is part of the FreeCAD CAx development system. * #* * #* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU General Public License (GPL) * +#* it under the terms of the GNU Library General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * diff --git a/src/Tools/updatets.py b/src/Tools/updatets.py index d9701ba8c..b4e28e2c0 100644 --- a/src/Tools/updatets.py +++ b/src/Tools/updatets.py @@ -1,6 +1,6 @@ #! python # -*- coding: utf-8 -*- -# (c) 2010 Werner Mayer GPL +# (c) 2010 Werner Mayer LGPL Usage = """updatets - update all .ts files found in the source directories diff --git a/src/Tools/wiki2chm.py b/src/Tools/wiki2chm.py index 4826a2d65..71f1e606d 100644 --- a/src/Tools/wiki2chm.py +++ b/src/Tools/wiki2chm.py @@ -1,6 +1,6 @@ #! python # -*- coding: utf-8 -*- -# (c) 2007 Juergen Riegel GPL +# (c) 2007 Juergen Riegel LGPL Usage = """wiki2chm - connect to a wiki and spider the docu diff --git a/src/Tools/wiki2qhelp.py b/src/Tools/wiki2qhelp.py index 9df24d341..09c47139a 100755 --- a/src/Tools/wiki2qhelp.py +++ b/src/Tools/wiki2qhelp.py @@ -5,7 +5,7 @@ #* Copyright (c) 2009 Yorik van Havre * #* * #* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU General Public License (GPL) * +#* it under the terms of the GNU Library General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. *