]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1649: Added options to create plane by rotation around axis;
authordbv <dbv@opencascade.com>
Thu, 14 Jul 2016 15:03:38 +0000 (18:03 +0300)
committerdbv <dbv@opencascade.com>
Thu, 14 Jul 2016 15:03:38 +0000 (18:03 +0300)
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
src/ConstructionPlugin/ConstructionPlugin_Plane.h
src/ConstructionPlugin/icons/angle.png [new file with mode: 0644]
src/ConstructionPlugin/plane_widget.xml

index 368bc32368a5d6e9c261f9ab8a5a455b4aa42a3e..ff3030055983dfbccfbeb00ca625b6145ea16dac 100644 (file)
@@ -9,9 +9,12 @@
 #include <Config_PropManager.h>
 
 #include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAlgoAPI_Rotation.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 
+#include <GeomAPI_Ax1.h>
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Pnt2d.h>
@@ -65,6 +68,8 @@ void ConstructionPlugin_Plane::initAttributes()
   data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(DISTANCE(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(COINCIDENT_POINT(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(AXIS(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(ANGLE(), ModelAPI_AttributeDouble::typeId());
 }
 
 //==================================================================================================
@@ -85,6 +90,8 @@ void ConstructionPlugin_Plane::execute()
       aShape = createByDistanceFromOther();
     } else if(aCreationMethodOption == CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
       aShape = createByCoincidentPoint();
+    } else if(aCreationMethodOption == CREATION_METHOD_BY_ROTATION()) {
+      aShape = createByRotation();
     }
   }
 
@@ -272,6 +279,41 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByCoincidentPoint
   return makeRectangularFace(aFace, aNewPln);
 }
 
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByRotation()
+{
+  // 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));
+
+  // Get axis.
+  AttributeSelectionPtr anAxisSelection = selection(AXIS());
+  GeomShapePtr anAxisShape = anAxisSelection->value();
+  if(!anAxisShape.get()) {
+    anAxisShape = anAxisSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(anAxisShape));
+
+  std::shared_ptr<GeomAPI_Ax1> anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
+                                                                                     anEdge->line()->direction()));
+
+  // Getting angle.
+  double anAngle = real(ANGLE())->value();
+
+  GeomAlgoAPI_Rotation aRotationAlgo(aFace, anAxis, anAngle);
+
+  std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face(aRotationAlgo.shape()));
+  std::shared_ptr<GeomAPI_Pln> aNewPln = aRes->getPlane();
+
+  aRes = makeRectangularFace(aRes, aNewPln);
+
+  return aRes;
+}
+
 //==================================================================================================
 GeomShapePtr faceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theV1,
                                  const std::shared_ptr<GeomAPI_Vertex> theV2,
index d92f00811d0f4b7468ce8c7343c22d773cae63ee..eb2ae37c4dcead206ad35afbb7eb21418e5cbb83 100644 (file)
@@ -166,6 +166,20 @@ public:
     return ATTR_ID;
   }
 
+  /// Attribute name for axis.
+  inline static const std::string& AXIS()
+  {
+    static const std::string ATTR_ID("axis");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for angle.
+  inline static const std::string& ANGLE()
+  {
+    static const std::string ATTR_ID("angle");
+    return ATTR_ID;
+  }
+
   /// Attribute name for a parameter for the general equation of a plane (ax+by+cz+d=0)
   inline static const std::string& A()
   {
@@ -213,6 +227,7 @@ protected:
   std::shared_ptr<GeomAPI_Shape> createByThreePoints();
   std::shared_ptr<GeomAPI_Shape> createByLineAndPoint();
   std::shared_ptr<GeomAPI_Shape> createByCoincidentPoint();
+  std::shared_ptr<GeomAPI_Shape> createByRotation();
   /// Creates a new plane by copy of face plane with translation along the normal
   /// to the specified distance.
   std::shared_ptr<GeomAPI_Shape> createByDistanceFromOther();
diff --git a/src/ConstructionPlugin/icons/angle.png b/src/ConstructionPlugin/icons/angle.png
new file mode 100644 (file)
index 0000000..e401acd
Binary files /dev/null and b/src/ConstructionPlugin/icons/angle.png differ
index 6c8e2f9667d54a4c90145257b3968406d4b8b1e5..4162ebfdd55cb7254618556c4f995a04f5ff3cd8 100644 (file)
              title="By rotation"
              tooltip="Plane by rotation around axis."
              icon="icons/Construction/plane_by_rotation_32x32.png">
+          <shape_selector id="axis"
+                          label="Axis"
+                          tooltip="Select line for axis."
+                          icon="icons/Construction/axis.png"
+                          shape_types="edge">
+            <validator id="GeomValidators_ShapeType" parameters="line"/>
+          </shape_selector>
+          <doublevalue id="angle"
+                       label="Angle"
+                       tooltip="Angle for rotation around axis."
+                       icon="icons/Construction/angle.png"
+                       default="0"/>
         </box>
       </toolbox>
     </box>