1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "LightApp_Selection.h"
24 #include "LightApp_SelectionMgr.h"
25 #include "LightApp_DataOwner.h"
26 #include "LightApp_Study.h"
27 #include "LightApp_Application.h"
28 #include "LightApp_Displayer.h"
30 #include "CAM_Module.h"
32 #include "SUIT_Session.h"
33 #include "SUIT_ViewWindow.h"
34 #include "SUIT_ViewManager.h"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_Selector.h"
38 #include <QtCore/QSet>
43 LightApp_Selection::LightApp_Selection()
51 LightApp_Selection::~LightApp_Selection()
58 void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr)
63 if ( mgr->application() )
64 myStudy = dynamic_cast<LightApp_Study*>( mgr->application()->activeStudy() );
69 //1) to take owners from current popup client
70 SUIT_DataOwnerPtrList sel( true ), cur_sel( true );
71 mgr->selected( sel, client );
73 //2) to take such owners from other popup clients that it's entry is different with every entry from current list
74 QList<SUIT_Selector*> aSelectors;
75 mgr->selectors( aSelectors );
76 QListIterator<SUIT_Selector*> it( aSelectors );
77 while ( it.hasNext() )
79 SUIT_Selector* selector = it.next();
80 if ( selector->type() != client && selector->isEnabled() ) {
81 selector->selected( cur_sel );
83 for ( SUIT_DataOwnerPtrList::const_iterator aLIt = cur_sel.begin(); aLIt != cur_sel.end(); ++aLIt )
84 sel.append( *aLIt ); //check entry and don't append if such entry is in list already
88 //3) to analyse owner and fill internal data structures
91 QSet<QString> entries;
92 myObjects.resize( sel.size() );
93 myObjects.fill( ObjectInfo() );
94 for ( SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(); anIt != sel.end(); anIt++ )
96 LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>( (*anIt ).get() );
99 QString entry = referencedToEntry( sowner->entry() );
100 if ( entries.contains( entry ) )
103 entries.insert( entry );
105 setObjectInfo( num, OI_Entry, entry );
106 setObjectInfo( num, OI_Reference, sowner->entry() != entry );
107 setObjectInfo( num, OI_RefEntry, sowner->entry() );
109 if ( processOwner( sowner ) )
112 entries.remove( entry );
116 myObjects.resize( num );
118 myContextParams.clear();
119 myObjectsParams.resize( num );
120 myObjectsParams.fill( ParameterMap() );
125 QString LightApp_Selection::referencedToEntry( const QString& entry ) const
127 return myStudy->referencedToEntry( entry );
131 Gets count of entries.
133 int LightApp_Selection::count() const
135 return myObjects.size();
139 Gets global parameters.
142 QVariant LightApp_Selection::parameter( const QString& p ) const
145 if ( myContextParams.contains( p ) )
146 v = myContextParams[p];
148 v = contextParameter( p );
150 v = QtxPopupSelection::parameter( p );
151 LightApp_Selection* that = (LightApp_Selection*)this;
152 that->myContextParams.insert( p, v );
159 Gets the object parameter.
162 QVariant LightApp_Selection::parameter( const int idx, const QString& p ) const
165 if ( 0 <= idx && idx < myObjectsParams.size() ) {
166 if ( myObjectsParams[idx].contains( p ) )
167 v = myObjectsParams[idx][p];
169 v = objectParameter( idx, p );
170 LightApp_Selection* that = (LightApp_Selection*)this;
171 that->myObjectsParams[idx].insert( p, v );
178 Gets global parameters. client, isActiveView, activeView etc.
180 //QVariant LightApp_Selection::contextParameter( const QString& p ) const
181 QVariant LightApp_Selection::parameter( const QString& p ) const
187 else if ( p == "activeModule" ) {
188 LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy->application() );
189 QString mod_name = app ? QString( app->activeModule()->name() ) : QString();
190 if ( !mod_name.isEmpty() )
193 else if ( p == "isActiveView" )
195 else if ( p == "activeView" )
196 v = activeViewType();
198 v = QtxPopupSelection::parameter( p );
204 Gets the object parameter.
206 //QVariant LightApp_Selection::objectParameter( const int idx, const QString& p ) const
207 QVariant LightApp_Selection::parameter( const int idx, const QString& p ) const
209 LightApp_Application* app = 0;
211 app = dynamic_cast<LightApp_Application*>( myStudy->application() );
215 QString e = entry( idx );
216 if ( !e.isEmpty() ) {
217 if ( p == "isVisible" ) {
218 QString mod_name = app->moduleTitle( myStudy->componentDataType( e ) );
219 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
220 // false in last parameter means that now we doesn't load module, if it isn't loaded
224 vis = d->IsDisplayed( e );
226 vis = LightApp_Displayer().IsDisplayed( e );
229 else if ( p == "component" || p == "displayer" )
230 v = myStudy->componentDataType( e );
231 else if ( p == "isComponent" )
232 v = myStudy->isComponent( e );
233 else if ( p == "isReference" )
234 v = isReference( idx );
235 else if ( p == "canBeDisplayed" ) {
236 QString mod_name = app->moduleTitle( myStudy->componentDataType( e ) );
237 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
238 // false in last parameter means that now we doesn't load module, if it isn't loaded
241 v = d->canBeDisplayed( e );
242 else if ( e.startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) ) // object is a Save Point object
246 //now if displayer is null, it means, that according module isn't loaded, so that we allow to all display/erase
247 //operations under object
256 Perform additional processing of the selected item (to be redefined by successors if necessary).
257 Returns \c true by default.
258 Note: if this method returns \c false, the item will be removed from the items list and
259 not taken into account when showing popup menu.
261 \param owner a data owner being processed
262 \return \c true if the owner should be collected and \c false otherwise
264 bool LightApp_Selection::processOwner( const LightApp_DataOwner* /*owner*/ )
270 Gets entry with index \a index.
272 QString LightApp_Selection::entry( const int index ) const
274 QVariant v = objectInfo( index, OI_Entry );
275 return v.canConvert( QVariant::String ) ? v.toString() : QString();
279 Returns true if i-th selected object was reference to object with entry( i )
281 bool LightApp_Selection::isReference( const int index ) const
283 QVariant v = objectInfo( index, OI_Reference );
284 return v.canConvert( QVariant::Bool ) ? v.toBool() : false;
288 Gets type of active view manager.
290 QString LightApp_Selection::activeViewType() const
292 SUIT_ViewWindow* win = activeVW();
294 SUIT_ViewManager* vm = win->getViewManager();
296 return vm->getType();
302 Gets active view window.
304 SUIT_ViewWindow* LightApp_Selection::activeVW() const
306 SUIT_Session* session = SUIT_Session::session();
308 SUIT_Application* app = session->activeApplication();
310 SUIT_Desktop* desk = app->desktop();
312 return desk->activeWindow();
319 Gets specified information about object with index idx.
321 QVariant LightApp_Selection::objectInfo( const int idx, const int inf ) const
324 if ( 0 <= idx && idx < myObjects.size() ) {
325 if ( myObjects[idx].contains( inf ) )
326 res = myObjects[idx][inf];
332 Sets specified information about object with index idx.
334 void LightApp_Selection::setObjectInfo( const int idx, const int inf, const QVariant& val )
336 if ( 0 <= idx && idx < myObjects.size() )
337 myObjects[idx].insert( inf, val );