1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "LightApp_Selection.h"
21 #include "LightApp_SelectionMgr.h"
22 #include "LightApp_DataOwner.h"
23 #include "LightApp_Study.h"
24 #include "LightApp_Application.h"
25 #include "LightApp_Displayer.h"
27 #include "SUIT_Session.h"
28 #include "SUIT_ViewWindow.h"
33 LightApp_Selection::LightApp_Selection()
41 LightApp_Selection::~LightApp_Selection()
48 void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr)
50 myPopupClient = client;
55 if( mgr->application() )
56 myStudy = dynamic_cast<LightApp_Study*>( mgr->application()->activeStudy() );
60 //1) to take owners from current popup client
61 SUIT_DataOwnerPtrList sel( true ), cur_sel( true );
62 mgr->selected( sel, client );
64 //2) to take such owners from other popup clients that it's entry is different with every entry from current list
65 QPtrList<SUIT_Selector> aSelectors;
66 mgr->selectors( aSelectors );
67 for( SUIT_Selector* selector = aSelectors.first(); selector; selector = aSelectors.next() )
69 qDebug( selector->type() );
70 if( selector->type()!=client )
72 mgr->selected( cur_sel, selector->type() );
73 SUIT_DataOwnerPtrList::const_iterator aLIt = cur_sel.begin(), aLLast = cur_sel.end();
74 for( ; aLIt!=aLLast; aLIt++ )
75 sel.append( *aLIt ); //check entry and don't append if such entry is in list already
79 //3) to analyse owner and fill internal data structures
80 SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end();
81 QMap<QString,int> entries;
84 for( ; anIt!=aLast; anIt++ )
86 LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>( (*anIt ).get() );
89 entry = myStudy->referencedToEntry( sowner->entry() );
90 if( entries.contains( entry ) )
93 entries.insert( entry, 0 );
94 myEntries.insert( num, entry );
95 myIsReferences.insert( num, sowner->entry() != entry );
96 processOwner( sowner );
104 Gets count of entries.
106 int LightApp_Selection::count() const
108 return myEntries.count();
114 QtxValue LightApp_Selection::param( const int ind, const QString& p ) const
116 LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy ? myStudy->application() : 0 );
117 if( !( ind>=0 && ind<count() ) || !app )
122 QString mod_name = app->moduleTitle( param( ind, "component" ).toString() );
123 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
124 // false in last parameter means that now we doesn't load module, if it isn't loaded
128 vis = d->IsDisplayed( myEntries[ ind ] );
131 LightApp_Displayer local_d;
132 vis = local_d.IsDisplayed( myEntries[ ind ] );
134 return QtxValue( vis, 0 );
137 else if( p=="component" )
139 return myStudy->componentDataType( myEntries[ ind ] );
142 else if( p=="isComponent" )
144 return QtxValue( myStudy->isComponent( myEntries[ ind ] ), 0 );
147 else if( p=="isReference" )
148 return QtxValue( isReference( ind ), false );
150 else if( p=="canBeDisplayed" )
152 QString mod_name = app->moduleTitle( param( ind, "component" ).toString() );
153 LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false );
154 // false in last parameter means that now we doesn't load module, if it isn't loaded
157 return d->canBeDisplayed( myEntries[ ind ] );
158 else if ( myEntries[ ind ].startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) ) // object is a Save Point object
162 //now if displayer is null, it means, that according module isn't loaded, so that we allow to all display/erase
163 //operations under object
170 Gets global parameters. client, isActiveView, activeView etc.
172 QtxValue LightApp_Selection::globalParam( const QString& p ) const
174 if ( p == "client" ) return QtxValue( myPopupClient );
175 else if ( p == "activeModule" )
177 LightApp_Application* app = dynamic_cast<LightApp_Application*>( myStudy->application() );
178 QString mod_name = app ? QString( app->activeModule()->name() ) : QString::null;
179 //cout << "activeModule : " << mod_name.latin1() << endl;
180 if( !mod_name.isEmpty() )
185 else if ( p == "isActiveView" ) return QtxValue( (bool)activeVW() );
186 else if ( p == "activeView" ) return QtxValue( activeViewType() );
188 else return QtxPopupMgr::Selection::globalParam( p );
190 else return Selection::globalParam( p );
195 Do nothing. To be redefined by successors
197 void LightApp_Selection::processOwner( const LightApp_DataOwner* )
202 Gets entry with index \a index.
204 QString LightApp_Selection::entry( const int index ) const
206 if ( index >= 0 && index < count() )
207 return myEntries[ index ];
212 Returns true if i-th selected object was reference to object with entry( i )
214 bool LightApp_Selection::isReference( const int index ) const
216 if( index >= 0 && index < count() )
217 return myIsReferences[ index ];
223 Gets type of active view manager.
225 QString LightApp_Selection::activeViewType() const
227 SUIT_ViewWindow* win = activeVW();
229 SUIT_ViewManager* vm = win->getViewManager();
231 return vm->getType();
233 return QString::null;
237 Gets active view window.
239 SUIT_ViewWindow* LightApp_Selection::activeVW() const
241 SUIT_Session* session = SUIT_Session::session();
243 SUIT_Application* app = session->activeApplication();
245 SUIT_Desktop* desk = app->desktop();
247 return desk->activeWindow();