Salome HOME
NRI : Merge from V1_2.
[modules/superv.git] / src / GraphBase / DataFlowBase_FactoryNode.cxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : DataFlowBase_FactoryNode.cxx
8 //  Author : Jean Rahuel, CEA
9 //  Module : SUPERV
10 //  $Header:
11
12 using namespace std;
13 #include <strstream>
14 #include <iostream>
15
16 #include "DataFlowBase_FactoryNode.hxx"
17
18 static void InitFields( char *              &_ComponentName ,
19                         char *              &_InterfaceName ,
20                         char *              &_Computer ) {
21   time_t T = time(NULL);
22   struct tm * Tm = localtime(&T);
23
24   _ComponentName = NULLSTRING ;
25   _InterfaceName = NULLSTRING ;
26
27   _Computer = FACTORYSERVER ;
28 }
29
30 GraphBase::FactoryNode::FactoryNode() :
31   GraphBase::ComputingNode::ComputingNode() {
32
33   InitFields( _ComponentName ,
34               _InterfaceName ,
35               _Computer ) ;
36   _Container = Engines::Container::_nil() ;
37   _ObjComponent = Engines::Component::_nil() ;
38   cdebug << "GraphBase::FactoryNode::FactoryNode "  << this 
39        << " _ComponentName " 
40        << (void *) _ComponentName << " " << _ComponentName << " _Name "
41        << (void *) Name() << " " << Name() << " _Computer "
42        << (void *) _Computer << " "  << _Computer << " _Comment "
43        << (void *) Comment() << " "  << Comment() << " "  << endl ;
44
45 }
46
47 GraphBase::FactoryNode::FactoryNode( CORBA::ORB_ptr ORB ,
48                        SALOME_NamingService* ptrNamingService ,
49                        const char * aDataFlowName ,
50                        int * Graph_prof_debug ,
51                        ostream * Graph_fdebug ) :
52   GraphBase::ComputingNode::ComputingNode( ORB , ptrNamingService , aDataFlowName ,
53                                            Graph_prof_debug , Graph_fdebug ) {
54
55   InitFields( _ComponentName ,
56               _InterfaceName ,
57               _Computer ) ;
58
59   _Container = Engines::Container::_nil() ;
60   _ObjComponent = Engines::Component::_nil() ;
61
62   cdebug << "GraphBase::FactoryNode::FactoryNode "  << this 
63        << " _ComponentName " 
64        << (void *) _ComponentName << " '" << _ComponentName
65        << "' _InterfaceName "
66        << (void *) _InterfaceName << " '" << _InterfaceName << "' _Name "
67        << (void *) Name() << " '" << Name() << "' _Computer "
68        << (void *) _Computer << " "  << _Computer << " _Comment "
69        << (void *) Comment() << " "  << Comment() << " "  << endl ;
70 }
71
72 GraphBase::FactoryNode::FactoryNode( CORBA::ORB_ptr ORB ,
73                        SALOME_NamingService* ptrNamingService ,
74                        const SALOME_ModuleCatalog::Service& aService ,
75                        const char *ComponentName ,
76                        const char* InterfaceName ,
77                        const char *NodeName ,
78                        const SUPERV::KindOfNode akind ,
79                        const SUPERV::SDate NodeFirstCreation ,
80                        const SUPERV::SDate NodeLastModification  ,
81                        const char * NodeEditorRelease ,
82                        const char * NodeAuthor ,
83                        const char * NodeComputer ,
84                        const char * NodeComment ,
85                        const bool   GeneratedName ,
86                        const long   X ,
87                        const long   Y ,
88                        int * Graph_prof_debug ,
89                        ostream * Graph_fdebug ) :
90   GraphBase::ComputingNode::ComputingNode( ORB , ptrNamingService , aService ,
91                                            NodeName , akind ,
92                                            NodeFirstCreation , NodeLastModification  ,
93                                            NodeEditorRelease , NodeAuthor , NodeComment ,
94                                            GeneratedName , X , Y ,
95                                            Graph_prof_debug , Graph_fdebug ) {
96
97   _Container = Engines::Container::_nil() ;
98   _ObjComponent = Engines::Component::_nil() ;
99
100   _ComponentName = new char[strlen(ComponentName)+1];
101   strcpy(_ComponentName , ComponentName ) ;
102
103   _InterfaceName = new char[strlen(InterfaceName)+1];
104   strcpy(_InterfaceName , InterfaceName ) ;
105
106   if ( NodeComputer ) {
107     _Computer = new char[ strlen( NodeComputer ) + 1 ] ;
108     strcpy( _Computer  , NodeComputer ) ;
109   }
110   else
111     _Computer = FACTORYSERVER ;
112
113   cdebug_in << "GraphBase::FactoryNode::FactoryNode(" << aService.ServiceName << ","
114             << ComponentName << "," << Name() << "," << akind
115             << "," << NodeComputer << "," << Comment() << ")" << endl;
116   
117   cdebug << "GraphBase::FactoryNode::FactoryNode "  << this 
118        << " _ComponentName " 
119        << (void *) _ComponentName << " '" << _ComponentName
120        << "' _InterfaceName "
121        << (void *) _InterfaceName << " '" << _InterfaceName << "' _Name "
122        << (void *) Name() << " '" << Name() << "' _Computer "
123        << (void *) _Computer << " "  << _Computer << " _Comment "
124        << (void *) Comment() << " "  << Comment() << " " 
125        << " KindOfNode " << Kind()
126        << " ServiceName " << ServiceName() << " In(" << ServiceInParameter().length()
127        << ") Out(" << ServiceOutParameter().length() << ")" << endl ;
128
129   cdebug_out << "GraphBase::FactoryNode::FactoryNode" << endl;
130 }
131
132 GraphBase::FactoryNode::~FactoryNode() {
133   cdebug << "GraphBase::Node::~Node "  << this 
134        << "_ComponentName " 
135        << (void *) _ComponentName << " " << _ComponentName << " _Name "
136        << (void *) Name() << " " << Name() << " _Computer "
137        << (void *) _Computer << " "  << _Computer << " _Comment "
138        << (void *) Comment() << " "  << Comment() << " "  << endl ;
139 //  if ( _ComponentName != NULLSTRING )
140 //    delete [] _ComponentName ;
141 //  delete [] _Name ;
142 //  delete [] _EditorRelease ;
143 //  if ( _Author != NULLSTRING )
144 //    delete [] _Author ;
145 //  if ( _Computer != FACTORYSERVER )
146 //    delete [] _Computer;
147 //  if ( _Comment != NULLSTRING )
148 //    delete [] _Comment;
149 }
150
151 bool GraphBase::FactoryNode::ComponentName(const char * aComponentName) {
152   if ( _ComponentName && _ComponentName != NULLSTRING )
153     delete [] _ComponentName ;
154   _ComponentName = new char[strlen(aComponentName)+1] ;
155   strcpy( _ComponentName , aComponentName ) ;
156   return true ;
157 }
158
159 bool GraphBase::FactoryNode::InterfaceName(const char * anInterfaceName) {
160   if ( _InterfaceName && _InterfaceName != NULLSTRING )
161     delete [] _InterfaceName ;
162   _InterfaceName = new char[strlen(anInterfaceName)+1] ;
163   strcpy( _InterfaceName , anInterfaceName ) ;
164   return true ;
165 }
166
167 bool GraphBase::FactoryNode::Computer(const char *c) {
168   cdebug_in << "GraphBase::FactoryNode::Computer" << endl;
169   if ( _Computer != FACTORYSERVER )
170     delete [] _Computer ;
171   _Computer = my_strdup(c);
172   cdebug_in << "GraphBase::FactoryNode::Computer('" << _Computer << "')" << endl;
173   cdebug_out << "GraphBase::FactoryNode::Computer" << endl;
174   return true ;
175 }
176
177 //bool GraphBase::FactoryNode::SaveXML( ostream &f , char *Tabs ,
178 bool GraphBase::FactoryNode::SaveXML( QDomDocument & Graph , QDomElement & info ,
179                                       int XCoordinate , int YCoordinate ) const {
180   GraphBase::ListOfFuncName aFuncNames ; 
181   GraphBase::ListOfPythonFunctions aVoidList ;
182 //  return GraphBase::ComputingNode::SaveXML( f , Tabs , ComponentName() ,
183   return GraphBase::ComputingNode::SaveXML( Graph , info , ComponentName() ,
184                                             InterfaceName() , Computer() , "" ,
185                                             aFuncNames , aVoidList ,
186                                             XCoordinate , YCoordinate ) ;
187 }
188
189 bool GraphBase::FactoryNode::SavePY(ostream &f , const char * aGraphName ,
190                                     int XCoordinate , int YCoordinate ) const {
191   GraphBase::ListOfFuncName aFuncNames ; 
192   GraphBase::ListOfPythonFunctions aVoidList ;
193   return GraphBase::ComputingNode::SavePY( f , aGraphName , ComponentName() ,
194                                            InterfaceName() , Computer() , NULL ,
195                                            aFuncNames  , aVoidList ,
196                                            XCoordinate , YCoordinate ) ;
197 }
198