- if ( !myInterp || !myModule )
- return;
-
- if ( PyObject_HasAttrString( myModule, (char*)"viewTryClose" ) )
- {
- PyObjWrapper res( PyObject_CallMethod( myModule, (char*)"viewTryClose", (char*)"i", pview->getId() ) );
- if ( !res )
- {
- PyErr_Print();
- }
- }
-}
-
-/*!
- \brief Signal handler closing(SUIT_ViewWindow*) of a view
- \param pview view being closed
-*/
-void SALOME_PYQT_ModuleLight::onViewClosed( SUIT_ViewWindow* pview )
-{
- class ViewClose : public PyInterp_LockRequest
- {
- public:
- ViewClose( PyInterp_Interp* _py_interp, SALOME_PYQT_ModuleLight* _obj, const SUIT_ViewWindow* _pview )
- : PyInterp_LockRequest( _py_interp, 0, true ),
- myObj(_obj),myView(_pview) {}
-
- protected:
- virtual void execute()
- {
- myObj->viewClosed( myView );
- }
-
- private:
- SALOME_PYQT_ModuleLight* myObj;
- const SUIT_ViewWindow * myView;
- };
-
- PyInterp_Dispatcher::Get()->Exec( new ViewClose( myInterp, this, pview ) );
-}
-
-/*!
- \brief Processes the view closing, calls Python module's viewClosed() method
- \param pview view being closed
-*/
-void SALOME_PYQT_ModuleLight::viewClosed( const SUIT_ViewWindow* pview )
-{
- if ( !myInterp || !myModule )
- return;
-
- if ( PyObject_HasAttrString( myModule, (char*)"viewClosed" ) )
- {
- PyObjWrapper res( PyObject_CallMethod( myModule, (char*)"viewClosed", (char*)"i", pview->getId() ) );
- if ( !res )
- {
- PyErr_Print();
- }
- }
-}
-
-/*!
- \brief Connects or disconnects signals about activating and cloning view on the module slots
- \param pview view which is connected/disconnected
-*/
-void SALOME_PYQT_ModuleLight::connectView( const SUIT_ViewWindow* pview )
-{
- SUIT_ViewManager* viewMgr = pview->getViewManager();
- SUIT_ViewModel* viewModel = viewMgr ? viewMgr->getViewModel() : 0;
-
- if ( viewMgr )
- {
- disconnect( viewMgr, SIGNAL( tryCloseView( SUIT_ViewWindow* ) ),
- this, SLOT( onViewTryClose( SUIT_ViewWindow* ) ) );
- disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
- this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
-
- connect( viewMgr, SIGNAL( tryCloseView( SUIT_ViewWindow* ) ),
- this, SLOT( onViewTryClose( SUIT_ViewWindow* ) ) );
- connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
- this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
- }
-
- // Connect cloneView() signal of an OCC View
- if ( pview->inherits( "OCCViewer_ViewWindow" ) )
- {
- disconnect( pview, SIGNAL( viewCloned( SUIT_ViewWindow* ) ),
- this, SLOT( onViewCloned( SUIT_ViewWindow* ) ) );
- connect( pview, SIGNAL( viewCloned( SUIT_ViewWindow* ) ),
- this, SLOT( onViewCloned( SUIT_ViewWindow* ) ) );
- }
- // Connect cloneView() signal of Plot2d View manager
- else if ( viewModel && viewModel->inherits( "Plot2d_Viewer" ) )
- {
- disconnect( viewModel, SIGNAL( viewCloned( SUIT_ViewWindow* ) ),
- this, SLOT( onViewCloned( SUIT_ViewWindow* ) ) );
- connect( viewModel, SIGNAL( viewCloned( SUIT_ViewWindow* ) ),
- this, SLOT( onViewCloned( SUIT_ViewWindow* ) ) );
- }
-}
-
-/*!
- \brief Get tag name for the DOM element.
- \param element DOM element
- \return empty string if the element does not have tag name
- \internal
-*/
-static QString tagName( const QDomElement& element )
-{
- return element.tagName().trimmed();
-}
-
-/*!
- \brief Get DOM element's attribute by its name.
- \param element DOM element
- \param attName attribute name
- \return empty string if the element does not have such attribute
- \internal
-*/
-static QString attribute( const QDomElement& element, const QString& attName )
-{
- return element.attribute( attName ).trimmed();
-}
-
-/*!
- \brief Inspect specified string for the boolean value.
-
- This function returns \c true if string represents boolean value:
- - "true", "yes" or "1" for \c true
- - "false", "no" or "0" for \c false
- Second parameter allows to specify what boolean value is expected:
- - 1: \c true
- - 0: \c false
- - other value is not taken into account (return represented value)
-
- \param value inspected string
- \param check expected boolean value
- \return boolean value represented by the string (\a check is not 1 or 0)
- or \c true if value correspond to the specified \a check
-*/
-static bool checkBool( const QString& value, const int check = -1 )
-{
- QString v = value.toLower();
- if ( ( v == "true" || v == "yes" || v == "1" ) && ( check != 0 ) )
- return true;
- if ( ( v == "false" || v == "no" || v == "0" ) && ( check == 0 ) )
- return true;
- return false;
-}
-
-/*!
- \brief Inspect specified string for the integer value.
-
- This function returns returns -1 if item is empty or represents
- an invalid number.
- \param value inspected string
- \param def default value
- \param shift shift value (it is added to the integer value to produce shifted result)
-*/
-static int checkInt( const QString& value, const int def = -1, const int shift = -1 )
-{
- bool bOk;
- int val = value.toInt( &bOk );
- if ( !bOk ) val = def;
- if ( shift > 0 && bOk && val < 0 )
- val += shift;
- return val;
-}
-
-/*!
- \brief Constructor
- \internal
- \param module parent module pointer
- \param fileName XML file path
-*/
-SALOME_PYQT_ModuleLight::XmlHandler::XmlHandler( SALOME_PYQT_ModuleLight* module,
- const QString& fileName )
-: myModule( module )
-{
- if ( fileName.isEmpty() )
- return;
- QFile aFile( fileName );
- if ( !aFile.open( QIODevice::ReadOnly ) )
- return;
- myDoc.setContent( &aFile );
- aFile.close();
-}
-
-/*!
- \brief Parse XML file and create actions.
- \internal
-
- Called by SALOME_PYQT_ModuleLight::activate() in order to create actions
- (menus, toolbars).
-*/
-void SALOME_PYQT_ModuleLight::XmlHandler::createActions()
-{
- // get document element
- QDomElement aDocElem = myDoc.documentElement();
-
- // create main menu actions
- QDomNodeList aMenuList = aDocElem.elementsByTagName( "menu-item" );
- for ( int i = 0; i < aMenuList.count(); i++ ) {
- QDomNode n = aMenuList.item( i );
- createMenu( n );
- }
-
- // create toolbars actions
- QDomNodeList aToolsList = aDocElem.elementsByTagName( "toolbar" );
- for ( int i = 0; i < aToolsList.count(); i++ ) {
- QDomNode n = aToolsList.item( i );
- createToolBar( n );
- }
-}
-
-/*!
- \brief Create popup menu.
- \internal
- \param menu popup menu
- \param context popup menu context
- \param context popup menu parent object name
- \param context popup menu object name
-*/
-void SALOME_PYQT_ModuleLight::XmlHandler::createPopup( QMenu* menu,
- const QString& context,
- const QString& parent,
- const QString& object )
-{
- // get document element
- QDomElement aDocElem = myDoc.documentElement();
-
- // get popup menus actions
- QDomNodeList aPopupList = aDocElem.elementsByTagName( "popupmenu" );
- for ( int i = 0; i < aPopupList.count(); i++ ) {
- QDomNode n = aPopupList.item( i );
- if ( !n.isNull() && n.isElement() ) {
- QDomElement e = n.toElement();
- // QString lab = attribute( e, "label-id" ); // not used //
- QString ctx = attribute( e, "context-id" );
- QString prt = attribute( e, "parent-id" );
- QString obj = attribute( e, "object-id" );
- if ( ctx == context && prt == parent && obj == object ) {
- insertPopupItems( n, menu );
- break;
- }
- }
- }
-}
-
-/*!
- \brief Activate menus
- \internal
- \param enable if \c true menus are activated, otherwise menus are deactivated
-*/
-void SALOME_PYQT_ModuleLight::XmlHandler::activateMenus( bool enable )
-{
- if ( !myModule )
- return;
-
- QtxActionMenuMgr* mgr = myModule->menuMgr();
- int id;
- foreach( id, myMenuItems ) mgr->setEmptyEnabled( id, enable );
-}
-
-/*!
- \brief Create main menu item and insert actions to it.
- \internal
- \param parentNode XML node with menu description
- \param parentMenuId parent menu ID (-1 for top-level menu)
- \param parentPopup parent popup menu (0 for top-level menu)
-*/
-void SALOME_PYQT_ModuleLight::XmlHandler::createMenu( QDomNode& parentNode,
- const int parentMenuId,
- QMenu* parentPopup )
-{
- if ( !myModule || parentNode.isNull() )
- return;
-
- QDomElement parentElement = parentNode.toElement();
- if ( !parentElement.isNull() ) {
- QString plabel = attribute( parentElement, "label-id" );
- int pid = checkInt( attribute( parentElement, "item-id" ) );
- int ppos = checkInt( attribute( parentElement, "pos-id" ) );
- int group = checkInt( attribute( parentElement, "group-id" ),
- myModule->defaultMenuGroup() );
- if ( !plabel.isEmpty() ) {
- QMenu* popup = 0;
- int menuId = -1;
- // create menu
- menuId = myModule->createMenu( plabel, // label
- parentMenuId, // parent menu ID, -1 for top-level menu
- pid, // ID
- group, // group ID
- ppos ); // position
- myMenuItems.append( menuId );
- QDomNode node = parentNode.firstChild();
- while ( !node.isNull() ) {
- if ( node.isElement() ) {
- QDomElement elem = node.toElement();
- QString aTagName = tagName( elem );
- if ( aTagName == "popup-item" ) {
- int id = checkInt( attribute( elem, "item-id" ) );
- int pos = checkInt( attribute( elem, "pos-id" ) );
- int group = checkInt( attribute( elem, "group-id" ),
- myModule->defaultMenuGroup() );
- QString label = attribute( elem, "label-id" );
- QString icon = attribute( elem, "icon-id" );
- QString tooltip = attribute( elem, "tooltip-id" );
- QString accel = attribute( elem, "accel-id" );
- bool toggle = checkBool( attribute( elem, "toggle-id" ) );
-
- // -1 action ID is not allowed : it means that <item-id> attribute is missed in the XML file!
- // also check if the action with given ID is already created
- if ( id != -1 ) {
- // create menu action
- QAction* action = myModule->createAction( id, // ID
- tooltip, // tooltip
- icon, // icon
- label, // menu text
- tooltip, // status-bar text
- QKeySequence( accel ), // keyboard accelerator
- toggle ); // toogled action
- myModule->createMenu( action, // action
- menuId, // parent menu ID
- id, // ID (same as for createAction())
- group, // group ID
- pos ); // position
- }
- }
- else if ( aTagName == "submenu" ) {
- // create sub-menu
- createMenu( node, menuId, popup );
- }
- else if ( aTagName == "separator" ) {
- // create menu separator
- int id = checkInt( attribute( elem, "item-id" ) ); // separator can have ID
- int pos = checkInt( attribute( elem, "pos-id" ) );
- int group = checkInt( attribute( elem, "group-id" ),
- myModule->defaultMenuGroup() );
- QAction* action = myModule->separator();
- myModule->createMenu( action, // separator action
- menuId, // parent menu ID
- id, // ID
- group, // group ID
- pos ); // position
- }
- }
- node = node.nextSibling();
- }
- }
- }
-}
-
-/*!
- \brief Create a toolbar and insert actions to it.
- \param parentNode XML node with toolbar description
-*/
-void SALOME_PYQT_ModuleLight::XmlHandler::createToolBar( QDomNode& parentNode )
-{
- if ( !myModule || parentNode.isNull() )
- return;
-
- QDomElement parentElement = parentNode.toElement();
- if ( !parentElement.isNull() ) {
- QString aLabel = attribute( parentElement, "label-id" );
- if ( !aLabel.isEmpty() ) {
- // create toolbar
- int tbId = myModule->createTool( aLabel );
- QDomNode node = parentNode.firstChild();
- while ( !node.isNull() ) {
- if ( node.isElement() ) {
- QDomElement elem = node.toElement();
- QString aTagName = tagName( elem );
- if ( aTagName == "toolbutton-item" ) {
- int id = checkInt( attribute( elem, "item-id" ) );
- int pos = checkInt( attribute( elem, "pos-id" ) );
- QString label = attribute( elem, "label-id" );
- QString icon = attribute( elem, "icon-id" );
- QString tooltip = attribute( elem, "tooltip-id" );
- QString accel = attribute( elem, "accel-id" );
- bool toggle = checkBool( attribute( elem, "toggle-id" ) );
-
- // -1 action ID is not allowed : it means that <item-id> attribute is missed in the XML file!
- // also check if the action with given ID is already created
- if ( id != -1 ) {
- // create toolbar action
- QAction* action = myModule->createAction( id, // ID
- tooltip, // tooltip
- icon, // icon
- label, // menu text
- tooltip, // status-bar text
- QKeySequence( accel ), // keyboard accelerator
- toggle ); // toogled action
- myModule->createTool( action, tbId, -1, pos );
- }
- }
- else if ( aTagName == "separatorTB" || aTagName == "separator" ) {
- // create toolbar separator
- int pos = checkInt( attribute( elem, "pos-id" ) );
- QAction* action = myModule->separator();
- myModule->createTool( action, tbId, -1, pos );
- }
- }
- node = node.nextSibling();
- }
- }
- }
-}
-
-/*!
- \brief Fill popup menu with the items.
- \param parentNode XML node with popup menu description
- \param menu popup menu
-*/
-void SALOME_PYQT_ModuleLight::XmlHandler::insertPopupItems( QDomNode& parentNode, QMenu* menu )
-{
- if ( !myModule && parentNode.isNull() )
- return;
-
- // we create popup menus without help of QtxPopupMgr
- QDomNode node = parentNode.firstChild();
- while ( !node.isNull() ) {
- if ( node.isElement() ) {
- QDomElement elem = node.toElement();
- QString aTagName = tagName( elem );
- QList<QAction*> actions = menu->actions();
- if ( aTagName == "popup-item" ) {
- // insert a command item
- int id = checkInt( attribute( elem, "item-id" ) );
- int pos = checkInt( attribute( elem, "pos-id" ) );
- QString label = attribute( elem, "label-id" );
- QString icon = attribute( elem, "icon-id" );
- QString tooltip = attribute( elem, "tooltip-id" );
- QString accel = attribute( elem, "accel-id" );
- bool toggle = checkBool( attribute( elem, "toggle-id" ) );
-
- // -1 action ID is not allowed : it means that <item-id> attribute is missed in the XML file!
- // also check if the action with given ID is already created
- if ( id != -1 ) {
- QAction* action = myModule->createAction( id, // ID
- tooltip, // tooltip
- icon, // icon
- label, // menu text
- tooltip, // status-bar text
- QKeySequence( accel ), // keyboard accelerator
- toggle ); // toogled action
- QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0;
- menu->insertAction( before, action );
- }
- }
- else if ( aTagName == "submenu" ) {
- // create sub-menu
- ////int id = checkInt( attribute( elem, "item-id" ) ); // not used //
- int pos = checkInt( attribute( elem, "pos-id" ) );
- QString label = attribute( elem, "label-id" );
- QString icon = attribute( elem, "icon-id" );
-
- QIcon anIcon;
- if ( !icon.isEmpty() ) {
- QPixmap pixmap = myModule->getApp()->resourceMgr()->loadPixmap( myModule->name(), icon );
- if ( !pixmap.isNull() )
- anIcon = QIcon( pixmap );
- }
-
- QMenu* newPopup = menu->addMenu( anIcon, label );
- QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0;
- menu->insertMenu( before, newPopup );
- insertPopupItems( node, newPopup );
- }
- else if ( aTagName == "separator" ) {
- // create menu separator
- int pos = checkInt( attribute( elem, "pos-id" ) );
- QAction* action = myModule->separator();
- QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0;
- menu->insertAction( before, action );
- }
- }
- node = node.nextSibling();
- }
-}
-
-/*
- * Save study request.
- * Called when user save study.
- */
-void SALOME_PYQT_ModuleLight::save(QStringList& theListOfFiles)
-{
- MESSAGE("SALOME_PYQT_ModuleLight::save()")
- // perform synchronous request to Python event dispatcher
- class SaveEvent: public PyInterp_LockRequest
- {
- public:
- SaveEvent(PyInterp_Interp* _py_interp,
- SALOME_PYQT_ModuleLight* _obj,
- QStringList& _files_list)
- : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
- myObj( _obj ) ,
- myFilesList(_files_list) {}
- protected:
- virtual void execute()
- {
- myObj->saveEvent(myFilesList);
- }
- private:
- SALOME_PYQT_ModuleLight* myObj;
- QStringList& myFilesList;
- };
-
- // Posting the request only if dispatcher is not busy!
- // Executing the request synchronously
- if ( !PyInterp_Dispatcher::Get()->IsBusy() )
- PyInterp_Dispatcher::Get()->Exec( new SaveEvent( myInterp, this, theListOfFiles ) );
-}
-
-void SALOME_PYQT_ModuleLight::saveEvent(QStringList& theListOfFiles)
-{
- MESSAGE("SALOME_PYQT_ModuleLight::saveEvent()");
- QStringList::Iterator it = theListOfFiles.begin();
- // Python interpreter should be initialized and Python module should be
- // import first
- if ( !myInterp || !myModule || (it == theListOfFiles.end()))
- return;
-
- if ( PyObject_HasAttrString(myModule, (char*)"saveFiles") ) {
- // temporary set myInitModule because saveEvent() method
- // might be called by the framework when this module is inactive,
- // but still it should be possible to access this module's data
- // from Python
- myInitModule = this;
-
- PyObjWrapper res( PyObject_CallMethod( myModule, (char*)"saveFiles",
- (char*)"s", (*it).toLatin1().constData()));
-
- myInitModule = 0;
-
- if( !res ) {
- PyErr_Print();
- }
- else{
- // parse the return value
- // result can be one string...
- if ( PyString_Check( res ) ) {
- QString astr = PyString_AsString( res );
- //SCRUTE(astr);
- theListOfFiles.append(astr);
- }
- //also result can be a list...
- else if ( PyList_Check( res ) ) {
- int size = PyList_Size( res );
- for ( int i = 0; i < size; i++ ) {
- PyObject* value = PyList_GetItem( res, i );
- if( value && PyString_Check( value ) ) {
- theListOfFiles.append( PyString_AsString( value ) );
- }
- }
- }
- }
- }
-}
-
-/*
- * Python dump request.
- * Called when user activates dump study operation.
- */
-void SALOME_PYQT_ModuleLight::dumpPython(QStringList& theListOfFiles)
-{
- MESSAGE("SALOME_PYQT_ModuleLight::dumpPython()")
- // perform synchronous request to Python event dispatcher
- class DumpEvent: public PyInterp_LockRequest
- {
- public:
- DumpEvent(PyInterp_Interp* _py_interp,
- SALOME_PYQT_ModuleLight* _obj,
- QStringList& _files_list)
- : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
- myObj( _obj ) ,
- myFilesList(_files_list) {}
- protected:
- virtual void execute()
- {
- myObj->dumpEvent(myFilesList);
- }
- private:
- SALOME_PYQT_ModuleLight* myObj;
- QStringList& myFilesList;
- };
-
- // Posting the request only if dispatcher is not busy!
- // Executing the request synchronously
- if ( !PyInterp_Dispatcher::Get()->IsBusy() )
- PyInterp_Dispatcher::Get()->Exec( new DumpEvent( myInterp, this, theListOfFiles ) );
-}
-
-void SALOME_PYQT_ModuleLight::dumpEvent(QStringList& theListOfFiles)
-{
- MESSAGE("SALOME_PYQT_ModuleLight::dumpEvent()");
- QStringList::Iterator it = theListOfFiles.begin();
- // Python interpreter should be initialized and Python module should be
- // import first
- if ( !myInterp || !myModule || (it == theListOfFiles.end()))
- return;
-
- if ( PyObject_HasAttrString(myModule, (char*)"dumpStudy") ) {
- // temporary set myInitModule because dumpEvent() method
- // might be called by the framework when this module is inactive,
- // but still it should be possible to access this module's data
- // from Python
- myInitModule = this;
-
- PyObjWrapper res( PyObject_CallMethod( myModule, (char*)"dumpStudy",
- (char*)"s", (*it).toLatin1().constData()));
-
- myInitModule = 0;
-
- if( !res ) {
- PyErr_Print();
- }
- else{
- // parse the return value
- // result can be one string...
- if ( PyString_Check( res ) ) {
- QString astr = PyString_AsString( res );
- //SCRUTE(astr);
- theListOfFiles.append(astr);
- }
- //also result can be a list...
- else if ( PyList_Check( res ) ) {
- int size = PyList_Size( res );
- for ( int i = 0; i < size; i++ ) {
- PyObject* value = PyList_GetItem( res, i );
- if( value && PyString_Check( value ) ) {
- theListOfFiles.append( PyString_AsString( value ) );
- }
- }
- }
- }
- }
-}
-
-/*
- * Open study request.
- * Called when user open study.
- */
-bool SALOME_PYQT_ModuleLight::open(QStringList theListOfFiles)
-{
- MESSAGE("SALOME_PYQT_ModuleLight::open()");
- // perform synchronous request to Python event dispatcher
- bool opened = false;
- class OpenEvent: public PyInterp_LockRequest
- {
- public:
- OpenEvent(PyInterp_Interp* _py_interp,
- SALOME_PYQT_ModuleLight* _obj,
- QStringList _files_list,
- bool& _opened)
- : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
- myObj( _obj ) ,
- myFilesList(_files_list),
- myOpened(_opened) {}
- protected:
- virtual void execute()
- {
- myObj->openEvent(myFilesList,myOpened);
- }
-
- private:
- SALOME_PYQT_ModuleLight* myObj;
- QStringList myFilesList;
- bool& myOpened;
- };
-
- // Posting the request only if dispatcher is not busy!
- // Executing the request synchronously
- if ( !PyInterp_Dispatcher::Get()->IsBusy() )
- PyInterp_Dispatcher::Get()->Exec( new OpenEvent( myInterp, this, theListOfFiles, opened) );
- return opened;
-}
-
-
-void SALOME_PYQT_ModuleLight::openEvent(QStringList theListOfFiles, bool &opened)
-{
- MESSAGE("SALOME_PYQT_ModuleLight::openEvent()");
- // Python interpreter should be initialized and Python module should be
- // import first
- if ( !myInterp || !myModule || theListOfFiles.isEmpty())
- return;
- QStringList* theList = new QStringList(theListOfFiles);
-
-#if SIP_VERSION < 0x040800
- PyObjWrapper sipList( sipBuildResult( 0, "M", theList, sipClass_QStringList) );
-#else
- PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
-#endif
- if ( PyObject_HasAttrString(myModule , (char*)"openFiles") ) {
- PyObjWrapper res( PyObject_CallMethod( myModule, (char*)"openFiles",
- (char*)"O", sipList.get()));
- if( !res || !PyBool_Check( res )) {
- PyErr_Print();
- opened = false;
- }
- else{
- opened = PyObject_IsTrue( res );
-
- }
- }
-}
-
-/*
- * Create new empty Data Object and return its entry
- */
-QString SALOME_PYQT_ModuleLight::createObject(const QString& parent)
-{
- SALOME_PYQT_DataObjectLight* obj=0;
- if(!parent.isEmpty())
- {
- SALOME_PYQT_DataObjectLight* parentObj = findObject(parent);
- if(parentObj)
- {
- obj = new SALOME_PYQT_DataObjectLight(parentObj);
- }
- }
- else
- {
- SALOME_PYQT_DataModelLight* dm =
- dynamic_cast<SALOME_PYQT_DataModelLight*>( dataModel());
- if(dm)
- {
- obj = new SALOME_PYQT_DataObjectLight(dm->getRoot());
- }
- }
- if (obj)
- return obj->entry();
- else
- return QString::null;
-}
-
-/*
- * Create new Data Object with name, icon and tooltip
- * and return its entry
- */
-QString SALOME_PYQT_ModuleLight::createObject(const QString& aname,
- const QString& iconname,
- const QString& tooltip,
- const QString& parent)
-{
- QString entry = createObject(parent);
- SALOME_PYQT_DataObjectLight* obj = findObject(entry);
-
- if(obj)
- {
- obj->setName(aname);
- obj->setToolTip(tooltip);
- obj->setIcon(iconname);
- return obj->entry();
- }
- else
- return QString::null;
-}
-
-/*
- * Find object by entry
- */
-SALOME_PYQT_DataObjectLight* SALOME_PYQT_ModuleLight::findObject(const QString& entry)
-{
- SALOME_PYQT_DataObjectLight* obj = 0;
- SALOME_PYQT_DataModelLight* dm =
- dynamic_cast<SALOME_PYQT_DataModelLight*>( dataModel());
- if(!entry.isEmpty() && dm ){
- for ( SUIT_DataObjectIterator it( dm->getRoot(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
- SALOME_PYQT_DataObjectLight* curentobj =
- dynamic_cast<SALOME_PYQT_DataObjectLight*>( it.current() );
-
- if(curentobj && curentobj->entry() == entry) {
- obj = curentobj;
- return obj;
- }