From: sbh Date: Tue, 8 Apr 2014 14:25:23 +0000 (+0400) Subject: Do not create empty property panel for features without xml widget representation. X-Git-Tag: V_0.1~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=420c997daf80ad43abc8cc65fb19b282169525c3;p=modules%2Fshaper.git Do not create empty property panel for features without xml widget representation. --- diff --git a/src/Config/Config_WidgetReader.cpp b/src/Config/Config_WidgetReader.cpp index 3558c6596..d746eb64e 100644 --- a/src/Config/Config_WidgetReader.cpp +++ b/src/Config/Config_WidgetReader.cpp @@ -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; } } diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 6abf8ea7b..0261f2551 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -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; +} diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index 01ad541a4..331de4b6b 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -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; diff --git a/src/XGUI/XGUI_Constants.h b/src/XGUI/XGUI_Constants.h index 53f9a4d05..17f0e2dd1 100644 --- a/src/XGUI/XGUI_Constants.h +++ b/src/XGUI/XGUI_Constants.h @@ -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 diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 9619f1cd6..99d2422e9 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -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(); + //setEnabled(true); myPropertyPanelDock->show(); myPropertyPanelDock->raise(); @@ -103,6 +105,7 @@ void XGUI_MainWindow::showPropertyPanel() void XGUI_MainWindow::hidePropertyPanel() { QAction* aViewAct = myPropertyPanelDock->toggleViewAction(); + //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); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 526adf0c8..add8dd246 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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 +#include #include #include @@ -19,6 +20,7 @@ #include #include #include +#include #ifdef _DEBUG #include @@ -123,7 +125,14 @@ void XGUI_Workshop::processEvent(const Event_Message* theMessage) const Config_PointerMessage* aPartSetMsg = dynamic_cast(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("property_panel_widget"); + connectToPropertyPanel(theOperation); + QWidget* aPropWidget = myMainWindow->findChild(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("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(XGUI::PROP_PANEL); + QPushButton* aOkBtn = aPanel->findChild(XGUI::PROP_PANEL_OK); connect(aOkBtn, SIGNAL(clicked()), theOperation, SLOT(commit())); - QPushButton* aCancelBtn = myMainWindow->findChild("property_panel_cancel"); + QPushButton* aCancelBtn = aPanel->findChild(XGUI::PROP_PANEL_CANCEL); connect(aCancelBtn, SIGNAL(clicked()), theOperation, SLOT(abort())); connect(theOperation, SIGNAL(started()), myMainWindow, SLOT(showPropertyPanel())); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index aa17e5a9e..e745c25af 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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();