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