From 62d90f590c1d7d2457887fe2ff9b76e07bd9b718 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 22 May 2018 11:20:31 +0300 Subject: [PATCH] Task 2.3: Creation of Intersection --- src/GeomAPI/GeomAPI_Edge.cpp | 29 +++++++++++++++++++++++ src/GeomAPI/GeomAPI_Edge.h | 7 ++++++ src/PartSet/PartSet_Module.cpp | 1 + src/PartSet/PartSet_Validators.cpp | 11 +++++++++ src/PartSet/PartSet_Validators.h | 9 +++++++ src/SketchPlugin/CMakeLists.txt | 2 ++ src/SketchPlugin/SketchPlugin_Plugin.cpp | 3 +++ src/SketchPlugin/icons/intersection.png | Bin 0 -> 577 bytes src/SketchPlugin/plugin-Sketch.xml | 22 ++++++++++++++++- 9 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/SketchPlugin/icons/intersection.png diff --git a/src/GeomAPI/GeomAPI_Edge.cpp b/src/GeomAPI/GeomAPI_Edge.cpp index cf6197337..8c219972d 100644 --- a/src/GeomAPI/GeomAPI_Edge.cpp +++ b/src/GeomAPI/GeomAPI_Edge.cpp @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include #include @@ -280,6 +282,33 @@ bool GeomAPI_Edge::isInPlane(std::shared_ptr thePlane) const return inPlane; } +std::list> GeomAPI_Edge::intersectWithPlane( + const std::shared_ptr thePlane) const +{ + std::list aResList; + double aFirst, aLast; + const TopoDS_Shape& aShape = const_cast(this)->impl(); + Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); + if (!aCurve.IsNull()) { + double A, B, C, D; + thePlane->coefficients(A, B, C, D); + gp_Pln aPln(A, B, C, D); + + Handle(Geom_Plane) aPlane = new Geom_Plane(aPln); + GeomAPI_IntCS aIntersect; + aIntersect.Perform(aCurve, aPlane); + if (aIntersect.IsDone() && (aIntersect.NbPoints() > 0)) { + gp_Pnt aPnt; + for (int i = 1; i <= aIntersect.NbPoints(); i++) { + aPnt = aIntersect.Point(i); + std::shared_ptr aPntPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z())); + aResList.push_back(aPntPtr); + } + } + } + return aResList; +} + double GeomAPI_Edge::length() const { const TopoDS_Edge& anEdge = TopoDS::Edge(impl()); diff --git a/src/GeomAPI/GeomAPI_Edge.h b/src/GeomAPI/GeomAPI_Edge.h index e7d4910f1..2827c2f0d 100644 --- a/src/GeomAPI/GeomAPI_Edge.h +++ b/src/GeomAPI/GeomAPI_Edge.h @@ -90,9 +90,16 @@ public: void getRange(double& theFirst, double& theLast) const; /// Returns true, if the edge is fully placed in the specified plane + /// \param thePlane a plane for intersection GEOMAPI_EXPORT bool isInPlane(const std::shared_ptr thePlane) const; + /// Returns list of intersection points if the edge has intersections with the given plane + /// \param thePlane a plane for intersection + GEOMAPI_EXPORT + std::list> + intersectWithPlane(const std::shared_ptr thePlane) const; + /// Returns edge length. GEOMAPI_EXPORT double length() const; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 704cf46a9..a28587f5b 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -264,6 +264,7 @@ void PartSet_Module::registerValidators() new PartSet_MultyTranslationSelection); aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection); aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection); + aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection); } //****************************************************** diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index b2f95ddd3..49f89d9c0 100755 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -407,6 +407,17 @@ bool PartSet_ProjectionSelection::isValid(const ModuleBase_ISelection* theSelect } } +bool PartSet_IntersectionSelection::isValid(const ModuleBase_ISelection* theSelection, + ModuleBase_Operation* theOperation) const +{ + if (theSelection->getSelected(ModuleBase_ISelection::Viewer).size() == 0) { + return isEmptySelectionValid(theOperation); + } else { + int aCount = shapesNbLines(theSelection); + return aCount == 0; + } +} + std::string PartSet_DifferentObjectsValidator::errorMessage( const PartSet_DifferentObjectsValidator::ErrorType& theType, diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index 039d259ca..c1fd7eaee 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -188,6 +188,15 @@ public: ModuleBase_Operation* theOperation) const; }; +//! \ingroup Validators +//! A class to validate a selection for intersection operation +class PartSet_IntersectionSelection : public ModuleBase_SelectionValidator +{ +public: + PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection, + ModuleBase_Operation* theOperation) const; +}; + ////////////// Attribute validators //////////////// diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 4fa4f8c0f..519741bec 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -66,6 +66,7 @@ SET(PROJECT_HEADERS SketchPlugin_Tools.h SketchPlugin_Trim.h SketchPlugin_Validators.h + SketchPlugin_Intersection.h ) SET(PROJECT_SOURCES @@ -111,6 +112,7 @@ SET(PROJECT_SOURCES SketchPlugin_Tools.cpp SketchPlugin_Trim.cpp SketchPlugin_Validators.cpp + SketchPlugin_Intersection.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index a392b6ef7..4ea4a6a18 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -208,6 +209,8 @@ FeaturePtr SketchPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new SketchPlugin_Arc); } else if (theFeatureID == SketchPlugin_Projection::ID()) { return FeaturePtr(new SketchPlugin_Projection); + } else if (theFeatureID == SketchPlugin_Intersection::ID()) { + return FeaturePtr(new SketchPlugin_Intersection); } else if (theFeatureID == SketchPlugin_ConstraintCoincidence::ID()) { return FeaturePtr(new SketchPlugin_ConstraintCoincidence); } else if (theFeatureID == SketchPlugin_ConstraintCollinear::ID()) { diff --git a/src/SketchPlugin/icons/intersection.png b/src/SketchPlugin/icons/intersection.png new file mode 100644 index 0000000000000000000000000000000000000000..5dc34484f39f873049bd86c181eb4f17fa7efe14 GIT binary patch literal 577 zcmV-H0>1r;P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;2FkAZe8V00FT{L_t(IPhDw^QN)os_%INx24M_w z7z5~6E_t8G^~wP;`+@iX5Fe8E2zxB!6?UIbLG>{kzu-qD-^ddxfw9M-_@ul~#4fl2 z3cgWG{VLjibZyxGzk9<0I1b4w`7bOf{l9+U`v1L~4*l=jeE5I=mc##}nd|T<@$^N#_>6yB;AA4L6(D@ey()R>c87=y!^ivC<#)q`RX$;25H`S`N{wF zmmdFLfAP`(br&A~k8hv$0~l7@U|wecI^{Ibv|m8{Q_3Uchm?EpcPY1^Z_*yYUx5Mm zS=KA;ldO062RZME_du7v1>ze(R|~=ofHA-v1_l-&UJt~Jk;U<0R1O0}HxPpo3k$M1 zK8#>6Fk}Gnbs!c&RzL_t2nGfZAbt+S8t4iLVGsbN@y9@HgG~W`{GR~;jKwXR$9hH@ P00000NkvXXu0mjf6w2?U literal 0 HcmV?d00001 diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 366b8b63b..89a471f41 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -27,7 +27,7 @@ email : webmaster.salome@opencascade.com + + + + + + + + + -- 2.39.2