]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1650: Added option to create axis by plane and point.
authordbv <dbv@opencascade.com>
Fri, 15 Jul 2016 15:01:29 +0000 (18:01 +0300)
committerdbv <dbv@opencascade.com>
Fri, 15 Jul 2016 15:01:29 +0000 (18:01 +0300)
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Axis.h
src/ConstructionPlugin/axis_widget.xml

index 876b7989712649ba7906319340c82c94031ddbcd..1dad21a9360dc5bb32b4ad7c52e35ac9804c6e1b 100644 (file)
@@ -18,6 +18,7 @@
 #include <ModelAPI_Validator.h>
 
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_Pln.h>
 #include <GeomAPI_Vertex.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_PointBuilder.h>
@@ -71,6 +72,10 @@ void ConstructionPlugin_Axis::initAttributes()
 
   /// Attributes for axis by line.
   data()->addAttribute(LINE(), ModelAPI_AttributeSelection::typeId());
+
+  /// Attributes for axis by plane and point.
+  data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
 }
 
 void ConstructionPlugin_Axis::createAxisByTwoPoints()
@@ -181,6 +186,40 @@ void ConstructionPlugin_Axis::createAxisByLine()
   setResult(aConstr);
 }
 
+void ConstructionPlugin_Axis::createAxisByPlaneAndPoint()
+{
+  // Get face.
+  AttributeSelectionPtr aFaceSelection = selection(PLANE());
+  GeomShapePtr aFaceShape = aFaceSelection->value();
+  if(!aFaceShape.get()) {
+    aFaceShape = aFaceSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aFaceShape));
+  std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
+
+  // Get point.
+  AttributeSelectionPtr aPointSelection = selection(POINT());
+  GeomShapePtr aPointShape = aPointSelection->value();
+  if(!aPointShape.get()) {
+    aPointShape = aPointSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+  std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+
+  std::shared_ptr<GeomAPI_Pnt> aProjPnt = aPln->project(aPnt);
+
+  if(aProjPnt->isEqual(aPnt)) {
+    aPnt->translate(aPln->direction(), 10);
+  }
+
+  std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aProjPnt, aPnt);
+
+  ResultConstructionPtr aConstr = document()->createConstruction(data());
+  aConstr->setInfinite(true);
+  aConstr->setShape(anEdge);
+  setResult(aConstr);
+}
+
 void ConstructionPlugin_Axis::execute()
 {
   AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
@@ -195,7 +234,8 @@ void ConstructionPlugin_Axis::execute()
     createAxisByDimensions();
   } else if(aMethodType == CREATION_METHOD_BY_LINE()) {
     createAxisByLine();
-
+  } else if(aMethodType == CREATION_METHOD_BY_PLANE_AND_POINT()) {
+    createAxisByPlaneAndPoint();
   }
 }
 
index c0116e81c712c73f3e09a4a34a6a0efd70705fc9..0a1eb5de8abc7382d5a04cf2764bc86a4e4c7234 100644 (file)
@@ -49,6 +49,13 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
     return METHOD_ATTR;
   }
 
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_PLANE_AND_POINT()
+  {
+    static const std::string METHOD_ATTR("by_plane_and_point");
+    return METHOD_ATTR;
+  }
+
   /// attribute name for first point
   inline static const std::string& POINT_FIRST()
   {
@@ -114,6 +121,20 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
     return ATTR_ID;
   }
 
+  /// Attribute name for plane.
+  inline static const std::string& PLANE()
+  {
+    static const std::string ATTR_ID("plane");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for point.
+  inline static const std::string& POINT()
+  {
+    static const std::string ATTR_ID("point");
+    return ATTR_ID;
+  }
+
   /// Returns a minimal length for axis
   inline static const double MINIMAL_LENGTH() { return 1.e-5; }
 
@@ -143,6 +164,7 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
   /// Creates a new axis by point and direction
   void createAxisByPointAndDirection();
   void createAxisByLine();
+  void createAxisByPlaneAndPoint();
 };
 
 
index 243d0c7947185b30123fd42eb2acd0b8fed88eed..e2e6ac47dcad662d25de67431af3b44f66756876 100644 (file)
         <validator id="GeomValidators_ShapeType" parameters="line"/>
       </shape_selector>
     </box>
+    <box id="by_plane_and_point" title="By plane and point" icon="icons/Construction/axis_by_plane_and_point_32x32.png">
+      <shape_selector id="plane"
+                      label="Plane"
+                      tooltip="Select a planar face."
+                      icon="icons/Construction/face.png"
+                      shape_types="face">
+        <validator id="GeomValidators_Face" parameters="plane"/>
+      </shape_selector>
+      <shape_selector id="point"
+                      label="Point"
+                      tooltip="Select point."
+                      icon="icons/Construction/point.png"
+                      shape_types="vertex">
+      </shape_selector>
+    </box>
   </toolbox>
   
 </source>