]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added option to create Construction Point by intersection of line and plane.
authordbv <dbv@opencascade.com>
Tue, 12 Jul 2016 13:26:30 +0000 (16:26 +0300)
committerdbv <dbv@opencascade.com>
Tue, 12 Jul 2016 13:26:45 +0000 (16:26 +0300)
19 files changed:
src/ConstructionAPI/ConstructionAPI_Point.cpp
src/ConstructionAPI/ConstructionAPI_Point.h
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.h
src/ConstructionPlugin/ConstructionPlugin_Validators.cpp
src/ConstructionPlugin/ConstructionPlugin_Validators.h
src/ConstructionPlugin/Test/TestPoint.py
src/ConstructionPlugin/icons/point_by_line_and_plane_intersection_32x32.png [new file with mode: 0644]
src/ConstructionPlugin/icons/point_by_planes_intersection_32x32.png [new file with mode: 0644]
src/ConstructionPlugin/point_widget.xml
src/GeomAPI/GeomAPI_Pln.cpp
src/GeomAPI/GeomAPI_Pln.h
src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h
src/ModelHighAPI/ModelHighAPI_Macro.h
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h

index 738703a6e19b16270d3114aabc938606016405cd..ef2ccc8100f05a2b888c5aa240aa8b23197d84e3 100644 (file)
@@ -6,8 +6,16 @@
 
 #include "ConstructionAPI_Point.h"
 
+#include <GeomAPI_Shape.h>
+
+#include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
 
+#include <algorithm>
+
+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<ModelAPI_Feature>& theFeature)
 : ModelHighAPI_Interface(theFeature)
@@ -47,9 +55,19 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feat
 : ModelHighAPI_Interface(theFeature)
 {
   if(initialize()) {
-    /// If first object is vertex and second object is face then set by projection.
-    /// TODO: check
-    setByProjection(theObject1, theObject2);
+    GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
+    GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
+
+    if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
+      // If first object is vertex and second object is face then set by projection.
+      setByProjection(theObject1, theObject2);
+    } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
+      // If both objects are edges then set by lines intersection.
+      setByLinesIntersection(theObject1, theObject2);
+    } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
+      // If first object is edge and second object is face then set by line and plane intersection.
+      setByLineAndPlaneIntersection(theObject1, theObject2);
+    }
   }
 }
 
@@ -89,11 +107,33 @@ void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& th
 
 //==================================================================================================
 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
-                                            const ModelHighAPI_Selection& thePlane)
+                                            const ModelHighAPI_Selection& theFace)
 {
   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
   fillAttribute(theVertex, mypoint);
-  fillAttribute(thePlane, myplane);
+  fillAttribute(theFace, myplane);
+
+  execute();
+}
+
+//==================================================================================================
+void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
+                                                   const ModelHighAPI_Selection& theEdge2)
+{
+  fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod);
+  fillAttribute(theEdge1, myfirstLine);
+  fillAttribute(theEdge2, mysecondLine);
+
+  execute();
+}
+
+//==================================================================================================
+void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
+                                                          const ModelHighAPI_Selection& theFace)
+{
+  fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
+  fillAttribute(theEdge, myintersectionLine);
+  fillAttribute(theFace, myintersectionPlane);
 
   execute();
 }
@@ -130,3 +170,63 @@ PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
   std::shared_ptr<ModelAPI_Feature> 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;
+}
index ab9f83837c72f6469c0604e1c293f06ffe547754..612df30753685f73857ca68f134df08d0aeb6b68 100644 (file)
@@ -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.
index 63d7308d204bc4008f7c0de549daafce1ebb6491..e9f202998ff660e70e8717db21e5cac216ced14c 100644 (file)
@@ -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);
index 22f91d732f9e2cb0d6677cb379eb1b3b8ef3c9d8..c3866c52d629e6cb054fc0606364b5ed7b9fbccb 100644 (file)
@@ -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<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
 }
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByIntersection()
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersection()
 {
   // Get first line.
   AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
@@ -157,3 +162,25 @@ std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByIntersection()
 
   return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
 }
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
+{
+  // Get line.
+  AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
+  GeomShapePtr aLineShape = aLineSelection->value();
+  if(!aLineShape.get()) {
+    aLineShape = aLineSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Edge> 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<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
+
+  return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);
+}
index b5619e7becfb34f6d6a402ef596be94ee87a4c92..0881e97fc1ba65fcf044dc3a2560caca7f6e0ef5 100644 (file)
@@ -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<GeomAPI_Vertex> createByXYZ();
   std::shared_ptr<GeomAPI_Vertex> createByDistanceOnEdge();
   std::shared_ptr<GeomAPI_Vertex> createByProjection();
-  std::shared_ptr<GeomAPI_Vertex> createByIntersection();
+  std::shared_ptr<GeomAPI_Vertex> createByLinesIntersection();
+  std::shared_ptr<GeomAPI_Vertex> createByLineAndPlaneIntersection();
 
 };
 
