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->setMinimumSize( 300, 0 );
496 SliderDistance->setMinimum( 0 );
497 SliderDistance->setMaximum( 100 );
498 SliderDistance->setSingleStep( 1 );
499 SliderDistance->setPageStep( 10 );
500 SliderDistance->setTracking( false );
501 GroupParametersLayout->addWidget( SliderDistance, 2, 1 );
503 TLValueRotation1 = new QLabel( GroupParameters );
504 TLValueRotation1->setObjectName( "TLValueRotation1" );
505 TLValueRotation1->setAlignment( Qt::AlignCenter );
506 TLValueRotation1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
507 TLValueRotation1->setFont( fnt );
508 GroupParametersLayout->addWidget( TLValueRotation1, 3, 1 );
510 TextLabelRotation1 = new QLabel( tr("ROTATION_AROUND_X_Y2Z"), GroupParameters );
511 TextLabelRotation1->setObjectName( "TextLabelRotation1" );
512 GroupParametersLayout->addWidget( TextLabelRotation1, 4, 0 );
514 SliderRotation1 = new QSlider( Qt::Horizontal, GroupParameters );
515 SliderRotation1->setObjectName( "SliderRotation1" );
516 SliderRotation1->setMinimumSize( 300, 0 );
517 SliderRotation1->setMinimum( -180 );
518 SliderRotation1->setMaximum( 180 );
519 SliderRotation1->setSingleStep( 1 );
520 SliderRotation1->setPageStep( 10 );
521 SliderRotation1->setTracking(false);
522 GroupParametersLayout->addWidget( SliderRotation1, 4, 1 );
524 TLValueRotation2 = new QLabel( GroupParameters );
525 TLValueRotation2->setObjectName( "TLValueRotation2" );
526 TLValueRotation2->setAlignment( Qt::AlignCenter );
527 TLValueRotation2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
528 TLValueRotation2->setFont( fnt );
529 GroupParametersLayout->addWidget( TLValueRotation2, 5, 1 );
531 TextLabelRotation2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
532 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
533 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
534 GroupParametersLayout->addWidget( TextLabelRotation2, 6, 0 );
536 SliderRotation2 = new QSlider( Qt::Horizontal, GroupParameters );
537 SliderRotation2->setObjectName( "SliderRotation2" );
538 SliderRotation2->setMinimumSize( 300, 0 );
539 SliderRotation2->setMinimum( -180 );
540 SliderRotation2->setMaximum( 180 );
541 SliderRotation2->setSingleStep( 1 );
542 SliderRotation2->setPageStep( 10 );
543 SliderRotation2->setTracking(false);
544 GroupParametersLayout->addWidget( SliderRotation2, 6, 1 );
546 /***************************************************************/
547 QGroupBox* CheckBoxWidget = new QGroupBox( this );
548 QHBoxLayout* CheckBoxLayout = new QHBoxLayout( CheckBoxWidget );
550 PreviewCheckBox = new QCheckBox( tr("PREVIEW"), CheckBoxWidget );
551 PreviewCheckBox->setObjectName( "PreviewCheckBox" );
552 PreviewCheckBox->setChecked( true );
553 CheckBoxLayout->addWidget( PreviewCheckBox, 0, Qt::AlignCenter );
555 AutoApplyCheckBox = new QCheckBox( tr("AUTO_APPLY"), CheckBoxWidget );
556 AutoApplyCheckBox->setObjectName( "AutoApplyCheckBox" );
557 CheckBoxLayout->addWidget( AutoApplyCheckBox, 0, Qt::AlignCenter );
559 /***************************************************************/
560 QGroupBox* GroupButtons = new QGroupBox( this );
561 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
562 GroupButtonsLayout->setAlignment( Qt::AlignTop );
563 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
565 buttonOk = new QPushButton( GroupButtons );
566 buttonOk->setObjectName( "buttonOk" );
567 buttonOk->setText( tr( "BUT_APPLY_AND_CLOSE" ) );
568 buttonOk->setAutoDefault( TRUE );
569 buttonOk->setDefault( TRUE );
570 GroupButtonsLayout->addWidget( buttonOk );
572 buttonApply = new QPushButton( GroupButtons );
573 buttonApply->setObjectName( "buttonApply" );
574 buttonApply->setText( tr( "BUT_APPLY" ) );
575 buttonApply->setAutoDefault( TRUE );
576 buttonApply->setDefault( TRUE );
577 GroupButtonsLayout->addWidget( buttonApply );
579 GroupButtonsLayout->addStretch();
581 buttonClose = new QPushButton( GroupButtons );
582 buttonClose->setObjectName( "buttonClose" );
583 buttonClose->setText( tr( "BUT_CLOSE" ) );
584 buttonClose->setAutoDefault( TRUE );
585 GroupButtonsLayout->addWidget( buttonClose );
587 QPushButton* buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
588 buttonHelp->setAutoDefault( TRUE );
589 GroupButtonsLayout->addWidget( buttonHelp );
591 /***************************************************************/
592 ModeStackedLayout->addWidget( ModeActiveWidget );
593 ModeStackedLayout->addWidget( GroupParameters );
595 topLayout->addWidget( GroupPlanes );
596 topLayout->addLayout( ModeStackedLayout );
597 topLayout->addWidget( CheckBoxWidget );
598 topLayout->addWidget( GroupButtons );
600 this->setLayout( topLayout );
605 // Signals and slots connections
606 connect( ComboBoxPlanes, SIGNAL( activated( int ) ), this, SLOT( onSelectPlane( int ) ) );
607 connect( isActivePlane, SIGNAL ( toggled ( bool ) ), this, SLOT( onValueChanged() ) );
608 connect( buttonNew, SIGNAL( clicked() ), buttonNew, SLOT( showMenu() ) );
609 connect( buttonDelete, SIGNAL( clicked() ), this, SLOT( ClickOnDelete() ) );
610 connect( buttonDisableAll, SIGNAL( clicked() ), this, SLOT( ClickOnDisableAll() ) );
612 connect( resetButton, SIGNAL (clicked() ), this, SLOT( onReset() ) );
613 connect( invertButton, SIGNAL (clicked() ), this, SLOT( onInvert() ) ) ;
614 connect( SpinBox_X, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
615 connect( SpinBox_Y, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
616 connect( SpinBox_Z, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
617 connect( SpinBox_Dx, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
618 connect( SpinBox_Dy, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
619 connect( SpinBox_Dz, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
620 connect( CBAbsoluteOrientation, SIGNAL ( activated ( int ) ), this, SLOT( onOrientationAbsoluteChanged( int ) ) ) ;
622 connect( CBRelativeOrientation, SIGNAL( activated( int ) ), this, SLOT( onOrientationRelativeChanged( int ) ) );
623 connect( SliderDistance, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) );
624 connect( SliderDistance, SIGNAL( valueChanged( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) );
625 connect( SliderRotation1, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) );
626 connect( SliderRotation1, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) );
627 connect( SliderRotation2, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) );
628 connect( SliderRotation2, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) );
630 connect( PreviewCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT( onPreview( bool ) ) ) ;
631 connect( AutoApplyCheckBox, SIGNAL ( toggled( bool ) ), this, SLOT( onAutoApply( bool ) ) );
633 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) ) ;
634 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
635 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
636 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
639 myIsSelectPlane = false;
640 myIsPlaneCreation = false;
643 myModel->getViewer3d()->InitActiveViews();
645 myLocalPlanes = myModel->getClipPlanes();
651 Destroys the object and frees any allocated resources
653 OCCViewer_ClippingDlg::~OCCViewer_ClippingDlg()
655 myLocalPlanes.clear();
659 Custom handling of close event: erases preview
661 void OCCViewer_ClippingDlg::closeEvent( QCloseEvent* e )
664 QDialog::closeEvent( e );
665 OCCViewer_ViewWindow* v = qobject_cast<OCCViewer_ViewWindow*>(parent());
667 v->onClipping(false);
671 Custom handling of show event: displays preview
673 void OCCViewer_ClippingDlg::showEvent( QShowEvent* e )
675 QDialog::showEvent( e );
676 onPreview( PreviewCheckBox->isChecked() );
680 Custom handling of hide event: erases preview
682 void OCCViewer_ClippingDlg::hideEvent( QHideEvent* e )
685 QDialog::hideEvent( e );
686 OCCViewer_ViewWindow* v = qobject_cast<OCCViewer_ViewWindow*>(parent());
688 v->onClipping(false);
693 Initialization of initial values of widgets
695 void OCCViewer_ClippingDlg::initParam()
697 SpinBox_X->setValue( 0.0 );
698 SpinBox_Y->setValue( 0.0 );
699 SpinBox_Z->setValue( 0.0 );
701 SpinBox_Dx->setValue( 1.0 );
702 SpinBox_Dy->setValue( 1.0 );
703 SpinBox_Dz->setValue( 1.0 );
705 CBAbsoluteOrientation->setCurrentIndex(0);
707 TLValueDistance->setText( "0.5" );
708 TLValueRotation1->setText( "0\xB0" );
709 TLValueRotation2->setText( "0\xB0" );
710 CBRelativeOrientation->setCurrentIndex( 0 );
711 SliderDistance->setValue( 50 );
712 SliderRotation1->setValue( 0 );
713 SliderRotation2->setValue( 0 );
717 Synchronize dialog's widgets with data
719 void OCCViewer_ClippingDlg::synchronize()
721 ComboBoxPlanes->clear();
722 int aNbPlanesAbsolute = myLocalPlanes.size();
725 for(int i = 1; i<=aNbPlanesAbsolute; i++ ) {
726 aName = QString("Plane %1").arg(i);
727 ComboBoxPlanes->addItem( aName );
730 int aPos = ComboBoxPlanes->count() - 1;
731 ComboBoxPlanes->setCurrentIndex( aPos );
733 bool anIsControlsEnable = ( aPos >= 0 );
734 if ( anIsControlsEnable ) {
735 onSelectPlane( aPos );
738 ComboBoxPlanes->addItem( tr( "NO_PLANES" ) );
741 if ( myCurrentClipPlaneMode == Absolute ) {
742 SpinBox_X->setEnabled( anIsControlsEnable );
743 SpinBox_Y->setEnabled( anIsControlsEnable );
744 SpinBox_Z->setEnabled( anIsControlsEnable );
745 SpinBox_Dx->setEnabled( anIsControlsEnable );
746 SpinBox_Dy->setEnabled( anIsControlsEnable );
747 SpinBox_Dz->setEnabled( anIsControlsEnable );
748 CBAbsoluteOrientation->setEnabled( anIsControlsEnable );
749 invertButton->setEnabled( anIsControlsEnable );
750 resetButton->setEnabled( anIsControlsEnable );
752 else if( myCurrentClipPlaneMode == Relative ) {
753 CBRelativeOrientation->setEnabled( anIsControlsEnable );
754 SliderDistance->setEnabled( anIsControlsEnable );
755 SliderRotation1->setEnabled( anIsControlsEnable );
756 SliderRotation2->setEnabled( anIsControlsEnable );
757 isActivePlane->setEnabled( anIsControlsEnable );
759 isActivePlane->setEnabled( anIsControlsEnable );
763 Displays preview of clipping plane
765 void OCCViewer_ClippingDlg::displayPreview()
767 if ( myBusy || !isValid() || !myModel)
770 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
772 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
774 for ( int i=0; i < clipPlanesCount(); i++ ) {
775 OCCViewer_ClipPlane& aClipPlane = getClipPlane(i);
776 if ( aClipPlane.IsOn ) {
777 Handle(AIS_Plane) myPreviewPlane;
781 clipPlaneParams(aClipPlane, ic, aSize, aBasePnt, aNormal, myModel->trihedronSize());
782 myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ) );
783 myPreviewPlane->SetSize( aSize, aSize );
784 ic->Display( myPreviewPlane, 1, -1, false );
785 ic->SetWidth( myPreviewPlane, 10, false );
786 ic->SetMaterial( myPreviewPlane, Graphic3d_NOM_PLASTIC, false );
787 ic->SetTransparency( myPreviewPlane, 0.5, false );
788 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 );
789 ic->SetColor( myPreviewPlane, c , false );
790 myPreviewPlaneVector.push_back( myPreviewPlane );
796 void OCCViewer_ClippingDlg::updatePreview() {
797 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
798 int count = clipPlanesCount();
804 (aCurPlaneIndex +1 > count) ||
805 !PreviewCheckBox->isChecked())
808 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
810 OCCViewer_ClipPlane& aClipPlane = getClipPlane(aCurPlaneIndex);
811 Handle(AIS_Plane) myPreviewPlane;
813 if (aClipPlane.IsOn) {
817 clipPlaneParams(aClipPlane, ic, aSize, aBasePnt, aNormal, myModel->trihedronSize());
818 if(myPreviewPlaneVector.size() < clipPlanesCount()) {
819 myPreviewPlaneVector.resize(clipPlanesCount());
821 myPreviewPlane = myPreviewPlaneVector[aCurPlaneIndex];
822 if(myPreviewPlane.IsNull()) {
823 //Plane was not created
824 myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ) );
825 myPreviewPlane->SetSize( aSize, aSize );
826 ic->Display( myPreviewPlane, 1, -1, false );
827 ic->SetWidth( myPreviewPlane, 10, false );
828 ic->SetMaterial( myPreviewPlane, Graphic3d_NOM_PLASTIC, false );
829 ic->SetTransparency( myPreviewPlane, 0.5, false );
830 myPreviewPlaneVector[aCurPlaneIndex] = myPreviewPlane;
832 myPreviewPlane->SetComponent(new Geom_Plane( aBasePnt, aNormal ));
833 myPreviewPlane->SetSize( aSize, aSize );
836 ic->SetColor( myPreviewPlane, Quantity_Color( 255. / 255., 70. / 255., 0. / 255., Quantity_TOC_RGB ), false );
838 if(myPreviewPlaneVector.size() > aCurPlaneIndex ) {
839 myPreviewPlane = myPreviewPlaneVector[aCurPlaneIndex];
840 if(ic->IsDisplayed(myPreviewPlane)) {
841 ic->Erase( myPreviewPlane, false );
842 ic->Remove( myPreviewPlane, false );
844 myPreviewPlaneVector[aCurPlaneIndex].Nullify();
847 for(int i = 0; i < myPreviewPlaneVector.size(); i++) {
848 if( i == aCurPlaneIndex ) continue;
849 if(!myPreviewPlaneVector[i].IsNull())
850 ic->SetColor( myPreviewPlaneVector[i], Quantity_Color( 85 / 255., 85 / 255., 255 / 255., Quantity_TOC_RGB ), false );
856 Erases preview of clipping plane
858 void OCCViewer_ClippingDlg::erasePreview()
863 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
865 for ( int i=0; i < myPreviewPlaneVector.size(); i++ ) {
866 Handle(AIS_Plane) myPreviewPlane = myPreviewPlaneVector[i];
867 if ( !myPreviewPlane.IsNull() && ic->IsDisplayed( myPreviewPlane ) ) {
868 ic->Erase( myPreviewPlane, false );
869 ic->Remove( myPreviewPlane, false );
870 myPreviewPlane.Nullify();
873 myPreviewPlaneVector.clear();
878 Return true if plane parameters are valid
880 bool OCCViewer_ClippingDlg::isValid()
882 return ( SpinBox_Dx->value() !=0 || SpinBox_Dy->value() !=0 || SpinBox_Dz->value() !=0 );
886 Update view after changes
888 void OCCViewer_ClippingDlg::updateClipping()
890 if (PreviewCheckBox->isChecked() || AutoApplyCheckBox->isChecked())
892 if (AutoApplyCheckBox->isChecked()) {
896 if (!PreviewCheckBox->isChecked())
904 SLOT on new button click: create a new clipping plane
906 void OCCViewer_ClippingDlg::ClickOnNew()
909 OCCViewer_ClipPlane aPlane;
910 aPlane.PlaneMode = (ClipPlaneMode )myCurrentClipPlaneMode;
911 myLocalPlanes.push_back(aPlane);
916 SLOT on delete button click: Delete selected clipping plane
918 void OCCViewer_ClippingDlg::ClickOnDelete()
920 int aPlaneIndex = ComboBoxPlanes->currentIndex();
921 if ( (clipPlanesCount() == 0) || (aPlaneIndex+1 > clipPlanesCount()))
924 myLocalPlanes.erase(myLocalPlanes.begin() + aPlaneIndex);
926 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
928 if(aPlaneIndex+1 <= myPreviewPlaneVector.size()) {
929 Handle(AIS_Plane) myPreviewPlane = myPreviewPlaneVector[aPlaneIndex];
930 if ( !myPreviewPlane.IsNull() && ic->IsDisplayed( myPreviewPlane ) ) {
931 ic->Erase( myPreviewPlane, false );
932 ic->Remove( myPreviewPlane, false );
934 myPreviewPlaneVector.erase(myPreviewPlaneVector.begin() + aPlaneIndex);
937 if (AutoApplyCheckBox->isChecked()) {
944 SLOT on disable all button click: Restore initial state of viewer,
945 erase all clipping planes
947 void OCCViewer_ClippingDlg::ClickOnDisableAll()
949 AutoApplyCheckBox->setChecked (false);
950 int aClipPlanesCount = clipPlanesCount();
951 for ( int anIndex = 0; anIndex < aClipPlanesCount; anIndex++)
953 OCCViewer_ClipPlane& aPlane = getClipPlane(anIndex);
957 isActivePlane->setChecked(false);
958 myModel->setClipPlanes(myLocalPlanes);
963 SLOT on ok button click: sets cutting plane and closes dialog
965 void OCCViewer_ClippingDlg::ClickOnOk()
972 SLOT on Apply button click: sets cutting plane and update viewer
974 void OCCViewer_ClippingDlg::ClickOnApply()
981 SLOT on close button click: erases preview and rejects dialog
983 void OCCViewer_ClippingDlg::ClickOnClose()
986 OCCViewer_ViewWindow* v = qobject_cast<OCCViewer_ViewWindow*>(parent());
988 v->onClipping(false);
992 SLOT on help button click: opens a help page
994 void OCCViewer_ClippingDlg::ClickOnHelp()
996 SUIT_Application* app = SUIT_Session::session()->activeApplication();
998 app->onHelpContextModule( "GUI", "occ_3d_viewer_page.html", "clipping_planes" );
1002 Set absolute mode of clipping plane
1004 void OCCViewer_ClippingDlg::onModeAbsolute()
1006 myIsPlaneCreation = true;
1007 ModeStackedLayout->setCurrentIndex(0);
1008 myCurrentClipPlaneMode = Absolute;
1010 myIsPlaneCreation = false;
1015 Set relative mode of clipping plane
1017 void OCCViewer_ClippingDlg::onModeRelative()
1019 myIsPlaneCreation = true;
1020 ModeStackedLayout->setCurrentIndex(1);
1021 myCurrentClipPlaneMode = Relative;
1023 myIsPlaneCreation = false;
1024 SetCurrentPlaneParam();
1029 SLOT: called on value of clipping plane changed
1031 void OCCViewer_ClippingDlg::onValueChanged()
1033 SetCurrentPlaneParam();
1034 if ( myIsSelectPlane )
1040 Set current parameters of selected plane
1042 void OCCViewer_ClippingDlg::onSelectPlane ( int theIndex )
1044 if ( clipPlanesCount() == 0 )
1047 OCCViewer_ClipPlane& aClipPlane = getClipPlane (theIndex);
1049 myIsSelectPlane = true;
1050 if ( aClipPlane.PlaneMode == Absolute ) {
1051 ModeStackedLayout->setCurrentIndex( 0 );
1052 myCurrentClipPlaneMode = Absolute;
1053 int anOrientation = aClipPlane.Orientation;
1054 // Set plane parameters in the dialog
1055 SpinBox_X->setValue( aClipPlane.X );
1056 SpinBox_Y->setValue( aClipPlane.Y );
1057 SpinBox_Z->setValue( aClipPlane.Z );
1058 SpinBox_Dx->setValue( aClipPlane.Dx );
1059 SpinBox_Dy->setValue( aClipPlane.Dy );
1060 SpinBox_Dz->setValue( aClipPlane.Dz );
1061 CBAbsoluteOrientation->setCurrentIndex( anOrientation );
1062 onOrientationAbsoluteChanged( anOrientation );
1064 else if( aClipPlane.PlaneMode == Relative ) {
1065 ModeStackedLayout->setCurrentIndex( 1 );
1066 myCurrentClipPlaneMode = Relative;
1067 int anOrientation = aClipPlane.RelativeMode.Orientation;
1068 // Set plane parameters in the dialog
1069 SliderDistance->setValue( aClipPlane.RelativeMode.Distance*100 );
1070 TLValueDistance->setText( QString::number(aClipPlane.RelativeMode.Distance ) );
1071 SliderRotation1->setValue( aClipPlane.RelativeMode.Rotation1 );
1072 TLValueRotation1->setText( QString( "%1\xB0" ).arg( aClipPlane.RelativeMode.Rotation1 ) );
1073 SliderRotation2->setValue( aClipPlane.RelativeMode.Rotation2 );
1074 TLValueRotation2->setText( QString( "%1\xB0" ).arg( aClipPlane.RelativeMode.Rotation2 ) );
1075 CBRelativeOrientation->setCurrentIndex( anOrientation );
1076 onOrientationRelativeChanged( anOrientation );
1079 isActivePlane->setChecked( aClipPlane.IsOn );
1080 ComboBoxPlanes->setCurrentIndex( theIndex );
1081 myIsSelectPlane = false;
1085 Restore parameters of selected plane
1087 void OCCViewer_ClippingDlg::SetCurrentPlaneParam()
1089 if ( clipPlanesCount() == 0 || myIsSelectPlane )
1092 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1094 OCCViewer_ClipPlane& aPlane = getClipPlane (aCurPlaneIndex);
1096 if ( aPlane.PlaneMode == Absolute ) {
1097 aPlane.Orientation = CBAbsoluteOrientation->currentIndex();
1098 aPlane.X = SpinBox_X->value();
1099 aPlane.Y = SpinBox_Y->value();
1100 aPlane.Z = SpinBox_Z->value();
1101 aPlane.Dx = SpinBox_Dx->value();
1102 aPlane.Dy = SpinBox_Dy->value();
1103 aPlane.Dz = SpinBox_Dz->value();
1105 else if( aPlane.PlaneMode == Relative ) {
1106 aPlane.RelativeMode.Orientation = CBRelativeOrientation->currentIndex();
1107 aPlane.RelativeMode.Distance = TLValueDistance->text().toDouble();
1108 aPlane.RelativeMode.Rotation1 = TLValueRotation1->text().remove("\xB0").toInt();
1109 aPlane.RelativeMode.Rotation2 = TLValueRotation2->text().remove("\xB0").toInt();
1110 RelativePlaneToAbsolute (aPlane, myModel->getAISContext(),myModel->trihedronSize() );
1112 aPlane.IsOn = isActivePlane->isChecked();
1116 SLOT on reset button click: sets default values
1118 void OCCViewer_ClippingDlg::onReset()
1121 SpinBox_X->setValue(0);
1122 SpinBox_Y->setValue(0);
1123 SpinBox_Z->setValue(0);
1130 SLOT on invert button click: inverts normal of cutting plane
1132 void OCCViewer_ClippingDlg::onInvert()
1134 double Dx = SpinBox_Dx->value();
1135 double Dy = SpinBox_Dy->value();
1136 double Dz = SpinBox_Dz->value();
1139 SpinBox_Dx->setValue( -Dx );
1140 SpinBox_Dy->setValue( -Dy );
1141 SpinBox_Dz->setValue( -Dz );
1144 if ( clipPlanesCount() != 0 ) {
1145 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1146 OCCViewer_ClipPlane& aPlane = getClipPlane (aCurPlaneIndex);
1147 aPlane.IsInvert = !aPlane.IsInvert;
1153 SLOT: called on orientation of clipping plane in absolute mode changed
1155 void OCCViewer_ClippingDlg::onOrientationAbsoluteChanged( int mode )
1157 bool isUserMode = (mode==0);
1159 TextLabelX->setEnabled( isUserMode );
1160 TextLabelY->setEnabled( isUserMode );
1161 TextLabelZ->setEnabled( isUserMode );
1163 SpinBox_X->setEnabled( isUserMode );
1164 SpinBox_Y->setEnabled( isUserMode );
1165 SpinBox_Z->setEnabled( isUserMode );
1167 TextLabelDx->setEnabled( isUserMode );
1168 TextLabelDy->setEnabled( isUserMode );
1169 TextLabelDz->setEnabled( isUserMode );
1171 SpinBox_Dx->setEnabled( isUserMode );
1172 SpinBox_Dy->setEnabled( isUserMode );
1173 SpinBox_Dz->setEnabled( isUserMode );
1175 if ( !isUserMode ) {
1177 double aDx = 0, aDy = 0, aDz = 0;
1182 TextLabelZ->setEnabled( true );
1183 SpinBox_Z->setEnabled( true );
1184 SpinBox_Z->setFocus();
1186 else if ( mode == 2 )
1189 TextLabelX->setEnabled( true );
1190 SpinBox_X->setEnabled( true );
1191 SpinBox_X->setFocus();
1193 else if ( mode == 3 )
1196 TextLabelY->setEnabled( true );
1197 SpinBox_Y->setEnabled( true );
1198 SpinBox_Y->setFocus();
1201 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1202 OCCViewer_ClipPlane& aPlane = getClipPlane (aCurPlaneIndex);
1203 if ( aPlane.IsInvert == true ) {
1204 aDx = -aDx; aDy = -aDy; aDz = -aDz;
1208 SpinBox_Dx->setValue( aDx );
1209 SpinBox_Dy->setValue( aDy );
1210 SpinBox_Dz->setValue( aDz );
1213 SetCurrentPlaneParam();
1218 SLOT: called on orientation of clipping plane in relative mode changed
1220 void OCCViewer_ClippingDlg::onOrientationRelativeChanged (int theItem)
1222 if ( clipPlanesCount() == 0 )
1225 if ( theItem == 0 ) {
1226 TextLabelRotation1->setText( tr( "ROTATION_AROUND_X_Y2Z" ) );
1227 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Y_X2Z" ) );
1229 else if ( theItem == 1 ) {
1230 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Y_Z2X" ) );
1231 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Z_Y2X" ) );
1233 else if ( theItem == 2 ) {
1234 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Z_X2Y" ) );
1235 TextLabelRotation2->setText( tr( "ROTATION_AROUND_X_Z2Y" ) );
1238 if( (QComboBox*)sender() == CBRelativeOrientation )
1239 SetCurrentPlaneParam();
1244 SLOT: called on preview check box toggled
1246 void OCCViewer_ClippingDlg::onPreview( bool on )
1254 SLOT: called on Auto Apply check box toggled
1256 void OCCViewer_ClippingDlg::onAutoApply( bool toggled )
1265 SLOT on Apply button click: sets cutting plane
1267 void OCCViewer_ClippingDlg::onApply()
1271 myIsSelectPlane = true;
1273 qApp->processEvents();
1274 QApplication::setOverrideCursor( Qt::WaitCursor );
1275 qApp->processEvents();
1277 myModel->setClipPlanes(myLocalPlanes);
1279 QApplication::restoreOverrideCursor();
1280 myIsSelectPlane = false;
1284 SLOT: Called when value of slider distance change
1286 void OCCViewer_ClippingDlg::SliderDistanceHasMoved( int value )
1288 double new_value = value/100.;
1289 TLValueDistance->setText( QString("%1").arg( new_value ) );
1294 SLOT: Called when value of slider rotation1 change
1296 void OCCViewer_ClippingDlg::SliderRotation1HasMoved( int value )
1298 TLValueRotation1->setText( QString("%1\xB0").arg( value ) );
1303 SLOT: Called when value of slider rotation2 change
1305 void OCCViewer_ClippingDlg::SliderRotation2HasMoved( int value )
1307 TLValueRotation2->setText( QString("%1\xB0").arg( value ) );
1311 OCCViewer_ClipPlane& OCCViewer_ClippingDlg::getClipPlane (int theIndex) {
1312 return myLocalPlanes[theIndex];
1315 int OCCViewer_ClippingDlg::clipPlanesCount() {
1316 return myLocalPlanes.size();