From: vsv Date: Tue, 22 May 2018 08:20:31 +0000 (+0300) Subject: Task 2.3: Creation of Intersection X-Git-Tag: EDF_2018-1~33^2~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=62d90f590c1d7d2457887fe2ff9b76e07bd9b718;p=modules%2Fshaper.git Task 2.3: Creation of Intersection --- 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 000000000..5dc34484f Binary files /dev/null and b/src/SketchPlugin/icons/intersection.png differ 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 + + + + + + + + +