SET(CMAKE_AUTOMOC ON)
SET(PROJECT_HEADERS
- ModuleBase.h
+ ModuleBase.h
ModuleBase_ActionInfo.h
ModuleBase_Definitions.h
ModuleBase_DoubleSpinBox.h
ModuleBase_ViewerPrs.h
ModuleBase_WidgetBoolValue.h
ModuleBase_WidgetChoice.h
+ ModuleBase_WidgetCreatorFactory.h
ModuleBase_WidgetDoubleValue.h
ModuleBase_WidgetEditor.h
ModuleBase_WidgetExprEditor.h
ModuleBase_ViewerPrs.cpp
ModuleBase_WidgetBoolValue.cpp
ModuleBase_WidgetChoice.cpp
+ ModuleBase_WidgetCreatorFactory.cpp
ModuleBase_WidgetDoubleValue.cpp
ModuleBase_WidgetEditor.cpp
ModuleBase_WidgetExprEditor.cpp
QWidget* theParent = NULL) = 0;
};
+typedef std::shared_ptr<ModuleBase_IWidgetCreator> WidgetCreatorPtr;
+
#endif
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetCreatorFactory.cpp
+// Created: 03 Dec 2015
+// Author: Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetCreatorFactory.h>
+#include <ModuleBase_IWidgetCreator.h>
+
+#include <Events_Error.h>
+
+#include <QStringList>
+
+/// Factory instance that will be initialized by first getting, one per application
+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());
+ }
+ return MY_WIDGET_CREATOR_FACTORY;
+}
+
+ModuleBase_WidgetCreatorFactory::ModuleBase_WidgetCreatorFactory()
+{
+}
+
+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::string aKey = *anIt;
+ if (!myModelWidgets.contains(aKey))
+ myModelWidgets[aKey] = theCreator;
+ else {
+ Events_Error::send("The" + aKey + " widget XML definition has been already\
+ used by another widget creator");
+ }
+ }
+}
+
+ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
+ const std::string& theType, QWidget* theParent)
+{
+ ModuleBase_ModelWidget* aWidget = 0;
+
+ if (myModelWidgets.contains(theType)) {
+ WidgetCreatorPtr aCreator = myModelWidgets[theType];
+ aWidget = aCreator->createWidgetByType(theType, theParent);
+ }
+
+ return aWidget;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_WidgetCreatorFactory.cpp
+// Created: 03 Dec 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef MODULEBASE_WIDGETCREATORFACTORY_H_
+#define MODULEBASE_WIDGETCREATORFACTORY_H_
+
+#include <ModuleBase.h>
+
+#include <memory>
+#include <string>
+
+#include <QMap>
+
+#include <ModuleBase_IWidgetCreator.h>
+
+class ModuleBase_ModelWidget;
+
+class QWidget;
+
+/**
+* \ingroup GUI
+* A class for creation of widgets instances in for property panel using XML deskription of
+* a feature
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory
+{
+ public:
+ // Returns an singular instance of the class if it exists or create it
+ static std::shared_ptr<ModuleBase_WidgetCreatorFactory> get();
+
+ /// Destructor
+ virtual ~ModuleBase_WidgetCreatorFactory();
+
+ /// The creator is added to the internal container to be used when the createWidgetByType is called
+ /// \param theCreator a new widget creator
+ void registerCreator(const WidgetCreatorPtr& theCreator);
+
+ /// Create widget by its type
+ /// \param theType a type
+ /// \param theParent a parent widget
+ ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
+ QWidget* theParent = NULL);
+
+private:
+ /// Constructor is hidden
+ ModuleBase_WidgetCreatorFactory();
+
+ /// List of created model widgets
+ QMap<std::string, WidgetCreatorPtr> myModelWidgets;
+};
+
+typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
+
+#endif /* MODULEBASE_WIDGETCREATORFACTORY_H_ */
#include <ModuleBase_PageGroupBox.h>
#include <ModuleBase_PageWidget.h>
#include <ModuleBase_WidgetExprEditor.h>
+#include <ModuleBase_WidgetCreatorFactory.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
result = NULL;
} else {
result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi, myParentId);
+ if (!result)
+ result = ModuleBase_WidgetCreatorFactory::get()->createWidgetByType(theType, theParent);
#ifdef _DEBUG
if (!result) {
qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type %s", theType.c_str());
}
#endif
}
- if (result) {
+ if (result)
myModelWidgets.append(result);
- }
return result;
}
#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Validator.h>
+
+#include <ModuleBase_WidgetCreatorFactory.h>
+#include <SketchShapePlugin_WidgetCreator.h>
/*#include <ModelAPI_Data.h>
#include <ModuleBase_ModelWidget.h>
#include <memory>*/
// the only created instance of this plugin
-//static SketchShapePlugin_Plugin* MY_SKETCH_SHAPE_INSTANCE = new SketchShapePlugin_Plugin();
+static SketchShapePlugin_Plugin* MY_SKETCH_SHAPE_INSTANCE = new SketchShapePlugin_Plugin();
SketchShapePlugin_Plugin::SketchShapePlugin_Plugin()
{
aFactory->registerValidator("SketchShapePlugin_FeatureValidator",
new SketchShapePlugin_FeatureValidator);
+ WidgetCreatorFactoryPtr aWidgetCreatorFactory = ModuleBase_WidgetCreatorFactory::get();
+ aWidgetCreatorFactory->registerCreator(
+ std::shared_ptr<SketchShapePlugin_WidgetCreator>(new SketchShapePlugin_WidgetCreator()));
+
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
}
const std::string& theType, QWidget* theParent)
{
ModuleBase_ModelWidget* aWidget = 0;
- if (myTypes.find(theType) != myTypes.end())
+ if (myTypes.find(theType) == myTypes.end())
return aWidget;
- if (theType == "sketchshape_groupbox") {
- //aWidget =
- new SketchShapePlugin_PageGroupBox(theParent);
- }
+ //if (theType == "sketchshape_groupbox") {
+ // aWidget = new SketchShapePlugin_PageGroupBox(theParent);
+ //}
return aWidget;
}
std::set<std::string> myTypes; /// types of widgets
};
+typedef std::shared_ptr<SketchShapePlugin_WidgetCreator> SketchShapePlguinWidgetCreatorPtr;
#endif