]> SALOME platform Git repositories - modules/shaper.git/blob - src/NewGeom/NewGeom_DataModel.cpp
Salome HOME
Persistent correction in full Salome mode.
[modules/shaper.git] / src / NewGeom / NewGeom_DataModel.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include "NewGeom_DataModel.h"
4 #include "NewGeom_Module.h"
5
6 #include <XGUI_Workshop.h>
7
8 #include <ModelAPI_Session.h>
9
10 #include <LightApp_Study.h>
11 #include <CAM_Application.h>
12 #include <SUIT_Tools.h>
13 #include <SUIT_ResourceMgr.h>
14
15 #include <QFile>
16 #include <QDir>
17
18 NewGeom_DataModel::NewGeom_DataModel(NewGeom_Module* theModule)
19     : LightApp_DataModel(theModule), myStudyPath(""), myModule(theModule)
20 {
21 }
22
23 NewGeom_DataModel::~NewGeom_DataModel()
24 {
25 }
26
27 bool NewGeom_DataModel::open(const QString& thePath, CAM_Study* theStudy, QStringList theFiles)
28 {
29   LightApp_DataModel::open( thePath, theStudy, theFiles );
30   if (theFiles.size() == 0)
31     return false;
32
33   myStudyPath = thePath;
34
35   // If the file is Multi(contain all module files inside), the open SALOME functionality creates
36   // these files in a temporary directory. After the open functionality is finished, it removes
37   // these files (in the full SALOME mode).
38   // The postponed loading of the files is realized in the NewGEOM module. So, it is important do
39   // not remove the opened files.
40   // The following code creates a new tmp directory with a copy of files.
41   QString aTmpDir = theFiles.first();
42
43   //LightApp_Driver aDriver;
44   //QString aNewTmpDir = QString(aDriver.GetTmpDir("", false).c_str());
45   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( myModule->application()->activeStudy() );
46   QString aNewTmpDir = aStudy->GetTmpDir("", false).c_str();
47
48   bool isDone = true;
49   QDir aDir(aTmpDir);
50   QStringList aFiles = aDir.entryList(QDir::Files);
51   QStringList::const_iterator anIt = aFiles.begin(), aLast = aFiles.end();
52   for (; anIt != aLast; anIt++) {
53     QString aFileName = *anIt;
54
55     QString aCurrentFile = SUIT_Tools::addSlash(aTmpDir) + aFileName;
56     QString aNewFile = SUIT_Tools::addSlash(aNewTmpDir) + aFileName;
57     if (!QFile::copy(aCurrentFile, aNewFile))
58       isDone = false;
59   }
60
61   SessionPtr aMgr = ModelAPI_Session::get();
62   aMgr->load(qPrintable(aNewTmpDir));
63   myModule->setIsOpened(true);
64   return true;
65 }
66
67 bool NewGeom_DataModel::save(QStringList& theFiles)
68 {
69   LightApp_DataModel::save( theFiles );
70   XGUI_Workshop* aWorkShop = myModule->workshop();
71   std::list<std::string> aFileNames;
72
73   CAM_Application* anApp = myModule->application();
74   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(anApp->activeStudy());
75   SUIT_ResourceMgr* aResMgr = anApp->resourceMgr();
76
77   // it is important to check whether the file is saved in the multi-files mode in order to save
78   // files in temporary directories, which are removed in the full SALOME mode after copiying
79   // the files content in a result file.
80   bool isMultiFile = aResMgr ? aResMgr->booleanValue("Study", "multi_file", false) : false;
81
82   std::string aTmpDir = aStudy->GetTmpDir(qPrintable(myStudyPath), isMultiFile);
83   //std::string aTmpDir = aStudy->GetTmpDir("", false);//true );
84   theFiles.append(QString(aTmpDir.c_str()));
85
86   aWorkShop->saveDocument(QString(aTmpDir.c_str()), aFileNames);
87   std::list<std::string>::iterator aIt;
88   for (aIt = aFileNames.begin(); aIt != aFileNames.end(); ++aIt) {
89     QString aName((*aIt).c_str());
90     aName.replace(QChar('\\'), QChar('/'));
91     int aN = aName.lastIndexOf('/');
92     theFiles.append(aName.right(aName.length() - aN - 1));
93   }
94   return true;
95 }
96
97 bool NewGeom_DataModel::saveAs(const QString& thePath, CAM_Study* theStudy, QStringList& theFiles)
98 {
99   myStudyPath = thePath;
100   return save(theFiles);
101 }
102
103 bool NewGeom_DataModel::close()
104 {
105   myModule->workshop()->closeDocument();
106   return LightApp_DataModel::close();
107 }
108
109 bool NewGeom_DataModel::create(CAM_Study* theStudy)
110 {
111   return true;
112 }
113
114 bool NewGeom_DataModel::isModified() const
115 {
116   SessionPtr aMgr = ModelAPI_Session::get();
117   return aMgr->isModified();
118 }
119
120 bool NewGeom_DataModel::isSaved() const
121 {
122   return !isModified();
123 }
124
125 void NewGeom_DataModel::update(LightApp_DataObject* theObj, LightApp_Study* theStudy)
126 {
127 }