From e5953cedac75bbd8eba7351007dbf7a92a88003f Mon Sep 17 00:00:00 2001 From: logari81 Date: Tue, 10 Jul 2012 15:25:27 +0200 Subject: [PATCH] Sketcher: points defined as external geometry, fix behavior of external geometry cursor, improve appearance of point creation cursor --- src/Mod/Sketcher/App/SketchObject.cpp | 44 ++++++++++++++--------- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 43 +++++++++++----------- 2 files changed, 50 insertions(+), 37 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 0cb04d84c4..32d718d212 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -32,6 +32,7 @@ # include # include # include +# include # include # include # include @@ -1226,15 +1227,17 @@ void SketchObject::rebuildExternalGeometry(void) invPlm.multVec(p2,p2); if (Base::Distance(p1,p2) < Precision::Confusion()) { - std::string msg = SubElement + " perpendicular to the sketch plane cannot be used as external geometry"; - throw Base::Exception(msg.c_str()); + Base::Vector3d p = (p1 + p2) / 2; + Part::GeomPoint* point = new Part::GeomPoint(p); + point->Construction = true; + ExternalGeo.push_back(point); + } + else { + Part::GeomLineSegment* line = new Part::GeomLineSegment(); + line->setPoints(p1,p2); + line->Construction = true; + ExternalGeo.push_back(line); } - - Part::GeomLineSegment* line = new Part::GeomLineSegment(); - line->setPoints(p1,p2); - - line->Construction = true; - ExternalGeo.push_back(line); } else { try { @@ -1256,15 +1259,17 @@ void SketchObject::rebuildExternalGeometry(void) Base::Vector3d p2(P2.X(),P2.Y(),P2.Z()); if (Base::Distance(p1,p2) < Precision::Confusion()) { - std::string msg = SubElement + " perpendicular to the sketch plane cannot be used as external geometry"; - throw Base::Exception(msg.c_str()); + Base::Vector3d p = (p1 + p2) / 2; + Part::GeomPoint* point = new Part::GeomPoint(p); + point->Construction = true; + ExternalGeo.push_back(point); + } + else { + Part::GeomLineSegment* line = new Part::GeomLineSegment(); + line->setPoints(p1,p2); + line->Construction = true; + ExternalGeo.push_back(line); } - - Part::GeomLineSegment* line = new Part::GeomLineSegment(); - line->setPoints(p1,p2); - - line->Construction = true; - ExternalGeo.push_back(line); } else if (curve.GetType() == GeomAbs_Circle) { gp_Circ c = curve.Circle(); @@ -1304,7 +1309,12 @@ void SketchObject::rebuildExternalGeometry(void) } break; case TopAbs_VERTEX: - throw Base::Exception("Vertices cannot be used as external geometry for sketches"); + { + gp_Pnt p = BRep_Tool::Pnt(TopoDS::Vertex(refSubShape)); + Part::GeomPoint* point = new Part::GeomPoint(Base::Vector3d(p.X(),p.Y(),p.Z())); + point->Construction = true; + ExternalGeo.push_back(point); + } break; default: throw Base::Exception("Unknown type of geometry"); diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index cf6680aede..299a5229b2 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -1269,22 +1269,22 @@ static const char *cursor_createpoint[]={ "......+.........................", "......+.........................", "......+.........................", -"...............+++++++..........", -"..............++.....++.........", -".............+.........+........", -"............++.........++.......", -"...........++...........++......", -"...........+.............+......", -"...........+.............+......", -"...........+.............+......", -"...........+.............+......", -"...........+.............+......", -"...........+.............+......", -"...........++...........++......", -"............++.........++.......", -".............+.........+........", -"..............++.....++.........", -"...............+++++++..........", +"................................", +"................................", +"................................", +".................++++...........", +"................++++++..........", +"...............++++++++.........", +"...............++++++++.........", +"...............++++++++.........", +"...............++++++++.........", +"................++++++..........", +".................++++...........", +"................................", +"................................", +"................................", +"................................", +"................................", "................................", "................................", "................................"}; @@ -1843,8 +1843,9 @@ namespace SketcherGui { if (!sSubName || sSubName[0] == '\0') return false; std::string element(sSubName); - // for the moment we allow only edges - if (element.substr(0,4) == "Edge") { + // for the moment we allow only edges and vertices + if ((element.size() > 4 && element.substr(0,4) == "Edge") || + (element.size() > 6 && element.substr(0,6) == "Vertex")) { return true; } return false; @@ -1917,7 +1918,8 @@ public: virtual void mouseMove(Base::Vector2D onSketchPos) { - applyCursor(); + if (Gui::Selection().getPreselection().pObjectName) + applyCursor(); } virtual bool pressButton(Base::Vector2D onSketchPos) @@ -1935,7 +1937,8 @@ public: { if (msg.Type == Gui::SelectionChanges::AddSelection) { std::string subName(msg.pSubName); - if (subName.size() > 4 && subName.substr(0,4) == "Edge") { + if ((subName.size() > 4 && subName.substr(0,4) == "Edge") || + (subName.size() > 6 && subName.substr(0,6) == "Vertex")) { try { Gui::Command::openCommand("Add external geometry"); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addExternal(\"%s\",\"%s\")",