Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFactory.cpp
index d89f27de4855c7bf3ef765bd546f33ed05434312..63646b9565474d81917db69ca089bd0cf30155bb 100644 (file)
@@ -7,12 +7,12 @@
 
 #include <ModuleBase_WidgetFactory.h>
 
-#include <ModuleBase_MetaWidget.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
-#include <ModuleBase_PropPanelOperation.h>
 #include <ModuleBase_WidgetPoint2D.h>
 #include <ModuleBase_WidgetSwitch.h>
+#include <ModuleBase_SelectorWidget.h>
+#include <ModuleBase_Widgets.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -34,8 +34,8 @@
 #include <cfloat>
 #include <climits>
 
-ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(ModuleBase_Operation* theOperation)
- : myOperation(theOperation)
+ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(ModuleBase_Operation* theOperation, ModuleBase_IWorkshop* theWorkshop)
+ : myOperation(theOperation), myWorkshop(theWorkshop)
 {
   QString aXml = myOperation->getDescription()->xmlRepresentation();
   myWidgetApi = new Config_WidgetAPI(aXml.toStdString());
@@ -104,14 +104,21 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
 {
   QWidget* result = NULL;
   if (theType == WDG_DOUBLEVALUE) {
-    result = doubleSpinBoxControl();
+    result = doubleSpinBoxControl(theParent);
+
   } else if (theType == WDG_INFO) {
     result = labelControl(theParent);
-  }
-  else if (theType == WDG_POINT_SELECTOR) {
+
+  } else if (theType == WDG_SELECTOR) {
+    result = selectorControl(theParent);
+
+  } else if (theType == WDG_BOOLVALUE) {
+    result = booleanControl(theParent);
+
+  } else if (theType == WDG_POINT_SELECTOR) {
     result = pointSelectorControl(theParent);
-  }
-  else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
+
+  else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
     result = createContainer(theType, theParent);
   }
 #ifdef _DEBUG
@@ -140,62 +147,26 @@ QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, Q
   return result;
 }
 
-QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl()
+QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent)
 {
-  QWidget* result = new QWidget();
-  QHBoxLayout* aControlLay = new QHBoxLayout(result);
-  aControlLay->setContentsMargins(0, 0, 0, 0);
-  QString aLabelText = qs(myWidgetApi->widgetLabel());
-  QString aLabelIcon = qs(myWidgetApi->widgetIcon());
-  QLabel* aLabel = new QLabel(aLabelText);
-  aLabel->setPixmap(QPixmap(aLabelIcon));
-
-  aControlLay->addWidget(aLabel);
-  QDoubleSpinBox* aBox = new QDoubleSpinBox(result);
-  QString anObjName = QString::fromStdString(myWidgetApi->widgetId());
-  aBox->setObjectName(anObjName);
-  bool isOk = false;
-  std::string aProp = myWidgetApi->getProperty(DOUBLE_WDG_MIN);
-  double aMinVal = qs(aProp).toDouble(&isOk);
-  if (isOk) {
-    aBox->setMinimum(aMinVal);
-  } else {
-    aBox->setMinimum(-DBL_MAX);
-  }
-  aProp = myWidgetApi->getProperty(DOUBLE_WDG_MAX);
-  double aMaxVal = qs(aProp).toDouble(&isOk);
-  if (isOk) {
-    aBox->setMaximum(aMaxVal);
-  } else {
-    aBox->setMaximum(DBL_MAX);
-  }
-  aProp = myWidgetApi->getProperty(DOUBLE_WDG_STEP);
-  double aStepVal = qs(aProp).toDouble(&isOk);
-  if (isOk) {
-    aBox->setSingleStep(aStepVal);
-  }
-  aProp = myWidgetApi->getProperty(DOUBLE_WDG_DFLT);
-  double aDefVal = qs(aProp).toDouble(&isOk);
-  if (isOk) {
-    aBox->setValue(aDefVal);
-  }
-  QString aTTip = qs(myWidgetApi->widgetTooltip());
-  aBox->setToolTip(aTTip);
-  aControlLay->addWidget(aBox);
-  aControlLay->setStretch(1, 1);
-  result->setLayout(aControlLay);
-  connectWidget(aBox, WDG_DOUBLEVALUE);
-  ModuleBase_MetaWidget* aWrappedWdg =
-      new ModuleBase_MetaWidget(anObjName, aBox, myOperation->feature());
-  myWidgets.append(aWrappedWdg);
-  return result;
+  ModuleBase_DoubleValueWidget* aDblWgt = new ModuleBase_DoubleValueWidget(theParent, myWidgetApi);
+  QObject::connect(aDblWgt, SIGNAL(valuesChanged()),  myOperation, SLOT(storeCustomValue()));
+
+  myModelWidgets.append(aDblWgt);
+
+  // Init default values
+  if (!myOperation->isEditOperation())
+    aDblWgt->storeValue(myOperation->feature());
+  return aDblWgt->getControl();
 }
 
 QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent)
 {
   ModuleBase_WidgetPoint2D* aWidget = new ModuleBase_WidgetPoint2D(theParent,
-                       qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)), myWidgetApi->widgetId());
+                       qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)),
+                       myWidgetApi->widgetId());
   connectWidget(aWidget, WDG_POINT_SELECTOR);
+  myModelWidgets.append(aWidget);
   return aWidget->getControl();
 }
 
@@ -207,8 +178,7 @@ bool ModuleBase_WidgetFactory::connectWidget(QObject* theWidget,  const QString&
                               myOperation, SLOT(storeReal(double)));
   }
   if (theType == WDG_POINT_SELECTOR) {
-    ModuleBase_WidgetCustom* aCustom = dynamic_cast<ModuleBase_WidgetCustom*>(theWidget);
-    result = QObject::connect(aCustom, SIGNAL(valuesChanged()), 
+    result = QObject::connect(theWidget, SIGNAL(valuesChanged()),
                               myOperation, SLOT(storeCustomValue()));
   }
   return result;
@@ -218,3 +188,28 @@ QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
 {
   return QString::fromStdString(theStdString);
 }
+
+
+QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent)
+{
+  ModuleBase_SelectorWidget* aSelector = new ModuleBase_SelectorWidget(theParent, myWorkshop, myWidgetApi);
+  
+  QObject::connect(aSelector, SIGNAL(valuesChanged()),  myOperation, SLOT(storeCustomValue()));
+
+  myModelWidgets.append(aSelector);
+  return aSelector->getControl();
+}
+
+
+QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent)
+{
+  ModuleBase_BoolValueWidget* aBoolWgt = new ModuleBase_BoolValueWidget(theParent, myWidgetApi);
+  QObject::connect(aBoolWgt, SIGNAL(valuesChanged()),  myOperation, SLOT(storeCustomValue()));
+
+  myModelWidgets.append(aBoolWgt);
+
+  // Init default values
+  if (!myOperation->isEditOperation())
+    aBoolWgt->storeValue(myOperation->feature());
+  return aBoolWgt->getControl();
+}
\ No newline at end of file