]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Do not create empty property panel for features without xml widget representation.
authorsbh <sergey.belash@opencascade.com>
Tue, 8 Apr 2014 14:25:23 +0000 (18:25 +0400)
committersbh <sergey.belash@opencascade.com>
Tue, 8 Apr 2014 14:25:23 +0000 (18:25 +0400)
src/Config/Config_WidgetReader.cpp
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h
src/XGUI/XGUI_Constants.h
src/XGUI/XGUI_MainWindow.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 3558c659652307e27ab1bf6ac314cc1d31bc8121..d746eb64eb0b4c8ba6556f394c65cd0b97e0578b 100644 (file)
@@ -36,10 +36,14 @@ std::string Config_WidgetReader::featureWidgetCfg(std::string theFeatureName)
 void Config_WidgetReader::processNode(xmlNodePtr theNode)
 {
   if (isNode(theNode, NODE_FEATURE, NULL)) {
-    xmlBufferPtr buffer = xmlBufferCreate();
-    int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1);
+    std::string result = "";
     std::string aNodeName = getProperty(theNode, _ID);
-    myWidgetCache[aNodeName] = std::string((char*) buffer->content);
+    if (hasChild(theNode)) {
+      xmlBufferPtr buffer = xmlBufferCreate();
+      int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1);
+      result = std::string((char*) buffer->content);
+    }
+    myWidgetCache[aNodeName] = result;
   }
 }
 
index 6abf8ea7b04359857add3f1488cecdc19cb2d683..0261f2551600b54fd7dec93cd03f81247c6763f6 100644 (file)
@@ -148,12 +148,12 @@ bool Config_XMLReader::isNode(xmlNodePtr theNode, const char* theNodeName, ...)
 {
   bool result = false;
   const xmlChar* aName = theNode->name;
-  if (!aName || theNode->type != XML_ELEMENT_NODE)
+  if (!aName || theNode->type != XML_ELEMENT_NODE) {
     return false;
-
-  if (!xmlStrcmp(aName, (const xmlChar *) theNodeName))
+  }
+  if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {
     return true;
-
+  }
   va_list args; // define argument list variable
   va_start(args, theNodeName); // init list; point to last defined argument
   while(true) {
@@ -168,3 +168,21 @@ bool Config_XMLReader::isNode(xmlNodePtr theNode, const char* theNodeName, ...)
   va_end(args); // cleanup the system stack
   return false;
 }
+
+/*
+ * Every xml node has child. Even if there is no explicit
+ * child nodes libxml gives the "Text node" as child.
+ *
+ * This method checks if real child nodes exist in the
+ * given node.
+ */
+bool Config_XMLReader::hasChild(xmlNodePtr theNode)
+{
+  xmlNodePtr aNode = theNode->children;
+  for(; aNode; aNode = aNode->next) {
+    if (aNode->type != XML_ELEMENT_NODE) {
+      return true;
+    }
+  }
+  return false;
+}
index 01ad541a4eefcb0c036aa70abad39d184f669016..331de4b6b4383406639f112b18237a1796a04ccb 100644 (file)
@@ -54,6 +54,7 @@ protected:
    * TODO(sbh): find a way to simplify calling this method.
    */
   bool isNode(xmlNodePtr theNode, const char* name, ...);
+  bool hasChild(xmlNodePtr theNode);
 
 protected:
   std::string myDocumentPath;
index 53f9a4d057f72a4a712e0f01f5efc06839fa734f..17f0e2dd17996c10cedcd9c577996f92ff7ad528 100644 (file)
@@ -65,7 +65,11 @@ enum TextureMode
   StretchTexture,            // stretch texture
 };
 
-}
-;
+const static char* PROP_PANEL = "property_panel_dock";
+const static char* PROP_PANEL_OK = "property_panel_ok";
+const static char* PROP_PANEL_CANCEL = "property_panel_cancel";
+const static char* PROP_PANEL_WDG = "property_panel_widget";
+
+};
 
 #endif
index 9619f1cd6d416b7642b80126a9d5fc850ea537e0..99d2422e9c32dced0a0ce88ac985f384998ed7f5 100644 (file)
@@ -1,4 +1,5 @@
 #include "XGUI_MainWindow.h"
+#include "XGUI_Constants.h"
 #include "XGUI_MainMenu.h"
 #include "XGUI_ViewWindow.h"
 #include "XGUI_Viewer.h"
