]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_ShrinkFactorDlg.cxx
Salome HOME
Porting to med 3.0.6 / Win32 compatibility / Replace dependency on libmed (fortran...
[modules/visu.git] / src / VISUGUI / VisuGUI_ShrinkFactorDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : VisuGUI_ShrinkFactorDlg.cxx
21 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
22 //
23 #include "VisuGUI_ShrinkFactorDlg.h"
24
25 #include "VisuGUI.h"
26 #include "VisuGUI_ViewTools.h"
27 #include "VisuGUI_Tools.h"
28 #include "VISU_Actor.h"
29
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"
35
36 #include "SALOME_ListIO.hxx"
37 #include "SALOME_ListIteratorOfListIO.hxx"
38 #include "SALOME_InteractiveObject.hxx"
39
40 #include <SalomeApp_IntSpinBox.h>
41
42 #include "LightApp_Study.h"
43 #include "LightApp_SelectionMgr.h"
44 #include "LightApp_Application.h"
45
46 #include "SVTK_ViewWindow.h"
47
48 // QT Includes
49 #include <QLabel>
50 #include <QPushButton>
51 #include <QLayout>
52 #include <QGroupBox>
53 #include <QKeyEvent>
54
55 const int DEFAULT_SHRINK = 80;
56 const int UNDEF_SHRINK   = -1;
57
58 //=================================================================================
59 // class    : VisuGUI_ShrinkFactorDlg()
60 // purpose  :
61 //
62 //=================================================================================
63 VisuGUI_ShrinkFactorDlg::VisuGUI_ShrinkFactorDlg( VisuGUI* theModule, bool modal )
64   : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
65     myModule(theModule),
66     mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
67     myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
68 {
69   setModal( modal );
70   setAttribute( Qt::WA_DeleteOnClose );
71     
72   setWindowTitle( tr( "SHRINKFACTOR_TITLE" ) );
73   setSizeGripEnabled( true );
74   QVBoxLayout* topLayout = new QVBoxLayout( this );
75   topLayout->setSpacing( 6 );
76   topLayout->setMargin( 11 );
77
78   /*************************************************************************/
79   GroupC1 = new QGroupBox( this );
80   QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1 );
81   GroupC1Layout->setSpacing( 6 );
82   GroupC1Layout->setMargin( 11 );
83
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 );
90
91   GroupC1Layout->addWidget( ValueLab );
92   GroupC1Layout->addWidget( ValueSpin );
93
94   /*************************************************************************/
95   QGroupBox* GroupButtons = new QGroupBox( this );
96   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
97   GroupButtonsLayout->setSpacing( 6 );
98   GroupButtonsLayout->setMargin( 11 );
99
100   buttonOk = new QPushButton( tr( "BUT_CLOSE" ), GroupButtons );
101   buttonOk->setAutoDefault( true );
102   buttonOk->setDefault( true );
103
104   buttonHelp = new QPushButton( tr( "BUT_HELP" ), GroupButtons);
105   buttonHelp->setAutoDefault( true );
106
107   GroupButtonsLayout->addWidget( buttonOk );
108   GroupButtonsLayout->addSpacing( 10 );
109   GroupButtonsLayout->addStretch();
110   GroupButtonsLayout->addWidget( buttonHelp );
111
112   topLayout->addWidget( GroupC1 );
113   topLayout->addWidget( GroupButtons );
114
115   // Initial state
116   onSelectionChanged();
117
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() ) );
123 }
124
125 //=================================================================================
126 // function : ~VisuGUI_ShrinkFactorDlg()
127 // purpose  :
128 //=================================================================================
129 VisuGUI_ShrinkFactorDlg::~VisuGUI_ShrinkFactorDlg()
130 {
131 }
132
133 //=======================================================================
134 // function : help()
135 // purpose  :
136 //=======================================================================
137 void VisuGUI_ShrinkFactorDlg::help()
138 {
139   QString aHelpFileName = "viewing_3d_presentations_page.html#width_shrink_factor_anchor";
140   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
141   if (app) {
142     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
143     app->onHelpContextModule( aVisuGUI ? app->moduleName( aVisuGUI->moduleName() ) : QString(""), aHelpFileName );
144   }
145   else {
146     QString platform;
147 #ifdef WIN32
148     platform = "winapplication";
149 #else
150     platform = "application";
151 #endif
152     SUIT_MessageBox::warning( this,
153                               tr( "WRN_WARNING" ),
154                               tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
155                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( aHelpFileName ),
156                               tr( "BUT_OK" ) );
157   }
158 }
159
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()
166 {
167   if ( myViewWindow ) {
168     SUIT_OverrideCursor wc;
169     float shrink = ValueSpin->value() / 100.;
170
171     SALOME_ListIO aList;
172     mySelectionMgr->selectedObjects( aList );
173
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 ) {
179         if ( anActor->IsShrunkable() )
180           anActor->SetShrinkFactor( shrink );
181       }
182       else {
183         VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, anIO->getEntry());
184         if ( anActor ) {
185           if ( anActor->IsShrunkable() )
186             anActor->SetShrinkFactor( shrink );
187         }
188       }
189     }
190     myViewWindow->Repaint();
191   }
192 }
193
194 //=================================================================================
195 // function : onSelectionChanged()
196 // purpose  : Called when selection is changed
197 //=================================================================================
198 void VisuGUI_ShrinkFactorDlg::onSelectionChanged()
199 {
200   bool shrinkable = false;
201   if ( myViewWindow ) {
202     int shrinkFactor = UNDEF_SHRINK;
203
204     SALOME_ListIO aList;
205     mySelectionMgr->selectedObjects( aList );
206
207     SALOME_ListIteratorOfListIO It( aList );
208     for ( ; It.More(); It.Next() ) {
209       Handle(SALOME_InteractiveObject) IO = It.Value();
210       if (!IO.IsNull()) {
211         bool ashrinkable = false;
212         int shr = UNDEF_SHRINK;
213         VISU_Actor* anActor = VISU::FindActor( VISU::GetAppStudy( myModule ), myViewWindow, IO->getEntry() );
214         if ( anActor ) {
215           ashrinkable = anActor->IsShrunkable();
216           if ( ashrinkable ) shr = int( anActor->GetShrinkFactor() * 100. + 0.5 );
217         } 
218         else {
219           VISU_ActorBase* anActor = VISU::FindActorBase(VISU::GetAppStudy(myModule), myViewWindow, IO->getEntry());
220           if ( anActor ) {
221             ashrinkable = anActor->IsShrunkable();
222             if ( ashrinkable ) shr = int( anActor->GetShrinkFactor() * 100. + 0.5 );
223           }
224         }
225         shrinkable = shrinkable || ashrinkable;
226         if ( shr != UNDEF_SHRINK ) {
227           if ( shrinkFactor == UNDEF_SHRINK )
228             shrinkFactor = shr;
229           else if ( shrinkFactor != shr ) {
230             shrinkFactor = DEFAULT_SHRINK;
231             break;
232           }
233         }
234       }
235     }
236     ValueSpin->blockSignals( true );
237     ValueSpin->setValue( shrinkFactor == UNDEF_SHRINK ? DEFAULT_SHRINK : shrinkFactor );
238     ValueSpin->blockSignals( false );
239   }
240   GroupC1->setEnabled( shrinkable );
241 }
242
243 //=================================================================================
244 // function : keyPressEvent()
245 // purpose  :
246 //=================================================================================
247 void VisuGUI_ShrinkFactorDlg::keyPressEvent( QKeyEvent* e )
248 {
249   QDialog::keyPressEvent( e );
250   if ( e->isAccepted() )
251     return;
252
253   if ( e->key() == Qt::Key_F1 ) {
254     e->accept();
255     help();
256   }
257 }