8bd0b6145832dafbda5b16cc36eaf59cfd837e99
[occt.git] / samples / qt / Graphic3dDemo / src / ViewDlg.cxx
1 // ViewDlg.cpp: implementation of the ViewDlg class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include <qlayout.h>
6 #include <qpushbutton.h>
7 #include <qframe.h>
8 #include <qcheckbox.h>
9 #include <qlabel.h>
10 #include <qcombobox.h>
11
12 #include <V3d_TypeOfVisualization.hxx>
13 \r
14 #include "Application.h"
15 #include "ViewDlg.h"
16 #include "global.h"
17
18 //////////////////////////////////////////////////////////////////////
19 // Construction/Destruction
20 //////////////////////////////////////////////////////////////////////
21
22 ViewDlg::ViewDlg( QWidget* parent/*, Handle(V3d_View)& view*/ )
23 :QDialog( parent ),
24   myAutoApply( true ), /*myView( view ),*/ myApplyAllViews(false)
25 {\r
26     setModal( false );
27     setWindowTitle( tr( "TITLE_VIEW_DLG" ) );
28
29     QVBoxLayout* topLayout = new QVBoxLayout( this );
30     topLayout->setMargin( 5 );
31
32     QFrame* mainFrame = new QFrame( this );
33     mainFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
34     topLayout->addWidget( mainFrame );
35     topLayout->addSpacing( 10 );
36
37     // view properties
38     QGridLayout* pLayout = new QGridLayout( mainFrame );\r
39     pLayout->setMargin( 5 );
40     myZBufferBox = new QCheckBox( mainFrame );;
41     myZBufferBox->setText( tr( "BTN_ZBUFFER" ) );
42     verify( connect( myZBufferBox, SIGNAL( toggled( bool ) ), SLOT( onZBuffer( bool ) ) ) );\r
43
44     myAnimBox = new QCheckBox( mainFrame );
45     myAnimBox->setText( tr( "BTN_ANIMATION" ) );
46     verify( connect( myAnimBox, SIGNAL( toggled( bool ) ), SLOT( onAnimation( bool ) ) ) );\r
47
48     myDegBox = new QCheckBox( mainFrame );
49     myDegBox->setText( tr( "BTN_DEGENERATION" ) );
50     verify( connect( myDegBox, SIGNAL( toggled( bool ) ), SLOT( onDegeneration( bool ) ) ) );
51
52     pLayout->addWidget( myZBufferBox, 0, 0 );
53     pLayout->addWidget( myAnimBox, 1, 0 );
54     pLayout->addWidget( myDegBox, 2, 0 );
55     pLayout->setRowStretch( 3, 10 );
56     pLayout->setColumnStretch( 1, 10 );\r
57
58     // apply controls
59     QCheckBox *autoApply, *applyAllViews;
60     autoApply = new QCheckBox( this );
61     autoApply->setText( tr( "BTN_AUTOAPPLY" ) );
62     autoApply->setChecked( true );
63     verify( connect( autoApply, SIGNAL( toggled( bool ) ), SLOT( onAutoApply( bool ) ) ) );
64     applyAllViews = new QCheckBox( this );
65     applyAllViews->setText( tr( "BTN_APPLYALLVIEWS" ) );
66     verify( connect( applyAllViews, SIGNAL( toggled( bool ) ), 
67                                     SLOT( onApplyAllViews( bool ) ) ) );
68
69     QHBoxLayout* applyLayout = new QHBoxLayout();
70     applyLayout->addWidget( autoApply );
71     applyLayout->addStretch( 10 );
72     applyLayout->addWidget( applyAllViews );\r
73     topLayout->addLayout( applyLayout );
74     topLayout->addSpacing( 10 );
75
76     // control buttons
77     QPushButton *bOk, *bCancel/*, *bHelp*/;\r
78         \r
79     bOk     = new QPushButton( tr( "BTN_OK" ), this );
80     verify( connect( bOk, SIGNAL( clicked() ), SLOT( onOk() ) ) );\r
81         bOk->setDefault(true); 
82     bCancel = new QPushButton( tr( "BTN_CANCEL" ), this );
83     verify( connect( bCancel, SIGNAL( clicked() ), SLOT( onCancel() ) ) );\r
84 \r
85
86 //    bHelp   = new QPushButton( tr( "BTN_HELP" ), this );\r
87 //    verify( connect( bHelp, SIGNAL( clicked() ), SLOT( onHelp() ) ) );\r
88
89     QHBoxLayout* btnLayout = new QHBoxLayout();
90     btnLayout->setSpacing( 5 );\r
91     btnLayout->addStretch( 10 );\r
92     btnLayout->addWidget( bOk );
93     btnLayout->addWidget( bCancel );
94     btnLayout->addStretch( 10 );
95 //    btnLayout->addWidget( bHelp );\r
96     topLayout->addLayout( btnLayout );
97
98     QSize s = topLayout->totalMinimumSize();
99     s.setWidth( s.width() + topLayout->margin() + 10 );
100     s.setHeight( s.height() + topLayout->margin() + 10 );
101     setFixedSize( s );\r
102 \r
103         Handle(V3d_View) aView = Application::getApplication()->getActiveMDI()->getView();\r
104         myIsAnim = aView->AnimationMode(myIsDeg);\r
105 }
106
107 ViewDlg::~ViewDlg()
108 {
109 }
110
111 void ViewDlg::showEvent ( QShowEvent* e )
112 {\r
113         Update();\r
114         QWidget::showEvent( e );\r
115 }   
116
117 void ViewDlg::onOk()
118 {
119     hide();\r
120         bool Auto = myAutoApply;\r
121 \r
122         myAutoApply = true;\r
123         onZBuffer(myZBufferBox->isChecked());\r
124         onAnimation(myAnimBox->isChecked());\r
125         onDegeneration(myDegBox->isChecked());\r
126         myAutoApply = Auto;
127 }
128  
129 void ViewDlg::onCancel()
130 {
131     hide();
132 }
133 \r
134 void ViewDlg::onHelp()
135 {
136 }
137
138 void ViewDlg::onZBuffer( bool on )
139 {\r
140         QWidgetList aWidgetList;\r
141         Handle(V3d_View) aView;\r
142         QWidget* aWidget;\r
143 \r
144         if (!myApplyAllViews)\r
145                 aWidgetList.append(Application::getApplication()->getActiveMDI());\r
146         else\r
147                 aWidgetList = Application::getWorkspace()->windowList();\r
148 \r
149         if ( myAutoApply ){\r
150                 foreach(aWidget, aWidgetList){\r
151       if ( !aWidget ) continue;\r
152                         MDIWindow* aMDIWindow = (MDIWindow*)aWidget;\r
153                         aView = aMDIWindow->getView();\r
154                         if ( on )
155                                 aView->SetVisualization( V3d_ZBUFFER );
156                         else
157                                 aView->SetVisualization( V3d_WIREFRAME );\r
158                 }\r
159         }
160 }
161
162 void ViewDlg::onAnimation( bool on )
163 {\r
164         QWidgetList aWidgetList;\r
165         Handle(V3d_View) aView;\r
166 \r
167         myIsAnim = on;\r
168     myDegBox->setEnabled( myIsAnim );\r
169         if (!myIsAnim) myDegBox->setChecked(false);\r
170 \r
171         if (!myApplyAllViews)\r
172                 aWidgetList.append(Application::getApplication()->getActiveMDI());\r
173         else\r
174                 aWidgetList = Application::getWorkspace()->windowList();\r
175         \r
176         if ( myAutoApply ){\r
177                 QWidget* aWidget;\r
178                 foreach(aWidget, aWidgetList){\r
179       if ( !aWidget ) continue;\r
180                         MDIWindow* aMDIWindow = (MDIWindow*)aWidget;\r
181                         aView = aMDIWindow->getView();
182                         aView->SetAnimationMode( myIsAnim, myIsDeg );\r
183                         aView->Redraw();\r
184                         aView->SetImmediateUpdate(true);\r
185                         aView->Update();\r
186                 }
187         }       \r
188 }
189
190 void ViewDlg::onDegeneration( bool on )
191 {\r
192         QWidgetList aWidgetList;\r
193         Handle(V3d_View) aView;\r
194         QWidget* aWidget;\r
195 \r
196         if (!myApplyAllViews)\r
197                 aWidgetList.append(Application::getApplication()->getActiveMDI());\r
198         else\r
199                 aWidgetList = Application::getWorkspace()->windowList();\r
200 \r
201
202     myIsDeg = on;
203     if ( myAutoApply ){\r
204                 foreach(aWidget, aWidgetList){\r
205       if ( !aWidget ) continue;\r
206                         MDIWindow* aMDIWindow = (MDIWindow*)aWidget;\r
207                         aView = aMDIWindow->getView();\r
208             aView->SetAnimationMode( myIsAnim, myIsDeg );\r
209                 }\r
210         }
211 }
212
213 void ViewDlg::onAutoApply( bool on )
214 {
215   myAutoApply = on;
216 }
217
218 void ViewDlg::onApplyAllViews( bool on )
219 {\r
220         myApplyAllViews = on;
221 }
222 \r
223 void ViewDlg::Update()\r
224 {\r
225         MDIWindow* anActiveMDIWindow = Application::getApplication()->getActiveMDI();\r
226         if (anActiveMDIWindow){\r
227                 Handle(V3d_View) aView = anActiveMDIWindow->getView();\r
228                 if(!aView.IsNull()){\r
229                 \r
230                 myIsAnim = aView->AnimationMode( myIsDeg );\r
231                 myAnimBox->blockSignals( true );\r
232                 myDegBox->blockSignals( true );\r
233                 myAnimBox->setChecked( myIsAnim );\r
234                 myDegBox->setChecked( myIsDeg );\r
235                 myDegBox->setEnabled( myIsAnim );\r
236                 myAnimBox->blockSignals( false );\r
237                 myDegBox->blockSignals( false );\r
238 \r
239                 myZBufferBox->blockSignals(true);\r
240                 V3d_TypeOfVisualization aVisuType = aView->Visualization();\r
241                 if(aVisuType == V3d_WIREFRAME)\r
242                         myZBufferBox -> setChecked(false);\r
243                 else\r
244                         myZBufferBox -> setChecked(true);\r
245                 myZBufferBox->blockSignals(false);\r
246                 }\r
247         }\r
248 }\r