index 098485d0a000381d778367735ff4eadda8ac030b..7c8fd6751849ab5fe53528bb4ecf45458cc65357 100644 (file)
@@ -7,12 +7,17 @@
 #include "ConstructionPlugin_Validators.h"
 
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_Face.h>
 #include <GeomAPI_Lin.h>
+#include <GeomAPI_Pln.h>
 
 #include <ModelAPI_AttributeSelection.h>
 
 #include <Events_InfoMessage.h>
 
+static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
+static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
+
 //==================================================================================================
 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
                                                      const std::list<std::string>& theArguments,
@@ -68,3 +73,94 @@ bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttr
 
   return true;
 }
+
+//==================================================================================================
+bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& theArguments,
+    Events_InfoMessage& theError) const
+{
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+
+  AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
+
+  std::shared_ptr<GeomAPI_Lin> aLin;
+  std::shared_ptr<GeomAPI_Pln> 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<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
+{
+  std::shared_ptr<GeomAPI_Lin> aLin;
+
+  if(!theShape->isEdge()) {
+    return aLin;
+  }
+
+  std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
+
+  if(!anEdge->isLine()) {
+    return aLin;
+  }
+
+  aLin = anEdge->line();
+
+  return aLin;
+}
+
+static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
+{
+  std::shared_ptr<GeomAPI_Pln> aPln;
+
+  if(!theShape->isFace()) {
+    return aPln;
+  }
+
+  std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
+
+  if(!aFace->isPlanar()) {
+    return aPln;
+  }
+
+  aPln = aFace->getPlane();
+
+  return aPln;
+}
index 85dc4a431187f4c776033e8780b8b8d828975ace..65fb54be5d0b07a3ead7800a9d425f52a74f6b6f 100644 (file)
@@ -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<std::string>& theArguments,
+                        Events_InfoMessage& theError) const;
+};
+
 #endif
\ No newline at end of file
index 272fe4d8e7db3dc9114ac0e031adc86ecbf72f07..e5a067323f229737e23caa658a5e1e7523655480 100644 (file)
@@ -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 (file)
index 0000000..d54a9c7
Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_line_and_plane_intersection_32x32.png differ
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 (file)
index 0000000..4c03323
Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_planes_intersection_32x32.png differ
index c489daaad365e99417a4811f3760672e8970ebf1..8f14af3b2f199780812bf2d6a157e25e48bb1c6f 100644 (file)
       </shape_selector>
     </box>
     <box id="by_lines_intersection"
-         title="By intersection"
+         title="By two lines intersection"
          tooltip="Point by intersection of two coplanar lines."
          icon="icons/Construction/point_by_lines_intersection_32x32.png">
       <shape_selector id="first_line"
                       label="First line"
                       tooltip="First line."
-                      icon="icons/Construction/point.png"
+                      icon="icons/Construction/edge.png"
                       shape_types="edge">
         <validator id="GeomValidators_ShapeType" parameters="line"/>
         <validator id="ConstructionPlugin_ValidatorPointLines" parameters="second_line"/>
       <shape_selector id="second_line"
                       label="Second line"
                       tooltip="Second line."
-                      icon="icons/Construction/point.png"
+                      icon="icons/Construction/edge.png"
                       shape_types="edge">
         <validator id="GeomValidators_ShapeType" parameters="line"/>
         <validator id="ConstructionPlugin_ValidatorPointLines" parameters="first_line"/>
       </shape_selector>
     </box>
+    <box id="by_line_and_plane_intersection"
+         title="By line and plane intersection"
+         tooltip="Point by intersection of line and plane."
+         icon="icons/Construction/point_by_line_and_plane_intersection_32x32.png">
+      <shape_selector id="intersection_line"
+                      label="Line"
+                      tooltip="Line for intersection."
+                      icon="icons/Construction/edge.png"
+                      shape_types="edge">
+        <validator id="GeomValidators_ShapeType" parameters="line"/>
+        <validator id="ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel" parameters="intersection_plane"/>
+      </shape_selector>
+      <shape_selector id="intersection_plane"
+                      label="Plane"
+                      tooltip="Plane for intersection."
+                      icon="icons/Construction/face.png"
+                      shape_types="face">
+        <validator id="GeomValidators_Face" parameters="plane"/>
+        <validator id="ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel" parameters="intersection_line"/>
+      </shape_selector>
+    </box>
+
   </toolbox>
 </source>
index 8dcce0a701aca40d6bc7748a6b3404dddcaecccf..4c26557cfe13d693aeb49dfe28dbf25b80e9efa4 100644 (file)
@@ -65,6 +65,18 @@ bool GeomAPI_Pln::isCoincident(const std::shared_ptr<GeomAPI_Pln> thePlane, cons
   return (aMyPln.Contains(anOtherPln.Location(), theTolerance) && aMyPln.Axis().IsParallel(anOtherPln.Axis(), theTolerance));
 }
 
