]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#816 In multi-rotation, be able to put the total angle or the step angle (Rotation...
authornds <nds@opencascade.com>
Fri, 6 Nov 2015 15:49:02 +0000 (18:49 +0300)
committernds <nds@opencascade.com>
Fri, 6 Nov 2015 15:49:26 +0000 (18:49 +0300)
It must also be possible to enter the full angle value of the multi-rotation, with a toggle button defining the semantic of the angle value (either full rotation or between two consecutive repetitions).
For consistency, it should be the same for multi-translation.

src/PartSet/PartSet_icons.qrc
src/PartSet/icons/angle_up_full_32x32.png [new file with mode: 0755]
src/SketchPlugin/SketchPlugin_MultiRotation.cpp
src/SketchPlugin/SketchPlugin_MultiRotation.h
src/SketchPlugin/SketchPlugin_Tools.cpp
src/SketchPlugin/SketchPlugin_Tools.h
src/SketchPlugin/plugin-Sketch.xml

index cf582520c56dc6b91925899bc091ff348422158f..25010c84876a271136a868f952b1b5d786ddbb1d 100644 (file)
@@ -69,6 +69,7 @@
      <file>icons/angle_up_32x32.png</file>
      <file>icons/angle_up_down.png</file>
      <file>icons/angle_up_down_32x32.png</file>
+     <file>icons/angle_up_full_32x32.png</file>
      <file>icons/dimension_up_down.png</file>
      <file>icons/dimension_up_down_32x32.png</file>
      <file>icons/by_two_points_32x32.png</file>
diff --git a/src/PartSet/icons/angle_up_full_32x32.png b/src/PartSet/icons/angle_up_full_32x32.png
new file mode 100755 (executable)
index 0000000..fdcde01
Binary files /dev/null and b/src/PartSet/icons/angle_up_full_32x32.png differ
index 6f3c0c8c737223bf4c20d76d90cf045ba236e1bc..e58b5d267e75fc274a217b5c8d3d5bea588c62b1 100755 (executable)
@@ -5,9 +5,11 @@
 // Author:  Artem ZHIDKOV
 
 #include "SketchPlugin_MultiRotation.h"
+#include "SketchPlugin_Tools.h"
 
 #include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
 #define PI 3.1415926535897932
 
 SketchPlugin_MultiRotation::SketchPlugin_MultiRotation()
+: myBlockAngle(true)
 {
 }
 
 void SketchPlugin_MultiRotation::initAttributes()
 {
   data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
+
+  data()->addAttribute(ANGLE_TYPE(),   ModelAPI_AttributeString::typeId());
   data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ANGLE_FULL_ID(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(NUMBER_OF_OBJECTS_ID(), ModelAPI_AttributeInteger::typeId());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId());
@@ -59,11 +65,20 @@ void SketchPlugin_MultiRotation::execute()
       attribute(CENTER_ID()));
   if (!aCenter || !aCenter->isInitialized())
     return;
+
+  if (attribute(ANGLE_ID())->isInitialized() && !attribute(ANGLE_FULL_ID())->isInitialized()) {
+    myBlockAngle = true;
+    SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()),
+                                             aNbCopies, true);
+    myBlockAngle = false;
+  }
+
   // make a visible points
   SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0);
 
   double anAngle = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
-      attribute(ANGLE_ID()))->value();
+                                                             attribute(ANGLE_ID()))->value();
+
   // Convert angle to radians
   anAngle *= PI / 180.0;
 
@@ -310,4 +325,41 @@ void SketchPlugin_MultiRotation::attributeChanged(const std::string& theID)
         data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear();
     }
   }
+  else if (theID == ANGLE_ID() && !myBlockAngle) {
+    int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
+    if (aNbCopies > 0) {
+      myBlockAngle = true;
+      SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()),
+                                               aNbCopies, true);
+      myBlockAngle = false;
+      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+    }
+  }
+  else if (theID == ANGLE_FULL_ID() && !myBlockAngle) {
+    int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
+    if (aNbCopies > 0) {
+      myBlockAngle = true;
+      SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_FULL_ID()), attribute(ANGLE_ID()),
+                                               aNbCopies, false);
+      myBlockAngle = false;
+      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+    }
+  }
+  else if (theID == NUMBER_OF_OBJECTS_ID()) {
+    AttributeStringPtr aMethodTypeAttr = string(ANGLE_TYPE());
+    std::string aMethodType = aMethodTypeAttr->value();
+    int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
+    if (aNbCopies > 0) {
+      myBlockAngle = true;
+      if (aMethodType == "SingleAngle")
+        SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()),
+                                                 aNbCopies, true);
+      else
+        SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_FULL_ID()), attribute(ANGLE_ID()),
+                                                 aNbCopies, false);
+
+      myBlockAngle = false;
+      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+    }
+  }
 }
