Salome HOME
Construction of vertices/edges/faces on the base of sketch: a special group box in...
authornds <nds@opencascade.com>
Fri, 4 Dec 2015 15:02:59 +0000 (18:02 +0300)
committerdbv <dbv@opencascade.com>
Tue, 8 Dec 2015 08:51:15 +0000 (11:51 +0300)
src/ModuleBase/ModuleBase_IWidgetCreator.h
src/ModuleBase/ModuleBase_WidgetCreatorFactory.cpp
src/ModuleBase/ModuleBase_WidgetCreatorFactory.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.cpp
src/SketchShapePlugin/SketchShapePlugin_WidgetCreator.h

index 58ec86295ede58754705b97acda26ce3e1c904ed..ecdee3a848a534f3e95c0af2d6a3bbafe049723e 100755 (executable)
@@ -10,6 +10,7 @@
 #include <memory>
 
 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<std::string>& pageTypes() = 0;
+
+  /// Returns a container of possible widget types, which this creator can process
+  /// \returns types
   virtual const std::set<std::string>& 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,
index ff3ee01f9c5dbf6e89158a1c92c547c4de0230b7..1427e22a709ef242ac8043081cee93f30217d193 100755 (executable)
@@ -36,22 +36,52 @@ void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& th
   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;
+    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<std::string>& 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);
   }
 
index 40db320086f97470c398c924a2febeee4522331c..63c4d626085f11f733119af76bcde95ee4f018da 100755 (executable)
@@ -17,6 +17,7 @@
 #include <ModuleBase_IWidgetCreator.h>
 
 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<std::string, WidgetCreatorPtr> myModelWidgets;
+  /// Map of widget type in XML to creator
+  QMap<std::string, WidgetCreatorPtr> myCreators;
+
+  /// Map of widget page in XML to creator
+  QMap<std::string, WidgetCreatorPtr> myPageToCreator;
 };
 
 typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
index dd124111185c05c0e5e379ae5ea0eac684193575..dec5f78ab6efc24d0e717b0b784ca7128f3e0052 100644 (file)
@@ -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)
 {
index 1e1f29fa76e8dfc54e6de9b682f1efc2881cc0f5..05f3b7b8a2bba7c6fc1c8750ac3e109523047785 100644 (file)
@@ -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);
 
index 5c01de0632ed1ccd14d73b5f8a4788ecccf59019..a5fa8cda417b75e219040daaf0343b7e311c4d72 100755 (executable)
@@ -6,7 +6,12 @@
 SketchShapePlugin_WidgetCreator::SketchShapePlugin_WidgetCreator()
 : ModuleBase_IWidgetCreator()
 {
-  myTypes.insert("sketchshape_groupbox");
+  myPages.insert("sketchshape_groupbox");
+}
+
+const std::set<std::string>& SketchShapePlugin_WidgetCreator::pageTypes()
+{
+  return myPages;
 }
 
 const std::set<std::string>& SketchShapePlugin_WidgetCreator::widgetTypes()
@@ -14,6 +19,20 @@ const std::set<std::string>& 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)
 {
index fe4a442217d11234157c3274cd40edeb2f577d37..7d3e734b493e2f81b23f0a126d725fcdd24f6664 100755 (executable)
@@ -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<std::string>& pageTypes();
+
   /// Returns a list of possible widget types, which this creator can process
-  /// \return theTypes
+  /// \returns types
   virtual const std::set<std::string>& 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<std::string> myPages; /// types of pages
   std::set<std::string> myTypes; /// types of widgets
 };