X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLIGHTGUI%2FLIGHTGUI_Selection.cxx;h=3d0309f0e51d5a07c44395b19c0a87d10a5e68f0;hb=d8a6e5cb29a698ab256852b40b1eb067c9ab3640;hp=82db12c09a2f18ac6c1ebc8ac8cce7a1a651dbd3;hpb=3ef6336ba646d7a3beb2d34f2e2f405f3f3729d3;p=samples%2Flight.git diff --git a/src/LIGHTGUI/LIGHTGUI_Selection.cxx b/src/LIGHTGUI/LIGHTGUI_Selection.cxx index 82db12c..3d0309f 100644 --- a/src/LIGHTGUI/LIGHTGUI_Selection.cxx +++ b/src/LIGHTGUI/LIGHTGUI_Selection.cxx @@ -1,83 +1,142 @@ -// LIGHT : sample (no-corba-engine) SALOME module +// Copyright (C) 2005-2013 OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// 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. // -// 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. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// Author : Julia DOROVSKIKH -// Date : 01/01/2005 -// $Header$ +// LIGHT : sample (no-corba-engine) SALOME module +// File : LIGHTGUI_Selection.cxx +// Author : Julia DOROVSKIKH +// #include "LIGHTGUI_Selection.h" -#include "LIGHTGUI_DataOwner.h" +#include "LIGHTGUI_DataModel.h" +#include "LIGHTGUI.h" + +#include +#include +#include +#include +#include +#include +#include -#include +/*! + \class LIGHTGUI_Selection + \brief Handles the data selection, builds the rules to be used in the + popup menu. +*/ -//================================================================================= -// function : LIGHTGUI_Selection() -// purpose : constructor -//================================================================================= -LIGHTGUI_Selection::LIGHTGUI_Selection ( const QString& client, - SalomeApp_SelectionMgr* mgr ) +/*! + \brief Constructor. +*/ +LIGHTGUI_Selection::LIGHTGUI_Selection() +: LightApp_Selection() { - myPopupClient = client; +} - if ( mgr ) { - SUIT_DataOwnerPtrList sel; - mgr->selected( sel); - SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), - aLast = sel.end(); - for ( ; anIt != aLast; anIt++ ) { - SUIT_DataOwner* owner = (SUIT_DataOwner*)( (*anIt).get() ); - LIGHTGUI_DataOwner* sowner = dynamic_cast( owner ); - if ( sowner && sowner->lineNb() > 0 ) - myTypes.append( "TextLine" ); - else - myTypes.append( "Unknown" ); +/*! + \brief Destructor. +*/ +LIGHTGUI_Selection::~LIGHTGUI_Selection() +{ +} + +/*! + \brief Get selection parameter value. + \param index selected object index + \param p parameter name + \return parameter value +*/ +QVariant LIGHTGUI_Selection::parameter( const int index, const QString& p ) const +{ + if ( p == "type" ) + return type( index ); + else if ( p == "empty" ) + return isEmpty( index ); + else if ( p == "visible" ) + return isVisible( index ); + return LightApp_Selection::parameter( p ); +} + +/*! + \brief Check if selected object is empty line (beginning of the paragraph) + \param index selected object index + \return \c true if selected object is empty line +*/ +bool LIGHTGUI_Selection::isEmpty( const int index ) const +{ + bool empty = true; + LightApp_Application* app = dynamic_cast( study()->application() ); + if ( app ) { + LIGHTGUI_DataModel* dm = dynamic_cast( app->activeModule()->dataModel() ); + if ( dm ) { + QString line = dm->getLineText( LIGHTGUI_DataModel::id( entry( index ) ) ); + empty = line.isEmpty(); } } + return empty; } -//================================================================================= -// function : ~LIGHTGUI_Selection() -// purpose : destructor -//================================================================================= -LIGHTGUI_Selection::~LIGHTGUI_Selection() +/*! + \brief Check if selected object is displayed in the active viewer. + \param index selected object index + \return \c true if selected object is displayed +*/ +bool LIGHTGUI_Selection::isVisible( const int index ) const { + bool visible = false; + LightApp_Application* app = dynamic_cast( study()->application() ); + if ( app ) { + SUIT_ViewManager* vm = app->activeViewManager(); + if ( vm && vm->getType() == "OCCViewer" ) { + SOCC_Viewer* v = (SOCC_Viewer*)vm->getViewModel(); + if ( v ) { + QString e = entry( index ); + int id = LIGHTGUI_DataModel::id( e ); + visible = id != -1 && v->isVisible( new SALOME_InteractiveObject( e.toLatin1(), "" ) ); + } + } + } + return visible; } -//================================================================================= -// function : count() -// purpose : returns number of supported types -//================================================================================= -int LIGHTGUI_Selection::count() const +/*! + \brief Get selected object type. + \param index selected object index + \return object type +*/ +QString LIGHTGUI_Selection::type( const int index ) const { - return myTypes.count(); + return lineNb( entry( index ) ) > 0 ? "TextLine" : "Unknown"; } -//================================================================================= -// function : param() -// purpose : returns selection parameter value -//================================================================================= -QtxValue LIGHTGUI_Selection::param ( const int ind, const QString& p ) const +/*! + \brief Get line number corresponding to the selected object. + \param index selected object index + \return line number or 0 if the pbject is not appropriate +*/ +int LIGHTGUI_Selection::lineNb( const QString& e ) const { - if ( p == "client" ) - return myPopupClient; - else - return myTypes[ind]; + int pos = 0; // invalid position + LightApp_Application* app = dynamic_cast( study()->application() ); + if ( app ) { + LIGHTGUI_DataModel* dm = dynamic_cast( app->activeModule()->dataModel() ); + if ( dm ) { + pos = dm->lineNb( e ); + } + } + return pos; }