1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "NewGeom_DataModel.h"
4 #include "NewGeom_Module.h"
6 #include <XGUI_Workshop.h>
8 #include <ModelAPI_Session.h>
10 #include <LightApp_Study.h>
11 #include <CAM_Application.h>
12 #include <SUIT_Tools.h>
13 #include <SUIT_ResourceMgr.h>
18 NewGeom_DataModel::NewGeom_DataModel(NewGeom_Module* theModule)
19 : LightApp_DataModel(theModule), myStudyPath(""), myModule(theModule)
23 NewGeom_DataModel::~NewGeom_DataModel()
27 bool NewGeom_DataModel::open(const QString& thePath, CAM_Study* theStudy, QStringList theFiles)
29 LightApp_DataModel::open( thePath, theStudy, theFiles );
30 if (theFiles.size() == 0)
33 myStudyPath = thePath;
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();
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();
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;
55 QString aCurrentFile = SUIT_Tools::addSlash(aTmpDir) + aFileName;
56 QString aNewFile = SUIT_Tools::addSlash(aNewTmpDir) + aFileName;
57 if (!QFile::copy(aCurrentFile, aNewFile))
61 SessionPtr aMgr = ModelAPI_Session::get();
62 aMgr->load(qPrintable(aNewTmpDir));
63 myModule->setIsOpened(true);
67 bool NewGeom_DataModel::save(QStringList& theFiles)
69 LightApp_DataModel::save( theFiles );
70 XGUI_Workshop* aWorkShop = myModule->workshop();
71 std::list<std::string> aFileNames;
73 CAM_Application* anApp = myModule->application();
74 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(anApp->activeStudy());
75 SUIT_ResourceMgr* aResMgr = anApp->resourceMgr();
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;
82 std::string aTmpDir = aStudy->GetTmpDir(qPrintable(myStudyPath), isMultiFile);
83 //std::string aTmpDir = aStudy->GetTmpDir("", false);//true );
84 theFiles.append(QString(aTmpDir.c_str()));
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));
97 bool NewGeom_DataModel::saveAs(const QString& thePath, CAM_Study* theStudy, QStringList& theFiles)
99 myStudyPath = thePath;
100 return save(theFiles);
103 bool NewGeom_DataModel::close()
105 myModule->workshop()->closeDocument();
106 return LightApp_DataModel::close();
109 bool NewGeom_DataModel::create(CAM_Study* theStudy)
114 bool NewGeom_DataModel::isModified() const
116 SessionPtr aMgr = ModelAPI_Session::get();
117 return aMgr->isModified();
120 bool NewGeom_DataModel::isSaved() const
122 return !isModified();
125 void NewGeom_DataModel::update(LightApp_DataObject* theObj, LightApp_Study* theStudy)