Salome HOME
#2027 Sketcher Trim Feature: correction of compilation on Linux
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetCreatorFactory.cpp
index 3f2ff93079c0e633f0caf23126abbd48b14d3e29..d9f10f31ce9df6d5a50c760aadd8bbfc4b9c3690 100755 (executable)
@@ -9,7 +9,7 @@
 
 #include <Config_WidgetAPI.h>
 
-#include <Events_Error.h>
+#include <Events_InfoMessage.h>
 
 #include <QStringList>
 
@@ -19,7 +19,8 @@ std::shared_ptr<ModuleBase_WidgetCreatorFactory> MY_WIDGET_CREATOR_FACTORY;
 std::shared_ptr<ModuleBase_WidgetCreatorFactory> ModuleBase_WidgetCreatorFactory::get()
 {
   if (!MY_WIDGET_CREATOR_FACTORY) {
-    MY_WIDGET_CREATOR_FACTORY =  std::shared_ptr<ModuleBase_WidgetCreatorFactory>(new ModuleBase_WidgetCreatorFactory());
+    MY_WIDGET_CREATOR_FACTORY =
+      std::shared_ptr<ModuleBase_WidgetCreatorFactory>(new ModuleBase_WidgetCreatorFactory());
   }
   return MY_WIDGET_CREATOR_FACTORY;
 }
@@ -34,30 +35,67 @@ 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_InfoMessage("ModuleBase_WidgetCreatorFactory",
+        "The %1 panel XML definition has been already used by another widget creator")
+        .arg(aKey).send();
+    }
+  }
+
+  /// 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;
     else {
-      Events_Error::send("The" + aKey + " widget XML definition has been already \
-used by another widget creator");
+      Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
+        "The %1 widget XML definition has been already used by another widget creator")
+        .arg(aKey).send();
     }
   }
 
-  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))
       myPageToCreator[aKey] = theCreator;
     else {
-      Events_Error::send("The" + aKey + " page XML definition has been already \
-used by another widget creator");
+      Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
+        "The %1 page XML definition has been already used by another widget creator")
+        .arg(aKey).send();
     }
   }
 }
 
+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);