1 // Copyright (C) 2005-2008 OPEN CASCADE
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
19 // LIGHT : sample (no-corba-engine) SALOME module
20 // File : LIGHTGUI_Selection.cxx
21 // Author : Julia DOROVSKIKH
23 #include "LIGHTGUI_Selection.h"
24 #include "LIGHTGUI_DataModel.h"
27 #include <LightApp_Application.h>
28 #include <LightApp_Study.h>
29 #include <LightApp_DataOwner.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <SOCC_ViewModel.h>
32 #include <SUIT_ViewManager.h>
33 #include <QtxPopupMgr.h>
36 \class LIGHTGUI_Selection
37 \brief Handles the data selection, builds the rules to be used in the
44 LIGHTGUI_Selection::LIGHTGUI_Selection()
45 : LightApp_Selection()
52 LIGHTGUI_Selection::~LIGHTGUI_Selection()
57 \brief Get selection parameter value.
58 \param index selected object index
59 \param p parameter name
60 \return parameter value
62 QVariant LIGHTGUI_Selection::parameter( const int index, const QString& p ) const
66 else if ( p == "empty" )
67 return isEmpty( index );
68 else if ( p == "visible" )
69 return isVisible( index );
70 return LightApp_Selection::parameter( p );
74 \brief Check if selected object is empty line (beginning of the paragraph)
75 \param index selected object index
76 \return \c true if selected object is empty line
78 bool LIGHTGUI_Selection::isEmpty( const int index ) const
81 LightApp_Application* app = dynamic_cast<LightApp_Application*>( study()->application() );
83 LIGHTGUI_DataModel* dm = dynamic_cast<LIGHTGUI_DataModel*>( app->activeModule()->dataModel() );
85 QString line = dm->getLineText( LIGHTGUI_DataModel::id( entry( index ) ) );
86 empty = line.isEmpty();
93 \brief Check if selected object is displayed in the active viewer.
94 \param index selected object index
95 \return \c true if selected object is displayed
97 bool LIGHTGUI_Selection::isVisible( const int index ) const
100 LightApp_Application* app = dynamic_cast<LightApp_Application*>( study()->application() );
102 SUIT_ViewManager* vm = app->activeViewManager();
103 if ( vm && vm->getType() == "OCCViewer" ) {
104 SOCC_Viewer* v = (SOCC_Viewer*)vm->getViewModel();
106 QString e = entry( index );
107 int id = LIGHTGUI_DataModel::id( e );
108 visible = id != -1 && v->isVisible( new SALOME_InteractiveObject( e.toLatin1(), "" ) );
116 \brief Get selected object type.
117 \param index selected object index
120 QString LIGHTGUI_Selection::type( const int index ) const
122 return lineNb( entry( index ) ) > 0 ? "TextLine" : "Unknown";
126 \brief Get line number corresponding to the selected object.
127 \param index selected object index
128 \return line number or 0 if the pbject is not appropriate
130 int LIGHTGUI_Selection::lineNb( const QString& e ) const
132 int pos = 0; // invalid position
133 LightApp_Application* app = dynamic_cast<LightApp_Application*>( study()->application() );
135 LIGHTGUI_DataModel* dm = dynamic_cast<LIGHTGUI_DataModel*>( app->activeModule()->dataModel() );
137 pos = dm->lineNb( e );