index 7fd3cf14a333c3ee48f4980c27bb56ece585dfd2..416f477b14ef26bfe20fb94fbb89ad319e53dbd5 100644 (file)
@@ -52,12 +52,26 @@ class SketchPlugin_MultiRotation : public SketchPlugin_ConstraintBase
     static const std::string MY_CENTER_ID("MultiRotationCenter");
     return MY_CENTER_ID;
   }
+  /// attribute name for first point
+  inline static const std::string& ANGLE_TYPE()
+  {
+    static const std::string ANGLE_TYPE_ATTR("AngleType");
+    return ANGLE_TYPE_ATTR;
+  }
+
   /// End point of translation
   inline static const std::string& ANGLE_ID()
   {
     static const std::string MY_ANGLE_ID("MultiRotationAngle");
     return MY_ANGLE_ID;
   }
+  /// End point of translation
+  inline static const std::string& ANGLE_FULL_ID()
+  {
+    static const std::string MY_ANGLE_FULL_ID("MultiRotationFullAngle");
+    return MY_ANGLE_FULL_ID;
+  }
+
   /// Total number of objects, initial and translated objects
   inline static const std::string& NUMBER_OF_OBJECTS_ID()
   {
@@ -85,6 +99,11 @@ private:
   ObjectPtr copyFeature(ObjectPtr theObject);
   void rotateFeature(ObjectPtr theInitial, ObjectPtr theTarget,
                      double theCenterX, double theCenterY, double theAngle);
+
+  bool updateFullAngleValue();
+
+private:
+  bool myBlockAngle; /// a boolean state to avoid recusive angle change in attributeChanged
 };
 
 #endif
index 82c5a3f93986c9c07d3857e797771ec59f7cdc52..e73349ef3486a0b58ed47779555dba6a4f34c659 100644 (file)
@@ -101,4 +101,24 @@ void findCoincidences(const FeaturePtr theStartCoin,
   }
 }
 
+void updateAngleAttribute(const AttributePtr& theFirstAngleAttribute,
+                          const AttributePtr& theSecondAngleAttribute,
+                          const int& theNumberOfCopies,
+                          const bool toFullAngle)
+{
+  if (theNumberOfCopies == 0)
+    return;
+
+  AttributeDoublePtr aDoubleFirstAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+                                                                theFirstAngleAttribute);
+  double aValue = aDoubleFirstAttr->value();
+
+  AttributeDoublePtr aDoubleSecondAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+                                                                theSecondAngleAttribute);
+  if (toFullAngle)
+    aDoubleSecondAttr->setValue(aValue*theNumberOfCopies);
+  else
+    aDoubleSecondAttr->setValue(aValue/theNumberOfCopies);
+}
+
 } // namespace SketchPlugin_Tools
index 9637b5d09929120b118aed70ff96f9b048ae0614..79a4d62b8d182f8dac329be072680baa0acd4b11 100644 (file)
@@ -10,6 +10,7 @@
 #include <GeomAPI_Pnt2d.h>
 
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Attribute.h>
 
 namespace SketchPlugin_Tools {
 
@@ -28,6 +29,17 @@ void findCoincidences(const FeaturePtr theStartCoin,
                       const std::string& theAttr,
                       std::set<FeaturePtr>& theList);
 
+/// Changes the second attribute value to full or single angle. If it is corrected to full
+/// value, the first angle is miltipied to the number of copies otherwise it is separated by it.
+/// \param theFirstAngleAttribute the source attribute
+/// \param theSecondAngleAttribute the changed attribute
+/// \param theNumberOfCopies a value for modification
+/// \param toFullAngle a type of modification
+void updateAngleAttribute(const AttributePtr& theFirstAngleAttribute,
+                          const AttributePtr& theSecondAngleAttribute,
+                          const int& theNumberOfCopies,
+                          const bool toFullAngle);
+
 }; // namespace SketchPlugin_Tools
 
 #endif // SKETCHPLUGIN_TOOLS_H_
\ No newline at end of file
index d8c4ede48e67a5657f3edd503ab44ce6fb4905da..8d9939005b1f864660a92c0561e5a982e7d7c007 100644 (file)
             title="Center of rotation"
             tooltip="Center of rotation"
             default="0"/>
-        <point2dangle id="MultiRotationAngle"
+        <toolbox id="AngleType">
+          <box id="SingleAngle" title="Single angle" icon=":icons/angle_up_32x32.png">
+            <point2dangle id="MultiRotationAngle"
                          first_point="MultiRotationCenter"
                          label="Angle"
                          icon=":icons/angle.png"
                          tooltip="Rotation angle"
                          default="90"/>
+          </box>
+          <box id="FullAngle" title="Full angle" icon=":icons/angle_up_full_32x32.png">
+            <point2dangle id="MultiRotationFullAngle"
+                         first_point="MultiRotationCenter"
+                         label="Full angle"
+                         icon=":icons/angle.png"
+                         tooltip="Rotation angle"/>
+          </box>
+        </toolbox>
         <integervalue id="MultiRotationObjects"
             label="Total number of objects"
             tooltip="Total number of objects"