]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: first extrusion widge...
authornds <nds@opencascade.com>
Fri, 18 Mar 2016 08:05:31 +0000 (11:05 +0300)
committerdbv <dbv@opencascade.com>
Wed, 6 Apr 2016 10:19:57 +0000 (13:19 +0300)
src/FeaturesPlugin/extrusion_widget.xml
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.h
src/PartSet/PartSet_WidgetSketchCreator.cpp
src/PartSet/PartSet_WidgetSketchCreator.h

index 82414a999db3b375c35ccf6377713d0afc60e748..ac410cf69cfd5d31ee70164f4f586fb6718fb397 100644 (file)
@@ -2,10 +2,13 @@
 
 <source>
   <sketch_launcher id="sketch"
-    label="Sketch"
+    label="Select: 1. Planar face of non-sketch object or a plane. Sketch creation will be started.
+2. An existing sketch face or contour. Extrusion will be filled with them. 3.A shape on existing result: wires/edge/vertices.
+Extrusion will be filled with them"
     icon=":icons/sketch.png"
     use_body="false"
-    tooltip="Create or edit a sketch">
+    tooltip="Create or edit a sketch"
+    shape_types="vertex edge face">
   </sketch_launcher>
   <toolbox id="CreationMethod">
     <box id="BySizes" title="By sizes" icon=":icons/dimension_up_down_32x32.png">
index d2d36e4461c118a9ee40d25bf38dc1be8e292baa..454ed88de5f6efac08c523c516309db07f23e720 100755 (executable)
@@ -62,6 +62,12 @@ void ModuleBase_WidgetSelector::onSelectionChanged()
     updateFocus();
 }
 
+//********************************************************************
+QList<ModuleBase_ViewerPrs> ModuleBase_WidgetSelector::getAttributeSelection() const
+{
+  return QList<ModuleBase_ViewerPrs>();
+}
+
 //********************************************************************
 bool ModuleBase_WidgetSelector::acceptSubShape(const GeomShapePtr& theShape,
                                                const ResultPtr& theResult) const
index 2a41f711449980ddc0f0d5169eabed0d0fb8a487..d2fbdeb08dcc660d5204e980440c6e8dbe8ceab6 100755 (executable)
@@ -64,26 +64,26 @@ Q_OBJECT
 
  protected:
   /// Update focus after the attribute value change
-  virtual void updateFocus() = 0;
+   virtual void updateFocus() {};
 
   /// Return the attribute values wrapped in a list of viewer presentations
   /// \return a list of viewer presentations, which contains an attribute result and
   /// a shape. If the attribute do not uses the shape, it is empty
-  virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const = 0;
+   virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
 
   /// Retunrs a list of possible shape types
   /// \return a list of shapes
   virtual QIntList getShapeTypes() const = 0;
 
   /// Computes and updates name of selected object in the widget
-  virtual void updateSelectionName() = 0;
+  virtual void updateSelectionName() {};
 
   /// Store the values to the model attribute of the widget. It casts this attribute to
   /// the specific type and set the given values
   /// \param theSelectedObject an object
   /// \param theShape a selected shape, which is used in the selection attribute
   /// \return true if it is succeed
-  virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) = 0;
+  virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) {};
 
   /// The methiod called when widget is activated
   virtual void activateCustom();
index b965f4348d51ce42126f2067118faa1f7133120b..22e839ce5cc20816300c6aa9be9e43bd327c2746 100644 (file)
@@ -14,6 +14,7 @@
 #include <XGUI_Displayer.h>
 #include <XGUI_SelectionMgr.h>
 #include <XGUI_OperationMgr.h>
+#include <XGUI_PropertyPanel.h>
 
 #include <GeomAPI_Face.h>
 
 
 #include <QLabel>
 #include <QLineEdit>
-#include <QFormLayout>
+//#include <QFormLayout>
+#include <QVBoxLayout>
 #include <QMessageBox>
 
 PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, 
                                                          PartSet_Module* theModule,
                                                          const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData), myModule(theModule), myUseBody(true)
