X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSUPERVGUI%2FSUPERVGUI_Service.cxx;h=a6bb0fa65b6abd018d19f324b00631ac789b22d9;hb=ce03308cda9f25081342e1d4f4bc804d7cb3a290;hp=2bd81911ea933f8bef28ce9b5e491f244315c5b1;hpb=7d3931c54614b3d73351551e662ccbd3be07a0d8;p=modules%2Fsuperv.git diff --git a/src/SUPERVGUI/SUPERVGUI_Service.cxx b/src/SUPERVGUI/SUPERVGUI_Service.cxx index 2bd8191..a6bb0fa 100644 --- a/src/SUPERVGUI/SUPERVGUI_Service.cxx +++ b/src/SUPERVGUI/SUPERVGUI_Service.cxx @@ -25,16 +25,20 @@ // Author : Francis KLOSS // Module : SUPERV -using namespace std; #include "SUPERVGUI_Service.h" #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 #include #include #include @@ -95,7 +99,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 +282,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 +292,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 { @@ -313,7 +316,7 @@ void SUPERVGUI_Service::initialise() { SALOME_ModuleCatalog::Service* Service = &(Interface->interfaceservicelist[k]); QListViewItem* myServiceItem = new QListViewItem(myInterfaceItem, (char*)Service->ServiceName); myServiceItem->setSelectable(true); - components->ensureItemVisible(myServiceItem); + //components->ensureItemVisible(myServiceItem); long nbPortsOut = Service->ServiceoutParameter.length(); for (int m=0; mactiveApplication()->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 +395,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 +421,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,32 +451,36 @@ 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()); - SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(component); - if (myComponent==NULL) { - QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE")); - } - else { - const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service); - SUPERV_CNode aNode; - if ( myService->TypeOfNode == 0 ) { // ComputeNode - aNode = aMain->getDataflow()->CNode(*myService); - if (CORBA::is_nil( aNode ) ) { - QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); - return; - } + //const char* component = anApp->moduleName(item->parent()->parent()->text(0).latin1()); + if ( aSupMod->getInterfaceNameMap().contains(item->parent()->text(0)) ) { + const char* component = aSupMod->getInterfaceNameMap().find(item->parent()->text(0)).data(); + + SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(component); + if (myComponent==NULL) { + QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE")); } - else { // Factory Node - aNode = aMain->getDataflow()->FNode(component, interface, *myService); - if ( CORBA::is_nil( aNode ) ) { - QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); - return; + else { + const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service); + SUPERV_CNode aNode; + if ( myService->TypeOfNode == 0 ) { // ComputeNode + aNode = aMain->getDataflow()->CNode(*myService); + if (CORBA::is_nil( aNode ) ) { + QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); + return; + } + } + else { // Factory Node + aNode = aMain->getDataflow()->FNode(component, interface, *myService, myComponent->implementation_type()); // mkr : PAL11273 + if ( CORBA::is_nil( aNode ) ) { + QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); + return; + } } + SUPERV::INode_var aDummyEndNode; + addNode( aNode, aDummyEndNode, myX, myY ); + b = true; } - SUPERV::INode_var aDummyEndNode; - addNode( aNode, aDummyEndNode, myX, myY ); - b = true; - } + } } } if ( !b ) { @@ -467,25 +492,38 @@ 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(); switch (aSel) { case 0: // Computation { - SUPERV_CNode aNode = aMain->getDataflow()->INode(myScriptPane->getFuncName().latin1(), - (myScriptPane->getFunction()).in()); + SUPERV_CNode aNode = + aMain->getDataflow()->INode(myScriptPane->getFuncName().isEmpty() ? "" : myScriptPane->getFuncName().latin1(), + (myScriptPane->getFunction()).in()); if (CORBA::is_nil(aNode)) { QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); return; } SUPERV::INode_var aDummyEndNode; + // here we have to + // 1) parse nodes' python function to find ports names + // 2) create ports for engine node with found names and "undefined" types + // ( aNode->InPort(name,type), aNode->OutPort(name,type) ) + // P.S. CanvasNode->createPort(...) for create presentation of port + // will be called from addNode(...) (inside CanvasNode constructor) addNode( aNode, aDummyEndNode, myX, myY ); } break; @@ -493,9 +531,10 @@ void SUPERVGUI_Service::addInlineNode() { case 1: // Switch { SUPERV_INode aEndNode; - SUPERV_CNode aStartNode = aMain->getDataflow()->SNode(myScriptPane->getFuncName().latin1(), - (myScriptPane->getFunction()).in(), - aEndNode); + SUPERV_CNode aStartNode = + aMain->getDataflow()->SNode(myScriptPane->getFuncName().isEmpty() ? "" : myScriptPane->getFuncName().latin1(), + (myScriptPane->getFunction()).in(), + aEndNode); if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) { QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); return; @@ -507,10 +546,14 @@ void SUPERVGUI_Service::addInlineNode() { case 2: // Loop { SUPERV_INode aEndNode; - SUPERV_CNode aStartNode = aMain->getDataflow()->LNode(myInitPane->getFuncName().latin1(), (myInitPane->getFunction()).in(), - myMorePane->getFuncName().latin1(), (myMorePane->getFunction()).in(), - myNextPane->getFuncName().latin1(), (myNextPane->getFunction()).in(), - aEndNode); + SUPERV_CNode aStartNode = + aMain->getDataflow()->LNode(myInitPane->getFuncName().isEmpty() ? "" : myInitPane->getFuncName().latin1(), + (myInitPane->getFunction()).in(), + myMorePane->getFuncName().isEmpty() ? "" : myMorePane->getFuncName().latin1(), + (myMorePane->getFunction()).in(), + myNextPane->getFuncName().isEmpty() ? "" : myNextPane->getFuncName().latin1(), + (myNextPane->getFunction()).in(), + aEndNode); if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) { QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE")); return; @@ -540,12 +583,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 +619,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 +632,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 +651,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 +683,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 +805,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 +825,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; } @@ -854,21 +909,23 @@ void SUPERVGUI_PythonEditPane::autoIndentLine() { // get current cursor position and previous line (the one to be analized) int pos, para, i; + QString spacesStr; myText->getCursorPosition( ¶, &pos ); // pos==0, beginning of line - QString line = myText->text( para-1 ); // previous paragraph line + if ( myText->paragraphLength(para-1) > 0 ) { // mkr : IPAL9817 + QString line = myText->text( para-1 ); // previous paragraph line - // construct a string containing all leading space characters of previous line (tabs, etc.) - QString spacesStr; - i = -1; - while ( line[++i].isSpace() ) // append all isSpace() characters at beginning of line to spacesStr - spacesStr += line[i]; - - // if ':' was found -- add more spaces to spacesStr - line = line.stripWhiteSpace(); - if ( line[ line.length()-1 ] == ':' ) { - i = 0; - while ( i++ < N ) - spacesStr += ' '; + // construct a string containing all leading space characters of previous line (tabs, etc.) + i = -1; + while ( line[++i].isSpace() ) // append all isSpace() characters at beginning of line to spacesStr + spacesStr += line[i]; + + // if ':' was found -- add more spaces to spacesStr + line = line.stripWhiteSpace(); + if ( line[ line.length()-1 ] == ':' ) { + i = 0; + while ( i++ < N ) + spacesStr += ' '; + } } // ok, append spacesStr at the beginning of the current line = make indentation @@ -894,13 +951,14 @@ 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")); resize( 500, 250 ); QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4); int a,b; // dummies for PythonEditPane, not used, since library = false and myX, myY are not used in PythonEditPane + myIsLoop = isLoop; // mkr : PAL12236 if (isLoop) { QTabWidget* aLoopTabPane = new QTabWidget(this); myInitPane = new SUPERVGUI_PythonEditPane( this, false, a, b ); // library == false, since no creation of a node is needed here @@ -925,7 +983,7 @@ SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg( bool isLoop ) aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 ); QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox ); - connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) ); aBtnLayout->addWidget( aOKBtn ); aBtnLayout->addStretch(); @@ -937,6 +995,21 @@ SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg( bool isLoop ) aMainLayout->addWidget(aBtnBox); } +// mkr : IPAL9817 : to avoid a SIGSEGV when INode_Impl::SetPyFunction(...) +// will call with null python function name +void SUPERVGUI_EditPythonDlg::clickOnOk() +{ + // mkr : PAL12236 + bool hasEmptyName = myIsLoop ? + ( getInitFuncName().isEmpty() || getMoreFuncName().isEmpty() || getNextFuncName().isEmpty() ) : + getFuncName().isEmpty(); + + if ( hasEmptyName ) + QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_INCORRECT_INDENT" ) ); + else + accept(); +} + /** * Do the following actions for newly created Engine's CNode: * 1. Create a presentation for it (CanvasNode) @@ -945,9 +1018,19 @@ 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 ) { - if ( !CORBA::is_nil( theNode ) ) { + SUPERVGUI* aSupMod = SUPERVGUI::Supervision(); + if ( !aSupMod ) { + MESSAGE("NULL Supervision module!"); + return; + } + + SUPERVGUI_Main* aMain = aSupMod->getMain(); + + if ( !CORBA::is_nil( theNode ) && aMain ) { + + aMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, why here? -> PAL7960 + int cx, cy; //to appear a new node in the top-left corner of the current viewport - SUPERVGUI_Main* aMain = Supervision.getMain(); //2.8 point of improvements: Adding node to graph window with taking into account zoom factor QWMatrix aWM = aMain->getCanvasView()->worldMatrix(); @@ -968,8 +1051,9 @@ void SUPERVGUI_Service::addNode( SUPERV::CNode_var theNode, SUPERV::INode_var th aMain->addMacroNode( theNode ); else if ( theNode->IsLoop() || theNode->IsSwitch() ) aMain->addControlNode( theNode, SUPERV::CNode::_narrow( theEndNode ), true ); - else + else aMain->addComputeNode( theNode ); - } + aSupMod->nullifyInitialVF(); + } }