Salome HOME
Traces
[modules/superv.git] / src / GraphEditor / DataFlowEditor_OutNode.hxx
index 713834b418ae45a1306830c19e5ac180508d2b0c..cf560f07972fb939086d77e5b4b460f76cf77926 100644 (file)
@@ -1,16 +1,47 @@
+//  SUPERV GraphEditor : contains classes that permit edition of graphs
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : DataFlowEditor_OutNode.hxx
+//  Module : SUPERV
+
 #ifndef _DATAFLOWEDITOR_OUTNODE_HXX
 #define _DATAFLOWEDITOR_OUTNODE_HXX
 
-#include "DataFlowBase_Graph.hxx"
+#include "DataFlowBase_StreamGraph.hxx"
 
 #include "DataFlowEditor_InNode.hxx"
 
 namespace GraphEditor {
 
-  class OutNode : public GraphBase::Graph {
+  class OutNode : public GraphBase::Base {
     
     private :
 
+      GraphBase::StreamGraph * _StreamGraph ;
+      GraphBase::Graph       * _Graph ;
+
+      int  _Graph_prof_debug ;
+
       bool _Imported ;
 
       bool _Valid ;
@@ -19,39 +50,54 @@ namespace GraphEditor {
 
       CORBA::ORB_ptr _Orb;
 
-      bool Valid() ;
+      bool Valid(bool kLoopSwitch = true ) ;
       bool Executable() ;
 
       bool LoadNodes( map< string , int > & aMapOfNodes ,
-                      const GraphBase::ListOfNodes &aNodes ) ;
+                      const GraphBase::ListOfSNodes &aNodes ) ;
       bool LoadLinks( map< string , int > & aMapOfNodes ,
-                      const GraphBase::ListOfLinks &aLinks ) ;
+                      const GraphBase::ListOfSLinks &aLinks ) ;
       bool LoadDatas( map< string , int > & aMapOfNodes ,
-                      const GraphBase::ListOfLinks &aDatas ) ;
+                      const GraphBase::ListOfSLinks &aDatas ) ;
 
 //      bool GraphEditor::OutNode::LinkSaveXML( ostream &f , char *Tabs ,
       bool GraphEditor::OutNode::LinkSaveXML( QDomDocument & Graph , QDomElement & link ,
                                               GraphBase::SLink aLink ,
                                               bool wdata ) const ;
 //      bool SaveXML(ostream &f ) ;QDomDocument & Graph 
-      bool SaveXML(QDomDocument & Graph ) ;
+      bool SaveXML( ostream & f , QDomDocument & Graph ,
+                    bool aSuperGraph , QDomElement & supergraph ) ;
 
       bool GraphEditor::OutNode::LinkSavePY( ostream &f ,
                                              const char *aGraphName ,
                                              GraphBase::SLink aLink ,
-                                             bool intervar ,
+                                             bool fromparam ,
+                                             bool toparam ,
                                              bool wdata ) const;
-      bool SavePY(ostream &f ) ;
+      bool SavePY(ostream &f , bool importSuperV ) ;
 
       void DateModification() ;
 
+      // asv 20.09.04 added from GraphExecutor::FiniteStateMachine class (removed from there)
+//      static map< string , GraphBase::Graph * > _MapOfGraphs ;
+//      static map< string , int >                _MapOfGraphNames ;
+    
+//      GraphBase::Graph * MapGraph( const char * aGraphName ) ;
+//      bool MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) ;
+//      void EraseGraph( const char * aGraphName ) ;
+//      bool GraphName( const char * aGraphName ) ;
+//      string GraphInstanceName( const char * aGraphName ) ;
+      // end added from FiniteStateMachine
+
+
     public:
 
       OutNode();
       OutNode( CORBA::ORB_ptr ORB,
                SALOME_NamingService* ptrNamingService ,
                const char *DataFlowName ,
-               const char * DebugFileName );
+               const char * DebugFileName ,
+               const SUPERV::KindOfNode aKindOfNode );
       OutNode( CORBA::ORB_ptr ORB,
                SALOME_NamingService* ptrNamingService ,
                const SALOME_ModuleCatalog::Service& DataFlowService ,
@@ -68,11 +114,21 @@ namespace GraphEditor {
                const char * DebugFileName ) ;
       virtual ~OutNode();
 
-//      SALOME_NamingService* NamingService() const {
-//            return _theNamingService ; } ;
+      bool Name( const char * aName ) ;
+
+      void Set_prof_debug( CORBA::ORB_ptr ORB , const char * DebugFileName ) ;
+      GraphBase::StreamGraph * StreamGraph() {
+                               return _StreamGraph ; } ;
+      GraphBase::StreamGraph * StreamGraph() const {
+                               return _StreamGraph ; } ;
+      GraphBase::Graph * Graph() {
+                         return _Graph ; } ;
+      const GraphBase::Graph * Graph() const {
+                               return _Graph ; } ;
 
       bool LoadDataFlow( const GraphBase::SGraph *aDataFlow ) ;
-      bool LoadXml( const char* myFileName ) ;
+      bool LoadXml( const char* myFileName , GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
+//      bool LoadXml( const char* myFileName ) ;
       bool LoadInfo( const GraphBase::SNode &aDataFlowInfo ) ;
 
       bool SaveXml(const char* myFileName ) ;
@@ -80,7 +136,7 @@ namespace GraphEditor {
       bool SavePy(const char* myFileName ) ;
 
 // get all DataFlow informations (for a .XML file) :
-      GraphBase::SGraph * GetDataFlow() ;
+      GraphBase::ListOfSGraphs * GetDataFlows( GraphBase::ListOfSGraphs * aListOfDataFlows ) ;
 
 //    void DateModification() ;
 
@@ -101,61 +157,71 @@ namespace GraphEditor {
                         const int NodeX ,
                         const int NodeY ) ;
       GraphEditor::InNode * GetNode( const char* NodeName ) {
-               return (GraphEditor::InNode * ) (GraphBase::Graph::GetGraphNode( NodeName )->GetInNode()) ; } ;
+               const GraphBase::Graph::ComputingNode * aNode = _Graph->GetGraphNode( NodeName ) ;
+               if ( aNode ) {
+                 return (GraphEditor::InNode * ) (aNode->GetInNode()) ;
+               }
+               else {
+                 return (GraphEditor::InNode * ) NULL ;
+               } } ;
       bool RemoveNode( const char* NodeName ) {
            DateModification() ;
            _Valid = false ;
-           return GraphBase::Graph::RemoveNode( NodeName ) ; } ;
+           return _Graph->RemoveNode( NodeName ) ; } ;
       bool ReNameNode( const char* OldNodeName ,
                        const char* NewNodeName ) {
-           DateModification() ;
-           _Valid = false ;
-           return GraphBase::Graph::ReNameNode( OldNodeName , NewNodeName ) ; } ;
+//PAL9048 JR Debug : a node may not have the same name as the graph
+           if ( strcmp( Graph()->Name() , NewNodeName ) ) {
+             DateModification() ;
+             _Valid = false ;
+             return _Graph->ReNameNode( OldNodeName , NewNodeName ) ;
+          }
+           cdebug << "Editor::OutNode::ReNameNode ERROR "  << NewNodeName << " already exists"
+                  << endl ;
+           return false ; } ;
 
       void Coordinates( const int X , const int Y ) {
-           return GraphBase::Graph::Coordinates( X , Y ) ; } ;
+           return _Graph->Coordinates( X , Y ) ; } ;
       const int XCoordinate() {
-           return GraphBase::Graph::XCoordinate() ; } ;
+           return _Graph->XCoordinate() ; } ;
       const int YCoordinate() {
-           return GraphBase::Graph::YCoordinate() ; } ;
+           return _Graph->YCoordinate() ; } ;
       void Coordinates( const char* NodeName , const int X , const int Y ) ;
       const int XCoordinate( const char* NodeName ) ;
       const int YCoordinate( const char* NodeName ) ;
 
