1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <ModuleBase_WidgetCreatorFactory.h>
22 #include <ModuleBase_IWidgetCreator.h>
24 #include <Config_WidgetAPI.h>
26 #include <Events_InfoMessage.h>
28 #include <QStringList>
30 /// Factory instance that will be initialized by first getting, one per application
31 std::shared_ptr<ModuleBase_WidgetCreatorFactory> MY_WIDGET_CREATOR_FACTORY;
33 std::shared_ptr<ModuleBase_WidgetCreatorFactory> ModuleBase_WidgetCreatorFactory::get()
35 if (!MY_WIDGET_CREATOR_FACTORY) {
36 MY_WIDGET_CREATOR_FACTORY =
37 std::shared_ptr<ModuleBase_WidgetCreatorFactory>(new ModuleBase_WidgetCreatorFactory());
39 return MY_WIDGET_CREATOR_FACTORY;
42 ModuleBase_WidgetCreatorFactory::ModuleBase_WidgetCreatorFactory()
46 ModuleBase_WidgetCreatorFactory::~ModuleBase_WidgetCreatorFactory()
50 void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator)
52 std::set<std::string>::const_iterator anIt, aLast;
53 /// fill map of panels
54 std::set<std::string> aPanelTypes;
55 theCreator->panelTypes(aPanelTypes);
56 for (anIt = aPanelTypes.begin(), aLast = aPanelTypes.end(); anIt != aLast; anIt++) {
57 std::string aKey = *anIt;
58 if (!myPanelToCreator.contains(aKey))
59 myPanelToCreator[aKey] = theCreator;
61 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
62 "The %1 panel XML definition has been already used by another widget creator")
67 /// fill map of widgets
68 std::set<std::string> aTypes;
69 theCreator->widgetTypes(aTypes);
70 for (anIt = aTypes.begin(), aLast = aTypes.end(); anIt != aLast; anIt++) {
71 std::string aKey = *anIt;
72 if (!myCreators.contains(aKey))
73 myCreators[aKey] = theCreator;
75 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
76 "The %1 widget XML definition has been already used by another widget creator")
82 std::set<std::string> aPTypes;
83 theCreator->pageTypes(aPTypes);
84 for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
85 std::string aKey = *anIt;
86 if (!myPageToCreator.contains(aKey))
87 myPageToCreator[aKey] = theCreator;
89 Events_InfoMessage("ModuleBase_WidgetCreatorFactory",
90 "The %1 page XML definition has been already used by another widget creator")
96 bool ModuleBase_WidgetCreatorFactory::hasPanelWidget(const std::string& theType)
98 return myPanelToCreator.contains(theType);
101 QWidget* ModuleBase_WidgetCreatorFactory::createPanelByType(const std::string& theType,
103 const FeaturePtr& theFeature)
106 if (myPanelToCreator.contains(theType)) {
107 WidgetCreatorPtr aCreator = myPanelToCreator[theType];
108 aPanel = aCreator->createPanelByType(theType, theParent, theFeature);
113 bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
115 return myPageToCreator.contains(theType);
118 ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
119 const std::string& theType, QWidget* theParent,
120 Config_WidgetAPI* theWidgetApi)
122 ModuleBase_PageBase* aPage = 0;
124 if (myPageToCreator.contains(theType)) {
125 WidgetCreatorPtr aCreator = myPageToCreator[theType];
126 aPage = aCreator->createPageByType(theType, theParent, theWidgetApi);
133 ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
134 const std::string& theType, QWidget* theParent,
135 Config_WidgetAPI* theWidgetApi,
136 ModuleBase_IWorkshop* theWorkshop)
138 ModuleBase_ModelWidget* aWidget = 0;
140 if (myCreators.contains(theType)) {
141 WidgetCreatorPtr aCreator = myCreators[theType];
142 aWidget = aCreator->createWidgetByType(theType, theParent, theWidgetApi, theWorkshop);