1 // Copyright (C) 2005-2023 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, or (at your option) any later version.
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 // File : LIGHTGUI_Selection.cxx
20 // Author : Julia DOROVSKIKH
22 #include "LIGHTGUI_Selection.h"
23 #include "LIGHTGUI_DataModel.h"
26 #include <LightApp_Application.h>
27 #include <LightApp_Study.h>
28 #include <SALOME_InteractiveObject.hxx>
29 #include <SOCC_ViewModel.h>
30 #include <SUIT_ViewManager.h>
33 \class LIGHTGUI_Selection
34 \brief Handles the data selection, builds the rules to be used in the
37 This class provides the methods of defining the context popup menu
38 contents for the selected objects by using of popup menu manager
45 LIGHTGUI_Selection::LIGHTGUI_Selection()
46 : LightApp_Selection()
53 LIGHTGUI_Selection::~LIGHTGUI_Selection()
58 \brief Get selection parameter value.
59 \param index selected object index
60 \param p parameter name
61 \return parameter value
63 QVariant LIGHTGUI_Selection::parameter( const int index, const QString& p ) const
67 else if ( p == "empty" )
68 return isEmpty( index );
69 else if ( p == "visible" )
70 return isVisible( index );
71 return LightApp_Selection::parameter( p );
75 \brief Check if selected object is empty line (beginning of the paragraph)
76 \param index selected object index
77 \return \c true if selected object is empty line
79 bool LIGHTGUI_Selection::isEmpty( const int index ) const
82 LightApp_Application* app = dynamic_cast<LightApp_Application*>( study()->application() );
84 LIGHTGUI_DataModel* dm = dynamic_cast<LIGHTGUI_DataModel*>( app->activeModule()->dataModel() );
86 QString line = dm->getLineText( LIGHTGUI_DataModel::id( entry( index ) ) );
87 empty = line.isEmpty();
94 \brief Check if selected object is displayed in the active viewer.
95 \param index selected object index
96 \return \c true if selected object is displayed
98 bool LIGHTGUI_Selection::isVisible( const int index ) const
100 bool visible = false;
101 LightApp_Application* app = dynamic_cast<LightApp_Application*>( study()->application() );
103 SUIT_ViewManager* vm = app->activeViewManager();
104 if ( vm && vm->getType() == "OCCViewer" ) {
105 SOCC_Viewer* v = (SOCC_Viewer*)vm->getViewModel();
107 QString e = entry( index );
108 int id = LIGHTGUI_DataModel::id( e );
109 visible = id != -1 && v->isVisible( new SALOME_InteractiveObject( e.toLatin1(), "" ) );
117 \brief Get selected object type.
118 \param index selected object index
121 QString LIGHTGUI_Selection::type( const int index ) const
123 return lineNb( entry( index ) ) > 0 ? "TextLine" : "Unknown";
127 \brief Get line number corresponding to the selected object.
128 \param index selected object index
129 \return line number or 0 if the pbject is not appropriate
131 int LIGHTGUI_Selection::lineNb( const QString& e ) const
133 int pos = 0; // invalid position
134 LightApp_Application* app = dynamic_cast<LightApp_Application*>( study()->application() );
136 LIGHTGUI_DataModel* dm = dynamic_cast<LIGHTGUI_DataModel*>( app->activeModule()->dataModel() );
138 pos = dm->lineNb( e );