From b6c1e15493b2ba826ec2d464e2337dc2f3a49b7c Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Fri, 15 Jan 2016 17:25:09 +0100 Subject: [PATCH] Hyperbola InternalAlignment Focus is working. --- src/Mod/Sketcher/App/SketchObject.cpp | 118 ++++++++++++++++++++++ src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 43 ++------ 2 files changed, 126 insertions(+), 35 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index dbd29096b..27e231e3f 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -2880,6 +2880,124 @@ int SketchObject::ExposeInternalGeometry(int GeoId) return incrgeo; //number of added elements } + else if(geo->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { + // First we search what has to be restored + bool major=false; + bool minor=false; + bool focus=false; + + const std::vector< Sketcher::Constraint * > &vals = Constraints.getValues(); + + for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); + it != vals.end(); ++it) { + if((*it)->Type == Sketcher::InternalAlignment && (*it)->Second == GeoId) + { + switch((*it)->AlignmentType){ + case Sketcher::HyperbolaMajor: + major=true; + break; + case Sketcher::HyperbolaMinor: + minor=true; + break; + case Sketcher::HyperbolaFocus: + focus=true; + break; + default: + return -1; + } + } + } + + int currentgeoid= getHighestCurveIndex(); + int incrgeo= 0; + + const Part::GeomArcOfHyperbola *aoh = static_cast(geo); + + Base::Vector3d center = aoh->getCenter(); + double majord = aoh->getMajorRadius(); + double minord = aoh->getMinorRadius(); + Base::Vector3d majdir = aoh->getMajorAxisDir(); + + std::vector igeo; + std::vector icon; + + Base::Vector3d mindir = Vector3d(-majdir.y, majdir.x); + + Base::Vector3d majorpositiveend = center + majord * majdir; + Base::Vector3d majornegativeend = center - majord * majdir; + Base::Vector3d minorpositiveend = center + minord * mindir; + Base::Vector3d minornegativeend = center - minord * mindir; + + double df= sqrt(majord*majord+minord*minord); + + Base::Vector3d focus1P = center + df * majdir; + + /*if(!major) + { + Part::GeomLineSegment *lmajor = new Part::GeomLineSegment(); + lmajor->setPoints(majorpositiveend,majornegativeend); + + igeo.push_back(lmajor); + + Sketcher::Constraint *newConstr = new Sketcher::Constraint(); + newConstr->Type = Sketcher::InternalAlignment; + newConstr->AlignmentType = Sketcher::HyperbolaMajor; + newConstr->First = currentgeoid+incrgeo+1; + newConstr->Second = GeoId; + + icon.push_back(newConstr); + incrgeo++; + } + if(!minor) + { + Part::GeomLineSegment *lminor = new Part::GeomLineSegment(); + lminor->setPoints(minorpositiveend,minornegativeend); + + igeo.push_back(lminor); + + Sketcher::Constraint *newConstr = new Sketcher::Constraint(); + newConstr->Type = Sketcher::InternalAlignment; + newConstr->AlignmentType = Sketcher::HyperbolaMinor; + newConstr->First = currentgeoid+incrgeo+1; + newConstr->Second = GeoId; + + icon.push_back(newConstr); + incrgeo++; + }*/ + if(!focus) + { + Part::GeomPoint *pf1 = new Part::GeomPoint(); + pf1->setPoint(focus1P); + + igeo.push_back(pf1); + + Sketcher::Constraint *newConstr = new Sketcher::Constraint(); + newConstr->Type = Sketcher::InternalAlignment; + newConstr->AlignmentType = Sketcher::HyperbolaFocus; + newConstr->First = currentgeoid+incrgeo+1; + newConstr->FirstPos = Sketcher::start; + newConstr->Second = GeoId; + + icon.push_back(newConstr); + incrgeo++; + } + + this->addGeometry(igeo,true); + this->addConstraints(icon); + + for (std::vector::iterator it=igeo.begin(); it != igeo.end(); ++it) + if (*it) + delete *it; + + for (std::vector::iterator it=icon.begin(); it != icon.end(); ++it) + if (*it) + delete *it; + + icon.clear(); + igeo.clear(); + + return incrgeo; //number of added elements + } else return -1; // not supported type } diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index d45c602f3..759e65f35 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -3663,6 +3663,8 @@ public: int currentgeoid = getHighestCurveIndex(); + try { + Gui::Command::openCommand("Add sketch arc of hyperbola"); //Add arc of hyperbola, point and constrain point as focus2. We add focus2 for it to balance @@ -3677,43 +3679,14 @@ public: minAxisPoint.fX, minAxisPoint.fY, centerPoint.fX, centerPoint.fY, startAngle, endAngle); - /* + currentgeoid++; - - try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))", - sketchgui->getObject()->getNameInDocument(), - majorpositiveend.x,majorpositiveend.y,majornegativeend.x,majornegativeend.y); // create line for major axis - - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ", - sketchgui->getObject()->getNameInDocument(),currentgeoid+1); - - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMajorDiameter',%d,%d)) ", - sketchgui->getObject()->getNameInDocument(),currentgeoid+1,currentgeoid); // constrain major axis - - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))", - sketchgui->getObject()->getNameInDocument(), - minorpositiveend.x,minorpositiveend.y,minornegativeend.x,minornegativeend.y); // create line for minor axis - - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ", - sketchgui->getObject()->getNameInDocument(),currentgeoid+2); - - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseMinorDiameter',%d,%d)) ", - sketchgui->getObject()->getNameInDocument(),currentgeoid+2,currentgeoid); // constrain minor axis - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))", - sketchgui->getObject()->getNameInDocument(), - focus1P.x,focus1P.y); - - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus1',%d,%d,%d)) ", - sketchgui->getObject()->getNameInDocument(),currentgeoid+3,Sketcher::start,currentgeoid); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.ExposeInternalGeometry(%d)", + sketchgui->getObject()->getNameInDocument(), + currentgeoid); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))", - sketchgui->getObject()->getNameInDocument(), - focus2P.x,focus2P.y); - - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ", - sketchgui->getObject()->getNameInDocument(),currentgeoid+4,Sketcher::start,currentgeoid); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); @@ -3721,7 +3694,7 @@ public: Gui::Command::updateActive(); return false; } - */ + Gui::Command::commitCommand(); Gui::Command::updateActive();