From 2bfe473cb1e3b79dc0dcb68aad9ca40b0fb9301e Mon Sep 17 00:00:00 2001 From: mkr Date: Thu, 9 Jun 2005 12:46:32 +0000 Subject: [PATCH] Modifications for correct adding factory nodes into the dataflow. --- src/SUPERVGUI/SUPERVGUI.cxx | 36 +++++++++++++++++++ src/SUPERVGUI/SUPERVGUI.h | 5 +++ src/SUPERVGUI/SUPERVGUI_Service.cxx | 54 ++++++++++++++++------------- 3 files changed, 70 insertions(+), 25 deletions(-) diff --git a/src/SUPERVGUI/SUPERVGUI.cxx b/src/SUPERVGUI/SUPERVGUI.cxx index 3d4f78f..e97ccda 100644 --- a/src/SUPERVGUI/SUPERVGUI.cxx +++ b/src/SUPERVGUI/SUPERVGUI.cxx @@ -141,6 +141,8 @@ void SUPERVGUI::initialize( CAM_Application* app ) //info = new SUPERVGUI_Information(); cursor = application()->desktop()->cursor(); + fillInterfaceNameMap(); + // ----- create actions -------------- createSupervAction( 301, "IMPORT" ); createSupervAction( 302, "EXPORT" ); @@ -890,3 +892,37 @@ bool SUPERVGUI::ActiveStudyChanged() { buffer[0] = (int)VIEW_GRAPHSUPERV; }*/ +void SUPERVGUI::fillInterfaceNameMap() { + //fill map: interface_name <-> component_name for all + //interfaces of all loaded components, it is necessary + //for correct adding factory nodes from AddComponent, + //SubComponent, MulComponent, etc. components. + myInterfaceNameMap.clear(); + + //get naming service + SALOME_NamingService* namingService = (( SalomeApp_Application* )application())->namingService(); + //get module catalog + CORBA::Object_ptr obj = namingService->Resolve("/Kernel/ModulCatalog"); + SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var; + *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj); + if (!CORBA::is_nil(*aModuleCatalog)) { + //get component list + SALOME_ModuleCatalog::ListOfComponents_var aCompList = (*aModuleCatalog)->GetComponentList(); + for (int ind1 = 0; ind1 < aCompList->length(); ind1++) { + //get component + SALOME_ModuleCatalog::Acomponent_ptr aComponent = (*aModuleCatalog)->GetComponent(aCompList[ind1]); + if ( aComponent != NULL ) { + //get interface list + SALOME_ModuleCatalog::ListOfInterfaces_var anIntList = aComponent->GetInterfaceList(); + for (int ind2 = 0; ind2 < anIntList->length(); ind2++) { + const char* anIntName = anIntList[ind2]; + myInterfaceNameMap.insert(QString(anIntName), QString(aComponent->componentname())); + } + } + } + } +} + +QMap SUPERVGUI::getInterfaceNameMap() const { + return myInterfaceNameMap; +} diff --git a/src/SUPERVGUI/SUPERVGUI.h b/src/SUPERVGUI/SUPERVGUI.h index e484bcd..f5bd8d9 100644 --- a/src/SUPERVGUI/SUPERVGUI.h +++ b/src/SUPERVGUI/SUPERVGUI.h @@ -108,6 +108,8 @@ class SUPERVGUI: public SalomeApp_Module { virtual void windows( QMap& ) const; + QMap getInterfaceNameMap() const; + signals: void KillMainThread(bool theValue); @@ -139,6 +141,8 @@ class SUPERVGUI: public SalomeApp_Module { void createSupervAction( const int id, const QString& po_id, const QString& icon_id = QString(""), const int key = 0, const bool toggle = false ); + void fillInterfaceNameMap(); + static int factory; SUIT_Study* study; SUPERV_Engine engine; @@ -148,6 +152,7 @@ class SUPERVGUI: public SalomeApp_Module { SUPERVGUI_Main* main; // active main QPtrList myGraphList; + QMap myInterfaceNameMap; }; #endif diff --git a/src/SUPERVGUI/SUPERVGUI_Service.cxx b/src/SUPERVGUI/SUPERVGUI_Service.cxx index 788cd8e..9732c58 100644 --- a/src/SUPERVGUI/SUPERVGUI_Service.cxx +++ b/src/SUPERVGUI/SUPERVGUI_Service.cxx @@ -452,32 +452,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 = 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")); - } - 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); + 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 ) { @@ -994,7 +998,7 @@ void SUPERVGUI_Service::addNode( SUPERV::CNode_var theNode, SUPERV::INode_var th 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 @@ -1020,6 +1024,6 @@ void SUPERVGUI_Service::addNode( SUPERV::CNode_var theNode, SUPERV::INode_var th aMain->addControlNode( theNode, SUPERV::CNode::_narrow( theEndNode ), true ); else aMain->addComputeNode( theNode ); - } + } } -- 2.39.2