From fa33bcae4a0fcaea0aee4d32a5578b4f6c03509e Mon Sep 17 00:00:00 2001 From: logari81 Date: Sat, 8 Feb 2014 23:48:08 +0100 Subject: [PATCH] + fixes #0000928: Change selection numbering base in the Sketcher from 0 to 1 --- src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp | 4 +- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 20 ++--- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 14 ++-- .../Sketcher/Gui/TaskSketcherConstrains.cpp | 8 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 82 ++++++++++--------- 5 files changed, 65 insertions(+), 63 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp index 939b8e073..5f1ccc9f5 100644 --- a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp +++ b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp @@ -98,9 +98,9 @@ void CmdSketcherToggleConstruction::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()) - 1; // issue the actual commands to toggle - doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),index); + doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),GeoId); } } // finish the transaction and update diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index bc3fd208a..f82b84ae8 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -102,7 +102,7 @@ void getIdsFromName(const std::string &name, const Sketcher::SketchObject* Obj, PosId = Sketcher::none; if (name.size() > 4 && name.substr(0,4) == "Edge") { - GeoId = std::atoi(name.substr(4,4000).c_str()); + GeoId = std::atoi(name.substr(4,4000).c_str()) - 1; } else if (name.size() == 9 && name.substr(0,9) == "RootPoint") { GeoId = -1; @@ -113,9 +113,9 @@ void getIdsFromName(const std::string &name, const Sketcher::SketchObject* Obj, 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()); + GeoId = -2 - std::atoi(name.substr(12,4000).c_str()); else if (name.size() > 6 && name.substr(0,6) == "Vertex") { - int VtId = std::atoi(name.substr(6,4000).c_str()); + int VtId = std::atoi(name.substr(6,4000).c_str()) - 1; Obj->getGeoVertexIndex(VtId,GeoId,PosId); } } @@ -270,7 +270,7 @@ 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 GeoId=std::atoi(it->substr(4,4000).c_str()); + int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1; const Part::Geometry *geo = Obj->getGeometry(GeoId); if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId()) { @@ -362,9 +362,9 @@ void CmdSketcherConstrainVertical::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()) - 1; - 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")); @@ -374,18 +374,18 @@ void CmdSketcherConstrainVertical::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("Impossible 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("Double constraint"), QObject::tr("The selected edge has already a vertical constraint!")); return; } } - ids.push_back(index); + ids.push_back(GeoId); } } @@ -1447,7 +1447,7 @@ void CmdSketcherConstrainRadius::activated(int iMsg) } if (SubNames[0].size() > 4 && SubNames[0].substr(0,4) == "Edge") { - int GeoId = std::atoi(SubNames[0].substr(4,4000).c_str()); + int GeoId = std::atoi(SubNames[0].substr(4,4000).c_str()) - 1; const Part::Geometry *geom = Obj->getGeometry(GeoId); if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 1b3328c2a..fb9cd4d20 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -1582,18 +1582,18 @@ namespace SketcherGui { return false; std::string element(sSubName); if (element.substr(0,4) == "Edge") { - int index=std::atoi(element.substr(4,4000).c_str()); + int GeoId = std::atoi(element.substr(4,4000).c_str()) - 1; Sketcher::SketchObject *Sketch = static_cast(object); - const Part::Geometry *geom = Sketch->getGeometry(index); + const Part::Geometry *geom = Sketch->getGeometry(GeoId); if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId()) return true; } if (element.substr(0,6) == "Vertex") { - int index=std::atoi(element.substr(6,4000).c_str()); + int VtId = std::atoi(element.substr(6,4000).c_str()) - 1; Sketcher::SketchObject *Sketch = static_cast(object); std::vector GeoIdList; std::vector PosIdList; - Sketch->getCoincidentPoints(index, GeoIdList, PosIdList); + Sketch->getCoincidentPoints(VtId, GeoIdList, PosIdList); if (GeoIdList.size() == 2 && GeoIdList[0] >= 0 && GeoIdList[1] >= 0) { const Part::Geometry *geom1 = Sketch->getGeometry(GeoIdList[0]); const Part::Geometry *geom2 = Sketch->getGeometry(GeoIdList[1]); @@ -1734,7 +1734,7 @@ public: Mode = STATUS_SEEK_Second; // add the line to the selection std::stringstream ss; - ss << "Edge" << firstCurve; + ss << "Edge" << firstCurve + 1; Gui::Selection().addSelection(sketchgui->getSketchObject()->getDocument()->getName() ,sketchgui->getSketchObject()->getNameInDocument() ,ss.str().c_str() @@ -1829,9 +1829,9 @@ namespace SketcherGui { return false; std::string element(sSubName); if (element.substr(0,4) == "Edge") { - int index=std::atoi(element.substr(4,4000).c_str()); + int GeoId = std::atoi(element.substr(4,4000).c_str()) - 1; Sketcher::SketchObject *Sketch = static_cast(object); - const Part::Geometry *geom = Sketch->getGeometry(index); + const Part::Geometry *geom = Sketch->getGeometry(GeoId); if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId() || geom->getTypeId() == Part::GeomCircle::getClassTypeId()|| geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index bbe3fd143..8df11be9a 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -132,13 +132,13 @@ void TaskSketcherConstrains::onSelectionChanged(const Gui::SelectionChanges& msg int pos = expr.indexOf(rx); if (pos > -1) { bool ok; - int index = rx.cap(1).toInt(&ok); + int ConstrId = rx.cap(1).toInt(&ok) - 1; if (ok) { int countItems = ui->listWidgetConstraints->count(); - for (int i=0; i (ui->listWidgetConstraints->item(i)); - if (item->ConstraintNbr == index) { + if (item->ConstraintNbr == ConstrId) { ui->listWidgetConstraints->blockSignals(true); item->setSelected(select); ui->listWidgetConstraints->blockSignals(false); @@ -170,7 +170,7 @@ void TaskSketcherConstrains::on_listWidgetConstraints_itemSelectionChanged(void) QList items = ui->listWidgetConstraints->selectedItems(); for (QList::iterator it = items.begin(); it != items.end(); ++it) { std::stringstream ss; - ss << "Constraint" << static_cast(*it)->ConstraintNbr; + ss << "Constraint" << static_cast(*it)->ConstraintNbr + 1; Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), ss.str().c_str()); } this->blockConnection(block); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index d2eea6c09..dfd625495 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -511,7 +511,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe //Base::Console().Log("Select Point:%d\n",this->DragPoint); // Do selection std::stringstream ss; - ss << "Vertex" << edit->PreselectPoint; + ss << "Vertex" << edit->PreselectPoint + 1; if (Gui::Selection().isSelected(getSketchObject()->getDocument()->getName() ,getSketchObject()->getNameInDocument(),ss.str().c_str()) ) { @@ -536,9 +536,9 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe //Base::Console().Log("Select Point:%d\n",this->DragPoint); std::stringstream ss; if (edit->PreselectCurve >= 0) - ss << "Edge" << edit->PreselectCurve; + ss << "Edge" << edit->PreselectCurve + 1; else // external geometry - ss << "ExternalEdge" << -edit->PreselectCurve - 3; + ss << "ExternalEdge" << -edit->PreselectCurve - 2; // If edge already selected move from selection if (Gui::Selection().isSelected(getSketchObject()->getDocument()->getName() @@ -594,7 +594,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe if (pp) { std::stringstream ss; - ss << "Constraint" << edit->PreselectConstraint; + ss << "Constraint" << edit->PreselectConstraint + 1; // If the constraint already selected remove if (Gui::Selection().isSelected(getSketchObject()->getDocument()->getName() @@ -768,8 +768,8 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe // If the object selected is of type edge if (it->size() > 4 && it->substr(0,4) == "Edge") { // Get the index of the object selected - int index=std::atoi(it->substr(4,4000).c_str()); - if (edit->PreselectCurve == index) + int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1; + if (edit->PreselectCurve == GeoId) rightClickOnSelectedLine = true; } else { // The selection is not exclusively edges @@ -1221,18 +1221,19 @@ void ViewProviderSketch::onSelectionChanged(const Gui::SelectionChanges& msg) if (msg.pSubName) { std::string shapetype(msg.pSubName); if (shapetype.size() > 4 && shapetype.substr(0,4) == "Edge") { - int index=std::atoi(&shapetype[4]); - edit->SelCurvSet.insert(index); + int GeoId = std::atoi(&shapetype[4]) - 1; + edit->SelCurvSet.insert(GeoId); this->updateColor(); } else if (shapetype.size() > 12 && shapetype.substr(0,12) == "ExternalEdge") { - int index=std::atoi(&shapetype[12]); - edit->SelCurvSet.insert(-index-3); + int GeoId = std::atoi(&shapetype[12]) - 1; + GeoId = -GeoId - 3; + edit->SelCurvSet.insert(GeoId); this->updateColor(); } else if (shapetype.size() > 6 && shapetype.substr(0,6) == "Vertex") { - int index=std::atoi(&shapetype[6]); - addSelectPoint(index); + int VtId = std::atoi(&shapetype[6]) - 1; + addSelectPoint(VtId); this->updateColor(); } else if (shapetype == "RootPoint") { @@ -1248,8 +1249,8 @@ void ViewProviderSketch::onSelectionChanged(const Gui::SelectionChanges& msg) this->updateColor(); } else if (shapetype.size() > 10 && shapetype.substr(0,10) == "Constraint") { - int index=std::atoi(&shapetype[10]); - edit->SelConstraintSet.insert(index); + int ConstrId = std::atoi(&shapetype[10]) - 1; + edit->SelConstraintSet.insert(ConstrId); this->drawConstraintIcons(); this->updateColor(); } @@ -1265,18 +1266,19 @@ void ViewProviderSketch::onSelectionChanged(const Gui::SelectionChanges& msg) if (msg.pSubName) { std::string shapetype(msg.pSubName); if (shapetype.size() > 4 && shapetype.substr(0,4) == "Edge") { - int index=std::atoi(&shapetype[4]); - edit->SelCurvSet.erase(index); + int GeoId = std::atoi(&shapetype[4]) - 1; + edit->SelCurvSet.erase(GeoId); this->updateColor(); } else if (shapetype.size() > 12 && shapetype.substr(0,12) == "ExternalEdge") { - int index=std::atoi(&shapetype[12]); - edit->SelCurvSet.erase(-index-3); + int GeoId = std::atoi(&shapetype[12]) - 1; + GeoId = -GeoId - 3; + edit->SelCurvSet.erase(GeoId); this->updateColor(); } else if (shapetype.size() > 6 && shapetype.substr(0,6) == "Vertex") { - int index=std::atoi(&shapetype[6]); - removeSelectPoint(index); + int VtId = std::atoi(&shapetype[6]) - 1; + removeSelectPoint(VtId); this->updateColor(); } else if (shapetype == "RootPoint") { @@ -1292,8 +1294,8 @@ void ViewProviderSketch::onSelectionChanged(const Gui::SelectionChanges& msg) this->updateColor(); } else if (shapetype.size() > 10 && shapetype.substr(0,10) == "Constraint") { - int index=std::atoi(&shapetype[10]); - edit->SelConstraintSet.erase(index); + int ConstrId = std::atoi(&shapetype[10]) - 1; + edit->SelConstraintSet.erase(ConstrId); this->drawConstraintIcons(); this->updateColor(); } @@ -1377,7 +1379,7 @@ bool ViewProviderSketch::detectPreselection(const SoPickedPoint *Point, int &PtI if (PtIndex != -1 && PtIndex != edit->PreselectPoint) { // if a new point is hit std::stringstream ss; - ss << "Vertex" << PtIndex; + ss << "Vertex" << PtIndex + 1; bool accepted = Gui::Selection().setPreselect(getSketchObject()->getDocument()->getName() ,getSketchObject()->getNameInDocument() @@ -1398,9 +1400,9 @@ bool ViewProviderSketch::detectPreselection(const SoPickedPoint *Point, int &PtI } else if (GeoIndex != -1 && GeoIndex != edit->PreselectCurve) { // if a new curve is hit std::stringstream ss; if (GeoIndex >= 0) - ss << "Edge" << GeoIndex; + ss << "Edge" << GeoIndex + 1; else // external geometry - ss << "ExternalEdge" << -GeoIndex - 3; // convert index start from -3 to 0 + ss << "ExternalEdge" << -GeoIndex - 2; // convert index start from -3 to 1 bool accepted = Gui::Selection().setPreselect(getSketchObject()->getDocument()->getName() ,getSketchObject()->getNameInDocument() @@ -1447,7 +1449,7 @@ bool ViewProviderSketch::detectPreselection(const SoPickedPoint *Point, int &PtI } } else if (ConstrIndex != -1 && ConstrIndex != edit->PreselectConstraint) { // if a constraint is hit std::stringstream ss; - ss << "Constraint" << ConstrIndex; + ss << "Constraint" << ConstrIndex + 1; bool accepted = Gui::Selection().setPreselect(getSketchObject()->getDocument()->getName() ,getSketchObject()->getNameInDocument() @@ -1543,7 +1545,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (polygon.Contains(Base::Vector2D(pnt0.x, pnt0.y))) { std::stringstream ss; - ss << "Vertex" << VertexId; + ss << "Vertex" << VertexId + 1; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); } @@ -1560,19 +1562,19 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & bool pnt2Inside = polygon.Contains(Base::Vector2D(pnt2.x, pnt2.y)); if (pnt1Inside) { std::stringstream ss; - ss << "Vertex" << VertexId - 1; + ss << "Vertex" << VertexId; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); } if (pnt2Inside) { std::stringstream ss; - ss << "Vertex" << VertexId; + ss << "Vertex" << VertexId + 1; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); } if (pnt1Inside && pnt2Inside) { std::stringstream ss; - ss << "Edge" << GeoId; + ss << "Edge" << GeoId + 1; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); } @@ -1587,7 +1589,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (polygon.Contains(Base::Vector2D(pnt0.x, pnt0.y))) { std::stringstream ss; - ss << "Vertex" << VertexId; + ss << "Vertex" << VertexId + 1; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); int countSegments = 12; @@ -1614,7 +1616,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (bpolyInside) { ss.clear(); ss.str(""); - ss << "Edge" << GeoId; + ss << "Edge" << GeoId + 1; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(),ss.str().c_str()); } } @@ -1638,20 +1640,20 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & bool pnt0Inside = polygon.Contains(Base::Vector2D(pnt0.x, pnt0.y)); if (pnt0Inside) { std::stringstream ss; - ss << "Vertex" << VertexId - 2; + ss << "Vertex" << VertexId - 1; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); } bool pnt1Inside = polygon.Contains(Base::Vector2D(pnt1.x, pnt1.y)); if (pnt1Inside) { std::stringstream ss; - ss << "Vertex" << VertexId - 1; + ss << "Vertex" << VertexId; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); } if (polygon.Contains(Base::Vector2D(pnt2.x, pnt2.y))) { std::stringstream ss; - ss << "Vertex" << VertexId; + ss << "Vertex" << VertexId + 1; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); } @@ -1685,7 +1687,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if (bpolyInside) { std::stringstream ss; - ss << "Edge" << GeoId; + ss << "Edge" << GeoId + 1; Gui::Selection().addSelection(doc->getName(), sketchObject->getNameInDocument(), ss.str().c_str()); } } @@ -3440,14 +3442,14 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) // go through the selected subelements for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { if (it->size() > 4 && it->substr(0,4) == "Edge") { - int GeoId = std::atoi(it->substr(4,4000).c_str()); + int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1; delGeometries.insert(GeoId); } else if (it->size() > 12 && it->substr(0,12) == "ExternalEdge") { - int GeoId = std::atoi(it->substr(12,4000).c_str()); + int GeoId = std::atoi(it->substr(12,4000).c_str()) - 1; GeoId = -GeoId - 3; delGeometries.insert(GeoId); } else if (it->size() > 6 && it->substr(0,6) == "Vertex") { - int VtId = std::atoi(it->substr(6,4000).c_str()); + int VtId = std::atoi(it->substr(6,4000).c_str()) - 1; int GeoId; Sketcher::PointPos PosId; getSketchObject()->getGeoVertexIndex(VtId, GeoId, PosId); @@ -3459,7 +3461,7 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) } else if (*it == "RootPoint") { delCoincidents.insert(-1); } else if (it->size() > 10 && it->substr(0,10) == "Constraint") { - int ConstrId = std::atoi(it->substr(10,4000).c_str()); + int ConstrId = std::atoi(it->substr(10,4000).c_str()) - 1; delConstraints.insert(ConstrId); } }