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>
42 DEBTRACE(
"SalomeWrap_DataModel::SalomeWrap_DataModel");
49 DEBTRACE(
"SalomeWrap_DataModel::~SalomeWrap_DataModel");
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;
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);
87 string filePath = schemaName.toStdString();
88 aType->SetString(
"FilePath", filePath.c_str());
89 DEBTRACE(
"DataModel : FilePath = " << filePath);
94 DEBTRACE(
"--- " << viewWindow <<
" "<< aSObj->GetID());
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);
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;
114 _PTR(SComponent) aSComp(aRoot->object());
115 _PTR(Study) aStudy = getStudy()->studyDS();
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);
132 string filePath = newName.toStdString();
133 aType->SetString(
"FilePath", filePath.c_str());
134 DEBTRACE(
"DataModel : FilePath = " << filePath);
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);
147 DEBTRACE(
"SalomeWrap_DataModel::deleteSchema");
148 SalomeApp_ModuleObject* aRoot =
dynamic_cast<SalomeApp_ModuleObject*
>(root());
149 if (!aRoot)
return false;
152 _PTR(SComponent) aSComp(aRoot->object());
153 _PTR(Study) aStudy = getStudy()->studyDS();
156 _PTR(SObject) aSObj = aStudy->FindObjectID(
id);
158 _PTR(StudyBuilder) aBuilder(aStudy->NewBuilder());
159 aBuilder->RemoveObject(aSObj);
162 if (mod) mod->updateObjBrowser();
167 const QString& runName,
171 DEBTRACE(
"SalomeWrap_DataModel::createNewRun");
172 SalomeApp_ModuleObject* aRoot =
dynamic_cast<SalomeApp_ModuleObject*
>(root());
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;
188 _PTR(SObject) aRefObj = aStudy->FindObjectID(
id);
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);
206 string filePath = runName.toStdString();
207 aType->SetString(
"FilePath", filePath.c_str());
208 DEBTRACE(
"DataModel : FilePath = " << filePath);
212 DEBTRACE(
"--- " << viewWindow <<
" "<< aSObj->GetID());
214 if (mod) mod->updateObjBrowser();
216 QxScene_ViewWindow *swv =
dynamic_cast<QxScene_ViewWindow*
>(viewWindow);
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);
235 DEBTRACE(
"SalomeWrap_DataModel::setSelected");
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 );
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())))