+: ModuleBase_WidgetSelector(theParent, theModule->workshop(), theData),
+  myModule(theModule), myUseBody(true)
 {
-  QFormLayout* aLayout = new QFormLayout(this);
+  myAttributeListID = theData->getProperty("attribute_list_id");
+
+  //QFormLayout* aLayout = new QFormLayout(this);
+  QVBoxLayout* aLayout = new QVBoxLayout(this);
+  ModuleBase_Tools::zeroMargins(aLayout);
+
   ModuleBase_Tools::adjustMargins(aLayout);
 
   QString aLabelText = QString::fromStdString(theData->widgetLabel());
   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+
   myLabel = new QLabel(aLabelText, this);
-  if (!aLabelIcon.isEmpty())
+  myLabel->setWordWrap(true);
+  aLayout->addWidget(myLabel);
+  /*if (!aLabelIcon.isEmpty())
     myLabel->setPixmap(QPixmap(aLabelIcon));
 
 
@@ -68,7 +79,10 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
     myUseBody = QVariant(aUseBody).toBool();
   }
 
-  aLayout->addRow(myLabel, myTextLine);
+  aLayout->addRow(myLabel, myTextLine);*/
+
+  std::string aTypes = theData->getProperty("shape_types");
+  myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts);
 }
 
 PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator()
@@ -78,18 +92,18 @@ PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator()
 QList<QWidget*> PartSet_WidgetSketchCreator::getControls() const
 {
   QList<QWidget*> aControls;
-  aControls.append(myTextLine);
+  aControls.append(myLabel);
   return aControls;
 }
 
 bool PartSet_WidgetSketchCreator::restoreValueCustom()
 {
-  CompositeFeaturePtr aCompFeature = 
+  /*CompositeFeaturePtr aCompFeature = 
     std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
   if (aCompFeature->numberOfSubs() > 0) {
     FeaturePtr aSubFeature = aCompFeature->subFeature(0);
     myTextLine->setText(QString::fromStdString(aSubFeature->data()->name()));
-  }
+  }*/
   return true;
 }
 
