From fd67236d5d82ece65fe19059e4176d53d8fe2f1d Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 30 Mar 2016 08:11:31 +0300 Subject: [PATCH] Issue #1368: Creation of a Qt panel. SamplePanelPlugin feature providing --- CMakeLists.txt | 1 + src/Config/Config_WidgetReader.cpp | 8 ++++ src/ModuleBase/ModuleBase_IWidgetCreator.h | 5 ++ src/ModuleBase/ModuleBase_WidgetFactory.cpp | 1 + src/SamplePanelPlugin/CMakeLists.txt | 45 +++++++++++++++++ src/SamplePanelPlugin/SamplePanelPlugin.h | 20 ++++++++ .../SamplePanelPlugin_Feature.cpp | 12 +++++ .../SamplePanelPlugin_Feature.h | 46 ++++++++++++++++++ .../SamplePanelPlugin_Panel.cpp | 25 ++++++++++ .../SamplePanelPlugin_Panel.h | 25 ++++++++++ .../SamplePanelPlugin_Plugin.cpp | 39 +++++++++++++++ .../SamplePanelPlugin_Plugin.h | 35 ++++++++++++++ .../SamplePanelPlugin_WidgetCreator.cpp | 34 +++++++++++++ .../SamplePanelPlugin_WidgetCreator.h | 48 +++++++++++++++++++ src/SamplePanelPlugin/plugin-SamplePanel.xml | 9 ++++ src/XGUI/XGUI_OperationMgr.cpp | 2 + 16 files changed, 355 insertions(+) create mode 100755 src/SamplePanelPlugin/CMakeLists.txt create mode 100755 src/SamplePanelPlugin/SamplePanelPlugin.h create mode 100755 src/SamplePanelPlugin/SamplePanelPlugin_Feature.cpp create mode 100755 src/SamplePanelPlugin/SamplePanelPlugin_Feature.h create mode 100755 src/SamplePanelPlugin/SamplePanelPlugin_Panel.cpp create mode 100755 src/SamplePanelPlugin/SamplePanelPlugin_Panel.h create mode 100755 src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp create mode 100755 src/SamplePanelPlugin/SamplePanelPlugin_Plugin.h create mode 100755 src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.cpp create mode 100755 src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h create mode 100755 src/SamplePanelPlugin/plugin-SamplePanel.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index 41bd71526..649cf98c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/Config/Config_WidgetReader.cpp b/src/Config/Config_WidgetReader.cpp index 25d1fdc65..4a6590c68 100644 --- a/src/Config/Config_WidgetReader.cpp +++ b/src/Config/Config_WidgetReader.cpp @@ -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; diff --git a/src/ModuleBase/ModuleBase_IWidgetCreator.h b/src/ModuleBase/ModuleBase_IWidgetCreator.h index d27f5be82..cbab144be 100755 --- a/src/ModuleBase/ModuleBase_IWidgetCreator.h +++ b/src/ModuleBase/ModuleBase_IWidgetCreator.h @@ -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& 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& theTypes) {} @@ -43,6 +45,7 @@ public: virtual void widgetTypes(std::set& 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 diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 165aa750f..e8ae59b50 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -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 index 000000000..afb6f0482 --- /dev/null +++ b/src/SamplePanelPlugin/CMakeLists.txt @@ -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 index 000000000..6960dc429 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin.h @@ -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 index 000000000..3beab1b74 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_Feature.cpp @@ -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 index 000000000..6c4db0051 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_Feature.h @@ -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 + +/**\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 SamplePanelFeaturePtr; + +#endif diff --git a/src/SamplePanelPlugin/SamplePanelPlugin_Panel.cpp b/src/SamplePanelPlugin/SamplePanelPlugin_Panel.cpp new file mode 100755 index 000000000..baaecd720 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_Panel.cpp @@ -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 + +#include +#include +#include + +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 index 000000000..29c2859d8 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_Panel.h @@ -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 + +/*! + * \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 index 000000000..cc59adb70 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.cpp @@ -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 +#include +#include +#include +#include + +#include +#include + +// 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(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 index 000000000..dcad38352 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_Plugin.h @@ -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 +#include +//#include + +#include +#include + +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 index 000000000..293f8918f --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.cpp @@ -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& 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 index 000000000..315742fa6 --- /dev/null +++ b/src/SamplePanelPlugin/SamplePanelPlugin_WidgetCreator.h @@ -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 + +#include +#include + +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& 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 myPanelTypes; /// types of panels +}; + +typedef std::shared_ptr SamplePanelWidgetCreatorPtr; + +#endif diff --git a/src/SamplePanelPlugin/plugin-SamplePanel.xml b/src/SamplePanelPlugin/plugin-SamplePanel.xml new file mode 100755 index 000000000..fdcdb444c --- /dev/null +++ b/src/SamplePanelPlugin/plugin-SamplePanel.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index e2b43b619..949d9f9f3 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -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); -- 2.39.2