Version: 8.3.0
SalomeWrap_DataModel Class Reference

#include <SalomeWrap_DataModel.hxx>

Inheritance diagram for SalomeWrap_DataModel:
Collaboration diagram for SalomeWrap_DataModel:

Public Types

enum  ObjectType { SchemaObject, RunObject, UnknownObject }
 

Public Member Functions

 SalomeWrap_DataModel (CAM_Module *theModule)
 
virtual ~SalomeWrap_DataModel ()
 
virtual void createNewSchema (const QString &schemaName, QWidget *viewWindow)
 
virtual bool renameSchema (const QString &oldName, const QString &newName, QWidget *viewWindow)
 
virtual bool deleteSchema (QWidget *viewWindow)
 
virtual void createNewRun (const QString &schemaName, const QString &runName, QWidget *refWindow, QWidget *viewWindow)
 
virtual void setSelected (QWidget *viewWindow)
 
SUIT_DataObject * getDataObject (std::string entry)
 
QWidgetgetViewWindow (std::string entry)
 

Protected Attributes

std::map< QWidget *, std::string > _viewEntryMap
 
std::map< std::string, QWidget * > _entryViewMap
 
std::map< std::string, int > _runCountMap
 

Detailed Description

Definition at line 31 of file SalomeWrap_DataModel.hxx.

Member Enumeration Documentation

Enumerator
SchemaObject 
RunObject 
UnknownObject 

Definition at line 53 of file SalomeWrap_DataModel.hxx.

54  {
56  RunObject,
58  };

Constructor & Destructor Documentation

SalomeWrap_DataModel::SalomeWrap_DataModel ( CAM_Module *  theModule)

Definition at line 39 of file SalomeWrap_DataModel.cxx.

References _entryViewMap, _viewEntryMap, and DEBTRACE.

40  : SalomeApp_DataModel(theModule)
41 {
42  DEBTRACE("SalomeWrap_DataModel::SalomeWrap_DataModel");
43  _viewEntryMap.clear();
44  _entryViewMap.clear();
45 }
SalomeWrap_DataModel::~SalomeWrap_DataModel ( )
virtual

Definition at line 47 of file SalomeWrap_DataModel.cxx.

References DEBTRACE.

48 {
49  DEBTRACE("SalomeWrap_DataModel::~SalomeWrap_DataModel");
50 }

Member Function Documentation

void SalomeWrap_DataModel::createNewRun ( const QString &  schemaName,
const QString &  runName,
QWidget refWindow,
QWidget viewWindow 
)
virtual

Definition at line 166 of file SalomeWrap_DataModel.cxx.

References _entryViewMap, _runCountMap, _viewEntryMap, DEBTRACE, and SchemaObject.

Referenced by YACS::HMI::SuitWrapper::createNewRun().

170 {
171  DEBTRACE("SalomeWrap_DataModel::createNewRun");
172  SalomeApp_ModuleObject* aRoot = dynamic_cast<SalomeApp_ModuleObject*>(root());
173  if (!aRoot) return;
174  DEBTRACE(refWindow);
175  if (!_viewEntryMap.count(refWindow)) return;
176  DEBTRACE("---");
177 
178  _PTR(SComponent) aSComp(aRoot->object());
179  _PTR(Study) aStudy = getStudy()->studyDS();
180 
181  _PTR(StudyBuilder) aBuilder(aStudy->NewBuilder());
182  _PTR(GenericAttribute) anAttr;
183  _PTR(AttributeName) aName;
184  _PTR(AttributePixMap) aPixmap;
185  _PTR(AttributeParameter) aType;
186 
187  string id = _viewEntryMap[refWindow];
188  _PTR(SObject) aRefObj = aStudy->FindObjectID(id);
189 
190  // --- create a new schema SObject
191 
192  _PTR(SObject) aSObj;
193  aSObj = aBuilder->NewObject(aRefObj);
194 
195  anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeName");
196  aName = _PTR(AttributeName)(anAttr);
197  aName->SetValue(QFileInfo(runName).baseName().toStdString());
198 
199  anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributePixMap");
200  aPixmap = _PTR(AttributePixMap)(anAttr);
201  aPixmap->SetPixMap("schema.png");
202 
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);
209 
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();
215 
216  QxScene_ViewWindow *swv = dynamic_cast<QxScene_ViewWindow*>(viewWindow);
217  if (!swv) return;
218 
219  int count = 0;
220  if (_runCountMap.count(schemaName.toStdString()))
221  count = ++_runCountMap[schemaName.toStdString()];
222  else
223  _runCountMap[schemaName.toStdString()] = count;
224 
225  QString tabName = QFileInfo(schemaName).baseName() +QString("_run%1").arg(count);
226  swv->getViewManager()->setTitle(tabName);
227 
228  QPixmap pixmap;
229  pixmap.load("icons:run_active.png");
230  swv->getViewManager()->setIcon(pixmap);
231 }
void SalomeWrap_DataModel::createNewSchema ( const QString &  schemaName,
QWidget viewWindow 
)
virtual

Definition at line 52 of file SalomeWrap_DataModel.cxx.

References _entryViewMap, _viewEntryMap, DEBTRACE, and SchemaObject.

Referenced by YACS::HMI::SuitWrapper::createNewSchema().

