Salome HOME
6c563e8d3425f3bd2fd60fe6a96e72a1c2e46297
[modules/paravis.git] / src / PVGUI / PVGUI_DataModel.cxx
1 // Copyright (C) 2010-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Adrien Bruneton (CEA)
20 //
21
22 //Local includes
23 #include "PVGUI_DataModel.h"
24 #include "PVGUI_Module.h"
25
26 // GUI includes
27 #include <LightApp_Study.h>
28 #include <CAM_DataObject.h>
29
30 // Qt includes
31 #include <QFile>
32 #include <QTextStream>
33
34 PVGUI_DataModel::PVGUI_DataModel( PVGUI_Module* theModule ):
35   LightApp_DataModel(theModule)
36 {}
37
38 PVGUI_DataModel::~PVGUI_DataModel()
39 {}
40
41 bool PVGUI_DataModel::dumpPython( const QString& path, CAM_Study* std,
42             bool isMultiFile, QStringList& listOfFiles)
43 {
44
45   LightApp_Study* study = dynamic_cast<LightApp_Study*>( std );
46   if(!study)
47     return false;
48
49   std::string aTmpDir = study->GetTmpDir( path.toLatin1().constData(), isMultiFile );
50   std::string aFile = aTmpDir + "paravis_dump.tmp";
51
52   listOfFiles.append(aTmpDir.c_str());
53   listOfFiles.append("paravis_dump.tmp");
54
55   QFile file(aFile.c_str());
56   if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
57     return false;
58
59   PVGUI_Module * mod = (PVGUI_Module *) getModule();
60   QString trace(mod->getTraceString());
61
62   if (isMultiFile)
63     {
64       QStringList abuffer;
65       abuffer.push_back(QString("def RebuildData( theStudy ):"));
66       QStringList lst(trace.split("\n"));
67       foreach(QString elem, lst)
68         {
69           QString s = "  " + elem;
70           abuffer.push_back(s);
71         }
72       abuffer.push_back(QString("  pass"));
73       trace = abuffer.join("\n");
74     }
75   QTextStream out(&file);
76   out << trace.toStdString().c_str() << "\n";
77   out.flush();
78   file.close();
79
80   return true;
81 }
82
83 /*-----------------------------------------------------------------------------------------*/
84 bool PVGUI_DataModel::open( const QString& theName, CAM_Study* theStudy, QStringList theList) {
85   bool res = LightApp_DataModel::open(theName, theStudy, theList);
86   publishComponent(theStudy);
87   return res;
88 }
89
90 /*-----------------------------------------------------------------------------------------*/
91 bool PVGUI_DataModel::create( CAM_Study* theStudy) {
92   bool res = LightApp_DataModel::create(theStudy);
93   publishComponent(theStudy);
94   return res;
95 }
96 /*-----------------------------------------------------------------------------------------*/
97 void PVGUI_DataModel::publishComponent( CAM_Study* theStudy ) {
98   LightApp_Study* study = dynamic_cast<LightApp_Study*>( theStudy );
99   CAM_ModuleObject *aModelRoot = dynamic_cast<CAM_ModuleObject*>( root());
100   if( study && aModelRoot == NULL ) {
101     aModelRoot = createModuleObject( theStudy->root() );
102     aModelRoot->setDataModel( this );
103     setRoot(aModelRoot);
104   }
105 }