]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
According to "operation-widget_factory-property"
authornds <natalia.donis@opencascade.com>
Mon, 16 Jun 2014 06:45:04 +0000 (10:45 +0400)
committernds <natalia.donis@opencascade.com>
Mon, 16 Jun 2014 06:45:04 +0000 (10:45 +0400)
final modification to use in the property panel the operation widgets.
To do: the property panel clear the widgets, but should not do it.

src/ModuleBase/ModuleBase_IOperation.cpp
src/ModuleBase/ModuleBase_IOperation.h
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_OperationDescription.cpp
src/ModuleBase/ModuleBase_OperationDescription.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Tools.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 378af8663e35751e213566728e7ea3bfc3e41849..30af6ccc1ea61c1f5bcf0b0cbefdf095872dab9a 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "ModuleBase_IOperation.h"
 #include "ModuleBase_OperationDescription.h"
+#include "ModuleBase_ModelWidget.h"
 
 #include <ModelAPI_Document.h>
 #include <ModelAPI_PluginManager.h>
@@ -41,6 +42,16 @@ bool ModuleBase_IOperation::isGranted(ModuleBase_IOperation* /*theOperation*/) c
   return false;
 }
 
+void ModuleBase_IOperation::setModelWidgets(const std::string& theXmlRepresentation,
+                                            QList<ModuleBase_ModelWidget*> theWidgets)
+{
+  QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end();
+  for (; anIt != aLast; anIt++) {
+    QObject::connect(*anIt, SIGNAL(valuesChanged()),  this, SLOT(storeCustomValue()));
+  }
+  getDescription()->setModelWidgets(theXmlRepresentation, theWidgets);
+}
+
 boost::shared_ptr<ModelAPI_Document> ModuleBase_IOperation::document() const
 {
   return ModelAPI_PluginManager::get()->rootDocument();
index a936a6f1073ef8e8780b42f27ca7906c8978cffc..5c753c728067ff1a0978a2405291262957a908d3 100644 (file)
 
 #include <QObject>
 #include <QString>
+#include <QList>
 
 #include <boost/shared_ptr.hpp>
 
 class ModelAPI_Document;
 class ModuleBase_OperationDescription;
+class ModuleBase_ModelWidget;
 
 /*!
  \class ModuleBase_IOperation
@@ -68,6 +70,12 @@ public:
   /// \param theOperation the previous running operation
   virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
 
+  /// Sets a list of model widgets, according to the operation feature xml definition
+  /// \param theXmlRepresentation an xml feature definition
+  /// \param theWidgets a list of widgets
+  void setModelWidgets(const std::string& theXmlRepresentation,
+                       QList<ModuleBase_ModelWidget*> theWidgets);
+
 signals:
   void started(); /// the operation is started
   void aborted(); /// the operation is aborted
index 3a5364fe89864a5e2ee1863f93bcce2ceef585df..223bf59e266815888905f0783e28dc2794c41b39 100644 (file)
@@ -100,10 +100,16 @@ void ModuleBase_Operation::flushCreated()
 FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
 {
   boost::shared_ptr<ModelAPI_Document> aDoc = document();
-  FeaturePtr aFeature = aDoc->addFeature(
-                                           getDescription()->operationId().toStdString());
-  if (aFeature) // TODO: generate an error if feature was not created
+  FeaturePtr aFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
+  if (aFeature) { // TODO: generate an error if feature was not created
     aFeature->execute();
+    // Init default values
+    QList<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
+    QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
+    for (; anIt != aLast; anIt++) {
+      (*anIt)->storeValue(aFeature);
+    }
+  }
 
   if (theFlushMessage)
     flushCreated();
index 692c5721a924777084540403c7a2eee2be51af45..a97d11816255062a457e60fcce1b6a5084d75d7f 100644 (file)
@@ -22,23 +22,32 @@ const QString& ModuleBase_OperationDescription::operationId() const
   return myOperationId;
 }
 
-const QString& ModuleBase_OperationDescription::xmlRepresentation() const
+const QString& ModuleBase_OperationDescription::description() const
 {
-  return myXmlRepr;
+  return myDescription;
 }
 
-void ModuleBase_OperationDescription::setXmlRepresentation(const QString& xmlRepr)
+void ModuleBase_OperationDescription::setDescription(const QString& theDescription)
 {
-  myXmlRepr = xmlRepr;
+  myDescription = theDescription;
 }
 
-const QString& ModuleBase_OperationDescription::description() const
+void ModuleBase_OperationDescription::setModelWidgets(const std::string& theXmlRepresentation,
+                                                      const QList<ModuleBase_ModelWidget*>& theWidgets)
 {
-  return myDescription;
+  myWidgets.clear();
+  QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast = theWidgets.end();
+  for (; anIt != aLast; anIt++)
+    myWidgets.push_back(*anIt);
+  myXmlRepresentation = theXmlRepresentation;
 }
 
-void ModuleBase_OperationDescription::setDescription(const QString& theDescription)
+const QList<ModuleBase_ModelWidget*>& ModuleBase_OperationDescription::modelWidgets() const
 {
-  myDescription = theDescription;
+  return myWidgets;
 }
 
+bool ModuleBase_OperationDescription::hasXmlRepresentation() const
+{
+  return !myWidgets.empty() || !myXmlRepresentation.empty();
+}
index 56b37c28eec66a01ceae2117a82bcc3e24a44f44..11b4abc10ea04da657d78db2a62db5bc5592a280 100644 (file)
 
 #include <QObject>
 #include <QString>
+#include <QList>
 
 #include <memory>
 
+class ModuleBase_ModelWidget;
+
 /*!
  * \class ModuleBase_OperationDescription
  *
@@ -35,11 +38,7 @@ public:
 
   /// Returns XML representation of the operation's widget.
   /// \return XML QString
-  const QString& xmlRepresentation() const;
-
-  /// Sets XML representation of the operation's widget.
-  /// \param xmlRepr - XML QString
-  void setXmlRepresentation(const QString& xmlRepr);
+  //const QString& xmlRepresentation() const;
 
   /// Returns a short description of operation (will be
   /// inserted in title of property panel)
@@ -49,11 +48,25 @@ public:
   /// inserted in title of property panel)
   void setDescription(const QString& theDescription);
 
+  /// Sets a list of model widgets, according to the operation feature xml definition
+  /// \param theWidgets a list of widgets
+  void setModelWidgets(const std::string& theXmlRepresentation,
+                       const QList<ModuleBase_ModelWidget*>& theWidgets);
+
+  /// Sets a list of model widgets, according to the operation feature xml definition
+  /// \param theWidgets a list of widgets
+  const QList<ModuleBase_ModelWidget*>& modelWidgets() const;
+
+  /// Returns true if there are no model widgets
+  /// \return the boolean value
+  bool hasXmlRepresentation() const;
+
 private:
   //!< Next fields could be extracted into a subclass;
   QString myOperationId; /// the operation identifier
-  QString myXmlRepr; /// the XML representation of the operation's widget
   QString myDescription; /// the short description of the opertaion
+  std::string myXmlRepresentation; /// the xml definition
+  QList<ModuleBase_ModelWidget*> myWidgets; /// the list of operation widgets
 };
 
 #endif //ModuleBase_OperationDescription_H
index ae43f8a3a1dd50118947ead54cd83d40b1452972..f33b67a13d65d735f3206f13858b0df0066a9f84 100644 (file)
@@ -5,6 +5,7 @@
 #include <PartSet_OperationConstraint.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
+#include <ModuleBase_WidgetFactory.h>
 #include <PartSet_Listener.h>
 #include <PartSet_TestOCC.h>
 #include <PartSet_Presentation.h>
@@ -23,6 +24,7 @@
 #include <XGUI_ViewerProxy.h>
 #include <XGUI_ContextMenuMgr.h>
 #include <XGUI_PropertyPanel.h>
+#include <XGUI_ModuleConnector.h>
 #include <XGUI_Tools.h>
 
 #include <SketchPlugin_Line.h>
@@ -231,7 +233,7 @@ void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeatur
   if (aPreviewOp)
   {
     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-      // refill the features list with avoiding of the features, obtained only by vertex shape (TODO)
+    // refill the features list with avoiding of the features, obtained only by vertex shape (TODO)
     std::list<XGUI_ViewerPrs> aSelected = aDisplayer->getSelected(TopAbs_VERTEX);
     std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted(TopAbs_VERTEX);
     aPreviewOp->init(theFeature, aSelected, aHighlighted);
@@ -333,7 +335,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
     anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
   }
 
-  // set operation xml description
+  // set operation description and list of widgets corresponding to the feature xml definition
   std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
 
   std::string aPluginFileName = featureFile(aFeatureKind);
@@ -342,9 +344,17 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
   std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
 
-  anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
+  QString aXmlRepr = QString::fromStdString(aXmlCfg);
+  ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
+                                                               myWorkshop->moduleConnector());
+  QWidget* aContent = myWorkshop->propertyPanel()->contentWidget();
+  qDeleteAll(aContent->children());
+  aFactory.createWidget(aContent);
+
   anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
 
+  anOperation->setModelWidgets(aXmlRepr.toStdString(), aFactory.getModelWidgets());
+
   // connect the operation
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
index 3cfa835db921703800889a8d995ff0aaeab7cb67..3e965280a5c77f8643787045fbe6cdce93f53a14 100644 (file)
@@ -179,24 +179,25 @@ boost::shared_ptr<PartSet_FeaturePrs> PartSet_Tools::createFeaturePrs(const std:
                                                                       FeaturePtr theSketch,
                                                                       FeaturePtr theFeature)
 {
-  PartSet_FeaturePrs* aFeaturePrs;
+  boost::shared_ptr<PartSet_FeaturePrs> aFeaturePrs;
 
   if (theKind == PartSet_FeaturePointPrs::getKind()) {
-    aFeaturePrs = new PartSet_FeaturePointPrs(theSketch);
+    aFeaturePrs = boost::shared_ptr<PartSet_FeaturePrs>(new PartSet_FeaturePointPrs(theSketch));
   }
   else if (theKind == PartSet_FeatureLinePrs::getKind()) {
-    aFeaturePrs = new PartSet_FeatureLinePrs(theSketch);
+    aFeaturePrs = boost::shared_ptr<PartSet_FeaturePrs>(new PartSet_FeatureLinePrs(theSketch));
   }
   else if (theKind == PartSet_FeatureCirclePrs::getKind()) {
-    aFeaturePrs = new PartSet_FeatureCirclePrs(theSketch);
+    aFeaturePrs = boost::shared_ptr<PartSet_FeaturePrs>(new PartSet_FeatureCirclePrs(theSketch));
   }
   else if (theKind == PartSet_FeatureArcPrs::getKind()) {
-    aFeaturePrs = new PartSet_FeatureArcPrs(theSketch);
+    aFeaturePrs = boost::shared_ptr<PartSet_FeaturePrs>(new PartSet_FeatureArcPrs(theSketch));
   }
-  if (theFeature)
+
+  if (theFeature && aFeaturePrs)
     aFeaturePrs->init(theFeature, FeaturePtr());
 
-  return boost::shared_ptr<PartSet_FeaturePrs>(aFeaturePrs);
+  return aFeaturePrs;
 }
 
 FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
index 26d1bb1d28e41a49a370f21cf113d23f2a951501..affbac1a123ca886387a6dc4ffebcf035fc63bda 100644 (file)
@@ -281,14 +281,14 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
   //An operation passed by message. Start it, process and commit.
   const Config_PointerMessage* aPartSetMsg = dynamic_cast<const Config_PointerMessage*>(theMessage);
   if (aPartSetMsg) {
-    // Clear previous content
-    myPropertyPanel->cleanContent();
+    // TODO: Clear previous content
+    //myPropertyPanel->cleanContent();
     ModuleBase_Operation* anOperation =
         (ModuleBase_Operation*)(aPartSetMsg->pointer());
 
     if (myOperationMgr->startOperation(anOperation)) {
       myPropertyPanel->updateContentWidget(anOperation->feature());
-      if (anOperation->getDescription()->xmlRepresentation().isEmpty()) {
+      if (!anOperation->getDescription()->hasXmlRepresentation()) {
         anOperation->commit();
         updateCommandStatus();
       }
@@ -308,30 +308,20 @@ void XGUI_Workshop::onOperationStarted()
 {
   ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
 
-  if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) { //!< No need for property panel
+  if(aOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
     connectWithOperation(aOperation);
 
     showPropertyPanel();
-
+    // TODO: Clear previous content
+    /*
     QString aXmlRepr = aOperation->getDescription()->xmlRepresentation();
     ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(), myModuleConnector);
     QWidget* aContent = myPropertyPanel->contentWidget();
     qDeleteAll(aContent->children());
     aFactory.createWidget(aContent);
-
-    QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
-    QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
-    ModuleBase_ModelWidget* aWidget;
-    for (; anIt != aLast; anIt++) {
-      aWidget = *anIt;
-      QObject::connect(aWidget, SIGNAL(valuesChanged()),  aOperation, SLOT(storeCustomValue()));
-      // Init default values
-      if (!aOperation->isEditOperation()) {
-        aWidget->storeValue(aOperation->feature());
-      }
-    }
-
     myPropertyPanel->setModelWidgets(aFactory.getModelWidgets());
+    */
+    myPropertyPanel->setModelWidgets(aOperation->getDescription()->modelWidgets());
     myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
   }
   updateCommandStatus();
@@ -343,6 +333,7 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
   //!< No need for property panel
   updateCommandStatus();
   hidePropertyPanel();
+  //myPropertyPanel->cleanContent();
 }
 
 /*
index dad0857074b93a92e6e91d51226012ecf5e5e4ea..fba793e83cec553a386a6701e529b2a8a6873965 100644 (file)
@@ -96,6 +96,10 @@ public:
 
   XGUI_ViewerProxy* viewer() const { return myViewerProxy; }
 
+  /// Returns the module connectory
+  /// \returns the instance of connector
+  XGUI_ModuleConnector* moduleConnector() const { return myModuleConnector; }
+
   //! Returns icon name according to feature Id
   static QString featureIcon(const std::string& theId);