Salome HOME
cf560f07972fb939086d77e5b4b460f76cf77926
[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       bool SavePY(ostream &f , bool importSuperV ) ;
78
79       void DateModification() ;
80
81       // asv 20.09.04 added from GraphExecutor::FiniteStateMachine class (removed from there)
82 //      static map< string , GraphBase::Graph * > _MapOfGraphs ;
83 //      static map< string , int >                _MapOfGraphNames ;
84     
85 //      GraphBase::Graph * MapGraph( const char * aGraphName ) ;
86 //      bool MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) ;
87 //      void EraseGraph( const char * aGraphName ) ;
88 //      bool GraphName( const char * aGraphName ) ;
89 //      string GraphInstanceName( const char * aGraphName ) ;
90       // end added from FiniteStateMachine
91
92
93     public:
94
95       OutNode();
96       OutNode( CORBA::ORB_ptr ORB,
97                SALOME_NamingService* ptrNamingService ,
98                const char *DataFlowName ,
99                const char * DebugFileName ,
100                const SUPERV::KindOfNode aKindOfNode );
101       OutNode( CORBA::ORB_ptr ORB,
102                SALOME_NamingService* ptrNamingService ,
103                const SALOME_ModuleCatalog::Service& DataFlowService ,
104                const char *DataFlowComponentName ,
105                const char *DataFlowInterfaceName ,
106                const char *DataFlowName ,
107                const SUPERV::KindOfNode DataFlowkind ,
108                const SUPERV::SDate DataFlowFirstCreation ,
109                const SUPERV::SDate DataFlowLastModification ,
110                const char * DataFlowEditorRelease ,
111                const char * DataFlowAuthor ,
112                const char * DataFlowComputer ,
113                const char * DataFlowComment ,
114                const char * DebugFileName ) ;
115       virtual ~OutNode();
116
117       bool Name( const char * aName ) ;
118
119       void Set_prof_debug( CORBA::ORB_ptr ORB , const char * DebugFileName ) ;
120       GraphBase::StreamGraph * StreamGraph() {
121                                return _StreamGraph ; } ;
122       GraphBase::StreamGraph * StreamGraph() const {
123                                return _StreamGraph ; } ;
124       GraphBase::Graph * Graph() {
125                          return _Graph ; } ;
126       const GraphBase::Graph * Graph() const {
127                                return _Graph ; } ;
128
129       bool LoadDataFlow( const GraphBase::SGraph *aDataFlow ) ;
130       bool LoadXml( const char* myFileName , GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
131 //      bool LoadXml( const char* myFileName ) ;
132       bool LoadInfo( const GraphBase::SNode &aDataFlowInfo ) ;
133
134       bool SaveXml(const char* myFileName ) ;
135
136       bool SavePy(const char* myFileName ) ;
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 //PAL9048 JR Debug : a node may not have the same name as the graph
174            if ( strcmp( Graph()->Name() , NewNodeName ) ) {
175              DateModification() ;
176              _Valid = false ;
177              return _Graph->ReNameNode( OldNodeName , NewNodeName ) ;
178            }
179            cdebug << "Editor::OutNode::ReNameNode ERROR "  << NewNodeName << " already exists"
180                   << endl ;
181            return false ; } ;
182
183       void Coordinates( const int X , const int Y ) {
184            return _Graph->Coordinates( X , Y ) ; } ;
185       const int XCoordinate() {
186            return _Graph->XCoordinate() ; } ;
187       const int YCoordinate() {
188            return _Graph->YCoordinate() ; } ;
189       void Coordinates( const char* NodeName , const int X , const int Y ) ;
190       const int XCoordinate( const char* NodeName ) ;
191       const int YCoordinate( const char* NodeName ) ;
192
193       const GraphBase::InPort *GetInPort( const char * InPortName ) {
194             return _Graph->GetInPort( InPortName ) ; } ;
195       const GraphBase::OutPort *GetOutPort( const char * OutPortName ) {
196             return _Graph->GetOutPort( OutPortName ) ; } ;
197       GraphBase::InPort *GetChangeInPort( const char * InPortName ) {
198             return _Graph->GetChangeInPort( InPortName ) ; } ;
199       GraphBase::OutPort *GetChangeOutPort( const char * OutPortName ) {
200             return _Graph->GetChangeOutPort( OutPortName ) ; } ;
201
202       bool HasInput(const char * ToServiceParameterName ) {
203            return _Graph->HasInput( ToServiceParameterName ) ;
204          }
205
206       bool AddLink( const char* FromNodeName ,
207                     const char* FromServiceParameterName ,
208                     const char* ToNodeName ,
209                     const char* ToServiceParameterName ) {
210 //                    , const CORBA::Any aValue ) {
211            DateModification() ;
212            _Valid = false ;
213            return _Graph->AddLink( FromNodeName , FromServiceParameterName ,
214                                    ToNodeName , ToServiceParameterName ) ; } ;
215 //                                   , aValue ) ; } ;
216
217       bool RemoveLink( const char* FromNodeName ,
218                        const char* FromServiceParameterName ,
219                        const char* ToNodeName ,
220                        const char* ToServiceParameterName ) {
221            bool RetVal = _Graph->RemoveLink( FromNodeName ,
222                                              FromServiceParameterName , 
223                                              ToNodeName ,
224                                              ToServiceParameterName ) ;
225            if ( RetVal )
226              DateModification() ;
227            _Valid = false ;
228            return RetVal ; } ;
229
230       bool GetLink(const char* ToNodeName ,
231                    const char* ToServiceParameterName ,
232                    char** FromNodeName ,
233                    char** FromServiceParameterName ) {
234            return _Graph->GetLink( ToNodeName ,
235                                    ToServiceParameterName ,
236                                    FromNodeName ,
237                                    FromServiceParameterName ) ; } ;
238
239       bool AddLinkCoord( const char* FromNodeName ,
240                          const char* FromServiceParameterName ,
241                          const char* ToNodeName ,
242                          const char* ToServiceParameterName ,
243                          const int nXY ,
244                          const int* X ,
245                          const int* Y ) ;
246       bool AddLinkCoord( const char* FromNodeName ,
247                          const char* FromServiceParameterName ,
248                          const char* ToNodeName ,
249                          const char* ToServiceParameterName ,
250                          const int index ,
251                          const int X ,
252                          const int Y ) ;
253       bool ChangeLinkCoord( const char* FromNodeName ,
254                             const char* FromServiceParameterName ,
255                             const char* ToNodeName ,
256                             const char* ToServiceParameterName ,
257                             const int index ,
258                             const int X ,
259                             const int Y ) ;
260       bool RemoveLinkCoord( const char* FromNodeName ,
261                             const char* FromServiceParameterName ,
262                             const char* ToNodeName ,
263                             const char* ToServiceParameterName ,
264                             const int index ) ;
265       int GetLinkCoordSize( const char* FromNodeName ,
266                             const char* FromServiceParameterName ,
267                             const char* ToNodeName ,
268                             const char* ToServiceParameterName ) ;
269       bool GetLinkCoord( const char* FromNodeName ,
270                          const char* FromServiceParameterName ,
271                          const char* ToNodeName ,
272                          const char* ToServiceParameterName ,
273                          int *X , int *Y ) ;
274       bool GetLinkCoord( const char* FromNodeName ,
275                          const char* FromServiceParameterName ,
276                          const char* ToNodeName ,
277                          const char* ToServiceParameterName ,
278                          const int index , long &X , long &Y ) ;
279
280
281       bool IsValid(bool kLoopSwitch = true ) {
282            if ( !_Valid )
283              Valid( kLoopSwitch ) ;
284            return _Valid ; } ;
285       bool IsNotValid() const {
286            return !_Valid ; } ;
287       bool UnValid() ;
288
289       bool IsExecutable() {
290            if ( !_Valid )
291              Valid() ;
292            if ( _Valid ) {
293              if ( !_Executable )
294                Executable() ;
295            }
296            else
297              _Executable = false ;
298            return _Executable ; } ;
299       bool IsNotExecutable() const {
300            return !_Executable ; } ;
301
302       // iterate through ALL links (OutPort-InPort pairs) and check if their types are 
303       // compatible - IsCompatible(type1, type2).  
304       // Returns true if all are compatible.   
305       bool IsLinksCompatible();
306
307       // Returns true if an out-port of type "OutPortType" can be bound with 
308       // in-port of type "InPortType".  Called from IsLinksCompatible() and Link_Impl::IsValid().
309       bool IsCompatible( const char* OutPortType, const char* InPortType ) const;
310
311 //JR 30.03.2005      const CORBA::Any *GetInData( const char *ToNodeName ,
312       const CORBA::Any GetInData( const char *ToNodeName ,
313                                   const char *ToParameterName ) ;
314 //JR 30.03.2005      const CORBA::Any *GetOutData( const char *FromNodeName ,
315       const CORBA::Any GetOutData( const char *FromNodeName ,
316                                    const char *FromParameterName ) ;
317   } ;
318
319 };
320
321 ostream & operator << (ostream &,const GraphEditor::OutNode & G);
322 ostream & operator << (ostream &,const SUPERV::SDate &);
323
324 #endif
325
326
327