]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1302 Restricting preselection to the first argument only: mirror feature has...
authornds <nds@opencascade.com>
Thu, 10 Mar 2016 10:53:09 +0000 (13:53 +0300)
committernds <nds@opencascade.com>
Thu, 10 Mar 2016 10:53:09 +0000 (13:53 +0300)
src/Config/Config_Keywords.h
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/ModuleBase/ModuleBase_OperationFeature.h
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_Tools.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_Workshop.cpp

index e26ba0aa42a52416e45d5037b233628d980d4be2..daacdbf8b5ccf5f4758708e6f964fa0fddfcc0ba 100644 (file)
@@ -71,6 +71,7 @@ const static char* ATTR_INTERNAL = "internal";
 const static char* ATTR_OBLIGATORY = "obligatory";
 const static char* ATTR_CONCEALMENT = "concealment";
 const static char* ATTR_USE_RESET = "use_reset";
+const static char* ATTR_GREED = "greed";
 
 // WDG_INFO properties
 const static char* INFO_WDG_TEXT = FEATURE_TEXT;
index cee58efb0a8fb83405f8d6148ad3acbb3ba6694d..294d0f037812315cf2085d3c4c9cbb70b89d4b94 100755 (executable)
@@ -15,6 +15,7 @@
 #include "ModuleBase_IPropertyPanel.h"
 #include "ModuleBase_ISelection.h"
 #include "ModuleBase_IViewer.h"
+#include "ModuleBase_Tools.h"
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Document.h>
@@ -330,33 +331,55 @@ bool ModuleBase_OperationFeature::commit()
   return false;
 }
 
-void ModuleBase_OperationFeature::activateByPreselection()
+void ModuleBase_OperationFeature::activateByPreselection(ModuleBase_IWorkshop* theWorkshop)
 {
   if (myPreSelection.empty())
     return;
 
   ModuleBase_ISelection::filterSelectionOnEqualPoints(myPreSelection);
 
-  ModuleBase_ModelWidget* aFilledWgt = 0;
+  std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(theWorkshop, myFeature);
+
   ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
+  ModuleBase_ModelWidget* aFilledWgt = 0;
   if (aPropertyPanel) {
     const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
+    QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+    ModuleBase_ModelWidget* aWgt = 0;
     if (!aWidgets.empty()) {
-      ModuleBase_ModelWidget* aWgt = 0;
-      QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
-      bool isSet = false;
-      // 1. apply the selection to controls
-      for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
-        aWgt = (*aWIt);
-        if (!aWgt->canSetValue())
-          continue;
-        aPropertyPanel->setPreselectionWidget(aWgt);
-        if (!aWgt->setSelection(myPreSelection, true)) {
-          isSet = false;
-          break;
-        } else {
-          isSet = true;
-          aFilledWgt = aWgt;
+      if (!aGreedAttributeId.empty()) {
+        // set preselection to greed widget
+        for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
+          aWgt = (*aWIt);
+          if (aWgt->attributeID() == aGreedAttributeId) {
+            aPropertyPanel->setPreselectionWidget(aWgt);
+            aWgt->setSelection(myPreSelection, true);
+            aPropertyPanel->setPreselectionWidget(NULL);
+            break;
+          }
+        }
+        // activate first not greed widget
+        std::string aFirstAttributeId = aWidgets.front()->attributeID();
+        if (aFirstAttributeId == aGreedAttributeId) // activate next widget after greeded
+          aFilledWgt = aWidgets.front();
+        else
+          aFilledWgt = NULL; // activate first widget of the panel
+      }
+      else {
+        bool isSet = false;
+        // 1. apply the selection to controls
+        for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
+          aWgt = (*aWIt);
+          if (!aWgt->canSetValue())
+            continue;
+          aPropertyPanel->setPreselectionWidget(aWgt);
+          if (!aWgt->setSelection(myPreSelection, true)) {
+            isSet = false;
+            break;
+          } else {
+            isSet = true;
+            aFilledWgt = aWgt;
+          }
         }
       }
       aPropertyPanel->setPreselectionWidget(NULL);
@@ -371,9 +394,9 @@ void ModuleBase_OperationFeature::activateByPreselection()
       if (aFilledWgt)
         emit activatedByPreselection();
     }
-    // 4. activate the next obligatory widget
-    aPropertyPanel->activateNextWidget(aFilledWgt);
   }
