Salome HOME
Issue #1303 Re-ordering of Sketcher menus: Delete to be the last
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetCreatorFactory.cpp
index 1427e22a709ef242ac8043081cee93f30217d193..13c7bf571d9e5db21073f67610ebd1a15d7dc1c8 100755 (executable)
@@ -7,6 +7,8 @@
 #include <ModuleBase_WidgetCreatorFactory.h>
 #include <ModuleBase_IWidgetCreator.h>
 
+#include <Config_WidgetAPI.h>
+
 #include <Events_Error.h>
 
 #include <QStringList>
@@ -32,9 +34,24 @@ ModuleBase_WidgetCreatorFactory::~ModuleBase_WidgetCreatorFactory()
 
 void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator)
 {
-  const std::set<std::string>& aTypes = theCreator->widgetTypes();
-  std::set<std::string>::const_iterator anIt = aTypes.begin(), aLast = aTypes.end();
-  for (; anIt != aLast; anIt++) {
+  std::set<std::string>::const_iterator anIt, aLast;
+  /// fill map of panels
+  std::set<std::string> aPanelTypes;
+  theCreator->panelTypes(aPanelTypes);
+  for (anIt = aPanelTypes.begin(), aLast = aPanelTypes.end(); anIt != aLast; anIt++) {
+    std::string aKey = *anIt;
+    if (!myPanelToCreator.contains(aKey))
+      myPanelToCreator[aKey] = theCreator;
+    else {
+      Events_Error::send("The" + aKey + " panel XML definition has been already \
+used by another widget creator");
+    }
+  }
+
+  /// fill map of widgets
+  std::set<std::string> aTypes;
+  theCreator->widgetTypes(aTypes);
+  for (anIt = aTypes.begin(), aLast = aTypes.end(); anIt != aLast; anIt++) {
     std::string aKey = *anIt;
     if (!myCreators.contains(aKey))
       myCreators[aKey] = theCreator;
@@ -44,7 +61,9 @@ used by another widget creator");
     }
   }
 
-  const std::set<std::string>& aPTypes = theCreator->pageTypes();
+  /// fill map of pages
+  std::set<std::string> aPTypes;
+  theCreator->pageTypes(aPTypes);
   for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
     std::string aKey = *anIt;
     if (!myPageToCreator.contains(aKey))
@@ -56,19 +75,37 @@ used by another widget creator");
   }
 }
 
+bool ModuleBase_WidgetCreatorFactory::hasPanelWidget(const std::string& theType)
+{
+  return myPanelToCreator.contains(theType);
+}
+
+QWidget* ModuleBase_WidgetCreatorFactory::createPanelByType(const std::string& theType,
+                                                            QWidget* theParent,
+                                                            const FeaturePtr& theFeature)
+{
+  QWidget* aPanel = 0;
+  if (myPanelToCreator.contains(theType)) {
+    WidgetCreatorPtr aCreator = myPanelToCreator[theType];
+    aPanel = aCreator->createPanelByType(theType, theParent, theFeature);
+  }
+  return aPanel;
+}
+
 bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
 {
   return myPageToCreator.contains(theType);
 }
 
 ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
-                              const std::string& theType, QWidget* theParent)
+                                          const std::string& theType, QWidget* theParent,
+                                          Config_WidgetAPI* theWidgetApi)
 {
   ModuleBase_PageBase* aPage = 0;
 
   if (myPageToCreator.contains(theType)) {
     WidgetCreatorPtr aCreator = myPageToCreator[theType];
-    aPage = aCreator->createPageByType(theType, theParent);
+    aPage = aCreator->createPageByType(theType, theParent, theWidgetApi);
   }
 
   return aPage;
@@ -76,13 +113,15 @@ ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
 
 
 ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
-                              const std::string& theType, QWidget* theParent)
+                                                const std::string& theType, QWidget* theParent,
+                                                Config_WidgetAPI* theWidgetApi,
+                                                ModuleBase_IWorkshop* theWorkshop)
 {
   ModuleBase_ModelWidget* aWidget = 0;
 
   if (myCreators.contains(theType)) {
     WidgetCreatorPtr aCreator = myCreators[theType];
-    aWidget = aCreator->createWidgetByType(theType, theParent);
+    aWidget = aCreator->createWidgetByType(theType, theParent, theWidgetApi, theWorkshop);
   }
 
   return aWidget;