Adding svn:eol-style=LF property
[occt.git] / samples / qt / Graphic3dDemo / src / ShapeDlg.cxx
CommitLineData
7fd59977 1#include <qapplication.h>
2#include <qlayout.h>
3#include <qpushbutton.h>
4#include <qframe.h>
5#include <qcheckbox.h>
6#include <qlabel.h>
7#include <qcombobox.h>
8#include <qspinbox.h>
9
10#include <Aspect_TypeOfLine.hxx>
11#include <Graphic3d_AspectFillArea3d.hxx>
12#include <Graphic3d_AspectLine3d.hxx>
13#include <V3d_TypeOfVisualization.hxx>
14#include <Prs3d_LineAspect.hxx>
15#include <Prs3d_ShadingAspect.hxx>
16#include <AIS_InteractiveObject.hxx>
17#include <AIS_Drawer.hxx>
c6c9371f 18#include <Graphic3d_ArrayOfPrimitives.hxx>
7fd59977 19
20#include <Sphere_Sphere.hxx>
21#include <gp_Pnt.hxx>
22
23#include "ShapeDlg.h"
24#include "Application.h"
25#include "MDIWindow.h"
26#include "Document.h"
27#include "global.h"
28
29//////////////////////////////////////////////////////////////////////
30// Construction/Destruction
31//////////////////////////////////////////////////////////////////////
32
33ShapeDlg::ShapeDlg( QWidget* parent, Handle(V3d_View)& view,
34 Handle(AIS_InteractiveContext)& cxt )
35: QDialog( parent ),
36 myView( view ), myContext( cxt )
c6c9371f 37{
7fd59977 38 setModal( false );
39 setWindowTitle( tr( "TITLE_SHAPE_DLG" ) );
40
41 myRadius = 100;
42 myDeflection = 1.0;
43 myNbPanes = 0;
44 myNbItems = 0;
45
c6c9371f 46 QVBoxLayout* topLayout = new QVBoxLayout( this );
7fd59977 47 topLayout->setMargin( 5 );
48
49 // radius frame
50 QFrame* rFrame = new QFrame( this );
51 //rFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
52 topLayout->addWidget( rFrame );
53 topLayout->addSpacing( 10 );
54
55 QHBoxLayout* rBox = new QHBoxLayout( rFrame );
c6c9371f 56 rBox->setMargin( 5 );
7fd59977 57 QLabel* rad = new QLabel( tr( "MEN_DLG_RADIUS" ), rFrame );
c6c9371f 58 QDoubleSpinBox* rSpin = new QDoubleSpinBox( rFrame );
59 rSpin->setRange( 1, 10000 );
60 rSpin->setSingleStep( 1 );
7fd59977 61// rSpin->setValueDouble( myRadius );
c6c9371f 62 rSpin->setValue( myRadius );
7fd59977 63// verify( connect( rSpin, SIGNAL( sbdValueChanged( double ) ), SLOT( onRadiusChanged( double ) ) ) );
c6c9371f 64 verify( connect( rSpin, SIGNAL( valueChanged( double ) ), SLOT( onRadiusChanged( double ) ) ) );
7fd59977 65
66 rBox->addWidget( rad );
67 rBox->addWidget( rSpin );
68 rBox->addStretch( 2 );
69
70 // sphere position frame
71 QFrame* pFrame = new QFrame( this );
72 QHBoxLayout* pBox = new QHBoxLayout( pFrame );
c6c9371f 73 pBox->setMargin( 5 );
7fd59977 74
75 pFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
76 topLayout->addWidget( pFrame );
77 topLayout->addSpacing( 10 );
78
79 QLabel *lX, *lY, *lZ;
80
81 lX = new QLabel( tr( "MEN_DLG_X" ), pFrame );
82 lY = new QLabel( tr( "MEN_DLG_Y" ), pFrame );
83 lZ = new QLabel( tr( "MEN_DLG_Z" ), pFrame );
84
c6c9371f 85 myXSpin = new QDoubleSpinBox( pFrame );
86 myXSpin->setRange( -10000, 10000 );
87 myXSpin->setSingleStep( 1 );
88 myXSpin->setValue( 0 );
89 connect(myXSpin, SIGNAL(valueChanged (double)), SLOT(onPositionChanged()));
90 myYSpin = new QDoubleSpinBox( pFrame );
91 myYSpin->setRange( -10000, 10000 );
92 myYSpin->setSingleStep( 1 );
93 myYSpin->setValue( 0 );
94 connect(myYSpin, SIGNAL(valueChanged (double)), SLOT(onPositionChanged()));
95 myZSpin = new QDoubleSpinBox( pFrame );
96 myZSpin->setRange( -10000, 10000 );
97 myZSpin->setSingleStep( 1 );
98 myZSpin->setValue( 0 );
99 connect(myZSpin, SIGNAL(valueChanged (double)), SLOT(onPositionChanged()));
100
7fd59977 101
102 pBox->addStretch( 2 );
103 pBox->addWidget( lX );
104 pBox->addWidget( myXSpin );
105 pBox->addStretch( 2 );
106 pBox->addWidget( lY );
107 pBox->addWidget( myYSpin );
108 pBox->addStretch( 2 );
109 pBox->addWidget( lZ );
110 pBox->addWidget( myZSpin );
111 pBox->addStretch( 2 );
112
113 // sphere aspect frame
114 QFrame* aFrame = new QFrame( this );
115 QHBoxLayout* aBox = new QHBoxLayout( aFrame );
c6c9371f 116 aBox->setMargin( 5 );
7fd59977 117
118 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
119 topLayout->addWidget( aFrame );
120 topLayout->addSpacing( 10 );
121
122 myVNormal = new QCheckBox( aFrame );
123 myVNormal->setText( tr( "MEN_BTN_VNORMAL" ) );
124 myVNormal->setChecked( true );
125 //verify( connect( myVNormal, SIGNAL( toggled( bool ) ), SLOT( onShowEdges( bool ) ) ) );
126
127 myVColor = new QCheckBox( aFrame );
128 myVColor->setText( tr( "MEN_BTN_VCOLOR" ) );
129 //verify( connect( myVColor, SIGNAL( toggled( bool ) ), SLOT( onShowEdges( bool ) ) ) );
130
131 myVTexel = new QCheckBox( aFrame );
132 myVTexel->setText( tr( "MEN_BTN_VTEXEL" ) );
133 //verify( connect( myVTexel, SIGNAL( toggled( bool ) ), SLOT( onShowEdges( bool ) ) ) );
134
c6c9371f 135 myText = new QCheckBox( aFrame );
136 myText->setText( tr( "MEN_BTN_TEXT" ) );
137 verify( connect( myText, SIGNAL( clicked() ), SLOT( onText() ) ) );
138
7fd59977 139 aBox->addStretch( 2 );
140 aBox->addWidget( myVNormal );
141 aBox->addStretch( 2 );
142 aBox->addWidget( myVColor );
143 aBox->addStretch( 2 );
144 aBox->addWidget( myVTexel );
145 aBox->addStretch( 2 );
c6c9371f 146 aBox->addWidget( myText );
147 aBox->addStretch( 2 );
7fd59977 148
149 // tesselation frame
150 QFrame* tFrame = new QFrame( this );
151 QHBoxLayout* tBox = new QHBoxLayout( tFrame );
c6c9371f 152 tBox->setMargin( 5 );
7fd59977 153
154 tFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
155 topLayout->addWidget( tFrame );
156 topLayout->addSpacing( 10 );
157
158 QLabel *defl, *panes, *items;
159
160 defl = new QLabel( tr( "MEN_DLG_DEFLECTION" ), tFrame );
161 panes = new QLabel( tr( "MEN_DLG_PANES" ), tFrame );
162 items = new QLabel( tr( "MEN_DLG_ITEMS" ), tFrame );
163
c6c9371f 164 myDefSpin = new QDoubleSpinBox( tFrame );
165 myDefSpin->setRange( 0.1, 13 );
166 myDefSpin->setSingleStep( 0.1 );
167 myDefSpin->setValue( 1 );
168 verify( connect( myDefSpin, SIGNAL( valueChanged( double ) ), SLOT( onDeflectionChanged( double ) ) ) );
169 myPanesSpin = new QSpinBox( tFrame );
170 myPanesSpin->setRange( 8, 10000 );
171 myPanesSpin->setSingleStep( 1 );
7fd59977 172 verify( connect( myPanesSpin, SIGNAL( valueChanged( int ) ), SLOT( onPanesChanged( int ) ) ) );
173 myItemsSpin = new QSpinBox( tFrame );
c6c9371f 174 myItemsSpin->setRange( 25, 10000000 );
175 myItemsSpin->setSingleStep( 1 );
7fd59977 176 verify( connect( myItemsSpin, SIGNAL( valueChanged( int ) ), SLOT( onItemsChanged( int ) ) ) );
177
178 tBox->addWidget( defl );
179 tBox->addWidget( myDefSpin );
180 tBox->addWidget( panes );
181 tBox->addWidget( myPanesSpin );
182 tBox->addWidget( items );
183 tBox->addWidget( myItemsSpin );
184
185 // control buttons
186 QPushButton *bOk, *bCancel/*, *bHelp*/;
187 bOk = new QPushButton( tr( "BTN_OK" ), this );
188 bOk->setDefault(true);
189 verify( connect( bOk, SIGNAL( clicked() ), SLOT( onOk() ) ) );
190 bCancel = new QPushButton( tr( "BTN_CANCEL" ), this );
c6c9371f 191 verify( connect( bCancel, SIGNAL( clicked() ), SLOT( onCancel() ) ) );
7fd59977 192 verify( connect( this, SIGNAL( destroyed() ), SLOT( onCancel() ) ) );
c6c9371f 193// bHelp = new QPushButton( tr( "BTN_HELP" ), this );
194// verify( connect( bHelp, SIGNAL( clicked() ), SLOT( onHelp() ) ) );
7fd59977 195
196 QHBoxLayout* btnLayout = new QHBoxLayout();
c6c9371f 197 btnLayout->setSpacing( 5 );
7fd59977 198 btnLayout->addStretch( 10 );
199 btnLayout->addWidget( bOk );
200 btnLayout->addWidget( bCancel );
c6c9371f 201 btnLayout->addStretch( 10 );
202// btnLayout->addWidget( bHelp );
203 topLayout->addLayout( btnLayout );
7fd59977 204
205 QSize s = topLayout->totalMinimumSize();
206 s.setWidth( s.width() + topLayout->margin() + 10 );
207 s.setHeight( s.height() + topLayout->margin() + 10 );
208 setFixedSize( s );
209}
210
211ShapeDlg::~ShapeDlg()
212{
213}
214
215void ShapeDlg::showEvent ( QShowEvent* e )
216{
217 QWidget::showEvent( e );
218// myXSpin->setValueDouble( 0 );
219// myYSpin->setValueDouble( 0 );
220// myZSpin->setValueDouble( 0 );
c6c9371f 221 myXSpin->setValue( 0 );
222 myYSpin->setValue( 0 );
223 myZSpin->setValue( 0 );
7fd59977 224 onRadiusChanged( myRadius );
225}
226
227void ShapeDlg::onOk()
228{
229 hide();
230 updateSphere();
231 myShape.Nullify();
232}
233
234void ShapeDlg::onCancel()
235{
236 hide();
237 myContext->Remove( myShape );
238 myShape.Nullify();
239}
240
241void ShapeDlg::onHelp()
242{
243}
244
245void ShapeDlg::onRadiusChanged( double value )
246{
247 myRadius = value;
248
249 myNbPanes = Sphere_Sphere::NbPanes( myRadius, myDeflection );
250 myNbItems = Sphere_Sphere::NbItems( myNbPanes );
251
252 myPanesSpin->blockSignals( true );
253 myItemsSpin->blockSignals( true );
254
255 myPanesSpin->setValue( myNbPanes );
256 myItemsSpin->setValue( myNbItems );
257
258 myPanesSpin->blockSignals( false );
259 myItemsSpin->blockSignals( false );
c6c9371f 260
7fd59977 261 updateSphere();
262}
263
264void ShapeDlg::onItemsChanged( int value )
265{
266 myNbItems = value;
267 myNbPanes = Sphere_Sphere::NbPanes( myNbItems );
268 myDeflection = Sphere_Sphere::Deflection( myRadius, myNbPanes );
269
270 myDefSpin->blockSignals( true );
271 myPanesSpin->blockSignals( true );
272
273// myDefSpin->setValueDouble( myDeflection );
c6c9371f 274 myDefSpin->setValue( myDeflection );
7fd59977 275 myPanesSpin->setValue( myNbPanes );
276
277 myDefSpin->blockSignals( false );
278 myPanesSpin->blockSignals( false );
279
280 updateSphere();
281}
282
283void ShapeDlg::onPanesChanged( int value )
284{
285 myNbPanes = value;
286 myNbItems = Sphere_Sphere::NbItems( myNbPanes );
287 myDeflection = Sphere_Sphere::Deflection( myRadius, myNbPanes );
288
289 myDefSpin->blockSignals( true );
290 myItemsSpin->blockSignals( true );
291
292// myDefSpin->setValueDouble( myDeflection );
c6c9371f 293 myDefSpin->setValue( myDeflection );
7fd59977 294 myItemsSpin->setValue( myNbItems );
295
296 myDefSpin->blockSignals( false );
297 myItemsSpin->blockSignals( false );
298
299 updateSphere();
300}
301
302void ShapeDlg::onDeflectionChanged( double value )
303{
304 myDeflection = value;
305 myNbPanes = Sphere_Sphere::NbPanes( myRadius, myDeflection );
306 myNbItems = Sphere_Sphere::NbItems( myNbPanes );
307
308 myPanesSpin->blockSignals( true );
309 myItemsSpin->blockSignals( true );
310
311 myPanesSpin->setValue( myNbPanes );
312 myItemsSpin->setValue( myNbItems );
313
314 myPanesSpin->blockSignals( false );
315 myItemsSpin->blockSignals( false );
316
317 updateSphere();
318}
c6c9371f 319
320void ShapeDlg::onText()
321{
322 updateSphere();
323}
324
7fd59977 325
326void ShapeDlg::updateSphere()
327{
328 QApplication::setOverrideCursor( Qt::WaitCursor );
329 bool visible = isVisible();
330 gp_Pnt myPosition( myXSpin->value(), myYSpin->value(), myZSpin->value() );
331 if ( !myShape.IsNull() ) {
332 myContext->Remove( myShape, false );
333 myShape.Nullify();
334 }
335
336 myShape =
337 new Sphere_Sphere( myPosition, myRadius, myDeflection, 1/*myVNormalsFlag*/,
338 0/*myVColorsFlag*/, 0/*myVTexelsFlag*/, myText->isChecked(), Graphic3d_ArrayOfPrimitives::IsEnable());
339 myContext->SetDisplayMode( myShape, Application::getApplication()->getActiveMDI()->getDisplayMode(), false );
340 Application::startTimer();
341 myContext->Display( myShape, false );
342 Application::stopTimer( 0, "Display Sphere::Sphere", !visible );
343 Application::startTimer();
344 myView->Update();
345 Application::stopTimer( 0, "UPDATE", !visible );
346 QApplication::restoreOverrideCursor();
347}
c6c9371f 348
349void ShapeDlg::onPositionChanged()
350{
351 updateSphere();
352}
353
354void ShapeDlg::closeEvent ( QCloseEvent* e )
355{
356 onCancel();
357}