Salome HOME
Feature #534: 5.01. Body placement by 3D rotation in respect to axis
authordbv <dbv@opencascade.com>
Fri, 5 Jun 2015 16:55:25 +0000 (19:55 +0300)
committerdbv <dbv@opencascade.com>
Fri, 5 Jun 2015 16:55:43 +0000 (19:55 +0300)
src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp
src/FeaturesPlugin/FeaturesPlugin_Rotation.h
src/FeaturesPlugin/boolean_widget.xml
src/FeaturesPlugin/plugin-Features.xml
src/FeaturesPlugin/rotation_widget.xml
src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/rotation.png [new file with mode: 0644]

index 8493688f1bdd59653cd5341f854c94f7e85c69ed..154e5cfa4f0c32829423f900b814c164820752c3 100755 (executable)
@@ -8,8 +8,14 @@
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Session.h>
 
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+
+#define _ROTATED_TAG 1
+
 //=================================================================================================
 FeaturesPlugin_Rotation::FeaturesPlugin_Rotation()
 {
@@ -20,16 +26,93 @@ void FeaturesPlugin_Rotation::initAttributes()
 {
   AttributeSelectionListPtr aSelection = 
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
-    FeaturesPlugin_Rotation::LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
+    FeaturesPlugin_Rotation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
   // revolution works with faces always
   aSelection->setSelectionType("SOLID");
 
   data()->addAttribute(FeaturesPlugin_Rotation::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
-
   data()->addAttribute(FeaturesPlugin_Rotation::ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
 }
 
 //=================================================================================================
 void FeaturesPlugin_Rotation::execute()
 {
+  // Getting objects.
+  ListOfShape anObjects;
+  AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Rotation::OBJECTS_LIST_ID());
+  if (anObjectsSelList->size() == 0) {
+    return;
+  }
+  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
+    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
+    if(!anObject.get()) {
+      return;
+    }
+    anObjects.push_back(anObject);
+  }
+
+  //Getting axe.
+  std::shared_ptr<GeomAPI_Ax1> anAxis;
+  std::shared_ptr<GeomAPI_Edge> anEdge;
+  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_Rotation::AXIS_OBJECT_ID());
+  if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
+  }
+  if(anEdge) {
+    anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
+  }
+
+  // Getting angle.
+  double anAngle = real(FeaturesPlugin_Rotation::ANGLE_ID())->value();
+
+  // Rotating each object.
+  int aResultIndex = 0;
+  for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
+    std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
+    GeomAlgoAPI_Rotation aRotationAlgo(aBaseShape, anAxis, anAngle);
+
+    // Checking that the algorithm worked properly.
+    if(!aRotationAlgo.isDone()) {
+      static const std::string aFeatureError = "Rotation algorithm failed";
+      setError(aFeatureError);
+      break;
+    }
+    if(aRotationAlgo.shape()->isNull()) {
+      static const std::string aShapeError = "Resulting shape is Null";
+      setError(aShapeError);
+      break;
+    }
+    if(!aRotationAlgo.isValid()) {
+      std::string aFeatureError = "Warning: resulting shape is not valid";
+      setError(aFeatureError);
+      break;
+    }
+
+    // Setting result.
+    ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+    LoadNamingDS(aRotationAlgo, aResultBody, aBaseShape);
+    setResult(aResultBody, aResultIndex);
+    aResultIndex++;
+  }
+
+  // Remove the rest results if there were produced in the previous pass.
+  removeResults(aResultIndex);
+}
+
+void FeaturesPlugin_Rotation::LoadNamingDS(const GeomAlgoAPI_Rotation& theRotaionAlgo,
+                                           std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+                                           std::shared_ptr<GeomAPI_Shape> theBaseShape)
+{
+  // Store result.
+  theResultBody->storeModified(theBaseShape, theRotaionAlgo.shape());
+
+  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theRotaionAlgo.mapOfShapes();
+
+  int aRotatedTag = 1;
+  std::string aRotatedName = "Rotated";
+  theResultBody->loadAndOrientModifiedShapes(theRotaionAlgo.makeShape().get(),
+                                             theBaseShape, GeomAPI_Shape::FACE,
+                                             aRotatedTag, aRotatedName, *aSubShapes.get());
+
 }
index b8a65d6fff726fbd5aa4b4edb5da4fc476ad81ca..57316316603250344466403abca713cc1103d097 100755 (executable)
 
 #include <ModelAPI_Feature.h>
 
