1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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 <QtxDoubleSpinSlider.h>
27 #include <QtxIntSpinSlider.h>
28 #include <QtxAction.h>
30 #include "SUIT_Session.h"
31 #include "SUIT_ViewWindow.h"
32 #include "SUIT_ViewManager.h"
33 #include "OCCViewer_ClipPlane.h"
34 #include "OCCViewer_ViewWindow.h"
35 #include "OCCViewer_ViewPort3d.h"
36 #include "OCCViewer_ViewModel.h"
37 #include "OCCViewer_ViewManager.h"
38 #include "OCCViewer_ClipPlaneInteractor.h"
40 #include <Basics_OCCTVersion.hxx>
42 #include <V3d_View.hxx>
43 #include <Visual3d_View.hxx>
44 #include <Geom_Plane.hxx>
45 #include <Prs3d_Presentation.hxx>
46 #include <AIS_ListIteratorOfListOfInteractive.hxx>
47 #include <AIS_ListOfInteractive.hxx>
48 #include <AIS_InteractiveObject.hxx>
49 #include <AIS_InteractiveContext.hxx>
50 #include <IntAna_IntConicQuad.hxx>
56 #include <QApplication>
58 #include <QHBoxLayout>
59 #include <QVBoxLayout>
60 #include <QGridLayout>
62 #include <QPushButton>
65 #include <QStackedLayout>
69 /**********************************************************************************
70 ************************ Internal functions ************************
71 *********************************************************************************/
73 void getMinMaxFromContext( Handle(AIS_InteractiveContext) ic,
74 double theDefaultSize,
82 double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
83 aXMin = aYMin = aZMin = DBL_MAX;
84 aXMax = aYMax = aZMax = -DBL_MAX;
87 AIS_ListOfInteractive aList;
88 ic->DisplayedObjects( aList );
89 for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() ) {
90 Handle(AIS_InteractiveObject) anObj = it.Value();
91 if ( !anObj.IsNull() && anObj->HasPresentation() &&
92 !anObj->IsKind( STANDARD_TYPE(AIS_Plane) ) ) {
93 Handle(Prs3d_Presentation) aPrs = anObj->Presentation();
94 if ( !aPrs->IsEmpty() && !aPrs->IsInfinite() ) {
96 double xmin, ymin, zmin, xmax, ymax, zmax;
97 #if OCC_VERSION_LARGE > 0x06070100
98 Bnd_Box aBox = aPrs->MinMaxValues();
99 xmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
100 ymin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
101 zmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
102 xmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
103 ymax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
104 zmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
106 aPrs->MinMaxValues( xmin, ymin, zmin, xmax, ymax, zmax );
108 aXMin = qMin( aXMin, xmin ); aXMax = qMax( aXMax, xmax );
109 aYMin = qMin( aYMin, ymin ); aYMax = qMax( aYMax, ymax );
110 aZMin = qMin( aZMin, zmin ); aZMax = qMax( aZMax, zmax );
116 if(theDefaultSize == 0.0)
117 theDefaultSize = 100.;
118 aXMin = aYMin = aZMin = -theDefaultSize;
119 aXMax = aYMax = aZMax = theDefaultSize;
121 theXMin = aXMin;theYMin = aYMin;theZMin = aZMin;
122 theXMax = aXMax;theYMax = aYMax;theZMax = aZMax;
126 Compute the point of bounding box and current clipping plane
128 void ComputeBoundsParam( const double theBounds[6],
129 const double theDirection[3],
131 double& theMaxBoundPrj,
132 double& theMinBoundPrj )
134 double aEnlargeBounds[6];
136 // Enlarge bounds in order to avoid conflicts of precision
137 for(int i = 0; i < 6; i += 2)
139 static double EPS = 1.0E-3;
140 double aDelta = (theBounds[i+1] - theBounds[i])*EPS;
141 aEnlargeBounds[i ] = theBounds[i ] - aDelta;
142 aEnlargeBounds[i+1] = theBounds[i+1] + aDelta;
145 double aBoundPoints[8][3] = { { aEnlargeBounds[0], aEnlargeBounds[2], aEnlargeBounds[4] },
146 { aEnlargeBounds[1], aEnlargeBounds[2], aEnlargeBounds[4] },
147 { aEnlargeBounds[0], aEnlargeBounds[3], aEnlargeBounds[4] },
148 { aEnlargeBounds[1], aEnlargeBounds[3], aEnlargeBounds[4] },
149 { aEnlargeBounds[0], aEnlargeBounds[2], aEnlargeBounds[5] },
150 { aEnlargeBounds[1], aEnlargeBounds[2], aEnlargeBounds[5] },
151 { aEnlargeBounds[0], aEnlargeBounds[3], aEnlargeBounds[5] },
152 { aEnlargeBounds[1], aEnlargeBounds[3], aEnlargeBounds[5] } };
155 theMaxBoundPrj = theDirection[0] * aBoundPoints[aMaxId][0] + theDirection[1] * aBoundPoints[aMaxId][1]
156 + theDirection[2] * aBoundPoints[aMaxId][2];
157 theMinBoundPrj = theMaxBoundPrj;
158 for(int i = 1; i < 8; i++) {
159 double aTmp = theDirection[0] * aBoundPoints[i][0] + theDirection[1] * aBoundPoints[i][1]
160 + theDirection[2] * aBoundPoints[i][2];
161 if(theMaxBoundPrj < aTmp) {
162 theMaxBoundPrj = aTmp;
165 if(theMinBoundPrj > aTmp) {
166 theMinBoundPrj = aTmp;
169 double *aMinPnt = aBoundPoints[aMaxId];
170 theMinPnt[0] = aMinPnt[0];
171 theMinPnt[1] = aMinPnt[1];
172 theMinPnt[2] = aMinPnt[2];
176 Compute the position of current plane by distance
178 void DistanceToPosition( const double theBounds[6],
179 const double theDirection[3],
180 const double theDist,
183 double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
184 ComputeBoundsParam( theBounds, theDirection, aMinPnt, aMaxBoundPrj, aMinBoundPrj );
185 double aLength = (aMaxBoundPrj - aMinBoundPrj) * theDist;
186 thePos[0] = aMinPnt[0] - theDirection[0] * aLength;
187 thePos[1] = aMinPnt[1] - theDirection[1] * aLength;
188 thePos[2] = aMinPnt[2] - theDirection[2] * aLength;
192 Compute the parameters of clipping plane
194 bool ComputeClippingPlaneParameters( const Handle(AIS_InteractiveContext)& theIC,
195 const double theDefaultSize,
196 const double theNormal[3],
197 const double theDist,
198 double theOrigin[3] )
200 double aBounds[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
202 getMinMaxFromContext( theIC, theDefaultSize, aBounds[0], aBounds[2], aBounds[4], aBounds[1], aBounds[3], aBounds[5] );
204 DistanceToPosition( aBounds, theNormal, theDist, theOrigin );
209 \brief Converts relative plane parameters to absolute.
210 \param theIC [in] the interactive context.
211 \param theDefaultSize [in] the default trihedron size.
212 \param theDistance [in] the plane distance relative to minimum corner of model boundaries.
213 \param theDX [in] x component of plane direction.
214 \param theDY [in] y component of plane direction.
215 \param theDZ [in] z component of plane direction.
216 \param theX [out] x coordinate of plane origin.
217 \param theY [out] y coordinate of plane origin.
218 \param theZ [out] z coordinate of plane origin.
220 bool DistanceToXYZ ( const Handle(AIS_InteractiveContext)& theIC,
221 const double theDefaultSize,
222 const double theDistance,
230 double aNormal[3] = { theDX, theDY, theDZ };
231 double anOrigin[3] = { 0.0, 0.0, 0.0 };
233 bool anIsOk = ComputeClippingPlaneParameters( theIC, theDefaultSize, aNormal, theDistance, anOrigin );
248 \brief Converts absolute position and direction to bounding box distance.
249 \param theIC [in] the interactive context.
250 \param theDefaultSize [in] the default trihedron size.
251 \param theX [in] x coordinate of plane origin.
252 \param theY [in] y coordinate of plane origin.
253 \param theZ [in] z coordinate of plane origin.
254 \param theDX [in] x component of plane direction.
255 \param theDY [in] y component of plane direction.
256 \param theDZ [in] z component of plane direction.
257 \param theDistance [out] the plane distance relative to minimum corner of model boundaries.
259 void XYZToDistance ( const Handle(AIS_InteractiveContext)& theIC,
260 const double theDefaultSize,
267 double& theDistance )
269 gp_Pnt aPlaneP( theX, theY, theZ );
270 gp_Dir aPlaneN( theDX, theDY, theDZ );
272 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
274 getMinMaxFromContext( theIC, theDefaultSize, aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
277 aMinMax.Update( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
279 gp_Trsf aRelativeTransform;
280 aRelativeTransform.SetTransformation( gp_Ax3(), gp_Ax3( aPlaneP, aPlaneN ) );
281 Bnd_Box aRelativeBounds = aMinMax.Transformed( aRelativeTransform );
283 aRelativeBounds.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
285 double aLength = aZmax - aZmin;
286 double aDistance = aZmax;
288 double aRelativeDistance = aLength > 0.01 ? aDistance / aLength : 0.0;
289 aRelativeDistance = qMin( aRelativeDistance, aLength );
290 aRelativeDistance = qMax( aRelativeDistance, 0.0 );
291 theDistance = aRelativeDistance;
295 Compute clipping plane size base point and normal
298 void clipPlaneParams(OCCViewer_ClipPlane& theClipPlane, Handle(AIS_InteractiveContext) theContext,
299 double& theSize, gp_Pnt& theBasePnt, gp_Dir& theNormal, double defaultSize) {
300 double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
301 aXMin = aYMin = aZMin = DBL_MAX;
302 aXMax = aYMax = aZMax = -DBL_MAX;
304 getMinMaxFromContext(theContext,defaultSize,aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
307 double aNormalX = 0.0;
308 double aNormalY = 0.0;
309 double aNormalZ = 0.0;
310 theClipPlane.OrientationToXYZ( aNormalX, aNormalY, aNormalZ );
311 gp_Pnt aBasePnt( theClipPlane.X, theClipPlane.Y, theClipPlane.Z );
312 gp_Dir aNormal( aNormalX, aNormalY, aNormalZ );
314 // compute clipping plane size
315 gp_Pnt aCenter = gp_Pnt( ( aXMin + aXMax ) / 2, ( aYMin + aYMax ) / 2, ( aZMin + aZMax ) / 2 );
316 double aDiag = aCenter.Distance( gp_Pnt( aXMax, aYMax, aZMax ) )*2;
319 // compute clipping plane center ( redefine the base point )
320 IntAna_IntConicQuad intersector = IntAna_IntConicQuad();
322 intersector.Perform( gp_Lin( aCenter, aNormal), gp_Pln( aBasePnt, aNormal), Precision::Confusion() );
324 if ( intersector.IsDone() && intersector.NbPoints() == 1 )
325 aBasePnt = intersector.Point( 1 );
328 theBasePnt = aBasePnt;
333 /*********************************************************************************
334 ********************* class OCCViewer_ClippingDlg *********************
335 *********************************************************************************/
338 \param view - view window
339 \param parent - parent widget
341 OCCViewer_ClippingDlg::OCCViewer_ClippingDlg(OCCViewer_ViewWindow* parent , OCCViewer_Viewer* model)
342 : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
344 setObjectName( "OCCViewer_ClippingDlg" );
347 setWindowTitle( tr( "Clipping" ) );
349 setAttribute (Qt::WA_DeleteOnClose, true);
351 QVBoxLayout* topLayout = new QVBoxLayout( this );
352 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
354 /***************************************************************/
355 // Controls for selecting, creating, deleting planes
356 QGroupBox* GroupPlanes = new QGroupBox( tr("CLIPPING_PLANES"), this );
357 QHBoxLayout* GroupPlanesLayout = new QHBoxLayout( GroupPlanes );
358 ComboBoxPlanes = new QComboBox( GroupPlanes );
359 isActivePlane = new QCheckBox( tr("IS_ACTIVE_PLANE"), this );
360 buttonNew = new QPushButton( tr("BTN_NEW"), GroupPlanes );
361 buttonDelete = new QPushButton( tr("BTN_DELETE"), GroupPlanes );
362 buttonDisableAll = new QPushButton( tr("BTN_DISABLE_ALL"), GroupPlanes );
363 MenuMode = new QMenu( "MenuMode", buttonNew );
364 MenuMode->addAction( tr( "ABSOLUTE" ), this, SLOT( onModeAbsolute() ) );
365 MenuMode->addAction( tr( "RELATIVE" ), this, SLOT( onModeRelative() ) );
366 buttonNew->setMenu( MenuMode );
368 GroupPlanesLayout->addWidget( ComboBoxPlanes );
369 GroupPlanesLayout->addWidget( isActivePlane );
370 GroupPlanesLayout->addWidget( buttonNew );
371 GroupPlanesLayout->addWidget( buttonDelete );
372 GroupPlanesLayout->addWidget( buttonDisableAll );
374 ModeStackedLayout = new QStackedLayout();
376 /********************** Mode Absolute **********************/
377 /* Controls for absolute mode of clipping plane:
378 X, Y, Z - coordinates of the intersection of cutting plane and the three axes
379 Dx, Dy, Dz - components of normal to the cutting plane
380 Orientation - direction of cutting plane
382 const double min = -1e+7;
383 const double max = 1e+7;
384 const double step = 5;
385 const int precision = -7;
388 QGroupBox* GroupAbsolutePoint = new QGroupBox( this );
389 GroupAbsolutePoint->setObjectName( "GroupPoint" );
390 GroupAbsolutePoint->setTitle( tr("BASE_POINT") );
391 QGridLayout* GroupPointLayout = new QGridLayout( GroupAbsolutePoint );
392 GroupPointLayout->setAlignment( Qt::AlignTop );
393 GroupPointLayout->setSpacing( 6 ); GroupPointLayout->setMargin( 11 );
395 TextLabelX = new QLabel( GroupAbsolutePoint );
396 TextLabelX->setObjectName( "TextLabelX" );
397 TextLabelX->setText( tr("X:") );
398 GroupPointLayout->addWidget( TextLabelX, 0, 0 );
400 SpinBox_X = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
401 SpinBox_X->setObjectName("SpinBox_X" );
402 SpinBox_X->setPrecision( precision );
403 GroupPointLayout->addWidget( SpinBox_X, 0, 1 );
405 TextLabelY = new QLabel( GroupAbsolutePoint );
406 TextLabelY->setObjectName( "TextLabelY" );
407 TextLabelY->setText( tr("Y:") );
408 GroupPointLayout->addWidget( TextLabelY, 0, 2 );
410 SpinBox_Y = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
411 SpinBox_Y->setObjectName("SpinBox_Y" );
412 SpinBox_Y->setPrecision( precision );
413 GroupPointLayout->addWidget( SpinBox_Y, 0, 3 );
415 TextLabelZ = new QLabel( GroupAbsolutePoint );
416 TextLabelZ->setObjectName( "TextLabelZ" );
417 TextLabelZ->setText( tr("Z:") );
418 GroupPointLayout->addWidget( TextLabelZ, 0, 4 );
420 SpinBox_Z = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
421 SpinBox_Z->setObjectName("SpinBox_Z" );
422 SpinBox_Z->setPrecision( precision );
423 GroupPointLayout->addWidget( SpinBox_Z, 0, 5 );
425 resetButton = new QPushButton( GroupAbsolutePoint );
426 resetButton->setObjectName( "resetButton" );
427 resetButton->setText( tr( "RESET" ) );
428 GroupPointLayout->addWidget( resetButton, 0, 6 );
431 GroupAbsoluteDirection = new QGroupBox( this );
432 GroupAbsoluteDirection->setObjectName( "GroupDirection" );
433 GroupAbsoluteDirection->setTitle( tr("DIRECTION") );
434 QGridLayout* GroupDirectionLayout = new QGridLayout( GroupAbsoluteDirection );
435 GroupDirectionLayout->setAlignment( Qt::AlignTop );
436 GroupDirectionLayout->setSpacing( 6 );
437 GroupDirectionLayout->setMargin( 11 );
439 TextLabelDx = new QLabel( GroupAbsoluteDirection );
440 TextLabelDx->setObjectName( "TextLabelDx" );
441 TextLabelDx->setText( tr("Dx:") );
442 GroupDirectionLayout->addWidget( TextLabelDx, 0, 0 );
444 SpinBox_Dx = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
445 SpinBox_Dx->setObjectName("SpinBox_Dx" );
446 SpinBox_Dx->setPrecision( precision );
447 GroupDirectionLayout->addWidget( SpinBox_Dx, 0, 1 );
449 TextLabelDy = new QLabel( GroupAbsoluteDirection );
450 TextLabelDy->setObjectName( "TextLabelDy" );
451 TextLabelDy->setText( tr("Dy:") );
452 GroupDirectionLayout->addWidget( TextLabelDy, 0, 2 );
454 SpinBox_Dy = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
455 SpinBox_Dy->setObjectName("SpinBox_Dy" );
456 SpinBox_Dy->setPrecision( precision );
457 GroupDirectionLayout->addWidget( SpinBox_Dy, 0, 3 );
459 TextLabelDz = new QLabel( GroupAbsoluteDirection );
460 TextLabelDz->setObjectName( "TextLabelDz" );
461 TextLabelDz->setText( tr("Dz:") );
462 GroupDirectionLayout->addWidget( TextLabelDz, 0, 4 );
464 SpinBox_Dz = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
465 SpinBox_Dz->setObjectName("SpinBox_Dz" );
466 SpinBox_Dz->setPrecision( precision );
467 GroupDirectionLayout->addWidget( SpinBox_Dz, 0, 5 );
469 invertButton = new QPushButton( GroupAbsoluteDirection );
470 invertButton->setObjectName( "invertButton" );
471 invertButton->setText( tr( "INVERT" ) );
472 GroupDirectionLayout->addWidget( invertButton, 0, 6 );
474 CBAbsoluteOrientation = new QComboBox( GroupAbsoluteDirection );
475 CBAbsoluteOrientation->setObjectName( "AbsoluteOrientation" );
476 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "CUSTOM" ) );
477 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||X-Y" ) );
478 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Y-Z" ) );
479 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Z-X" ) );
480 GroupDirectionLayout->addWidget( CBAbsoluteOrientation, 1, 0, 1, 6 );
482 QVBoxLayout* ModeActiveLayout = new QVBoxLayout();
483 ModeActiveLayout->setMargin( 11 ); ModeActiveLayout->setSpacing( 6 );
484 ModeActiveLayout->addWidget( GroupAbsolutePoint );
485 ModeActiveLayout->addWidget( GroupAbsoluteDirection );
487 QWidget* ModeActiveWidget = new QWidget( this );
488 ModeActiveWidget->setLayout( ModeActiveLayout );
490 /********************** Mode Relative **********************/
491 /* Controls for relative mode of clipping plane:
492 Distance - Value from 0 to 1.
493 Specifies the distance from the minimum value in a given direction of bounding box to the current position
494 Rotation1, Rotation2 - turn angles of cutting plane in given directions
495 Orientation - direction of cutting plane
497 QGroupBox* GroupParameters = new QGroupBox( tr("PARAMETERS"), this );
498 QGridLayout* GroupParametersLayout = new QGridLayout( GroupParameters );
499 GroupParametersLayout->setMargin( 11 ); GroupParametersLayout->setSpacing( 6 );
501 TextLabelOrientation = new QLabel( tr("ORIENTATION"), GroupParameters);
502 TextLabelOrientation->setObjectName( "TextLabelOrientation" );
503 GroupParametersLayout->addWidget( TextLabelOrientation, 0, 0 );
505 CBRelativeOrientation = new QComboBox(GroupParameters);
506 CBRelativeOrientation->setObjectName( "RelativeOrientation" );
507 CBRelativeOrientation->addItem( tr("ALONG_XY") );
508 CBRelativeOrientation->addItem( tr("ALONG_YZ") );
509 CBRelativeOrientation->addItem( tr("ALONG_ZX") );
510 GroupParametersLayout->addWidget( CBRelativeOrientation, 0, 1 );
512 TextLabelDistance = new QLabel( tr("DISTANCE"), GroupParameters );
513 TextLabelDistance->setObjectName( "TextLabelDistance" );
514 GroupParametersLayout->addWidget( TextLabelDistance, 1, 0 );
516 SpinSliderDistance = new QtxDoubleSpinSlider( 0., 1., 0.01, GroupParameters );
517 SpinSliderDistance->setObjectName( "SpinSliderDistance" );
518 SpinSliderDistance->setPrecision( precision );
519 QFont fnt = SpinSliderDistance->font(); fnt.setBold( true ); SpinSliderDistance->setFont( fnt );
520 GroupParametersLayout->addWidget( SpinSliderDistance, 1, 1 );
522 QString aUnitRot = "\xB0";
524 TextLabelRotation1 = new QLabel( tr("ROTATION_AROUND_X_Y2Z"), GroupParameters );
525 TextLabelRotation1->setObjectName( "TextLabelRotation1" );
526 GroupParametersLayout->addWidget( TextLabelRotation1, 2, 0 );
528 SpinSliderRotation1 = new QtxIntSpinSlider( -180, 180, 1, GroupParameters );
529 SpinSliderRotation1->setObjectName( "SpinSliderRotation1" );
530 SpinSliderRotation1->setUnit( aUnitRot );
531 SpinSliderRotation1->setFont( fnt );
532 GroupParametersLayout->addWidget( SpinSliderRotation1, 2, 1 );
534 TextLabelRotation2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
535 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
536 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
537 GroupParametersLayout->addWidget( TextLabelRotation2, 3, 0 );
539 SpinSliderRotation2 = new QtxIntSpinSlider( -180, 180, 1, GroupParameters );
540 SpinSliderRotation2->setObjectName( "SpinSliderRotation2" );
541 SpinSliderRotation2->setUnit( aUnitRot );
542 SpinSliderRotation2->setFont( fnt );
543 GroupParametersLayout->addWidget( SpinSliderRotation2, 3, 1 );
545 /***************************************************************/
546 QGroupBox* CheckBoxWidget = new QGroupBox( this );
547 QHBoxLayout* CheckBoxLayout = new QHBoxLayout( CheckBoxWidget );
549 PreviewCheckBox = new QCheckBox( tr("PREVIEW"), CheckBoxWidget );
550 PreviewCheckBox->setObjectName( "PreviewCheckBox" );
551 PreviewCheckBox->setChecked( true );
552 CheckBoxLayout->addWidget( PreviewCheckBox, 0, Qt::AlignCenter );
554 AutoApplyCheckBox = new QCheckBox( tr("AUTO_APPLY"), CheckBoxWidget );
555 AutoApplyCheckBox->setObjectName( "AutoApplyCheckBox" );
556 CheckBoxLayout->addWidget( AutoApplyCheckBox, 0, Qt::AlignCenter );
558 /***************************************************************/
559 QGroupBox* GroupButtons = new QGroupBox( this );
560 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
561 GroupButtonsLayout->setAlignment( Qt::AlignTop );
562 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
564 buttonOk = new QPushButton( GroupButtons );
565 buttonOk->setObjectName( "buttonOk" );
566 buttonOk->setText( tr( "BUT_APPLY_AND_CLOSE" ) );
567 buttonOk->setAutoDefault( TRUE );
568 buttonOk->setDefault( TRUE );
569 GroupButtonsLayout->addWidget( buttonOk );
571 buttonApply = new QPushButton( GroupButtons );
572 buttonApply->setObjectName( "buttonApply" );
573 buttonApply->setText( tr( "BUT_APPLY" ) );
574 buttonApply->setAutoDefault( TRUE );
575 buttonApply->setDefault( TRUE );
576 GroupButtonsLayout->addWidget( buttonApply );
578 GroupButtonsLayout->addStretch();
580 buttonClose = new QPushButton( GroupButtons );
581 buttonClose->setObjectName( "buttonClose" );
582 buttonClose->setText( tr( "BUT_CLOSE" ) );
583 buttonClose->setAutoDefault( TRUE );
584 GroupButtonsLayout->addWidget( buttonClose );
586 QPushButton* buttonHelp = new QPushButton( tr( "HELP" ), GroupButtons );
587 buttonHelp->setAutoDefault( TRUE );
588 GroupButtonsLayout->addWidget( buttonHelp );
590 /***************************************************************/
591 ModeStackedLayout->addWidget( ModeActiveWidget );
592 ModeStackedLayout->addWidget( GroupParameters );
594 topLayout->addWidget( GroupPlanes );
595 topLayout->addLayout( ModeStackedLayout );
596 topLayout->addWidget( CheckBoxWidget );
597 topLayout->addWidget( GroupButtons );
599 this->setLayout( topLayout );
604 // Signals and slots connections
605 connect( ComboBoxPlanes, SIGNAL( activated( int ) ), this, SLOT( onSelectPlane( int ) ) );
606 connect( isActivePlane, SIGNAL ( toggled ( bool ) ), this, SLOT( onValueChanged() ) );
607 connect( buttonNew, SIGNAL( clicked() ), buttonNew, SLOT( showMenu() ) );
608 connect( buttonDelete, SIGNAL( clicked() ), this, SLOT( ClickOnDelete() ) );
609 connect( buttonDisableAll, SIGNAL( clicked() ), this, SLOT( ClickOnDisableAll() ) );
611 connect( resetButton, SIGNAL (clicked() ), this, SLOT( onReset() ) );
612 connect( invertButton, SIGNAL (clicked() ), this, SLOT( onInvert() ) ) ;
613 connect( SpinBox_X, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
614 connect( SpinBox_Y, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
615 connect( SpinBox_Z, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
616 connect( SpinBox_Dx, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
617 connect( SpinBox_Dy, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
618 connect( SpinBox_Dz, SIGNAL ( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
619 connect( CBAbsoluteOrientation, SIGNAL ( activated ( int ) ), this, SLOT( onOrientationAbsoluteChanged( int ) ) ) ;
621 connect( CBRelativeOrientation, SIGNAL( activated( int ) ), this, SLOT( onOrientationRelativeChanged( int ) ) );
622 connect( SpinSliderDistance, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
623 connect( SpinSliderRotation1, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
624 connect( SpinSliderRotation2, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
626 connect( PreviewCheckBox, SIGNAL ( toggled ( bool ) ), this, SLOT( onPreview( bool ) ) ) ;
627 connect( AutoApplyCheckBox, SIGNAL ( toggled( bool ) ), this, SLOT( onAutoApply( bool ) ) );
629 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) ) ;
630 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
631 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
632 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
635 myIsSelectPlane = false;
636 myIsPlaneCreation = false;
637 myIsUpdatingControls = false;
640 myModel->getViewer3d()->InitActiveViews();
642 OCCViewer_ViewManager* aViewMgr = (OCCViewer_ViewManager*) myModel->getViewManager();
643 myInteractor = new OCCViewer_ClipPlaneInteractor( aViewMgr, this );
644 connect( myInteractor, SIGNAL( planeClicked( const Handle_AIS_Plane& ) ), SLOT( onPlaneClicked( const Handle_AIS_Plane& ) ) );
645 connect( myInteractor, SIGNAL( planeDragged( const Handle_AIS_Plane& ) ), SLOT( onPlaneDragged( const Handle_AIS_Plane& ) ) );
647 myLocalPlanes = myModel->getClipPlanes();
653 Destroys the object and frees any allocated resources
655 OCCViewer_ClippingDlg::~OCCViewer_ClippingDlg()
657 myLocalPlanes.clear();
661 Custom handling of close event: erases preview
663 void OCCViewer_ClippingDlg::closeEvent( QCloseEvent* e )
666 QDialog::closeEvent( e );
667 OCCViewer_ViewWindow* v = qobject_cast<OCCViewer_ViewWindow*>(parent());
669 v->onClipping(false);
673 Custom handling of show event: displays preview
675 void OCCViewer_ClippingDlg::showEvent( QShowEvent* e )
677 QDialog::showEvent( e );
678 onPreview( PreviewCheckBox->isChecked() );
682 Custom handling of hide event: erases preview
684 void OCCViewer_ClippingDlg::hideEvent( QHideEvent* e )
687 QDialog::hideEvent( e );
688 OCCViewer_ViewWindow* v = qobject_cast<OCCViewer_ViewWindow*>(parent());
690 v->onClipping(false);
695 Initialization of initial values of widgets
697 void OCCViewer_ClippingDlg::initParam()
699 SpinBox_X->setValue( 0.0 );
700 SpinBox_Y->setValue( 0.0 );
701 SpinBox_Z->setValue( 0.0 );
703 SpinBox_Dx->setValue( 1.0 );
704 SpinBox_Dy->setValue( 1.0 );
705 SpinBox_Dz->setValue( 1.0 );
707 CBAbsoluteOrientation->setCurrentIndex(0);
709 SpinSliderDistance->setValue( 0.5 );
710 SpinSliderRotation1->setValue( 0 );
711 SpinSliderRotation2->setValue( 0 );
712 CBRelativeOrientation->setCurrentIndex( 0 );
714 isActivePlane->setChecked( true );
718 Set plane parameters from widgets.
720 void OCCViewer_ClippingDlg::setPlaneParam( OCCViewer_ClipPlane& thePlane )
722 OCCViewer_ClipPlane::PlaneMode aMode = currentPlaneMode();
724 thePlane.Mode = aMode;
726 if ( aMode == OCCViewer_ClipPlane::Absolute )
728 if( qFuzzyIsNull( SpinBox_Dx->value() ) &&
729 qFuzzyIsNull( SpinBox_Dy->value() ) &&
730 qFuzzyIsNull( SpinBox_Dz->value() ) ) {
735 thePlane.OrientationType = (aMode == OCCViewer_ClipPlane::Absolute)
736 ? CBAbsoluteOrientation->currentIndex()
737 : CBRelativeOrientation->currentIndex();
740 if ( aMode == OCCViewer_ClipPlane::Absolute )
742 if ( thePlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
744 thePlane.AbsoluteOrientation.Dx = SpinBox_Dx->value();
745 thePlane.AbsoluteOrientation.Dy = SpinBox_Dy->value();
746 thePlane.AbsoluteOrientation.Dz = SpinBox_Dz->value();
750 thePlane.AbsoluteOrientation.IsInvert = SpinBox_Dx->value() < 0.0
751 || SpinBox_Dy->value() < 0.0
752 || SpinBox_Dz->value() < 0.0;
755 thePlane.X = SpinBox_X->value();
756 thePlane.Y = SpinBox_Y->value();
757 thePlane.Z = SpinBox_Z->value();
761 thePlane.RelativeOrientation.Rotation1 = SpinSliderRotation1->value();
762 thePlane.RelativeOrientation.Rotation2 = SpinSliderRotation2->value();
764 double aPlaneDx = 0.0;
765 double aPlaneDy = 0.0;
766 double aPlaneDz = 0.0;
771 OCCViewer_ClipPlane::RelativeToDXYZ( thePlane.OrientationType,
772 thePlane.RelativeOrientation.Rotation1,
773 thePlane.RelativeOrientation.Rotation2,
774 aPlaneDx, aPlaneDy, aPlaneDz );
776 DistanceToXYZ( myModel->getAISContext(),
777 myModel->trihedronSize(),
778 SpinSliderDistance->value(),
779 aPlaneDx, aPlaneDy, aPlaneDz,
787 thePlane.IsOn = isActivePlane->isChecked();
791 Synchronize dialog's widgets with data
793 void OCCViewer_ClippingDlg::synchronize()
795 ComboBoxPlanes->clear();
796 int aNbPlanesAbsolute = myLocalPlanes.size();
799 for(int i = 1; i<=aNbPlanesAbsolute; i++ ) {
800 aName = QString("Plane %1").arg(i);
801 ComboBoxPlanes->addItem( aName );
804 int aPos = ComboBoxPlanes->count() - 1;
805 ComboBoxPlanes->setCurrentIndex( aPos );
807 bool anIsControlsEnable = ( aPos >= 0 );
808 if ( anIsControlsEnable ) {
809 onSelectPlane( aPos );
812 ComboBoxPlanes->addItem( tr( "NO_PLANES" ) );
815 if ( currentPlaneMode() == OCCViewer_ClipPlane::Absolute )
817 SpinBox_X->setEnabled( anIsControlsEnable );
818 SpinBox_Y->setEnabled( anIsControlsEnable );
819 SpinBox_Z->setEnabled( anIsControlsEnable );
820 SpinBox_Dx->setEnabled( anIsControlsEnable );
821 SpinBox_Dy->setEnabled( anIsControlsEnable );
822 SpinBox_Dz->setEnabled( anIsControlsEnable );
823 CBAbsoluteOrientation->setEnabled( anIsControlsEnable );
824 invertButton->setEnabled( anIsControlsEnable );
825 resetButton->setEnabled( anIsControlsEnable );
827 else if ( currentPlaneMode() == OCCViewer_ClipPlane::Relative )
829 CBRelativeOrientation->setEnabled( anIsControlsEnable );
830 SpinSliderDistance->setEnabled( anIsControlsEnable );
831 SpinSliderRotation1->setEnabled( anIsControlsEnable );
832 SpinSliderRotation2->setEnabled( anIsControlsEnable );
833 isActivePlane->setEnabled( anIsControlsEnable );
835 isActivePlane->setEnabled( anIsControlsEnable );
839 Displays preview of clipping plane
841 void OCCViewer_ClippingDlg::displayPreview()
843 if ( myBusy || !isValid() || !myModel)
846 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
848 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
850 for ( int i=0; i < clipPlanesCount(); i++ ) {
851 OCCViewer_ClipPlane& aClipPlane = getClipPlane(i);
852 if ( aClipPlane.IsOn ) {
853 Handle(AIS_Plane) myPreviewPlane;
857 clipPlaneParams(aClipPlane, ic, aSize, aBasePnt, aNormal, myModel->trihedronSize());
858 myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ), aBasePnt );
859 myPreviewPlane->SetTypeOfSensitivity( Select3D_TOS_INTERIOR );
860 myPreviewPlane->SetSize( aSize, aSize );
861 ic->SetWidth( myPreviewPlane, 10, false );
862 ic->SetMaterial( myPreviewPlane, Graphic3d_NOM_PLASTIC, false );
863 ic->SetTransparency( myPreviewPlane, 0.5, false );
864 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 );
865 ic->SetColor( myPreviewPlane, c , false );
866 ic->Display( myPreviewPlane, 1, 0, false );
867 myPreviewPlaneVector.push_back( myPreviewPlane );
872 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
873 getMinMaxFromContext( ic, myModel->trihedronSize(), aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
874 gp_Pnt aRotationCenter( (aXmax + aXmin) * 0.5,
875 (aYmax + aYmin) * 0.5,
876 (aZmax + aZmin) * 0.5 );
878 aMinMax.Update( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
880 myInteractor->setPlanes( myPreviewPlaneVector );
881 myInteractor->setRotationCenter( aRotationCenter );
882 myInteractor->setMinMax( aMinMax );
883 myInteractor->setEnabled( true );
886 void OCCViewer_ClippingDlg::updatePreview() {
887 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
888 int count = clipPlanesCount();
894 (aCurPlaneIndex +1 > count) ||
895 !PreviewCheckBox->isChecked())
898 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
900 OCCViewer_ClipPlane& aClipPlane = getClipPlane(aCurPlaneIndex);
901 Handle(AIS_Plane) myPreviewPlane;
903 if (aClipPlane.IsOn) {
907 clipPlaneParams(aClipPlane, ic, aSize, aBasePnt, aNormal, myModel->trihedronSize());
908 if(myPreviewPlaneVector.size() < clipPlanesCount()) {
909 myPreviewPlaneVector.resize(clipPlanesCount());
911 myPreviewPlane = myPreviewPlaneVector[aCurPlaneIndex];
912 if(myPreviewPlane.IsNull()) {
913 //Plane was not created
914 myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ), aBasePnt );
915 myPreviewPlane->SetTypeOfSensitivity( Select3D_TOS_INTERIOR );
916 myPreviewPlane->SetSize( aSize, aSize );
917 ic->Display( myPreviewPlane, 1, 0, false );
918 ic->SetWidth( myPreviewPlane, 10, false );
919 ic->SetMaterial( myPreviewPlane, Graphic3d_NOM_PLASTIC, false );
920 ic->SetTransparency( myPreviewPlane, 0.5, false );
921 myPreviewPlaneVector[aCurPlaneIndex] = myPreviewPlane;
923 myPreviewPlane->SetComponent( new Geom_Plane( aBasePnt, aNormal ) );
924 myPreviewPlane->SetCenter( aBasePnt );
925 myPreviewPlane->SetSize( aSize, aSize );
928 ic->SetColor( myPreviewPlane, Quantity_Color( 255. / 255., 70. / 255., 0. / 255., Quantity_TOC_RGB ), false );
929 ic->Update( myPreviewPlane, Standard_False );
931 if(myPreviewPlaneVector.size() > aCurPlaneIndex ) {
932 myPreviewPlane = myPreviewPlaneVector[aCurPlaneIndex];
933 if(ic->IsDisplayed(myPreviewPlane)) {
934 ic->Erase( myPreviewPlane, false );
935 ic->Remove( myPreviewPlane, false );
937 myPreviewPlaneVector[aCurPlaneIndex].Nullify();
940 for(int i = 0; i < myPreviewPlaneVector.size(); i++) {
941 if( i == aCurPlaneIndex ) continue;
942 if(!myPreviewPlaneVector[i].IsNull())
943 ic->SetColor( myPreviewPlaneVector[i], Quantity_Color( 85 / 255., 85 / 255., 255 / 255., Quantity_TOC_RGB ), false );
947 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
948 getMinMaxFromContext( ic, myModel->trihedronSize(), aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
949 gp_Pnt aRotationCenter( (aXmax + aXmin) * 0.5,
950 (aYmax + aYmin) * 0.5,
951 (aZmax + aZmin) * 0.5 );
953 aMinMax.Update( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
955 myInteractor->setPlanes( myPreviewPlaneVector );
956 myInteractor->setRotationCenter( aRotationCenter );
957 myInteractor->setMinMax( aMinMax );
961 Erases preview of clipping plane
963 void OCCViewer_ClippingDlg::erasePreview()
968 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
970 for ( int i=0; i < myPreviewPlaneVector.size(); i++ ) {
971 Handle(AIS_Plane) myPreviewPlane = myPreviewPlaneVector[i];
972 if ( !myPreviewPlane.IsNull() && ic->IsDisplayed( myPreviewPlane ) ) {
973 ic->Erase( myPreviewPlane, false );
974 ic->Remove( myPreviewPlane, false );
975 myPreviewPlane.Nullify();
978 myPreviewPlaneVector.clear();
980 myInteractor->setEnabled( false );
984 Return true if plane parameters are valid
986 bool OCCViewer_ClippingDlg::isValid()
988 return ( SpinBox_Dx->value() !=0 || SpinBox_Dy->value() !=0 || SpinBox_Dz->value() !=0 );
992 Update view after changes
994 void OCCViewer_ClippingDlg::updateClipping()
996 if (PreviewCheckBox->isChecked() || AutoApplyCheckBox->isChecked())
998 if (AutoApplyCheckBox->isChecked()) {
1002 if (!PreviewCheckBox->isChecked())
1010 Updates state of user controls.
1012 void OCCViewer_ClippingDlg::updateControls()
1014 if ( clipPlanesCount() == 0 )
1020 int aPlaneIdx = ComboBoxPlanes->currentIndex();
1022 OCCViewer_ClipPlane& aPlane = getClipPlane( aPlaneIdx );
1024 double aPlaneDx = 0.0;
1025 double aPlaneDy = 0.0;
1026 double aPlaneDz = 0.0;
1027 double aDistance = 0.0;
1028 aPlane.OrientationToXYZ( aPlaneDx, aPlaneDy, aPlaneDz );
1030 if ( aPlane.Mode == OCCViewer_ClipPlane::Absolute )
1032 ModeStackedLayout->setCurrentIndex( 0 );
1034 // Set plane parameters in the dialog
1035 SpinBox_X->setValue( aPlane.X );
1036 SpinBox_Y->setValue( aPlane.Y );
1037 SpinBox_Z->setValue( aPlane.Z );
1038 SpinBox_Dx->setValue( aPlaneDx );
1039 SpinBox_Dy->setValue( aPlaneDy );
1040 SpinBox_Dz->setValue( aPlaneDz );
1041 CBAbsoluteOrientation->setCurrentIndex( aPlane.OrientationType );
1042 onOrientationAbsoluteChanged( aPlane.OrientationType );
1044 else if( aPlane.Mode == OCCViewer_ClipPlane::Relative )
1046 ModeStackedLayout->setCurrentIndex( 1 );
1048 // Set plane parameters in the dialog
1049 SpinSliderRotation1->setValue( int( aPlane.RelativeOrientation.Rotation1 ) );
1050 SpinSliderRotation2->setValue( int( aPlane.RelativeOrientation.Rotation2 ) );
1052 XYZToDistance( myModel->getAISContext(),
1053 myModel->trihedronSize(),
1054 aPlane.X, aPlane.Y, aPlane.Z,
1055 aPlaneDx, aPlaneDy, aPlaneDz,
1058 SpinSliderDistance->setValue( aDistance );
1060 CBRelativeOrientation->setCurrentIndex( aPlane.OrientationType );
1061 onOrientationRelativeChanged( aPlane.OrientationType );
1064 isActivePlane->setChecked( aPlane.IsOn );
1068 SLOT on new button click: create a new clipping plane
1070 void OCCViewer_ClippingDlg::ClickOnNew()
1072 OCCViewer_ClipPlane aClipPlane;
1074 // init controls state
1075 myIsUpdatingControls = true;
1077 myIsUpdatingControls = false;
1079 // init plane according to the state of controls
1080 setPlaneParam( aClipPlane );
1083 myLocalPlanes.push_back( aClipPlane );
1088 SLOT on delete button click: Delete selected clipping plane
1090 void OCCViewer_ClippingDlg::ClickOnDelete()
1092 int aPlaneIndex = ComboBoxPlanes->currentIndex();
1093 if ( (clipPlanesCount() == 0) || (aPlaneIndex+1 > clipPlanesCount()))
1096 myLocalPlanes.erase(myLocalPlanes.begin() + aPlaneIndex);
1098 Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
1100 if(aPlaneIndex+1 <= myPreviewPlaneVector.size()) {
1101 Handle(AIS_Plane) myPreviewPlane = myPreviewPlaneVector[aPlaneIndex];
1102 if ( !myPreviewPlane.IsNull() && ic->IsDisplayed( myPreviewPlane ) ) {
1103 ic->Erase( myPreviewPlane, false );
1104 ic->Remove( myPreviewPlane, false );
1106 myPreviewPlaneVector.erase(myPreviewPlaneVector.begin() + aPlaneIndex);
1109 if (AutoApplyCheckBox->isChecked()) {
1116 SLOT on disable all button click: Restore initial state of viewer,
1117 erase all clipping planes
1119 void OCCViewer_ClippingDlg::ClickOnDisableAll()
1121 AutoApplyCheckBox->setChecked (false);
1122 int aClipPlanesCount = clipPlanesCount();
1123 for ( int anIndex = 0; anIndex < aClipPlanesCount; anIndex++)
1125 OCCViewer_ClipPlane& aPlane = getClipPlane(anIndex);
1126 aPlane.IsOn = false;
1129 isActivePlane->setChecked(false);
1130 myModel->setClipPlanes(myLocalPlanes);
1135 SLOT on ok button click: sets cutting plane and closes dialog
1137 void OCCViewer_ClippingDlg::ClickOnOk()
1144 SLOT on Apply button click: sets cutting plane and update viewer
1146 void OCCViewer_ClippingDlg::ClickOnApply()
1153 SLOT on close button click: erases preview and rejects dialog
1155 void OCCViewer_ClippingDlg::ClickOnClose()
1158 OCCViewer_ViewWindow* v = qobject_cast<OCCViewer_ViewWindow*>(parent());
1160 v->onClipping(false);
1164 SLOT on help button click: opens a help page
1166 void OCCViewer_ClippingDlg::ClickOnHelp()
1168 SUIT_Application* app = SUIT_Session::session()->activeApplication();
1170 app->onHelpContextModule( "GUI", "occ_3d_viewer_page.html", "clipping_planes" );
1174 Set absolute mode of clipping plane
1176 void OCCViewer_ClippingDlg::onModeAbsolute()
1178 myIsPlaneCreation = true;
1179 ModeStackedLayout->setCurrentIndex(0);
1181 myIsPlaneCreation = false;
1186 Set relative mode of clipping plane
1188 void OCCViewer_ClippingDlg::onModeRelative()
1190 myIsPlaneCreation = true;
1191 ModeStackedLayout->setCurrentIndex(1);
1193 myIsPlaneCreation = false;
1194 SetCurrentPlaneParam();
1199 SLOT: called on value of clipping plane changed
1201 void OCCViewer_ClippingDlg::onValueChanged()
1203 if ( myIsUpdatingControls )
1208 SetCurrentPlaneParam();
1210 if ( myIsSelectPlane )
1219 Set current parameters of selected plane
1221 void OCCViewer_ClippingDlg::onSelectPlane ( int theIndex )
1223 if ( clipPlanesCount() == 0 )
1228 OCCViewer_ClipPlane& aClipPlane = getClipPlane( theIndex );
1230 myIsSelectPlane = true;
1232 ComboBoxPlanes->setCurrentIndex( theIndex );
1233 myIsSelectPlane = false;
1237 Restore parameters of selected plane
1239 void OCCViewer_ClippingDlg::SetCurrentPlaneParam()
1241 if ( clipPlanesCount() == 0 || myIsSelectPlane || myBusy )
1246 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1248 OCCViewer_ClipPlane& aPlane = getClipPlane( aCurPlaneIndex );
1250 setPlaneParam( aPlane );
1254 SLOT on reset button click: sets default values
1256 void OCCViewer_ClippingDlg::onReset()
1259 SpinBox_X->setValue(0);
1260 SpinBox_Y->setValue(0);
1261 SpinBox_Z->setValue(0);
1268 SLOT on invert button click: inverts normal of cutting plane
1270 void OCCViewer_ClippingDlg::onInvert()
1272 double Dx = SpinBox_Dx->value();
1273 double Dy = SpinBox_Dy->value();
1274 double Dz = SpinBox_Dz->value();
1277 SpinBox_Dx->setValue( -Dx );
1278 SpinBox_Dy->setValue( -Dy );
1279 SpinBox_Dz->setValue( -Dz );
1282 if ( clipPlanesCount() != 0 )
1284 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1285 OCCViewer_ClipPlane& aPlane = getClipPlane( aCurPlaneIndex );
1286 aPlane.AbsoluteOrientation.IsInvert = !aPlane.AbsoluteOrientation.IsInvert;
1292 SLOT: called on orientation of clipping plane in absolute mode changed
1294 void OCCViewer_ClippingDlg::onOrientationAbsoluteChanged( int mode )
1296 bool isUserMode = (mode==0);
1298 TextLabelX->setEnabled( isUserMode );
1299 TextLabelY->setEnabled( isUserMode );
1300 TextLabelZ->setEnabled( isUserMode );
1302 SpinBox_X->setEnabled( isUserMode );
1303 SpinBox_Y->setEnabled( isUserMode );
1304 SpinBox_Z->setEnabled( isUserMode );
1306 TextLabelDx->setEnabled( isUserMode );
1307 TextLabelDy->setEnabled( isUserMode );
1308 TextLabelDz->setEnabled( isUserMode );
1310 SpinBox_Dx->setEnabled( isUserMode );
1311 SpinBox_Dy->setEnabled( isUserMode );
1312 SpinBox_Dz->setEnabled( isUserMode );
1314 if ( !isUserMode ) {
1316 double aDx = 0, aDy = 0, aDz = 0;
1321 TextLabelZ->setEnabled( true );
1322 SpinBox_Z->setEnabled( true );
1323 SpinBox_Z->setFocus();
1325 else if ( mode == 2 )
1328 TextLabelX->setEnabled( true );
1329 SpinBox_X->setEnabled( true );
1330 SpinBox_X->setFocus();
1332 else if ( mode == 3 )
1335 TextLabelY->setEnabled( true );
1336 SpinBox_Y->setEnabled( true );
1337 SpinBox_Y->setFocus();
1340 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1341 OCCViewer_ClipPlane& aPlane = getClipPlane( aCurPlaneIndex );
1342 if ( aPlane.AbsoluteOrientation.IsInvert == true )
1350 SpinBox_Dx->setValue( aDx );
1351 SpinBox_Dy->setValue( aDy );
1352 SpinBox_Dz->setValue( aDz );
1356 if ( !myIsUpdatingControls )
1358 SetCurrentPlaneParam();
1364 SLOT: called on orientation of clipping plane in relative mode changed
1366 void OCCViewer_ClippingDlg::onOrientationRelativeChanged (int theItem)
1368 if ( clipPlanesCount() == 0 )
1371 if ( theItem == 0 ) {
1372 TextLabelRotation1->setText( tr( "ROTATION_AROUND_X_Y2Z" ) );
1373 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Y_X2Z" ) );
1375 else if ( theItem == 1 ) {
1376 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Y_Z2X" ) );
1377 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Z_Y2X" ) );
1379 else if ( theItem == 2 ) {
1380 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Z_X2Y" ) );
1381 TextLabelRotation2->setText( tr( "ROTATION_AROUND_X_Z2Y" ) );
1384 if ( !myIsUpdatingControls )
1386 if( (QComboBox*)sender() == CBRelativeOrientation )
1388 SetCurrentPlaneParam();
1396 SLOT: called on preview check box toggled
1398 void OCCViewer_ClippingDlg::onPreview( bool on )
1406 SLOT: called on Auto Apply check box toggled
1408 void OCCViewer_ClippingDlg::onAutoApply( bool toggled )
1417 SLOT on Apply button click: sets cutting plane
1419 void OCCViewer_ClippingDlg::onApply()
1423 myIsSelectPlane = true;
1425 qApp->processEvents();
1426 QApplication::setOverrideCursor( Qt::WaitCursor );
1427 qApp->processEvents();
1429 myModel->setClipPlanes(myLocalPlanes);
1431 QApplication::restoreOverrideCursor();
1432 myIsSelectPlane = false;
1436 SLOT: Called when clip plane is clicked in viewer.
1438 void OCCViewer_ClippingDlg::onPlaneClicked( const Handle(AIS_Plane)& thePlane )
1440 for ( int aPlaneIt = 0; aPlaneIt < myPreviewPlaneVector.size(); aPlaneIt++ )
1442 Handle(AIS_Plane)& aPlane = myPreviewPlaneVector.at( aPlaneIt );
1443 if ( aPlane != thePlane )
1448 ComboBoxPlanes->setCurrentIndex( aPlaneIt );
1455 SLOT: Called when clip plane is changed by dragging in viewer.
1457 void OCCViewer_ClippingDlg::onPlaneDragged( const Handle(AIS_Plane)& thePlane )
1459 for ( int aPlaneIt = 0; aPlaneIt < myPreviewPlaneVector.size(); aPlaneIt++ )
1461 Handle(AIS_Plane)& aPlane = myPreviewPlaneVector.at( aPlaneIt );
1462 if ( aPlane != thePlane )
1467 OCCViewer_ClipPlane& aClipPlane = getClipPlane( aPlaneIt );
1469 gp_Pln aPln = thePlane->Component()->Pln();
1470 const gp_Pnt& aPlaneP = aPln.Location();
1471 const gp_Dir& aPlaneN = aPln.Axis().Direction();
1473 aClipPlane.X = aPlaneP.X();
1474 aClipPlane.Y = aPlaneP.Y();
1475 aClipPlane.Z = aPlaneP.Z();
1477 if ( aClipPlane.Mode == OCCViewer_ClipPlane::Absolute )
1479 if ( aClipPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
1481 aClipPlane.AbsoluteOrientation.Dx = aPlaneN.X();
1482 aClipPlane.AbsoluteOrientation.Dy = aPlaneN.Y();
1483 aClipPlane.AbsoluteOrientation.Dz = aPlaneN.Z();
1488 OCCViewer_ClipPlane::DXYZToRelative( aPlaneN.X(), aPlaneN.Y(), aPlaneN.Z(),
1489 aClipPlane.OrientationType,
1490 aClipPlane.RelativeOrientation.Rotation1,
1491 aClipPlane.RelativeOrientation.Rotation2 );
1494 myIsUpdatingControls = true;
1496 myIsUpdatingControls = false;
1498 if ( AutoApplyCheckBox->isChecked() )
1507 OCCViewer_ClipPlane& OCCViewer_ClippingDlg::getClipPlane( int theIdx )
1509 return myLocalPlanes[theIdx];
1512 int OCCViewer_ClippingDlg::clipPlanesCount()
1514 return myLocalPlanes.size();
1517 OCCViewer_ClipPlane::PlaneMode OCCViewer_ClippingDlg::currentPlaneMode() const
1519 return ModeStackedLayout->currentIndex() == 0
1520 ? OCCViewer_ClipPlane::Absolute
1521 : OCCViewer_ClipPlane::Relative;