Sketcher: fix Circle to Line distance constraint display
This commit is contained in:
committed by
0penBrain
parent
a892de5fc6
commit
e69e9019df
@@ -657,36 +657,27 @@ Restart:
|
||||
pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos);
|
||||
pnt2 = geolistfacade.getPoint(Constr->Second, Constr->SecondPos);
|
||||
} else if (Constr->Second != GeoEnum::GeoUndef) {
|
||||
pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos);
|
||||
|
||||
const Part::Geometry *geo = geolistfacade.getGeometryFromGeoId(Constr->Second);
|
||||
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||
const Part::GeomLineSegment *lineSeg = static_cast<const Part::GeomLineSegment *>(geo);
|
||||
Base::Vector3d l2p1 = lineSeg->getStartPoint();
|
||||
Base::Vector3d l2p2 = lineSeg->getEndPoint();
|
||||
if (Constr->FirstPos != Sketcher::PointPos::none) { // point to line distance
|
||||
const Part::GeomLineSegment *lineSeg = static_cast<const Part::GeomLineSegment *>(geo);
|
||||
Base::Vector3d l2p1 = lineSeg->getStartPoint();
|
||||
Base::Vector3d l2p2 = lineSeg->getEndPoint();
|
||||
pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos);
|
||||
// calculate the projection of p1 onto line2
|
||||
pnt2.ProjectToLine(pnt1-l2p1, l2p2-l2p1);
|
||||
pnt2 += pnt1;
|
||||
} else {
|
||||
const Part::Geometry *geo1 = geolistfacade.getGeometryFromGeoId(Constr->First);
|
||||
if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) { // circle to line distance
|
||||
const Part::GeomLineSegment *lineSeg = static_cast<const Part::GeomLineSegment *>(geo);
|
||||
const Part::GeomCircle *circleSeg = static_cast<const Part::GeomCircle*>(geo1);
|
||||
Base::Vector3d ct = circleSeg->getCenter();
|
||||
Base::Vector3d l2p1 = lineSeg->getStartPoint();
|
||||
Base::Vector3d l2p2 = lineSeg->getEndPoint();
|
||||
double radius = circleSeg->getRadius();
|
||||
pnt2.ProjectToLine(ct-l2p1, l2p2-l2p1); //project on the line translated to origin
|
||||
Base::Vector3d dir = pnt2;
|
||||
pnt1.ProjectToLine(ct-l2p1, l2p2-l2p1); //project on the line translated to origin
|
||||
Base::Vector3d dir = pnt1;
|
||||
dir.Normalize();
|
||||
pnt1 = ct + dir * radius;
|
||||
pnt2 += ct;
|
||||
Base::Vector3d d = l2p2 - l2p1;
|
||||
double ActDist = std::abs(-ct.x*d.y+ct.y*d.x+l2p1.x*l2p2.y-l2p2.x*l2p1.y) / d.Length() - radius;
|
||||
if (ActDist < 0) {
|
||||
std::swap(pnt1, pnt2);
|
||||
}
|
||||
pnt1 += ct;
|
||||
pnt2 = ct + dir * radius;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1391,13 +1391,25 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2d &toPo
|
||||
} else if (Constr->Second != GeoEnum::GeoUndef) {
|
||||
p1 = getSolvedSketch().getPoint(Constr->First, Constr->FirstPos);
|
||||
const Part::Geometry *geo = GeoList::getGeometryFromGeoId (geomlist, Constr->Second);
|
||||
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { // point to line distance
|
||||
if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||
const Part::GeomLineSegment *lineSeg = static_cast<const Part::GeomLineSegment *>(geo);
|
||||
Base::Vector3d l2p1 = lineSeg->getStartPoint();
|
||||
Base::Vector3d l2p2 = lineSeg->getEndPoint();
|
||||
// calculate the projection of p1 onto line2
|
||||
p2.ProjectToLine(p1-l2p1, l2p2-l2p1);
|
||||
p2 += p1;
|
||||
if (Constr->FirstPos != Sketcher::PointPos::none) { // point to line distance
|
||||
// calculate the projection of p1 onto line2
|
||||
p2.ProjectToLine(p1-l2p1, l2p2-l2p1);
|
||||
p2 += p1;
|
||||
} else {
|
||||
const Part::Geometry *geo1 = GeoList::getGeometryFromGeoId (geomlist, Constr->First);
|
||||
const Part::GeomCircle *circleSeg = static_cast<const Part::GeomCircle*>(geo1);
|
||||
Base::Vector3d ct = circleSeg->getCenter();
|
||||
double radius = circleSeg->getRadius();
|
||||
p1.ProjectToLine(ct-l2p1, l2p2-l2p1); //project on the line translated to origin
|
||||
Base::Vector3d dir = p1;
|
||||
dir.Normalize();
|
||||
p1 += ct;
|
||||
p2 = ct + dir * radius;
|
||||
}
|
||||
} else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { // circle to circle distance
|
||||
const Part::Geometry *geo1 = GeoList::getGeometryFromGeoId (geomlist, Constr->First);
|
||||
if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
||||
|
||||
Reference in New Issue
Block a user