Salome HOME
Issue #3236: Add buttons for shape type choice to Extrusion/Revolution objects
authorvsv <vsv@opencascade.com>
Thu, 25 Jun 2020 13:36:28 +0000 (16:36 +0300)
committervsv <vsv@opencascade.com>
Thu, 25 Jun 2020 13:36:55 +0000 (16:36 +0300)
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.h
src/FeaturesPlugin/extrusion_widget.xml
src/FeaturesPlugin/extrusionfuse_widget.xml
src/FeaturesPlugin/revolution_widget.xml
src/FeaturesPlugin/revolutionfuse_widget.xml
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/PartSet/PartSet_WidgetSketchCreator.cpp
src/PartSet/PartSet_WidgetSketchCreator.h

index 6ae36c31a79d9498615ef4fd3a4352e5027a5482..57b1ba874b20897df91b6a0d5875b18093f244c9 100644 (file)
@@ -23,7 +23,6 @@
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeString.h>
-#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
@@ -58,8 +57,6 @@ void FeaturesPlugin_Extrusion::initAttributes()
 
   data()->addAttribute(DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
 
-  data()->addAttribute(USE_SHAPES_ID(), ModelAPI_AttributeInteger::typeId());
-
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DIRECTION_OBJECT_ID());
index 91a30f16d32237c7d8f63b47b73e4c092f308594..1f657b30afceb5c7af7bcd94abf75c76f4300ce6 100644 (file)
@@ -123,13 +123,6 @@ public:
     return MY_FROM_OFFSET_ID;
   }
 
-  /// Attribute name of using shape types.
-  inline static const std::string& USE_SHAPES_ID()
-  {
-    static const std::string MY_USE_SHAPEST_ID("use_sapes");
-    return MY_USE_SHAPEST_ID;
-  }
-
   /// \return the kind of a feature.
   FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
   {
index 7d833c09532cada1ad5c219b1c71604f2bec1b32..138b4dca31b2888970213de180c97c74eb3f4b52 100644 (file)
@@ -5,24 +5,19 @@
 1. Planar face of non-sketch object or a plane. Sketch creation will be started.&lt;br /&gt;
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices. Extrusion will be filled by it."
-                   shape_types="vertices edges wires faces shells solids compsolids compounds">
+                  shape_types="Vertices Edges Faces"
+                  default_type = "2"
+                  use_choice="true">
     <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
   </sketch_launcher>
-  <choice id="use_sapes"
-    widget_type="radiobuttons"
-    buttons_dir="horizontal"
-    label="Type"
-    tooltip="Using shapes type"
-    string_list="Vertices Edges Faces"
-    icons_list=":pictures/vertex32.png :pictures/edge32.png :pictures/face32.png"
-    default="2">
-  </choice>
   <multi_selector id="base"
                   label="Base objects:"
                   tooltip="Select a base objects"
-                  shape_types="vertices edges wires faces shells compounds"
+                  shape_types="Vertices Edges Faces"
+                  default_type = "2"
+                  use_choice="true"
                   concealment="true">
-    <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell,compound"/>
+    <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face"/>
   </multi_selector>
   <shape_selector id="direction_object"
                   icon="icons/Features/axis.png"
index 5e9d7355698c63a689089848627233e0230331e6..7596c09e7d47f996e3c733c46580040ccc1902be 100644 (file)
@@ -6,14 +6,18 @@
 1. Planar face of non-sketch object or a plane. Sketch creation will be started.&lt;br /&gt;
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices. Extrusion will be filled by it."
-      shape_types="vertices edges wires faces shells compounds">
+      shape_types="Vertices Edges Faces"
+      default_type = "2"
+      use_choice="true">
       <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
     </sketch_launcher>
     <multi_selector id="base"
       label="Select a sketch face"
       icon="icons/Features/sketch.png"
       tooltip="Select a sketch face"
-      shape_types="vertices edges wires faces shells compounds"
+      shape_types="Vertices Edges Faces"
+      default_type = "2"
+      use_choice="true"
       concealment="true">
       <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell,compound"/>
     </multi_selector>
index f69065d75ff8bf58b30eb63d956d1c9a8983d48a..d8ec39801daad3961ccb9da4962cce0291c9892c 100644 (file)
@@ -5,13 +5,17 @@
 1. Planar face of non-sketch object or a plane. Sketch creation will be started.&lt;br /&gt;
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices. Extrusion will be filled by it."
-                   shape_types="vertices edges wires faces shells compounds">
+                  shape_types="Vertices Edges Faces"
+                  default_type = "2"
+                  use_choice="true">
     <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
   </sketch_launcher>
   <multi_selector id="base"
                   label="Base objects:"
                   tooltip="Select a base objects"
-                  shape_types="vertices edges wires faces shells compounds"
+                  shape_types="Vertices Edges Faces"
+                  default_type = "2"
+                  use_choice="true"
                   concealment="true">
     <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell,compound"/>
   </multi_selector>
index 4f571406e089f1fac9229e8c0348802124fa2443..bcde5490fd0dd9535dc4402e4439d1294755b04f 100644 (file)
@@ -6,14 +6,18 @@
 1. Planar face of non-sketch object or a plane. Sketch creation will be started.&lt;br /&gt;
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices. Extrusion will be filled by it."
-      shape_types="vertices edges wires faces shells compounds">
+      shape_types="Vertices Edges Faces"
+      default_type = "2"
+      use_choice="true">
       <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
     </sketch_launcher>
     <multi_selector id="base"
       label="Select a sketch face"
       icon="icons/Features/sketch.png"
       tooltip="Select a sketch face"
-      shape_types="vertices edges wires faces shells compounds"
+      shape_types="Vertices Edges Faces"
+      default_type = "2"
+      use_choice="true"
       concealment="true">
       <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell,compound"/>
     </multi_selector>
index bab6ca0029ab230033e73bc315756249009c52b9..9c4f6f9efe294bd5b5cb535f1c0cb5aff44dd792 100644 (file)
@@ -132,8 +132,19 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList);
   myTypeCtrl->setLabel(tr("Type"));
   if (!myShapeTypes.empty()) {
-    myTypeCtrl->setValue(0);
-    myDefMode = myShapeTypes.first().toStdString();
+    std::string aDefType = theData->getProperty("default_type");
+    if (aDefType.size() > 0) {
+      bool aOk = false;
+      int aId = QString(aDefType.c_str()).toInt(&aOk);
+      if (aOk) {
+        myTypeCtrl->setValue(aId);
+        myDefMode = myShapeTypes.at(aId).toStdString();
+      }
+    }
+    if (myDefMode.size() == 0) {
+      myTypeCtrl->setValue(0);
+      myDefMode = myShapeTypes.first().toStdString();
+    }
   }
   myMainLayout->addWidget(myTypeCtrl);
 
