Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/superv.git] / src / GraphBase / DataFlowBase_ComputingNode.hxx
index 91a0f2d979fdab8fb64b895bab5e0be44bdafaf8..981989bd9eb5f4a44068ae89f6969d7e6b750e8c 100644 (file)
@@ -1,63 +1,91 @@
 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
 //
-//  Copyright (C) 2003  CEA/DEN, EDF R&D
-//
-//
+//  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //  File   : DataFlowBase_ComputingNode.hxx
 //  Author : Jean Rahuel, CEA
 //  Module : SUPERV
-//  $Header:
 
-#ifndef _DATAFLOWBASE_NODE_HXX
-#define _DATAFLOWBASE_NODE_HXX
+#ifndef _DATAFLOWBASE_COMPUTINGNODE_HXX
+#define _DATAFLOWBASE_COMPUTINGNODE_HXX
+
+#include "SALOME_NamingService.hxx"
+
+#include "DataFlowBase_StreamNode.hxx"
 
-#include "DataFlowBase_PortsOfNode.hxx"
+class CNode_Impl ;
 
 namespace GraphBase {
 
+  class Graph ;
+
   class InLineNode ;
 
-  class ComputingNode : public PortsOfNode {
+  class LoopNode ;
+  class EndOfLoopNode ;
+  class EndOfSwitchNode ;
+
+  class ComputingNode : public StreamNode {
 
     private:
     
       CORBA::ORB_ptr         _ORB ;
       SALOME_NamingService * _NamingService ;
-      int                  * _Graph_prof_debug ;
-      ostream              * _Graph_fdebug ;
-      SUPERV::CNode_var      _Node ;
+//->StreamNode      int                  * _Graph_prof_debug ;
+//->StreamNode      ofstream             * _Graph_fdebug ;
+      SUPERV::CNode_var      _Node_var ;
+      CNode_Impl           * _Node_Impl ;
       void                 * _InNode ; // From GraphExecutor:: or GraphEditor::
       bool                   _ObjInterface ;
 
       pthread_t              _ThreadNo ;
 
-      char                 * _Name ;
-      SUPERV::KindOfNode     _Kind ;
+//->StreamNode      char                 * _Name ;
+//->StreamNode      SUPERV::KindOfNode     _Kind ;
       SUPERV::SDate          _FirstCreation ;
       SUPERV::SDate          _LastModification ;
       char                 * _EditorRelease ;
       char                 * _Author ;
       char                 * _Comment ;
 
-      bool                   _HeadNode ;
-      int                    _LevelNumber ;
-      int                    _SubGraphNumber ;
+//->StreamNode      bool                   _HeadNode ;
+//->StreamNode      int                    _LevelNumber ;
+//->StreamNode      int                    _SubGraphNumber ;
       bool                   _GeneratedName ;
 
+//->StreamNode      int                    _DataStreamInPortsNumber ;
+//->StreamNode      int                    _DataStreamOutPortsNumber ;
+
       int                    _ConnectedInPortsNumber ;
       int                    _DecrConnectedInPortsNumber ;
 
 // For generated NodeNames with ServiceName : number of Nodes using
 // the same ServiceName. It is not the same Service if it belongs to
 // a different Interface and/or a different Component ...
-      map< string , int > _MapOfServiceNames ;
+//->StreamNode      map< string , int > _MapOfServiceNames ;
 
 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
-      map< string , int >      _MapOfLinkedNodes ;
-      int                      _LinkedNodesSize ;
-      vector<ComputingNode * > _LinkedNodes ;
-      vector<int >             _LinkedInPortsNumber ;
+//->StreamNode      map< string , int >      _MapOfLinkedNodes ;
+//->StreamNode      int                      _LinkedNodesSize ;
+//->StreamNode      vector<ComputingNode * > _LinkedNodes ;
+//->StreamNode      vector<int >             _LinkedInPortsNumber ;
 
     protected:
 
@@ -70,8 +98,9 @@ namespace GraphBase {
       ComputingNode( CORBA::ORB_ptr ORB ,
                      SALOME_NamingService* ptrNamingService ,
                      const char * DataFlowName ,
-                     int * Graph_prof_debug = NULL ,
-                     ostream * Graph_fdebug = NULL ) ;
+                     const SUPERV::KindOfNode DataFlowkind ,
+                     int * Graph_prof_debug ,
+                     ofstream * Graph_fdebug ) ;
       ComputingNode( CORBA::ORB_ptr ORB ,
                      SALOME_NamingService* ptrNamingService ,
                      const SALOME_ModuleCatalog::Service& NodeService ,
@@ -86,15 +115,48 @@ namespace GraphBase {
                      const long   X ,
                      const long   Y ,
                      int * Graph_prof_debug = NULL ,
-                     ostream * Graph_fdebug = NULL ) ;
+                     ofstream * Graph_fdebug = NULL ) ;
       virtual ~ComputingNode() ;
 
       SALOME_NamingService * NamingService() const {
              return _NamingService ; } ;
 
-      SUPERV::CNode_var ObjRef() const { return _Node ; } ;
-      void SetObjRef(SUPERV::CNode_var aNode) {
-                     _Node = aNode ; } ;
+      SUPERV::CNode_var ObjRef() const {
+//                        char * _NodeName ;
+//                        cdebug << "ComputingNode::ObjRef() " << _Node << " " << Name()
+//                               << " " << endl ;
+//                        SUPERV::CNode_var _NodeObjRef = SUPERV::CNode::_narrow( _Node ) ;
+//                        if ( CORBA::is_nil( _NodeObjRef ) ) {
+//                          _NodeName = "NilRef" ;
+//                     }
+//                     else {
+//                          try {
+//                            _NodeName = _NodeObjRef->Name() ;
+//                       }
+//                          catch ( ... ) {
+//                            _NodeName = "Catch Error" ;
+//                       }
+//                     }
+//                        cdebug << _NodeName << " " << Name() << endl ;
+                         return _Node_var ; } ;
+      void SetObjRef( SUPERV::CNode_var aNode_var ) {
+//                        char * _NodeName ;
+//                        if ( CORBA::is_nil( _Node ) ) {
+//                          _NodeName = "NilRef" ;
+//                     }
+//                     else {
+//                          _NodeName = _Node->Name() ;
+//                     }
+//                        cdebug << "ComputingNode::SetObjRef( " << _Node << " "
+//                               << _NodeName << " ) " << Name() << " --> " ;
+                        _Node_var = aNode_var ;
+//                        cdebug << _Node << " " << _Node->Name() << " ) " << Name() << endl ;
+                        } ;
+
+      CNode_Impl * ObjImpl() const { return _Node_Impl ; } ;
+      void SetObjImpl( CNode_Impl * aNode_Impl ) {
+                       _Node_Impl = aNode_Impl ; } ;
+
       void InNode( void * anInNode ) {
 //           cdebug << "GraphBase::ComputingNode::InNode " << Name() << endl ;
            _InNode = anInNode ; } ;
@@ -107,21 +169,21 @@ namespace GraphBase {
       pthread_t ThreadNo() { return _ThreadNo ; } ;
       void ThreadNo( pthread_t aThread ) { _ThreadNo = aThread ; } ;
 
-      char * Name() const { return my_strdup( _Name ) ; } ;
-      const char *const * NamePtr() const { return &_Name ; } ;
-      SUPERV::KindOfNode Kind() const {
-            return _Kind; } ;
+//->StreamNode      char * Name() const { return my_strdup( _Name ) ; } ;
+//->StreamNode      const char *const * NamePtr() const { return &_Name ; } ;
 //      const SALOME_ModuleCatalog::Service * Service() const ;
       SUPERV::SDate FirstCreation() const ;
       SUPERV::SDate LastModification() const ;
-      char* Author() const { return my_strdup( _Author ) ; } ;
-      char* EditorRelease() const { return my_strdup( _EditorRelease ) ; } ;
-      char * Comment() const { return my_strdup( _Comment ) ; } ;
+//JR 17.02.2005 Memory Leak      char* Author() const { return my_strdup( _Author ) ; } ;
+      char* Author() const { return _Author ; } ;
+//JR 17.02.2005 Memory Leak      char* EditorRelease() const { return my_strdup( _EditorRelease ) ; } ;
+      char* EditorRelease() const { return _EditorRelease ; } ;
+//JR 17.02.2005 Memory Leak      char * Comment() const { return my_strdup( _Comment ) ; } ;
+      char * Comment() const { return _Comment ; } ;
       int XCoordinate() const { return _X ; } ;
       int YCoordinate() const { return _Y ; } ;
 
-      bool Name( const char * aName ) ;
-      bool Kind( SUPERV::KindOfNode aKind) ;
+//->StreamNode      bool Name( const char * aName ) ;
 //      void Service( const SALOME_ModuleCatalog::Service aService ) ;
       void FirstCreation( const SUPERV::SDate aFirstCreation ) ;
       void LastModification( const SUPERV::SDate aLastModification ) ;
@@ -135,67 +197,77 @@ namespace GraphBase {
                      const char * ServiceParameterName ,
                      char ** aNode , char ** aPort ) ;
 
-      bool IsLinked(const char * ToServiceParameterName ) ;
+      bool IsLinked(const char * ToServiceParameterName, bool isInput ) ; // mkr : PAL8060
       bool HasInput(const char * ToServiceParameterName ) ;
 
       GraphBase::SNode * GetInfo() ;
 
-      const bool IsComputingNode() const {
-            return (_Kind == SUPERV::ComputingNode ) ; } ;
-      const bool IsFactoryNode() const {
-            return (_Kind == SUPERV::FactoryNode ) ; } ;
-      const bool IsOneOfGOTONodes() const {
-            return (_Kind == SUPERV::LoopNode ||
-                    _Kind == SUPERV::EndLoopNode ||
-                    _Kind == SUPERV::SwitchNode ||
-                    _Kind == SUPERV::EndSwitchNode ||
-                    _Kind == SUPERV::GOTONode ) ; } ;
-      const bool IsOneOfInLineNodes() const {
-            return (_Kind == SUPERV::InLineNode || IsOneOfGOTONodes() ) ; } ;
-      const bool IsInLineNode() const {
-            return (_Kind == SUPERV::InLineNode ) ; } ;
-      const bool IsDataFlowNode() const {
-            return (_Kind == SUPERV::DataFlowNode ) ; } ;
-      const bool IsLoopNode() const {
-            return (_Kind == SUPERV::LoopNode ) ; } ;
-      const bool IsEndLoopNode() const {
-            return (_Kind == SUPERV::EndLoopNode ) ; } ;
-      const bool IsSwitchNode() const {
-            return (_Kind == SUPERV::SwitchNode ) ; } ;
-      const bool IsEndSwitchNode() const {
-            return (_Kind == SUPERV::EndSwitchNode ) ; } ;
-      const bool IsGOTONode() const {
-            return (_Kind == SUPERV::GOTONode ) ; } ;
-      void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
-      const bool IsHeadNode() const { return _HeadNode ; } ;
+//      void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
+//      const bool IsHeadNode() const { return _HeadNode ; } ;
 
       bool RemovePorts( const char* aNodeName ) ;
 
+      void SetMacroPorts( GraphBase::Graph * aGraph ) ;
+      void UpdateMacroPorts( GraphBase::Graph * aGraph ) ;
+      void SetMacroDatas( GraphBase::Graph * aGraph , GraphBase::Graph * aGraphOfMacroGraph ) ;
+
+      void DelInPort( const char * InputParameterName ) ;
+      void DelOutPort( const char * OutputParameterName ) ;
+
       InPort * AddInPort( const char * InputParameterName ,
-                          const char * InputParameterType ) ;
+                          const char * InputParameterType ,
+                          const SUPERV::KindOfPort aKindOfPort ,
+                          int index = -1 ) ;
       OutPort * AddOutPort( const char * OutputParameterName ,
-                            const char * OutputParameterType ) ;
-
-      void AddLink( ComputingNode * aNode ) ;
-      void RemoveLink( ComputingNode * aNode ) ;
-      void ReNameLink( const char* OldNodeName ,
-                       const char* NewNodeName ) ;
-
-      int GetServiceNameNumber( const char * name ) {
-          int num = _MapOfServiceNames[ name ] ;
-          if ( num == 0 ) {
-            _MapOfServiceNames[ name ] = 1 ;
-          }
-          else {
-            _MapOfServiceNames[ name ] = num + 1 ;
-         }
-          return _MapOfServiceNames[ name ] ; } ;
+                            const char * OutputParameterType ,
+                            const SUPERV::KindOfPort aKindOfPort ,
+                            int index = -1 ) ;
+
+      void DelInDataStreamPort( const char * InputParameterName ) ;
+      void DelOutDataStreamPort( const char * OutputParameterName ) ;
+
+      InDataStreamPort * AddInDataStreamPort( const char * InputParameterName ,
+                                              const char * InputParameterType ,
+                                              const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
+                                              const SUPERV::KindOfPort aKindOfPort ,
+                                              int index = -1 ) ;
+      OutDataStreamPort * AddOutDataStreamPort( const char * OutputParameterName ,
+                                                const char * OutputParameterType ,
+                                                const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
+                                                const SUPERV::KindOfPort aKindOfPort ,
+                                                int index = -1 ) ;
+
+//      ComputingNode * LinkedNodes( int i ) const { return (GraphBase::ComputingNode *) GraphBase::StreamNode::LinkedNodes( i ) ; } ;
+
+      void AddLinkedNode( GraphBase::ComputingNode * ToNode ) {
+           GraphBase::StreamNode::AddLinkedNode( ToNode ) ;
+           cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
+                  << ") ConnectedInPortsNumber " << ToNode->ConnectedInPortsNumber()
+                  << " + 1 Service " << ServiceName() << endl ;
+           ToNode->IncrConnectedInPortsNumber() ; } ;
+
+      bool RemoveLinkedNode( GraphBase::ComputingNode * ToNode ,
+                             bool DoLinkedFromNode = true ) {
+           bool RetVal = GraphBase::StreamNode::RemoveLinkedNode( ToNode , DoLinkedFromNode ) ;
+           if ( RetVal ) {
+             cdebug << "ComputingNode::RemoveLinkedNode to " << ToNode->Name() << " from "
+                    << Name() << " ConnectedInPortsNumber "
+                    << ToNode->ConnectedInPortsNumber() - 1 << endl ;
+             ToNode->DecrConnectedInPortsNumber() ;
+          }
+           return RetVal ; } ;
+
+      void ReNameLinkedNode( const char* OldNodeName ,
+                             const char* NewNodeName ) {
+           GraphBase::StreamNode::ReNameLinkedNode( OldNodeName , NewNodeName ) ; } ;
 
       void IncrConnectedInPortsNumber() {
-           cdebug << "IncrConnectedInPortsNumber " << Name() << " -> "
+           cdebug << "ComputingNode::IncrConnectedInPortsNumber " << Name() << " -> "
                   << _ConnectedInPortsNumber+1 << endl ;
            _ConnectedInPortsNumber++ ; } ;
       void DecrConnectedInPortsNumber() {
+           cdebug << "ComputingNode::DecrConnectedInPortsNumber " << Name() << " -> "
+                  << _ConnectedInPortsNumber-1 << endl ;
            _ConnectedInPortsNumber-- ; } ;
       int ConnectedInPortsNumber() const {
           return _ConnectedInPortsNumber ; } ;
@@ -214,36 +286,16 @@ namespace GraphBase {
           }
            return false ; } ;
 
-      int GetLinkedNodeIndex( const char * name ) {
-          int index = _MapOfLinkedNodes[ name ] -1 ;
-          if ( index >= 0 ) {
-            cdebug << "GetLinkedNodeIndex of " << name
-                   << " in _MapOfLinkedNodes : "
-                   << index << " Node " << hex << (void *) _LinkedNodes[ index ]
-                   << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
-                   << endl ;
-         }
-          return index ; } ;
-      void SetLinkedNodeIndex( const char * name , const int index ) {
-          _MapOfLinkedNodes[ name ] = index +1 ;
-          cdebug << "SetLinkedNodeIndex of " << name << " in _MapOfLinkedNodes : "
-                 << index << " Node " << hex << (void *) _LinkedNodes[ index ]
-                 << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
-                 << " _MapOfLinkedNodes " << _MapOfLinkedNodes[ name ] - 1
-                 << endl ;
-          } ;
-      void DelLinkedNodeIndex( const char * name ) {
-           _MapOfLinkedNodes.erase( name ) ; } ;
-      int LinkedNodesSize() const { return _LinkedNodesSize ; } ;
-      ComputingNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
-      const int LinkedInPortsNumber( int i ) const { return _LinkedInPortsNumber[ i ] ; } ;
-
-      int Level() { return _LevelNumber ; } ;
-      void Level( int LevelNumber ) {
-           _LevelNumber = LevelNumber ; } ;
-      int SubGraph() { return _SubGraphNumber ; } ;
-      void SubGraph( int SubGraphNumber ) {
-           _SubGraphNumber = SubGraphNumber ; } ;
+      bool CheckLoop( GraphBase::LoopNode * aLoopNode ,
+                      GraphBase::EndOfLoopNode * anEndLoopNode ,
+                      string & anErrorMessage ) const ;
+      bool CheckEndLoop( GraphBase::LoopNode * aLoopNode ,
+                         GraphBase::EndOfLoopNode * anEndLoopNode ,
+                         string & anErrorMessage ) const ;
+      bool InitBranchOfSwitchDone( bool AllInit , GraphBase::EndOfSwitchNode * anEndSwitchNode ,
+                                   string & anErrorMessage ) ;
+      bool CheckSwitch( GraphBase::EndOfSwitchNode * anEndSwitchNode ,
+                        string & anErrorMessage ) ;
 
 //      const GraphBase::ListOfParameters * GetListOfParameters() const ;
 
@@ -281,7 +333,7 @@ namespace GraphBase {
                                const GraphBase::ListOfPythonFunctions PythonFunctions ,
                                int X , int Y ) const ;
 
-      void NodeInfo(ostrstream & s) const ;
+      void NodeInfo(ostream & s) const ;
 
       void ListLinks(ostream &f ) const ;