@@ -100,16 +114,72 @@ bool PartSet_WidgetSketchCreator::storeValueCustom() const
 
 void PartSet_WidgetSketchCreator::activateCustom()
 {
-  CompositeFeaturePtr aCompFeature = 
-    std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
-  if (aCompFeature->numberOfSubs() == 0)
-    connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
+  if (isSelectionMode()) {
+    ModuleBase_WidgetSelector::activateCustom();
+    //connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
+
+    //setVisibleSelectionControl(true);
+  }
+  else {
+    setVisibleSelectionControl(false);
+    emit focusOutWidget(this);
+  }
+}
+
+void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelectionControl)
+{
+  // hide current widget, activate the next widget
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel();
+  const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
+  foreach(ModuleBase_ModelWidget* aWidget, aWidgets) {
+    if (theSelectionControl) { // hide other controls
+      if (aWidget != this)
+        aWidget->setVisible(false);
+    }
+    else { // hide current control
+      if (aWidget == this)
+        aWidget->setVisible(false);
+    }
+  }
+}
+
+QIntList PartSet_WidgetSketchCreator::getShapeTypes() const
+{
+  QIntList aShapeTypes;
+  foreach(QString aType, myShapeTypes) {
+    aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
+  }
+  return aShapeTypes;
+}
+
+void PartSet_WidgetSketchCreator::deactivate()
+{
+  if (isSelectionMode()) {
+    ModuleBase_WidgetSelector::activateCustom();
+  }
+}
+
+bool PartSet_WidgetSketchCreator::isSelectionMode() const
+{
+  //CompositeFeaturePtr aCompFeature =
+  //  std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+  //bool aHasSub = aCompFeature->numberOfSubs() > 0;
+
+  AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID);
+  bool aHasValueInList = anAttrList.get() && anAttrList->size() > 0;
+
+  return !aHasValueInList;//aHasSub || aHasValueInList;
 }
 
 void PartSet_WidgetSketchCreator::onStarted()
 {
   disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
 
+  setVisibleSelectionControl(true);
+
+  /*
   // Check that model already has bodies
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
   XGUI_Workshop* aWorkshop = aConnector->workshop();
@@ -156,26 +226,30 @@ void PartSet_WidgetSketchCreator::onStarted()
         tr("There are no bodies found. Operation aborted."), QMessageBox::Ok);
     ModuleBase_Operation* aOp = myModule->workshop()->currentOperation();
     aOp->abort();
-  }
+  }*/
 }
 
 bool PartSet_WidgetSketchCreator::focusTo()
 {
-  CompositeFeaturePtr aCompFeature = 
-    std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
-  if (aCompFeature->numberOfSubs() == 0)
-    return ModuleBase_ModelWidget::focusTo(); 
-
-  connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*)));
-  SessionPtr aMgr = ModelAPI_Session::get();
-  // Open transaction that is general for the previous nested one: it will be closed on nested commit
-  bool aIsOp = aMgr->isOperation();
-  if (!aIsOp) {
-    const static std::string aNestedOpID("Parameters modification");
-    aMgr->startOperation(aNestedOpID, true);
+  if (isSelectionMode()) {
+    //CompositeFeaturePtr aCompFeature = 
+    //   std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+    // if (aCompFeature->numberOfSubs() == 0)
+    //   return ModuleBase_ModelWidget::focusTo(); 
+    connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
+    return true;
+  }
+  else {
+    connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*)));
+    SessionPtr aMgr = ModelAPI_Session::get();
+    // Open transaction that is general for the previous nested one: it will be closed on nested commit
+    bool aIsOp = aMgr->isOperation();
+    if (!aIsOp) {
+      const static std::string aNestedOpID("Parameters modification");
+      aMgr->startOperation(aNestedOpID, true);
+    }
+    restoreValue();
   }
-
-  restoreValue();
   return false;
 }
 
index 4bb31fe94de04f0324ac1bdd662f0c4dd74e02a3..f52a0f1fa3f06d68822772db56a2930e1e3f2e0b 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "PartSet.h"
 
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetSelector.h>
 
 class QLabel;
 class QLineEdit;
@@ -24,10 +24,11 @@ class ModuleBase_Operation;
 * it will transfer a focus to next widget. It is supposed that the widget will be placed as 
 * a first widget in property panel
 */
-class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_ModelWidget
+class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_WidgetSelector
 {
 Q_OBJECT
- public:
+
+public:
   /// Constructor
   /// \param theParent the parent object
   /// \param theModule a reference to a module object
@@ -46,6 +47,9 @@ Q_OBJECT
   /// \return the state whether the widget can accept the focus
   virtual bool focusTo();
 
+  /// The methiod called when widget is deactivated
+  virtual void deactivate();
+
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
@@ -56,12 +60,27 @@ protected:
   /// The methiod called when widget is activated
   virtual void activateCustom();
 
+  /// Visualization of the current control or others in PP
+  /// \param theSelectionControl state whether the control should be shown/hidden
+  void setVisibleSelectionControl(const bool theSelectionControl);
+
+  /// Retunrs a list of possible shape types
+  /// \return a list of shapes
+  virtual QIntList getShapeTypes() const;
+
+private:
+  /// Returns true if the selection mode is active. This is when composition feature has no
+  ///  a sub-object and the attribute list is empty
+  /// \return boolean value
+  bool isSelectionMode() const;
+
 private slots:
   void onStarted();
 
   void onResumed(ModuleBase_Operation* theOp);
 
 private:
+  std::string myAttributeListID;
 
   PartSet_Module* myModule;
 
@@ -71,6 +90,9 @@ private:
   /// Input control of the widget
   QLineEdit* myTextLine;
 
+  /// List of accepting shapes types
+  QStringList myShapeTypes;
+
   /// To check if we need to use body for composite feature or not
   bool myUseBody;