Hyperbola InternalAlignment

Focus is working.
This commit is contained in:
Abdullah Tahiri 2016-01-15 17:25:09 +01:00 committed by wmayer
parent fb12cb83fc
commit b6c1e15493
2 changed files with 126 additions and 35 deletions

View File

@ -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<const Part::GeomArcOfHyperbola *>(geo);
Base::Vector3d center = aoh->getCenter();
double majord = aoh->getMajorRadius();
double minord = aoh->getMinorRadius();
Base::Vector3d majdir = aoh->getMajorAxisDir();
std::vector<Part::Geometry *> igeo;
std::vector<Constraint *> 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<Part::Geometry *>::iterator it=igeo.begin(); it != igeo.end(); ++it)
if (*it)
delete *it;
for (std::vector<Constraint *>::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
}

View File

@ -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();