Salome HOME
SMH: 3.0.0 preparation = merged version (POLYWORK + RTVDEBUG01) + adopation for new GUI
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Service.cxx
index 953784f9951db5c1f919afd85d3b60a8eb270af0..788cd8eeaa3df87339ac569b84ccb750f8bb7aa9 100644 (file)
@@ -30,11 +30,16 @@ using namespace std;
 #include "SUPERVGUI_Main.h"
 #include "SUPERVGUI_Library.h"
 #include "SUPERVGUI.h"
-#include "QAD_Tools.h"
-#include "QAD_FileDlg.h"
+
+#include "CAM_Application.h"
+#include "SUIT_Desktop.h"
+#include "SUIT_FileDlg.h"
+#include "SUIT_Session.h"
+#include "SUIT_Tools.h"
 
 #include "SALOME_NamingService.hxx"
 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
+#include <qlabel.h>
 #include <qlayout.h>
 #include <qhbox.h>
 #include <qtextstream.h>
@@ -95,7 +100,7 @@ static const char * InterfaceIcon[] = {
 
 
 SUPERVGUI_Service::SUPERVGUI_Service(SALOME_NamingService* ns):
-    QDialog(QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+    QDialog(SUIT_Session::session()->activeApplication()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
     naming(ns), myMFile(0)
 {
   setSizeGripEnabled( true );
@@ -278,7 +283,7 @@ void SUPERVGUI_Service::initialise() {
     return;
   }
   
-  QAD_ResourceMgr* aResMgr = QAD_Desktop::createResourceManager();
+  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
 
   SALOME_ModuleCatalog::ListOfComponents_var lComponents = (*aModuleCatalog)->GetComponentList();
   long nbComp = lComponents->length();
@@ -288,10 +293,9 @@ void SUPERVGUI_Service::initialise() {
     myComponentItem->setSelectable(false);
     QString aIconName = C->component_icone();
     if (!aIconName.isEmpty()) {
-      QString resDir = aResMgr->findFile(aIconName, C->componentname()) ;
-      if (resDir) {
-       resDir = QAD_Tools::addSlash(resDir);
-       QPixmap aIcone(resDir + aIconName);
+      QString resFilePath = aResMgr->path(aResMgr->resSection(), C->componentname(), aIconName) ;
+      if ( resFilePath ) {
+       QPixmap aIcone(resFilePath);
        QIconSet aIconSet(aIcone);
        myComponentItem->setPixmap(0, aIconSet.pixmap(QIconSet::Small, QIconSet::Normal));
       } else {
@@ -361,8 +365,17 @@ SUPERVGUI_Service::~SUPERVGUI_Service() {
 }
 
 void SUPERVGUI_Service::addComputeNode() {
-  QAD_Desktop* aDesktop = QAD_Application::getDesktop();
-  SUPERVGUI_Main* aMain = Supervision.getMain();
+  SUIT_Desktop* aDesktop = SUIT_Session::session()->activeApplication()->desktop();
+  CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
+  if ( !anApp ) return;
+  
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( !aSupMod ) {
+    MESSAGE("NULL Supervision module!");
+    return;
+  }
+
+  SUPERVGUI_Main* aMain = aSupMod->getMain();
   if (aMain==0) {
     QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
   } else if (!aMain->isEditable()) {
@@ -383,7 +396,7 @@ void SUPERVGUI_Service::addComputeNode() {
          const char* service   = item->text(0).latin1();
          const char* interface = item->parent()->text(0).latin1();
          const char* component = item->parent()->parent()->text(0).latin1();
-         SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(aDesktop->getComponentName(component));
+         SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(anApp->moduleName(component));
          if ( myComponent == NULL ) {
            QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
          } 
@@ -409,8 +422,17 @@ void SUPERVGUI_Service::addComputeNode() {
 }
 
 void SUPERVGUI_Service::addFactoryNode() {
-  QAD_Desktop* aDesktop = QAD_Application::getDesktop();
-  SUPERVGUI_Main* aMain = Supervision.getMain();
+  SUIT_Desktop* aDesktop = SUIT_Session::session()->activeApplication()->desktop();
+  CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
+  if ( !anApp ) return;
+
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( !aSupMod ) {
+    MESSAGE("NULL Supervision module!");
+    return;
+  }
+
+  SUPERVGUI_Main* aMain = aSupMod->getMain();
   if (aMain==0) {
     QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
   } else if (!aMain->isEditable()) {
@@ -430,7 +452,7 @@ void SUPERVGUI_Service::addFactoryNode() {
        if (item->isSelected()) {
          const char* service   = item->text(0).latin1();
          const char* interface = item->parent()->text(0).latin1();
-         const char* component = aDesktop->getComponentName(item->parent()->parent()->text(0).latin1());
+         const char* component = anApp->moduleName(item->parent()->parent()->text(0).latin1());
          SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(component);
          if (myComponent==NULL) {
            QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
@@ -467,12 +489,18 @@ void SUPERVGUI_Service::addFactoryNode() {
 
 
 void SUPERVGUI_Service::addInlineNode() {
-  SUPERVGUI_Main* aMain = Supervision.getMain();
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( !aSupMod ) {
+    MESSAGE("NULL Supervision module!");
+    return;
+  }
+
+  SUPERVGUI_Main* aMain = aSupMod->getMain();
   if (aMain==0) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
   } 
   else if (!aMain->isEditable()) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));        
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));      
   } 
   else {
     int aSel = myTypeCombo->currentItem();
@@ -540,12 +568,18 @@ void SUPERVGUI_Service::addInlineNode() {
 }
 
 void SUPERVGUI_Service::addMacroNode() {
-  SUPERVGUI_Main* aMain = Supervision.getMain();
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( !aSupMod ) {
+    MESSAGE("NULL Supervision module!");
+    return;
+  }
+
+  SUPERVGUI_Main* aMain = aSupMod->getMain();
   if (aMain==0) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
   } 
   else if (!aMain->isEditable()) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));        
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));      
   } 
   else {
     if ( myMFile ) {
@@ -570,7 +604,7 @@ void SUPERVGUI_Service::addMacroNode() {
       addNode( aNode, aDummyEndNode, myX, myY );
     }
     else {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NONODE_TOADD"));
+      QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NONODE_TOADD"));
     }
   }
 }
@@ -583,18 +617,18 @@ void SUPERVGUI_Service::loadGraph() {
                return;
        }
 
-  QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
-                                              "",
-                                              "*.xml",
-                                              tr("MSG_GRAPH_INSERT"),
-                                              true);
+  QString aFileName = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
+                                               "",
+                                               "*.xml",
+                                               tr("MSG_GRAPH_INSERT"),
+                                               true);
   if (aFileName.isEmpty()) return;
 
   myMacroPane->clear();
 
   myMFile = new QFile(aFileName);
   if (!myMFile->open(IO_ReadOnly)) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), 
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), 
                         tr("MSG_CANT_LOADSCRIPT"));
     delete myMFile; myMFile = 0;
     return;
@@ -602,7 +636,7 @@ void SUPERVGUI_Service::loadGraph() {
 
   QTextStream* aStream = new QTextStream(myMFile);
   if (aStream->atEnd()) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), 
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), 
                         tr("MSG_EMTY_FILE"));
     delete aStream;
     myMFile->close();
@@ -634,7 +668,13 @@ void SUPERVGUI_Service::choose() {
     
 
 void SUPERVGUI_Service::showEvent(QShowEvent* theEvent) {
-  SUPERVGUI_Main* aMain = Supervision.getMain();
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( !aSupMod ) {
+    MESSAGE("NULL Supervision module!");
+    return;
+  }
+
+  SUPERVGUI_Main* aMain = aSupMod->getMain();
   if (aMain && (!aMain->isArrayShown())) {
     aMain->getArrayView()->viewportToContents(0, 0, myX, myY);
     //aMain->getGraph()->viewportToContents(0, 0, myX, myY);
@@ -750,16 +790,16 @@ void SUPERVGUI_PythonEditPane::initPyFunctions( QTextStream& theStream ) {
  * Load existing Python script
  */
 void SUPERVGUI_PythonEditPane::loadFile() {
-  QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
-                                              "",
-                                              "*.py",
-                                              tr("TIT_LOADSCRIPT"),
-                                              true);
+  QString aFileName = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
+                                               "",
+                                               "*.py",
+                                               tr("TIT_LOADSCRIPT"),
+                                               true);
   if (aFileName.isEmpty()) return;
 
   QFile aFile( aFileName );
   if (!aFile.open(IO_ReadOnly)) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), 
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), 
                         tr("MSG_CANT_LOADSCRIPT"));
     return;
   }
