1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SalomeWrap_DataModel.hxx"
22 #include <SalomeApp_DataObject.h>
23 #include <SalomeApp_Study.h>
24 #include <SalomeApp_Module.h>
25 #include <SalomeApp_Application.h>
26 #include <LightApp_SelectionMgr.h>
27 #include <SALOME_ListIO.hxx>
28 #include <SUIT_DataBrowser.h>
29 #include <SUIT_ViewManager.h>
30 #include <QxScene_ViewWindow.h>
35 #include "YacsTrace.hxx"
39 SalomeWrap_DataModel::SalomeWrap_DataModel(CAM_Module* theModule)
40 : SalomeApp_DataModel(theModule)
42 DEBTRACE("SalomeWrap_DataModel::SalomeWrap_DataModel");
43 _viewEntryMap.clear();
44 _entryViewMap.clear();
47 SalomeWrap_DataModel::~SalomeWrap_DataModel()
49 DEBTRACE("SalomeWrap_DataModel::~SalomeWrap_DataModel");
52 void SalomeWrap_DataModel::createNewSchema(const QString& schemaName,
55 DEBTRACE("SalomeWrap_DataModel::createNewSchema : " << schemaName.toStdString());
56 SalomeApp_ModuleObject* aRoot = dynamic_cast<SalomeApp_ModuleObject*>(root());
59 DEBTRACE("SalomeApp_ModuleObject* aRoot =0");
63 _PTR(SComponent) aSComp(aRoot->object());
64 _PTR(Study) aStudy = getStudy()->studyDS();
65 _PTR(StudyBuilder) aBuilder(aStudy->NewBuilder());
66 _PTR(GenericAttribute) anAttr;
67 _PTR(AttributeName) aName;
68 _PTR(AttributePixMap) aPixmap;
69 _PTR(AttributeParameter) aType;
71 // --- create a new schema SObject
74 aSObj = aBuilder->NewObject(aSComp);
76 anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeName");
77 aName = _PTR(AttributeName)(anAttr);
78 aName->SetValue(QFileInfo(schemaName).baseName().toStdString());
80 anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributePixMap");
81 aPixmap = _PTR(AttributePixMap)(anAttr);
82 aPixmap->SetPixMap("schema.png");
84 anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeParameter");
85 aType = _PTR(AttributeParameter)(anAttr);
86 aType->SetInt("ObjectType", SchemaObject);
87 string filePath = schemaName.toStdString();
88 aType->SetString("FilePath", filePath.c_str());
89 DEBTRACE("DataModel : FilePath = " << filePath);
91 _viewEntryMap[viewWindow] = aSObj->GetID();
93 _entryViewMap[aSObj->GetID()] = viewWindow;
94 DEBTRACE("--- " << viewWindow << " "<< aSObj->GetID());
95 SalomeApp_Module *mod = dynamic_cast<SalomeApp_Module*>(module());
96 if (mod) mod->updateObjBrowser();
98 QxScene_ViewWindow *swv = dynamic_cast<QxScene_ViewWindow*>(viewWindow);
100 QString tabName = QFileInfo(schemaName).baseName();
101 swv->getViewManager()->setTitle(tabName);
104 bool SalomeWrap_DataModel::renameSchema(const QString& oldName,
105 const QString& newName,
108 DEBTRACE("SalomeWrap_DataModel::renameSchema " << oldName.toStdString()
109 << " " << newName.toStdString());
110 SalomeApp_ModuleObject* aRoot = dynamic_cast<SalomeApp_ModuleObject*>(root());
111 if (!aRoot) return false;
112 if (!_viewEntryMap.count(viewWindow)) return false;
114 _PTR(SComponent) aSComp(aRoot->object());
115 _PTR(Study) aStudy = getStudy()->studyDS();
117 string id = _viewEntryMap[viewWindow];
118 _PTR(SObject) aSObj = aStudy->FindObjectID(id);
120 _PTR(StudyBuilder) aBuilder(aStudy->NewBuilder());
121 _PTR(GenericAttribute) anAttr;
122 _PTR(AttributeName) aName;
123 _PTR(AttributeParameter) aType;
125 anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeName");
126 aName = _PTR(AttributeName)(anAttr);
127 aName->SetValue(QFileInfo(newName).baseName().toStdString());
129 anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeParameter");
130 aType = _PTR(AttributeParameter)(anAttr);
131 aType->SetInt("ObjectType", SchemaObject);
132 string filePath = newName.toStdString();
133 aType->SetString("FilePath", filePath.c_str());
134 DEBTRACE("DataModel : FilePath = " << filePath);
136 SalomeApp_Module *mod = dynamic_cast<SalomeApp_Module*>(module());
137 if (mod) mod->updateObjBrowser();
139 QxScene_ViewWindow *swv = dynamic_cast<QxScene_ViewWindow*>(viewWindow);
140 QString tabName = QFileInfo(newName).baseName();
141 if (swv) swv->getViewManager()->setTitle(tabName);
145 bool SalomeWrap_DataModel::deleteSchema(QWidget* viewWindow)
147 DEBTRACE("SalomeWrap_DataModel::deleteSchema");
148 SalomeApp_ModuleObject* aRoot = dynamic_cast<SalomeApp_ModuleObject*>(root());
149 if (!aRoot) return false;
150 if (!_viewEntryMap.count(viewWindow)) return false;
152 _PTR(SComponent) aSComp(aRoot->object());
153 _PTR(Study) aStudy = getStudy()->studyDS();
155 string id = _viewEntryMap[viewWindow];
156 _PTR(SObject) aSObj = aStudy->FindObjectID(id);
158 _PTR(StudyBuilder) aBuilder(aStudy->NewBuilder());
159 aBuilder->RemoveObject(aSObj);
161 SalomeApp_Module *mod = dynamic_cast<SalomeApp_Module*>(module());
162 if (mod) mod->updateObjBrowser();
166 void SalomeWrap_DataModel::createNewRun(const QString& schemaName,
167 const QString& runName,
171 DEBTRACE("SalomeWrap_DataModel::createNewRun");
172 SalomeApp_ModuleObject* aRoot = dynamic_cast<SalomeApp_ModuleObject*>(root());
175 if (!_viewEntryMap.count(refWindow)) return;
178 _PTR(SComponent) aSComp(aRoot->object());
179 _PTR(Study) aStudy = getStudy()->studyDS();
181 _PTR(StudyBuilder) aBuilder(aStudy->NewBuilder());
182 _PTR(GenericAttribute) anAttr;
183 _PTR(AttributeName) aName;
184 _PTR(AttributePixMap) aPixmap;
185 _PTR(AttributeParameter) aType;
187 string id = _viewEntryMap[refWindow];
188 _PTR(SObject) aRefObj = aStudy->FindObjectID(id);
190 // --- create a new schema SObject
193 aSObj = aBuilder->NewObject(aRefObj);
195 anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeName");
196 aName = _PTR(AttributeName)(anAttr);
197 aName->SetValue(QFileInfo(runName).baseName().toStdString());
199 anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributePixMap");
200 aPixmap = _PTR(AttributePixMap)(anAttr);
201 aPixmap->SetPixMap("schema.png");
203 anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeParameter");
204 aType = _PTR(AttributeParameter)(anAttr);
205 aType->SetInt("ObjectType", SchemaObject);
206 string filePath = runName.toStdString();
207 aType->SetString("FilePath", filePath.c_str());
208 DEBTRACE("DataModel : FilePath = " << filePath);
210 _viewEntryMap[viewWindow] = aSObj->GetID();
211 _entryViewMap[aSObj->GetID()] = viewWindow;
212 DEBTRACE("--- " << viewWindow << " "<< aSObj->GetID());
213 SalomeApp_Module *mod = dynamic_cast<SalomeApp_Module*>(module());
214 if (mod) mod->updateObjBrowser();
216 QxScene_ViewWindow *swv = dynamic_cast<QxScene_ViewWindow*>(viewWindow);
220 if (_runCountMap.count(schemaName.toStdString()))
221 count = ++_runCountMap[schemaName.toStdString()];
223 _runCountMap[schemaName.toStdString()] = count;
225 QString tabName = QFileInfo(schemaName).baseName() +QString("_run%1").arg(count);
226 swv->getViewManager()->setTitle(tabName);
229 pixmap.load("icons:run_active.png");
230 swv->getViewManager()->setIcon(pixmap);
233 void SalomeWrap_DataModel::setSelected(QWidget* viewWindow)
235 DEBTRACE("SalomeWrap_DataModel::setSelected");
236 if (!_viewEntryMap.count(viewWindow)) return;
237 string entry = _viewEntryMap[viewWindow];
238 LightApp_SelectionMgr* selMgr = getModule()->getApp()->selectionMgr();
239 SALOME_ListIO ioList;
240 ioList.Append( new SALOME_InteractiveObject( entry.c_str(), "", "" ) );
241 selMgr->setSelectedObjects( ioList, false );
244 SUIT_DataObject* SalomeWrap_DataModel::getDataObject(std::string entry)
246 DEBTRACE("SalomeWrap_DataModel::getDataObject " << entry);
247 QString refEntry = entry.c_str();
248 SUIT_DataObject* sdo = 0;
249 SalomeApp_ModuleObject* aRoot = dynamic_cast<SalomeApp_ModuleObject*>(root());
250 if (!aRoot) return 0;
252 QList<SUIT_DataObject*> objList = root()->children(true);
253 for (int i = 0; i < objList.size(); ++i)
255 SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(objList.at(i));
256 if (obj && (!QString::compare(refEntry, obj->entry())))
265 QWidget* SalomeWrap_DataModel::getViewWindow(std::string entry)
267 if (! _entryViewMap.count(entry)) return 0;
268 return _entryViewMap[entry];