Salome HOME
SMH: 3.0.0 preparation = merged version (POLYWORK + RTVDEBUG01) + adopation for new GUI
[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     else {
148       MESSAGE("GNode_Impl::destroy ERROR ") ;
149     }
150   }
151 //  endService( "GNode_Impl::Destroy" );
152 }
153
154 bool GNode_Impl::Delete() {
155   beginService( "GNode_Impl::Delete" );
156   bool RetVal = false ;
157   if ( DataFlowEditor()->IsEditing() ) {
158     if ( DataFlowNode() ) {
159       GraphBase::GOTONode * aGOTONode = DataFlowNode()->GOTONode() ;
160       if ( aGOTONode ) {
161         GraphBase::GOTONode * aCoupledNode = (GraphBase::GOTONode * ) aGOTONode->CoupledNode() ;
162         if ( aCoupledNode && ( aCoupledNode->IsOneOfGOTONodes() || aCoupledNode->IsDataFlowNode() ||
163                                aCoupledNode->IsDataStreamNode() ) ) {
164           aCoupledNode->CoupledNode( NULL ) ;
165           aCoupledNode->MacroObject( SUPERV::Graph::_nil() ) ;
166           aCoupledNode->GraphMacroLevel( 0 ) ;
167         }
168       }
169     }
170     DeletePorts() ;
171     RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
172     if ( RetVal )
173       DataFlowEditor()->UnValid() ;
174   }
175   endService( "GNode_Impl::Delete" );
176   return RetVal ;
177 }
178
179 SUPERV::INode_ptr GNode_Impl::Coupled() {
180 //  beginService( "GNode_Impl::Coupled" );
181   SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
182   if ( DataFlowNode() ) {
183     if ( DataFlowNode()->CoupledNode() ) {
184       if ( CORBA::is_nil( DataFlowNode()->CoupledNode()->ObjRef() ) ) {
185         INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
186                                               instanceName() , interfaceName() ,
187                                               DataFlowEditor() ,
188                                               (GraphEditor::InNode *) DataFlowNode()->CoupledNode()->GetInNode() ) ;
189         PortableServer::ObjectId * id = myNode->getId() ;
190         CORBA::Object_var obj = _poa->id_to_reference(*id);
191         iobject = SUPERV::INode::_narrow(obj) ;
192         myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
193       }
194       else {
195         iobject = SUPERV::INode::_narrow( DataFlowNode()->CoupledNode()->ObjRef() ) ;
196       }
197     }
198   }
199   else {
200     if ( DataFlowEditor()->Graph()->CoupledNode() ) {
201       if ( CORBA::is_nil( DataFlowEditor()->Graph()->CoupledNode()->ObjRef() ) ) {
202         INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
203                                               instanceName() , interfaceName() ,
204                                               DataFlowEditor() ,
205                                               (GraphEditor::InNode *) DataFlowEditor()->Graph()->CoupledNode()->GetInNode() ) ;
206         PortableServer::ObjectId * id = myNode->getId() ;
207         CORBA::Object_var obj = _poa->id_to_reference(*id);
208         iobject = SUPERV::INode::_narrow(obj) ;
209         myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
210       }
211       else {
212         iobject = SUPERV::INode::_narrow( DataFlowEditor()->Graph()->CoupledNode()->ObjRef() ) ;
213       }
214     }
215   }
216 //  endService( "GNode_Impl::Coupled" );
217   return SUPERV::INode::_duplicate( iobject ) ;
218 }
219
220 bool GNode_Impl::SetCoupled( const char * anInLineNode )
221 {
222   GraphBase::InLineNode * CoupledINode = (GraphBase::InLineNode * ) DataFlowEditor()->Graph()->GetGraphNode( anInLineNode ) ;
223   if ( !CoupledINode ) {
224     
225     // asv : 2.11.04 : nullify Coupled node if anInLineNode == "" (bug 7113)
226     if ( anInLineNode==NULL || !strlen( anInLineNode ) ) {
227       DataFlowNode()->CoupledNode( NULL );
228     }
229
230     return false;
231   } 
232   if ( ( IsGOTO() && ( CoupledINode->IsInLineNode() || CoupledINode->IsLoopNode() || CoupledINode->IsSwitchNode() ) ) ||
233        ( !IsGOTO() && ( IsLoop() || IsSwitch() || IsEndLoop() || IsEndSwitch() ) ) ) {
234     DataFlowNode()->CoupledNode( CoupledINode ) ;
235     if ( CoupledINode && IsSwitch() ) {
236       DataFlowEditor()->AddLink( Name() , "Default" ,CoupledINode->Name() , "Default" ) ;
237     }
238     else if ( CoupledINode && ( IsLoop() || IsEndLoop() ) ) {
239       DataFlowEditor()->AddLink( Name() , "DoLoop" , CoupledINode->Name() , "DoLoop" ) ;
240     }
241     else if ( CoupledINode && IsGOTO() ) {
242       DataFlowEditor()->AddLink( Name() , "OutGate" ,CoupledINode->Name() , "InGate" ) ;
243     }
244     return  true ;
245   }
246   return false ; 
247 }