+#include <GeomAlgoAPI_Rotation.h>
+
 /** \class FeaturesPlugin_Rotation
  *  \ingroup Plugins
- *  \brief Feature for creation of revolution from the planar face.
- *  Revolution creates the lateral faces based on edges of the base face and
- *  the start and end faces and/or start and end angles.
+ *  \brief Feature for rotation objects around the axis.
  */
 class FeaturesPlugin_Rotation : public ModelAPI_Feature
 {
  public:
-  /// Revolution kind.
+  /// Rotation kind.
   inline static const std::string& ID()
   {
-    static const std::string MY_REVOLUTION_ID("Rotation");
-    return MY_REVOLUTION_ID;
+    static const std::string MY_ROTATION_ID("Rotation");
+    return MY_ROTATION_ID;
   }
 
-  /// Attribute name of references sketch entities list, it should contain a sketch result or
-  /// a pair a sketch result to sketch face.
-  inline static const std::string& LIST_ID()
+  /// Attribute name of referenced objects.
+  inline static const std::string& OBJECTS_LIST_ID()
   {
-    static const std::string MY_GROUP_LIST_ID("base");
-    return MY_GROUP_LIST_ID;
+    static const std::string MY_OBJECTS_LIST_ID("main_objects");
+    return MY_OBJECTS_LIST_ID;
   }
 
-  /// Attribute name of an object to which the extrusion grows.
+  /// Attribute name of an axis.
   inline static const std::string& AXIS_OBJECT_ID()
   {
-    static const std::string MY_TO_OBJECT_ID("axis_object");
-    return MY_TO_OBJECT_ID;
+    static const std::string MY_AXIS_OBJECT_ID("axis_object");
+    return MY_AXIS_OBJECT_ID;
   }
 
-  /// Attribute name of revolution angle.
+  /// Attribute name of angle.
   inline static const std::string& ANGLE_ID()
   {
-    static const std::string MY_TO_ANGLE_ID("angle");
-    return MY_TO_ANGLE_ID;
+    static const std::string MY_ANGLE_ID("angle");
+    return MY_ANGLE_ID;
   }
 
   /// \return the kind of a feature.
@@ -64,6 +63,11 @@ class FeaturesPlugin_Rotation : public ModelAPI_Feature
 
   /// Use plugin manager for features creation.
   FeaturesPlugin_Rotation();
+
+private:
+  void LoadNamingDS(const GeomAlgoAPI_Rotation& theRotaionAlgo,
+                    std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+                    std::shared_ptr<GeomAPI_Shape> theBaseShape);
 };
 
 #endif
index 76c854b460fbe63f847530c7833b75f33ac5f7a4..22d958ccaf8a05e841ab17ecff88b4354727955b 100644 (file)
@@ -2,9 +2,9 @@
 
 <source>
   <multi_selector id="main_objects"
-    label="Main object"
+    label="Main objects"
     icon=":icons/cut_shape.png"
-    tooltip="Select an object solid"
+    tooltip="Select a solid objects"
     type_choice="Solids"
     concealment="true">
     <validator id="PartSet_DifferentObjects"/>
     <validator id="PartSet_DifferentObjects"/>
     <validator id="GeomValidators_ShapeType" parameters="solid"/>
   </multi_selector>
-  <!--<shape_selector id="main_object"
-    label="Main object"
-    icon=":icons/cut_shape.png"
-    tooltip="Select an object solid"
-    shape_types="solid"
-    concealment="true"
-  />
-  <shape_selector id="tool_object" 
-    label="Tool object" 
-    icon=":icons/cut_tool.png" 
-    tooltip="Select a tool solid"
-    shape_types="solid"
-    concealment="true" >
-       <validator id="PartSet_DifferentObjects"/>
-  </shape_selector>-->
   <choice id="bool_type" 
     label="Type" 
     tooltip="Type of boolean operation"
index c6f0a65f361b869a231a6748d3b748757a9266a5..312570f68c4ea0d9b6474f7aeab8652ebacd03df 100644 (file)
       <feature id="Placement" title="Placement" tooltip="Perform moving of an object to specified position" icon=":icons/placement.png">
           <source path="placement_widget.xml"/>
       </feature>
-      <!--Modification for specification of 1.3.0
-      <feature id="Rotation" title="Movement" tooltip="" icon=":icons/placement.png">
+      <feature id="Rotation" title="Rotation" tooltip="Perform rotation of an objects around the axis to specified angle" icon=":icons/rotation.png">
         <source path="rotation_widget.xml"/>
       </feature>
+      <!--Modification for specification of 1.3.0
       <feature id="ExtrusionCut" title="RevolutionCut" tooltip="" icon=":icons/placement.png">
         <source path="extrusioncut_widget.xml"/>
       </feature>-->
index 2b38c9a7ca8d8d30f583e85f84eb9d03b8365fbc..367f3bb0afe5fbd2c84f61d9112418fc51014758 100755 (executable)
@@ -1,11 +1,12 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
-  <multi_selector id="base"
-    label="Select a sketch face"
+  <multi_selector id="main_objects"
+    label="Main objects"
     icon=":icons/cut_shape.png"
