Version: 8.3.0
Yacsgui Class Reference

#include <Yacsgui.hxx>

Inheritance diagram for Yacsgui:
Collaboration diagram for Yacsgui:

Public Slots

bool deactivateModule (SUIT_Study *theStudy)
 
bool activateModule (SUIT_Study *theStudy)
 
void onDblClick (SUIT_DataObject *object)
 
void onCleanOnExit ()
 

Public Member Functions

 Yacsgui ()
 
virtual ~Yacsgui ()
 
void initialize (CAM_Application *app)
 
void windows (QMap< int, int > &theMap) const
 
virtual QString engineIOR () const
 
virtual void viewManagers (QStringList &list) const
 
virtual void setResource (SUIT_ResourceMgr *r)
 
virtual void createPreferences ()
 
virtual void preferencesChanged (const QString &sect, const QString &name)
 
virtual void loadSchema (const std::string &filename, bool edit=true, bool arrangeLocalNodes=false)
 
virtual void studyActivated ()
 
- Public Member Functions inherited from SalomeWrap_Module
 SalomeWrap_Module (const char *name)
 
QxScene_ViewWindow * getNewWindow (QGraphicsScene *scene)
 
int AssociateViewToWindow (QGraphicsView *gView, QxScene_ViewWindow *viewWindow)
 
int activeStudyId ()
 
QDockWidget * objectBrowser ()
 
QAction * wCreateAction (const int id, const QString &toolTip, const QIcon &icon, const QString &menu, const QString &status, const int shortCut, QObject *parent=0, bool checkable=false, QObject *receiver=0, const char *member=0)
 
int wCreateMenu (const QString &subMenu, const int parentMenuId, const int menuId=-1, const int groupId=-1, const int index=-1)
 
int wCreateMenu (const QString &subMenu, const QString &parentMenu, const int menuId=-1, const int groupId=-1, const int index=-1)
 
int wCreateMenu (const int actionId, const int menuId, const int groupId=-1, const int index=-1)
 
int wCreateMenu (const int actionId, const QString &menu, const int groupId=-1, const int index=-1)
 
int wCreateMenu (QAction *action, const int menuId, const int actionId=-1, const int groupId=-1, const int index=-1)
 
int wCreateMenu (QAction *action, const QString &menu, const int actionId=-1, const int groupId=-1, const int index=-1)
 
int wCreateTool (const QString &title, const QString &name=QString())
 
int wCreateTool (const int actionId, const int toolbarId, const int index=-1)
 
int wCreateTool (const int actionId, const QString &toolbar, const int index=-1)
 
int wCreateTool (QAction *action, const int toolbarId, const int actionId=-1, const int index=-1)
 
int wCreateTool (QAction *action, const QString &toolbar, const int actionId=-1, const int index=-1)
 
SalomeWrap_DataModelgetDataModel ()
 

Protected Slots

void onWindowActivated (SUIT_ViewWindow *svw)
 
void onWindowClosed (SUIT_ViewWindow *svw)
 
void onTryClose (bool &isClosed, QxScene_ViewWindow *window)
 

Protected Member Functions

virtual CAM_DataModel * createDataModel ()
 
bool createSComponent ()
 

Protected Attributes

YACS::HMI::SuitWrapper_wrapper
 
YACS::HMI::GenericGui_genericGui
 
bool _selectFromTree
 
Yacsgui_Resource_myresource
 
SUIT_ViewWindow * _currentSVW
 
std::map< int,
YACS::HMI::QtGuiContext * > 
_studyContextMap
 
- Protected Attributes inherited from SalomeWrap_Module
std::map< QGraphicsScene
*, QxScene_ViewWindow * > 
_mapOfViewWindow
 

Static Protected Attributes

static int _oldStudyId = -1
 

Friends

class Yacsgui_Resource
 

Additional Inherited Members

- Static Public Member Functions inherited from SalomeWrap_Module
static QAction * wSeparator ()
 

Detailed Description

Definition at line 43 of file Yacsgui.hxx.

Constructor & Destructor Documentation

Yacsgui::Yacsgui ( )

Definition at line 63 of file Yacsgui.cxx.

References _genericGui, _selectFromTree, _studyContextMap, _wrapper, and DEBTRACE.

