From: vsv Date: Mon, 7 Jul 2014 12:51:16 +0000 (+0400) Subject: Create custom widgets X-Git-Tag: V_0.4.4~204^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c5311359309c0ec43f24a94015ff56840ab4317d;p=modules%2Fshaper.git Create custom widgets --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 6a4401f76..b5245c37c 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -6,6 +6,8 @@ class QAction; class XGUI_Workshop; +class Config_WidgetAPI; +class ModuleBase_ModelWidget; /** * Interface to a module @@ -26,6 +28,13 @@ public: /// Called when it is necessary to update a command state (enable or disable it) virtual bool isFeatureEnabled(const QString& theCmdId) const = 0; + /// Creates custom widgets for property panel + virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, QList& theModelWidgets) + { + return 0; + } + virtual ~ModuleBase_IModule() {}; }; diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index d9dcf5405..4d6e920b0 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -13,6 +13,8 @@ #include +class ModuleBase_IModule; + /** * Class which provides access to Workshop object serveces */ @@ -30,6 +32,9 @@ public: //! Returns list of currently selected data objects virtual QList selectedFeatures() const = 0; + //! Returns instance of loaded module + virtual ModuleBase_IModule* module() const = 0; + signals: void selectionChanged(); }; diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index edb98aee8..0c62cf361 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include @@ -144,10 +146,12 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { result = createContainer(theType, theParent); - } + } else { + result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi, myModelWidgets); #ifdef _DEBUG - else { qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad widget type"; } + if (!result) { qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type"); } #endif + } return result; } diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 9a90b72f7..235acf63a 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -15,6 +15,7 @@ SET(PROJECT_HEADERS PartSet_OperationSketch.h PartSet_TestOCC.h PartSet_Tools.h + PartSet_WidgetSketchLabel.h ) SET(PROJECT_SOURCES @@ -28,6 +29,7 @@ SET(PROJECT_SOURCES PartSet_OperationSketch.cpp PartSet_TestOCC.cpp PartSet_Tools.cpp + PartSet_WidgetSketchLabel.cpp ) SET(PROJECT_RESOURCES diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 990c9e44b..9af38c4dc 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -540,3 +541,15 @@ bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const QStringList aList = aActMgr->nestedCommands(aOperation->id()); return aList.contains(theCmdId); } + +QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, QList& theModelWidgets) +{ + if (theType == "sketch-start-label") { + PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi); + aWgt->setOperationsMgr(myWorkshop->operationMgr()); + theModelWidgets.append(aWgt); + return aWgt->getControl(); + } else + return 0; +} diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 261427642..7dbbc587b 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -68,6 +68,11 @@ public: /// \param theCmdId the operation name void updateCurrentPreview(const std::string& theCmdId); + /// Creates custom widgets for property panel + virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent, + Config_WidgetAPI* theWidgetApi, QList& theModelWidgets); + + public slots: void onFeatureTriggered(); /// SLOT, that is called after the operation is started. Connect on the focus activated signal diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index df7243a49..0f0b0ead0 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -82,6 +82,10 @@ public: /// \return enabled state virtual bool isNestedOperationsEnabled() const; + /// Returns whether the sketch plane is set + /// \return the boolean value whether the sketch is set + bool hasSketchPlane() const; + signals: /// signal about the sketch plane is selected /// \param theX the value in the X direction of the plane @@ -96,10 +100,6 @@ protected: /// Default impl calls corresponding slot and commits immediately. virtual void startOperation(); - /// Returns whether the sketch plane is set - /// \return the boolean value whether the sketch is set - bool hasSketchPlane() const; - /// Set the plane to the current sketch /// \param theShape the shape void setSketchPlane(const TopoDS_Shape& theShape); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp new file mode 100644 index 000000000..de9c411c1 --- /dev/null +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -0,0 +1,60 @@ +// File: PartSet_WidgetSketchLabel.cpp +// Created: 07 July 2014 +// Author: Vitaly SMETANNIKOV + +#include "PartSet_WidgetSketchLabel.h" +#include "PartSet_OperationSketch.h" + +#include +#include + +#include + +#include + +PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, + const Config_WidgetAPI* theData) +: ModuleBase_ModelWidget(theParent, theData) +{ + myText = QString::fromStdString(theData->getProperty("title")); + myLabel = new QLabel(myText, theParent); + myLabel->setWordWrap(true); + myTooltip = QString::fromStdString(theData->getProperty("tooltip")); + myLabel->setToolTip(myTooltip); +} + +QList PartSet_WidgetSketchLabel::getControls() const +{ + QList aLst; + aLst<currentOperation(); + if (aOperation->inherits("PartSet_OperationSketch")) { + PartSet_OperationSketch* aSketchOpe = static_cast(aOperation); + connect(aSketchOpe, SIGNAL(planeSelected(double, double, double)), + this, SLOT(onPlaneSelected())); + } +} + +void PartSet_WidgetSketchLabel::onPlaneSelected() +{ + PartSet_OperationSketch* aSketchOpe = static_cast(sender()); + if (aSketchOpe->hasSketchPlane()) { + myLabel->setText(""); + myLabel->setToolTip(""); + } else { + myLabel->setText(myText); + myLabel->setToolTip(myTooltip); + } +} diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h new file mode 100644 index 000000000..1419cc667 --- /dev/null +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -0,0 +1,46 @@ +// File: PartSet_WidgetSketchLabel.h +// Created: 07 July 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef PartSet_WidgetSketchLabel_H +#define PartSet_WidgetSketchLabel_H + +#include "PartSet.h" + +#include + +class QLabel; +class XGUI_OperationMgr; + +class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_ModelWidget +{ + Q_OBJECT +public: + PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData); + + virtual ~PartSet_WidgetSketchLabel() {}; + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual bool storeValue(FeaturePtr theFeature) const { return true;} + + virtual bool restoreValue(FeaturePtr theFeature) { return true;} + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + QWidget* getControl() const; + + void setOperationsMgr(XGUI_OperationMgr* theMgr); + +private slots: + void onPlaneSelected(); + +private: + QLabel* myLabel; + QString myText; + QString myTooltip; +}; + +#endif \ No newline at end of file diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 365fb02c3..3b5801e77 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -2,7 +2,7 @@ - diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index a491a89ee..c00253fa7 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -32,3 +32,7 @@ QFeatureList XGUI_ModuleConnector::selectedFeatures() const return myWorkshop->selector()->selectedFeatures(); } +ModuleBase_IModule* XGUI_ModuleConnector::module() const +{ + return myWorkshop->module(); +} \ No newline at end of file diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index 8efd97e21..8ef06b321 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -31,6 +31,9 @@ public: //! Returns list of currently selected data objects virtual QFeatureList selectedFeatures() const; + //! Returns instance of loaded module + virtual ModuleBase_IModule* module() const; + private: XGUI_Workshop* myWorkshop; }; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 0b13ba514..7be906691 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -74,7 +74,7 @@ QString XGUI_Workshop::featureIcon(const std::string& theId) XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) : QObject(), myCurrentDir(QString()), - myPartSetModule(NULL), + myModule(NULL), mySalomeConnector(theConnector), myPropertyPanel(0), myObjectBrowser(0), @@ -396,7 +396,7 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) QKeySequence(), isUsePropPanel); salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" ")); myActionsMgr->addCommand(aAction); - myPartSetModule->featureCreated(aAction); + myModule->featureCreated(aAction); } else { XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); @@ -418,7 +418,7 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage) QKeySequence(), isUsePropPanel); aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts)); myActionsMgr->addCommand(aCommand); - myPartSetModule->featureCreated(aCommand); + myModule->featureCreated(aCommand); } } @@ -662,10 +662,10 @@ bool XGUI_Workshop::activateModule() { Config_ModuleReader aModuleReader; QString moduleName = QString::fromStdString(aModuleReader.getModuleName()); - myPartSetModule = loadModule(moduleName); - if (!myPartSetModule) + myModule = loadModule(moduleName); + if (!myModule) return false; - myPartSetModule->createFeatures(); + myModule->createFeatures(); myActionsMgr->update(); return true; } @@ -727,7 +727,7 @@ void XGUI_Workshop::updateModuleCommands() } } foreach(QAction* aCmd, aCommands) { - aCmd->setEnabled(myPartSetModule->isFeatureEnabled(aCmd->data().toString())); + aCmd->setEnabled(myModule->isFeatureEnabled(aCmd->data().toString())); } } @@ -815,7 +815,7 @@ void XGUI_Workshop::onFeatureTriggered() if (aCmd) { QString aId = salomeConnector()->commandId(aCmd); if (!aId.isNull()) - myPartSetModule->launchOperation(aId); + myModule->launchOperation(aId); } } diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 32a761f82..1172bc7de 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -117,6 +117,8 @@ public: //! Show the given features in 3d Viewer void showFeatures(QFeatureList theList, bool isVisible); + ModuleBase_IModule* module() const { return myModule; } + signals: void salomeViewerSelection(); void errorOccurred(const QString&); @@ -179,7 +181,7 @@ private: void createDockWidgets(); XGUI_MainWindow* myMainWindow; - ModuleBase_IModule* myPartSetModule; + ModuleBase_IModule* myModule; XGUI_ObjectsBrowser* myObjectBrowser; XGUI_PropertyPanel* myPropertyPanel; XGUI_SelectionMgr* mySelector;