]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implementatation of Toolbox as ModelWidget
authorsbh <sergey.belash@opencascade.com>
Fri, 27 Feb 2015 13:17:42 +0000 (16:17 +0300)
committersbh <sergey.belash@opencascade.com>
Fri, 27 Feb 2015 13:17:42 +0000 (16:17 +0300)
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Axis.h
src/ConstructionPlugin/axis_widget.xml
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/ModuleBase/ModuleBase_WidgetToolbox.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetToolbox.h [new file with mode: 0644]
src/XGUI/XGUI_Workshop.cpp

index 4f3fae9dbdd66352d6b8713368fea1c43ee7ef7e..258ed85e94e9404945072a0ce17ab5d145127d76 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeString.h>
 
 #include <GeomAPI_Edge.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
@@ -23,10 +24,14 @@ ConstructionPlugin_Axis::ConstructionPlugin_Axis()
 
 void ConstructionPlugin_Axis::initAttributes()
 {
+  data()->addAttribute(ConstructionPlugin_Axis::METHOD(),
+                       ModelAPI_AttributeString::type());
   data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(),
                        ModelAPI_AttributeSelection::type());
   data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(),
                        ModelAPI_AttributeSelection::type());
+  data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
+                       ModelAPI_AttributeSelection::type());
 }
 
 void ConstructionPlugin_Axis::execute()
index ef021ba50eb7caad950ef1202ffabed4c5a3aca0..473d3e3524e18f86435d88e3e9df969656fb4a29 100644 (file)
@@ -31,6 +31,13 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
     static const std::string CONSTRUCTION_AXIS_KIND("Axis");
     return CONSTRUCTION_AXIS_KIND;
   }
+
+  /// attribute name for first point
+  inline static const std::string& METHOD()
+  {
+    static const std::string METHOD_ATTR("creationMethod");
+    return METHOD_ATTR;
+  }
   /// attribute name for first point
   inline static const std::string& POINT_FIRST()
   {
@@ -43,6 +50,12 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
     static const std::string POINT_ATTR_SECOND("secondPoint");
     return POINT_ATTR_SECOND;
   }
+  /// attribute name for second point
+  inline static const std::string& CYLINDRICAL_FACE()
+  {
+    static const std::string CYLINDRICAL_FACE_ATTR("cylindricalFace");
+    return CYLINDRICAL_FACE_ATTR;
+  }
   /// default color for an axis
   inline static const std::string& DEFAULT_COLOR()
   {
index 0042745695cfdb98d3a7011925caded1e206e97e..5b554016697664cabf3ca0a9c1e41229a0205338 100644 (file)
@@ -1,7 +1,7 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
-  <toolbox>
+  <toolbox id="creationMethod">
     <box id="AxisByPointsCase" title="By two points">
       <shape_selector id="firstPoint"
         label="First point"
index aea5e669a1fdb02c3487a7bed0714da7bfc3ad1e..8104818536889a5862e6e440cbbe911b93f91394 100644 (file)
@@ -44,6 +44,7 @@ SET(PROJECT_HEADERS
        ModuleBase_IPrefMgr.h
        ModuleBase_Preferences.h
        ModuleBase_ActionInfo.h
+       ModuleBase_WidgetToolbox.h
 )
 
 SET(PROJECT_SOURCES
@@ -78,6 +79,7 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetLabel.cpp
        ModuleBase_Preferences.cpp
        ModuleBase_ActionInfo.cpp
+       ModuleBase_WidgetToolbox.cpp
 )
 
 SET(PROJECT_LIBRARIES
index d606c0bf74105eafd628df4f0118637d54d3fc83..c5e6e58e8e0ab09104641196eaa4f74613ecdc3e 100644 (file)
@@ -27,6 +27,7 @@
 #include <ModuleBase_WidgetLineEdit.h>
 #include <ModuleBase_WidgetMultiSelector.h>
 #include <ModuleBase_WidgetLabel.h>
+#include <ModuleBase_WidgetToolbox.h>
 
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
@@ -96,6 +97,7 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
       myWidgetApi->toChildWidget();
       do {
         QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
+        QString aCaseId = qs(myWidgetApi->getProperty(_ID));
         QWidget* aPage = new QWidget(aWidget);
         createWidget(aPage);
         ModuleBase_Tools::adjustMargins(aPage);
@@ -103,10 +105,9 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
           ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
           aSwitch->addPage(aPage, aPageName);
         } else if (aWdgType == WDG_TOOLBOX) {
-          QToolBox* aToolbox = qobject_cast<QToolBox*>(aWidget);
-          aToolbox->addItem(aPage, aPageName);
+          ModuleBase_WidgetToolbox* aToolbox = qobject_cast<ModuleBase_WidgetToolbox*>(aWidget);
+          aToolbox->addPage(aPage, aPageName, aCaseId);
         }
-
       } while (myWidgetApi->toNextWidget());
     }
     if (aWidget && !isStretchLayout) {
@@ -182,34 +183,25 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
 
 QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent)
 {
-  QWidget* result = NULL;
+  QWidget* aResult = NULL;
   if (theType == WDG_GROUP || theType == WDG_CHECK_GROUP) {
     QGroupBox* aGroupBox = new QGroupBox(theParent);
     aGroupBox->setCheckable(theType == WDG_CHECK_GROUP);
-    result = aGroupBox;
+    aResult = aGroupBox;
   } else if (theType == WDG_TOOLBOX) {
-    result = new QToolBox(theParent);
-    // Dark-grey rounded tabs with button-like border #and bold font
-    QString css = "QToolBox::tab{background-color:#c8c8c8;"
-                                "border-radius:5px;"
-                                "border:1px inset;"
-                                //"font-weight:700;"
-                                "border-color:#fff #505050 #505050 #fff;}";
-    result->setStyleSheet(css);
-    // default vertical size policy is preferred
-    QSizePolicy aSizePolicy = result->sizePolicy();
-    aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding);
-    result->setSizePolicy(aSizePolicy);
+    ModuleBase_WidgetToolbox* aWdg = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
+    myModelWidgets.append(aWdg);
+    aResult = aWdg;
   } else if (theType == WDG_SWITCH) {
-    result = new ModuleBase_WidgetSwitch(theParent);
+    aResult = new ModuleBase_WidgetSwitch(theParent);
   } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
     // Do nothing for "box" and "case"
