Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / NewGeom / NewGeom_DataModel.cpp
1 #include "NewGeom_DataModel.h"
2 #include "NewGeom_Module.h"
3
4 #include <XGUI_Workshop.h>
5
6 #include <LightApp_Study.h>
7 #include <CAM_Application.h>
8 #include <SUIT_Tools.h>
9
10 #include <QFile>
11
12
13 NewGeom_DataModel::NewGeom_DataModel(NewGeom_Module* theModule)
14     : LightApp_DataModel(theModule), myModule(theModule)
15 {
16 }
17
18 NewGeom_DataModel::~NewGeom_DataModel()
19 {
20 }
21
22 bool NewGeom_DataModel::open(const QString& thePath, CAM_Study* theStudy, QStringList theFiles)
23 {
24   LightApp_DataModel::open( thePath, theStudy, theFiles );
25   if (theFiles.size() == 0)
26     return false;
27
28   QString aFile = theFiles.first();
29
30   SessionPtr aMgr = ModelAPI_Session::get();
31   aMgr->load(qPrintable(aFile));
32   myModule->setIsOpened(true);
33   myStudyPath = aFile;
34   return true;
35 }
36
37 bool NewGeom_DataModel::save(QStringList& theFiles)
38 {
39   LightApp_DataModel::save( theFiles );
40   XGUI_Workshop* aWorkShop = myModule->workshop();
41   std::list<std::string> aFileNames;
42
43   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( myModule->application()->activeStudy() );
44   std::string aTmpDir = aStudy->GetTmpDir(qPrintable(myStudyPath), true );
45   theFiles.append(QString(aTmpDir.c_str()));
46
47   aWorkShop->saveDocument(QString(aTmpDir.c_str()), aFileNames);
48   std::list<std::string>::iterator aIt;
49   for (aIt = aFileNames.begin(); aIt != aFileNames.end(); ++aIt) {
50     QString aName((*aIt).c_str());
51     aName.replace(QChar('\\'), QChar('/'));
52     int aN = aName.lastIndexOf('/');
53     theFiles.append(aName.right(aName.length() - aN - 1));
54   }
55   return true;
56 }
57
58 bool NewGeom_DataModel::saveAs(const QString& thePath, CAM_Study* theStudy, QStringList& theFiles)
59 {
60   myStudyPath = thePath;
61   return save(theFiles);
62 }
63
64 bool NewGeom_DataModel::close()
65 {
66   return LightApp_DataModel::close();
67 }
68
69 bool NewGeom_DataModel::create(CAM_Study* theStudy)
70 {
71   return true;
72 }
73
74 bool NewGeom_DataModel::isModified() const
75 {
76   SessionPtr aMgr = ModelAPI_Session::get();
77   return aMgr->isModified();
78 }
79
80 bool NewGeom_DataModel::isSaved() const
81 {
82   return !isModified();
83 }
84
85 void NewGeom_DataModel::update(LightApp_DataObject* theObj, LightApp_Study* theStudy)
86 {
87 }