Sketcher: Ellipse enhancement: All internal geometry is shown on creation
Elements that have internal geometry are created with the internal geometry on creation. It has been under discussion for a long time. Ulrich was in favour (asked for it several times). DeepSOIC implemented the focus because he hated the poor dragging of the ellipse when empty.
This commit is contained in:
@@ -147,7 +147,7 @@ bool isSimpleVertex(const Sketcher::SketchObject* Obj, int GeoId, PointPos PosId
|
||||
if (geo->getTypeId() == Part::GeomPoint::getClassTypeId())
|
||||
return true;
|
||||
else if (PosId == Sketcher::mid &&
|
||||
(geo->getTypeId() == Part::GeomCircle::getClassTypeId() || // TODO: ellipse
|
||||
(geo->getTypeId() == Part::GeomCircle::getClassTypeId() ||
|
||||
geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()))
|
||||
return true;
|
||||
else
|
||||
@@ -802,7 +802,7 @@ void CmdSketcherConstrainPointOnObject::activated(int iMsg)
|
||||
|
||||
// Currently only accepts line segments and circles
|
||||
if (geom->getTypeId() == Part::GeomLineSegment::getClassTypeId() ||
|
||||
geom->getTypeId() == Part::GeomCircle::getClassTypeId() || // TODO: ellipse
|
||||
geom->getTypeId() == Part::GeomCircle::getClassTypeId() ||
|
||||
geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ||
|
||||
geom->getTypeId() == Part::GeomEllipse::getClassTypeId() ||
|
||||
geom->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() ) {
|
||||
@@ -1289,7 +1289,7 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg)
|
||||
}
|
||||
else if (geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId() &&
|
||||
geo2->getTypeId() != Part::GeomArcOfCircle::getClassTypeId() &&
|
||||
geo2->getTypeId() != Part::GeomCircle::getClassTypeId()) { // TODO: ellipse
|
||||
geo2->getTypeId() != Part::GeomCircle::getClassTypeId()) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected edge should be an arc, line or circle."));
|
||||
return;
|
||||
@@ -1765,7 +1765,7 @@ void CmdSketcherConstrainRadius::activated(int iMsg)
|
||||
double radius = arc->getRadius();
|
||||
geoIdRadiusMap.push_back(std::make_pair(GeoId, radius));
|
||||
}
|
||||
else if (geom && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) { // TODO: ellipse
|
||||
else if (geom && geom->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
||||
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle *>(geom);
|
||||
double radius = circle->getRadius();
|
||||
geoIdRadiusMap.push_back(std::make_pair(GeoId, radius));
|
||||
@@ -2113,9 +2113,9 @@ void CmdSketcherConstrainEqual::activated(int iMsg)
|
||||
arcSel = true;
|
||||
else if (geo->getTypeId() != Part::GeomCircle::getClassTypeId())
|
||||
circSel = true;
|
||||
else if (geo->getTypeId() != Part::GeomEllipse::getClassTypeId()) // TODO: ellipse
|
||||
else if (geo->getTypeId() != Part::GeomEllipse::getClassTypeId())
|
||||
ellipsSel = true;
|
||||
else if (geo->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId()) // TODO: ellipse
|
||||
else if (geo->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId())
|
||||
arcEllipsSel = true;
|
||||
else {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
|
||||
@@ -1976,6 +1976,20 @@ public:
|
||||
minAxisPoint = EditCurve[0]+minAxisDir;
|
||||
}
|
||||
|
||||
Base::Vector3d center = Base::Vector3d(EditCurve[0].fX,EditCurve[0].fY,0);
|
||||
|
||||
Base::Vector3d majorpositiveend = center + a * Base::Vector3d(cos(phi),sin(phi),0);
|
||||
Base::Vector3d majornegativeend = center - a * Base::Vector3d(cos(phi),sin(phi),0);
|
||||
Base::Vector3d minorpositiveend = center + b * Base::Vector3d(-sin(phi),cos(phi),0);
|
||||
Base::Vector3d minornegativeend = center - b * Base::Vector3d(-sin(phi),cos(phi),0);
|
||||
|
||||
double cf = sqrt( abs(a*a - b*b) );//using abs, avoided using different formula for a>b/a<b cases
|
||||
|
||||
Base::Vector3d focus1P = center + cf * Base::Vector3d(cos(phi),sin(phi),0);
|
||||
Base::Vector3d focus2P = center - cf * Base::Vector3d(cos(phi),sin(phi),0);
|
||||
|
||||
int currentgeoid = getHighestCurveIndex();//index of the arc of ellipse we just created
|
||||
|
||||
Gui::Command::openCommand("Add sketch ellipse");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.addGeometry(Part.Ellipse"
|
||||
@@ -1984,6 +1998,50 @@ public:
|
||||
majAxisPoint.fX, majAxisPoint.fY,
|
||||
minAxisPoint.fX, minAxisPoint.fY,
|
||||
EditCurve[0].fX, EditCurve[0].fY);
|
||||
|
||||
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.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());
|
||||
Gui::Command::abortCommand();
|
||||
Gui::Command::updateActive();
|
||||
return false;
|
||||
}
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
Gui::Command::updateActive();
|
||||
@@ -2290,14 +2348,19 @@ public:
|
||||
startAngle += M_PI/2;
|
||||
}
|
||||
|
||||
//calculate focus point vecF2
|
||||
double cf;//distance from center to focus
|
||||
cf = sqrt( abs(a*a - b*b) );//using abs, avoided using different formula for a>b/a<b cases
|
||||
Base::Vector2D vecCF;// a vector from center to focus2
|
||||
vecCF = majAxisDir;
|
||||
vecCF.Normalize();
|
||||
vecCF.Scale(-cf);//minus sign is because we want focus2 not focus1
|
||||
Base::Vector2D vecF2 = centerPoint + vecCF;
|
||||
Base::Vector3d center = Base::Vector3d(centerPoint.fX,centerPoint.fY,0);
|
||||
|
||||
Base::Vector3d majorpositiveend = center + a * Base::Vector3d(cos(phi),sin(phi),0);
|
||||
Base::Vector3d majornegativeend = center - a * Base::Vector3d(cos(phi),sin(phi),0);
|
||||
Base::Vector3d minorpositiveend = center + b * Base::Vector3d(-sin(phi),cos(phi),0);
|
||||
Base::Vector3d minornegativeend = center - b * Base::Vector3d(-sin(phi),cos(phi),0);
|
||||
|
||||
double cf = sqrt( abs(a*a - b*b) );//using abs, avoided using different formula for a>b/a<b cases
|
||||
|
||||
Base::Vector3d focus1P = center + cf * Base::Vector3d(cos(phi),sin(phi),0);
|
||||
Base::Vector3d focus2P = center - cf * Base::Vector3d(cos(phi),sin(phi),0);
|
||||
|
||||
int currentgeoid = getHighestCurveIndex();//index of the arc of ellipse we just created
|
||||
|
||||
Gui::Command::openCommand("Add sketch arc of ellipse");
|
||||
|
||||
@@ -2313,20 +2376,50 @@ public:
|
||||
minAxisPoint.fX, minAxisPoint.fY,
|
||||
centerPoint.fX, centerPoint.fY,
|
||||
startAngle, endAngle);
|
||||
int iAOE = getHighestCurveIndex();//index of the arc of ellipse we just created
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.addGeometry(Part.Point(App.Vector(%f,%f,0)))",
|
||||
|
||||
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(),
|
||||
vecF2.fX,vecF2.fY);
|
||||
int iPointF2 = getHighestCurveIndex();//index of the point we just created
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('InternalAlignment:EllipseFocus2',%d,%d,%d)) ",
|
||||
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(),
|
||||
iPointF2,Sketcher::start,iAOE);
|
||||
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.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());
|
||||
Gui::Command::abortCommand();
|
||||
Gui::Command::updateActive();
|
||||
return false;
|
||||
}
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
Gui::Command::updateActive();
|
||||
|
||||
@@ -242,7 +242,7 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint> &suggested
|
||||
}
|
||||
|
||||
} else if ((*it)->getTypeId() == Part::GeomEllipse::getClassTypeId()) {
|
||||
// TODO: Ellipse
|
||||
|
||||
const Part::GeomEllipse *ellipse = dynamic_cast<const Part::GeomEllipse *>((*it));
|
||||
|
||||
Base::Vector3d center = ellipse->getCenter();
|
||||
|
||||
@@ -718,7 +718,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
|
||||
geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ||
|
||||
geo->getTypeId() == Part::GeomCircle::getClassTypeId() ||
|
||||
geo->getTypeId() == Part::GeomEllipse::getClassTypeId()||
|
||||
geo->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { // TODO: ellipse
|
||||
geo->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) {
|
||||
Gui::Command::openCommand("Drag Curve");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.movePoint(%i,%i,App.Vector(%f,%f,0),%i)"
|
||||
,getObject()->getNameInDocument()
|
||||
@@ -3133,7 +3133,7 @@ Restart:
|
||||
norm1 = Base::Vector3d(cos(midangle),sin(midangle),0);
|
||||
dir1 = Base::Vector3d(-norm1.y,norm1.x,0);
|
||||
midpos1 = arc->getCenter() + arc->getRadius() * norm1;
|
||||
} else if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) { // TODO: ellipse
|
||||
} else if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
||||
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle *>(geo1);
|
||||
norm1 = Base::Vector3d(cos(M_PI/4),sin(M_PI/4),0);
|
||||
dir1 = Base::Vector3d(-norm1.y,norm1.x,0);
|
||||
@@ -3154,7 +3154,7 @@ Restart:
|
||||
norm2 = Base::Vector3d(cos(midangle),sin(midangle),0);
|
||||
dir2 = Base::Vector3d(-norm2.y,norm2.x,0);
|
||||
midpos2 = arc->getCenter() + arc->getRadius() * norm2;
|
||||
} else if (geo2->getTypeId() == Part::GeomCircle::getClassTypeId()) { // TODO: ellipse
|
||||
} else if (geo2->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
||||
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle *>(geo2);
|
||||
norm2 = Base::Vector3d(cos(M_PI/4),sin(M_PI/4),0);
|
||||
dir2 = Base::Vector3d(-norm2.y,norm2.x,0);
|
||||
@@ -3201,7 +3201,7 @@ Restart:
|
||||
if (Constr->Type == Equal) {
|
||||
double r1a,r1b,r2a,r2b;
|
||||
double angle1,angle1plus=0., angle2, angle2plus=0.;//angle1 = rotation of object as a whole; angle1plus = arc angle (t parameter for ellipses).
|
||||
if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) { // TODO: ellipse
|
||||
if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
||||
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle *>(geo1);
|
||||
r1a = circle->getRadius();
|
||||
angle1 = M_PI/4;
|
||||
@@ -3463,7 +3463,7 @@ Restart:
|
||||
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment *>(geo1);
|
||||
Base::Vector3d dir = (lineSeg->getEndPoint() - lineSeg->getStartPoint()).Normalize();
|
||||
Base::Vector3d norm(-dir.y, dir.x, 0);
|
||||
if (geo2->getTypeId()== Part::GeomCircle::getClassTypeId()) { // TODO: ellipse
|
||||
if (geo2->getTypeId()== Part::GeomCircle::getClassTypeId()) {
|
||||
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle *>(geo2);
|
||||
// tangency between a line and a circle
|
||||
float length = (circle->getCenter() - lineSeg->getStartPoint())*dir;
|
||||
@@ -3472,7 +3472,7 @@ Restart:
|
||||
relPos = norm * 1; //TODO Huh?
|
||||
}
|
||||
else if (geo2->getTypeId()== Part::GeomEllipse::getClassTypeId() ||
|
||||
geo2->getTypeId()== Part::GeomArcOfEllipse::getClassTypeId()) { // TODO: ellipse
|
||||
geo2->getTypeId()== Part::GeomArcOfEllipse::getClassTypeId()) {
|
||||
|
||||
Base::Vector3d center;
|
||||
if(geo2->getTypeId()== Part::GeomEllipse::getClassTypeId()){
|
||||
@@ -3499,7 +3499,7 @@ Restart:
|
||||
}
|
||||
}
|
||||
|
||||
if (geo1->getTypeId()== Part::GeomCircle::getClassTypeId() && // TODO: ellipse
|
||||
if (geo1->getTypeId()== Part::GeomCircle::getClassTypeId() &&
|
||||
geo2->getTypeId()== Part::GeomCircle::getClassTypeId()) {
|
||||
const Part::GeomCircle *circle1 = dynamic_cast<const Part::GeomCircle *>(geo1);
|
||||
const Part::GeomCircle *circle2 = dynamic_cast<const Part::GeomCircle *>(geo2);
|
||||
@@ -3508,12 +3508,12 @@ Restart:
|
||||
pos = circle1->getCenter() + dir * circle1->getRadius();
|
||||
relPos = dir * 1;
|
||||
}
|
||||
else if (geo2->getTypeId()== Part::GeomCircle::getClassTypeId()) { // TODO: ellipse
|
||||
else if (geo2->getTypeId()== Part::GeomCircle::getClassTypeId()) {
|
||||
std::swap(geo1,geo2);
|
||||
}
|
||||
|
||||
if (geo1->getTypeId()== Part::GeomCircle::getClassTypeId() &&
|
||||
geo2->getTypeId()== Part::GeomArcOfCircle::getClassTypeId()) { // TODO: ellipse
|
||||
geo2->getTypeId()== Part::GeomArcOfCircle::getClassTypeId()) {
|
||||
const Part::GeomCircle *circle = dynamic_cast<const Part::GeomCircle *>(geo1);
|
||||
const Part::GeomArcOfCircle *arc = dynamic_cast<const Part::GeomArcOfCircle *>(geo2);
|
||||
// tangency between a circle and an arc
|
||||
|
||||
Reference in New Issue
Block a user