-    tooltip="Select a sketch face"
-    type_choice="Solids">
+    tooltip="Select a solid objects"
+    type_choice="Solids"
+    concealment="true">
   </multi_selector>
   <shape_selector id="axis_object"
                   icon=":icons/axis.png"
                   tooltip="Select an edge for axis"
                   shape_types="edge"
                   default="">
+    <validator id="GeomValidators_ShapeType" parameters="line"/>
   </shape_selector>
   <doublevalue
     id="angle"
     label="Angle"
-    min="0"
+    min="-360"
+    max="360"
     step="1.0"
     default="0"
     icon=":icons/radius.png"
index f165e5aa829efb4b484528408610e9266418b905..81c3ca6e334a4437cd96dd53cac39a819636df1b 100644 (file)
@@ -18,7 +18,9 @@ GeomAlgoAPI_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSou
                                            std::shared_ptr<GeomAPI_Ax1>   theAxis,
                                            double                         theAngle)
 : myDone(false),
-  myShape(new GeomAPI_Shape())
+  myShape(new GeomAPI_Shape()),
+  myMap(new GeomAPI_DataMapOfShapeShape()),
+  myMkShape(new GeomAlgoAPI_MakeShape())
 {
   build(theSourceShape, theAxis, theAngle);
 }
@@ -48,7 +50,6 @@ void GeomAlgoAPI_Rotation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
     return;
   }
 
-  setImpl(aBuilder);
   myDone = aBuilder->IsDone() == Standard_True;
 
   if(!myDone) {
@@ -60,11 +61,11 @@ void GeomAlgoAPI_Rotation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
   for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
     std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
     aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
-    myMap.bind(aCurrentShape, aCurrentShape);
+    myMap->bind(aCurrentShape, aCurrentShape);
   }
 
   myShape->setImpl(new TopoDS_Shape(aResult));
-  myMkShape = new GeomAlgoAPI_MakeShape(aBuilder);
+  myMkShape->setImpl(aBuilder);
 }
 
 //=================================================================================================
@@ -91,21 +92,13 @@ const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Rotation::shape() const
 }
 
 //=================================================================================================
-void GeomAlgoAPI_Rotation::mapOfShapes(GeomAPI_DataMapOfShapeShape& theMap) const
+std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Rotation::mapOfShapes() const
 {
-  theMap = myMap;
+  return myMap;
 }
 
 //=================================================================================================
-GeomAlgoAPI_MakeShape* GeomAlgoAPI_Rotation::makeShape() const
+std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Rotation::makeShape() const
 {
   return myMkShape;
 }
-
-//=================================================================================================
-GeomAlgoAPI_Rotation::~GeomAlgoAPI_Rotation()
-{
-  if (myImpl) {
-    myMap.clear();
-  }
-}
index 3f77f21593c63df5f8c0a9fa7e5bba6e9b2b8196..079fe75aa62a75a520ac3ad4e25999b2a0b6a9e5 100644 (file)
@@ -43,13 +43,10 @@ public:
   GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& shape() const;
 
   /// \return map of sub-shapes of the result. To be used for History keeping.
-  GEOMALGOAPI_EXPORT void  mapOfShapes(GeomAPI_DataMapOfShapeShape& theMap) const;
+  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfShapes() const;
 
   /// \return interface for for History processing.
-  GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape() const;
-
-  /// Destructor.
-  GEOMALGOAPI_EXPORT virtual ~GeomAlgoAPI_Rotation();
+  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape() const;
 
 private:
   /// Builds resulting shape.
@@ -61,8 +58,8 @@ private:
   /// Fields.
   bool myDone;
   std::shared_ptr<GeomAPI_Shape> myShape;
-  GeomAPI_DataMapOfShapeShape    myMap;
-  GeomAlgoAPI_MakeShape*         myMkShape;
+  std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
+  std::shared_ptr<GeomAlgoAPI_MakeShape> myMkShape;
 };
 
 #endif
index 1f679d3247efb759dd69ce8b019b0723f362fb8a..89a55518b6dd8bf67497e303ba3a7d754b50afca 100644 (file)
@@ -53,5 +53,6 @@
      <file>icons/activate.png</file>
      <file>icons/deactivate.png</file>
      <file>icons/edit.png</file>
+     <file>icons/rotation.png</file>
  </qresource>
  </RCC>
diff --git a/src/PartSet/icons/rotation.png b/src/PartSet/icons/rotation.png
new file mode 100644 (file)
index 0000000..7905fa1
Binary files /dev/null and b/src/PartSet/icons/rotation.png differ