+  // 4. activate the next obligatory widget
+  aPropertyPanel->activateNextWidget(aFilledWgt);
 
   clearPreselection();
 }
index 4f96cd56e284f39548a13f599555d8e5cfe76eda..c2411b8841c217e385aac9398afe09d614b7d9ab 100755 (executable)
@@ -26,6 +26,7 @@
 class ModuleBase_ModelWidget;
 class ModuleBase_ISelection;
 class ModuleBase_IViewer;
+class ModuleBase_IWorkshop;
 
 class QKeyEvent;
 
@@ -105,7 +106,7 @@ Q_OBJECT
   //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
 
   /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
-  virtual void activateByPreselection();
+  virtual void activateByPreselection(ModuleBase_IWorkshop* theWorkshop);
 
   /// If the operation works with feature which is sub-feature of another one
   /// then this variable has to be initialised by parent feature 
index 5d921bdc8594b1c59d50c68005d6bba43626b2a4..02e774313557d097188d93aa4c4db0c24571cc50 100755 (executable)
@@ -8,6 +8,9 @@
 
 #include <ModuleBase_ParamIntSpinBox.h>
 #include <ModuleBase_ParamSpinBox.h>
+#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IModule.h>
 
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeRefAttr.h>
@@ -407,6 +410,20 @@ void getParameters(QStringList& theParameters)
   }
 }
 
+std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop, const FeaturePtr& theFeature)
+{
+  std::string anAttributeId;
+
+  std::string aXmlCfg, aDescription;
+  theWorkshop->module()->getXMLRepresentation(theFeature->getKind(), aXmlCfg, aDescription);
+
+  ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
+  std::string anAttributeTitle;
+  aFactory.getGreedAttribute(anAttributeId);
+
+  return anAttributeId;
+}
+
 } // namespace ModuleBase_Tools
 
 
index 9346e28ff49c7e2d483a207262dcb3f360f101c9..3e8f3b4d740f370999c118abf6f65196deb77bdc 100755 (executable)
@@ -26,6 +26,7 @@ class QLayout;
 class QDoubleSpinBox;
 class ModuleBase_ParamIntSpinBox;
 class ModuleBase_ParamSpinBox;
+class ModuleBase_IWorkshop;
 
 namespace ModuleBase_Tools {
 
@@ -171,6 +172,10 @@ MODULEBASE_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theSha
 /// \theParameters a list of parameter names
 MODULEBASE_EXPORT void getParameters(QStringList& theParameters);
 
+/// Returns list of parameters accessible in the active part and partset
+/// \theParameters a list of parameter names
+MODULEBASE_EXPORT std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
+                                                 const FeaturePtr& theFeature);
 }
 
 #endif
index 45d6446cad7272f8db35a3ca2bf9b34948cc5fc4..267ab17b5468e28aa64ed4b1142689fdebce4421 100644 (file)
@@ -143,8 +143,7 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage,
   thePage->alignToTop();
 }
 
