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