+bool GeomAPI_Pln::isParallel(const std::shared_ptr<GeomAPI_Lin> theLine)
+{
+  std::shared_ptr<GeomAPI_XYZ> aLineDir = theLine->direction()->xyz();
+  std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
+
+  std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
+  std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
+
+  double aDot = aNormal->dot(aLineDir);
+  return Abs(aDot) < Precision::SquareConfusion();
+}
+
 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pln::intersect(const std::shared_ptr<GeomAPI_Lin>& theLine) const
 {
   std::shared_ptr<GeomAPI_XYZ> aLineDir = theLine->direction()->xyz();
index 5c173838dcdfbac5a2b370daabb1ee4fdd52d1f2..c3cd27e7fa6b5d467e399f8adc28556b75f7b3d4 100644 (file)
@@ -56,6 +56,10 @@ class GeomAPI_Pln : public GeomAPI_Interface
   GEOMAPI_EXPORT
   bool isCoincident(const std::shared_ptr<GeomAPI_Pln> thePlane, const double theTolerance = 1.e-7);
 
+  /// Returns true if plane is parallel to theLine.
+  GEOMAPI_EXPORT
+  bool isParallel(const std::shared_ptr<GeomAPI_Lin> theLine);
+
   /// Returns intersection point or empty if no intersections
   GEOMAPI_EXPORT
   std::shared_ptr<GeomAPI_Pnt> intersect(const std::shared_ptr<GeomAPI_Lin>& theLine) const;
index df42f8e3b33cf724673eaf9b0538adb38a899a52..39175ee2e6a1f45de9442bcdd39a6edd65cb5706 100644 (file)
@@ -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
index 1c7e51bb733736e6a38729c46e5475da71890640..e7414346d08c7f64a1aa29025c088ba04a39a8e0 100644 (file)
@@ -116,23 +116,16 @@ std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
     return aVertex;
   }
 
-  std::shared_ptr<GeomAPI_Pnt> aGeomPnt = theVertex->point();
-  gp_Pnt aPnt = aGeomPnt->impl<gp_Pnt>();
+  std::shared_ptr<GeomAPI_Pnt> aProjPnt = theVertex->point();
+  std::shared_ptr<GeomAPI_Pln> aProjPln = thePlane->getPlane();
 
-  std::shared_ptr<GeomAPI_Pln> aGeomPln = thePlane->getPlane();
-  gp_Pln aPln = aGeomPln->impl<gp_Pln>();
+  std::shared_ptr<GeomAPI_Pnt> 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<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByIntersection(
 
   return aVertex;
 }
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByIntersection(
+    const std::shared_ptr<GeomAPI_Edge> theEdge,
+    const std::shared_ptr<GeomAPI_Face> theFace)
+{
+  std::shared_ptr<GeomAPI_Vertex> aVertex;
+
+  if(!theEdge.get() || !theFace.get() || !theEdge->isLine() || !theFace->isPlanar()) {
+    return aVertex;
+  }
+
+  std::shared_ptr<GeomAPI_Lin> aLin = theEdge->line();
+  std::shared_ptr<GeomAPI_Pln> aPln = theFace->getPlane();
+
+  std::shared_ptr<GeomAPI_Pnt> aPnt = aPln->intersect(aLin);
+
+  if(!aPnt.get()) {
+    return aVertex;
+  }
+
+  aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
+
+  return aVertex;
+}
index c9298401c65d160b9af2704e684520a114752d03..28703d91da9a85132f5277f91308e411b9661da4 100644 (file)
@@ -55,6 +55,13 @@ public:
   static std::shared_ptr<GeomAPI_Vertex> vertexByIntersection(const std::shared_ptr<GeomAPI_Edge> theEdge1,
                                                               const std::shared_ptr<GeomAPI_Edge> 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<GeomAPI_Vertex> vertexByIntersection(const std::shared_ptr<GeomAPI_Edge> theEdge,
+                                                              const std::shared_ptr<GeomAPI_Face> theFace);
+
   /// Return point by shape vertex
   static std::shared_ptr<GeomAPI_Pnt> point(const std::shared_ptr<GeomAPI_Shape> theVertex);
 };
index 4e15701addcdc8b2d10008694c0742246ad99742..944929e6b2b8ae2de2c32b5572e5d5b37176a1c4 100644 (file)
     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_ */
index ff2ba0479b00db32db1335b15ce5b883f250890e..1a7e90cc0391f88be5ce50a3cb4bd60c77f85eda 100644 (file)
@@ -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;
+}
index 0be8642f78557c541dfe43b96d6d6ed0f2e2eec3..2a72733197c78190291cd789f8c0827845a054fe 100644 (file)
@@ -28,6 +28,12 @@ typedef std::pair<std::string, std::string> 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<ModelAPI_AttributeSelectionList> & 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;
 };