-void ModuleBase_WidgetFactory::getAttributeTitle(const std::string& theFeatureKind,
-                                                 const std::string& theAttributeId,
+void ModuleBase_WidgetFactory::getAttributeTitle(const std::string& theAttributeId,
                                                  std::string& theTitle)
 {
   bool aFound = false;
@@ -156,6 +155,39 @@ void ModuleBase_WidgetFactory::getAttributeTitle(const std::string& theFeatureKi
   }
 }
 
+void ModuleBase_WidgetFactory::getGreedAttribute(std::string& theAttributeId)
+{
+  if (!theAttributeId.empty())
+    return;
+
+  myParentId = myWidgetApi->widgetId();
+  if (!myWidgetApi->toChildWidget())
+    return;
+
+  do {  //Iterate over each node
+    std::string aWdgType = myWidgetApi->widgetType();
+    // Find title under PageGroup
+    if (myWidgetApi->isGroupBoxWidget() ||
+      ModuleBase_WidgetCreatorFactory::get()->hasPageWidget(aWdgType)) {
+      getGreedAttribute(theAttributeId);
+    }
+    else {
+      // Find title here
+      std::string anAttributeId = myWidgetApi->widgetId();
+      if (myWidgetApi->getBooleanAttribute(ATTR_GREED, false))
+        theAttributeId = anAttributeId;
+      if (theAttributeId.empty() && myWidgetApi->isPagedWidget()) {
+        //If current widget is toolbox or switch-casebox then fetch all
+        //it's pages recursively and setup into the widget.
+        myWidgetApi->toChildWidget();
+        do {
+          getGreedAttribute(theAttributeId);
+        } while (theAttributeId.empty() && myWidgetApi->toNextWidget());
+      }
+    }
+  } while (theAttributeId.empty() && myWidgetApi->toNextWidget());
+}
+
 void ModuleBase_WidgetFactory::moveToWidgetId(const std::string& theWidgetId, bool& theFound)
 {
   if (theFound)
index fd416271ecd652c380da60843ea9e5600d3124cf..5e14ad4af7a8f4dda8abe566990b544461eec9f7 100644 (file)
@@ -54,13 +54,15 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory
   }
 
   /// Returns the value of the title key from XML definition of the attribute in the feature
-  /// \param theFeatureKind a value of a kind of a feature
   /// \param theAttributeId a value of a kind of the attribute under the feature
   /// \param theTitle the result title
-  void getAttributeTitle(const std::string& theFeatureKind,
-                         const std::string& theAttributeId,
+  void getAttributeTitle(const std::string& theAttributeId,
                          std::string& theTitle);
 
+  /// Returns the identifier of the first found attribute where greed field value is set and true
+  /// \param theAttributeId an outpup parameter with  attribute
+  void getGreedAttribute(std::string& theAttributeId);
+
 protected:
   /// check if ModuleBase_Widget has expandable widgets in getControls
   bool hasExpandingControls(QWidget* theParent);
index e8c6093438fc650319046cad21c6f5ddeeb31844..9471f0b8d6e314fedbf5b28761f35b7c1c703137 100755 (executable)
@@ -190,7 +190,7 @@ std::string ModuleBase_WidgetSelector::generateName(const AttributePtr& theAttri
 
       ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
       std::string anAttributeTitle;
-      aFactory.getAttributeTitle(aFeature->getKind(), theAttribute->id(), anAttributeTitle);
+      aFactory.getAttributeTitle(theAttribute->id(), anAttributeTitle);
 
       std::stringstream aStreamName;
       aStreamName << theAttribute->owner()->data()->name() << "/"<< anAttributeTitle.c_str();
index 323067442d7188b9f54eb16602ac182a712f7d71..2eb9cffe15108cdc2164d00a678ec1a71b2c5576 100644 (file)
             label="Segments:"
             tooltip="Select list of mirroring objects"
             type_choice="Edges"
-            use_external="true">
+            use_external="true"
+            greed ="true">
             <validator id="SketchPlugin_MirrorAttr" />
         </sketch_multi_selector>
       </feature>
index cb56c38795c4e51f8a1c29093dfa6b31a54ee0f2..e04181c6c36f2f2c3567149b461eead199e3b65a 100755 (executable)
@@ -451,7 +451,7 @@ void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
     // if the operation can be committed after the controls filling, the method perform should
     // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
     if (!aFOperation->isEditOperation()) {
-      aFOperation->activateByPreselection();
+      aFOperation->activateByPreselection(moduleConnector());
       if (operationMgr()->currentOperation() != aFOperation)
         return;
     }