]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task 2.3: Creation of Intersection
authorvsv <vsv@opencascade.com>
Tue, 22 May 2018 08:20:31 +0000 (11:20 +0300)
committervsv <vsv@opencascade.com>
Tue, 22 May 2018 08:20:49 +0000 (11:20 +0300)
src/GeomAPI/GeomAPI_Edge.cpp
src/GeomAPI/GeomAPI_Edge.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_Validators.h
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/icons/intersection.png [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml

index cf6197337c8ee80f4af7f39fea46cc2cf8dd55d2..8c219972d3c459f931cd1262f5393debaf2a5505 100644 (file)
@@ -38,6 +38,8 @@
 #include <Geom_Line.hxx>
 #include <Geom_Circle.hxx>
 #include <Geom_Ellipse.hxx>
+#include <Geom_Plane.hxx>
+#include <GeomAPI_IntCS.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <gp_Ax1.hxx>
 #include <gp_Pln.hxx>
@@ -280,6 +282,33 @@ bool GeomAPI_Edge::isInPlane(std::shared_ptr<GeomAPI_Pln> thePlane) const
   return inPlane;
 }
 
+std::list<std::shared_ptr<GeomAPI_Pnt>> GeomAPI_Edge::intersectWithPlane(
+  const std::shared_ptr<GeomAPI_Pln> thePlane) const
+{
+  std::list<GeomPointPtr> aResList;
+  double aFirst, aLast;
+  const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+  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<GeomAPI_Pnt> 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<TopoDS_Shape>());
index e7d4910f1deb0eda3ea05d810e485b2f4396d4ed..2827c2f0dbd0b96a4530196094cc4526dfbed245 100644 (file)
@@ -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<GeomAPI_Pln> 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<std::shared_ptr<GeomAPI_Pnt>>
+    intersectWithPlane(const std::shared_ptr<GeomAPI_Pln> thePlane) const;
+
   /// Returns edge length.
   GEOMAPI_EXPORT
   double length() const;
index 704cf46a944d1a05d37f44d1a2e3024abbd71e9e..a28587f5b278b1b7e8cae90d93f553bfabd0d7fe 100755 (executable)
@@ -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);
 }
 
 //******************************************************
index b2f95ddd3f665a4bc4871e814c7ba1e63996cd8b..49f89d9c033ac2a308aade1b1a558a10846ac122 100755 (executable)
@@ -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,
index 039d259ca9536dec339feab3d2f9cfb4b592225d..c1fd7eaee43b6cad787e7fd699fe72f23077f871 100644 (file)
@@ -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 ////////////////
 
 
index 4fa4f8c0fa0f068aa86d00609488ba6aabafce61..519741bec563ecd201847cb82cd0a945f70a7218 100644 (file)
@@ -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
index a392b6ef74c1536958545b24cd07f46460f5fbce..4ea4a6a1838cee8d93283ec991f033b511797551 100644 (file)
@@ -26,6 +26,7 @@
 #include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Projection.h>
+#include <SketchPlugin_Intersection.h>
 #include <SketchPlugin_ConstraintAngle.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintCollinear.h>
@@ -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 (file)
index 0000000..5dc3448
Binary files /dev/null and b/src/SketchPlugin/icons/intersection.png differ
index 366b8b63b8f8bafc4f8ca50b51e19149e1e3d194..89a471f414ae0c9641d21a4f7bb03f11dc6d7353 100644 (file)
@@ -27,7 +27,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
         nested="SketchPoint SketchIntersectionPoint SketchLine
                 SketchCircle SketchMacroCircle SketchArc SketchMacroArc
                 SketchRectangle
-                SketchProjection
+                SketchProjection SketchIntersection
                 SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintDistanceHorizontal SketchConstraintDistanceVertical
                 SketchConstraintParallel SketchConstraintPerpendicular
                 SketchConstraintRigid SketchConstraintHorizontal SketchConstraintVertical
@@ -488,6 +488,26 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
         <boolvalue id="IncludeToResult" label="Include into the sketch result" default="true" tooltip="Include projected feature into the sketch result"/>
         <validator id="PartSet_ProjectionSelection"/>
       </feature>
+
+      <!-- Intersection feature -->
+      <feature
+        id="SketchIntersection"
+        title="Intersection"
+        tooltip="Intersect edge with sketch plane"
+        icon="icons/Sketch/intersection.png">
+        <sketch_shape_selector
+              id="ExternalFeature"
+              label="Object"
+              tooltip="Select external edge."
+              shape_types="edge"
+              use_external="true"
+              can_create_external="false"
+              use_sketch_plane="false">
+          <validator id="SketchPlugin_ProjectionValidator"/>
+        </sketch_shape_selector>
+        <boolvalue id="IncludeToResult" label="Include into the sketch result" default="true" tooltip="Include projected feature into the sketch result"/>
+        <validator id="PartSet_IntersectionSelection"/>
+      </feature>
     </group>
 
     <group id="Replication">