64  :
65  SalomeWrap_Module( "YACS" ) // default name
66 {
67  DEBTRACE("Yacsgui::Yacsgui");
68  _wrapper = 0;
69  _genericGui = 0;
70  _selectFromTree = false;
71  _studyContextMap.clear();
}
Yacsgui::~Yacsgui ( )
virtual

Definition at line 73 of file Yacsgui.cxx.

References _genericGui, _wrapper, and onCleanOnExit().

74 {
75  if ( getApp() )
76  disconnect( getApp(), SIGNAL(studyClosed()), this, SLOT (onCleanOnExit()));
77  delete _wrapper;
78  delete _genericGui;
79 }

Member Function Documentation

bool Yacsgui::activateModule ( SUIT_Study *  theStudy)
slot

Definition at line 156 of file Yacsgui.cxx.

References _currentSVW, _genericGui, DEBTRACE, onWindowActivated(), and YACS::HMI::GenericGui::showDockWidgets().

Referenced by onWindowActivated().

157 {
158  DEBTRACE("Yacsgui::activateModule");
159  bool bOk = SalomeApp_Module::activateModule( theStudy );
160 
161  QMainWindow* parent = application()->desktop();
162  if(Resource::dockWidgetPriority)
163  {
164  parent->setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
165  parent->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
166  parent->setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
167  parent->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
168  }
169  setMenuShown( true );
170  setToolShown( true );
172 
173  // import Python module that manages YACS plugins (need to be here because SalomePyQt API uses active module)
174  PyGILState_STATE gstate = PyGILState_Ensure();
175  PyObject* pluginsmanager=PyImport_ImportModule((char*)"salome_pluginsmanager");
176  if(pluginsmanager==NULL)
177  PyErr_Print();
178  else
179  {
180  PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"yacs","YACS",tr("YACS_PLUGINS").toStdString().c_str());
181  if(result==NULL)
182  PyErr_Print();
183  Py_XDECREF(result);
184  }
185  Py_XDECREF(pluginsmanager);
186 
187  PyGILState_Release(gstate);
188  // end of YACS plugins loading
189 
190  if (_currentSVW)
192 
193  return bOk;
194 }
CAM_DataModel * Yacsgui::createDataModel ( )
protectedvirtual

Reimplemented from SalomeWrap_Module.

Definition at line 305 of file Yacsgui.cxx.

306 {
307  return new Yacsgui_DataModel(this);
308 }
void Yacsgui::createPreferences ( )
virtual

Definition at line 346 of file Yacsgui.cxx.

References _myresource, Yacsgui_Resource::createPreferences(), and DEBTRACE.

347 {
348  DEBTRACE("Yacsgui::createPreferences");
350 }
bool Yacsgui::createSComponent ( )
protected

Definition at line 310 of file Yacsgui.cxx.

References DEBTRACE, and engineIOR().

Referenced by initialize().

311 {
312  DEBTRACE("Yacsgui::createSComponent");
313  _PTR(Study) aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
314  _PTR(StudyBuilder) aBuilder (aStudy->NewBuilder());
315  _PTR(GenericAttribute) anAttr;
316  _PTR(AttributeName) aName;
317 
318  // --- Find or create "YACS" SComponent in the study
319 
320  _PTR(SComponent) aComponent = aStudy->FindComponent("YACS");
321  if ( !aComponent )
322  {
323  aComponent = aBuilder->NewComponent("YACS");
324  anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
325  aName = _PTR(AttributeName) (anAttr);
326  aName->SetValue(getApp()->moduleTitle("YACS").toStdString());
327 
328  anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
329  _PTR(AttributePixMap) aPixmap(anAttr);
330  aPixmap->SetPixMap("ModuleYacs.png");
331 
332  aBuilder->DefineComponentInstance(aComponent, engineIOR().toLatin1().constData());
333 
334  return true;
335  }
336  return false;
337 }
bool Yacsgui::deactivateModule ( SUIT_Study *  theStudy)
slot

Definition at line 196 of file Yacsgui.cxx.

References _genericGui, _studyContextMap, DEBTRACE, and YACS::HMI::GenericGui::showDockWidgets().