@@ -95,6 +96,7 @@ void XGUI_MainWindow::hidePythonConsole()
 void XGUI_MainWindow::showPropertyPanel()
 {
   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
+  //<! Restore ability to close panel from the window's menu
   aViewAct->setEnabled(true);
   myPropertyPanelDock->show();
   myPropertyPanelDock->raise();
@@ -103,6 +105,7 @@ void XGUI_MainWindow::showPropertyPanel()
 void XGUI_MainWindow::hidePropertyPanel()
 {
   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
+  //<! Do not allow to show empty property panel
   aViewAct->setEnabled(false);
   myPropertyPanelDock->hide();
 }
@@ -127,6 +130,7 @@ QDockWidget* XGUI_MainWindow::createPropertyPanel()
 {
   QDockWidget* aPropPanel = new QDockWidget(this);
   aPropPanel->setWindowTitle(tr("Property Panel"));
+  aPropPanel->setObjectName(XGUI::PROP_PANEL);
 
   QWidget* aContent = new QWidget(aPropPanel);
   QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
@@ -134,7 +138,7 @@ QDockWidget* XGUI_MainWindow::createPropertyPanel()
   aPropPanel->setWidget(aContent);
 
   QWidget* aCustomWidget = new QWidget(aContent);
-  aCustomWidget->setObjectName("property_panel_widget");
+  aCustomWidget->setObjectName(XGUI::PROP_PANEL_WDG);
   aMainLay->addWidget(aCustomWidget);
   aMainLay->addStretch(1);
 
@@ -150,11 +154,11 @@ QDockWidget* XGUI_MainWindow::createPropertyPanel()
   aBtnLay->addWidget(aBtn);
   aBtnLay->addStretch(1);
   aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
-  aBtn->setObjectName("property_panel_ok");
+  aBtn->setObjectName(XGUI::PROP_PANEL_OK);
   aBtn->setFlat(true);
   aBtnLay->addWidget(aBtn);
   aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
-  aBtn->setObjectName("property_panel_cancel");
+  aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
   aBtn->setFlat(true);
   aBtnLay->addWidget(aBtn);
 
index 526adf0c899ccb5725f410d88b17f0944ae03167..add8dd246e3175d1ef5822e18a022d00efc34551 100644 (file)
@@ -1,4 +1,5 @@
 #include "XGUI_Module.h"
+#include "XGUI_Constants.h"
 #include "XGUI_Command.h"
 #include "XGUI_MainMenu.h"
 #include "XGUI_MainWindow.h"
@@ -8,9 +9,9 @@
 #include "XGUI_Workshop.h"
 #include "XGUI_Viewer.h"
 #include "XGUI_WidgetFactory.h"
-#include "ModuleBase_Operation.h"
 
 #include <Event_Loop.h>
+#include <ModuleBase_Operation.h>
 #include <Config_FeatureMessage.h>
 #include <Config_PointerMessage.h>
 
@@ -19,6 +20,7 @@
 #include <QMessageBox>
 #include <QMdiSubWindow>
 #include <QPushButton>
+#include <QDockWidget>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -123,7 +125,14 @@ void XGUI_Workshop::processEvent(const Event_Message* theMessage)
   const Config_PointerMessage* aPartSetMsg =
       dynamic_cast<const Config_PointerMessage*>(theMessage);
   if (aPartSetMsg) {
-    fillPropertyPanel(aPartSetMsg);
+    ModuleBase_Operation* aOperation = (ModuleBase_Operation*)(aPartSetMsg->pointer());
+    setCurrentOperation(aOperation);
+    if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel
+      myCurrentOperation->start();
+      myCurrentOperation->commit();
+    } else {
+      fillPropertyPanel(aOperation);
+    }
     return;
   }
 
@@ -172,29 +181,40 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
 /*
  *
  */
-void XGUI_Workshop::fillPropertyPanel(const Config_PointerMessage* theMessage)
+void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
 {
-  ModuleBase_Operation* anOperation = (ModuleBase_Operation*)(theMessage->pointer());
-  connectToPropertyPanel(anOperation);
-  QWidget* aPropWidget = myMainWindow->findChild<QWidget*>("property_panel_widget");
+  connectToPropertyPanel(theOperation);
+  QWidget* aPropWidget = myMainWindow->findChild<QWidget*>(XGUI::PROP_PANEL_WDG);
   qDeleteAll(aPropWidget->children());
-  anOperation->start();
-  XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(anOperation);
+  theOperation->start();
+  XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(theOperation);
   aFactory.fillWidget(aPropWidget);
 }
 
-void XGUI_Workshop::connectToPropertyPanel(ModuleBase_Operation* theOperation)
+void XGUI_Workshop::setCurrentOperation(ModuleBase_Operation* theOperation)
 {
-  if(myCurrentOperation) {
-    //FIXME: Ask user about aborting of current operation?
-    myCurrentOperation->abort();
+  //FIXME: Ask user about aborting of current operation?
+  if (myCurrentOperation) {
+    //TODO get isOperation from document
+    if (myCurrentOperation->isRunning())
+      myCurrentOperation->abort();
+
     myCurrentOperation->deleteLater();
   }
   myCurrentOperation = theOperation;
+}
 
-  QPushButton* aOkBtn = myMainWindow->findChild<QPushButton*>("property_panel_ok");
+/*
+ * Makes a signal/slot connections between Property Panel
+ * and given operation. The given operation becomes a
+ * current operation and previous operation if exists
+ */
+void XGUI_Workshop::connectToPropertyPanel(ModuleBase_Operation* theOperation)
+{
+  QDockWidget* aPanel = myMainWindow->findChild<QDockWidget*>(XGUI::PROP_PANEL);
+  QPushButton* aOkBtn = aPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
   connect(aOkBtn, SIGNAL(clicked()), theOperation, SLOT(commit()));
-  QPushButton* aCancelBtn = myMainWindow->findChild<QPushButton*>("property_panel_cancel");
+  QPushButton* aCancelBtn = aPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
   connect(aCancelBtn, SIGNAL(clicked()), theOperation, SLOT(abort()));
 
   connect(theOperation, SIGNAL(started()), myMainWindow, SLOT(showPropertyPanel()));
index aa17e5a9e84886b67f14b5abb1894dd096118f4b..e745c25af8c8854191f385d698ce5cc71a180e66 100644 (file)
@@ -47,9 +47,9 @@ public slots:
 protected:
   //Event-loop processing methods:
   void addFeature(const Config_FeatureMessage*);
-  void fillPropertyPanel(const Config_PointerMessage*);
-
+  void fillPropertyPanel(ModuleBase_Operation* theOperation);
   void connectToPropertyPanel(ModuleBase_Operation* theOperation);
+  void setCurrentOperation(ModuleBase_Operation* theOperation);
 
 private:
   void initMenu();