1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, 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
20 // File : VisuGUI_ShrinkFactorDlg.cxx
21 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
23 #include "VisuGUI_ShrinkFactorDlg.h"
26 #include "VisuGUI_ViewTools.h"
27 #include "VisuGUI_Tools.h"
28 #include "VISU_Actor.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_OverrideCursor.h"
32 #include "SUIT_Session.h"
33 #include "SUIT_MessageBox.h"
34 #include "SUIT_ResourceMgr.h"
36 #include "SALOME_ListIO.hxx"
37 #include "SALOME_ListIteratorOfListIO.hxx"
38 #include "SALOME_InteractiveObject.hxx"
40 #include <SalomeApp_IntSpinBox.h>
42 #include "LightApp_Study.h"
43 #include "LightApp_SelectionMgr.h"
44 #include "LightApp_Application.h"
46 #include "SVTK_ViewWindow.h"
50 #include <QPushButton>
55 const int DEFAULT_SHRINK = 80;
57 //=================================================================================
58 // class : VisuGUI_ShrinkFactorDlg()
61 //=================================================================================
62 VisuGUI_ShrinkFactorDlg::VisuGUI_ShrinkFactorDlg( VisuGUI* theModule, bool modal )
63 : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
65 mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
66 myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
69 setAttribute( Qt::WA_DeleteOnClose );
71 setWindowTitle( tr( "SHRINKFACTOR_TITLE" ) );
72 setSizeGripEnabled( true );
73 QVBoxLayout* topLayout = new QVBoxLayout( this );
74 topLayout->setSpacing( 6 );
75 topLayout->setMargin( 11 );
77 /*************************************************************************/
78 GroupC1 = new QGroupBox( this );
79 QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 );
80 GroupC1Layout->setSpacing( 6 );
81 GroupC1Layout->setMargin( 11 );
83 ValueLab = new QLabel( tr( "SHRINKFACTOR_VALUE" ), GroupC1 );
84 ValueSpin = new SalomeApp_IntSpinBox( GroupC1 );
85 ValueSpin->setAcceptNames( false );
86 ValueSpin->setRange( 20, 100 );
87 ValueSpin->setSingleStep( 10 );
88 ValueSpin->setMinimumWidth( 70 );
90 GroupC1Layout->addWidget( ValueLab );
91 GroupC1Layout->addWidget( ValueSpin );
93 /*************************************************************************/
94 QGroupBox* GroupButtons = new QGroupBox( this );
95 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
96 GroupButtonsLayout->setSpacing( 6 );
97 GroupButtonsLayout->setMargin( 11 );
99 buttonOk = new QPushButton( tr( "BUT_CLOSE" ), GroupButtons );
100 buttonOk->setAutoDefault( true );
101 buttonOk->setDefault( true );
103 buttonHelp = new QPushButton( tr( "BUT_HELP" ), GroupButtons);
104 buttonHelp->setAutoDefault( true );
106 GroupButtonsLayout->addWidget( buttonOk );
107 GroupButtonsLayout->addSpacing( 10 );
108 GroupButtonsLayout->addStretch();
109 GroupButtonsLayout->addWidget( buttonHelp );
111 topLayout->addWidget( GroupC1 );
112 topLayout->addWidget( GroupButtons );
115 onSelectionChanged();
117 // signals and slots connections : after ValueHasChanged()
118 connect(buttonOk, SIGNAL( clicked() ), this, SLOT( close() ) );
119 connect(buttonHelp, SIGNAL( clicked() ), this, SLOT( help() ) );
120 connect(ValueSpin, SIGNAL( valueChanged( int ) ), this, SLOT( setShrinkFactor() ) );
121 connect(mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
124 //=================================================================================
125 // function : ~VisuGUI_ShrinkFactorDlg()
127 //=================================================================================
128 VisuGUI_ShrinkFactorDlg::~VisuGUI_ShrinkFactorDlg()
132 //=======================================================================
135 //=======================================================================
136 void VisuGUI_ShrinkFactorDlg::help()
138 QString aHelpFileName = "viewing_3d_presentations_page.html#width_shrink_factor_anchor";
139 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
141 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
142 app->onHelpContextModule( aVisuGUI ? app->moduleName( aVisuGUI->moduleName() ) : QString(""), aHelpFileName );
147 platform = "winapplication";
149 platform = "application";
151 SUIT_MessageBox::warning( this,
153 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
154 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( aHelpFileName ),
159 //=================================================================================
160 // function : setShrinkFactor()
161 // purpose : Called when value of spin box is changed
162 // : or the first time as initilisation
163 //=================================================================================
164 void VisuGUI_ShrinkFactorDlg::setShrinkFactor()
166 if ( myViewWindow ) {
167 SUIT_OverrideCursor wc;
168 float shrink = ValueSpin->value() / 100.;
171 mySelectionMgr->selectedObjects( aList );
173 SALOME_ListIteratorOfListIO anIter( aList );
174 for ( ; anIter.More(); anIter.Next() ) {
175 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
176 VISU_Actor* anActor = VISU::FindActor( VISU::GetAppStudy( myModule ), myViewWindow, anIO->getEntry() );
177 if ( anActor && anActor->IsShrunkable() )
178 anActor->SetShrinkFactor( shrink );
180 myViewWindow->Repaint();
184 //=================================================================================
185 // function : onSelectionChanged()
186 // purpose : Called when selection is changed
187 //=================================================================================
188 void VisuGUI_ShrinkFactorDlg::onSelectionChanged()
190 bool shrinkable = false;
191 if ( myViewWindow ) {
192 int shrink = DEFAULT_SHRINK;
195 mySelectionMgr->selectedObjects( aList );
197 if ( aList.Extent() == 1 ) {
198 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
199 if ( !FirstIOS.IsNull() ) {
200 VISU_Actor* anActor = VISU::FindActor( VISU::GetAppStudy( myModule ), myViewWindow, FirstIOS->getEntry() );
202 shrinkable = anActor->IsShrunkable();
204 shrink = int( anActor->GetShrinkFactor() * 100. + 0.5 );
208 else if ( aList.Extent() > 1 ) {
209 SALOME_ListIteratorOfListIO It( aList );
211 for ( ; It.More(); It.Next() ) {
212 Handle(SALOME_InteractiveObject) IO = It.Value();
214 VISU_Actor* anActor = VISU::FindActor( VISU::GetAppStudy( myModule ), myViewWindow, IO->getEntry() );
216 bool lshrinkable = anActor->IsShrunkable();
217 shrinkable = shrinkable || lshrinkable;
219 int shr = int( anActor->GetShrinkFactor() * 100. + 0.5 );
222 else if ( setShr != shr ) {
223 setShr = DEFAULT_SHRINK;
233 ValueSpin->blockSignals( true );
234 ValueSpin->setValue( shrink );
235 ValueSpin->blockSignals( false );
237 GroupC1->setEnabled( shrinkable );
240 //=================================================================================
241 // function : keyPressEvent()
243 //=================================================================================
244 void VisuGUI_ShrinkFactorDlg::keyPressEvent( QKeyEvent* e )
246 QDialog::keyPressEvent( e );
247 if ( e->isAccepted() )
250 if ( e->key() == Qt::Key_F1 ) {