From: nds Date: Fri, 4 Dec 2015 15:02:59 +0000 (+0300) Subject: Construction of vertices/edges/faces on the base of sketch: a special group box in... X-Git-Tag: V_2.1.0~214 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=37535e49f0b43f7b6605d6e23ead3d589580f41f;p=modules%2Fshaper.git Construction of vertices/edges/faces on the base of sketch: a special group box in shape plugin --- diff --git a/src/ModuleBase/ModuleBase_IWidgetCreator.h b/src/ModuleBase/ModuleBase_IWidgetCreator.h index 58ec86295..ecdee3a84 100755 --- a/src/ModuleBase/ModuleBase_IWidgetCreator.h +++ b/src/ModuleBase/ModuleBase_IWidgetCreator.h @@ -10,6 +10,7 @@ #include class ModuleBase_ModelWidget; +class ModuleBase_PageBase; class QWidget; @@ -26,11 +27,21 @@ public: /// Virtual destructor ~ModuleBase_IWidgetCreator(); - /// Returns a list of possible widget types, which this creator can process - /// \param theTypes + /// Returns a container of possible page types, which this creator can process + /// \returns types + virtual const std::set& pageTypes() = 0; + + /// Returns a container of possible widget types, which this creator can process + /// \returns types virtual const std::set& widgetTypes() = 0; - /// Create widget by its type + /// Create page by its type + /// \param theType a type + /// \param theParent a parent widget + virtual ModuleBase_PageBase* createPageByType(const std::string& theType, + QWidget* theParent) = 0; + + /// Create widget by its type /// \param theType a type /// \param theParent a parent widget virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, diff --git a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp index ff3ee01f9..1427e22a7 100755 --- a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp @@ -36,22 +36,52 @@ void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& th std::set::const_iterator anIt = aTypes.begin(), aLast = aTypes.end(); for (; anIt != aLast; anIt++) { std::string aKey = *anIt; - if (!myModelWidgets.contains(aKey)) - myModelWidgets[aKey] = theCreator; + 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_Error::send("The" + aKey + " widget XML definition has been already \ +used by another widget creator"); } } + + const std::set& aPTypes = theCreator->pageTypes(); + 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"); + } + } +} + +bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType) +{ + return myPageToCreator.contains(theType); } +ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType( + const std::string& theType, QWidget* theParent) +{ + ModuleBase_PageBase* aPage = 0; + + if (myPageToCreator.contains(theType)) { + WidgetCreatorPtr aCreator = myPageToCreator[theType]; + aPage = aCreator->createPageByType(theType, theParent); + } + + return aPage; +} + + ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType( const std::string& theType, QWidget* theParent) { ModuleBase_ModelWidget* aWidget = 0; - if (myModelWidgets.contains(theType)) { - WidgetCreatorPtr aCreator = myModelWidgets[theType]; + if (myCreators.contains(theType)) { + WidgetCreatorPtr aCreator = myCreators[theType]; aWidget = aCreator->createWidgetByType(theType, theParent); } diff --git a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h index 40db32008..63c4d6260 100755 --- a/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetCreatorFactory.h @@ -17,6 +17,7 @@ #include class ModuleBase_ModelWidget; +class ModuleBase_PageBase; class QWidget; @@ -38,6 +39,16 @@ class MODULEBASE_EXPORT ModuleBase_WidgetCreatorFactory /// \param theCreator a new widget creator void registerCreator(const WidgetCreatorPtr& theCreator); + /// Returns true if there is a creator, which can make a page by the type + /// \param theType a type + bool hasPageWidget(const std::string& theType); + + /// Create page by its type + /// \param theType a type + /// \param theParent a parent widget + ModuleBase_PageBase* createPageByType(const std::string& theType, + QWidget* theParent = NULL); + /// Create widget by its type /// \param theType a type /// \param theParent a parent widget @@ -48,8 +59,11 @@ private: /// Constructor is hidden ModuleBase_WidgetCreatorFactory(); - /// List of created model widgets - QMap myModelWidgets; + /// Map of widget type in XML to creator + QMap myCreators; + + /// Map of widget page in XML to creator + QMap myPageToCreator; }; typedef std::shared_ptr WidgetCreatorFactoryPtr; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index dd1241111..dec5f78ab 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -77,11 +77,12 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage) do { //Iterate over each node std::string aWdgType = myWidgetApi->widgetType(); // Create PageGroup TODO: extract - if (myWidgetApi->isGroupBoxWidget()) { + if (myWidgetApi->isGroupBoxWidget() || + ModuleBase_WidgetCreatorFactory::get()->hasPageWidget(aWdgType)) { + //if current widget is groupbox (container) process it's children recursively - QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); - ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(thePage->pageWidget()); - aPage->setTitle(aGroupName); + ModuleBase_PageBase* aPage = createPageByType(aWdgType, thePage->pageWidget()); + createWidget(aPage); thePage->addPageWidget(aPage); } else { @@ -119,6 +120,24 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage) thePage->alignToTop(); } +ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::string& theType, + QWidget* theParent) +{ + ModuleBase_PageBase* aResult = NULL; + + if (theType == WDG_GROUP) { + QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); + ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(theParent); + aPage->setTitle(aGroupName); + aResult = aPage; + } + + if (!aResult) + aResult = ModuleBase_WidgetCreatorFactory::get()->createPageByType(theType, theParent); + + return aResult; +} + ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType, QWidget* theParent) { diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index 1e1f29fa7..05f3b7b8a 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -51,9 +51,16 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory protected: /// check if ModuleBase_Widget has expandable widgets in getControls bool hasExpandingControls(QWidget* theParent); - /// Create widget by its type - /// \param theType a type - /// \param theParent a parent widget + + /// Create page by its type + /// \param theType a type + /// \param theParent a parent widget + ModuleBase_PageBase* createPageByType(const std::string& theType, + QWidget* theParent); + + /// Create widget by its type + /// \param theType a type + /// \param theParent a parent widget ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL); diff --git a/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.cpp b/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.cpp index 5c01de063..a5fa8cda4 100755 --- a/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.cpp +++ b/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.cpp @@ -6,7 +6,12 @@ SketchShapePlugin_WidgetCreator::SketchShapePlugin_WidgetCreator() : ModuleBase_IWidgetCreator() { - myTypes.insert("sketchshape_groupbox"); + myPages.insert("sketchshape_groupbox"); +} + +const std::set& SketchShapePlugin_WidgetCreator::pageTypes() +{ + return myPages; } const std::set& SketchShapePlugin_WidgetCreator::widgetTypes() @@ -14,6 +19,20 @@ const std::set& SketchShapePlugin_WidgetCreator::widgetTypes() return myTypes; } +ModuleBase_PageBase* SketchShapePlugin_WidgetCreator::createPageByType( + const std::string& theType, QWidget* theParent) +{ + ModuleBase_PageBase* aPage = 0; + if (myPages.find(theType) == myPages.end()) + return aPage; + + if (theType == "sketchshape_groupbox") { + aPage = new SketchShapePlugin_PageGroupBox(theParent); + } + + return aPage; +} + ModuleBase_ModelWidget* SketchShapePlugin_WidgetCreator::createWidgetByType( const std::string& theType, QWidget* theParent) { diff --git a/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.h b/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.h index fe4a44221..7d3e734b4 100755 --- a/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.h +++ b/src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.h @@ -24,10 +24,20 @@ public: /// Virtual destructor ~SketchShapePlugin_WidgetCreator() {} + /// Returns a container of possible page types, which this creator can process + /// \returns types + virtual const std::set& pageTypes(); + /// Returns a list of possible widget types, which this creator can process - /// \return theTypes + /// \returns types virtual const std::set& widgetTypes(); + /// Create page by its type + /// \param theType a type + /// \param theParent a parent widget + virtual ModuleBase_PageBase* createPageByType(const std::string& theType, + QWidget* theParent); + /// Create widget by its type /// \param theType a type /// \param theParent a parent widget @@ -35,6 +45,7 @@ public: QWidget* theParent = NULL); private: + std::set myPages; /// types of pages std::set myTypes; /// types of widgets };