]> SALOME platform Git repositories - modules/superv.git/blob - src/Supervision/GNode_Impl.cxx
Salome HOME
A special "Loading" state was implemented. It is returned to GUI if the correspondin...
[modules/superv.git] / src / Supervision / GNode_Impl.cxx
1 //  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : GNode_Impl.cxx
8 //  Author : Jean Rahuel
9 //  Module : SUPERV
10 //  $Header: 
11
12 using namespace std;
13 #include <stdio.h>
14 #include <fstream>
15 //#include <sstream>
16 #include <string>
17
18 //#include "utilities.h"
19
20 #include "GNode_Impl.hxx"
21
22 GNode_Impl::GNode_Impl() {
23 }
24
25 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
26                        PortableServer::POA_ptr poa ,
27                        PortableServer::ObjectId * contId , 
28                        const char *instanceName ,
29                        const char *interfaceName ,
30                        const char *aDataFlowName ,
31                        const SUPERV::KindOfNode aKindOfNode ) :
32   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName , aKindOfNode ) {
33 //  MESSAGE("GNode_Impl::GNode_Impl activate object instanceName("
34 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
35 //          << hex << (void *) this << dec )
36 //  _thisObj = this ;
37 //  _id = _poa->activate_object(_thisObj);
38 //  MESSAGE( "GNode_Impl::GNode_Impl " << aDataFlowName );
39 //  beginService( "GNode_Impl::GNode_Impl" );
40   _Orb = CORBA::ORB::_duplicate(orb);
41   _Poa = poa ;
42   _ContId = contId ;
43 //  endService( "INode_Impl::INode_Impl" );  
44 }
45
46 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
47                         PortableServer::POA_ptr poa ,
48                         PortableServer::ObjectId * contId , 
49                         const char *instanceName ,
50                         const char *interfaceName ,
51                         GraphEditor::DataFlow * aDataFlowEditor ,
52                         const char * FuncName ,
53                         const SUPERV::ListOfStrings & PythonFunction ,
54                         const SUPERV::KindOfNode NodeKindOfNode ) :
55 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
56   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , FuncName , PythonFunction , NodeKindOfNode ) {
57 //  MESSAGE( NodeName << " " );
58 //  beginService( "GNode_Impl::GNode_Impl" );
59   if ( FuncName ) {
60 //    cout << "GNode_Impl::GNode_Impl " << (void *) FuncName << " " << FuncName
61 //         << " " << strlen( FuncName ) << endl ;
62   }
63   if ( NodeKindOfNode == SUPERV::GOTONode ) {
64     _thisObj = this ;
65     _id = _poa->activate_object(_thisObj);
66   }
67   _Orb = CORBA::ORB::_duplicate(orb);
68   _Poa = poa ;
69   _ContId = contId ;
70 //  DataFlowNode( DataFlowEditor()->AddNode( NodeService , NodeComponentName ,
71 //                                           NodeInterfaceName , NodeName ,
72 //                                           NodeKindOfNode ) );
73 //  DataFlowNode( DataFlowEditor()->AddNode( SALOME_ModuleCatalog::Service() ,
74 //                                           "" , "" , "" ,
75 //                                           NodeKindOfNode ) ) ;
76 //  endService( "GNode_Impl::GNode_Impl" );  
77 }
78
79 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
80                         PortableServer::POA_ptr poa ,
81                         PortableServer::ObjectId * contId , 
82                         const char *instanceName ,
83                         const char *interfaceName ,
84                         GraphEditor::DataFlow * aDataFlowEditor ,
85                         GraphBase::ListOfFuncName FuncNameList ,
86                         GraphBase::ListOfPythonFunctions PythonFunctionList ,
87                         const SUPERV::KindOfNode NodeKindOfNode ) :
88 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
89   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , FuncNameList , PythonFunctionList , NodeKindOfNode ) {
90 //  MESSAGE( NodeName << " " );
91 //  beginService( "GNode_Impl::GNode_Impl" );
92   if ( NodeKindOfNode == SUPERV::GOTONode ) {
93     _thisObj = this ;
94     _id = _poa->activate_object(_thisObj);
95   }
96   _Orb = CORBA::ORB::_duplicate(orb);
97   _Poa = poa ;
98   _ContId = contId ;
99 //  DataFlowNode( DataFlowEditor()->AddNode( NodeService , NodeComponentName ,
100 //                                           NodeInterfaceName , NodeName ,
101 //                                           NodeKindOfNode ) );
102 //  DataFlowNode( DataFlowEditor()->AddNode( SALOME_ModuleCatalog::Service() ,
103 //                                           "" , "" , "" ,
104 //                                           NodeKindOfNode ) ) ;
105 //  endService( "GNode_Impl::GNode_Impl" );  
106 }
107
108 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
109                       PortableServer::POA_ptr poa ,
110                       PortableServer::ObjectId * contId , 
111                       const char *instanceName ,
112                       const char *interfaceName ,
113                       GraphEditor::DataFlow * aDataFlowEditor ,
114                       GraphEditor::InNode * aDataFlowNode ) :
115 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
116   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
117 //  beginService( "GNode_Impl::GNode_Impl" );
118   if ( DataFlowNode() && DataFlowNode()->IsGOTONode() ) {
119 //    MESSAGE( "GNode_Impl::GNode_Impl " << DataFlowNode()->PyFuncName()
120 //             << " _poa->activate_object" );
121     _thisObj = this ;
122     _id = _poa->activate_object(_thisObj);
123   }
124   else {
125 //    MESSAGE( "GNode_Impl::GNode_Impl NO _poa->activate_object" );
126   }
127   _Orb = CORBA::ORB::_duplicate(orb);
128   _Poa = poa ;
129   _ContId = contId ;
130 //  endService( "GNode_Impl::GNode_Impl" );  
131 }
132
133 GNode_Impl::~GNode_Impl() {
134   beginService( "GNode_Impl::~GNode_Impl" );
135   endService( "GNode_Impl::~GNode_Impl" );
136 }
137
138 void GNode_Impl::destroy() {
139   beginService( "GNode_Impl::Destroy" );
140   if ( DataFlowEditor()->IsEditing() ) {
141     if ( Delete() ) {
142       _poa->deactivate_object(*_id) ;
143       CORBA::release(_poa) ;
144       delete(_id) ;
145       _thisObj->_remove_ref();
146     }
147   }
148 //  endService( "GNode_Impl::Destroy" );
149 }
150
151 bool GNode_Impl::Delete() {
152   beginService( "GNode_Impl::Delete" );
153   bool RetVal = false ;
154   if ( DataFlowEditor()->IsEditing() ) {
155     if ( DataFlowNode() ) {
156       GraphBase::GOTONode * aGOTONode = DataFlowNode()->GOTONode() ;
157       if ( aGOTONode ) {
158         GraphBase::GOTONode * aCoupledNode = (GraphBase::GOTONode * ) aGOTONode->CoupledNode() ;
159         if ( aCoupledNode && ( aCoupledNode->IsOneOfGOTONodes() || aCoupledNode->IsDataFlowNode() ||
160                                aCoupledNode->IsDataStreamNode() ) ) {
161           aCoupledNode->CoupledNode( NULL ) ;
162           aCoupledNode->MacroObject( SUPERV::Graph::_nil() ) ;
163           aCoupledNode->GraphMacroLevel( 0 ) ;
164         }
165       }
166     }
167     DeletePorts() ;
168     RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
169     if ( RetVal )
170       RetVal = DataFlowEditor()->IsValid() ;
171   }
172   endService( "GNode_Impl::Delete" );
173   return RetVal ;
174 }
175
176 SUPERV::INode_ptr GNode_Impl::Coupled() {
177 //  beginService( "GNode_Impl::Coupled" );
178   SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
179   if ( DataFlowNode() ) {
180     if ( DataFlowNode()->CoupledNode() ) {
181       if ( CORBA::is_nil( DataFlowNode()->CoupledNode()->ObjRef() ) ) {
182         INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
183                                               instanceName() , interfaceName() ,
184                                               DataFlowEditor() ,
185                                               (GraphEditor::InNode *) DataFlowNode()->CoupledNode()->GetInNode() ) ;
186         PortableServer::ObjectId * id = myNode->getId() ;
187         CORBA::Object_var obj = _poa->id_to_reference(*id);
188         iobject = SUPERV::INode::_narrow(obj) ;
189         myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
190       }
191       else {
192         iobject = SUPERV::INode::_narrow( DataFlowNode()->CoupledNode()->ObjRef() ) ;
193       }
194     }
195   }
196   else {
197     if ( DataFlowEditor()->Graph()->CoupledNode() ) {
198       if ( CORBA::is_nil( DataFlowEditor()->Graph()->CoupledNode()->ObjRef() ) ) {
199         INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
200                                               instanceName() , interfaceName() ,
201                                               DataFlowEditor() ,
202                                               (GraphEditor::InNode *) DataFlowEditor()->Graph()->CoupledNode()->GetInNode() ) ;
203         PortableServer::ObjectId * id = myNode->getId() ;
204         CORBA::Object_var obj = _poa->id_to_reference(*id);
205         iobject = SUPERV::INode::_narrow(obj) ;
206         myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
207       }
208       else {
209         iobject = SUPERV::INode::_narrow( DataFlowEditor()->Graph()->CoupledNode()->ObjRef() ) ;
210       }
211     }
212   }
213 //  endService( "GNode_Impl::Coupled" );
214   return SUPERV::INode::_duplicate( iobject ) ;
215 }
216
217 bool GNode_Impl::SetCoupled( const char * anInLineNode )
218 {
219   GraphBase::InLineNode * CoupledINode = (GraphBase::InLineNode * ) DataFlowEditor()->Graph()->GetGraphNode( anInLineNode ) ;
220   if ( !CoupledINode ) {
221     
222     // asv : 2.11.04 : nullify Coupled node if anInLineNode == "" (bug 7113)
223     if ( anInLineNode==NULL || !strlen( anInLineNode ) ) {
224       DataFlowNode()->CoupledNode( NULL );
225     }
226
227     return false;
228   } 
229   if ( ( IsGOTO() && ( CoupledINode->IsInLineNode() || CoupledINode->IsLoopNode() || CoupledINode->IsSwitchNode() ) ) ||
230        ( !IsGOTO() && ( IsLoop() || IsSwitch() || IsEndLoop() || IsEndSwitch() ) ) ) {
231     DataFlowNode()->CoupledNode( CoupledINode ) ;
232     if ( CoupledINode && IsSwitch() ) {
233       DataFlowEditor()->AddLink( Name() , "Default" ,CoupledINode->Name() , "Default" ) ;
234     }
235     else if ( CoupledINode && ( IsLoop() || IsEndLoop() ) ) {
236       DataFlowEditor()->AddLink( Name() , "DoLoop" , CoupledINode->Name() , "DoLoop" ) ;
237     }
238     else if ( CoupledINode && IsGOTO() ) {
239       DataFlowEditor()->AddLink( Name() , "OutGate" ,CoupledINode->Name() , "InGate" ) ;
240     }
241     return  true ;
242   }
243   return false ; 
244 }