@@ -570,6 +581,8 @@ bool ModuleBase_WidgetMultiSelector::processDelete()
 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
 {
   QList<QWidget*> result;
+  if (myTypeCtrl->isVisible())
+    result << myTypeCtrl;
   result << myListView->getControl();
   return result;
 }
@@ -618,8 +631,9 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
   restoreValue();
   myWorkshop->setSelected(getAttributeSelection());
   // may be the feature's result is not displayed, but attributes should be
-  myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments,
-                            true); /// hope that something is redisplayed by object updated
+  // hope that something is redisplayed by object updated
+  myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments, false);
+  myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeResults, true);
   // clear history should follow after set selected to do not increase history by setSelected
   clearSelectedHistory();
 
index 9d6d90cf2dffd5f60023ca1504a07f0841cf5c26..49d94f227aa0f5985018950dd39ade7f8f85fe01 100644 (file)
@@ -53,6 +53,9 @@
 #include <ModuleBase_IPropertyPanel.h>
 #include <ModuleBase_OperationFeature.h>
 #include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_ChoiceCtrl.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_ISelectionActivate.h>
 
 #include <Config_WidgetAPI.h>
 
 
 #define DEBUG_UNDO_INVALID_SKETCH
 
+
+
+QStringList getIconsList(const QStringList& theNames)
+{
+  QStringList aIcons;
+  foreach(QString aName, theNames) {
+    QString aUName = aName.toUpper();
+    if ((aUName == "VERTICES") || (aUName == "VERTEX"))
+      aIcons << ":pictures/vertex32.png";
+    else if ((aUName == "EDGES") || (aUName == "EDGE"))
+      aIcons << ":pictures/edge32.png";
+    else if ((aUName == "FACES") || (aUName == "FACE"))
+      aIcons << ":pictures/face32.png";
+  }
+  return aIcons;
+}
+
+
+
 PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
                                                          PartSet_Module* theModule,
                                                          const Config_WidgetAPI* theData)
@@ -102,11 +124,37 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
 
   aLayout->addWidget(mySizeOfViewWidget);
   aLayout->addWidget(myLabel);
-  aLayout->addStretch(1);
 
   std::string aTypes = theData->getProperty("shape_types");
   myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts);
