X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLightApp%2FLightApp_Selection.cxx;h=87e0d50095396f24b6ca3987e5f481cbd4163477;hb=7397622d22624ab84dd52c68a276e2cf50d262fb;hp=5620c41d389b82ada1e64ea751f55098b6ff5b53;hpb=399155730966dfc225fbb24f66204b05664385f2;p=modules%2Fgui.git diff --git a/src/LightApp/LightApp_Selection.cxx b/src/LightApp/LightApp_Selection.cxx index 5620c41d3..87e0d5009 100644 --- a/src/LightApp/LightApp_Selection.cxx +++ b/src/LightApp/LightApp_Selection.cxx @@ -1,17 +1,20 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// Copyright (C) 2007-2015 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 +// // 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 +// License as published by the Free Software Foundation; either +// 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 +// 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 +// 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 @@ -24,8 +27,15 @@ #include "LightApp_Application.h" #include "LightApp_Displayer.h" +#include "CAM_Module.h" + #include "SUIT_Session.h" #include "SUIT_ViewWindow.h" +#include "SUIT_ViewManager.h" +#include "SUIT_Desktop.h" +#include "SUIT_Selector.h" + +#include /*! Constructor @@ -47,13 +57,12 @@ LightApp_Selection::~LightApp_Selection() */ void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr) { - myPopupClient = client; - myStudy = 0; - - if( mgr ) - { - if( mgr->application() ) + myContext = client; + + if ( mgr ) { + if ( mgr->application() ) myStudy = dynamic_cast( mgr->application()->activeStudy() ); + if( !myStudy ) return; @@ -62,140 +71,198 @@ void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr mgr->selected( sel, client ); //2) to take such owners from other popup clients that it's entry is different with every entry from current list - QPtrList aSelectors; + QList aSelectors; mgr->selectors( aSelectors ); - for( SUIT_Selector* selector = aSelectors.first(); selector; selector = aSelectors.next() ) + QListIterator it( aSelectors ); + while ( it.hasNext() ) { - qDebug( selector->type() ); - if( selector->type()!=client ) - { - mgr->selected( cur_sel, selector->type() ); - 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 + SUIT_Selector* selector = it.next(); + if ( selector->type() != client && selector->isEnabled() ) { + selector->selected( cur_sel ); + + 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 = myStudy->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() ); + */ } } +QString LightApp_Selection::referencedToEntry( const QString& entry ) const +{ + return myStudy->referencedToEntry( entry ); +} + /*! Gets count of entries. */ int LightApp_Selection::count() const { - return myEntries.count(); + return myObjects.size(); } /*! - Gets QtxValue(); + Gets global parameters. */ -QtxValue LightApp_Selection::param( 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( param( 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 QtxValue( vis, 0 ); + 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=="component" ) - { - return myStudy->componentDataType( myEntries[ ind ] ); - } - - else if( p=="isComponent" ) - { - return QtxValue( myStudy->isComponent( myEntries[ ind ] ), 0 ); +/*! + 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 v; +} + */ +/*! + Gets global parameters. client, isActiveView, activeView etc. +*/ + //QVariant LightApp_Selection::contextParameter( const QString& p ) const +QVariant LightApp_Selection::parameter( const QString& p ) const +{ + QVariant v; - else if( p=="isReference" ) - return QtxValue( isReference( ind ), false ); - - else if( p=="canBeDisplayed" ) - { - QString mod_name = app->moduleTitle( param( 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 + 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(); + 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 QtxValue(); + return v; } /*! - Gets global parameters. client, isActiveView, activeView etc. + Gets the object parameter. */ -QtxValue LightApp_Selection::globalParam( const QString& p ) const +//QVariant LightApp_Selection::objectParameter( const int idx, const QString& p ) const +QVariant LightApp_Selection::parameter( const int idx, const QString& p ) const { - if ( p == "client" ) return QtxValue( myPopupClient ); - else if ( p == "activeModule" ) - { - LightApp_Application* app = dynamic_cast( myStudy->application() ); - QString mod_name = app ? QString( app->activeModule()->name() ) : QString::null; - //cout << "activeModule : " << mod_name.latin1() << endl; - if( !mod_name.isEmpty() ) - return mod_name; - else - return QtxValue(); + 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 QtxValue( (bool)activeVW() ); - else if ( p == "activeView" ) return QtxValue( activeViewType() ); -#ifndef WNT - else return QtxPopupMgr::Selection::globalParam( p ); -#else - else return Selection::globalParam( p ); -#endif + + 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; } /*! @@ -203,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(); } /*! @@ -213,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; } /*! @@ -230,7 +294,7 @@ QString LightApp_Selection::activeViewType() const if ( vm ) return vm->getType(); } - return QString::null; + return QString(); } /*! @@ -243,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 ); +}