197 {
198  DEBTRACE("Yacsgui::deactivateModule");
199 
200  QMainWindow* parent = application()->desktop();
201  parent->setCorner(Qt::TopLeftCorner, Qt::TopDockWidgetArea);
202  parent->setCorner(Qt::BottomLeftCorner, Qt::BottomDockWidgetArea);
203  parent->setCorner(Qt::TopRightCorner, Qt::TopDockWidgetArea);
204  parent->setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
205 
206  setMenuShown( false );
207  setToolShown( false );
209  QtGuiContext *context = QtGuiContext::getQtCurrent();
210  _studyContextMap[theStudy->id()] = context;
211  DEBTRACE("_studyContextMap[theStudy] " << theStudy << " " << context);
212  return SalomeApp_Module::deactivateModule( theStudy );
213 }
QString Yacsgui::engineIOR ( ) const
virtual

Definition at line 225 of file Yacsgui.cxx.

References DEBTRACE.

Referenced by createSComponent().

226 {
227  DEBTRACE("Yacsgui::engineIOR");
228  QString anEngineIOR = SalomeApp_Engine_i::EngineIORForComponent( "YACS", true ).c_str();
229  return anEngineIOR;
230 }
void Yacsgui::initialize ( CAM_Application *  app)

Definition at line 81 of file Yacsgui.cxx.

References _currentSVW, _genericGui, _wrapper, YACS::HMI::CatalogWidget::addCatalogFromFile(), YACS::HMI::GenericGui::createActions(), YACS::HMI::GenericGui::createMenus(), createSComponent(), YACS::HMI::GenericGui::createTools(), DEBTRACE, YACS::HMI::GenericGui::getCatalogWidget(), onCleanOnExit(), onDblClick(), onWindowActivated(), setResource(), and studyActivated().

82 {
83  DEBTRACE("Yacsgui::initialize");
84  _currentSVW = 0;
85  SalomeApp_Module::initialize( app );
86 
87  QWidget* aParent = application()->desktop();
88  DEBTRACE(app << " " << application() << " " << application()->desktop() << " " << aParent);
89 
90  SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
91  setResource(aResourceMgr);
92 
93  _wrapper = new SuitWrapper(this);
94  _genericGui = new GenericGui(_wrapper, app->desktop());
95 
96  if ( app && app->desktop() )
97  {
98  connect( app->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
99  this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
100 
101  connect( getApp(),
102  SIGNAL(objectDoubleClicked( SUIT_DataObject* )),
103  this,
104  SLOT (onDblClick( SUIT_DataObject* )));
105 
106  connect( getApp(),
107  SIGNAL(studyClosed()),
108  this,
109  SLOT (onCleanOnExit()));
110  }
114  this->studyActivated();
115 
116  // VSR 23/10/2014: note that this is not a good way to create SComponent from this point
117  // as initialize() method can be potentially called when there's no yet open study;
118  // this is better to do in activateModule()
119  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
120  if ( aStudy ) {
121  bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->studyDS()->GetProperties()))->IsLocked();
122  if ( aLocked ) {
123  SUIT_MessageBox::warning ( app->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
124  }
125  else {
126  if (createSComponent()) updateObjBrowser();
127  }
128  }
129 
130  // Load SALOME module catalogs
131  QStringList appModules;
132  app->modules(appModules,false);
133  for ( QStringList::const_iterator it = appModules.begin(); it != appModules.end(); ++it )
134  {
135  QString aModule=*it;
136  QString modName = app->moduleName( aModule ); // module name
137  if ( modName.isEmpty() ) modName = aModule;
138  QString rootDir = QString( "%1_ROOT_DIR" ).arg( modName ); // module root dir variable
139  QString modDir = getenv( rootDir.toLatin1().constData() ); // module root dir
140  if ( !modDir.isEmpty() )
141  {
142  QStringList cataLst = QStringList() << modDir << "share" << "salome" << "resources" << modName.toLower() << modName+"SchemaCatalog.xml";
143  QString cataFile = cataLst.join( QDir::separator() ); // YACS module catalog
144  if ( QFile::exists( cataFile ) )
145  _genericGui->getCatalogWidget()->addCatalogFromFile(cataFile.toStdString());
146  }
147  }
148 }
void Yacsgui::loadSchema ( const std::string &  filename,
bool  edit = true,
bool  arrangeLocalNodes = false 
)
virtual

Definition at line 383 of file Yacsgui.cxx.

References _genericGui, and YACS::HMI::GenericGui::loadSchema().

384 {
385  _genericGui->loadSchema(filename,edit,arrangeLocalNodes);
386 }
void Yacsgui::onCleanOnExit ( )
slot

