diff --git a/src/Mod/Part/App/Attacher.cpp b/src/Mod/Part/App/Attacher.cpp index bb2dff522890..cebff12d764b 100644 --- a/src/Mod/Part/App/Attacher.cpp +++ b/src/Mod/Part/App/Attacher.cpp @@ -36,6 +36,7 @@ # include # include # include +# include # include # include # include @@ -1687,7 +1688,7 @@ AttachEngineLine::AttachEngineLine() modeRefTypes[mm1FaceNormal] = attacher3D.modeRefTypes[mmTangentPlane]; - + modeRefTypes[mm1Intersection].push_back(cat(rtFace,rtFace)); this->EnableAllSupportedModes(); } @@ -1886,6 +1887,34 @@ Base::Placement AttachEngineLine::calculateAttachedPlacement(const Base::Placeme LineBasePoint = dx2.Location(); } }break; + case mm1Intersection:{ + if (shapes.size() < 2) + throw Base::ValueError("AttachEngineLine::calculateAttachedPlacement: Intersection mode requires two shapes; only one is supplied"); + if (shapes[0]->IsNull() || shapes[1]->IsNull()) + throw Base::ValueError("Null shape in AttachEngineLine::calculateAttachedPlacement()!"); + + const TopoDS_Face &face1 = TopoDS::Face(*(shapes[0])); + const TopoDS_Face &face2 = TopoDS::Face(*(shapes[1])); + + Handle(Geom_Surface) hSurf1 = BRep_Tool::Surface(face1); + Handle(Geom_Surface) hSurf2 = BRep_Tool::Surface(face2); + GeomAPI_IntSS intersector(hSurf1, hSurf2, Precision::Confusion()); + if (!intersector.IsDone()) + throw Base::ValueError("AttachEngineLine::calculateAttachedPlacement: Intersection failed"); + + const Standard_Integer intLines = intersector.NbLines(); + if (intLines == 0) + throw Base::ValueError("AttachEngineLine::calculateAttachedPlacement: The two shapes don't intersect"); + if (intLines != 1) + throw Base::ValueError("AttachEngineLine::calculateAttachedPlacement: Intersection is not a single curve"); + + GeomAdaptor_Curve adapt(intersector.Line(1)); + if (adapt.GetType() != GeomAbs_Line) + throw Base::ValueError("AttachEngineLine::calculateAttachedPlacement: Intersection is not a straight line"); + + LineBasePoint = adapt.Line().Location(); + LineDir = adapt.Line().Direction(); + }break; case mm1Proximity:{ if (shapes.size() < 2) throw Base::ValueError("AttachEngineLine::calculateAttachedPlacement: Proximity mode requires two shapes; only one is supplied"); diff --git a/src/Mod/Part/Gui/AttacherTexts.cpp b/src/Mod/Part/Gui/AttacherTexts.cpp index 865cad5d419d..9daf966bd5df 100644 --- a/src/Mod/Part/Gui/AttacherTexts.cpp +++ b/src/Mod/Part/Gui/AttacherTexts.cpp @@ -245,7 +245,7 @@ TextSet getUIStrings(Base::Type attacherType, eMapMode mmode) qApp->translate("Attacher1D", "Line that passes through two vertices.","AttachmentLine mode tooltip")); case mm1Intersection: return TwoStrings(qApp->translate("Attacher1D", "Intersection","AttachmentLine mode caption"), - qApp->translate("Attacher1D", "Not implemented.","AttachmentLine mode tooltip")); + qApp->translate("Attacher1D", "Intersection of two faces.","AttachmentLine mode tooltip")); case mm1Proximity: return TwoStrings(qApp->translate("Attacher1D", "Proximity line","AttachmentLine mode caption"), qApp->translate("Attacher1D", "Line that spans the shortest distance between shapes.","AttachmentLine mode tooltip"));