From 98717f010a0744279b83f89bf03af1c92827bea5 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Mon, 6 Jul 2015 20:29:21 +0300 Subject: [PATCH] Attacher: proximity modes The modes that base on distToShape: * a line that connects the closest points, * the actual points --- src/Mod/Part/App/Attacher.cpp | 50 +++++++++++++++++++++++++++++++++++ src/Mod/Part/App/Attacher.h | 3 +++ 2 files changed, 53 insertions(+) diff --git a/src/Mod/Part/App/Attacher.cpp b/src/Mod/Part/App/Attacher.cpp index eedd8ff5b..0fcd21866 100644 --- a/src/Mod/Part/App/Attacher.cpp +++ b/src/Mod/Part/App/Attacher.cpp @@ -47,6 +47,7 @@ # include # include # include +# include #endif #include #include @@ -92,6 +93,7 @@ const char* AttachEngine::eMapModeStrings[]= { "TangentV", "TwoPointLine", "IntersectionLine", + "ProximityLine", "ObjectOrigin", "Focus1", @@ -101,6 +103,8 @@ const char* AttachEngine::eMapModeStrings[]= { "CenterOfMass", "IntersectionPoint", "Vertex", + "ProximityPoint1", + "ProximityPoint2", NULL}; @@ -1297,6 +1301,8 @@ AttachEngineLine::AttachEngineLine() modeRefTypes[mm1Directrix2].push_back(cat(rtEllipse)); modeRefTypes[mm1Directrix2].push_back(cat(rtHyperbola)); + modeRefTypes[mm1Proximity].push_back(cat(rtAnything, rtAnything)); + this->EnableAllSupportedModes(); } @@ -1461,6 +1467,26 @@ Base::Placement AttachEngineLine::calculateAttachedPlacement(Base::Placement ori LineBasePoint = dx2.Location(); } }break; + case mm1Proximity:{ + if (shapes.size() < 2) + throw Base::Exception("AttachEngineLine::calculateAttachedPlacement: Proximity mode requires two shapes; only one is supplied"); + if (shapes[0]->IsNull()) + throw Base::Exception("Null shape in AttachEngineLine::calculateAttachedPlacement()!"); + if (shapes[1]->IsNull()) + throw Base::Exception("Null shape in AttachEngineLine::calculateAttachedPlacement()!"); + BRepExtrema_DistShapeShape distancer (*(shapes[0]), *(shapes[1])); + if (!distancer.IsDone()) + throw Base::Exception("AttachEngineLine::calculateAttachedPlacement: proximity calculation failed."); + if (distancer.NbSolution()>1) + Base::Console().Warning("AttachEngineLine::calculateAttachedPlacement: proximity calculation gave %i solutions, ambiguous.\n",int(distancer.NbSolution())); + gp_Pnt p1 = distancer.PointOnShape1(1); + gp_Pnt p2 = distancer.PointOnShape2(1); + LineBasePoint = p1; + gp_Vec dist = gp_Vec(p1,p2); + if (dist.Magnitude() < Precision::Confusion()) + throw Base::Exception("AttachEngineLine::calculateAttachedPlacement: can't make proximity line, because shapes touch or intersect"); + LineDir = gp_Dir(dist); + }break; default: throwWrongMode(mmode); } @@ -1503,6 +1529,10 @@ AttachEnginePoint::AttachEnginePoint() modeRefTypes[mm0Focus2].push_back(cat(rtEllipse)); modeRefTypes[mm0Focus2].push_back(cat(rtHyperbola)); + s = cat(rtAnything, rtAnything); + modeRefTypes[mm0ProximityPoint1].push_back(s); + modeRefTypes[mm0ProximityPoint2].push_back(s); + this->EnableAllSupportedModes(); } @@ -1606,6 +1636,26 @@ Base::Placement AttachEnginePoint::calculateAttachedPlacement(Base::Placement or else BasePoint = f2; }break; + case mm0ProximityPoint1: + case mm0ProximityPoint2:{ + if (shapes.size() < 2) + throw Base::Exception("AttachEngineLine::calculateAttachedPlacement: Proximity mode requires two shapes; only one is supplied"); + if (shapes[0]->IsNull()) + throw Base::Exception("Null shape in AttachEngineLine::calculateAttachedPlacement()!"); + if (shapes[1]->IsNull()) + throw Base::Exception("Null shape in AttachEngineLine::calculateAttachedPlacement()!"); + BRepExtrema_DistShapeShape distancer (*(shapes[0]), *(shapes[1])); + if (!distancer.IsDone()) + throw Base::Exception("AttachEngineLine::calculateAttachedPlacement: proximity calculation failed."); + if (distancer.NbSolution()>1) + Base::Console().Warning("AttachEngineLine::calculateAttachedPlacement: proximity calculation gave %i solutions, ambiguous.\n",int(distancer.NbSolution())); + gp_Pnt p1 = distancer.PointOnShape1(1); + gp_Pnt p2 = distancer.PointOnShape2(1); + if (mmode == mm0ProximityPoint1) + BasePoint = p1; + else + BasePoint = p2; + }break; default: throwWrongMode(mmode); } diff --git a/src/Mod/Part/App/Attacher.h b/src/Mod/Part/App/Attacher.h index 87b2bcce0..3f7a4f9ae 100644 --- a/src/Mod/Part/App/Attacher.h +++ b/src/Mod/Part/App/Attacher.h @@ -83,6 +83,7 @@ enum eMapMode { mm1TangentV, mm1TwoPoints, mm1Intersection, + mm1Proximity, mm0Origin, mm0Focus1, @@ -92,6 +93,8 @@ enum eMapMode { mm0CenterOfMass, mm0Intersection, mm0Vertex, + mm0ProximityPoint1, + mm0ProximityPoint2, mmDummy_NumberOfModes//a value useful to check the validity of mode value };//see also eMapModeStrings[] definition in .cpp