Salome HOME
Issue #1302 Restricting preselection to the first argument only: mirror feature has...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFactory.cpp
index f32f0aca8dc7ce29cba19c7777daedfb0be209b5..267ab17b5468e28aa64ed4b1142689fdebce4421 100644 (file)
@@ -121,6 +121,105 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
   thePage->alignToTop();
 }
 
+void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage,
+                                            const std::string& theWidgetId)
+{
+  bool aFound = false;
+  moveToWidgetId(theWidgetId, aFound);
+  if (aFound) {
+    std::string aWdgType = myWidgetApi->widgetType();
+
+    // Create a ModelWidget
+    ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, thePage->pageWidget());
+    if (aWidget) {
+      if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
+        thePage->addModelWidget(aWidget);
+      }
+      else {
+        aWidget->setVisible(false);
+      }
+    }
+  }
+  thePage->alignToTop();
+}
+
+void ModuleBase_WidgetFactory::getAttributeTitle(const std::string& theAttributeId,
+                                                 std::string& theTitle)
+{
+  bool aFound = false;
+  moveToWidgetId(theAttributeId, aFound);
+  if (aFound) {
+    theTitle = QString::fromStdString(myWidgetApi->widgetLabel()).toStdString().c_str();
+    if (theTitle.empty())
+      theTitle = QString::fromStdString(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)).toStdString().c_str();
+  }
+}
+
+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)
+    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)) {
+      moveToWidgetId(theWidgetId, theFound);
+    }
+    else {
+      // Find title here
+      std::string anAttributeId = myWidgetApi->widgetId();
+      theFound = anAttributeId == theWidgetId;
+      if (!theFound && 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 {
+          moveToWidgetId(theWidgetId, theFound);
+        } while (!theFound && myWidgetApi->toNextWidget());
+      }
+    }
+  } while (!theFound && myWidgetApi->toNextWidget());
+}
+
 ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::string& theType,
                                                                 QWidget* theParent)
 {