X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLightApp%2FLightApp_Selection.cxx;h=ec86515eb7c51ab7d8b954ecb54dbc9afd342957;hb=aff8765b1aa57fbe9b0163341cde44799807b054;hp=09fab94d7b1f69f99ea10dbddd34eb319a0fafa1;hpb=1c889394b028b786898a995d38c07c8f3d564837;p=modules%2Fgui.git diff --git a/src/LightApp/LightApp_Selection.cxx b/src/LightApp/LightApp_Selection.cxx index 09fab94d7..ec86515eb 100644 --- a/src/LightApp/LightApp_Selection.cxx +++ b/src/LightApp/LightApp_Selection.cxx @@ -1,24 +1,25 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "LightApp_Selection.h" #include "LightApp_SelectionMgr.h" #include "LightApp_DataOwner.h" @@ -34,6 +35,8 @@ #include "SUIT_Desktop.h" #include "SUIT_Selector.h" +#include + /*! Constructor */ @@ -54,12 +57,12 @@ LightApp_Selection::~LightApp_Selection() */ void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr) { - myPopupClient = client; - - if( mgr ) - { - if( mgr->application() ) + myContext = client; + + if ( mgr ) { + if ( mgr->application() ) myStudy = dynamic_cast( mgr->application()->activeStudy() ); + if( !myStudy ) return; @@ -74,37 +77,47 @@ void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr while ( it.hasNext() ) { SUIT_Selector* selector = it.next(); - if( selector->type() != client && selector->isEnabled() ) - { - //mgr->selected( cur_sel, selector->type() ); + if ( selector->type() != client && selector->isEnabled() ) { selector->selected( cur_sel ); - SUIT_DataOwnerPtrList::const_iterator aLIt = cur_sel.begin(), aLLast = cur_sel.end(); - for( ; aLIt!=aLLast; aLIt++ ) - sel.append( *aLIt ); //check entry and don't append if such entry is in list already + + for ( SUIT_DataOwnerPtrList::const_iterator aLIt = cur_sel.begin(); aLIt != cur_sel.end(); ++aLIt ) + sel.append( *aLIt ); //check entry and don't append if such entry is in list already } } //3) to analyse owner and fill internal data structures - SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end(); - QMap entries; - QString entry; - int num=0; - for( ; anIt!=aLast; anIt++ ) + + int num = 0; + QSet entries; + myObjects.resize( sel.size() ); + myObjects.fill( ObjectInfo() ); + for ( SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(); anIt != sel.end(); anIt++ ) { LightApp_DataOwner* sowner = dynamic_cast( (*anIt ).get() ); - if( sowner ) + if ( sowner ) { - entry = referencedToEntry( sowner->entry() ); - if( entries.contains( entry ) ) - continue; - - entries.insert( entry, 0 ); - myEntries.insert( num, entry ); - myIsReferences.insert( num, sowner->entry() != entry ); - processOwner( sowner ); - num++; + QString entry = referencedToEntry( sowner->entry() ); + if ( entries.contains( entry ) ) + continue; + + entries.insert( entry ); + + setObjectInfo( num, OI_Entry, entry ); + setObjectInfo( num, OI_Reference, sowner->entry() != entry ); + + if ( processOwner( sowner ) ) + num++; + else + entries.remove( entry ); } } + + myObjects.resize( num ); + /* + myContextParams.clear(); + myObjectsParams.resize( num ); + myObjectsParams.fill( ParameterMap() ); + */ } } @@ -118,96 +131,138 @@ QString LightApp_Selection::referencedToEntry( const QString& entry ) const */ int LightApp_Selection::count() const { - return myEntries.count(); + return myObjects.size(); } /*! - Gets QVariant(); + Gets global parameters. */ -QVariant LightApp_Selection::parameter( const int ind, const QString& p ) const +/* +QVariant LightApp_Selection::parameter( const QString& p ) const { - LightApp_Application* app = dynamic_cast( myStudy ? myStudy->application() : 0 ); - if( !( ind>=0 && indmoduleTitle( parameter( ind, "component" ).toString() ); - LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false ); - // false in last parameter means that now we doesn't load module, if it isn't loaded - - bool vis = false; - if( d ) - vis = d->IsDisplayed( myEntries[ ind ] ); - else - { - LightApp_Displayer local_d; - vis = local_d.IsDisplayed( myEntries[ ind ] ); - } - return QVariant( vis ); - } - - else if( p=="component" ) - { - return myStudy->componentDataType( myEntries[ ind ] ); - } - - else if( p=="isComponent" ) - { - return QVariant( myStudy->isComponent( myEntries[ ind ] ) ); + QVariant v; + if ( myContextParams.contains( p ) ) + v = myContextParams[p]; + else + v = contextParameter( p ); + if ( !v.isValid() ) + v = QtxPopupSelection::parameter( p ); + LightApp_Selection* that = (LightApp_Selection*)this; + that->myContextParams.insert( p, v ); } + return v; +} +*/ - else if( p=="isReference" ) - return QVariant( isReference( ind ) ); - - else if( p=="displayer" ) - return parameter( ind, "component" ); - - else if( p=="canBeDisplayed" ) - { - QString mod_name = app->moduleTitle( parameter( ind, "component" ).toString() ); - LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false ); - // false in last parameter means that now we doesn't load module, if it isn't loaded - - if ( d ) - return d->canBeDisplayed( myEntries[ ind ] ); - else if ( myEntries[ ind ].startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) ) // object is a Save Point object - return false; - - return true; - //now if displayer is null, it means, that according module isn't loaded, so that we allow to all display/erase - //operations under object +/*! + Gets the object parameter. +*/ + /* +QVariant LightApp_Selection::parameter( const int idx, const QString& p ) const +{ + QVariant v; + if ( 0 <= idx && idx < myObjectsParams.size() ) { + if ( myObjectsParams[idx].contains( p ) ) + v = myObjectsParams[idx][p]; + else { + v = objectParameter( idx, p ); + LightApp_Selection* that = (LightApp_Selection*)this; + that->myObjectsParams[idx].insert( p, v ); + } } - - return QVariant(); + return v; } - + */ /*! Gets global parameters. client, isActiveView, activeView etc. */ + //QVariant LightApp_Selection::contextParameter( const QString& p ) const QVariant LightApp_Selection::parameter( const QString& p ) const { - if ( p == "client" ) return QVariant( myPopupClient ); - else if ( p == "activeModule" ) - { + QVariant v; + + if ( p == "client" ) + v = myContext; + else if ( p == "activeModule" ) { LightApp_Application* app = dynamic_cast( myStudy->application() ); QString mod_name = app ? QString( app->activeModule()->name() ) : QString(); - //cout << "activeModule : " << mod_name.latin1() << endl; - if( !mod_name.isEmpty() ) - return mod_name; - else - return QVariant(); + if ( !mod_name.isEmpty() ) + v = mod_name; + } + else if ( p == "isActiveView" ) + v = activeVW() != 0; + else if ( p == "activeView" ) + v = activeViewType(); + else + v = QtxPopupSelection::parameter( p ); + + return v; +} + +/*! + Gets the object parameter. +*/ +//QVariant LightApp_Selection::objectParameter( const int idx, const QString& p ) const +QVariant LightApp_Selection::parameter( const int idx, const QString& p ) const +{ + LightApp_Application* app = 0; + if ( myStudy ) + app = dynamic_cast( myStudy->application() ); + + QVariant v; + if ( app ) { + QString e = entry( idx ); + if ( !e.isEmpty() ) { + if ( p == "isVisible" ) { + QString mod_name = app->moduleTitle( myStudy->componentDataType( e ) ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false ); + // false in last parameter means that now we doesn't load module, if it isn't loaded + + bool vis = false; + if ( d ) + vis = d->IsDisplayed( e ); + else + vis = LightApp_Displayer().IsDisplayed( e ); + v = vis; + } + else if ( p == "component" || p == "displayer" ) + v = myStudy->componentDataType( e ); + else if ( p == "isComponent" ) + v = myStudy->isComponent( e ); + else if ( p == "isReference" ) + v = isReference( idx ); + else if ( p == "canBeDisplayed" ) { + QString mod_name = app->moduleTitle( myStudy->componentDataType( e ) ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false ); + // false in last parameter means that now we doesn't load module, if it isn't loaded + + if ( d ) + v = d->canBeDisplayed( e ); + else if ( e.startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) ) // object is a Save Point object + v = false; + else + v = true; + //now if displayer is null, it means, that according module isn't loaded, so that we allow to all display/erase + //operations under object + } + } } - else if ( p == "isActiveView" ) return QVariant( (bool)activeVW() ); - else if ( p == "activeView" ) return QVariant( activeViewType() ); - else return QtxPopupSelection::parameter( p ); + + return v; } /*! - Do nothing. To be redefined by successors + Perform additional processing of the selected item (to be redefined by successors if necessary). + Returns \c true by default. + Note: if this method returns \c false, the item will be removed from the items list and + not taken into account when showing popup menu. + + \param owner a data owner being processed + \return \c true if the owner should be collected and \c false otherwise */ -void LightApp_Selection::processOwner( const LightApp_DataOwner* ) +bool LightApp_Selection::processOwner( const LightApp_DataOwner* /*owner*/ ) { + return true; } /*! @@ -215,9 +270,8 @@ void LightApp_Selection::processOwner( const LightApp_DataOwner* ) */ QString LightApp_Selection::entry( const int index ) const { - if ( index >= 0 && index < count() ) - return myEntries[ index ]; - return QString(); + QVariant v = objectInfo( index, OI_Entry ); + return v.canConvert( QVariant::String ) ? v.toString() : QString(); } /*! @@ -225,10 +279,8 @@ QString LightApp_Selection::entry( const int index ) const */ bool LightApp_Selection::isReference( const int index ) const { - if( index >= 0 && index < count() ) - return myIsReferences[ index ]; - else - return false; + QVariant v = objectInfo( index, OI_Reference ); + return v.canConvert( QVariant::Bool ) ? v.toBool() : false; } /*! @@ -255,9 +307,31 @@ SUIT_ViewWindow* LightApp_Selection::activeVW() const SUIT_Application* app = session->activeApplication(); if ( app ) { SUIT_Desktop* desk = app->desktop(); - if ( desk ) - return desk->activeWindow(); + if ( desk ) + return desk->activeWindow(); } } return 0; } + +/*! + Gets specified information about object with index idx. +*/ +QVariant LightApp_Selection::objectInfo( const int idx, const int inf ) const +{ + QVariant res; + if ( 0 <= idx && idx < myObjects.size() ) { + if ( myObjects[idx].contains( inf ) ) + res = myObjects[idx][inf]; + } + return res; +} + +/*! + Sets specified information about object with index idx. +*/ +void LightApp_Selection::setObjectInfo( const int idx, const int inf, const QVariant& val ) +{ + if ( 0 <= idx && idx < myObjects.size() ) + myObjects[idx].insert( inf, val ); +}