X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOME_PYQT%2FSALOME_PYQT_GUILight%2FSALOME_PYQT_ModuleLight.cxx;h=92fda689fc21d19b37f128857478b1687d75ec28;hb=c1378217edce647cb0a0bbf856d9de5f77003782;hp=7b94636dbe4771bbd69aebc4e15ed76d2eb081bf;hpb=80f32aba5aa2bf61f6278621910d3e81a443d2e8;p=modules%2Fgui.git diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx index 7b94636db..92fda689f 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,20 +20,26 @@ // File : SALOME_PYQT_ModuleLight.cxx // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -#include "SALOME_PYQT_DataModelLight.h" #include "SALOME_PYQT_ModuleLight.h" +#include "SALOME_PYQT_DataModelLight.h" #include "SALOME_PYQT_PyModule.h" +#include "SALOME_PYQT_Selector.h" #include "CAM_Application.h" #include "SUITApp_init_python.hxx" #include "SUIT_DataObjectIterator.h" - +#include "LightApp_Application.h" +#include "LightApp_SelectionMgr.h" +#include "SUIT_DataBrowser.h" #include "sipAPISalomePyQtGUILight.h" #ifndef GUI_DISABLE_CORBA #include #endif +#include +#include + // Py_ssize_t for old Pythons // This code is as recommended by" // http://www.python.org/dev/peps/pep-0353/#conversion-guidelines @@ -57,7 +63,7 @@ // and to get C API from sip : sipBuildResult for example // -#define INIT_FUNCTION initSalomePyQtGUILight +#define INIT_FUNCTION PyInit_SalomePyQtGUILight #if defined(SIP_STATIC_MODULE) extern "C" void INIT_FUNCTION(); #else @@ -79,13 +85,14 @@ extern "C" { SALOME_PYQT_LIGHT_EXPORT CAM_Module* createModule() { - static bool alreadyInitialized = false; + QCoreApplication* app = QCoreApplication::instance(); + bool alreadyInitialized = app && app->property( "salome_pyqt_gui_light_initialized" ).toBool(); // make initialization only once (see comment above) ! if ( !alreadyInitialized ) { PyLockWrapper lck; // GIL acquisition INIT_FUNCTION(); - alreadyInitialized = !alreadyInitialized; + if ( app ) app->setProperty( "salome_pyqt_gui_light_initialized", true ); } return new SALOME_PYQT_ModuleLight(); @@ -102,7 +109,7 @@ extern "C" \brief Constructor */ SALOME_PYQT_ModuleLight::SALOME_PYQT_ModuleLight() - : LightApp_Module( "noname" ) // name is set explicitly at the module initialization + : LightApp_Module( "noname" ), mySelector(0) // name is set explicitly at the module initialization { // initialize helper myHelper = new PyModuleHelper( this ); @@ -128,6 +135,11 @@ void SALOME_PYQT_ModuleLight::initialize( CAM_Application* app ) // ... then call helper myHelper->initialize( app ); + SUIT_DataBrowser* ob = getApp()->objectBrowser(); + if (ob && ob->model()) { + connect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ), + myHelper, SLOT( onObjectBrowserClicked( SUIT_DataObject*, int ) ), Qt::UniqueConnection ); + } } /*! @@ -168,6 +180,8 @@ void SALOME_PYQT_ModuleLight::onModelClosed() { // call helper myHelper->modelClosed(application()->activeStudy()); + if (mySelector) + mySelector->clear(); LightApp_Module::onModelClosed(); } @@ -244,24 +258,27 @@ void SALOME_PYQT_ModuleLight::preferencesChanged( const QString& section, const /*! \brief Save module data. Called when user saves study. \param files output list of files where module stores data + \param url study URL \sa PyModuleHelper::save() */ -void SALOME_PYQT_ModuleLight::save( QStringList& files ) +void SALOME_PYQT_ModuleLight::save( QStringList& files, const QString& url ) { // call helper - myHelper->save( files ); + myHelper->save( files, url ); } /* - \brief Load module data. Called when user opens study - and activates module. - \param files list of files where module data is stored - \sa PyModuleHelper::load() + \brief Load module data. Called when user opens study + and activates module. + \param files list of files where module data is stored + \param url study URL + \return \c true if loading has been finished successfully or \c false otherwise + \sa PyModuleHelper::load() */ -bool SALOME_PYQT_ModuleLight::load( const QStringList& files ) +bool SALOME_PYQT_ModuleLight::load( const QStringList& files, const QString& url ) { // call helper - return myHelper->load( files ); + return myHelper->load( files, url ); } /*! @@ -454,6 +471,22 @@ QColor SALOME_PYQT_ModuleLight::getColor( const QString& entry ) const return color; } +void SALOME_PYQT_ModuleLight::setObjectPosition( const QString& theEntry, int thePos ) +{ + SALOME_PYQT_DataObjectLight* dataObj = findObject( theEntry ); + if ( dataObj ) + dataObj->setPosition(thePos); +} + +int SALOME_PYQT_ModuleLight::getObjectPosition( const QString& theEntry ) +{ + SALOME_PYQT_DataObjectLight* dataObj = findObject( theEntry ); + if ( dataObj ) + return dataObj->position(); + return -1; +} + + /*! \brief Set reference to another data object \param entry data object entry @@ -573,3 +606,71 @@ SALOME_PYQT_DataObjectLight* SALOME_PYQT_ModuleLight::findObject( const QString& } return obj; } + +/*! + \brief not used yet +*/ +void SALOME_PYQT_ModuleLight::getSelected( DataObjectList& ) const +{ + MESSAGE("getSelected"); +} + +/*! + \brief not used yet +*/ +//unsigned long SALOME_PYQT_ModuleLight::getModifiedTime() const +//{ +// MESSAGE("getModifiedTime"); +// return 0; +//} + +/*! + \brief not used yet +*/ +//SUIT_DataObject* SALOME_PYQT_ModuleLight::root() const +//{ +// MESSAGE("root"); +// return NULL; +//} + +/*! + \brief Used to notify a Python light module of a modification of selection in study (propagation of a remote selection) + \param list of study entries +*/ +void SALOME_PYQT_ModuleLight::setSelected( const QStringList& entries, const bool isUnused) +{ + MESSAGE("setSelected"); + return myHelper->selectionUpdated(entries); +} + +/*! + \brief called by Python module to notify a list of study entries locally selected (for selection propagation) + \param list of study entries +*/ +void SALOME_PYQT_ModuleLight::setLocalSelected(const QStringList & entries) +{ + MESSAGE("setLocalSelected"); + if (!mySelector) + { + mySelector = new SALOME_PYQT_Selector(this, this->getApp()->selectionMgr()); + } + mySelector->setLocalEntries(entries); + emit localSelectionChanged(); +} + +void SALOME_PYQT_ModuleLight::enableSelector() +{ + MESSAGE("enableSelector"); + if (!mySelector) + { + mySelector = new SALOME_PYQT_Selector(this, this->getApp()->selectionMgr()); + } + mySelector->setEnabled(true); +} + +void SALOME_PYQT_ModuleLight::disableSelector() +{ + MESSAGE("disableSelector"); + if (mySelector) + mySelector->setEnabled(false); +}