]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Create custom widgets
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 7 Jul 2014 12:51:16 +0000 (16:51 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 7 Jul 2014 12:51:16 +0000 (16:51 +0400)
14 files changed:
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_IWorkshop.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_WidgetSketchLabel.cpp [new file with mode: 0644]
src/PartSet/PartSet_WidgetSketchLabel.h [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ModuleConnector.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 6a4401f765e27efa2f7c1b83576ce313564595f9..b5245c37ce15a400416b35ffc78ea1f59e36213b 100644 (file)
@@ -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<ModuleBase_ModelWidget*>& theModelWidgets)
+  {
+    return 0;
+  }
+
   virtual ~ModuleBase_IModule() {};
 };
 
index d9dcf5405fb4d8968a5f9259566a96080c2ff3b9..4d6e920b0a504c442fd6a5ffe99f6267c0a93794 100644 (file)
@@ -13,6 +13,8 @@
 
 #include <QObject>
 
+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<FeaturePtr> selectedFeatures() const = 0; 
 
+  //! Returns instance of loaded module
+  virtual ModuleBase_IModule* module() const = 0;
+
 signals:
   void selectionChanged();
 };
index edb98aee88c9646ff232cb2632d4247518205d9c..0c62cf36106de4730782099a10e05de8203e15be 100644 (file)
@@ -18,6 +18,8 @@
 #include <ModuleBase_WidgetDoubleValue.h>
 #include <ModuleBase_WidgetBoolValue.h>
 #include <ModuleBase_WidgetPoint2dDistance.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IModule.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -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;
 }
 
index 9a90b72f761bd7930f650a46349fd34121c871dc..235acf63ac113e40ac5da2bab6414208b597f8f9 100644 (file)
@@ -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 
index 990c9e44bceeb1625de372a8ebb795fc0eaec4d2..9af38c4dc7c9bb8e69a7483522b804c715c22e00 100644 (file)
@@ -8,6 +8,7 @@
 #include <ModuleBase_WidgetFactory.h>
 #include <PartSet_Listener.h>
 #include <PartSet_TestOCC.h>
+#include <PartSet_WidgetSketchLabel.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModelAPI_Object.h>
@@ -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<ModuleBase_ModelWidget*>& 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;
+}
index 261427642304dff1cf6afc7cae2e37ab20790962..7dbbc587be49f10a7b7a50e2da9199e74b261972 100644 (file)
@@ -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<ModuleBase_ModelWidget*>& theModelWidgets);
+
+
 public slots:
   void onFeatureTriggered();
   /// SLOT, that is called after the operation is started. Connect on the focus activated signal
index df7243a49fa6a4978e438de4fdb7b77e82a56227..0f0b0ead0cbef3d4aa5e6d99f4db149d72716e2d 100644 (file)
@@ -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 (file)
index 0000000..de9c411
--- /dev/null
@@ -0,0 +1,60 @@
+// File:        PartSet_WidgetSketchLabel.cpp
+// Created:     07 July 2014
+// Author:      Vitaly SMETANNIKOV
+
+#include "PartSet_WidgetSketchLabel.h"
+#include "PartSet_OperationSketch.h"
+
+#include <ModuleBase_Operation.h>
+#include <XGUI_OperationMgr.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <QLabel>
+
+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<QWidget*> PartSet_WidgetSketchLabel::getControls() const
+{
+  QList<QWidget*> aLst;
+  aLst<<myLabel;
+  return aLst;
+}
+
+QWidget* PartSet_WidgetSketchLabel::getControl() const
+{
+  return myLabel;
+}
+
+
+
+void PartSet_WidgetSketchLabel::setOperationsMgr(XGUI_OperationMgr* theMgr)
+{
+  ModuleBase_Operation* aOperation = theMgr->currentOperation();
+  if (aOperation->inherits("PartSet_OperationSketch")) {
+    PartSet_OperationSketch* aSketchOpe = static_cast<PartSet_OperationSketch*>(aOperation);
+    connect(aSketchOpe, SIGNAL(planeSelected(double, double, double)), 
+            this, SLOT(onPlaneSelected()));
+  }
+}
+
+void PartSet_WidgetSketchLabel::onPlaneSelected()
+{
+  PartSet_OperationSketch* aSketchOpe = static_cast<PartSet_OperationSketch*>(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 (file)
index 0000000..1419cc6
--- /dev/null
@@ -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 <ModuleBase_ModelWidget.h>
+
+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<QWidget*> 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
index 365fb02c3f79fb49eb97e78eacb2efc1f773cc1f..3b5801e77067d33e723241a99add6bbbce914219 100644 (file)
@@ -2,7 +2,7 @@
   <workbench id="Sketch">
     <group id="Basic">
       <feature id="Sketch" nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
-        <label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/> 
+        <sketch-start-label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/> 
       <!--icon=":pictures/x_point.png"-->
       </feature>
       <feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png">
index a491a89ee3367e7f0010b81b426287d1839b5148..c00253fa7e1d89feef7ad9adfaa7826936c034de 100644 (file)
@@ -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
index 8efd97e210f0697814417da53b11a91115a48986..8ef06b3217cd9abced8e794b33bb1324701c53e3 100644 (file)
@@ -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;
 };
index 0b13ba5144359dd18a585d9fcc08e14530b1a273..7be906691ae361f33510a648ed18b9c56a9d6a45 100644 (file)
@@ -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);
   }
 }
 
index 32a761f82c8945049791e8aaae73f907f9d35359..1172bc7dee0479550053ff910a41ffca0ffaaa3c 100644 (file)
@@ -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;