]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp
Salome HOME
Issue #1834: Fix length of lines
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetCreatorFactory.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetCreatorFactory.cpp
4 // Created:     03 Dec 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <ModuleBase_WidgetCreatorFactory.h>
8 #include <ModuleBase_IWidgetCreator.h>
9
10 #include <Config_WidgetAPI.h>
11
12 #include <Events_InfoMessage.h>
13
14 #include <QStringList>
15
16 /// Factory instance that will be initialized by first getting, one per application
17 std::shared_ptr<ModuleBase_WidgetCreatorFactory> MY_WIDGET_CREATOR_FACTORY;
18
19 std::shared_ptr<ModuleBase_WidgetCreatorFactory> ModuleBase_WidgetCreatorFactory::get()
20 {
21   if (!MY_WIDGET_CREATOR_FACTORY) {
22     MY_WIDGET_CREATOR_FACTORY =  
23       std::shared_ptr<ModuleBase_WidgetCreatorFactory>(new ModuleBase_WidgetCreatorFactory());
24   }
25   return MY_WIDGET_CREATOR_FACTORY;
26 }
27
28 ModuleBase_WidgetCreatorFactory::ModuleBase_WidgetCreatorFactory()
29 {
30 }
31
32 ModuleBase_WidgetCreatorFactory::~ModuleBase_WidgetCreatorFactory()
33 {
34 }
35
36 void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator)
37 {
38   std::set<std::string>::const_iterator anIt, aLast;
39   /// fill map of panels
40   std::set<std::string> aPanelTypes;
41   theCreator->panelTypes(aPanelTypes);
42   for (anIt = aPanelTypes.begin(), aLast = aPanelTypes.end(); anIt != aLast; anIt++) {
43     std::string aKey = *anIt;
44     if (!myPanelToCreator.contains(aKey))
45       myPanelToCreator[aKey] = theCreator;
46     else {
47       Events_InfoMessage("ModuleBase_WidgetCreatorFactory", 
48         "The %1 panel XML definition has been already used by another widget creator")
49         .arg(aKey).send();
50     }
51   }
52
53   /// fill map of widgets
54   std::set<std::string> aTypes;
55   theCreator->widgetTypes(aTypes);
56   for (anIt = aTypes.begin(), aLast = aTypes.end(); anIt != aLast; anIt++) {
57     std::string aKey = *anIt;
58     if (!myCreators.contains(aKey))
59       myCreators[aKey] = theCreator;
60     else {
61       Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
62         "The %1 widget XML definition has been already used by another widget creator")
63         .arg(aKey).send();
64     }
65   }
66
67   /// fill map of pages
68   std::set<std::string> aPTypes;
69   theCreator->pageTypes(aPTypes);
70   for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
71     std::string aKey = *anIt;
72     if (!myPageToCreator.contains(aKey))
73       myPageToCreator[aKey] = theCreator;
74     else {
75       Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
76         "The %1 page XML definition has been already used by another widget creator")
77         .arg(aKey).send();
78     }
79   }
80 }
81
82 bool ModuleBase_WidgetCreatorFactory::hasPanelWidget(const std::string& theType)
83 {
84   return myPanelToCreator.contains(theType);
85 }
86
87 QWidget* ModuleBase_WidgetCreatorFactory::createPanelByType(const std::string& theType,
88                                                             QWidget* theParent,
89                                                             const FeaturePtr& theFeature)
90 {
91   QWidget* aPanel = 0;
92   if (myPanelToCreator.contains(theType)) {
93     WidgetCreatorPtr aCreator = myPanelToCreator[theType];
94     aPanel = aCreator->createPanelByType(theType, theParent, theFeature);
95   }
96   return aPanel;
97 }
98
99 bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
100 {
101   return myPageToCreator.contains(theType);
102 }
103
104 ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
105                                           const std::string& theType, QWidget* theParent,
106                                           Config_WidgetAPI* theWidgetApi)
107 {
108   ModuleBase_PageBase* aPage = 0;
109
110   if (myPageToCreator.contains(theType)) {
111     WidgetCreatorPtr aCreator = myPageToCreator[theType];
112     aPage = aCreator->createPageByType(theType, theParent, theWidgetApi);
113   }
114
115   return aPage;
116 }
117
118
119 ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
120                                                 const std::string& theType, QWidget* theParent,
121                                                 Config_WidgetAPI* theWidgetApi,
122                                                 ModuleBase_IWorkshop* theWorkshop)
123 {
124   ModuleBase_ModelWidget* aWidget = 0;
125
126   if (myCreators.contains(theType)) {
127     WidgetCreatorPtr aCreator = myCreators[theType];
128     aWidget = aCreator->createWidgetByType(theType, theParent, theWidgetApi, theWorkshop);
129   }
130
131   return aWidget;
132 }