+  myIsUseChoice = theData->getBooleanAttribute("use_choice", false);
+  QStringList aIconsList = getIconsList(myShapeTypes);
+  myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList);
+  myTypeCtrl->setLabel(tr("Type"));
+  if (!myShapeTypes.empty()) {
+    std::string aDefType = theData->getProperty("default_type");
+    if (aDefType.size() > 0) {
+      bool aOk = false;
+      int aId = QString(aDefType.c_str()).toInt(&aOk);
+      if (aOk) {
+        myTypeCtrl->setValue(aId);
+        myDefMode = myShapeTypes.at(aId).toStdString();
+      }
+    }
+    if (myDefMode.size() == 0) {
+      myTypeCtrl->setValue(0);
+      myDefMode = myShapeTypes.first().toStdString();
+    }
+  }
+  aLayout->addWidget(myTypeCtrl);
+  // There is no sense to parameterize list of types while we can not parameterize selection mode
+  // if the xml definition contains one type, the controls to select a type should not be shown
+  if (myShapeTypes.size() <= 1 || !myIsUseChoice) {
+    myTypeCtrl->setVisible(false);
+  }
+  connect(myTypeCtrl, SIGNAL(valueChanged(int)), this, SLOT(onSelectionTypeChanged()));
 
+  aLayout->addStretch(1);
   myPreviewPlanes = new PartSet_PreviewPlanes();
 }
 
@@ -212,9 +260,6 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec
   XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel();
   const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
   foreach(ModuleBase_ModelWidget* aWidget, aWidgets) {
-    QString aType(aWidget->metaObject()->className());
-    if (aType == "ModuleBase_WidgetChoice")
-      continue;
     if (theSelectionControl) { // hide other controls
       if (aWidget != this)
         aWidget->setVisible(false);
@@ -253,8 +298,13 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec
 QIntList PartSet_WidgetSketchCreator::shapeTypes() const
 {
   QIntList aShapeTypes;
-  foreach(QString aType, myShapeTypes) {
-    aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
+  if (myShapeTypes.length() > 1 && myIsUseChoice) {
+    aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCtrl->textValue()));
+  }
+  else {
+    foreach(QString aType, myShapeTypes) {
+      aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
+    }
   }
   return aShapeTypes;
 }
@@ -592,3 +642,38 @@ void PartSet_WidgetSketchCreator::setEnabledModelWidget(ModuleBase_ModelWidget*
     eachControl->setEnabled(theEnabled);
   }
 }
+
+void PartSet_WidgetSketchCreator::onSelectionTypeChanged()
+{
+  // Clear current selection in order to avoid updating of object browser with obsolete indexes
+  // which can appear because of results deletetion after changing a type of selection
+  QString aSelectionType = myTypeCtrl->textValue();
+  QList<ModuleBase_ViewerPrsPtr> aEmptyList;
+  myWorkshop->setSelected(aEmptyList);
+
+  updateSelectionModesAndFilters(true);
+  myWorkshop->selectionActivate()->updateSelectionModes();
+
+  if (!myFeature)
+    return;
+
+  if (aSelectionType != "Faces") {
+    setVisibleSelectionControl(false);
+    myWorkshop->propertyPanel()->activateNextWidget();
+  }
+
+  /// store the selected type
+  AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID);
+  anAttrList->setSelectionType(aSelectionType.toStdString());
+  anAttrList->clear();
+
+  // update object is necessary to flush update signal. It leads to objects references map update
+  // and the operation presentation will not contain deleted items visualized as parameters of
+  // the feature.
+  updateObject(myFeature);
+  myWorkshop->propertyPanel()->activeWidget()->restoreValue();
+  myWorkshop->setSelected(getAttributeSelection());
+  // may be the feature's result is not displayed, but attributes should be
+  // hope that something is redisplayed by object updated
+  myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments, true);
+}
\ No newline at end of file
index 0e32b02850471f4c180c7ce07a36e824f3e526ce..dd8bfa23a7260e03296526618d9935d0101c640c 100644 (file)
@@ -30,6 +30,7 @@ class PartSet_Module;
 class ModuleBase_Operation;
 class ModuleBase_IWorkshop;
 class PartSet_PreviewPlanes;
+class ModuleBase_ChoiceCtrl;
 
 /**
 * \ingroup Modules
@@ -140,6 +141,9 @@ private:
 private slots:
   void onResumed(ModuleBase_Operation* theOp);
 
+  /// Slot is called on selection type changed
+  void onSelectionTypeChanged();
+
 private:
   /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
   /// \param theValues a selection list
@@ -179,6 +183,12 @@ private:
 
   /// class to show/hide preview planes
   PartSet_PreviewPlanes* myPreviewPlanes;
+
+  bool myIsUseChoice; ///< A flag to store use_choice parameter state
+
+  /// Control for types
+  ModuleBase_ChoiceCtrl* myTypeCtrl;
+  std::string myDefMode;
 };
 
 #endif
\ No newline at end of file