-      const GraphBase::InPort *GetInPort( const char *name ) {
-            return GraphBase::PortsOfNode::GetInPort( name ) ; } ;
-      const GraphBase::OutPort *GetOutPort( const char *name ) {
-            return GraphBase::PortsOfNode::GetOutPort( name ) ; } ;
-      GraphBase::InPort *GetChangeInPort( const char *name ) {
-            return GraphBase::PortsOfNode::GetChangeInPort( name ) ; } ;
-      GraphBase::OutPort *GetChangeOutPort( const char *name ) {
-            return GraphBase::PortsOfNode::GetChangeOutPort( name ) ; } ;
+      const GraphBase::InPort *GetInPort( const char * InPortName ) {
+            return _Graph->GetInPort( InPortName ) ; } ;
+      const GraphBase::OutPort *GetOutPort( const char * OutPortName ) {
+            return _Graph->GetOutPort( OutPortName ) ; } ;
+      GraphBase::InPort *GetChangeInPort( const char * InPortName ) {
+            return _Graph->GetChangeInPort( InPortName ) ; } ;
+      GraphBase::OutPort *GetChangeOutPort( const char * OutPortName ) {
+            return _Graph->GetChangeOutPort( OutPortName ) ; } ;
 
       bool HasInput(const char * ToServiceParameterName ) {
-           return GraphBase::ComputingNode::HasInput( ToServiceParameterName ) ;
+           return _Graph->HasInput( ToServiceParameterName ) ;
         }
 
       bool AddLink( const char* FromNodeName ,
                     const char* FromServiceParameterName ,
                    const char* ToNodeName ,
-                    const char* ToServiceParameterName ,
-                    const CORBA::Any aValue ) {
+                    const char* ToServiceParameterName ) {
+//                    , const CORBA::Any aValue ) {
            DateModification() ;
            _Valid = false ;
-           return GraphBase::Graph::AddLink(
-                                    FromNodeName , FromServiceParameterName ,
-                                    ToNodeName , ToServiceParameterName ,
-                                    aValue ) ; } ;
+           return _Graph->AddLink( FromNodeName , FromServiceParameterName ,
+                                   ToNodeName , ToServiceParameterName ) ; } ;
+//                                   , aValue ) ; } ;
 
       bool RemoveLink( const char* FromNodeName ,
                        const char* FromServiceParameterName ,
                        const char* ToNodeName ,
                        const char* ToServiceParameterName ) {
-           bool RetVal = GraphBase::Graph::RemoveLink(
-                                                 FromNodeName ,
-                                                 FromServiceParameterName , 
-                                                 ToNodeName ,
-                                                 ToServiceParameterName ) ;
+           bool RetVal = _Graph->RemoveLink( FromNodeName ,
+                                             FromServiceParameterName , 
+                                             ToNodeName ,
+                                             ToServiceParameterName ) ;
            if ( RetVal )
              DateModification() ;
            _Valid = false ;
@@ -165,10 +231,10 @@ namespace GraphEditor {
                    const char* ToServiceParameterName ,
                    char** FromNodeName ,
                    char** FromServiceParameterName ) {
-           return GraphBase::Graph::GetLink( ToNodeName ,
-                                             ToServiceParameterName ,
-                                             FromNodeName ,
-                                            FromServiceParameterName ) ; } ;
+           return _Graph->GetLink( ToNodeName ,
+                                   ToServiceParameterName ,
+                                   FromNodeName ,
+                                  FromServiceParameterName ) ; } ;
 
       bool AddLinkCoord( const char* FromNodeName ,
                          const char* FromServiceParameterName ,
@@ -211,21 +277,14 @@ namespace GraphEditor {
                          const char* ToServiceParameterName ,
                          const int index , long &X , long &Y ) ;
 
-      bool AddInputData( const char* ToNodeName1 ,
-                         const char* ToParameterName1 ,
-                         const char* ToNodeName2 ,
-                         const char* ToParameterName2 ) ;
 
-      bool IsValid() {
+      bool IsValid(bool kLoopSwitch = true ) {
            if ( !_Valid )
-             Valid() ;
+             Valid( kLoopSwitch ) ;
            return _Valid ; } ;
       bool IsNotValid() const {
            return !_Valid ; } ;
-      bool UnValid() {
-           bool RetVal = _Valid ;
-           _Valid = false ;
-           return RetVal ; } ;
+      bool UnValid() ;
 
       bool IsExecutable() {
            if ( !_Valid )
@@ -240,15 +299,26 @@ namespace GraphEditor {
       bool IsNotExecutable() const {
            return !_Executable ; } ;
 
-      const CORBA::Any *GetInData( const char *ToNodeName ,
-                                   const char *ToParameterName ) ;
-      const CORBA::Any *GetOutData( const char *FromNodeName ,
-                                    const char *FromParameterName ) ;
+      // iterate through ALL links (OutPort-InPort pairs) and check if their types are 
+      // compatible - IsCompatible(type1, type2).  
+      // Returns true if all are compatible.   
+      bool IsLinksCompatible();
+
+      // Returns true if an out-port of type "OutPortType" can be bound with 
+      // in-port of type "InPortType".  Called from IsLinksCompatible() and Link_Impl::IsValid().
+      bool IsCompatible( const char* OutPortType, const char* InPortType ) const;
+
+//JR 30.03.2005      const CORBA::Any *GetInData( const char *ToNodeName ,
+      const CORBA::Any GetInData( const char *ToNodeName ,
+                                  const char *ToParameterName ) ;
+//JR 30.03.2005      const CORBA::Any *GetOutData( const char *FromNodeName ,
+      const CORBA::Any GetOutData( const char *FromNodeName ,
+                                   const char *FromParameterName ) ;
   } ;
 
 };
 
-ostrstream & operator << (ostrstream &,const GraphEditor::OutNode & G);
+ostream & operator << (ostream &,const GraphEditor::OutNode & G);
 ostream & operator << (ostream &,const SUPERV::SDate &);
 
 #endif