]> 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>
Mon, 9 Nov 2015 08:46:13 +0000 (11:46 +0300)
committernds <nds@opencascade.com>
Mon, 9 Nov 2015 08:46:13 +0000 (11:46 +0300)
Realization for Translation
WidgetPoint2d is corrected because multi translation can have equal points -> single end point value = full end point value when number of objects = 2.

src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/translate_32x32.png [new file with mode: 0755]
src/PartSet/icons/translate_full_32x32.png [new file with mode: 0755]
src/SketchPlugin/SketchPlugin_MultiTranslation.cpp
src/SketchPlugin/SketchPlugin_MultiTranslation.h
src/SketchPlugin/SketchPlugin_Tools.cpp
src/SketchPlugin/SketchPlugin_Tools.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_PropertyPanel.cpp

index 53b403e60a361c7903d76371ac0c02c5e219de84..8d9f07d31afe6579a720e41bc74e139c100b686f 100644 (file)
@@ -440,6 +440,10 @@ bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
                                                    double theX, double theY)
 {
   bool aPointIsFound = false;
+
+  if (feature()->getKind() != SketchPlugin_Line::ID())
+    return aPointIsFound;
+
   AttributePtr aWidgetAttribute = myFeature->attribute(attributeID());
 
   std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
index 25010c84876a271136a868f952b1b5d786ddbb1d..13a0a428f642010af71cabe5ad3d5f44370fd615 100644 (file)
@@ -55,6 +55,8 @@
      <file>icons/coincedence.png</file>
      <file>icons/mirror.png</file>
      <file>icons/translate.png</file>
+     <file>icons/translate_32x32.png</file>
+     <file>icons/translate_full_32x32.png</file>
      <file>icons/rotate.png</file>
      <file>icons/exec_state_failed.png</file>
      <file>icons/exec_state_invalid_parameters.png</file>
diff --git a/src/PartSet/icons/translate_32x32.png b/src/PartSet/icons/translate_32x32.png
new file mode 100755 (executable)
index 0000000..28f064b
Binary files /dev/null and b/src/PartSet/icons/translate_32x32.png differ
diff --git a/src/PartSet/icons/translate_full_32x32.png b/src/PartSet/icons/translate_full_32x32.png
new file mode 100755 (executable)
index 0000000..2f87688
Binary files /dev/null and b/src/PartSet/icons/translate_full_32x32.png differ
index 0db1082a168502602b4da20b81295c9e7846f48c..9c7994384d813b9e88d1afd2211e7c53c0b99ed1 100755 (executable)
@@ -5,6 +5,7 @@
 // Author:  Artem ZHIDKOV
 
 #include "SketchPlugin_MultiTranslation.h"
+#include "SketchPlugin_Tools.h"
 
 #include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
@@ -13,6 +14,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 #include <SketcherPrs_Factory.h>
 
 SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation()
+: myBlockValue(false)
 {
 }
 
 void SketchPlugin_MultiTranslation::initAttributes()
 {
+  data()->addAttribute(VALUE_TYPE(),   ModelAPI_AttributeString::typeId());
+
   data()->addAttribute(START_POINT_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(END_POINT_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(END_FULL_POINT_ID(), GeomDataAPI_Point2D::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());
@@ -56,9 +62,23 @@ void SketchPlugin_MultiTranslation::execute()
   if (!aStart || !aEnd || !aStart->isInitialized() || !aEnd->isInitialized())
     return;
 
+  if (attribute(END_POINT_ID())->isInitialized() && !attribute(END_FULL_POINT_ID())->isInitialized()) {
+    myBlockValue = true;
+    SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()),
+                                             attribute(END_FULL_POINT_ID()), aNbCopies, true);
+    myBlockValue = false;
+  }
+
+
   // make a visible points
   SketchPlugin_Sketch::createPoint2DResult(this, sketch(), START_POINT_ID(), 0);
-  SketchPlugin_Sketch::createPoint2DResult(this, sketch(), END_POINT_ID(), 1);
+
+  std::string aSecondPointAttributeID = END_POINT_ID();
+  AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE());
+  std::string aMethodType = aMethodTypeAttr->value();
+  if (aMethodType != "SingleValue")
+    aSecondPointAttributeID = END_FULL_POINT_ID();
+  SketchPlugin_Sketch::createPoint2DResult(this, sketch(), aSecondPointAttributeID, 1);
 
   std::shared_ptr<GeomAPI_XY> aShiftVec(new GeomAPI_XY(aEnd->x() - aStart->x(), aEnd->y() - aStart->y()));
 
@@ -252,4 +272,45 @@ void SketchPlugin_MultiTranslation::attributeChanged(const std::string& theID)
         data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear();
     }
   }