54 {
55  DEBTRACE("SalomeWrap_DataModel::createNewSchema : " << schemaName.toStdString());
56  SalomeApp_ModuleObject* aRoot = dynamic_cast<SalomeApp_ModuleObject*>(root());
57  if (!aRoot)
58  {
59  DEBTRACE("SalomeApp_ModuleObject* aRoot =0");
60  return;
61  }
62  DEBTRACE("aRoot OK");
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;
70 
71  // --- create a new schema SObject
72 
73  _PTR(SObject) aSObj;
74  aSObj = aBuilder->NewObject(aSComp);
75 
76  anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeName");
77  aName = _PTR(AttributeName)(anAttr);
78  aName->SetValue(QFileInfo(schemaName).baseName().toStdString());
79 
80  anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributePixMap");
81  aPixmap = _PTR(AttributePixMap)(anAttr);
82  aPixmap->SetPixMap("schema.png");
83 
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);
90 
91  _viewEntryMap[viewWindow] = aSObj->GetID();
92  DEBTRACE(viewWindow);
93  _entryViewMap[aSObj->GetID()] = viewWindow;
94  DEBTRACE("--- " << viewWindow << " "<< aSObj->GetID());
95  SalomeApp_Module *mod = dynamic_cast<SalomeApp_Module*>(module());
96  if (mod) mod->updateObjBrowser();
97 
98  QxScene_ViewWindow *swv = dynamic_cast<QxScene_ViewWindow*>(viewWindow);
99  if (!swv) return;
100  QString tabName = QFileInfo(schemaName).baseName();
101  swv->getViewManager()->setTitle(tabName);
102 }
bool SalomeWrap_DataModel::deleteSchema ( QWidget viewWindow)
virtual

Definition at line 145 of file SalomeWrap_DataModel.cxx.

References _viewEntryMap, and DEBTRACE.

Referenced by YACS::HMI::SuitWrapper::deleteSchema().

146 {
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;
151 
152  _PTR(SComponent) aSComp(aRoot->object());
153  _PTR(Study) aStudy = getStudy()->studyDS();
154 
155  string id = _viewEntryMap[viewWindow];
156  _PTR(SObject) aSObj = aStudy->FindObjectID(id);
157 
158  _PTR(StudyBuilder) aBuilder(aStudy->NewBuilder());
159  aBuilder->RemoveObject(aSObj);
160 
161  SalomeApp_Module *mod = dynamic_cast<SalomeApp_Module*>(module());
162  if (mod) mod->updateObjBrowser();
163  return true;
164 }
SUIT_DataObject * SalomeWrap_DataModel::getDataObject ( std::string  entry)

Definition at line 244 of file SalomeWrap_DataModel.cxx.

References DEBTRACE, and CORBAEngineTest::i.

245 {
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;
251 
252  QList<SUIT_DataObject*> objList = root()->children(true);
253  for (int i = 0; i < objList.size(); ++i)
254  {
255  SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(objList.at(i));
256  if (obj && (!QString::compare(refEntry, obj->entry())))
257  {
258  sdo = obj;
259  break;
260  }
261  }
262  return sdo;
263 }
QWidget * SalomeWrap_DataModel::getViewWindow ( std::string  entry)

Definition at line 265 of file SalomeWrap_DataModel.cxx.

References _entryViewMap.

266 {
267  if (! _entryViewMap.count(entry)) return 0;
268  return _entryViewMap[entry];
269 }
bool SalomeWrap_DataModel::renameSchema ( const QString &  oldName,
const QString &  newName,
QWidget viewWindow 
)
virtual

Definition at line 104 of file SalomeWrap_DataModel.cxx.

References _viewEntryMap, DEBTRACE, and SchemaObject.

Referenced by YACS::HMI::SuitWrapper::renameSchema().

107 {
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;
113 
114  _PTR(SComponent) aSComp(aRoot->object());
115  _PTR(Study) aStudy = getStudy()->studyDS();
116 
117  string id = _viewEntryMap[viewWindow];
118  _PTR(SObject) aSObj = aStudy->FindObjectID(id);
119 
120  _PTR(StudyBuilder) aBuilder(aStudy->NewBuilder());
121  _PTR(GenericAttribute) anAttr;
122  _PTR(AttributeName) aName;
123  _PTR(AttributeParameter) aType;
124 
125  anAttr = aBuilder->FindOrCreateAttribute(aSObj, "AttributeName");
126  aName = _PTR(AttributeName)(anAttr);
127  aName->SetValue(QFileInfo(newName).baseName().toStdString());
128 
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);
135 
136  SalomeApp_Module *mod = dynamic_cast<SalomeApp_Module*>(module());
137  if (mod) mod->updateObjBrowser();
138 
139  QxScene_ViewWindow *swv = dynamic_cast<QxScene_ViewWindow*>(viewWindow);
140  QString tabName = QFileInfo(newName).baseName();
141  if (swv) swv->getViewManager()->setTitle(tabName);
142  return true;
143 }
void SalomeWrap_DataModel::setSelected ( QWidget viewWindow)
virtual

Definition at line 233 of file SalomeWrap_DataModel.cxx.

References _viewEntryMap, and DEBTRACE.

Referenced by Yacsgui::onWindowActivated(), gui.Tree.Tree::selectItem(), and gui.Tree.Tree::selectNodeItem().

234 {
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 );
242 }

Member Data Documentation

std::map<std::string, QWidget*> SalomeWrap_DataModel::_entryViewMap
protected
std::map<std::string, int> SalomeWrap_DataModel::_runCountMap
protected

Definition at line 63 of file SalomeWrap_DataModel.hxx.

Referenced by createNewRun().

std::map<QWidget*, std::string> SalomeWrap_DataModel::_viewEntryMap
protected

The documentation for this class was generated from the following files: