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