1 // Copyright (C) 2007-2013 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
23 #include "OCCViewer_ClippingDlg.h"
25 #include <QtxDoubleSpinBox.h>
26 #include <QtxAction.h>
28 #include "SUIT_Session.h"
29 #include "SUIT_ViewWindow.h"
30 #include "SUIT_ViewManager.h"
31 #include "OCCViewer_ClipPlane.h"
32 #include "OCCViewer_ViewWindow.h"
33 #include "OCCViewer_ViewPort3d.h"
34 #include "OCCViewer_ViewModel.h"
36 #include <V3d_View.hxx>
37 #include <Visual3d_View.hxx>
38 #include <Geom_Plane.hxx>
39 #include <Prs3d_Presentation.hxx>
40 #include <AIS_ListIteratorOfListOfInteractive.hxx>
41 #include <AIS_ListOfInteractive.hxx>
42 #include <AIS_InteractiveObject.hxx>
43 #include <AIS_InteractiveContext.hxx>
44 #include <IntAna_IntConicQuad.hxx>
50 #include <QApplication>
52 #include <QHBoxLayout>
53 #include <QVBoxLayout>
54 #include <QGridLayout>
56 #include <QPushButton>
59 #include <QStackedLayout>
63 /**********************************************************************************
64 ************************ Internal functions ************************
65 *********************************************************************************/
67 void getMinMaxFromContext( Handle(AIS_InteractiveContext) ic,
68 double theDefaultSize,
76 double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
77 aXMin = aYMin = aZMin = DBL_MAX;
78 aXMax = aYMax = aZMax = -DBL_MAX;
81 AIS_ListOfInteractive aList;
82 ic->DisplayedObjects( aList );
83 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() ) {
84 Handle(AIS_InteractiveObject) anObj = it.Value();
85 if ( !anObj.IsNull() && anObj->HasPresentation() &&
86 !anObj->IsKind( STANDARD_TYPE(AIS_Plane) ) ) {
87 Handle(Prs3d_Presentation) aPrs = anObj->Presentation();
88 if ( !aPrs->IsEmpty() && !aPrs->IsInfinite() ) {
90 double xmin, ymin, zmin, xmax, ymax, zmax;
91 aPrs->MinMaxValues( xmin, ymin, zmin, xmax, ymax, zmax );
92 aXMin = qMin( aXMin, xmin ); aXMax = qMax( aXMax, xmax );
93 aYMin = qMin( aYMin, ymin ); aYMax = qMax( aYMax, ymax );
94 aZMin = qMin( aZMin, zmin ); aZMax = qMax( aZMax, zmax );
100 if(theDefaultSize == 0.0)
101 theDefaultSize = 100.;
102 aXMin = aYMin = aZMin = -theDefaultSize;
103 aXMax = aYMax = aZMax = theDefaultSize;
105 theXMin = aXMin;theYMin = aYMin;theZMin = aZMin;
106 theXMax = aXMax;theYMax = aYMax;theZMax = aZMax;
110 Compute the point of bounding box and current clipping plane
112 void ComputeBoundsParam( double theBounds[6],
113 double theDirection[3],
115 double& theMaxBoundPrj,
116 double& theMinBoundPrj )
118 //Enlarge bounds in order to avoid conflicts of precision
119 for(int i = 0; i < 6; i += 2) {
120 static double EPS = 1.0E-3;
121 double aDelta = (theBounds[i+1] - theBounds[i])*EPS;
122 theBounds[i] -= aDelta;
123 theBounds[i+1] += aDelta;
126 double aBoundPoints[8][3] = { { theBounds[0], theBounds[2], theBounds[4] },
127 { theBounds[1], theBounds[2], theBounds[4] },
128 { theBounds[0], theBounds[3], theBounds[4] },
129 { theBounds[1], theBounds[3], theBounds[4] },
130 { theBounds[0], theBounds[2], theBounds[5] },
131 { theBounds[1], theBounds[2], theBounds[5] },
132 { theBounds[0], theBounds[3], theBounds[5] },
133 { theBounds[1], theBounds[3], theBounds[5] } };
136 theMaxBoundPrj = theDirection[0] * aBoundPoints[aMaxId][0] + theDirection[1] * aBoundPoints[aMaxId][1]
137 + theDirection[2] * aBoundPoints[aMaxId][2];
138 theMinBoundPrj = theMaxBoundPrj;
139 for(int i = 1; i < 8; i++) {
140 double aTmp = theDirection[0] * aBoundPoints[i][0] + theDirection[1] * aBoundPoints[i][1]
141 + theDirection[2] * aBoundPoints[i][2];
142 if(theMaxBoundPrj < aTmp) {
143 theMaxBoundPrj = aTmp;
146 if(theMinBoundPrj > aTmp) {
147 theMinBoundPrj = aTmp;
150 double *aMinPnt = aBoundPoints[aMaxId];
151 theMinPnt[0] = aMinPnt[0];
152 theMinPnt[1] = aMinPnt[1];
153 theMinPnt[2] = aMinPnt[2];
157 Compute the position of current plane by distance
159 void DistanceToPosition( double theBounds[6],
160 double theDirection[3],
164 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
165 ComputeBoundsParam( theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj );
166 double aLength = (aMaxBoundPrj - aMinBoundPrj)*theDist;
167 thePos[0] = aMinPnt[0] - theDirection[0]*aLength;
168 thePos[1] = aMinPnt[1] - theDirection[1]*aLength;
169 thePos[2] = aMinPnt[2] - theDirection[2]*aLength;
173 Compute the parameters of clipping plane
175 bool ComputeClippingPlaneParameters( double theNormal[3],
178 Handle(AIS_InteractiveContext) ic,
179 double theDefaultSize)
181 double aBounds[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
182 getMinMaxFromContext(ic,theDefaultSize,aBounds[0], aBounds[2], aBounds[4], aBounds[1], aBounds[3], aBounds[5]);
184 DistanceToPosition( aBounds, theNormal, theDist, theOrigin );
189 Cross product of two 3-vectors. Result vector in result[3].
191 void Cross(const double first[3], const double second[3], double result[3])
193 result[0] = first[1]*second[2] - first[2]*second[1];
194 result[1] = first[2]*second[0] - first[0]*second[2];
195 result[2] = first[0]*second[1] - first[1]*second[0];
199 Compute relative clipping plane in absolute coordinates
201 void RelativePlaneToAbsolute (OCCViewer_ClipPlane& thePlane, Handle(AIS_InteractiveContext) ic, double theDefaultSize )
204 double aDir[2][3] = { { 0, 0, 0 }, { 0, 0, 0 } };
206 static double aCoeff = M_PI/180.0;
208 double anU[2] = { cos( aCoeff * thePlane.RelativeMode.Rotation1 ), cos( aCoeff * thePlane.RelativeMode.Rotation2 ) };
209 double aV[2] = { sqrt( 1.0 - anU[0]*anU[0] ), sqrt( 1.0 - anU[1] * anU[1] ) };
210 aV[0] = thePlane.RelativeMode.Rotation1 > 0? aV[0]: -aV[0];
211 aV[1] = thePlane.RelativeMode.Rotation2 > 0? aV[1]: -aV[1];
213 switch ( thePlane.RelativeMode.Orientation ) {
234 Cross( aDir[1], aDir[0], aNormal );
237 den = sqrt( aNormal[0] * aNormal[0] + aNormal[1] * aNormal[1] + aNormal[2] * aNormal[2] );
239 for (int i=0; i < 3; i++) {
243 Cross( aNormal, aDir[1], aDir[0] );
248 anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
251 anIsOk = ComputeClippingPlaneParameters( aNormal,
252 thePlane.RelativeMode.Distance,
258 thePlane.X = anOrigin[0];
259 thePlane.Y = anOrigin[1];
260 thePlane.Z = anOrigin[2];
261 thePlane.Dx = aNormal[0];
262 thePlane.Dy = aNormal[1];
263 thePlane.Dz = aNormal[2];
267 Compute clipping plane size base point and normal
270 void clipPlaneParams(OCCViewer_ClipPlane& theClipPlane, Handle(AIS_InteractiveContext) theContext,
271 double& theSize, gp_Pnt& theBasePnt, gp_Dir& theNormal, double defaultSize) {
272 double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
273 aXMin = aYMin = aZMin = DBL_MAX;
274 aXMax = aYMax = aZMax = -DBL_MAX;
276 getMinMaxFromContext(theContext,defaultSize,aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
280 gp_Pnt aBasePnt(theClipPlane.X , theClipPlane.Y , theClipPlane.Z);
281 gp_Dir aNormal(theClipPlane.Dx, theClipPlane.Dy, theClipPlane.Dz );
283 // compute clipping plane size
284 gp_Pnt aCenter = gp_Pnt( ( aXMin + aXMax ) / 2, ( aYMin + aYMax ) / 2, ( aZMin + aZMax ) / 2 );
285 double aDiag = aCenter.Distance( gp_Pnt( aXMax, aYMax, aZMax ) )*2;
288 // compute clipping plane center ( redefine the base point )
289 IntAna_IntConicQuad intersector = IntAna_IntConicQuad();
291 intersector.Perform( gp_Lin( aCenter, aNormal), gp_Pln( aBasePnt, aNormal), Precision::Confusion() );
293 if ( intersector.IsDone() && intersector.NbPoints() == 1 )
294 aBasePnt = intersector.Point( 1 );
297 theBasePnt = aBasePnt;
302 /*********************************************************************************
303 ********************* class OCCViewer_ClippingDlg *********************
304 *********************************************************************************/
307 \param view - view window
308 \param parent - parent widget
310 OCCViewer_ClippingDlg::OCCViewer_ClippingDlg(OCCViewer_ViewWindow* parent , OCCViewer_Viewer* model)
311 : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
312 myCurrentClipPlaneMode (Absolute)
314 setObjectName( "OCCViewer_ClippingDlg" );
317 setWindowTitle( tr( "Clipping" ) );
319 setAttribute (Qt::WA_DeleteOnClose, true);
321 QVBoxLayout* topLayout = new QVBoxLayout( this );
322 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
324 /***************************************************************/
325 // Controls for selecting, creating, deleting planes
326 QGroupBox* GroupPlanes = new QGroupBox( tr("CLIPPING_PLANES"), this );
327 QHBoxLayout* GroupPlanesLayout = new QHBoxLayout( GroupPlanes );
328 ComboBoxPlanes = new QComboBox( GroupPlanes );
329 isActivePlane = new QCheckBox( tr("IS_ACTIVE_PLANE"), this );
330 buttonNew = new QPushButton( tr("BTN_NEW"), GroupPlanes );
331 buttonDelete = new QPushButton( tr("BTN_DELETE"), GroupPlanes );
332 buttonDisableAll = new QPushButton( tr("BTN_DISABLE_ALL"), GroupPlanes );
333 MenuMode = new QMenu( "MenuMode", buttonNew );
334 MenuMode->addAction( tr( "ABSOLUTE" ), this, SLOT( onModeAbsolute() ) );
335 MenuMode->addAction( tr( "RELATIVE" ), this, SLOT( onModeRelative() ) );
336 buttonNew->setMenu( MenuMode );
338 GroupPlanesLayout->addWidget( ComboBoxPlanes );
339 GroupPlanesLayout->addWidget( isActivePlane );
340 GroupPlanesLayout->addWidget( buttonNew );
341 GroupPlanesLayout->addWidget( buttonDelete );
342 GroupPlanesLayout->addWidget( buttonDisableAll );
344 ModeStackedLayout = new QStackedLayout();
346 /********************** Mode Absolute **********************/
347 /* Controls for absolute mode of clipping plane:
348 X, Y, Z - coordinates of the intersection of cutting plane and the three axes
349 Dx, Dy, Dz - components of normal to the cutting plane
350 Orientation - direction of cutting plane
352 const double min = -1e+7;
353 const double max = 1e+7;
354 const double step = 5;
355 const int precision = -7;
358 QGroupBox* GroupAbsolutePoint = new QGroupBox( this );
359 GroupAbsolutePoint->setObjectName( "GroupPoint" );
360 GroupAbsolutePoint->setTitle( tr("BASE_POINT") );
361 QGridLayout* GroupPointLayout = new QGridLayout( GroupAbsolutePoint );
362 GroupPointLayout->setAlignment( Qt::AlignTop );
363 GroupPointLayout->setSpacing( 6 ); GroupPointLayout->setMargin( 11 );
365 TextLabelX = new QLabel( GroupAbsolutePoint );
366 TextLabelX->setObjectName( "TextLabelX" );
367 TextLabelX->setText( tr("X:") );
368 GroupPointLayout->addWidget( TextLabelX, 0, 0 );
370 SpinBox_X = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
371 SpinBox_X->setObjectName("SpinBox_X" );
372 SpinBox_X->setPrecision( precision );
373 GroupPointLayout->addWidget( SpinBox_X, 0, 1 );
375 TextLabelY = new QLabel( GroupAbsolutePoint );
376 TextLabelY->setObjectName( "TextLabelY" );
377 TextLabelY->setText( tr("Y:") );
378 GroupPointLayout->addWidget( TextLabelY, 0, 2 );
380 SpinBox_Y = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
381 SpinBox_Y->setObjectName("SpinBox_Y" );
382 SpinBox_Y->setPrecision( precision );
383 GroupPointLayout->addWidget( SpinBox_Y, 0, 3 );
385 TextLabelZ = new QLabel( GroupAbsolutePoint );
386 TextLabelZ->setObjectName( "TextLabelZ" );
387 TextLabelZ->setText( tr("Z:") );
388 GroupPointLayout->addWidget( TextLabelZ, 0, 4 );
390 SpinBox_Z = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
391 SpinBox_Z->setObjectName("SpinBox_Z" );
392 SpinBox_Z->setPrecision( precision );
393 GroupPointLayout->addWidget( SpinBox_Z, 0, 5 );
395 resetButton = new QPushButton( GroupAbsolutePoint );
396 resetButton->setObjectName( "resetButton" );
397 resetButton->setText( tr( "RESET" ) );
398 GroupPointLayout->addWidget( resetButton, 0, 6 );
401 GroupAbsoluteDirection = new QGroupBox( this );
402 GroupAbsoluteDirection->setObjectName( "GroupDirection" );
403 GroupAbsoluteDirection->setTitle( tr("DIRECTION") );
404 QGridLayout* GroupDirectionLayout = new QGridLayout( GroupAbsoluteDirection );
405 GroupDirectionLayout->setAlignment( Qt::AlignTop );
406 GroupDirectionLayout->setSpacing( 6 );
407 GroupDirectionLayout->setMargin( 11 );
409 TextLabelDx = new QLabel( GroupAbsoluteDirection );
410 TextLabelDx->setObjectName( "TextLabelDx" );
411 TextLabelDx->setText( tr("Dx:") );
412 GroupDirectionLayout->addWidget( TextLabelDx, 0, 0 );
414 SpinBox_Dx = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
415 SpinBox_Dx->setObjectName("SpinBox_Dx" );
416 SpinBox_Dx->setPrecision( precision );
417 GroupDirectionLayout->addWidget( SpinBox_Dx, 0, 1 );
419 TextLabelDy = new QLabel( GroupAbsoluteDirection );
420 TextLabelDy->setObjectName( "TextLabelDy" );
421 TextLabelDy->setText( tr("Dy:") );
422 GroupDirectionLayout->addWidget( TextLabelDy, 0, 2 );
424 SpinBox_Dy = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
425 SpinBox_Dy->setObjectName("SpinBox_Dy" );
426 SpinBox_Dy->setPrecision( precision );
427 GroupDirectionLayout->addWidget( SpinBox_Dy, 0, 3 );
429 TextLabelDz = new QLabel( GroupAbsoluteDirection );
430 TextLabelDz->setObjectName( "TextLabelDz" );
431 TextLabelDz->setText( tr("Dz:") );
432 GroupDirectionLayout->addWidget( TextLabelDz, 0, 4 );
434 SpinBox_Dz = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
435 SpinBox_Dz->setObjectName("SpinBox_Dz" );
436 SpinBox_Dz->setPrecision( precision );
437 GroupDirectionLayout->addWidget( SpinBox_Dz, 0, 5 );
439 invertButton = new QPushButton( GroupAbsoluteDirection );
440 invertButton->setObjectName( "invertButton" );
441 invertButton->setText( tr( "INVERT" ) );
442 GroupDirectionLayout->addWidget( invertButton, 0, 6 );
444 CBAbsoluteOrientation = new QComboBox( GroupAbsoluteDirection );
445 CBAbsoluteOrientation->setObjectName( "AbsoluteOrientation" );
446 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "CUSTOM" ) );
447 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||X-Y" ) );
448 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Y-Z" ) );
449 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Z-X" ) );
450 GroupDirectionLayout->addWidget( CBAbsoluteOrientation, 1, 0, 1, 6 );
452 QVBoxLayout* ModeActiveLayout = new QVBoxLayout();
453 ModeActiveLayout->setMargin( 11 ); ModeActiveLayout->setSpacing( 6 );
454 ModeActiveLayout->addWidget( GroupAbsolutePoint );
455 ModeActiveLayout->addWidget( GroupAbsoluteDirection );
457 QWidget* ModeActiveWidget = new QWidget( this );
458 ModeActiveWidget->setLayout( ModeActiveLayout );
460 /********************** Mode Relative **********************/
461 /* Controls for relative mode of clipping plane:
462 Distance - Value from 0 to 1.
463 Specifies the distance from the minimum value in a given direction of bounding box to the current position
464 Rotation1, Rotation2 - turn angles of cutting plane in given directions
465 Orientation - direction of cutting plane
467 QGroupBox* GroupParameters = new QGroupBox( tr("PARAMETERS"), this );
468 QGridLayout* GroupParametersLayout = new QGridLayout( GroupParameters );
469 GroupParametersLayout->setMargin( 11 ); GroupParametersLayout->setSpacing( 6 );
471 TextLabelOrientation = new QLabel( tr("ORIENTATION"), GroupParameters);
472 TextLabelOrientation->setObjectName( "TextLabelOrientation" );
473 GroupParametersLayout->addWidget( TextLabelOrientation, 0, 0 );
475 CBRelativeOrientation = new QComboBox(GroupParameters);
476 CBRelativeOrientation->setObjectName( "RelativeOrientation" );
477 CBRelativeOrientation->addItem( tr("ALONG_XY") );
478 CBRelativeOrientation->addItem( tr("ALONG_YZ") );
479 CBRelativeOrientation->addItem( tr("ALONG_ZX") );
480 GroupParametersLayout->addWidget( CBRelativeOrientation, 0, 1 );
482 TLValueDistance = new QLabel( GroupParameters );
483 TLValueDistance->setObjectName( "TLValueDistance" );
484 TLValueDistance->setAlignment( Qt::AlignCenter );
485 TLValueDistance->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
486 QFont fnt = TLValueDistance->font(); fnt.setBold( true ); TLValueDistance->setFont( fnt );
487 GroupParametersLayout->addWidget( TLValueDistance, 1, 1 );
489 TextLabelDistance = new QLabel( tr("DISTANCE"), GroupParameters );
490 TextLabelDistance->setObjectName( "TextLabelDistance" );
491 GroupParametersLayout->addWidget( TextLabelDistance, 2, 0 );
493 SliderDistance = new QSlider( Qt::Horizontal, GroupParameters );
494 SliderDistance->setObjectName( "SliderDistance" );
495 SliderDistance->setFocusPolicy( Qt::NoFocus );
496 SliderDistance->setMinimumSize( 300, 0 );
497 SliderDistance->setMinimum( 0 );
498 SliderDistance->setMaximum( 100 );
499 SliderDistance->setSingleStep( 1 );
500 SliderDistance->setPageStep( 10 );
501 SliderDistance->setTracking( false );
502 GroupParametersLayout->addWidget( SliderDistance, 2, 1 );
504 TLValueRotation1 = new QLabel( GroupParameters );
505 TLValueRotation1->setObjectName( "TLValueRotation1" );
506 TLValueRotation1->setAlignment( Qt::AlignCenter );
507 TLValueRotation1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
508 TLValueRotation1->setFont( fnt );
509 GroupParametersLayout->addWidget( TLValueRotation1, 3, 1 );
511 TextLabelRotation1 = new QLabel( tr("ROTATION_AROUND_X_Y2Z"), GroupParameters );
512 TextLabelRotation1->setObjectName( "TextLabelRotation1" );
513 GroupParametersLayout->addWidget( TextLabelRotation1, 4, 0 );
515 SliderRotation1 = new QSlider( Qt::Horizontal, GroupParameters );
516 SliderRotation1->setObjectName( "SliderRotation1" );
517 SliderRotation1->setFocusPolicy( Qt::NoFocus );
518 SliderRotation1->setMinimumSize( 300, 0 );
519 SliderRotation1->setMinimum( -180 );
520 SliderRotation1->setMaximum( 180 );
521 SliderRotation1->setSingleStep( 1 );
522 SliderRotation1->setPageStep( 10 );
523 SliderRotation1->setTracking(false);
524 GroupParametersLayout->addWidget( SliderRotation1, 4, 1 );
526 TLValueRotation2 = new QLabel( GroupParameters );
527 TLValueRotation2->setObjectName( "TLValueRotation2" );
528 TLValueRotation2->setAlignment( Qt::AlignCenter );
529 TLValueRotation2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
530 TLValueRotation2->setFont( fnt );
531 GroupParametersLayout->addWidget( TLValueRotation2, 5, 1 );
533 TextLabelRotation2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
534 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
535 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
536 GroupParametersLayout->addWidget( TextLabelRotation2, 6, 0 );
538 SliderRotation2 = new QSlider( Qt::Horizontal, GroupParameters );
539 SliderRotation2->setObjectName( "SliderRotation2" );
540 SliderRotation2->setFocusPolicy( Qt::NoFocus );
541 SliderRotation2->setMinimumSize( 300, 0 );
542 SliderRotation2->setMinimum( -180 );
543 SliderRotation2->setMaximum( 180 );
544 SliderRotation2->setSingleStep( 1 );
545 SliderRotation2->setPageStep( 10 );
546 SliderRotation2->setTracking(false);
547 GroupParametersLayout->addWidget( SliderRotation2, 6, 1 );
549 /***************************************************************/
550 QGroupBox* CheckBoxWidget = new QGroupBox( this );
551 QHBoxLayout* CheckBoxLayout = new QHBoxLayout( CheckBoxWidget );
553 PreviewCheckBox = new QCheckBox( tr("PREVIEW"), CheckBoxWidget );
554 PreviewCheckBox->setObjectName( "PreviewCheckBox" );
555 PreviewCheckBox->setChecked( true );
556 CheckBoxLayout->addWidget( PreviewCheckBox, 0, Qt::AlignCenter );
558 AutoApplyCheckBox = new QCheckBox( tr("AUTO_APPLY"), CheckBoxWidget );
559 AutoApplyCheckBox->setObjectName( "AutoApplyCheckBox" );
560 CheckBoxLayout->addWidget( AutoApplyCheckBox, 0, Qt::AlignCenter );
562 /***************************************************************/
563 QGroupBox* GroupButtons = new QGroupBox( this );
564 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
565 GroupButtonsLayout->setAlignment( Qt::AlignTop );
566 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
568 buttonOk = new QPushButton( GroupButtons );
569 buttonOk->setObjectName( "buttonOk" );
570 buttonOk->setText( tr( "BUT_APPLY_AND_CLOSE" ) );
571 buttonOk->setAutoDefault( TRUE );
572 buttonOk->setDefault( TRUE );
573 GroupButtonsLayout->addWidget( buttonOk );
575 buttonApply = new QPushButton( GroupButtons );
576 buttonApply->setObjectName( "buttonApply" );
577 buttonApply->setText( tr( "BUT_APPLY" ) );
578 buttonApply->setAutoDefault( TRUE );
579 buttonApply->setDefault( TRUE );
580 GroupButtonsLayout->addWidget( buttonApply );
582 GroupButtonsLayout->addStretch();
584 buttonClose = new QPushButton( GroupButtons );
585 buttonClose->setObjectName( "buttonClose" );
586 buttonClose->setText( tr( "BUT_CLOSE" ) );
587 buttonClose->setAutoDefault( TRUE );
588 GroupButtonsLayout->addWidget( buttonClose );
590 QPushButton* buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
591 buttonHelp->setAutoDefault( TRUE );
592 GroupButtonsLayout->addWidget( buttonHelp );
594 /***************************************************************/
595 ModeStackedLayout->addWidget( ModeActiveWidget );
596 ModeStackedLayout->addWidget( GroupParameters );
598 topLayout->addWidget( GroupPlanes );
599 topLayout->addLayout( ModeStackedLayout );
600 topLayout->addWidget( CheckBoxWidget );
601 topLayout->addWidget( GroupButtons );
603 this->setLayout( topLayout );
608 // Signals and slots connections
609 connect( ComboBoxPlanes, SIGNAL( activated( int ) ), this, SLOT( onSelectPlane( int ) ) );
610 connect( isActivePlane, SIGNAL ( toggled ( bool ) ), this, SLOT( onValueChanged() ) );
611 connect( buttonNew, SIGNAL( clicked() ), buttonNew, SLOT( showMenu() ) );
612 connect( buttonDelete, SIGNAL( clicked() ), this, SLOT( ClickOnDelete() ) );
613 connect( buttonDisableAll, SIGNAL( clicked() ), this, SLOT( ClickOnDisableAll() ) );
615 connect( resetButton, SIGNAL (clicked() ), this, SLOT( onReset() ) );
616 connect( invertButton, SIGNAL (clicked() ), this, SLOT( onInvert() ) ) ;
617 connect( SpinBox_X, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
618 connect( SpinBox_Y, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
619 connect( SpinBox_Z, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
620 connect( SpinBox_Dx, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
621 connect( SpinBox_Dy, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
622 connect( SpinBox_Dz, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
623 connect( CBAbsoluteOrientation, SIGNAL ( activated ( int ) ), this, SLOT( onOrientationAbsoluteChanged( int ) ) ) ;
625 connect( CBRelativeOrientation, SIGNAL( activated( int ) ), this, SLOT( onOrientationRelativeChanged( int ) ) );
626 connect( SliderDistance, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) );
627 connect( SliderDistance, SIGNAL( valueChanged( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) );
628 connect( SliderRotation1, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) );
629 connect( SliderRotation1, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) );
630 connect( SliderRotation2, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) );
631 connect( SliderRotation2, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) );
633 connect( PreviewCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT( onPreview( bool ) ) ) ;
634 connect( AutoApplyCheckBox, SIGNAL ( toggled( bool ) ), this, SLOT( onAutoApply( bool ) ) );
636 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) ) ;
637 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
638 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
639 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
642 myIsSelectPlane = false;
643 myIsPlaneCreation = false;
646 myModel->getViewer3d()->InitActiveViews();
648 myLocalPlanes = myModel->getClipPlanes();
654 Destroys the object and frees any allocated resources
656 OCCViewer_ClippingDlg::~OCCViewer_ClippingDlg()
658 myLocalPlanes.clear();
662 Custom handling of close event: erases preview
664 void OCCViewer_ClippingDlg::closeEvent( QCloseEvent* e )
667 QDialog::closeEvent( e );
668 OCCViewer_ViewWindow* v = qobject_cast<OCCViewer_ViewWindow*>(parent());
670 v->onClipping(false);
674 Custom handling of show event: displays preview
676 void OCCViewer_ClippingDlg::showEvent( QShowEvent* e )
678 QDialog::showEvent( e );
679 onPreview( PreviewCheckBox->isChecked() );
683 Custom handling of hide event: erases preview
685 void OCCViewer_ClippingDlg::hideEvent( QHideEvent* e )
688 QDialog::hideEvent( e );
689 OCCViewer_ViewWindow* v = qobject_cast<OCCViewer_ViewWindow*>(parent());
691 v->onClipping(false);
696 Initialization of initial values of widgets
698 void OCCViewer_ClippingDlg::initParam()
700 SpinBox_X->setValue( 0.0 );
701 SpinBox_Y->setValue( 0.0 );
702 SpinBox_Z->setValue( 0.0 );
704 SpinBox_Dx->setValue( 1.0 );
705 SpinBox_Dy->setValue( 1.0 );
706 SpinBox_Dz->setValue( 1.0 );
708 CBAbsoluteOrientation->setCurrentIndex(0);
710 TLValueDistance->setText( "0.5" );
711 TLValueRotation1->setText( "0\xB0" );
712 TLValueRotation2->setText( "0\xB0" );
713 CBRelativeOrientation->setCurrentIndex( 0 );
714 SliderDistance->setValue( 50 );
715 SliderRotation1->setValue( 0 );
716 SliderRotation2->setValue( 0 );
720 Synchronize dialog's widgets with data
722 void OCCViewer_ClippingDlg::synchronize()
724 ComboBoxPlanes->clear();
725 int aNbPlanesAbsolute = myLocalPlanes.size();
728 for(int i = 1; i<=aNbPlanesAbsolute; i++ ) {
729 aName = QString("Plane %1").arg(i);
730 ComboBoxPlanes->addItem( aName );
733 int aPos = ComboBoxPlanes->count() - 1;
734 ComboBoxPlanes->setCurrentIndex( aPos );
736 bool anIsControlsEnable = ( aPos >= 0 );
737 if ( anIsControlsEnable ) {
738 onSelectPlane( aPos );
741 ComboBoxPlanes->addItem( tr( "NO_PLANES" ) );
744 if ( myCurrentClipPlaneMode == Absolute ) {
745 SpinBox_X->setEnabled( anIsControlsEnable );
746 SpinBox_Y->setEnabled( anIsControlsEnable );
747 SpinBox_Z->setEnabled( anIsControlsEnable );
748 SpinBox_Dx->setEnabled( anIsControlsEnable );
749 SpinBox_Dy->setEnabled( anIsControlsEnable );
750 SpinBox_Dz->setEnabled( anIsControlsEnable );
751 CBAbsoluteOrientation->setEnabled( anIsControlsEnable );
752 invertButton->setEnabled( anIsControlsEnable );
753 resetButton->setEnabled( anIsControlsEnable );
755 else if( myCurrentClipPlaneMode == Relative ) {
756 CBRelativeOrientation->setEnabled( anIsControlsEnable );
757 SliderDistance->setEnabled( anIsControlsEnable );
758 SliderRotation1->setEnabled( anIsControlsEnable );
759 SliderRotation2->setEnabled( anIsControlsEnable );
760 isActivePlane->setEnabled( anIsControlsEnable );
762 isActivePlane->setEnabled( anIsControlsEnable );
766 Displays preview of clipping plane
768 void OCCViewer_ClippingDlg::displayPreview()
770 if ( myBusy || !isValid() || !myModel)
773 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
775 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
777 for ( int i=0; i < clipPlanesCount(); i++ ) {
778 OCCViewer_ClipPlane& aClipPlane = getClipPlane(i);
779 if ( aClipPlane.IsOn ) {
780 Handle(AIS_Plane) myPreviewPlane;
784 clipPlaneParams(aClipPlane, ic, aSize, aBasePnt, aNormal, myModel->trihedronSize());
785 myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ) );
786 myPreviewPlane->SetSize( aSize, aSize );
787 ic->Display( myPreviewPlane, 1, -1, false );
788 ic->SetWidth( myPreviewPlane, 10, false );
789 ic->SetMaterial( myPreviewPlane, Graphic3d_NOM_PLASTIC, false );
790 ic->SetTransparency( myPreviewPlane, 0.5, false );
791 Quantity_Color c = (aCurPlaneIndex == i) ? Quantity_Color( 255. / 255., 70. / 255., 0. / 255., Quantity_TOC_RGB ) : Quantity_Color( 85 / 255., 85 / 255., 255 / 255., Quantity_TOC_RGB );
792 ic->SetColor( myPreviewPlane, c , false );
793 myPreviewPlaneVector.push_back( myPreviewPlane );
799 void OCCViewer_ClippingDlg::updatePreview() {
800 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
801 int count = clipPlanesCount();
807 (aCurPlaneIndex +1 > count) ||
808 !PreviewCheckBox->isChecked())
811 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
813 OCCViewer_ClipPlane& aClipPlane = getClipPlane(aCurPlaneIndex);
814 Handle(AIS_Plane) myPreviewPlane;
816 if (aClipPlane.IsOn) {
820 clipPlaneParams(aClipPlane, ic, aSize, aBasePnt, aNormal, myModel->trihedronSize());
821 if(myPreviewPlaneVector.size() < clipPlanesCount()) {
822 myPreviewPlaneVector.resize(clipPlanesCount());
824 myPreviewPlane = myPreviewPlaneVector[aCurPlaneIndex];
825 if(myPreviewPlane.IsNull()) {
826 //Plane was not created
827 myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ) );
828 myPreviewPlane->SetSize( aSize, aSize );
829 ic->Display( myPreviewPlane, 1, -1, false );
830 ic->SetWidth( myPreviewPlane, 10, false );
831 ic->SetMaterial( myPreviewPlane, Graphic3d_NOM_PLASTIC, false );
832 ic->SetTransparency( myPreviewPlane, 0.5, false );
833 myPreviewPlaneVector[aCurPlaneIndex] = myPreviewPlane;
835 myPreviewPlane->SetComponent(new Geom_Plane( aBasePnt, aNormal ));
836 myPreviewPlane->SetSize( aSize, aSize );
839 ic->SetColor( myPreviewPlane, Quantity_Color( 255. / 255., 70. / 255., 0. / 255., Quantity_TOC_RGB ), false );
841 if(myPreviewPlaneVector.size() > aCurPlaneIndex ) {
842 myPreviewPlane = myPreviewPlaneVector[aCurPlaneIndex];
843 if(ic->IsDisplayed(myPreviewPlane)) {
844 ic->Erase( myPreviewPlane, false );
845 ic->Remove( myPreviewPlane, false );
847 myPreviewPlaneVector[aCurPlaneIndex].Nullify();
850 for(int i = 0; i < myPreviewPlaneVector.size(); i++) {
851 if( i == aCurPlaneIndex ) continue;
852 if(!myPreviewPlaneVector[i].IsNull())
853 ic->SetColor( myPreviewPlaneVector[i], Quantity_Color( 85 / 255., 85 / 255., 255 / 255., Quantity_TOC_RGB ), false );
859 Erases preview of clipping plane
861 void OCCViewer_ClippingDlg::erasePreview()
866 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
868 for ( int i=0; i < myPreviewPlaneVector.size(); i++ ) {
869 Handle(AIS_Plane) myPreviewPlane = myPreviewPlaneVector[i];
870 if ( !myPreviewPlane.IsNull() && ic->IsDisplayed( myPreviewPlane ) ) {
871 ic->Erase( myPreviewPlane, false );
872 ic->Remove( myPreviewPlane, false );
873 myPreviewPlane.Nullify();
876 myPreviewPlaneVector.clear();
881 Return true if plane parameters are valid
883 bool OCCViewer_ClippingDlg::isValid()
885 return ( SpinBox_Dx->value() !=0 || SpinBox_Dy->value() !=0 || SpinBox_Dz->value() !=0 );
889 Update view after changes
891 void OCCViewer_ClippingDlg::updateClipping()
893 if (PreviewCheckBox->isChecked() || AutoApplyCheckBox->isChecked())
895 if (AutoApplyCheckBox->isChecked()) {
899 if (!PreviewCheckBox->isChecked())
907 SLOT on new button click: create a new clipping plane
909 void OCCViewer_ClippingDlg::ClickOnNew()
912 OCCViewer_ClipPlane aPlane;
913 aPlane.PlaneMode = (ClipPlaneMode )myCurrentClipPlaneMode;
914 myLocalPlanes.push_back(aPlane);
919 SLOT on delete button click: Delete selected clipping plane
921 void OCCViewer_ClippingDlg::ClickOnDelete()
923 int aPlaneIndex = ComboBoxPlanes->currentIndex();
924 if ( (clipPlanesCount() == 0) || (aPlaneIndex+1 > clipPlanesCount()))
927 myLocalPlanes.erase(myLocalPlanes.begin() + aPlaneIndex);
929 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
931 if(aPlaneIndex+1 <= myPreviewPlaneVector.size()) {
932 Handle(AIS_Plane) myPreviewPlane = myPreviewPlaneVector[aPlaneIndex];
933 if ( !myPreviewPlane.IsNull() && ic->IsDisplayed( myPreviewPlane ) ) {
934 ic->Erase( myPreviewPlane, false );
935 ic->Remove( myPreviewPlane, false );
937 myPreviewPlaneVector.erase(myPreviewPlaneVector.begin() + aPlaneIndex);
940 if (AutoApplyCheckBox->isChecked()) {
947 SLOT on disable all button click: Restore initial state of viewer,
948 erase all clipping planes
950 void OCCViewer_ClippingDlg::ClickOnDisableAll()
952 AutoApplyCheckBox->setChecked (false);
953 int aClipPlanesCount = clipPlanesCount();
954 for ( int anIndex = 0; anIndex < aClipPlanesCount; anIndex++)
956 OCCViewer_ClipPlane& aPlane = getClipPlane(anIndex);
960 isActivePlane->setChecked(false);
961 myModel->setClipPlanes(myLocalPlanes);
966 SLOT on ok button click: sets cutting plane and closes dialog
968 void OCCViewer_ClippingDlg::ClickOnOk()
975 SLOT on Apply button click: sets cutting plane and update viewer
977 void OCCViewer_ClippingDlg::ClickOnApply()
984 SLOT on close button click: erases preview and rejects dialog
986 void OCCViewer_ClippingDlg::ClickOnClose()
989 OCCViewer_ViewWindow* v = qobject_cast<OCCViewer_ViewWindow*>(parent());
991 v->onClipping(false);
995 SLOT on help button click: opens a help page
997 void OCCViewer_ClippingDlg::ClickOnHelp()
999 SUIT_Application* app = SUIT_Session::session()->activeApplication();
1001 app->onHelpContextModule( "GUI", "occ_3d_viewer_page.html", "clipping_planes" );
1005 Set absolute mode of clipping plane
1007 void OCCViewer_ClippingDlg::onModeAbsolute()
1009 myIsPlaneCreation = true;
1010 ModeStackedLayout->setCurrentIndex(0);
1011 myCurrentClipPlaneMode = Absolute;
1013 myIsPlaneCreation = false;
1018 Set relative mode of clipping plane
1020 void OCCViewer_ClippingDlg::onModeRelative()
1022 myIsPlaneCreation = true;
1023 ModeStackedLayout->setCurrentIndex(1);
1024 myCurrentClipPlaneMode = Relative;
1026 myIsPlaneCreation = false;
1027 SetCurrentPlaneParam();
1032 SLOT: called on value of clipping plane changed
1034 void OCCViewer_ClippingDlg::onValueChanged()
1036 SetCurrentPlaneParam();
1037 if ( myIsSelectPlane )
1043 Set current parameters of selected plane
1045 void OCCViewer_ClippingDlg::onSelectPlane ( int theIndex )
1047 if ( clipPlanesCount() == 0 )
1050 OCCViewer_ClipPlane& aClipPlane = getClipPlane (theIndex);
1052 myIsSelectPlane = true;
1053 if ( aClipPlane.PlaneMode == Absolute ) {
1054 ModeStackedLayout->setCurrentIndex( 0 );
1055 myCurrentClipPlaneMode = Absolute;
1056 int anOrientation = aClipPlane.Orientation;
1057 // Set plane parameters in the dialog
1058 SpinBox_X->setValue( aClipPlane.X );
1059 SpinBox_Y->setValue( aClipPlane.Y );
1060 SpinBox_Z->setValue( aClipPlane.Z );
1061 SpinBox_Dx->setValue( aClipPlane.Dx );
1062 SpinBox_Dy->setValue( aClipPlane.Dy );
1063 SpinBox_Dz->setValue( aClipPlane.Dz );
1064 CBAbsoluteOrientation->setCurrentIndex( anOrientation );
1065 onOrientationAbsoluteChanged( anOrientation );
1067 else if( aClipPlane.PlaneMode == Relative ) {
1068 ModeStackedLayout->setCurrentIndex( 1 );
1069 myCurrentClipPlaneMode = Relative;
1070 int anOrientation = aClipPlane.RelativeMode.Orientation;
1071 // Set plane parameters in the dialog
1072 SliderDistance->setValue( aClipPlane.RelativeMode.Distance*100 );
1073 TLValueDistance->setText( QString::number(aClipPlane.RelativeMode.Distance ) );
1074 SliderRotation1->setValue( aClipPlane.RelativeMode.Rotation1 );
1075 TLValueRotation1->setText( QString( "%1\xB0" ).arg( aClipPlane.RelativeMode.Rotation1 ) );
1076 SliderRotation2->setValue( aClipPlane.RelativeMode.Rotation2 );
1077 TLValueRotation2->setText( QString( "%1\xB0" ).arg( aClipPlane.RelativeMode.Rotation2 ) );
1078 CBRelativeOrientation->setCurrentIndex( anOrientation );
1079 onOrientationRelativeChanged( anOrientation );
1082 isActivePlane->setChecked( aClipPlane.IsOn );
1083 ComboBoxPlanes->setCurrentIndex( theIndex );
1084 myIsSelectPlane = false;
1088 Restore parameters of selected plane
1090 void OCCViewer_ClippingDlg::SetCurrentPlaneParam()
1092 if ( clipPlanesCount() == 0 || myIsSelectPlane )
1095 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1097 OCCViewer_ClipPlane& aPlane = getClipPlane (aCurPlaneIndex);
1099 if ( aPlane.PlaneMode == Absolute ) {
1100 aPlane.Orientation = CBAbsoluteOrientation->currentIndex();
1101 aPlane.X = SpinBox_X->value();
1102 aPlane.Y = SpinBox_Y->value();
1103 aPlane.Z = SpinBox_Z->value();
1104 aPlane.Dx = SpinBox_Dx->value();
1105 aPlane.Dy = SpinBox_Dy->value();
1106 aPlane.Dz = SpinBox_Dz->value();
1108 else if( aPlane.PlaneMode == Relative ) {
1109 aPlane.RelativeMode.Orientation = CBRelativeOrientation->currentIndex();
1110 aPlane.RelativeMode.Distance = TLValueDistance->text().toDouble();
1111 aPlane.RelativeMode.Rotation1 = TLValueRotation1->text().remove("\xB0").toInt();
1112 aPlane.RelativeMode.Rotation2 = TLValueRotation2->text().remove("\xB0").toInt();
1113 RelativePlaneToAbsolute (aPlane, myModel->getAISContext(),myModel->trihedronSize() );
1115 aPlane.IsOn = isActivePlane->isChecked();
1119 SLOT on reset button click: sets default values
1121 void OCCViewer_ClippingDlg::onReset()
1124 SpinBox_X->setValue(0);
1125 SpinBox_Y->setValue(0);
1126 SpinBox_Z->setValue(0);
1133 SLOT on invert button click: inverts normal of cutting plane
1135 void OCCViewer_ClippingDlg::onInvert()
1137 double Dx = SpinBox_Dx->value();
1138 double Dy = SpinBox_Dy->value();
1139 double Dz = SpinBox_Dz->value();
1142 SpinBox_Dx->setValue( -Dx );
1143 SpinBox_Dy->setValue( -Dy );
1144 SpinBox_Dz->setValue( -Dz );
1147 if ( clipPlanesCount() != 0 ) {
1148 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1149 OCCViewer_ClipPlane& aPlane = getClipPlane (aCurPlaneIndex);
1150 aPlane.IsInvert = !aPlane.IsInvert;
1156 SLOT: called on orientation of clipping plane in absolute mode changed
1158 void OCCViewer_ClippingDlg::onOrientationAbsoluteChanged( int mode )
1160 bool isUserMode = (mode==0);
1162 TextLabelX->setEnabled( isUserMode );
1163 TextLabelY->setEnabled( isUserMode );
1164 TextLabelZ->setEnabled( isUserMode );
1166 SpinBox_X->setEnabled( isUserMode );
1167 SpinBox_Y->setEnabled( isUserMode );
1168 SpinBox_Z->setEnabled( isUserMode );
1170 TextLabelDx->setEnabled( isUserMode );
1171 TextLabelDy->setEnabled( isUserMode );
1172 TextLabelDz->setEnabled( isUserMode );
1174 SpinBox_Dx->setEnabled( isUserMode );
1175 SpinBox_Dy->setEnabled( isUserMode );
1176 SpinBox_Dz->setEnabled( isUserMode );
1178 if ( !isUserMode ) {
1180 double aDx = 0, aDy = 0, aDz = 0;
1185 TextLabelZ->setEnabled( true );
1186 SpinBox_Z->setEnabled( true );
1187 SpinBox_Z->setFocus();
1189 else if ( mode == 2 )
1192 TextLabelX->setEnabled( true );
1193 SpinBox_X->setEnabled( true );
1194 SpinBox_X->setFocus();
1196 else if ( mode == 3 )
1199 TextLabelY->setEnabled( true );
1200 SpinBox_Y->setEnabled( true );
1201 SpinBox_Y->setFocus();
1204 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1205 OCCViewer_ClipPlane& aPlane = getClipPlane (aCurPlaneIndex);
1206 if ( aPlane.IsInvert == true ) {
1207 aDx = -aDx; aDy = -aDy; aDz = -aDz;
1211 SpinBox_Dx->setValue( aDx );
1212 SpinBox_Dy->setValue( aDy );
1213 SpinBox_Dz->setValue( aDz );
1216 SetCurrentPlaneParam();
1221 SLOT: called on orientation of clipping plane in relative mode changed
1223 void OCCViewer_ClippingDlg::onOrientationRelativeChanged (int theItem)
1225 if ( clipPlanesCount() == 0 )
1228 if ( theItem == 0 ) {
1229 TextLabelRotation1->setText( tr( "ROTATION_AROUND_X_Y2Z" ) );
1230 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Y_X2Z" ) );
1232 else if ( theItem == 1 ) {
1233 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Y_Z2X" ) );
1234 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Z_Y2X" ) );
1236 else if ( theItem == 2 ) {
1237 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Z_X2Y" ) );
1238 TextLabelRotation2->setText( tr( "ROTATION_AROUND_X_Z2Y" ) );
1241 if( (QComboBox*)sender() == CBRelativeOrientation )
1242 SetCurrentPlaneParam();
1247 SLOT: called on preview check box toggled
1249 void OCCViewer_ClippingDlg::onPreview( bool on )
1257 SLOT: called on Auto Apply check box toggled
1259 void OCCViewer_ClippingDlg::onAutoApply( bool toggled )
1268 SLOT on Apply button click: sets cutting plane
1270 void OCCViewer_ClippingDlg::onApply()
1274 myIsSelectPlane = true;
1276 qApp->processEvents();
1277 QApplication::setOverrideCursor( Qt::WaitCursor );
1278 qApp->processEvents();
1280 myModel->setClipPlanes(myLocalPlanes);
1282 QApplication::restoreOverrideCursor();
1283 myIsSelectPlane = false;
1287 SLOT: Called when value of slider distance change
1289 void OCCViewer_ClippingDlg::SliderDistanceHasMoved( int value )
1291 double new_value = value/100.;
1292 TLValueDistance->setText( QString("%1").arg( new_value ) );
1297 SLOT: Called when value of slider rotation1 change
1299 void OCCViewer_ClippingDlg::SliderRotation1HasMoved( int value )
1301 TLValueRotation1->setText( QString("%1\xB0").arg( value ) );
1306 SLOT: Called when value of slider rotation2 change
1308 void OCCViewer_ClippingDlg::SliderRotation2HasMoved( int value )
1310 TLValueRotation2->setText( QString("%1\xB0").arg( value ) );
1314 OCCViewer_ClipPlane& OCCViewer_ClippingDlg::getClipPlane (int theIndex) {
1315 return myLocalPlanes[theIndex];
1318 int OCCViewer_ClippingDlg::clipPlanesCount() {
1319 return myLocalPlanes.size();