+  else if (theID == END_POINT_ID() && !myBlockValue) {
+    int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
+    if (aNbCopies > 0) {
+      myBlockValue = true;
+      SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()),
+                                               attribute(END_FULL_POINT_ID()), aNbCopies, true);
+      myBlockValue = false;
+      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+    }
+  }
+  else if (theID == END_FULL_POINT_ID() && !myBlockValue) {
+    int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
+    if (aNbCopies > 0) {
+      myBlockValue = true;
+      SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()),
+                                               attribute(END_POINT_ID()), aNbCopies, false);
+      myBlockValue = false;
+      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+    }
+  }
+  else if (theID == NUMBER_OF_OBJECTS_ID()) {
+    if (attribute(NUMBER_OF_OBJECTS_ID())->isInitialized() &&
+        attribute(END_POINT_ID())->isInitialized() &&
+        attribute(VALUE_TYPE())->isInitialized()) {
+      AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE());
+      std::string aMethodType = aMethodTypeAttr->value();
+      int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
+      if (aNbCopies > 0) {
+        myBlockValue = true;
+        if (aMethodType == "SingleValue")
+          SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()),
+                                                   attribute(END_FULL_POINT_ID()), aNbCopies, true);
+        else {
+          SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()),
+                                                   attribute(END_POINT_ID()), aNbCopies, false);
+        }
+        myBlockValue = false;
+        Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+      }
+    }
+  }
 }
index 967c60d186e0b951abb4aeae8d0495a2fc0b3472..ed9a8f878ff8e62880fcd8c74f7d53097e8490a6 100644 (file)
@@ -46,6 +46,13 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase
     return MY_TRANSLATION_LIST_ID;
   }
 
+  /// attribute name for first point
+  inline static const std::string& VALUE_TYPE()
+  {
+    static const std::string VALUE_TYPE_ATTR("ValueType");
+    return VALUE_TYPE_ATTR;
+  }
+
   /// Start point of translation
   inline static const std::string& START_POINT_ID()
   {
@@ -58,6 +65,13 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase
     static const std::string MY_END_POINT_ID("MultiTranslationEndPoint");
     return MY_END_POINT_ID;
   }
+  /// End point of translation
+  inline static const std::string& END_FULL_POINT_ID()
+  {
+    static const std::string MY_END_FULL_POINT_ID("MultiTranslationFullEndPoint");
+    return MY_END_FULL_POINT_ID;
+  }
+
   /// Total number of objects, initial and translated objects
   inline static const std::string& NUMBER_OF_OBJECTS_ID()
   {
@@ -83,6 +97,9 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase
 
 private:
   ObjectPtr copyFeature(ObjectPtr theObject);
+
+private:
+  bool myBlockValue; /// a boolean state to avoid recusive value change in attributeChanged
 };
 
 #endif
index 28d78bbd490f38abe1d06345eb2aa1dd7118c098..a9aa9d90c9227f17193f72ea945b42141ec2fd42 100644 (file)
@@ -121,4 +121,37 @@ void updateMultiAttribute(const AttributePtr& theFirstAngleAttribute,
     aDoubleSecondAttr->setValue(aValue/theValue);
 }
 
+void updateMultiAttribute(const AttributePtr& theFirstAttribute,
+                          const AttributePtr& theSecondAttribute,
+                          const AttributePtr& theModifiedAttribute,
+                          const int& theValue,
+                          const bool toMultiply)
+{
+  if (theValue == 0 || !theFirstAttribute->isInitialized()
+                    || !theSecondAttribute->isInitialized())
+    return;
+
+  std::shared_ptr<GeomDataAPI_Point2D> aFirstPoint = 
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFirstAttribute);
+  std::shared_ptr<GeomDataAPI_Point2D> aSecondPoint = 
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theSecondAttribute);
+  std::shared_ptr<GeomDataAPI_Point2D> aModifiedPoint = 
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theModifiedAttribute);
+
+  if (!aFirstPoint.get() || !aSecondPoint.get() || !aModifiedPoint.get())
+    return;
+
+  if (aFirstPoint->pnt()->isEqual(aSecondPoint->pnt()))
+    aModifiedPoint->setValue(aFirstPoint->pnt());
+  else {
+    double aDx = aSecondPoint->x() - aFirstPoint->x();
+    double aDy = aSecondPoint->y() - aFirstPoint->y();
+
+    double aX  = toMultiply ? aDx * theValue : aDx / theValue;
+    double anY = toMultiply ? aDy * theValue : aDy / theValue;
+
+    aModifiedPoint->setValue(aFirstPoint->x() + aX, aFirstPoint->y() + anY);
+  }
+}
+
 } // namespace SketchPlugin_Tools