@@ -770,7 +810,7 @@ void SUPERVGUI_PythonEditPane::loadFile() {
 
   QTextStream aFileReader(&aFile);
   if ( aFileReader.atEnd() ) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_EMTY_FILE"));
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_EMTY_FILE"));
     aFile.close();
     return;
   }
@@ -894,7 +934,7 @@ void SUPERVGUI_PythonEditPane::library() {
  * Edit Python dialog
  */
 SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg( bool isLoop )
-  :QDialog(QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) 
+  :QDialog(SUIT_Session::session()->activeApplication()->desktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) 
 {
   setSizeGripEnabled( true );
   setCaption(tr("TIT_FUNC_PYTHON"));
@@ -945,7 +985,13 @@ SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg( bool isLoop )
  * PS theEndNode is passed only for Loop and Switch nodes (EndLoop and EndSwitch)
  */ 
 void SUPERVGUI_Service::addNode( SUPERV::CNode_var theNode, SUPERV::INode_var theEndNode, int& theX, int& theY )  {
-  SUPERVGUI_Main* aMain = Supervision.getMain();
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( !aSupMod ) {
+    MESSAGE("NULL Supervision module!");
+    return;
+  }
+  
+  SUPERVGUI_Main* aMain = aSupMod->getMain();
 
   if ( !CORBA::is_nil( theNode ) && aMain ) {