From 40677b43bb137a6f014fafbc5ce4f647dc597f39 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 12 Jul 2016 16:26:30 +0300 Subject: [PATCH] Added option to create Construction Point by intersection of line and plane. --- src/ConstructionAPI/ConstructionAPI_Point.cpp | 110 +++++++++++++++++- src/ConstructionAPI/ConstructionAPI_Point.h | 20 +++- .../ConstructionPlugin_Plugin.cpp | 2 + .../ConstructionPlugin_Point.cpp | 31 ++++- .../ConstructionPlugin_Point.h | 30 ++++- .../ConstructionPlugin_Validators.cpp | 96 +++++++++++++++ .../ConstructionPlugin_Validators.h | 17 ++- src/ConstructionPlugin/Test/TestPoint.py | 19 ++- ...t_by_line_and_plane_intersection_32x32.png | Bin 0 -> 994 bytes .../point_by_planes_intersection_32x32.png | Bin 0 -> 969 bytes src/ConstructionPlugin/point_widget.xml | 28 ++++- src/GeomAPI/GeomAPI_Pln.cpp | 12 ++ src/GeomAPI/GeomAPI_Pln.h | 4 + src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h | 2 +- src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp | 44 ++++--- src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h | 7 ++ src/ModelHighAPI/ModelHighAPI_Macro.h | 51 ++++++++ src/ModelHighAPI/ModelHighAPI_Selection.cpp | 18 +++ src/ModelHighAPI/ModelHighAPI_Selection.h | 20 +++- 19 files changed, 475 insertions(+), 36 deletions(-) create mode 100644 src/ConstructionPlugin/icons/point_by_line_and_plane_intersection_32x32.png create mode 100644 src/ConstructionPlugin/icons/point_by_planes_intersection_32x32.png diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index 738703a6e..ef2ccc810 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -6,8 +6,16 @@ #include "ConstructionAPI_Point.h" +#include + +#include #include +#include + +static GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr); +static GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection); + //================================================================================================== ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr& theFeature) : ModelHighAPI_Interface(theFeature) @@ -47,9 +55,19 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr & thePart, std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Point::ID()); return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2)); } + +//================================================================================================== +GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr) +{ + GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE; + + std::string aShapeTypeStr = theShapeTypeStr; + std::transform(aShapeTypeStr.begin(), aShapeTypeStr.end(), aShapeTypeStr.begin(), ::tolower); + + if(theShapeTypeStr == "compound") { + aShapeType = GeomAPI_Shape::COMPOUND; + } else if(theShapeTypeStr == "compsolid") { + aShapeType = GeomAPI_Shape::COMPSOLID; + } else if(theShapeTypeStr == "solid") { + aShapeType = GeomAPI_Shape::SOLID; + } else if(theShapeTypeStr == "shell") { + aShapeType = GeomAPI_Shape::SHELL; + } else if(theShapeTypeStr == "face") { + aShapeType = GeomAPI_Shape::FACE; + } else if(theShapeTypeStr == "wire") { + aShapeType = GeomAPI_Shape::WIRE; + } else if(theShapeTypeStr == "edge") { + aShapeType = GeomAPI_Shape::EDGE; + } else if(theShapeTypeStr == "vertex") { + aShapeType = GeomAPI_Shape::VERTEX; + } else if(theShapeTypeStr == "shape") { + aShapeType = GeomAPI_Shape::SHAPE; + } + + return aShapeType; +} + +//================================================================================================== +GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection) +{ + GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE; + + switch(theSelection.variantType()) { + case ModelHighAPI_Selection::VT_ResultSubShapePair: { + ResultSubShapePair aPair = theSelection.resultSubShapePair(); + GeomShapePtr aShape = aPair.second; + if(!aShape.get()) { + aShape = aPair.first->shape(); + } + if(!aShape.get()) { + return aShapeType; + } + aShapeType = aShape->shapeType(); + break; + } + case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: { + TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair(); + std::string aType = aPair.first; + aShapeType = shapeTypeByStr(aType); + break; + } + } + + return aShapeType; +} diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h index ab9f83837..612df3075 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.h +++ b/src/ConstructionAPI/ConstructionAPI_Point.h @@ -53,7 +53,7 @@ public: CONSTRUCTIONAPI_EXPORT virtual ~ConstructionAPI_Point(); - INTERFACE_10(ConstructionPlugin_Point::ID(), + INTERFACE_14(ConstructionPlugin_Point::ID(), creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */, y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */, @@ -63,7 +63,11 @@ public: distancePercent, ConstructionPlugin_Point::DISTANCE_PERCENT(), ModelAPI_AttributeBoolean, /** Distance percent attribute */, reverse, ConstructionPlugin_Point::REVERSE(), ModelAPI_AttributeBoolean, /** Reverse attribute */, point, ConstructionPlugin_Point::POINT(), ModelAPI_AttributeSelection, /** Point attribute */, - plane, ConstructionPlugin_Point::PLANE(), ModelAPI_AttributeSelection, /** Plane attribute */ + plane, ConstructionPlugin_Point::PLANE(), ModelAPI_AttributeSelection, /** Plane attribute */, + firstLine, ConstructionPlugin_Point::FIRST_LINE(), ModelAPI_AttributeSelection, /** First line attribute */, + secondLine, ConstructionPlugin_Point::SECOND_LINE(), ModelAPI_AttributeSelection, /** Second line attribute */, + intersectionLine, ConstructionPlugin_Point::INTERSECTION_LINE(), ModelAPI_AttributeSelection, /** Intersection line attribute */, + intersectionPlane, ConstructionPlugin_Point::INTERSECTION_PLANE(), ModelAPI_AttributeSelection, /** Intersection plane attribute */ ) /// Set point values. @@ -82,7 +86,17 @@ public: /// Set point and plane for projection. CONSTRUCTIONAPI_EXPORT void setByProjection(const ModelHighAPI_Selection& theVertex, - const ModelHighAPI_Selection& thePlane); + const ModelHighAPI_Selection& theFace); + + /// Set lines for intersections. + CONSTRUCTIONAPI_EXPORT + void setByLinesIntersection(const ModelHighAPI_Selection& theEdge1, + const ModelHighAPI_Selection& theEdge2); + + /// Set line and plane for intersections. + CONSTRUCTIONAPI_EXPORT + void setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge, + const ModelHighAPI_Selection& theFace); }; /// Pointer on Point object. diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 63d7308d2..e9f202998 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -22,6 +22,8 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); aFactory->registerValidator("ConstructionPlugin_ValidatorPointLines", new ConstructionPlugin_ValidatorPointLines()); + aFactory->registerValidator("ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel", + new ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel()); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 22f91d732..c3866c52d 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -49,6 +49,9 @@ void ConstructionPlugin_Point::initAttributes() data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId()); + + data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId()); } //================================================================================================== @@ -64,7 +67,9 @@ void ConstructionPlugin_Point::execute() } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) { aShape = createByProjection(); } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) { - aShape = createByIntersection(); + aShape = createByLinesIntersection(); + } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) { + aShape = createByLineAndPlaneIntersection(); } if(aShape.get()) { @@ -137,7 +142,7 @@ std::shared_ptr ConstructionPlugin_Point::createByProjection() } //================================================================================================== -std::shared_ptr ConstructionPlugin_Point::createByIntersection() +std::shared_ptr ConstructionPlugin_Point::createByLinesIntersection() { // Get first line. AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE()); @@ -157,3 +162,25 @@ std::shared_ptr ConstructionPlugin_Point::createByIntersection() return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge); } + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByLineAndPlaneIntersection() +{ + // Get line. + AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE()); + GeomShapePtr aLineShape = aLineSelection->value(); + if(!aLineShape.get()) { + aLineShape = aLineSelection->context()->shape(); + } + std::shared_ptr anEdge(new GeomAPI_Edge(aLineShape)); + + // Get plane. + AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE()); + GeomShapePtr aPlaneShape = aPlaneSelection->value(); + if(!aPlaneShape.get()) { + aPlaneShape = aPlaneSelection->context()->shape(); + } + std::shared_ptr aFace(new GeomAPI_Face(aPlaneShape)); + + return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace); +} diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index b5619e7be..0881e97fc 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -66,6 +66,13 @@ public: return MY_CREATION_METHOD_ID; } + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION() + { + static const std::string MY_CREATION_METHOD_ID("by_line_and_plane_intersection"); + return MY_CREATION_METHOD_ID; + } + /// Attribute name for X coordinate. inline static const std::string& X() { @@ -87,7 +94,7 @@ public: return POINT_ATTR_Z; } - /// Attribute name for seleted edge. + /// Attribute name for selected edge. inline static const std::string& EDGE() { static const std::string ATTR_ID("edge"); @@ -129,20 +136,34 @@ public: return ATTR_ID; } - /// Attribute name for seleted first line. + /// Attribute name for selected first line. inline static const std::string& FIRST_LINE() { static const std::string ATTR_ID("first_line"); return ATTR_ID; } - /// Attribute name for seleted second line. + /// Attribute name for selected second line. inline static const std::string& SECOND_LINE() { static const std::string ATTR_ID("second_line"); return ATTR_ID; } + /// Attribute name for selected intersection line. + inline static const std::string& INTERSECTION_LINE() + { + static const std::string ATTR_ID("intersection_line"); + return ATTR_ID; + } + + /// Attribute name for selected intersection plane. + inline static const std::string& INTERSECTION_PLANE() + { + static const std::string ATTR_ID("intersection_plane"); + return ATTR_ID; + } + /// Creates a new part document if needed. CONSTRUCTIONPLUGIN_EXPORT virtual void execute(); @@ -163,7 +184,8 @@ private: std::shared_ptr createByXYZ(); std::shared_ptr createByDistanceOnEdge(); std::shared_ptr createByProjection(); - std::shared_ptr createByIntersection(); + std::shared_ptr createByLinesIntersection(); + std::shared_ptr createByLineAndPlaneIntersection(); }; diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp index 098485d0a..7c8fd6751 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp @@ -7,12 +7,17 @@ #include "ConstructionPlugin_Validators.h" #include +#include #include +#include #include #include +static std::shared_ptr getLin(const GeomShapePtr theShape); +static std::shared_ptr getPln(const GeomShapePtr theShape); + //================================================================================================== bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute, const std::list& theArguments, @@ -68,3 +73,94 @@ bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttr return true; } + +//================================================================================================== +bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid( + const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); + + AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front()); + + std::shared_ptr aLin; + std::shared_ptr aPln; + + GeomShapePtr aShape1 = anAttribute1->value(); + ResultPtr aContext1 = anAttribute1->context(); + if(!aContext1.get()) { + theError = "One of the attribute not initialized."; + return false; + } + if(!aShape1.get()) { + aShape1 = aContext1->shape(); + } + + GeomShapePtr aShape2 = anAttribute2->value(); + ResultPtr aContext2 = anAttribute2->context(); + if(!aContext2.get()) { + return true; + } + if(!aShape2.get()) { + aShape2 = aContext2->shape(); + } + + aLin = getLin(aShape1); + aPln = getPln(aShape2); + if(!aLin.get() || !aPln.get()) { + aLin = getLin(aShape2); + aPln = getPln(aShape1); + } + + if(!aLin.get() || !aPln.get()) { + theError = "Wrong shape types selected."; + return false; + } + + if(aPln->isParallel(aLin)) { + theError = "Plane and line are parallel."; + return false; + } + + return true; +} + +static std::shared_ptr getLin(const GeomShapePtr theShape) +{ + std::shared_ptr aLin; + + if(!theShape->isEdge()) { + return aLin; + } + + std::shared_ptr anEdge(new GeomAPI_Edge(theShape)); + + if(!anEdge->isLine()) { + return aLin; + } + + aLin = anEdge->line(); + + return aLin; +} + +static std::shared_ptr getPln(const GeomShapePtr theShape) +{ + std::shared_ptr aPln; + + if(!theShape->isFace()) { + return aPln; + } + + std::shared_ptr aFace(new GeomAPI_Face(theShape)); + + if(!aFace->isPlanar()) { + return aPln; + } + + aPln = aFace->getPlane(); + + return aPln; +} diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.h b/src/ConstructionPlugin/ConstructionPlugin_Validators.h index 85dc4a431..65fb54be5 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.h @@ -11,7 +11,7 @@ /// \class ConstructionPlugin_ValidatorPointLines /// \ingroup Validators -/// \brief A validator for selection lines for point by intersection.. +/// \brief A validator for selection lines for point by intersection. class ConstructionPlugin_ValidatorPointLines: public ModelAPI_AttributeValidator { public: @@ -24,4 +24,19 @@ public: Events_InfoMessage& theError) const; }; +/// \class ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel +/// \ingroup Validators +/// \brief A validator for selection line and plane for point by intersection.. +class ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel: public ModelAPI_AttributeValidator +{ +public: + //! \return True if the attribute is valid. + //! \param[in] theAttribute the checked attribute. + //! \param[in] theArguments arguments of the attribute. + //! \param[out] theError error message. + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const; +}; + #endif \ No newline at end of file diff --git a/src/ConstructionPlugin/Test/TestPoint.py b/src/ConstructionPlugin/Test/TestPoint.py index 272fe4d8e..e5a067323 100644 --- a/src/ConstructionPlugin/Test/TestPoint.py +++ b/src/ConstructionPlugin/Test/TestPoint.py @@ -22,18 +22,19 @@ aPoint = model.addPoint(aDocument, 50, 50, 50) aSession.finishOperation() assert (len(aPoint.result()) > 0) -# Create a sketch with line +# Create a sketch with lines aSession.startOperation() anOrigin = GeomAPI_Pnt(0, 0, 0) aDirX = GeomAPI_Dir(1, 0, 0) aNorm = GeomAPI_Dir(0, 0, 1) aSketch = model.addSketch(aDocument, GeomAPI_Ax3(anOrigin, aDirX, aNorm)) -aSketchLine = aSketch.addLine(25, 25, 100, 25) +aSketchLine1 = aSketch.addLine(0, 0, 100, 100) +aSketchLine2 = aSketch.addLine(0, 100, 100, 0) aSession.finishOperation() # Create a point on line aSession.startOperation() -aPoint = model.addPoint(aDocument, aSketchLine.result()[0], 50, True, False) +aPoint = model.addPoint(aDocument, aSketchLine1.result()[0], 25, True, False) aSession.finishOperation() assert (len(aPoint.result()) > 0) @@ -47,3 +48,15 @@ aSession.startOperation() aPoint = model.addPoint(aDocument, aPoint.result()[0], aPlane.result()[0]) aSession.finishOperation() assert (len(aPoint.result()) > 0) + +# Create a point by lines intersection +aSession.startOperation() +aPoint = model.addPoint(aDocument, aSketchLine1.result()[0], aSketchLine2.result()[0]) +aSession.finishOperation() +assert (len(aPoint.result()) > 0) + +# Create a point by line and plane intersection +aSession.startOperation() +aPoint = model.addPoint(aDocument, aSketchLine1.result()[0], aPlane.result()[0]) +aSession.finishOperation() +assert (len(aPoint.result()) > 0) diff --git a/src/ConstructionPlugin/icons/point_by_line_and_plane_intersection_32x32.png b/src/ConstructionPlugin/icons/point_by_line_and_plane_intersection_32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..d54a9c748c9ebe003ee9bd7c4da3ad0da2f986a4 GIT binary patch literal 994 zcmV<810DQ{P)N2bZe?^J zG%heMIczh2P5=M{U`a$lR9Hvtmsv=ZQ5453>bZxq)Fh}dS}Y=Zuni)|8P{~2aWbvZ zv<511OTt8LaY4%j6Ej09qD2Xf%BDpm@g>S4kydCWO4Bx?h=@9!bNTMa*UXvmn;x`> z4*cM||9j8<|F3suoEZZEKB1?$K2NZsH)L^|EbZKIu%b6)O)iY$uj^8_n; zLzbT*?j0I~!jK}1;`%(nik{Gxa&or-T%R{sk;Apn)T#+!Rb;l;8>~1SR6(Z1i88?7 z7)w}D57WZTlVkwbIbUE!Jp`_bojfW5WMP2uGJqn9;(ENniUe*v0}0izRAHG05dc}C zuo4MJjED(|Kq8SSBpQi9=<{O@5{DQ(nFk^75oz!TeqnLor`5tV&%W`IGarX^(SpVH zZD7bQg7EBOFy@qiDR&nvO4$MnlO15lDpog&$lDDe>l_feDHq~)RzQ4VC76+fqAIWy z?E_2ken>2-7T9*zz;Z{v?ETIKD5A*)XmYOa6v5?&NHy$ zY2}zBW=E+scOql8=JdhxoF=pCPqNKx3Mydl87HKa)(Rt9>mP0wW8%R1Zd_B&_7Vlh z+N60u;zz#P0B2}&b!H(rAH8*JCXMbl|40j-q70((B*ErX2ua#3#>Ae}PLBbOcK1P0 zlOPX+Gn!c}59k=$r1T((yDH{JtmP_X)}2ttt^w#8>aX2W$Esd-P@3OFCb$N;L6hst>)aYS z(yAI@YwdApe>ebnjm=Qnas@8jdkyxAddN9+%58mRYo|2-jLg)U%K#m;VBXpc@z$d| zosZCXt}PwrSU19KOBw_x*zwNocugB%dUO&57%f2W7Jp-cATYuT(;^cg&}3EhsrUj_ z%!y=Ia~U8@v&a{IYM#F#UlBUxC*%V{-qZ$B> z>3_QjK+oJ7J+Pu4(DaY5<=h%Qu%aIRg#h%sK>jqda%=R!iX#atjvO%NH*?fI+PtwM Q0ssI207*qoM6N<$f>&h01poj5 literal 0 HcmV?d00001 diff --git a/src/ConstructionPlugin/icons/point_by_planes_intersection_32x32.png b/src/ConstructionPlugin/icons/point_by_planes_intersection_32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..4c03323d3dc17fea9ba29fc675d5c3edceccec77 GIT binary patch literal 969 zcmV;)12+7LP)N2bZe?^J zG%heMIczh2P5=M{M@d9MR9HvtmDx*FQ5?tZFQ}ImEqX`{wW5gLgdSql%+eWWT*%24 zx12P~)J!WGl~K!F8n;TzTq%{xtxSX?sL=yHG;=^HFe%Nrs4mDy}Zaf(3{!ya+qvQfLsKF2{ldDDJoq8+`Rp|8SVA&xOqa zt`EKe*MLaKYV6|b*04FizSJBDJYC4ulwebU)an-48XOC4Pu_8LCH!-M8&BWU=8C%m zTwN(P-2rR55^xQI55bq9k_}*NzCD4Dni$ma8g-T+)<`XUw*syqVw@Y`Lf_!$E&HQk zdq_N}5;MR(F%#73CfbBoM8h~?0>6wr0c}S9ESUwMo5BC&849l97M;ujOmG8WQVh^G zG$Py)1odEJu~0|kSHj+uY@s%k)`GFATc~;98ZP89o(Yg72@qRUGqp`02jxBe+-7_a zbiVvV3D2tl?_)-xZh!F+ypCo``ozo_Bb|h0V)NxpOfc8UHfJ?-(p@8)gQCDm6AIob zMp`FVHG}W*Ty8ItR@2JN@o#%2`icWIqPWYDPIqJ3jAN*y37VlPnqvqS2*dfLU%@5Zco58u0c>SUuGVLf}>gwP5rO93m`bBLlh28@f@(a*Ws)o;qQCwY!G) z;A71K@d6~^AVd7tvP7)MoVzp~TU0$2S5)(x+>y!nk}JOq=W8bpnXmp#D69LCSXTc% zsiN^4a&6%C7uf*f0!22Fhc#UZO97Sw{Qm(K1F`2{0jz<|qMeKoR`BM{2kxL8EC9KV r6Lh>e^MyMo2L>SE&KJZS0POw%A39Brj0=?C00000NkvXXu0mjfhW4>; literal 0 HcmV?d00001 diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml index c489daaad..8f14af3b2 100644 --- a/src/ConstructionPlugin/point_widget.xml +++ b/src/ConstructionPlugin/point_widget.xml @@ -68,13 +68,13 @@ @@ -82,11 +82,33 @@ + + + + + + + + + + + diff --git a/src/GeomAPI/GeomAPI_Pln.cpp b/src/GeomAPI/GeomAPI_Pln.cpp index 8dcce0a70..4c26557cf 100644 --- a/src/GeomAPI/GeomAPI_Pln.cpp +++ b/src/GeomAPI/GeomAPI_Pln.cpp @@ -65,6 +65,18 @@ bool GeomAPI_Pln::isCoincident(const std::shared_ptr thePlane, cons return (aMyPln.Contains(anOtherPln.Location(), theTolerance) && aMyPln.Axis().IsParallel(anOtherPln.Axis(), theTolerance)); } +bool GeomAPI_Pln::isParallel(const std::shared_ptr theLine) +{ + std::shared_ptr aLineDir = theLine->direction()->xyz(); + std::shared_ptr aLineLoc = theLine->location()->xyz(); + + std::shared_ptr aNormal = direction()->xyz(); + std::shared_ptr aLocation = location()->xyz(); + + double aDot = aNormal->dot(aLineDir); + return Abs(aDot) < Precision::SquareConfusion(); +} + std::shared_ptr GeomAPI_Pln::intersect(const std::shared_ptr& theLine) const { std::shared_ptr aLineDir = theLine->direction()->xyz(); diff --git a/src/GeomAPI/GeomAPI_Pln.h b/src/GeomAPI/GeomAPI_Pln.h index 5c173838d..c3cd27e7f 100644 --- a/src/GeomAPI/GeomAPI_Pln.h +++ b/src/GeomAPI/GeomAPI_Pln.h @@ -56,6 +56,10 @@ class GeomAPI_Pln : public GeomAPI_Interface GEOMAPI_EXPORT bool isCoincident(const std::shared_ptr thePlane, const double theTolerance = 1.e-7); + /// Returns true if plane is parallel to theLine. + GEOMAPI_EXPORT + bool isParallel(const std::shared_ptr theLine); + /// Returns intersection point or empty if no intersections GEOMAPI_EXPORT std::shared_ptr intersect(const std::shared_ptr& theLine) const; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h index df42f8e3b..39175ee2e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h @@ -19,7 +19,7 @@ class GeomAlgoAPI_Boolean : public GeomAlgoAPI_MakeShape { public: /// Type of booelan operation - enum OperationType{ + enum OperationType { BOOL_CUT, ///< Cut objects BOOL_FUSE, ///< Fuse objects BOOL_COMMON ///< Take common part of objects diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp index 1c7e51bb7..e7414346d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp @@ -116,23 +116,16 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByProjection( return aVertex; } - std::shared_ptr aGeomPnt = theVertex->point(); - gp_Pnt aPnt = aGeomPnt->impl(); + std::shared_ptr aProjPnt = theVertex->point(); + std::shared_ptr aProjPln = thePlane->getPlane(); - std::shared_ptr aGeomPln = thePlane->getPlane(); - gp_Pln aPln = aGeomPln->impl(); + std::shared_ptr aPnt = aProjPln->project(aProjPnt); - gp_Dir aPntAxis = aPnt.XYZ() - aPln.Location().XYZ(); - gp_Dir aPlnNorm = aPln.Axis().Direction(); - - if(aPntAxis * aPlnNorm > 0) { - aPlnNorm.Reverse(); + if(!aPnt.get()) { + return aVertex; } - double aDistance = aPln.Distance(aPnt); - aPnt.Translate(gp_Vec(aPlnNorm) * aDistance); - - aVertex.reset(new GeomAPI_Vertex(aPnt.X(), aPnt.Y(), aPnt.Z())); + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); return aVertex; } @@ -161,3 +154,28 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByIntersection( return aVertex; } + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByIntersection( + const std::shared_ptr theEdge, + const std::shared_ptr theFace) +{ + std::shared_ptr aVertex; + + if(!theEdge.get() || !theFace.get() || !theEdge->isLine() || !theFace->isPlanar()) { + return aVertex; + } + + std::shared_ptr aLin = theEdge->line(); + std::shared_ptr aPln = theFace->getPlane(); + + std::shared_ptr aPnt = aPln->intersect(aLin); + + if(!aPnt.get()) { + return aVertex; + } + + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); + + return aVertex; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h index c9298401c..28703d91d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h @@ -55,6 +55,13 @@ public: static std::shared_ptr vertexByIntersection(const std::shared_ptr theEdge1, const std::shared_ptr theEdge2); + /// \brief Creates vertex by intersection line and plane. + /// \param[in] theEdge linear edge. + /// \param[in] theFace planar face. + /// \return created vertex. + static std::shared_ptr vertexByIntersection(const std::shared_ptr theEdge, + const std::shared_ptr theFace); + /// Return point by shape vertex static std::shared_ptr point(const std::shared_ptr theVertex); }; diff --git a/src/ModelHighAPI/ModelHighAPI_Macro.h b/src/ModelHighAPI/ModelHighAPI_Macro.h index 4e15701ad..944929e6b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Macro.h +++ b/src/ModelHighAPI/ModelHighAPI_Macro.h @@ -373,5 +373,56 @@ END_INIT() \ public: +//-------------------------------------------------------------------------------------- +#define INTERFACE_14(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2, \ + N_3, AN_3, T_3, C_3, \ + N_4, AN_4, T_4, C_4, \ + N_5, AN_5, T_5, C_5, \ + N_6, AN_6, T_6, C_6, \ + N_7, AN_7, T_7, C_7, \ + N_8, AN_8, T_8, C_8, \ + N_9, AN_9, T_9, C_9, \ + N_10, AN_10, T_10, C_10, \ + N_11, AN_11, T_11, C_11, \ + N_12, AN_12, T_12, C_12, \ + N_13, AN_13, T_13, C_13) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + DEFINE_ATTRIBUTE(N_3, T_3, C_3) \ + DEFINE_ATTRIBUTE(N_4, T_4, C_4) \ + DEFINE_ATTRIBUTE(N_5, T_5, C_5) \ + DEFINE_ATTRIBUTE(N_6, T_6, C_6) \ + DEFINE_ATTRIBUTE(N_7, T_7, C_7) \ + DEFINE_ATTRIBUTE(N_8, T_8, C_8) \ + DEFINE_ATTRIBUTE(N_9, T_9, C_9) \ + DEFINE_ATTRIBUTE(N_10, T_10, C_10) \ + DEFINE_ATTRIBUTE(N_11, T_11, C_11) \ + DEFINE_ATTRIBUTE(N_12, T_12, C_12) \ + DEFINE_ATTRIBUTE(N_13, T_13, C_13) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + SET_ATTRIBUTE(N_3, T_3, AN_3) \ + SET_ATTRIBUTE(N_4, T_4, AN_4) \ + SET_ATTRIBUTE(N_5, T_5, AN_5) \ + SET_ATTRIBUTE(N_6, T_6, AN_6) \ + SET_ATTRIBUTE(N_7, T_7, AN_7) \ + SET_ATTRIBUTE(N_8, T_8, AN_8) \ + SET_ATTRIBUTE(N_9, T_9, AN_9) \ + SET_ATTRIBUTE(N_10, T_10, AN_10) \ + SET_ATTRIBUTE(N_11, T_11, AN_11) \ + SET_ATTRIBUTE(N_12, T_12, AN_12) \ + SET_ATTRIBUTE(N_13, T_13, AN_13) \ + END_INIT() \ + public: + //-------------------------------------------------------------------------------------- #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_MACRO_H_ */ diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index ff2ba0479..1a7e90cc0 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -52,3 +52,21 @@ void ModelHighAPI_Selection::appendToList( return; } } + +//================================================================================================== +ModelHighAPI_Selection::VariantType ModelHighAPI_Selection::variantType() const +{ + return myVariantType; +} + +//================================================================================================== +ResultSubShapePair ModelHighAPI_Selection::resultSubShapePair() const +{ + return myResultSubShapePair; +} + +//================================================================================================== +TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const +{ + return myTypeSubShapeNamePair; +} diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.h b/src/ModelHighAPI/ModelHighAPI_Selection.h index 0be8642f7..2a7273319 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.h +++ b/src/ModelHighAPI/ModelHighAPI_Selection.h @@ -28,6 +28,12 @@ typedef std::pair TypeSubShapeNamePair; */ class ModelHighAPI_Selection { +public: + enum VariantType { + VT_ResultSubShapePair, + VT_TypeSubShapeNamePair + }; + public: /// Constructor for result and sub-shape MODELHIGHAPI_EXPORT @@ -49,8 +55,20 @@ public: MODELHIGHAPI_EXPORT virtual void appendToList(const std::shared_ptr & theAttribute) const; + /// \return variant type. + MODELHIGHAPI_EXPORT + virtual VariantType variantType() const; + + /// \return pair of result and sub-shape. + MODELHIGHAPI_EXPORT + virtual ResultSubShapePair resultSubShapePair() const; + + /// \return pair of sub-shape type and name. + MODELHIGHAPI_EXPORT + virtual TypeSubShapeNamePair typeSubShapeNamePair() const; + private: - enum VariantType { VT_ResultSubShapePair, VT_TypeSubShapeNamePair } myVariantType; + VariantType myVariantType; ResultSubShapePair myResultSubShapePair; TypeSubShapeNamePair myTypeSubShapeNamePair; }; -- 2.39.2