Salome HOME
The final values of InPorts of EndSwitchNodes in a loop may be wrong
[modules/superv.git] / src / GraphBase / DataFlowBase_LoadXml.cxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
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   : DataFlowBase_LoadXml.cxx
25 //  Module : SUPERV
26
27 using namespace std;
28 #include "DataFlowBase_XmlHandler.hxx"
29
30 //#include <qaccel.h>
31 #include <qxml.h>
32 #include <qmessagebox.h>
33
34 // Pour Jean
35 // Fonction Load qui utilise un Parser de fichier xml de Dataflow
36 // Utilise DataFlowEditor_XmlHandler.hxx et .cxx
37
38 //#include "SALOME_NamingService.hxx"
39
40 //#include <SALOMEconfig.h>
41 //#include CORBA_CLIENT_HEADER(SALOME_SuperVision)
42
43 #include "DataFlowBase_Graph.hxx"
44
45 bool GraphBase::Graph::LoadXml( CORBA::ORB_ptr _Orb ,
46                                 const char* myFileName ,
47                                 GraphBase::ListOfSGraphs & ListOfDataFlows )
48 {
49   char * FileName = new char[ strlen( myFileName ) + 5 ] ;
50   strcpy( FileName , myFileName ) ;
51   QString aqstrFileName(FileName) ;
52   QFile afile( aqstrFileName) ;
53
54   if ( !afile.exists() || !afile.open( IO_ReadOnly ) )  {
55     strcat( FileName , ".xml" ) ;
56     aqstrFileName = QString(FileName) ;
57     QFile afile( aqstrFileName ) ;
58     if ( !afile.exists() || !afile.open( IO_ReadOnly ) )  {
59       return false ;
60     }
61     afile.close() ;
62   }
63   else {
64     afile.close() ;
65   }
66
67   QString qstrFileName(FileName);
68   QFile file( qstrFileName);
69 //  GraphBase::XmlHandler::XmlHandler * myXmlHandler = new GraphBase::XmlHandler::XmlHandler( _Orb , true );
70   QXmlInputSource source( file );
71 //  QXmlSimpleReader reader;
72 //  reader.setContentHandler( myXmlHandler );
73 //  reader.setErrorHandler( myXmlHandler );
74
75   bool RetVal = true ;
76   int status = 1 ;
77   GraphBase::XmlHandler::XmlHandler * myXmlHandler = new GraphBase::XmlHandler::XmlHandler( _Orb , true );
78   QXmlSimpleReader reader;
79   reader.setContentHandler( myXmlHandler );
80   reader.setErrorHandler( myXmlHandler );
81   status = reader.parse( source ) ;
82   if ( status == 1 ) {
83     ListOfDataFlows = myXmlHandler->ListOfDataFlows() ;
84     cdebug << "Graph::LoadXml " << ListOfDataFlows.size() << " Graphs" << endl ;
85   }
86   else {
87     cdebug << "Graph::LoadXml Graph status " << status << endl ;
88     RetVal = false ;
89   }
90   delete myXmlHandler ;
91
92   file.close();
93 //  delete myXmlHandler ;
94   // Dataflow is now loaded.
95   return RetVal ;
96 }
97
98