Definition at line 388 of file Yacsgui.cxx.

References _currentSVW, _genericGui, and YACS::HMI::GenericGui::onCleanOnExit().

Referenced by initialize(), and ~Yacsgui().

389 {
390  if ( _genericGui )
392  _currentSVW = 0;
393 }
void Yacsgui::onDblClick ( SUIT_DataObject *  object)
slot

Definition at line 232 of file Yacsgui.cxx.

References _genericGui, _selectFromTree, and DEBTRACE.

Referenced by initialize().

233 {
234  DEBTRACE("Yacsgui::onDblClick");
235  DataObjectList dol =getApp()->objectBrowser()->getSelected();
236  if (dol.isEmpty()) return;
237 
238  SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
239  if (!item) return;
240 
241  DEBTRACE(item->name().toStdString());
242  SalomeWrap_DataModel *model = dynamic_cast<SalomeWrap_DataModel*>(dataModel());
243  if (!model) return;
244  DEBTRACE(item->entry().toStdString());
245  QWidget * viewWindow = model->getViewWindow(item->entry().toStdString());
246  if (!_genericGui) return;
247  if (!viewWindow) return;
248  DEBTRACE("--- " << viewWindow << " " << item->entry().toStdString());
249  if (getApp()->activeModule()->moduleName().compare("YACS") != 0)
250  getApp()->activateModule("YACS");
251 
252  _selectFromTree = true;
253  viewWindow->setFocus();
254  _selectFromTree = false;
255 }
void Yacsgui::onTryClose ( bool &  isClosed,
QxScene_ViewWindow *  window 
)
protectedslot

Definition at line 298 of file Yacsgui.cxx.

References _genericGui, YACS::HMI::GenericGui::closeContext(), DEBTRACE, and YASSERT.

Referenced by onWindowActivated().

299 {
300  DEBTRACE("Yacsgui::onTryClose");
302  isClosed = _genericGui->closeContext(window);
303 }
void Yacsgui::onWindowActivated ( SUIT_ViewWindow *  svw)
protectedslot

Definition at line 257 of file Yacsgui.cxx.

References _currentSVW, _genericGui, _selectFromTree, _studyContextMap, activateModule(), DEBTRACE, onTryClose(), onWindowClosed(), SalomeWrap_DataModel::setSelected(), YACS::HMI::GenericGui::switchContext(), and YASSERT.

Referenced by activateModule(), and initialize().

258 {
259  DEBTRACE("Yacsgui::onWindowActivated");
260  QxScene_ViewWindow* viewWindow = dynamic_cast<QxScene_ViewWindow*>(svw);
261  _currentSVW = svw;
262  if (!viewWindow)
263  {
264  _currentSVW = 0; // switch to another module
265  return;
266  }
267  DEBTRACE("viewWindow " << viewWindow);
268  DEBTRACE("activeModule()->moduleName() " << (getApp()->activeModule() ? getApp()->activeModule()->moduleName().toStdString() : "") );
269  if (!getApp()->activeModule() || getApp()->activeModule()->moduleName() != "YACS")
270  if ( !getApp()->activateModule("YACS") ) return;
271 
272  disconnect(viewWindow, SIGNAL( tryClose( bool&, QxScene_ViewWindow* ) ),
273  this, SLOT(onTryClose( bool&, QxScene_ViewWindow* )) );
274  disconnect(viewWindow->getViewManager(), SIGNAL( deleteView( SUIT_ViewWindow* ) ),
275  this, SLOT(onWindowClosed( SUIT_ViewWindow* )) );
276  connect(viewWindow, SIGNAL( tryClose( bool&, QxScene_ViewWindow* ) ),
277  this, SLOT(onTryClose( bool&, QxScene_ViewWindow* )) );
278  connect(viewWindow->getViewManager(), SIGNAL( deleteView( SUIT_ViewWindow* ) ),
279  this, SLOT(onWindowClosed( SUIT_ViewWindow* )) );
280 
282  _genericGui->switchContext(viewWindow);
283  _studyContextMap[getApp()->activeStudy()->id()] = QtGuiContext::getQtCurrent();
284 
285  if (_selectFromTree) return;
286  SalomeWrap_DataModel *model = dynamic_cast<SalomeWrap_DataModel*>(dataModel());
287  if (!model) return;
288  model->setSelected(svw);
289 }
void Yacsgui::onWindowClosed ( SUIT_ViewWindow *  svw)
protectedslot

