Salome HOME
89228a591aaa5939d988116f4919393faff38612
[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  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : GNode_Impl.cxx
23 //  Author : Jean Rahuel
24 //  Module : SUPERV
25
26 using namespace std;
27 #include <stdio.h>
28 #include <fstream>
29 //#include <sstream>
30 #include <string>
31
32 //#include "utilities.h"
33
34 #include "GNode_Impl.hxx"
35
36 GNode_Impl::GNode_Impl() {
37 }
38
39 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
40                        PortableServer::POA_ptr poa ,
41                        PortableServer::ObjectId * contId , 
42                        const char *instanceName ,
43                        const char *interfaceName ,
44                        const char *aDataFlowName ,
45                        const SUPERV::KindOfNode aKindOfNode ) :
46   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName , aKindOfNode ) {
47 //  MESSAGE("GNode_Impl::GNode_Impl activate object instanceName("
48 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
49 //          << hex << (void *) this << dec )
50 //  _thisObj = this ;
51 //  _id = _poa->activate_object(_thisObj);
52 //  MESSAGE( "GNode_Impl::GNode_Impl " << aDataFlowName );
53 //  beginService( "GNode_Impl::GNode_Impl" );
54   _Orb = CORBA::ORB::_duplicate(orb);
55   _Poa = poa ;
56   _ContId = contId ;
57 //  endService( "INode_Impl::INode_Impl" );  
58 }
59
60 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
61                         PortableServer::POA_ptr poa ,
62                         PortableServer::ObjectId * contId , 
63                         const char *instanceName ,
64                         const char *interfaceName ,
65                         GraphEditor::DataFlow * aDataFlowEditor ,
66                         const char * FuncName ,
67                         const SUPERV::ListOfStrings & PythonFunction ,
68                         const SUPERV::KindOfNode NodeKindOfNode ) :
69 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
70   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , FuncName , PythonFunction , NodeKindOfNode ) {
71 //  MESSAGE( NodeName << " " );
72 //  beginService( "GNode_Impl::GNode_Impl" );
73   if ( FuncName ) {
74 //    cout << "GNode_Impl::GNode_Impl " << (void *) FuncName << " " << FuncName
75 //         << " " << strlen( FuncName ) << endl ;
76   }
77   if ( NodeKindOfNode == SUPERV::GOTONode ) {
78     _thisObj = this ;
79     _id = _poa->activate_object(_thisObj);
80   }
81   _Orb = CORBA::ORB::_duplicate(orb);
82   _Poa = poa ;
83   _ContId = contId ;
84 //  DataFlowNode( DataFlowEditor()->AddNode( NodeService , NodeComponentName ,
85 //                                           NodeInterfaceName , NodeName ,
86 //                                           NodeKindOfNode ) );
87 //  DataFlowNode( DataFlowEditor()->AddNode( SALOME_ModuleCatalog::Service() ,
88 //                                           "" , "" , "" ,
89 //                                           NodeKindOfNode ) ) ;
90 //  endService( "GNode_Impl::GNode_Impl" );  
91 }
92
93 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
94                         PortableServer::POA_ptr poa ,
95                         PortableServer::ObjectId * contId , 
96                         const char *instanceName ,
97                         const char *interfaceName ,
98                         GraphEditor::DataFlow * aDataFlowEditor ,
99                         GraphBase::ListOfFuncName FuncNameList ,
100                         GraphBase::ListOfPythonFunctions PythonFunctionList ,
101                         const SUPERV::KindOfNode NodeKindOfNode ) :
102 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
103   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , FuncNameList , PythonFunctionList , NodeKindOfNode ) {
104 //  MESSAGE( NodeName << " " );
105 //  beginService( "GNode_Impl::GNode_Impl" );
106   if ( NodeKindOfNode == SUPERV::GOTONode ) {
107     _thisObj = this ;
108     _id = _poa->activate_object(_thisObj);
109   }
110   _Orb = CORBA::ORB::_duplicate(orb);
111   _Poa = poa ;
112   _ContId = contId ;
113 //  DataFlowNode( DataFlowEditor()->AddNode( NodeService , NodeComponentName ,
114 //                                           NodeInterfaceName , NodeName ,
115 //                                           NodeKindOfNode ) );
116 //  DataFlowNode( DataFlowEditor()->AddNode( SALOME_ModuleCatalog::Service() ,
117 //                                           "" , "" , "" ,
118 //                                           NodeKindOfNode ) ) ;
119 //  endService( "GNode_Impl::GNode_Impl" );  
120 }
121
122 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
123                       PortableServer::POA_ptr poa ,
124                       PortableServer::ObjectId * contId , 
125                       const char *instanceName ,
126                       const char *interfaceName ,
127                       GraphEditor::DataFlow * aDataFlowEditor ,
128                       GraphEditor::InNode * aDataFlowNode ) :
129 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
130   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
131 //  beginService( "GNode_Impl::GNode_Impl" );
132   if ( DataFlowNode() && DataFlowNode()->IsGOTONode() ) {
133 //    MESSAGE( "GNode_Impl::GNode_Impl " << DataFlowNode()->PyFuncName()
134 //             << " _poa->activate_object" );
135     _thisObj = this ;
136     _id = _poa->activate_object(_thisObj);
137   }
138   else {
139 //    MESSAGE( "GNode_Impl::GNode_Impl NO _poa->activate_object" );
140   }
141   _Orb = CORBA::ORB::_duplicate(orb);
142   _Poa = poa ;
143   _ContId = contId ;
144 //  endService( "GNode_Impl::GNode_Impl" );  
145 }
146
147 GNode_Impl::~GNode_Impl() {
148   beginService( "GNode_Impl::~GNode_Impl" );
149   endService( "GNode_Impl::~GNode_Impl" );
150 }
151
152 void GNode_Impl::destroy() {
153   beginService( "GNode_Impl::Destroy" );
154   if ( DataFlowEditor()->IsEditing() ) {
155     if ( Delete() ) {
156       _poa->deactivate_object(*_id) ;
157 //      CORBA::release(_poa) ;
158       delete(_id) ;
159 //      _thisObj->_remove_ref();
160     }
161     else {
162       MESSAGE("GNode_Impl::destroy ERROR ") ;
163     }
164   }
165 //  endService( "GNode_Impl::Destroy" );
166 }
167
168 bool GNode_Impl::Delete() {
169   beginService( "GNode_Impl::Delete" );
170   bool RetVal = false ;
171   if ( DataFlowEditor()->IsEditing() ) {
172     if ( DataFlowNode() ) {
173       GraphBase::GOTONode * aGOTONode = DataFlowNode()->GOTONode() ;
174       if ( aGOTONode ) {
175         GraphBase::GOTONode * aCoupledNode = (GraphBase::GOTONode * ) aGOTONode->CoupledNode() ;
176         if ( aCoupledNode && ( aCoupledNode->IsOneOfGOTONodes() || aCoupledNode->IsDataFlowNode() ||
177                                aCoupledNode->IsDataStreamNode() ) ) {
178           aCoupledNode->CoupledNode( NULL ) ;
179           aCoupledNode->MacroObject( SUPERV::Graph::_nil() ) ;
180           aCoupledNode->GraphMacroLevel( 0 ) ;
181         }
182       }
183     }
184     DeletePorts() ;
185     RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
186     if ( RetVal )
187       DataFlowEditor()->UnValid() ;
188   }
189   endService( "GNode_Impl::Delete" );
190   return RetVal ;
191 }
192
193 SUPERV::INode_ptr GNode_Impl::Coupled() {
194 //  beginService( "GNode_Impl::Coupled" );
195   SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
196   if ( DataFlowNode() ) {
197     if ( DataFlowNode()->CoupledNode() ) {
198       if ( CORBA::is_nil( DataFlowNode()->CoupledNode()->ObjRef() ) ) {
199         INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
200                                               instanceName() , interfaceName() ,
201                                               DataFlowEditor() ,
202                                               (GraphEditor::InNode *) DataFlowNode()->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( DataFlowNode()->CoupledNode()->ObjRef() ) ;
210       }
211     }
212   }
213   else {
214     if ( DataFlowEditor()->Graph()->CoupledNode() ) {
215       if ( CORBA::is_nil( DataFlowEditor()->Graph()->CoupledNode()->ObjRef() ) ) {
216         INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
217                                               instanceName() , interfaceName() ,
218                                               DataFlowEditor() ,
219                                               (GraphEditor::InNode *) DataFlowEditor()->Graph()->CoupledNode()->GetInNode() ) ;
220         PortableServer::ObjectId * id = myNode->getId() ;
221         CORBA::Object_var obj = _poa->id_to_reference(*id);
222         iobject = SUPERV::INode::_narrow(obj) ;
223         myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
224       }
225       else {
226         iobject = SUPERV::INode::_narrow( DataFlowEditor()->Graph()->CoupledNode()->ObjRef() ) ;
227       }
228     }
229   }
230 //  endService( "GNode_Impl::Coupled" );
231   return SUPERV::INode::_duplicate( iobject ) ;
232 }
233
234 bool GNode_Impl::SetCoupled( const char * anInLineNode )
235 {
236   GraphBase::InLineNode * CoupledINode = (GraphBase::InLineNode * ) DataFlowEditor()->Graph()->GetGraphNode( anInLineNode ) ;
237   if ( !CoupledINode ) {
238     
239     // asv : 2.11.04 : nullify Coupled node if anInLineNode == "" (bug 7113)
240     if ( anInLineNode==NULL || !strlen( anInLineNode ) ) {
241       DataFlowNode()->CoupledNode( NULL );
242     }
243
244     return false;
245   } 
246   if ( ( IsGOTO() && ( CoupledINode->IsInLineNode() || CoupledINode->IsLoopNode() || CoupledINode->IsSwitchNode() ) ) ||
247        ( !IsGOTO() && ( IsLoop() || IsSwitch() || IsEndLoop() || IsEndSwitch() ) ) ) {
248     DataFlowNode()->CoupledNode( CoupledINode ) ;
249     if ( CoupledINode && IsSwitch() ) {
250       DataFlowEditor()->AddLink( Name() , "Default" ,CoupledINode->Name() , "Default" ) ;
251     }
252     else if ( CoupledINode && ( IsLoop() || IsEndLoop() ) ) {
253       DataFlowEditor()->AddLink( Name() , "DoLoop" , CoupledINode->Name() , "DoLoop" ) ;
254     }
255     else if ( CoupledINode && IsGOTO() ) {
256       DataFlowEditor()->AddLink( Name() , "OutGate" ,CoupledINode->Name() , "InGate" ) ;
257     }
258     return  true ;
259   }
260   return false ; 
261 }