Salome HOME
a439910e61bd12b3f55feeb9e6950cca4703cd71
[modules/superv.git] / src / GraphEditor / DataFlowEditor_OutNode.hxx
1 //  SUPERV GraphEditor : contains classes that permit edition of graphs
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowEditor_OutNode.hxx
25 //  Module : SUPERV
26
27 #ifndef _DATAFLOWEDITOR_OUTNODE_HXX
28 #define _DATAFLOWEDITOR_OUTNODE_HXX
29
30 #include "DataFlowBase_StreamGraph.hxx"
31
32 #include "DataFlowEditor_InNode.hxx"
33
34 namespace GraphEditor {
35
36   class OutNode : public GraphBase::Base {
37     
38     private :
39
40       GraphBase::StreamGraph * _StreamGraph ;
41       GraphBase::Graph       * _Graph ;
42
43       int  _Graph_prof_debug ;
44
45       bool _Imported ;
46
47       bool _Valid ;
48
49       bool _Executable ;
50
51       CORBA::ORB_ptr _Orb;
52
53       bool Valid(bool kLoopSwitch = true ) ;
54       bool Executable() ;
55
56       bool LoadNodes( map< string , int > & aMapOfNodes ,
57                       const GraphBase::ListOfSNodes &aNodes ) ;
58       bool LoadLinks( map< string , int > & aMapOfNodes ,
59                       const GraphBase::ListOfSLinks &aLinks ) ;
60       bool LoadDatas( map< string , int > & aMapOfNodes ,
61                       const GraphBase::ListOfSLinks &aDatas ) ;
62
63 //      bool GraphEditor::OutNode::LinkSaveXML( ostream &f , char *Tabs ,
64       bool GraphEditor::OutNode::LinkSaveXML( QDomDocument & Graph , QDomElement & link ,
65                                               GraphBase::SLink aLink ,
66                                               bool wdata ) const ;
67 //      bool SaveXML(ostream &f ) ;QDomDocument & Graph 
68       bool SaveXML( ostream & f , QDomDocument & Graph ,
69                     bool aSuperGraph , QDomElement & supergraph ) ;
70
71       bool GraphEditor::OutNode::LinkSavePY( ostream &f ,
72                                              const char *aGraphName ,
73                                              GraphBase::SLink aLink ,
74                                              bool fromparam ,
75                                              bool toparam ,
76                                              bool wdata ) const;
77       void DateModification() ;
78
79       // asv 20.09.04 added from GraphExecutor::FiniteStateMachine class (removed from there)
80 //      static map< string , GraphBase::Graph * > _MapOfGraphs ;
81 //      static map< string , int >                _MapOfGraphNames ;
82     
83 //      GraphBase::Graph * MapGraph( const char * aGraphName ) ;
84 //      bool MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) ;
85 //      void EraseGraph( const char * aGraphName ) ;
86 //      bool GraphName( const char * aGraphName ) ;
87 //      string GraphInstanceName( const char * aGraphName ) ;
88       // end added from FiniteStateMachine
89
90
91     public:
92
93       OutNode();
94       OutNode( CORBA::ORB_ptr ORB,
95                SALOME_NamingService* ptrNamingService ,
96                const char *DataFlowName ,
97                const char * DebugFileName ,
98                const SUPERV::KindOfNode aKindOfNode );
99       OutNode( CORBA::ORB_ptr ORB,
100                SALOME_NamingService* ptrNamingService ,
101                const SALOME_ModuleCatalog::Service& DataFlowService ,
102                const char *DataFlowComponentName ,
103                const char *DataFlowInterfaceName ,
104                const char *DataFlowName ,
105                const SUPERV::KindOfNode DataFlowkind ,
106                const SUPERV::SDate DataFlowFirstCreation ,
107                const SUPERV::SDate DataFlowLastModification ,
108                const char * DataFlowEditorRelease ,
109                const char * DataFlowAuthor ,
110                const char * DataFlowComputer ,
111                const char * DataFlowComment ,
112                const char * DebugFileName ) ;
113       virtual ~OutNode();
114
115       bool Name( const char * aName ) ;
116
117       void Set_prof_debug( CORBA::ORB_ptr ORB , const char * DebugFileName ) ;
118       GraphBase::StreamGraph * StreamGraph() {
119                                return _StreamGraph ; } ;
120       GraphBase::StreamGraph * StreamGraph() const {
121                                return _StreamGraph ; } ;
122       GraphBase::Graph * Graph() {
123                          return _Graph ; } ;
124       const GraphBase::Graph * Graph() const {
125                                return _Graph ; } ;
126
127       bool LoadDataFlow( const GraphBase::SGraph *aDataFlow ) ;
128       bool LoadXml( const char* myFileName , GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
129 //      bool LoadXml( const char* myFileName ) ;
130       bool LoadInfo( const GraphBase::SNode &aDataFlowInfo ) ;
131
132       bool SaveXml(const char* myFileName ) ;
133
134       bool SavePy(const char* myFileName ) ;
135       bool SavePY(ostream &f , bool importSuperV ) ;
136
137
138 // get all DataFlow informations (for a .XML file) :
139       GraphBase::ListOfSGraphs * GetDataFlows( GraphBase::ListOfSGraphs * aListOfDataFlows ) ;
140
141 //    void DateModification() ;
142
143       GraphEditor::InNode * AddNode(
144                         const SALOME_ModuleCatalog::Service& NodeService ,
145                         GraphBase::ListOfFuncName aFuncName ,
146                         GraphBase::ListOfPythonFunctions aPythonFunction ,
147                         const char* NodeComponentName ,
148                         const char* NodeInterfaceName ,
149                         const char* NodeName ,
150                         const SUPERV::KindOfNode NodeKindOfNode ,
151                         const SUPERV::SDate NodeFirstCreation ,
152                         const SUPERV::SDate NodeLastModification ,
153                         const char * NodeEditorRelease ,
154                         const char * NodeAuthor ,
155                         const char * NodeComputer ,
156                         const char * NodeComment ,
157                         const int NodeX ,
158                         const int NodeY ) ;
159       GraphEditor::InNode * GetNode( const char* NodeName ) {
160                const GraphBase::Graph::ComputingNode * aNode = _Graph->GetGraphNode( NodeName ) ;
161                if ( aNode ) {
162                  return (GraphEditor::InNode * ) (aNode->GetInNode()) ;
163                }
164                else {
165                  return (GraphEditor::InNode * ) NULL ;
166                } } ;
167       bool RemoveNode( const char* NodeName ) {
168            DateModification() ;
169            _Valid = false ;
170            return _Graph->RemoveNode( NodeName ) ; } ;
171       bool ReNameNode( const char* OldNodeName ,
172                        const char* NewNodeName ) {
173            DateModification() ;
174            _Valid = false ;
175            return _Graph->ReNameNode( OldNodeName , NewNodeName ) ; } ;
176
177       void Coordinates( const int X , const int Y ) {
178            return _Graph->Coordinates( X , Y ) ; } ;
179       const int XCoordinate() {
180            return _Graph->XCoordinate() ; } ;
181       const int YCoordinate() {
182            return _Graph->YCoordinate() ; } ;
183       void Coordinates( const char* NodeName , const int X , const int Y ) ;
184       const int XCoordinate( const char* NodeName ) ;
185       const int YCoordinate( const char* NodeName ) ;
186
187       const GraphBase::InPort *GetInPort( const char * InPortName ) {
188             return _Graph->GetInPort( InPortName ) ; } ;
189       const GraphBase::OutPort *GetOutPort( const char * OutPortName ) {
190             return _Graph->GetOutPort( OutPortName ) ; } ;
191       GraphBase::InPort *GetChangeInPort( const char * InPortName ) {
192             return _Graph->GetChangeInPort( InPortName ) ; } ;
193       GraphBase::OutPort *GetChangeOutPort( const char * OutPortName ) {
194             return _Graph->GetChangeOutPort( OutPortName ) ; } ;
195
196       bool HasInput(const char * ToServiceParameterName ) {
197            return _Graph->HasInput( ToServiceParameterName ) ;
198          }
199
200       bool AddLink( const char* FromNodeName ,
201                     const char* FromServiceParameterName ,
202                     const char* ToNodeName ,
203                     const char* ToServiceParameterName ) {
204 //                    , const CORBA::Any aValue ) {
205            DateModification() ;
206            _Valid = false ;
207            return _Graph->AddLink( FromNodeName , FromServiceParameterName ,
208                                    ToNodeName , ToServiceParameterName ) ; } ;
209 //                                   , aValue ) ; } ;
210
211       bool RemoveLink( const char* FromNodeName ,
212                        const char* FromServiceParameterName ,
213                        const char* ToNodeName ,
214                        const char* ToServiceParameterName ) {
215            bool RetVal = _Graph->RemoveLink( FromNodeName ,
216                                              FromServiceParameterName , 
217                                              ToNodeName ,
218                                              ToServiceParameterName ) ;
219            if ( RetVal )
220              DateModification() ;
221            _Valid = false ;
222            return RetVal ; } ;
223
224       bool GetLink(const char* ToNodeName ,
225                    const char* ToServiceParameterName ,
226                    char** FromNodeName ,
227                    char** FromServiceParameterName ) {
228            return _Graph->GetLink( ToNodeName ,
229                                    ToServiceParameterName ,
230                                    FromNodeName ,
231                                    FromServiceParameterName ) ; } ;
232
233       bool AddLinkCoord( const char* FromNodeName ,
234                          const char* FromServiceParameterName ,
235                          const char* ToNodeName ,
236                          const char* ToServiceParameterName ,
237                          const int nXY ,
238                          const int* X ,
239                          const int* Y ) ;
240       bool AddLinkCoord( const char* FromNodeName ,
241                          const char* FromServiceParameterName ,
242                          const char* ToNodeName ,
243                          const char* ToServiceParameterName ,
244                          const int index ,
245                          const int X ,
246                          const int Y ) ;
247       bool ChangeLinkCoord( const char* FromNodeName ,
248                             const char* FromServiceParameterName ,
249                             const char* ToNodeName ,
250                             const char* ToServiceParameterName ,
251                             const int index ,
252                             const int X ,
253                             const int Y ) ;
254       bool RemoveLinkCoord( const char* FromNodeName ,
255                             const char* FromServiceParameterName ,
256                             const char* ToNodeName ,
257                             const char* ToServiceParameterName ,
258                             const int index ) ;
259       int GetLinkCoordSize( const char* FromNodeName ,
260                             const char* FromServiceParameterName ,
261                             const char* ToNodeName ,
262                             const char* ToServiceParameterName ) ;
263       bool GetLinkCoord( const char* FromNodeName ,
264                          const char* FromServiceParameterName ,
265                          const char* ToNodeName ,
266                          const char* ToServiceParameterName ,
267                          int *X , int *Y ) ;
268       bool GetLinkCoord( const char* FromNodeName ,
269                          const char* FromServiceParameterName ,
270                          const char* ToNodeName ,
271                          const char* ToServiceParameterName ,
272                          const int index , long &X , long &Y ) ;
273
274
275       bool IsValid(bool kLoopSwitch = true ) {
276            if ( !_Valid )
277              Valid( kLoopSwitch ) ;
278            return _Valid ; } ;
279       bool IsNotValid() const {
280            return !_Valid ; } ;
281       bool UnValid() ;
282
283       bool IsExecutable() {
284            if ( !_Valid )
285              Valid() ;
286            if ( _Valid ) {
287              if ( !_Executable )
288                Executable() ;
289            }
290            else
291              _Executable = false ;
292            return _Executable ; } ;
293       bool IsNotExecutable() const {
294            return !_Executable ; } ;
295
296       // iterate through ALL links (OutPort-InPort pairs) and check if their types are 
297       // compatible - IsCompatible(type1, type2).  
298       // Returns true if all are compatible.   
299       bool IsLinksCompatible();
300
301       // Returns true if an out-port of type "OutPortType" can be bound with 
302       // in-port of type "InPortType".  Called from IsLinksCompatible() and Link_Impl::IsValid().
303       bool IsCompatible( const char* OutPortType, const char* InPortType ) const;
304
305 //JR 30.03.2005      const CORBA::Any *GetInData( const char *ToNodeName ,
306       const CORBA::Any GetInData( const char *ToNodeName ,
307                                   const char *ToParameterName ) ;
308 //JR 30.03.2005      const CORBA::Any *GetOutData( const char *FromNodeName ,
309       const CORBA::Any GetOutData( const char *FromNodeName ,
310                                    const char *FromParameterName ) ;
311   } ;
312
313 };
314
315 ostream & operator << (ostream &,const GraphEditor::OutNode & G);
316 ostream & operator << (ostream &,const SUPERV::SDate &);
317
318 #endif
319
320
321