+ fixes #0000692: Sketcher: Add angle constraint for arcs
This commit is contained in:
parent
2bff32d704
commit
6a3437e28e
|
@ -1376,18 +1376,29 @@ int Sketch::addAngleConstraint(int geoId, double value)
|
||||||
{
|
{
|
||||||
geoId = checkGeoId(geoId);
|
geoId = checkGeoId(geoId);
|
||||||
|
|
||||||
if (Geoms[geoId].type != Line)
|
if (Geoms[geoId].type == Line) {
|
||||||
return -1;
|
GCS::Line &l = Lines[Geoms[geoId].index];
|
||||||
|
|
||||||
GCS::Line &l = Lines[Geoms[geoId].index];
|
// add the parameter for the angle
|
||||||
|
FixParameters.push_back(new double(value));
|
||||||
|
double *angle = FixParameters[FixParameters.size()-1];
|
||||||
|
|
||||||
// add the parameter for the angle
|
int tag = ++ConstraintsCounter;
|
||||||
FixParameters.push_back(new double(value));
|
GCSsys.addConstraintP2PAngle(l.p1, l.p2, angle, tag);
|
||||||
double *angle = FixParameters[FixParameters.size()-1];
|
return ConstraintsCounter;
|
||||||
|
}
|
||||||
|
else if (Geoms[geoId].type == Arc) {
|
||||||
|
GCS::Arc &a = Arcs[Geoms[geoId].index];
|
||||||
|
|
||||||
int tag = ++ConstraintsCounter;
|
// add the parameter for the angle
|
||||||
GCSsys.addConstraintP2PAngle(l.p1, l.p2, angle, tag);
|
FixParameters.push_back(new double(value));
|
||||||
return ConstraintsCounter;
|
double *angle = FixParameters[FixParameters.size()-1];
|
||||||
|
|
||||||
|
int tag = ++ConstraintsCounter;
|
||||||
|
GCSsys.addConstraintL2LAngle(a.center, a.start, a.center, a.end, angle, tag);
|
||||||
|
return ConstraintsCounter;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// line to line angle constraint
|
// line to line angle constraint
|
||||||
|
|
|
@ -2070,7 +2070,7 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
|
||||||
if (isEdge(GeoId1, PosId1) && isEdge(GeoId2, PosId2) && isVertex(GeoId3, PosId3)) {
|
if (isEdge(GeoId1, PosId1) && isEdge(GeoId2, PosId2) && isVertex(GeoId3, PosId3)) {
|
||||||
double ActAngle = 0.0;
|
double ActAngle = 0.0;
|
||||||
|
|
||||||
openCommand("add angle constraint");
|
openCommand("Add angle constraint");
|
||||||
|
|
||||||
//add missing point-on-object constraints
|
//add missing point-on-object constraints
|
||||||
if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){
|
if(! IsPointAlreadyOnCurve(GeoId1, GeoId3, PosId3, Obj)){
|
||||||
|
@ -2163,7 +2163,7 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
|
||||||
std::swap(PosId1,PosId2);
|
std::swap(PosId1,PosId2);
|
||||||
}
|
}
|
||||||
|
|
||||||
openCommand("add angle constraint");
|
openCommand("Add angle constraint");
|
||||||
Gui::Command::doCommand(
|
Gui::Command::doCommand(
|
||||||
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ",
|
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ",
|
||||||
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActAngle);
|
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActAngle);
|
||||||
|
@ -2187,12 +2187,28 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
|
||||||
Base::Vector3d dir = lineSeg->getEndPoint()-lineSeg->getStartPoint();
|
Base::Vector3d dir = lineSeg->getEndPoint()-lineSeg->getStartPoint();
|
||||||
double ActAngle = atan2(dir.y,dir.x);
|
double ActAngle = atan2(dir.y,dir.x);
|
||||||
|
|
||||||
openCommand("add angle constraint");
|
openCommand("Add angle constraint");
|
||||||
Gui::Command::doCommand(
|
Gui::Command::doCommand(
|
||||||
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%f)) ",
|
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%f)) ",
|
||||||
selection[0].getFeatName(),GeoId1,ActAngle);
|
selection[0].getFeatName(),GeoId1,ActAngle);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
|
finishDistanceConstraint(this, Obj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (geom->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) {
|
||||||
|
const Part::GeomArcOfCircle *arc;
|
||||||
|
arc = dynamic_cast<const Part::GeomArcOfCircle*>(geom);
|
||||||
|
double startangle, endangle;
|
||||||
|
arc->getRange(startangle, endangle);
|
||||||
|
double angle = endangle - startangle;
|
||||||
|
|
||||||
|
openCommand("Add angle constraint");
|
||||||
|
Gui::Command::doCommand(
|
||||||
|
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Angle',%d,%f)) ",
|
||||||
|
selection[0].getFeatName(),GeoId1,angle);
|
||||||
|
commitCommand();
|
||||||
|
|
||||||
finishDistanceConstraint(this, Obj);
|
finishDistanceConstraint(this, Obj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1265,12 +1265,19 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo
|
||||||
dir2.RotateZ(-M_PI/2);
|
dir2.RotateZ(-M_PI/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (Constr->First != Constraint::GeoUndef) { // line angle
|
} else if (Constr->First != Constraint::GeoUndef) { // line/arc angle
|
||||||
const Part::Geometry *geo = GeoById(geomlist, Constr->First);
|
const Part::Geometry *geo = GeoById(geomlist, Constr->First);
|
||||||
if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId())
|
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||||
|
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment *>(geo);
|
||||||
|
p0 = (lineSeg->getEndPoint()+lineSeg->getStartPoint())/2;
|
||||||
|
}
|
||||||
|
else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) {
|
||||||
|
const Part::GeomArcOfCircle *arc = dynamic_cast<const Part::GeomArcOfCircle *>(geo);
|
||||||
|
p0 = arc->getCenter();
|
||||||
|
}
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment *>(geo);
|
}
|
||||||
p0 = (lineSeg->getEndPoint()+lineSeg->getStartPoint())/2;
|
|
||||||
} else
|
} else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -3721,16 +3728,26 @@ Restart:
|
||||||
|
|
||||||
} else if (Constr->First != Constraint::GeoUndef) {
|
} else if (Constr->First != Constraint::GeoUndef) {
|
||||||
const Part::Geometry *geo = GeoById(*geomlist, Constr->First);
|
const Part::Geometry *geo = GeoById(*geomlist, Constr->First);
|
||||||
if (geo->getTypeId() != Part::GeomLineSegment::getClassTypeId())
|
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||||
|
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment *>(geo);
|
||||||
|
p0 = Base::convertTo<SbVec3f>((lineSeg->getEndPoint()+lineSeg->getStartPoint())/2);
|
||||||
|
|
||||||
|
Base::Vector3d dir = lineSeg->getEndPoint()-lineSeg->getStartPoint();
|
||||||
|
startangle = 0.;
|
||||||
|
range = atan2(dir.y,dir.x);
|
||||||
|
endangle = startangle + range;
|
||||||
|
}
|
||||||
|
else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) {
|
||||||
|
const Part::GeomArcOfCircle *arc = dynamic_cast<const Part::GeomArcOfCircle *>(geo);
|
||||||
|
p0 = Base::convertTo<SbVec3f>(arc->getCenter());
|
||||||
|
|
||||||
|
Base::Vector3d dir = arc->getEndPoint()-arc->getStartPoint();
|
||||||
|
arc->getRange(startangle, endangle);
|
||||||
|
range = endangle - startangle;
|
||||||
|
}
|
||||||
|
else {
|
||||||
break;
|
break;
|
||||||
const Part::GeomLineSegment *lineSeg = dynamic_cast<const Part::GeomLineSegment *>(geo);
|
}
|
||||||
|
|
||||||
p0 = Base::convertTo<SbVec3f>((lineSeg->getEndPoint()+lineSeg->getStartPoint())/2);
|
|
||||||
|
|
||||||
Base::Vector3d dir = lineSeg->getEndPoint()-lineSeg->getStartPoint();
|
|
||||||
startangle = 0.;
|
|
||||||
range = atan2(dir.y,dir.x);
|
|
||||||
endangle = startangle + range;
|
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user