Definition at line 291 of file Yacsgui.cxx.

References _currentSVW, and DEBTRACE.

Referenced by onWindowActivated().

292 {
293  DEBTRACE("Yacsgui::onWindowClosed");
294  if ( svw && svw == _currentSVW )
295  _currentSVW = 0;
296 }
void Yacsgui::preferencesChanged ( const QString &  sect,
const QString &  name 
)
virtual

Definition at line 352 of file Yacsgui.cxx.

References _genericGui, _myresource, YACS::HMI::CatalogWidget::addCatalogFromFile(), DEBTRACE, YACS::HMI::GenericGui::getCatalogWidget(), and Yacsgui_Resource::preferencesChanged().

353 {
354  DEBTRACE("Yacsgui::preferencesChanged");
355  _myresource->preferencesChanged(sect, name);
356  if(name=="userCatalog")
357  {
358  _genericGui->getCatalogWidget()->addCatalogFromFile(Resource::userCatalog.toStdString());
359  }
360 }
void Yacsgui::setResource ( SUIT_ResourceMgr *  r)
virtual

Definition at line 339 of file Yacsgui.cxx.

References _myresource, DEBTRACE, Yacsgui_Resource::preferencesChanged(), and Yacsgui_Resource.

Referenced by initialize().

340 {
341  DEBTRACE("Yacsgui::setResource");
342  _myresource = new Yacsgui_Resource(r);
344 }
void Yacsgui::studyActivated ( )
virtual

Definition at line 362 of file Yacsgui.cxx.

References _oldStudyId, _studyContextMap, and DEBTRACE.

Referenced by initialize().

363 {
364  int newStudyId = getApp()->activeStudy()->id();
365  DEBTRACE("Yacsgui::studyActivated " << _oldStudyId << " " << newStudyId);
366 
367  if (_oldStudyId != -1)
368  {
369  _studyContextMap[_oldStudyId] = QtGuiContext::getQtCurrent();
370  if (_studyContextMap.count(newStudyId))
371  {
372  DEBTRACE("switch to valid context " << QtGuiContext::getQtCurrent() << " " << _studyContextMap[newStudyId]);
373  QtGuiContext::setQtCurrent(_studyContextMap[newStudyId]);
374  }
375  else
376  {
377  DEBTRACE("no switch to null context");
378  }
379  }
380  _oldStudyId = newStudyId;
381 }
void Yacsgui::viewManagers ( QStringList &  list) const
virtual

Definition at line 150 of file Yacsgui.cxx.

References DEBTRACE.

151 {
152  DEBTRACE("Yacsgui::viewManagers");
153  list.append( QxScene_Viewer::Type() );
154 }
void Yacsgui::windows ( QMap< int, int > &  theMap) const

Definition at line 217 of file Yacsgui.cxx.

References DEBTRACE.

218 {
219  DEBTRACE("Yacsgui::windows");
220  theMap.clear();
221  theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
222  theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
223 }

Friends And Related Function Documentation

friend class Yacsgui_Resource
friend

Definition at line 47 of file Yacsgui.hxx.

Referenced by setResource().

Member Data Documentation

SUIT_ViewWindow* Yacsgui::_currentSVW
protected
YACS::HMI::GenericGui* Yacsgui::_genericGui
protected
Yacsgui_Resource* Yacsgui::_myresource
protected

Definition at line 82 of file Yacsgui.hxx.

Referenced by createPreferences(), preferencesChanged(), and setResource().

int Yacsgui::_oldStudyId = -1
staticprotected

Definition at line 85 of file Yacsgui.hxx.

Referenced by studyActivated().

bool Yacsgui::_selectFromTree
protected

Definition at line 81 of file Yacsgui.hxx.

Referenced by onDblClick(), onWindowActivated(), and Yacsgui().

std::map<int, YACS::HMI::QtGuiContext*> Yacsgui::_studyContextMap
protected

Definition at line 84 of file Yacsgui.hxx.

Referenced by deactivateModule(), onWindowActivated(), studyActivated(), and Yacsgui().

YACS::HMI::SuitWrapper* Yacsgui::_wrapper
protected

Definition at line 79 of file Yacsgui.hxx.

Referenced by initialize(), Yacsgui(), and ~Yacsgui().


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