Salome HOME
NRI : Merge from V1_2.
[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 <strstream>
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                         GraphEditor::DataFlow * aDataFlowEditor ,
31                         const char * FuncName ,
32                         const SUPERV::ListOfStrings & PythonFunction ,
33                         const SUPERV::KindOfNode NodeKindOfNode ) :
34 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
35   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , FuncName , PythonFunction , NodeKindOfNode ) {
36 //  MESSAGE( NodeName << " " );
37   beginService( "GNode_Impl::GNode_Impl" );
38   if ( FuncName ) {
39     cout << "GNode_Impl::GNode_Impl " << (void *) FuncName << " " << FuncName
40          << " " << strlen( FuncName ) << endl ;
41   }
42   if ( NodeKindOfNode == SUPERV::GOTONode ) {
43     _thisObj = this ;
44     _id = _poa->activate_object(_thisObj);
45   }
46   _Orb = CORBA::ORB::_duplicate(orb);
47   _Poa = poa ;
48   _ContId = contId ;
49 //  DataFlowNode( DataFlowEditor()->AddNode( NodeService , NodeComponentName ,
50 //                                           NodeInterfaceName , NodeName ,
51 //                                           NodeKindOfNode ) );
52 //  DataFlowNode( DataFlowEditor()->AddNode( SALOME_ModuleCatalog::Service() ,
53 //                                           "" , "" , "" ,
54 //                                           NodeKindOfNode ) ) ;
55   endService( "GNode_Impl::GNode_Impl" );  
56 }
57
58 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
59                         PortableServer::POA_ptr poa ,
60                         PortableServer::ObjectId * contId , 
61                         const char *instanceName ,
62                         const char *interfaceName ,
63                         GraphEditor::DataFlow * aDataFlowEditor ,
64                         GraphBase::ListOfFuncName FuncNameList ,
65                         GraphBase::ListOfPythonFunctions PythonFunctionList ,
66                         const SUPERV::KindOfNode NodeKindOfNode ) :
67 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
68   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , FuncNameList , PythonFunctionList , NodeKindOfNode ) {
69 //  MESSAGE( NodeName << " " );
70   beginService( "GNode_Impl::GNode_Impl" );
71   if ( NodeKindOfNode == SUPERV::GOTONode ) {
72     _thisObj = this ;
73     _id = _poa->activate_object(_thisObj);
74   }
75   _Orb = CORBA::ORB::_duplicate(orb);
76   _Poa = poa ;
77   _ContId = contId ;
78 //  DataFlowNode( DataFlowEditor()->AddNode( NodeService , NodeComponentName ,
79 //                                           NodeInterfaceName , NodeName ,
80 //                                           NodeKindOfNode ) );
81 //  DataFlowNode( DataFlowEditor()->AddNode( SALOME_ModuleCatalog::Service() ,
82 //                                           "" , "" , "" ,
83 //                                           NodeKindOfNode ) ) ;
84   endService( "GNode_Impl::GNode_Impl" );  
85 }
86
87 GNode_Impl::GNode_Impl( CORBA::ORB_ptr orb ,
88                       PortableServer::POA_ptr poa ,
89                       PortableServer::ObjectId * contId , 
90                       const char *instanceName ,
91                       const char *interfaceName ,
92                       GraphEditor::DataFlow * aDataFlowEditor ,
93                       GraphEditor::InNode * aDataFlowNode ) :
94 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
95   INode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
96   MESSAGE( DataFlowNode()->Name() << " " );
97   beginService( "GNode_Impl::GNode_Impl" );
98   if ( DataFlowNode()->IsGOTONode() ) {
99     _thisObj = this ;
100     _id = _poa->activate_object(_thisObj);
101   }
102   _Orb = CORBA::ORB::_duplicate(orb);
103   _Poa = poa ;
104   _ContId = contId ;
105   endService( "GNode_Impl::GNode_Impl" );  
106 }
107
108 GNode_Impl::~GNode_Impl() {
109   beginService( "GNode_Impl::~GNode_Impl" );
110   endService( "GNode_Impl::~GNode_Impl" );
111 }
112
113 void GNode_Impl::destroy() {
114   beginService( "GNode_Impl::Destroy" );
115   if ( DataFlowEditor()->IsEditing() ) {
116     if ( Delete() ) {
117       _poa->deactivate_object(*_id) ;
118       CORBA::release(_poa) ;
119       delete(_id) ;
120       _thisObj->_remove_ref();
121     }
122   }
123   endService( "GNode_Impl::Destroy" );
124 }
125
126 bool GNode_Impl::Delete() {
127 //  beginService( "GNode_Impl::Delete" );
128   bool RetVal = false ;
129   if ( DataFlowEditor()->IsEditing() ) {
130     RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
131     if ( RetVal )
132       RetVal = DataFlowEditor()->IsValid() ;
133   }
134 //  endService( "GNode_Impl::Delete" );
135   return RetVal ;
136 }
137
138 SUPERV::INode_ptr GNode_Impl::Coupled() {
139   beginService( "GNode_Impl::Coupled" );
140   SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
141   if ( DataFlowNode()->CoupledNode() ) {
142     if ( CORBA::is_nil( DataFlowNode()->CoupledNode()->ObjRef() ) ) {
143       INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
144                                             instanceName() , interfaceName() ,
145                                             DataFlowEditor() ,
146                                             (GraphEditor::InNode *) DataFlowNode()->CoupledNode()->GetInNode() ) ;
147       PortableServer::ObjectId * id = myNode->getId() ;
148       CORBA::Object_var obj = _poa->id_to_reference(*id);
149       iobject = SUPERV::INode::_narrow(obj) ;
150       myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
151     }
152     else {
153       iobject = SUPERV::INode::_narrow( DataFlowNode()->CoupledNode()->ObjRef() ) ;
154     }
155   }
156   endService( "GNode_Impl::Coupled" );
157   return SUPERV::INode::_duplicate( iobject ) ;
158 }
159