1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : VisuGUI_ShrinkFactorDlg.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "VisuGUI_ShrinkFactorDlg.h"
29 #include "VisuGUI_ViewTools.h"
30 #include "VisuGUI_Tools.h"
31 #include "VISU_Actor.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_OverrideCursor.h"
35 #include "SUIT_Session.h"
36 #include "SUIT_MessageBox.h"
37 #include "SUIT_ResourceMgr.h"
39 #include "SALOME_ListIO.hxx"
40 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include "SALOME_InteractiveObject.hxx"
43 #include "LightApp_Study.h"
44 #include "LightApp_SelectionMgr.h"
45 #include "LightApp_Application.h"
47 #include "SVTK_ViewWindow.h"
51 #include <QPushButton>
57 const int DEFAULT_SHRINK = 80;
59 //=================================================================================
60 // class : VisuGUI_ShrinkFactorDlg()
63 //=================================================================================
64 VisuGUI_ShrinkFactorDlg::VisuGUI_ShrinkFactorDlg( VisuGUI* theModule, bool modal )
65 : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
67 mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
68 myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
71 setAttribute( Qt::WA_DeleteOnClose );
73 setWindowTitle( tr( "SHRINKFACTOR_TITLE" ) );
74 setSizeGripEnabled( true );
75 QVBoxLayout* topLayout = new QVBoxLayout( this );
76 topLayout->setSpacing( 6 );
77 topLayout->setMargin( 11 );
79 /*************************************************************************/
80 GroupC1 = new QGroupBox( this );
81 QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 );
82 GroupC1Layout->setSpacing( 6 );
83 GroupC1Layout->setMargin( 11 );
85 ValueLab = new QLabel( tr( "SHRINKFACTOR_VALUE" ), GroupC1 );
86 ValueSpin = new QSpinBox( GroupC1 );
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() );
178 if ( anActor && anActor->IsShrunkable() )
179 anActor->SetShrinkFactor( shrink );
181 myViewWindow->Repaint();
185 //=================================================================================
186 // function : onSelectionChanged()
187 // purpose : Called when selection is changed
188 //=================================================================================
189 void VisuGUI_ShrinkFactorDlg::onSelectionChanged()
191 bool shrinkable = false;
192 if ( myViewWindow ) {
193 int shrink = DEFAULT_SHRINK;
196 mySelectionMgr->selectedObjects( aList );
198 if ( aList.Extent() == 1 ) {
199 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
200 if ( !FirstIOS.IsNull() ) {
201 VISU_Actor* anActor = VISU::FindActor( VISU::GetAppStudy( myModule ), myViewWindow, FirstIOS->getEntry() );
203 shrinkable = anActor->IsShrunkable();
205 shrink = int( anActor->GetShrinkFactor() * 100. + 0.5 );
209 else if ( aList.Extent() > 1 ) {
210 SALOME_ListIteratorOfListIO It( aList );
212 for ( ; It.More(); It.Next() ) {
213 Handle(SALOME_InteractiveObject) IO = It.Value();
215 VISU_Actor* anActor = VISU::FindActor( VISU::GetAppStudy( myModule ), myViewWindow, IO->getEntry() );
217 bool lshrinkable = anActor->IsShrunkable();
218 shrinkable = shrinkable || lshrinkable;
220 int shr = int( anActor->GetShrinkFactor() * 100. + 0.5 );
223 else if ( setShr != shr ) {
224 setShr = DEFAULT_SHRINK;
234 ValueSpin->blockSignals( true );
235 ValueSpin->setValue( shrink );
236 ValueSpin->blockSignals( false );
238 GroupC1->setEnabled( shrinkable );
241 //=================================================================================
242 // function : keyPressEvent()
244 //=================================================================================
245 void VisuGUI_ShrinkFactorDlg::keyPressEvent( QKeyEvent* e )
247 QDialog::keyPressEvent( e );
248 if ( e->isAccepted() )
251 if ( e->key() == Qt::Key_F1 ) {