index 17ab8b58f15521305df3345400bef0ed685e12f9..6b242532bb74ce7fdd5e443d9a42336c074f0ccc 100644 (file)
@@ -39,6 +39,17 @@ void updateMultiAttribute(const AttributePtr& theFirstAngleAttribute,
                           const int& theValue,
                           const bool toMultiply);
 
+/// Changes the second attribute value to be multiplied or divided by the given value.
+/// \param theFirstAngleAttribute the source attribute
+/// \param theSecondAngleAttribute the changed attribute
+/// \param theValue a value for modification
+/// \param toMultiply a type of modification
+void updateMultiAttribute(const AttributePtr& theFirstAttribute,
+                          const AttributePtr& theSecondAttribute,
+                          const AttributePtr& theModifiedAttribute,
+                          const int& theValue,
+                          const bool toMultiply);
+
 }; // namespace SketchPlugin_Tools
 
 #endif // SKETCHPLUGIN_TOOLS_H_
\ No newline at end of file
index 8d9939005b1f864660a92c0561e5a982e7d7c007..e728cf7cc7d982755e524c961e0aa119050888b5 100644 (file)
             use_external="true">
           <validator id="SketchPlugin_CopyValidator" />
         </sketch_multi_selector>
-        <groupbox title="Direction">
-          <sketch-2dpoint_selector
-              id="MultiTranslationStartPoint"
-              title="Start point"
-              tooltip="Start point of translation"/>
-          <sketch-2dpoint_selector
-              id="MultiTranslationEndPoint"
-              title="End point"
-              tooltip="Final point of translation"/>
-        </groupbox>
+        <toolbox id="ValueType">
+          <box id="SingleValue" title="Single value" icon=":icons/translate_32x32.png">
+            <groupbox title="Direction">
+              <sketch-2dpoint_selector
+                  id="MultiTranslationStartPoint"
+                  title="Start point"
+                  tooltip="Start point of translation"/>
+              <sketch-2dpoint_selector
+                  id="MultiTranslationEndPoint"
+                  title="End point"
+                  tooltip="Final point of translation"/>
+            </groupbox>
+          </box>
+          <box id="FullValue" title="Full value" icon=":icons/translate_full_32x32.png">
+            <groupbox title="Direction">
+              <sketch-2dpoint_selector
+                  id="MultiTranslationStartPoint"
+                  title="Start point"
+                  tooltip="Start point of translation"/>
+              <sketch-2dpoint_selector
+                  id="MultiTranslationFullEndPoint"
+                  title="End point"
+                  tooltip="Final point of translation"/>
+            </groupbox>
+          </box>
+        </toolbox>
         <integervalue id="MultiTranslationObjects"
             label="Total number of objects"
             tooltip="Total number of objects" 
index f447f24a20aa9cbdf610048ed72e2b2541ce1d45..f75ca242bb7db523fdb59c0a5120dc2d64077cc2 100755 (executable)
@@ -16,6 +16,9 @@
 #include <ModuleBase_PageBase.h>
 #include <ModuleBase_PageWidget.h>
 
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
 #include <QEvent>
 #include <QFrame>
 #include <QIcon>
@@ -154,12 +157,19 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
     activateWidget(NULL);
     return;
   }
+  ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+
   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
   bool isFoundWidget = false;
   activateWindow();
   for (; anIt != aLast; anIt++) {
+    ModuleBase_ModelWidget* aCurrentWidget = *anIt;
     if (isFoundWidget || !theWidget) {
-      if ((*anIt)->focusTo()) {
+
+      if (!aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID()))
+        continue; // this attribute is not participated in the current case
+
+      if (aCurrentWidget->focusTo()) {
         return;
       }
     }