*/
void LightApp_Application::onSelection()
{
+ MESSAGE("onSelection_1")
onSelectionChanged();
+ MESSAGE("onSelection_2")
if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
((LightApp_Module*)activeModule())->selectionChanged();
+ MESSAGE("onSelection_3")
}
/*!
}
-void SALOME_PYQT_ModuleLight::setSelected( const DataObjectList&, const bool)
+void SALOME_PYQT_ModuleLight::setSelected( const QStringList& entries, const bool isUnused)
{
MESSAGE("setSelected");
-
+ return myHelper->selectionUpdated(entries);
}
mySelector = new SALOME_PYQT_Selector(this, this->getApp()->selectionMgr());
}
mySelector->setLocalEntries(entries);
- emit selectionChanged();
+ emit localSelectionChanged();
}
void getSelected( DataObjectList& ) const;
unsigned long getModifiedTime() const;
SUIT_DataObject* root() const;
- void setSelected( const DataObjectList&, const bool = false );
+ void setSelected( const QStringList&, const bool = false );
protected:
CAM_DataModel* createDataModel();
signals:
void selectionChanged();
+ void localSelectionChanged();
private:
PyModuleHelper* myHelper;
PyInterp_Dispatcher::Get()->Exec( new ActionReq( myInterp, this, myModule->actionId( action ) ) );
}
+/*!
+ \brief update selection from other views or modules.
+
+ Called when selection is modified outside.
+*/
+void PyModuleHelper::selectionUpdated(const QStringList& entries)
+{
+ FuncMsg fmsg( "PyModuleHelper::selectionUpdated()" );
+
+ // perform synchronous request to Python event dispatcher
+ class SelectionReq : public PyInterp_LockRequest
+ {
+ public:
+ SelectionReq( PyInterp_Interp* _py_interp,
+ PyModuleHelper* _helper,
+ const QStringList& _entries )
+ : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+ myHelper( _helper ),
+ myEntries( _entries )
+ {}
+ protected:
+ virtual void execute()
+ {
+ myHelper->internalSelectionUpdated( myEntries );
+ }
+ private:
+ PyModuleHelper* myHelper;
+ const QStringList& myEntries;
+ };
+
+ // get sender action
+ QAction* action = qobject_cast<QAction*>( sender() );
+ if ( !action )
+ return;
+
+ // post request
+ PyInterp_Dispatcher::Get()->Exec( new SelectionReq( myInterp, this, entries ) );
+}
+
/*!
\brief Process context popup menu request.
}
}
+/*!
+ \brief update selection from other views or modules
+ \internal
+
+ Performs the following actions:
+ - calls Python module's onSelectionpdated(entries) method
+
+ \param list of entries
+*/
+void PyModuleHelper::internalSelectionUpdated(const QStringList& entries)
+{
+ FuncMsg fmsg("--- PyModuleHelper::internalSelectionUpdated()");
+
+ // Python interpreter should be initialized and Python module should be imported first
+ if (!myInterp || !myPyModule)
+ return; // Error
+
+ QStringList* theList = new QStringList(entries);
+
+#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(myPyModule, (char*) "onSelectionUpdated"))
+ {
+ PyObjWrapper res(PyObject_CallMethod(myPyModule, (char*) "onSelectionUpdated", (char*) "O", sipList.get()));
+
+ if (!res)
+ {
+ PyErr_Print();
+ }
+ }
+}
+
/*!
\brief Context popup menu handling callback function
\internal
void preferenceChanged( const QString&, const QString&, const QString& setting );
void studyActivated( SUIT_Study* );
void actionActivated();
+ void selectionUpdated(const QStringList&);
void contextMenu( const QString&, QMenu* );
void createPreferences();
void activeViewChanged( SUIT_ViewWindow* );
void internalPreferencesChanged( const QString&, const QString& );
void internalStudyChanged( SUIT_Study* );
void internalActionActivated( int );
+ void internalSelectionUpdated(const QStringList&);
void internalContextMenu( const QString&, QMenu* );
void internalCreatePreferences();
void internalActiveViewChanged( SUIT_ViewWindow* );
MESSAGE("constructor");
if (myPyModule)
{
- connect(myPyModule, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ connect(myPyModule, SIGNAL(localSelectionChanged()), this, SLOT(onSelectionChanged()));
}
setModified();
}
if (myEntries.count() == 0 || myModifiedTime < myPyModule->getModifiedTime())
fillEntries(myEntries);
- DataObjectList objList;
- for (SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it)
- {
- const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>((*it).operator->());
- if (owner && myEntries.contains(owner->entry()))
- objList.append(myEntries[owner->entry()]);
- }
-
- myPyModule->setSelected(objList);
+// DataObjectList objList;
+// for (SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it)
+// {
+// const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>((*it).operator->());
+// if (owner && myEntries.contains(owner->entry()))
+// objList.append(myEntries[owner->entry()]);
+// }
+//
+// myPyModule->setSelected(objList);
mySelectedList.clear();
}
if (!myPyModule)
return;
- for (SUIT_DataObjectIterator it(myPyModule->root(), SUIT_DataObjectIterator::DepthLeft); it.current(); ++it)
- {
- LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(it.current());
- if (obj)
- entries.insert(obj->entry(), obj);
- }
+// for (SUIT_DataObjectIterator it(myPyModule->root(), SUIT_DataObjectIterator::DepthLeft); it.current(); ++it)
+// {
+// LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(it.current());
+// if (obj)
+// entries.insert(obj->entry(), obj);
+// }
setModified();
}