-    result = NULL;
+    aResult = NULL;
   }
 #ifdef _DEBUG
   else {qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad container type";}
 #endif
-  return result;
+  return aResult;
 }
 
 QWidget* ModuleBase_WidgetFactory::labelControl(QWidget* theParent)
index 93b8443ae6c87f30dd041f61d5ec5277020c9756..71834e86d3db0d8bfe80e377eff9eef5c6400c14 100644 (file)
@@ -58,7 +58,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory
    /// Create a widget of container type
    /// \param theType a type
    /// \param theParent a parent widget
-  QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
+  QWidget* createContainer(const std::string& theType, QWidget* theParent);
 
   /// Create label widget
   /// \param theParent a parent widget
diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp
new file mode 100644 (file)
index 0000000..220be9b
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * ModuleBase_WidgetToolbox.cpp
+ *
+ *  Created on: Feb 27, 2015
+ *      Author: sbh
+ */
+
+#include <ModuleBase_WidgetToolbox.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_AttributeString.h>
+
+#include <QWidget>
+#include <QVBoxLayout>
+
+ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
+                                                   const std::string& theParentId)
+: ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+  QVBoxLayout* aMainLayout = new QVBoxLayout(this);
+  ModuleBase_Tools::zeroMargins(aMainLayout);
+  myToolBox = new QToolBox(this);
+  // Dark-grey rounded tabs with button-like border #and bold font
+  QString css = "QToolBox::tab{background-color:#c8c8c8;"
+                              "border-radius:5px;"
+                              "border:1px inset;"
+                              //"font-weight:700;"
+                              "border-color:#fff #505050 #505050 #fff;}";
+  myToolBox->setStyleSheet(css);
+  // default vertical size policy is preferred
+  QSizePolicy aSizePolicy = myToolBox->sizePolicy();
+  aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding);
+  myToolBox->setSizePolicy(aSizePolicy);
+  aMainLayout->addWidget(myToolBox);
+
+  connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
+}
+
+ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
+{
+}
+
+int ModuleBase_WidgetToolbox::addPage(QWidget* theWidget,
+                                      const QString& theName, const QString& theCaseId)
+{
+  myCaseIds << theCaseId;
+  return myToolBox->addItem(theWidget, theName);
+}
+
+bool ModuleBase_WidgetToolbox::restoreValue()
+{
+  // A rare case when plugin was not loaded.
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+  QString aCaseId = QString::fromStdString(aStringAttr->value());
+  int idx = myCaseIds.indexOf(aCaseId);
+  if (idx == -1)
+    return false;
+  bool isSignalsBlocked = myToolBox->blockSignals(true);
+  myToolBox->setCurrentIndex(idx);
+  myToolBox->blockSignals(isSignalsBlocked);
+  return true;
+}
+
+QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
+{
+  QList<QWidget*> aList;
+  aList << myToolBox;
+  return aList;
+}
+
+bool ModuleBase_WidgetToolbox::storeValueCustom() const
+{
+  // A rare case when plugin was not loaded.
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+  QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
+  aStringAttr->setValue(aWidgetValue.toStdString());
+  return true;
+}
+
+void ModuleBase_WidgetToolbox::onPageChanged()
+{
+  storeValue();
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.h b/src/ModuleBase/ModuleBase_WidgetToolbox.h
new file mode 100644 (file)
index 0000000..c57c75e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * ModuleBase_WidgetToolbox.h
+ *
+ *  Created on: Feb 27, 2015
+ *      Author: sbh
+ */
+
+#ifndef MODULEBASE_WIDGETTOOLBOX_H_
+#define MODULEBASE_WIDGETTOOLBOX_H_
+
+#include <ModuleBase_ModelWidget.h>
+
+#include <QToolBox>
+
+class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+ public:
+  ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
+                           const std::string& theParentId);
+  virtual ~ModuleBase_WidgetToolbox();
+
+  virtual bool restoreValue();
+  virtual QList<QWidget*> getControls() const;
+
+  int addPage(QWidget* theWidget, const QString& theName, const QString& theCaseId);
+
+ protected:
+  virtual bool storeValueCustom() const;
+
+ protected slots:
+  void onPageChanged();
+
+ private:
+  QToolBox* myToolBox;
+  QStringList myCaseIds;
+};
+
+#endif /* MODULEBASE_WIDGETTOOLBOX_H_ */
index 9f5a0083ddfbbc457964cf667cf9937a01b90346..86107e2d9b5aaab030e8e7f0a679ae9b895b0df3 100644 (file)
@@ -653,7 +653,8 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
   QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
   foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
     bool isStoreValue = !theOperation->isEditOperation() &&
-                        !aWidget->getDefaultValue().empty() && !aWidget->isComputedDefault();
+                        !aWidget->getDefaultValue().empty() &&
+                        !aWidget->isComputedDefault();
     aWidget->setFeature(theOperation->feature(), isStoreValue);
     aWidget->enableFocusProcessing();
   }