Salome HOME
Issue #1368: Creation of a Qt panel. SamplePanelPlugin feature providing
authornds <nds@opencascade.com>
Wed, 30 Mar 2016 05:11:31 +0000 (08:11 +0300)
committernds <nds@opencascade.com>
Wed, 30 Mar 2016 05:11:31 +0000 (08:11 +0300)
16 files changed:
CMakeLists.txt
src/Config/Config_WidgetReader.cpp
src/ModuleBase/ModuleBase_IWidgetCreator.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/SamplePanelPlugin/CMakeLists.txt [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin.h [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_Feature.cpp [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_Feature.h [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_Panel.cpp [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_Panel.h [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_Plugin.h [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.cpp [new file with mode: 0755]
src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h [new file with mode: 0755]
src/SamplePanelPlugin/plugin-SamplePanel.xml [new file with mode: 0755]
src/XGUI/XGUI_OperationMgr.cpp

index 41bd7152619fb9935c211534517ee64acb4057d5..649cf98c0b7ac766fed17fb5cee86f7def5faadf 100644 (file)
@@ -79,6 +79,7 @@ ADD_SUBDIRECTORY (src/GeomDataAPI)
 ADD_SUBDIRECTORY (src/PartSetPlugin)
 ADD_SUBDIRECTORY (src/ConstructionPlugin)
 ADD_SUBDIRECTORY (src/FeaturesPlugin)
+ADD_SUBDIRECTORY (src/SamplePanelPlugin)
 ADD_SUBDIRECTORY (src/SketcherPrs)
 ADD_SUBDIRECTORY (src/SketchPlugin)
 ADD_SUBDIRECTORY (src/SketchSolver)
index 25d1fdc65c090722c4dddf32bf36ad88068f4cd3..4a6590c68a20446a7300d17e4da827ca498b5730 100644 (file)
@@ -94,6 +94,14 @@ std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode)
 {
   std::string result = "";
   if (!hasChild(theNode)) {
+    // feature which has the next property should be dumped itself
+    std::string anOwnPanel = getProperty(theNode, PROPERTY_PANEL_ID);
+    if (!anOwnPanel.empty()) {
+      xmlBufferPtr buffer = xmlBufferCreate();
+      int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 0);
+      result = std::string((char*) (buffer->content));
+      xmlBufferFree(buffer);
+    }
     return result;
   }
   //Replace all "source" nodes with content;
index d27f5be824bf2ce86db3239baf4c84ff8dd473ec..cbab144bed2bda4c567efaa159edab5d164afa8e 100755 (executable)
@@ -31,10 +31,12 @@ public:
   ~ModuleBase_IWidgetCreator();
 
   /// Returns a container of possible page types, which this creator can process
+  /// The default implementation is empty
   /// \param theTypes a list of type names
   virtual void panelTypes(std::set<std::string>& theTypes) {}
 
   /// Returns a container of possible page types, which this creator can process
+  /// The default implementation is empty
   /// \param a list of type names
   virtual void pageTypes(std::set<std::string>& theTypes) {}
 
@@ -43,6 +45,7 @@ public:
   virtual void widgetTypes(std::set<std::string>& theTypes) {}
 
   /// Create panel control by its type.
+  /// The default implementation is empty
   /// \param theType a panel type
   /// \param theParent a parent widget
   /// \return created widget or null
@@ -50,6 +53,7 @@ public:
                                      QWidget* theParent);
 
   /// Create page by its type
+  /// The default implementation is empty
   /// \param theType a type
   /// \param theParent a parent widget
   /// \param theData a low-level API for reading xml definitions of widgets
@@ -58,6 +62,7 @@ public:
                                                 Config_WidgetAPI* theWidgetApi);
 
   /// Create widget by its type
+  /// The default implementation is empty
   /// \param theType a type
   /// \param theParent a parent widget
   /// \param theData a low-level API for reading xml definitions of widgets
index 165aa750fa7acdf9aac2c929efd25642edba9067..e8ae59b507d7ae2a7401fa7b4a52737d3638bf94 100644 (file)
@@ -76,6 +76,7 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
     QWidget* aPanel = createPanel(thePage->pageWidget());
     if (aPanel) {
       thePage->addWidget(aPanel);
+      thePage->alignToTop();
       return;
     }
   }
diff --git a/src/SamplePanelPlugin/CMakeLists.txt b/src/SamplePanelPlugin/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..afb6f04
--- /dev/null
@@ -0,0 +1,45 @@
+## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+INCLUDE(Common)
+INCLUDE(UnitTest)
+
+SET(PROJECT_HEADERS
+    SamplePanelPlugin.h
+    SamplePanelPlugin_Feature.h
+    SamplePanelPlugin_Panel.h
+    SamplePanelPlugin_Plugin.h
+    SamplePanelPlugin_WidgetCreator.h
+)
+
+SET(PROJECT_SOURCES
+    SamplePanelPlugin_Feature.cpp
+    SamplePanelPlugin_Panel.cpp
+    SamplePanelPlugin_Plugin.cpp
+    SamplePanelPlugin_WidgetCreator.cpp
+)
+
+SET(PROJECT_LIBRARIES
+    Config
+    Events
+    ModelAPI
+    ModuleBase
+    ${QT_LIBRARIES}
+)
+
+SET(XML_RESOURCES
+  plugin-SamplePanel.xml
+)
+
+ADD_DEFINITIONS(-DSAMPLEPANELPLUGIN_EXPORTS -DWNT)
+ADD_LIBRARY(SamplePanelPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
+TARGET_LINK_LIBRARIES(SamplePanelPlugin ${PROJECT_LIBRARIES})
+
+INCLUDE_DIRECTORIES(
+  ../Config
+  ../Events
+  ../ModelAPI
+  ../ModuleBase
+)
+
+INSTALL(TARGETS SamplePanelPlugin DESTINATION plugins)
+INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin.h b/src/SamplePanelPlugin/SamplePanelPlugin.h
new file mode 100755 (executable)
index 0000000..6960dc4
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+#ifndef SAMPLEPANELPLUGIN_H
+#define SAMPLEPANELPLUGIN_H
+
+#if defined SAMPLEPANELPLUGIN_EXPORTS
+#if defined WIN32
+#define SAMPLEPANELPLUGIN_EXPORT              __declspec( dllexport )
+#else
+#define SAMPLEPANELPLUGIN_EXPORT
+#endif
+#else
+#if defined WIN32
+#define SAMPLEPANELPLUGIN_EXPORT              __declspec( dllimport )
+#else
+#define SAMPLEPANELPLUGIN_EXPORT
+#endif
+#endif
+
+#endif
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_Feature.cpp b/src/SamplePanelPlugin/SamplePanelPlugin_Feature.cpp
new file mode 100755 (executable)
index 0000000..3beab1b
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SamplePanelPlugin_Feature.cpp
+// Created:     29 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#include "SamplePanelPlugin_Feature.h"
+
+SamplePanelPlugin_Feature::SamplePanelPlugin_Feature()
+: ModelAPI_Feature()
+{
+}
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_Feature.h b/src/SamplePanelPlugin/SamplePanelPlugin_Feature.h
new file mode 100755 (executable)
index 0000000..6c4db00
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SamplePanelPlugin_Feature.h
+// Created:     29 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef SAMPLEPANELPLUGIN_FEATURE_H_
+#define SAMPLEPANELPLUGIN_FEATURE_H_
+
+#include "SamplePanelPlugin.h"
+
+#include <ModelAPI_Feature.h>
+
+/**\class SamplePanelPlugin_Feature
+ * \ingroup Plugins
+ * \brief Sample feature to be filled by the panel.
+ */
+class SamplePanelPlugin_Feature : public ModelAPI_Feature
+{
+ public:
+  /// SketchShape feature kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_SAMPLE_PANEL_FEATURE_ID("SamplePanelFeature");
+    return MY_SAMPLE_PANEL_FEATURE_ID;
+  }
+
+  /// Request for initialization of data model of the object: adding all attributes
+  virtual void initAttributes() {};
+
+  /// Returns the unique kind of a feature
+  virtual const std::string& getKind() {
+    static std::string MY_KIND = SamplePanelPlugin_Feature::ID();
+    return MY_KIND;
+  };
+
+  /// Computes or recomputes the results
+  virtual void execute() {}
+
+  /// Use plugin manager for features creation
+  SamplePanelPlugin_Feature();
+};
+
+typedef std::shared_ptr<SamplePanelPlugin_Feature> SamplePanelFeaturePtr;
+
+#endif
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_Panel.cpp b/src/SamplePanelPlugin/SamplePanelPlugin_Panel.cpp
new file mode 100755 (executable)
index 0000000..baaecd7
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SamplePanelPlugin_PageGroupBox.h
+// Created:     29 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#include <SamplePanelPlugin_Panel.h>
+
+#include <QGridLayout>
+#include <QLabel>
+#include <QComboBox>
+
+SamplePanelPlugin_Panel::SamplePanelPlugin_Panel(QWidget* theParent)
+  : QWidget(theParent)
+{
+  QGridLayout* aLayout = new QGridLayout(this);
+  aLayout->addWidget(new QLabel("Values:"), 0, 0);
+
+  QComboBox* aComboBox = new QComboBox(this);
+  aComboBox->addItem("Value_1");
+  aComboBox->addItem("Value_2");
+  aComboBox->addItem("Value_3");
+
+  aLayout->addWidget(aComboBox, 0, 1);
+}
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_Panel.h b/src/SamplePanelPlugin/SamplePanelPlugin_Panel.h
new file mode 100755 (executable)
index 0000000..29c2859
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SamplePanelPlugin_PageGroupBox.h
+// Created:     29 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef SAMPLEPANELPLUGIN_PANEL_H_
+#define SAMPLEPANELPLUGIN_PANEL_H_
+
+#include <QWidget>
+
+/*!
+ * \ingroup GUI
+ * Represent a property panel's list of ModuleBase_ModelWidgets.
+ */
+class SamplePanelPlugin_Panel : public QWidget
+{
+public:
+  /// Constructs a panel page
+  SamplePanelPlugin_Panel(QWidget* theParent);
+  /// Destructs the page
+  virtual ~SamplePanelPlugin_Panel() {}
+};
+
+#endif /* SAMPLEPANELPLUGIN_PANEL_H_ */
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp b/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp
new file mode 100755 (executable)
index 0000000..cc59adb
--- /dev/null
@@ -0,0 +1,39 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SamplePanelPlugin_Plugin.cpp
+// Created:     29 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#include <SamplePanelPlugin_Plugin.h>
+#include <SamplePanelPlugin_Feature.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Validator.h>
+
+#include <ModuleBase_WidgetCreatorFactory.h>
+#include <SamplePanelPlugin_WidgetCreator.h>
+
+// the only created instance of this plugin
+static SamplePanelPlugin_Plugin* MY_SAMPLE_PANEL_PLUGIN_INSTANCE = new SamplePanelPlugin_Plugin();
+
+SamplePanelPlugin_Plugin::SamplePanelPlugin_Plugin()
+{
+  SessionPtr aMgr = ModelAPI_Session::get();
+
+  WidgetCreatorFactoryPtr aWidgetCreatorFactory = ModuleBase_WidgetCreatorFactory::get();
+  aWidgetCreatorFactory->registerCreator(
+          std::shared_ptr<SamplePanelPlugin_WidgetCreator>(new SamplePanelPlugin_WidgetCreator()));
+
+  // register this plugin
+  ModelAPI_Session::get()->registerPlugin(this);
+}
+
+FeaturePtr SamplePanelPlugin_Plugin::createFeature(std::string theFeatureID)
+{
+  if (theFeatureID == SamplePanelPlugin_Feature::ID()) {
+    return FeaturePtr(new SamplePanelPlugin_Feature);
+  }
+  // feature of such kind is not found
+  return FeaturePtr();
+}
+
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.h b/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.h
new file mode 100755 (executable)
index 0000000..dcad383
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SamplePanelPlugin_Plugin.hxx
+// Created:     29 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef SAMPLEPANELPLUGIN_PLUGIN_H_
+#define SAMPLEPANELPLUGIN_PLUGIN_H_
+
+#include <SamplePanelPlugin.h>
+#include <ModelAPI_Plugin.h>
+//#include <ModuleBase_IWidgetCreator.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Events.h>
+
+class ModuleBase_ModelWidget;
+class QWidget;
+
+/**\class SamplePanelPlugin_Plugin
+ * \ingroup Plugins
+ * \brief Interface common for any plugin: allows to use plugin by the plugins manager.
+ */
+//, public ModuleBase_IWidgetCreator
+class SamplePanelPlugin_Plugin : public ModelAPI_Plugin
+{
+public:
+  /// Creates the feature object of this plugin by the feature string ID
+  virtual FeaturePtr createFeature(std::string theFeatureID);
+
+ public:
+   SamplePanelPlugin_Plugin();
+};
+
+#endif
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.cpp b/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.cpp
new file mode 100755 (executable)
index 0000000..293f891
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SamplePanelPlugin_WidgetCreator.cpp
+// Created:     29 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#include "SamplePanelPlugin_WidgetCreator.h"
+
+#include "SamplePanelPlugin_Panel.h"
+
+SamplePanelPlugin_WidgetCreator::SamplePanelPlugin_WidgetCreator()
+: ModuleBase_IWidgetCreator()
+{
+  myPanelTypes.insert("SampePanel");
+}
+
+void SamplePanelPlugin_WidgetCreator::panelTypes(std::set<std::string>& theTypes)
+{
+  theTypes = myPanelTypes;
+}
+
+QWidget* SamplePanelPlugin_WidgetCreator::createPanelByType(const std::string& theType,
+                                                            QWidget* theParent)
+{
+  QWidget* aWidget = 0;
+  if (myPanelTypes.find(theType) == myPanelTypes.end())
+    return aWidget;
+
+  if (theType == "SampePanel") {
+    aWidget = new SamplePanelPlugin_Panel(theParent);
+  }
+
+  return aWidget;
+}
diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h b/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h
new file mode 100755 (executable)
index 0000000..315742f
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SamplePanelPlugin_WidgetCreator.h
+// Created:     29 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef SamplePanelPlugin_WidgetCreator_H
+#define SamplePanelPlugin_WidgetCreator_H
+
+#include "SamplePanelPlugin.h"
+
+#include <ModuleBase_IWidgetCreator.h>
+
+#include <string>
+#include <set>
+
+class QWidget;
+
+/** 
+* \ingroup GUI
+* Interface to WidgetCreator which can create specific widgets by type
+*/
+class SamplePanelPlugin_WidgetCreator : public ModuleBase_IWidgetCreator
+{
+public:
+  /// Default constructor
+  SamplePanelPlugin_WidgetCreator();
+
+  /// Virtual destructor
+  ~SamplePanelPlugin_WidgetCreator() {}
+
+  /// Returns a container of possible page types, which this creator can process
+  /// \param theTypes a list of type names
+  virtual void panelTypes(std::set<std::string>& theTypes);
+
+  /// Create panel control by its type.
+  /// \param theType a panel type
+  /// \param theParent a parent widget
+  /// \return created widget or null
+  virtual QWidget* createPanelByType(const std::string& theType,
+                                     QWidget* theParent);
+private:
+  std::set<std::string> myPanelTypes; /// types of panels
+};
+
+typedef std::shared_ptr<SamplePanelPlugin_WidgetCreator> SamplePanelWidgetCreatorPtr;
+
+#endif
diff --git a/src/SamplePanelPlugin/plugin-SamplePanel.xml b/src/SamplePanelPlugin/plugin-SamplePanel.xml
new file mode 100755 (executable)
index 0000000..fdcdb44
--- /dev/null
@@ -0,0 +1,9 @@
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<plugin>
+  <workbench id="Sample">
+    <group id="Features">
+      <feature id="SamplePanelFeature" property_panel_id="SampePanel" title="Sample Panel Feature"/>
+    </group>
+  </workbench>
+</plugin>
index e2b43b619f271b868d0790bb2b7e21ba049f9977..949d9f9f3262990a4ba1afba9a8e6f4f07c11be8 100644 (file)
@@ -595,6 +595,8 @@ bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
 {
   bool isAccepted = false;
   ModuleBase_Operation* aOperation = currentOperation();
+  if (!aOperation)
+    return false;
   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
   // only property panel enter is processed in order to do not process enter in application dialogs
   bool isPPChild = isChildObject(theObject, aPanel);