Salome HOME
6d7cd4a29a6866193ed7e3bc5d54bbe167563626
[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( CORBA::ORB_ptr orb ,
134                       PortableServer::POA_ptr poa ,
135                       PortableServer::ObjectId * contId , 
136                       const char *instanceName ,
137                       const char *interfaceName ,
138                       GraphExecutor::DataFlow * aDataFlowExecutor ,
139                       GraphExecutor::InNode * aDataFlowExecutorNode ) :
140 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
141   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowExecutor , aDataFlowExecutorNode ) {
142 //  beginService( "GNode_Impl::GNode_Impl" );
143   if ( DataFlowExecutorNode() && DataFlowExecutorNode()->IsGOTONode() ) {
144 //    MESSAGE( "GNode_Impl::GNode_Impl " << DataFlowExecutorNode()->Name()
145 //             << " _poa->activate_object" );
146     _thisObj = this ;
147     _id = _poa->activate_object(_thisObj);
148   }
149   else {
150 //    MESSAGE( "GNode_Impl::GNode_Impl NO _poa->activate_object" );
151   }
152   _Orb = CORBA::ORB::_duplicate(orb);
153   _Poa = poa ;
154   _ContId = contId ;
155 //  endService( "GNode_Impl::GNode_Impl" );  
156 }
157
158 GNode_Impl::~GNode_Impl() {
159   beginService( "GNode_Impl::~GNode_Impl" );
160   endService( "GNode_Impl::~GNode_Impl" );
161 }
162
163 void GNode_Impl::destroy() {
164   beginService( "GNode_Impl::Destroy" );
165   if ( DataFlowEditor()->IsEditing() ) {
166     if ( Delete() ) {
167       _poa->deactivate_object(*_id) ;
168       CORBA::release(_poa) ;
169       delete(_id) ;
170       _thisObj->_remove_ref();
171     }
172   }
173 //  endService( "GNode_Impl::Destroy" );
174 }
175
176 bool GNode_Impl::Delete() {
177   beginService( "GNode_Impl::Delete" );
178   bool RetVal = false ;
179   if ( DataFlowEditor()->IsEditing() ) {
180     DeletePorts() ;
181     RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
182     if ( RetVal )
183       RetVal = DataFlowEditor()->IsValid() ;
184   }
185   endService( "GNode_Impl::Delete" );
186   return RetVal ;
187 }
188
189 SUPERV::INode_ptr GNode_Impl::Coupled() {
190 //  beginService( "GNode_Impl::Coupled" );
191   SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
192   if ( DataFlowNode() ) {
193     if ( DataFlowNode()->CoupledNode() ) {
194       if ( CORBA::is_nil( DataFlowNode()->CoupledNode()->ObjRef() ) ) {
195         INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
196                                               instanceName() , interfaceName() ,
197                                               DataFlowEditor() ,
198                                               (GraphEditor::InNode *) DataFlowNode()->CoupledNode()->GetInNode() ) ;
199         PortableServer::ObjectId * id = myNode->getId() ;
200         CORBA::Object_var obj = _poa->id_to_reference(*id);
201         iobject = SUPERV::INode::_narrow(obj) ;
202         myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
203       }
204       else {
205         iobject = SUPERV::INode::_narrow( DataFlowNode()->CoupledNode()->ObjRef() ) ;
206       }
207     }
208   }
209   else {
210     if ( DataFlowEditor()->Graph()->CoupledNode() ) {
211       if ( CORBA::is_nil( DataFlowEditor()->Graph()->CoupledNode()->ObjRef() ) ) {
212         INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
213                                               instanceName() , interfaceName() ,
214                                               DataFlowEditor() ,
215                                               (GraphEditor::InNode *) DataFlowEditor()->Graph()->CoupledNode()->GetInNode() ) ;
216         PortableServer::ObjectId * id = myNode->getId() ;
217         CORBA::Object_var obj = _poa->id_to_reference(*id);
218         iobject = SUPERV::INode::_narrow(obj) ;
219         myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
220       }
221       else {
222         iobject = SUPERV::INode::_narrow( DataFlowEditor()->Graph()->CoupledNode()->ObjRef() ) ;
223       }
224     }
225   }
226 //  endService( "GNode_Impl::Coupled" );
227   return SUPERV::INode::_duplicate( iobject ) ;
228 }
229