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;
56 const int UNDEF_SHRINK = -1;
58 //=================================================================================
59 // class : VisuGUI_ShrinkFactorDlg()
62 //=================================================================================
63 VisuGUI_ShrinkFactorDlg::VisuGUI_ShrinkFactorDlg( VisuGUI* theModule, bool modal )
64 : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
66 mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
67 myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
70 setAttribute( Qt::WA_DeleteOnClose );
72 setWindowTitle( tr( "SHRINKFACTOR_TITLE" ) );
73 setSizeGripEnabled( true );
74 QVBoxLayout* topLayout = new QVBoxLayout( this );
75 topLayout->setSpacing( 6 );
76 topLayout->setMargin( 11 );
78 /*************************************************************************/
79 GroupC1 = new QGroupBox( this );
80 QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 );
81 GroupC1Layout->setSpacing( 6 );
82 GroupC1Layout->setMargin( 11 );
84 ValueLab = new QLabel( tr( "SHRINKFACTOR_VALUE" ), GroupC1 );
85 ValueSpin = new SalomeApp_IntSpinBox( GroupC1 );
86 ValueSpin->setAcceptNames( false );
87 ValueSpin->setRange( 20, 100 );
88 ValueSpin->setSingleStep( 10 );
89 ValueSpin->setMinimumWidth( 70 );
91 GroupC1Layout->addWidget( ValueLab );
92 GroupC1Layout->addWidget( ValueSpin );
94 /*************************************************************************/
95 QGroupBox* GroupButtons = new QGroupBox( this );
96 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
97 GroupButtonsLayout->setSpacing( 6 );
98 GroupButtonsLayout->setMargin( 11 );
100 buttonOk = new QPushButton( tr( "BUT_CLOSE" ), GroupButtons );
101 buttonOk->setAutoDefault( true );
102 buttonOk->setDefault( true );
104 buttonHelp = new QPushButton( tr( "BUT_HELP" ), GroupButtons);
105 buttonHelp->setAutoDefault( true );
107 GroupButtonsLayout->addWidget( buttonOk );
108 GroupButtonsLayout->addSpacing( 10 );
109 GroupButtonsLayout->addStretch();
110 GroupButtonsLayout->addWidget( buttonHelp );
112 topLayout->addWidget( GroupC1 );
113 topLayout->addWidget( GroupButtons );
116 onSelectionChanged();
118 // signals and slots connections : after ValueHasChanged()
119 connect(buttonOk, SIGNAL( clicked() ), this, SLOT( close() ) );
120 connect(buttonHelp, SIGNAL( clicked() ), this, SLOT( help() ) );
121 connect(ValueSpin, SIGNAL( valueChanged( int ) ), this, SLOT( setShrinkFactor() ) );
122 connect(mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
125 //=================================================================================
126 // function : ~VisuGUI_ShrinkFactorDlg()
128 //=================================================================================
129 VisuGUI_ShrinkFactorDlg::~VisuGUI_ShrinkFactorDlg()
133 //=======================================================================
136 //=======================================================================
137 void VisuGUI_ShrinkFactorDlg::help()
139 QString aHelpFileName = "viewing_3d_presentations_page.html#width_shrink_factor_anchor";
140 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
142 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
143 app->onHelpContextModule( aVisuGUI ? app->moduleName( aVisuGUI->moduleName() ) : QString(""), aHelpFileName );
148 platform = "winapplication";
150 platform = "application";
152 SUIT_MessageBox::warning( this,
154 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
155 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( aHelpFileName ),
160 //=================================================================================
161 // function : setShrinkFactor()
162 // purpose : Called when value of spin box is changed
163 // : or the first time as initilisation
164 //=================================================================================
165 void VisuGUI_ShrinkFactorDlg::setShrinkFactor()
167 if ( myViewWindow ) {
168 SUIT_OverrideCursor wc;
169 float shrink = ValueSpin->value() / 100.;
172 mySelectionMgr->selectedObjects( aList );
174 SALOME_ListIteratorOfListIO anIter( aList );
175 for ( ; anIter.More(); anIter.Next() ) {
176 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
177 VISU_Actor* anActor = VISU::FindActor( VISU::GetAppStudy( myModule ), myViewWindow, anIO->getEntry() );
179 if ( anActor->IsShrunkable() )
180 anActor->SetShrinkFactor( shrink );
183 VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
185 if ( anActor->IsShrunkable() )
186 anActor->SetShrinkFactor( shrink );
190 myViewWindow->Repaint();
194 //=================================================================================
195 // function : onSelectionChanged()
196 // purpose : Called when selection is changed
197 //=================================================================================
198 void VisuGUI_ShrinkFactorDlg::onSelectionChanged()
200 bool shrinkable = false;
201 if ( myViewWindow ) {
202 int shrinkFactor = UNDEF_SHRINK;
205 mySelectionMgr->selectedObjects( aList );
207 SALOME_ListIteratorOfListIO It( aList );
208 for ( ; It.More(); It.Next() ) {
209 Handle(SALOME_InteractiveObject) IO = It.Value();
211 bool ashrinkable = false;
212 int shr = UNDEF_SHRINK;
213 VISU_Actor* anActor = VISU::FindActor( VISU::GetAppStudy( myModule ), myViewWindow, IO->getEntry() );
215 ashrinkable = anActor->IsShrunkable();
216 if ( ashrinkable ) shr = int( anActor->GetShrinkFactor() * 100. + 0.5 );
219 VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
221 ashrinkable = anActor->IsShrunkable();
222 if ( ashrinkable ) shr = int( anActor->GetShrinkFactor() * 100. + 0.5 );
225 shrinkable = shrinkable || ashrinkable;
226 if ( shr != UNDEF_SHRINK ) {
227 if ( shrinkFactor == UNDEF_SHRINK )
229 else if ( shrinkFactor != shr ) {
230 shrinkFactor = DEFAULT_SHRINK;
236 ValueSpin->blockSignals( true );
237 ValueSpin->setValue( shrinkFactor == UNDEF_SHRINK ? DEFAULT_SHRINK : shrinkFactor );
238 ValueSpin->blockSignals( false );
240 GroupC1->setEnabled( shrinkable );
243 //=================================================================================
244 // function : keyPressEvent()
246 //=================================================================================
247 void VisuGUI_ShrinkFactorDlg::keyPressEvent( QKeyEvent* e )
249 QDialog::keyPressEvent( e );
250 if ( e->isAccepted() )
253 if ( e->key() == Qt::Key_F1 ) {