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 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_ClippingDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
28 #include "SMESHGUI_ClippingDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_SpinBox.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
38 // SALOME GUI includes
39 #include <SUIT_Desktop.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_OverrideCursor.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_ViewManager.h>
46 #include <SALOME_ListIO.hxx>
48 #include <SalomeApp_Study.h>
50 #include <LightApp_Application.h>
52 #include <VTKViewer_Algorithm.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SVTK_RenderWindowInteractor.h>
59 #include <QPushButton>
62 #include <QVBoxLayout>
63 #include <QHBoxLayout>
64 #include <QGridLayout>
67 #include <QListWidget>
68 #include <QStackedLayout>
74 #include <vtkDataSet.h>
75 #include <vtkDataSetMapper.h>
76 #include <vtkPlaneSource.h>
77 #include <vtkProperty.h>
78 #include <vtkRenderer.h>
79 #include <vtkCallbackCommand.h>
80 #include <vtkImplicitPlaneWidget.h>
84 #define SIZEFACTOR 1.1
87 Create new object of class OrientedPlane
89 SMESH::OrientedPlane* SMESH::OrientedPlane::New()
91 return new OrientedPlane();
95 Create new object of class OrientedPlane
97 SMESH::OrientedPlane* SMESH::OrientedPlane::New( SVTK_ViewWindow* theViewWindow )
99 return new OrientedPlane( theViewWindow );
103 Copy the object of class OrientedPlane
105 void SMESH::OrientedPlane::ShallowCopy( SMESH::OrientedPlane* theOrientedPlane )
107 SetNormal( theOrientedPlane->GetNormal() );
108 SetOrigin( theOrientedPlane->GetOrigin() );
110 myRelativeOrientation = theOrientedPlane->GetOrientation();
111 myDistance = theOrientedPlane->GetDistance();
113 IsOpenGLClipping = theOrientedPlane->IsOpenGLClipping;
115 myAngle[0] = theOrientedPlane->myAngle[0];
116 myAngle[1] = theOrientedPlane->myAngle[1];
118 myAbsoluteOrientation = theOrientedPlane->myAbsoluteOrientation;
119 X = theOrientedPlane->X;
120 Y = theOrientedPlane->Y;
121 Z = theOrientedPlane->Z;
122 Dx = theOrientedPlane->Dx;
123 Dy = theOrientedPlane->Dy;
124 Dz = theOrientedPlane->Dz;
126 PlaneMode = theOrientedPlane->PlaneMode;
128 myPlaneSource->SetNormal( theOrientedPlane->myPlaneSource->GetNormal() );
129 myPlaneSource->SetOrigin( theOrientedPlane->myPlaneSource->GetOrigin() );
130 myPlaneSource->SetPoint1( theOrientedPlane->myPlaneSource->GetPoint1() );
131 myPlaneSource->SetPoint2( theOrientedPlane->myPlaneSource->GetPoint2() );
132 myPlaneSource->Update();
136 Invert current clipping plane in contrary direction
138 SMESH::OrientedPlane* SMESH::OrientedPlane::InvertPlane()
140 OrientedPlane* aPlane = new OrientedPlane();
141 aPlane->ShallowCopy( this );
142 double* aNormal = aPlane->GetNormal();
143 for( int i=0; i<3; i++ )
144 aNormal[i] = -aNormal[i];
145 aPlane->SetNormal( aNormal );
150 Constructor of class OrientedPlane
152 SMESH::OrientedPlane::OrientedPlane(SVTK_ViewWindow* theViewWindow):
153 myViewWindow(theViewWindow)
156 myViewWindow->AddActor(myActor, false, false); // don't adjust actors
160 Constructor of class OrientedPlane
162 SMESH::OrientedPlane::OrientedPlane():
169 Initialize parameters of class OrientedPlane
171 void SMESH::OrientedPlane::Init()
173 myPlaneSource = vtkPlaneSource::New();
175 PlaneMode = SMESH::Absolute;
178 myAbsoluteOrientation = 0; // CUSTOM
179 myRelativeOrientation = SMESH::XY;
181 myAngle[0] = myAngle[1] = 0.0;
183 IsOpenGLClipping = false;
185 // Create and display actor
186 myMapper = vtkDataSetMapper::New();
187 myMapper->SetInputConnection(myPlaneSource->GetOutputPort());
189 myActor = SALOME_Actor::New();
190 myActor->VisibilityOff();
191 myActor->PickableOff();
192 myActor->SetInfinitive(true);
193 myActor->SetMapper(myMapper);
197 SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "255, 170, 0|-100" ) ;
199 vtkProperty* aProp = vtkProperty::New();
200 SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "255, 170, 0|-100" ) ;
201 aProp->SetColor(ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255.);
202 aProp->SetOpacity(0.75);
203 myActor->SetProperty(aProp);
206 vtkProperty* aBackProp = vtkProperty::New();
207 bfc = Qtx::mainColorToSecondary(ffc, delta);
208 aBackProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255.);
209 aBackProp->SetOpacity(0.75);
210 myActor->SetBackfaceProperty(aBackProp);
215 Destructor of class OrientedPlane
217 SMESH::OrientedPlane::~OrientedPlane()
220 myViewWindow->RemoveActor(myActor);
223 myMapper->RemoveAllInputs();
226 // commented: porting to vtk 5.0
227 // myPlaneSource->UnRegisterAllOutputs();
228 myPlaneSource->Delete();
232 Definition of class ActorItem
234 class ActorItem : public QListWidgetItem
237 ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) :
238 QListWidgetItem( theName, theListWidget ),
239 myActor( theActor ) {}
241 SMESH_Actor* getActor() const { return myActor; }
244 SMESH_Actor* myActor;
248 Definition of class TSetVisibility
250 struct TSetVisibility {
251 // Set visibility of cutting plane
252 TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){}
253 void operator()(SMESH::TPlaneData& thePlaneData){
254 bool anIsEmpty = thePlaneData.ActorList.empty();
255 thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty);
260 /*********************************************************************************
261 ********************* class SMESHGUI_ClippingDlg *********************
262 *********************************************************************************/
267 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
268 QDialog( SMESH::GetDesktop(theModule) ),
269 mySMESHGUI(theModule),
270 myViewWindow(theViewWindow)
273 setAttribute( Qt::WA_DeleteOnClose, true );
274 setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
275 setSizeGripEnabled(true);
277 myPreviewWidget = vtkImplicitPlaneWidget::New();
278 myCallback = vtkCallbackCommand::New();
279 myCallback->SetClientData( this );
280 myCallback->SetCallback( SMESHGUI_ClippingDlg::ProcessEvents );
281 myPreviewWidget = createPreviewWidget();
283 myIsPreviewMoved = false;
285 QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
286 SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
287 SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
289 // Controls for selecting, creating, deleting planes
290 QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
291 QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
292 GroupPlanesLayout->setSpacing(SPACING);
293 GroupPlanesLayout->setMargin(MARGIN);
295 ComboBoxPlanes = new QComboBox(GroupPlanes);
297 isOpenGLClipping = new QCheckBox( GroupPlanes );
298 isOpenGLClipping->setText( tr( "IS_OPENGL_CLIPPING" ) );
300 buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
302 MenuMode = new QMenu( "MenuMode", buttonNew );
303 MenuMode->addAction( tr( "ABSOLUTE" ), this, SLOT( onModeAbsolute() ) );
304 MenuMode->addAction( tr( "RELATIVE" ), this, SLOT( onModeRelative() ) );
305 buttonNew->setMenu( MenuMode );
306 CurrentMode = SMESH::Absolute;
308 buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
310 QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
312 ActorList = new QListWidget(GroupPlanes);
313 ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
315 SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
317 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
318 GroupPlanesLayout->addWidget(isOpenGLClipping, 0, 1);
319 GroupPlanesLayout->addWidget(new QWidget(), 0, 2);
320 GroupPlanesLayout->addWidget(buttonNew, 0, 3);
321 GroupPlanesLayout->addWidget(buttonDelete, 0, 4);
322 GroupPlanesLayout->addWidget(aLabel, 1, 0, 1, 5);
323 GroupPlanesLayout->addWidget(ActorList, 2, 0, 1, 5);
324 GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 5);
325 GroupPlanesLayout->setColumnStretch( 1, 1 );
327 ModeStackedLayout = new QStackedLayout();
329 // Controls for defining plane parameters
330 /********************** Mode Absolute **********************/
331 /* Controls for absolute mode of clipping plane:
332 X, Y, Z - coordinates of the intersection of cutting plane and the three axes
333 Dx, Dy, Dz - components of normal to the cutting plane
334 Orientation - direction of cutting plane
336 const double min = -1e+7;
337 const double max = 1e+7;
338 const double step = 5;
339 const int precision = -7;
342 QGroupBox* GroupAbsolutePoint = new QGroupBox( this );
343 GroupAbsolutePoint->setObjectName( "GroupPoint" );
344 GroupAbsolutePoint->setTitle( tr("BASE_POINT") );
345 QGridLayout* GroupPointLayout = new QGridLayout( GroupAbsolutePoint );
346 GroupPointLayout->setAlignment( Qt::AlignTop );
347 GroupPointLayout->setSpacing( 6 ); GroupPointLayout->setMargin( 11 );
349 TextLabelX = new QLabel( GroupAbsolutePoint );
350 TextLabelX->setObjectName( "TextLabelX" );
351 TextLabelX->setText( tr("X:") );
352 GroupPointLayout->addWidget( TextLabelX, 0, 0 );
354 SpinBox_X = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
355 SpinBox_X->setObjectName("SpinBox_X" );
356 SpinBox_X->setPrecision( precision );
357 GroupPointLayout->addWidget( SpinBox_X, 0, 1 );
359 TextLabelY = new QLabel( GroupAbsolutePoint );
360 TextLabelY->setObjectName( "TextLabelY" );
361 TextLabelY->setText( tr("Y:") );
362 GroupPointLayout->addWidget( TextLabelY, 0, 2 );
364 SpinBox_Y = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
365 SpinBox_Y->setObjectName("SpinBox_Y" );
366 SpinBox_Y->setPrecision( precision );
367 GroupPointLayout->addWidget( SpinBox_Y, 0, 3 );
369 TextLabelZ = new QLabel( GroupAbsolutePoint );
370 TextLabelZ->setObjectName( "TextLabelZ" );
371 TextLabelZ->setText( tr("Z:") );
372 GroupPointLayout->addWidget( TextLabelZ, 0, 4 );
374 SpinBox_Z = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
375 SpinBox_Z->setObjectName("SpinBox_Z" );
376 SpinBox_Z->setPrecision( precision );
377 GroupPointLayout->addWidget( SpinBox_Z, 0, 5 );
379 resetButton = new QPushButton( GroupAbsolutePoint );
380 resetButton->setObjectName( "resetButton" );
381 resetButton->setText( tr( "RESET" ) );
382 GroupPointLayout->addWidget( resetButton, 0, 6 );
385 GroupAbsoluteDirection = new QGroupBox( this );
386 GroupAbsoluteDirection->setObjectName( "GroupDirection" );
387 GroupAbsoluteDirection->setTitle( tr("DIRECTION") );
388 QGridLayout* GroupDirectionLayout = new QGridLayout( GroupAbsoluteDirection );
389 GroupDirectionLayout->setAlignment( Qt::AlignTop );
390 GroupDirectionLayout->setSpacing( 6 );
391 GroupDirectionLayout->setMargin( 11 );
393 TextLabelDx = new QLabel( GroupAbsoluteDirection );
394 TextLabelDx->setObjectName( "TextLabelDx" );
395 TextLabelDx->setText( tr("Dx:") );
396 GroupDirectionLayout->addWidget( TextLabelDx, 0, 0 );
398 SpinBox_Dx = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
399 SpinBox_Dx->setObjectName("SpinBox_Dx" );
400 SpinBox_Dx->setPrecision( precision );
401 GroupDirectionLayout->addWidget( SpinBox_Dx, 0, 1 );
403 TextLabelDy = new QLabel( GroupAbsoluteDirection );
404 TextLabelDy->setObjectName( "TextLabelDy" );
405 TextLabelDy->setText( tr("Dy:") );
406 GroupDirectionLayout->addWidget( TextLabelDy, 0, 2 );
408 SpinBox_Dy = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
409 SpinBox_Dy->setObjectName("SpinBox_Dy" );
410 SpinBox_Dy->setPrecision( precision );
411 GroupDirectionLayout->addWidget( SpinBox_Dy, 0, 3 );
413 TextLabelDz = new QLabel( GroupAbsoluteDirection );
414 TextLabelDz->setObjectName( "TextLabelDz" );
415 TextLabelDz->setText( tr("Dz:") );
416 GroupDirectionLayout->addWidget( TextLabelDz, 0, 4 );
418 SpinBox_Dz = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
419 SpinBox_Dz->setObjectName("SpinBox_Dz" );
420 SpinBox_Dz->setPrecision( precision );
421 GroupDirectionLayout->addWidget( SpinBox_Dz, 0, 5 );
423 invertButton = new QPushButton( GroupAbsoluteDirection );
424 invertButton->setObjectName( "invertButton" );
425 invertButton->setText( tr( "INVERT" ) );
426 GroupDirectionLayout->addWidget( invertButton, 0, 6 );
428 CBAbsoluteOrientation = new QComboBox( GroupAbsoluteDirection );
429 CBAbsoluteOrientation->setObjectName( "AbsoluteOrientation" );
430 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "CUSTOM" ) );
431 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||X-Y" ) );
432 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Y-Z" ) );
433 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Z-X" ) );
434 GroupDirectionLayout->addWidget( CBAbsoluteOrientation, 1, 0, 1, 6 );
436 QVBoxLayout* ModeActiveLayout = new QVBoxLayout();
437 ModeActiveLayout->setMargin( 11 ); ModeActiveLayout->setSpacing( 6 );
438 ModeActiveLayout->addWidget( GroupAbsolutePoint );
439 ModeActiveLayout->addWidget( GroupAbsoluteDirection );
441 QWidget* ModeActiveWidget = new QWidget( this );
442 ModeActiveWidget->setLayout( ModeActiveLayout );
444 /********************** Mode Relative **********************/
445 /* Controls for relative mode of clipping plane:
446 Distance - Value from 0 to 1.
447 Specifies the distance from the minimum value in a given direction of bounding box to the current position
448 Rotation1, Rotation2 - turn angles of cutting plane in given directions
449 Orientation - direction of cutting plane
451 QGroupBox* GroupParameters = new QGroupBox( tr("SMESH_PARAMETERS"), this );
452 QGridLayout* GroupParametersLayout = new QGridLayout( GroupParameters );
453 GroupParametersLayout->setMargin( 11 ); GroupParametersLayout->setSpacing( 6 );
455 TextLabelOrientation = new QLabel( tr("SMESH_ORIENTATION"), GroupParameters);
456 TextLabelOrientation->setObjectName( "TextLabelOrientation" );
457 GroupParametersLayout->addWidget( TextLabelOrientation, 0, 0 );
459 CBRelativeOrientation = new QComboBox(GroupParameters);
460 CBRelativeOrientation->setObjectName( "RelativeOrientation" );
461 CBRelativeOrientation->addItem( tr("ALONG_XY") );
462 CBRelativeOrientation->addItem( tr("ALONG_YZ") );
463 CBRelativeOrientation->addItem( tr("ALONG_ZX") );
464 GroupParametersLayout->addWidget( CBRelativeOrientation, 0, 1 );
466 TLValueDistance = new QLabel( GroupParameters );
467 TLValueDistance->setObjectName( "TLValueDistance" );
468 TLValueDistance->setAlignment( Qt::AlignCenter );
469 TLValueDistance->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
470 QFont fnt = TLValueDistance->font(); fnt.setBold( true ); TLValueDistance->setFont( fnt );
471 GroupParametersLayout->addWidget( TLValueDistance, 1, 1 );
473 TextLabelDistance = new QLabel( tr("SMESH_DISTANCE"), GroupParameters );
474 TextLabelDistance->setObjectName( "TextLabelDistance" );
475 GroupParametersLayout->addWidget( TextLabelDistance, 2, 0 );
477 SliderDistance = new QSlider( Qt::Horizontal, GroupParameters );
478 SliderDistance->setObjectName( "SliderDistance" );
479 SliderDistance->setMinimumSize( 300, 0 );
480 SliderDistance->setMinimum( 0 );
481 SliderDistance->setMaximum( 100 );
482 SliderDistance->setSingleStep( 1 );
483 SliderDistance->setPageStep( 10 );
484 SliderDistance->setTracking( false );
485 GroupParametersLayout->addWidget( SliderDistance, 2, 1 );
487 TLValueRotation1 = new QLabel( GroupParameters );
488 TLValueRotation1->setObjectName( "TLValueRotation1" );
489 TLValueRotation1->setAlignment( Qt::AlignCenter );
490 TLValueRotation1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
491 TLValueRotation1->setFont( fnt );
492 GroupParametersLayout->addWidget( TLValueRotation1, 3, 1 );
494 TextLabelRotation1 = new QLabel( tr("ROTATION_AROUND_X_Y2Z"), GroupParameters );
495 TextLabelRotation1->setObjectName( "TextLabelRotation1" );
496 GroupParametersLayout->addWidget( TextLabelRotation1, 4, 0 );
498 SliderRotation1 = new QSlider( Qt::Horizontal, GroupParameters );
499 SliderRotation1->setObjectName( "SliderRotation1" );
500 SliderRotation1->setMinimumSize( 300, 0 );
501 SliderRotation1->setMinimum( -180 );
502 SliderRotation1->setMaximum( 180 );
503 SliderRotation1->setSingleStep( 1 );
504 SliderRotation1->setPageStep( 10 );
505 SliderRotation1->setTracking(false);
506 GroupParametersLayout->addWidget( SliderRotation1, 4, 1 );
508 TLValueRotation2 = new QLabel( GroupParameters );
509 TLValueRotation2->setObjectName( "TLValueRotation2" );
510 TLValueRotation2->setAlignment( Qt::AlignCenter );
511 TLValueRotation2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
512 TLValueRotation2->setFont( fnt );
513 GroupParametersLayout->addWidget( TLValueRotation2, 5, 1 );
515 TextLabelRotation2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
516 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
517 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
518 GroupParametersLayout->addWidget( TextLabelRotation2, 6, 0 );
520 SliderRotation2 = new QSlider( Qt::Horizontal, GroupParameters );
521 SliderRotation2->setObjectName( "SliderRotation2" );
522 SliderRotation2->setMinimumSize( 300, 0 );
523 SliderRotation2->setMinimum( -180 );
524 SliderRotation2->setMaximum( 180 );
525 SliderRotation2->setSingleStep( 1 );
526 SliderRotation2->setPageStep( 10 );
527 SliderRotation2->setTracking(false);
528 GroupParametersLayout->addWidget( SliderRotation2, 6, 1 );
530 /***************************************************************/
531 QWidget* CheckBoxWidget = new QWidget( this );
532 QHBoxLayout* CheckBoxLayout = new QHBoxLayout( CheckBoxWidget );
534 PreviewCheckBox = new QCheckBox( tr("SHOW_PREVIEW"), CheckBoxWidget );
535 PreviewCheckBox->setObjectName( "PreviewCheckBox" );
536 PreviewCheckBox->setChecked( true );
537 CheckBoxLayout->addWidget( PreviewCheckBox, 0, Qt::AlignCenter );
539 AutoApplyCheckBox = new QCheckBox( tr("AUTO_APPLY"), CheckBoxWidget );
540 AutoApplyCheckBox->setObjectName( "AutoApplyCheckBox" );
541 CheckBoxLayout->addWidget( AutoApplyCheckBox, 0, Qt::AlignCenter );
543 /***************************************************************/
544 // Controls for "Ok", "Apply" and "Close" button
545 QGroupBox* GroupButtons = new QGroupBox(this);
546 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
547 GroupButtonsLayout->setSpacing(SPACING);
548 GroupButtonsLayout->setMargin(MARGIN);
550 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
551 buttonOk->setAutoDefault( true );
552 buttonOk->setDefault( true );
553 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
554 buttonApply->setAutoDefault( true );
555 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
556 buttonCancel->setAutoDefault( true );
557 buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
558 buttonHelp->setAutoDefault( true );
559 GroupButtonsLayout->addWidget( buttonOk );
560 GroupButtonsLayout->addSpacing(10);
561 GroupButtonsLayout->addWidget( buttonApply );
562 GroupButtonsLayout->addSpacing(10);
563 GroupButtonsLayout->addStretch();
564 GroupButtonsLayout->addWidget( buttonCancel );
565 GroupButtonsLayout->addWidget( buttonHelp );
567 ModeStackedLayout->addWidget( ModeActiveWidget );
568 ModeStackedLayout->addWidget( GroupParameters );
570 SMESHGUI_ClippingDlgLayout->addWidget( GroupPlanes );
571 SMESHGUI_ClippingDlgLayout->addLayout( ModeStackedLayout );
572 SMESHGUI_ClippingDlgLayout->addWidget( CheckBoxWidget );
573 SMESHGUI_ClippingDlgLayout->addWidget( GroupButtons );
578 myIsSelectPlane = false;
580 myHelpFileName = "clipping_page.html";
582 // signals and slots connections :
583 connect( ComboBoxPlanes, SIGNAL( activated( int ) ), this, SLOT( onSelectPlane( int ) ) );
584 connect( isOpenGLClipping, SIGNAL( toggled( bool ) ), this, SLOT( onIsOpenGLClipping( bool ) ) );
585 connect( buttonNew, SIGNAL( clicked() ), buttonNew, SLOT( showMenu() ) );
586 connect( buttonDelete, SIGNAL( clicked() ), this, SLOT( ClickOnDelete() ) );
587 connect( ActorList, SIGNAL( itemChanged( QListWidgetItem* ) ), this, SLOT( onActorItemChanged( QListWidgetItem*) ) );
588 connect( SelectAllCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( onSelectAll( int ) ) );
590 connect( invertButton, SIGNAL (clicked() ), this, SLOT( onInvert() ) ) ;
591 connect( resetButton, SIGNAL (clicked() ), this, SLOT( onReset() ) );
592 connect( SpinBox_X, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
593 connect( SpinBox_Y, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
594 connect( SpinBox_Z, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
595 connect( SpinBox_Dx, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
596 connect( SpinBox_Dy, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
597 connect( SpinBox_Dz, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
598 connect( CBAbsoluteOrientation, SIGNAL ( activated ( int ) ), this, SLOT( onSelectAbsoluteOrientation( int ) ) ) ;
600 connect( CBRelativeOrientation, SIGNAL( activated( int ) ), this, SLOT( onSelectRelativeOrientation( int ) ) );
601 connect( SliderDistance, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) );
602 connect( SliderDistance, SIGNAL( valueChanged( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) );
603 connect( SliderRotation1, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) );
604 connect( SliderRotation1, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) );
605 connect( SliderRotation2, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) );
606 connect( SliderRotation2, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) );
608 connect( PreviewCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( OnPreviewToggle( bool ) ) );
609 connect( AutoApplyCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( onAutoApply( bool ) ) );
610 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
611 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
612 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
613 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
614 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( reject() ) );
615 /* to close dialog if study frame change */
616 connect( mySMESHGUI, SIGNAL ( SignalStudyFrameChanged() ), this, SLOT( reject() ) );
618 initializePlaneData();
626 Destroys the object and frees any allocated resources
628 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
630 // no need to delete child widgets, Qt does it all for us
631 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
633 SMESH::RenderViewWindow(myViewWindow);
635 for( int i=0; i< myPlanes.size(); i++ ) {
636 SMESH::TPlaneData aPlaneData = myPlanes[i];
637 aPlaneData.Plane->Delete();
640 if (myPreviewWidget) {
641 myPreviewWidget->Off();
642 myPreviewWidget->Delete();
645 myCallback->Delete();
647 myViewWindow->Repaint();
651 Get distance for cutting plane in relative mode
653 double SMESHGUI_ClippingDlg::getDistance() const
655 return TLValueDistance->text().toDouble();
659 Set distance of cutting plane in relative mode
661 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
663 SliderDistance->setValue( theDistance*100 );
667 Get rotation1 for cutting plane in relative mode
669 double SMESHGUI_ClippingDlg::getRotation1() const
671 return TLValueRotation1->text().remove("\xB0").toInt();
675 Get rotation2 for cutting plane in relative mode
677 double SMESHGUI_ClippingDlg::getRotation2() const
679 return TLValueRotation2->text().remove("\xB0").toInt();
683 Set angles of clipping plane in relative mode
685 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
687 SliderRotation1->setValue( theRot1 );
688 SliderRotation2->setValue( theRot2 );
692 Set coordinates of origin point in dialog box
694 void SMESHGUI_ClippingDlg::setOrigin( double theVal[3] )
696 int anOrientation = CBAbsoluteOrientation->currentIndex();
697 if( anOrientation == 0 || anOrientation == 2 )
698 SpinBox_X->setValue( theVal[0] );
699 if( anOrientation == 0 || anOrientation == 3 )
700 SpinBox_Y->setValue( theVal[1] );
701 if( anOrientation == 0 || anOrientation == 1 )
702 SpinBox_Z->setValue( theVal[2] );
706 Set coordinates of normal vector in dialog box
708 void SMESHGUI_ClippingDlg::setDirection( double theVal[3] )
710 int anOrientation = CBAbsoluteOrientation->currentIndex();
711 if( anOrientation == 0 ) {
712 SpinBox_Dx->setValue( theVal[0] );
713 SpinBox_Dy->setValue( theVal[1] );
714 SpinBox_Dz->setValue( theVal[2] );
719 Create a new widget for preview clipping plane
721 vtkImplicitPlaneWidget* SMESHGUI_ClippingDlg::createPreviewWidget()
723 vtkImplicitPlaneWidget* aPlaneWgt = vtkImplicitPlaneWidget::New();
725 aPlaneWgt->SetInteractor( myViewWindow->getInteractor() );
726 aPlaneWgt->SetPlaceFactor( SIZEFACTOR );
727 aPlaneWgt->ScaleEnabledOff();
728 aPlaneWgt->SetOrigin( 0, 0, 0 );
729 aPlaneWgt->SetNormal( -1, -1, -1 );
733 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
735 aPlaneWgt->GetPlaneProperty()->SetColor( anRGB[0],anRGB[1],anRGB[2] );
736 aPlaneWgt->GetPlaneProperty()->SetOpacity( 0.2 );;
738 aPlaneWgt->GetSelectedPlaneProperty()->SetColor( anRGB[0],anRGB[1],anRGB[2] );
739 aPlaneWgt->GetSelectedPlaneProperty()->SetOpacity( 0.2 );
740 aPlaneWgt->GetSelectedPlaneProperty()->SetLineWidth( 2.0 );
742 aPlaneWgt->AddObserver(vtkCommand::InteractionEvent, myCallback, 0.);
748 Translate two angles of plane to normal
750 void rotationToNormal ( double theRotation[2],
753 double theDir[2][3] )
755 static double aCoeff = M_PI/180.0;
757 double anU[2] = { cos( aCoeff * theRotation[0] ), cos( aCoeff * theRotation[1] ) };
758 double aV[2] = { sqrt( 1.0 - anU[0]*anU[0] ), sqrt( 1.0 - anU[1] * anU[1] ) };
759 aV[0] = theRotation[0] > 0? aV[0]: -aV[0];
760 aV[1] = theRotation[1] > 0? aV[1]: -aV[1];
762 switch ( theOrientation ) {
765 theDir[0][1] = anU[0];
766 theDir[0][2] = aV[0];
767 theDir[1][0] = anU[1];
768 theDir[1][2] = aV[1];
771 theDir[0][2] = anU[0];
772 theDir[0][0] = aV[0];
773 theDir[1][1] = anU[1];
774 theDir[1][0] = aV[1];
777 theDir[0][0] = anU[0];
778 theDir[0][1] = aV[0];
779 theDir[1][2] = anU[1];
780 theDir[1][1] = aV[1];
784 vtkMath::Cross( theDir[1], theDir[0], theNormal );
785 vtkMath::Normalize( theNormal );
786 vtkMath::Cross( theNormal, theDir[1], theDir[0] );
790 Used in SMESHGUI::restoreVisualParameters() to avoid
791 Declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
793 bool SMESHGUI_ClippingDlg::AddPlane ( SMESH::TActorList theActorList,
794 SMESH::OrientedPlane* thePlane )
797 double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
798 static double aCoeff = vtkMath::Pi()/180.0;
801 if ( thePlane->PlaneMode == SMESH::Absolute )
802 anOrientation = thePlane->myAbsoluteOrientation;
803 else if ( thePlane->PlaneMode == SMESH::Relative )
804 anOrientation = thePlane->myRelativeOrientation + 1;
806 if ( anOrientation == 0 ) {
807 // compute a direction for plane in absolute mode
808 double znam = sqrt( thePlane->Dx*thePlane->Dx + thePlane->Dy*thePlane->Dy + thePlane->Dz*thePlane->Dz );
809 double aRotation = acos( thePlane->Dy/znam )/aCoeff;
810 if ( thePlane->Dy >= 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[0] = 90.0 + aRotation;
811 else if ( thePlane->Dy >= 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[0] = 90.0 - aRotation;
812 else if ( thePlane->Dy < 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[0] = aRotation - 90.0;
813 else if ( thePlane->Dy < 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[0] = 270.0 - aRotation;
815 aRotation = acos( thePlane->Dx/znam )/aCoeff;
816 if ( thePlane->Dx >= 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[1] = 90.0 + aRotation;
817 else if ( thePlane->Dx >= 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[1] = 90.0 - aRotation;
818 else if ( thePlane->Dx < 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[1] = aRotation - 90.0;
819 else if ( thePlane->Dx < 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[1] = 270.0 - aRotation;
823 rotationToNormal( thePlane->myAngle, anOrientation, aNormal, aDir );
828 if ( thePlane->PlaneMode == SMESH::Absolute ) {
829 aNormal[0] = thePlane->Dx;
830 aNormal[1] = thePlane->Dy;
831 aNormal[2] = thePlane->Dz;
835 if( theActorList.empty() ) {
836 // to support planes with empty actor list we should create
837 // a nullified plane that will be initialized later
838 anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
839 aBounds[0] = aBounds[2] = aBounds[4] = 0;
840 aBounds[1] = aBounds[3] = aBounds[5] = 0;
844 anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
846 thePlane->myDistance,
852 if ( thePlane->PlaneMode == SMESH::Absolute ) {
853 anOrigin[0] = thePlane->X;
854 anOrigin[1] = thePlane->Y;
855 anOrigin[2] = thePlane->Z;
857 thePlane->SetNormal( aNormal );
858 thePlane->SetOrigin( anOrigin );
861 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
862 ( aBounds[2] + aBounds[3] ) / 2.,
863 ( aBounds[4] + aBounds[5] ) / 2. };
865 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
866 pow( aBounds[3] - aBounds[2], 2 ) +
867 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
869 double aDelta[2][3] = { { aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel },
870 { aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel } };
871 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
873 double aPnt01[3] = { aPnt[0] - aDelta[0][0] - aDelta[1][0],
874 aPnt[1] - aDelta[0][1] - aDelta[1][1],
875 aPnt[2] - aDelta[0][2] - aDelta[1][2] };
876 double aPnt02[3] = { aPnt01[0] + aNormal[0],
877 aPnt01[1] + aNormal[1],
878 aPnt01[2] + aNormal[2] };
879 vtkPlane::IntersectWithLine( aPnt01, aPnt02, aNormal, anOrigin, aParam, aPnt0 );
881 double aPnt11[3] = { aPnt[0] - aDelta[0][0] + aDelta[1][0],
882 aPnt[1] - aDelta[0][1] + aDelta[1][1],
883 aPnt[2] - aDelta[0][2] + aDelta[1][2] };
884 double aPnt12[3] = { aPnt11[0] + aNormal[0],
885 aPnt11[1] + aNormal[1],
886 aPnt11[2] + aNormal[2] };
887 vtkPlane::IntersectWithLine( aPnt11, aPnt12, aNormal, anOrigin, aParam, aPnt1);
889 double aPnt21[3] = { aPnt[0] + aDelta[0][0] - aDelta[1][0],
890 aPnt[1] + aDelta[0][1] - aDelta[1][1],
891 aPnt[2] + aDelta[0][2] - aDelta[1][2] };
892 double aPnt22[3] = { aPnt21[0] + aNormal[0],
893 aPnt21[1] + aNormal[1],
894 aPnt21[2] + aNormal[2] };
895 vtkPlane::IntersectWithLine( aPnt21, aPnt22, aNormal, anOrigin, aParam, aPnt2);
897 vtkPlaneSource* aPlaneSource = thePlane->myPlaneSource;
898 aPlaneSource->SetNormal( aNormal[0], aNormal[1], aNormal[2] );
899 aPlaneSource->SetOrigin( aPnt0[0], aPnt0[1], aPnt0[2] );
900 aPlaneSource->SetPoint1( aPnt1[0], aPnt1[1], aPnt1[2] );
901 aPlaneSource->SetPoint2( aPnt2[0], aPnt2[1], aPnt2[2] );
902 aPlaneSource->Update();
904 SMESH::TActorList::iterator anIter = theActorList.begin();
905 for ( ; anIter != theActorList.end(); anIter++ )
906 if( vtkActor* aVTKActor = *anIter )
907 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
908 if( thePlane->IsOpenGLClipping )
909 anActor->AddOpenGLClippingPlane( thePlane->InvertPlane() );
911 anActor->AddClippingPlane( thePlane );
918 Custom handling of events
920 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
922 QDialog::keyPressEvent( e );
923 if ( e->isAccepted() )
926 if ( e->key() == Qt::Key_F1 ) {
933 Handles the char preview widget activation event
935 void SMESHGUI_ClippingDlg::ProcessEvents( vtkObject* theObject,
936 unsigned long theEvent,
938 void* vtkNotUsed( theCallData ) )
940 vtkImplicitPlaneWidget* aWidget = vtkImplicitPlaneWidget::SafeDownCast( theObject );
941 if ( aWidget == NULL ) return;
942 if ( theClientData == NULL ) return;
944 SMESHGUI_ClippingDlg* aDlg = (SMESHGUI_ClippingDlg*) theClientData;
950 case vtkCommand::InteractionEvent:
951 aWidget->GetOrigin( anOrigin );
952 aWidget->GetNormal( aDir );
954 aDlg->myIsSelectPlane = true;
956 if( aDlg->CurrentMode == SMESH::Absolute ) {
957 aDlg->setOrigin( anOrigin );
958 aDlg->setDirection( aDir );
959 aDlg->myIsPreviewMoved = true;
961 else if( aDlg->CurrentMode == SMESH::Relative ) {
962 aDlg->absolutePlaneToRelative( anOrigin, aDir );
964 aDlg->myIsSelectPlane = false;
966 aDlg->SetCurrentPlaneParam();
967 aDlg->myIsPreviewMoved = false;
973 Initialize the planes's data when the dialog opened
975 void SMESHGUI_ClippingDlg::initializePlaneData()
977 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
978 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
979 if( anIter1 != aClippingPlaneInfoMap.end() ) {
980 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
981 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
982 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
983 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
984 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
985 anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
986 SMESH::TPlane aTPlane( anOrientedPlane );
987 SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
988 myPlanes.push_back( aPlaneData );
991 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
992 if( myPlanes.size() )
993 myPreviewWidget->SetEnabled( PreviewCheckBox->isChecked() );
997 Initialization of initial values of widgets
999 void SMESHGUI_ClippingDlg::initParam()
1001 SpinBox_X->setValue( 0.0 );
1002 SpinBox_Y->setValue( 0.0 );
1003 SpinBox_Z->setValue( 0.0 );
1005 SpinBox_Dx->setValue( 1.0 );
1006 SpinBox_Dy->setValue( 1.0 );
1007 SpinBox_Dz->setValue( 1.0 );
1009 CBAbsoluteOrientation->setCurrentIndex(0);
1011 TLValueDistance->setText( "0.5" );
1012 TLValueRotation1->setText( "0\xB0" );
1013 TLValueRotation2->setText( "0\xB0" );
1014 CBRelativeOrientation->setCurrentIndex( 0 );
1015 SliderDistance->setValue( 50 );
1016 SliderRotation1->setValue( 0 );
1017 SliderRotation2->setValue( 0 );
1021 Synchronize dialog's widgets with data
1023 void SMESHGUI_ClippingDlg::synchronize()
1025 int aNbPlanes = myPlanes.size();
1026 ComboBoxPlanes->clear();
1029 for( int i = 1; i<=aNbPlanes; i++ ) {
1030 aName = QString( tr( "PLANE_NUM" ) ).arg(i);
1031 ComboBoxPlanes->addItem( aName );
1034 int aPos = ComboBoxPlanes->count() - 1;
1035 ComboBoxPlanes->setCurrentIndex( aPos );
1037 bool anIsControlsEnable = ( aPos >= 0 );
1038 if ( anIsControlsEnable ) {
1039 onSelectPlane( aPos );
1041 if( PreviewCheckBox->isChecked() )
1042 myPreviewWidget->On();
1045 ComboBoxPlanes->addItem( tr( "NO_PLANES" ) );
1048 if( PreviewCheckBox->isChecked() )
1049 myPreviewWidget->Off();
1052 isOpenGLClipping->setEnabled( anIsControlsEnable );
1053 ActorList->setEnabled( anIsControlsEnable );
1054 SelectAllCheckBox->setEnabled( anIsControlsEnable );
1055 buttonDelete->setEnabled( anIsControlsEnable );
1056 if ( CurrentMode == SMESH::Absolute ) {
1057 SpinBox_X->setEnabled( anIsControlsEnable );
1058 SpinBox_Y->setEnabled( anIsControlsEnable );
1059 SpinBox_Z->setEnabled( anIsControlsEnable );
1060 SpinBox_Dx->setEnabled( anIsControlsEnable );
1061 SpinBox_Dy->setEnabled( anIsControlsEnable );
1062 SpinBox_Dz->setEnabled( anIsControlsEnable );
1063 CBAbsoluteOrientation->setEnabled( anIsControlsEnable );
1064 invertButton->setEnabled( anIsControlsEnable );
1065 resetButton->setEnabled( anIsControlsEnable );
1067 else if ( CurrentMode == SMESH::Relative ) {
1068 CBRelativeOrientation->setEnabled( anIsControlsEnable );
1069 SliderDistance->setEnabled( anIsControlsEnable );
1070 SliderRotation1->setEnabled( anIsControlsEnable );
1071 SliderRotation2->setEnabled( anIsControlsEnable );
1076 Update the list of actors
1078 void SMESHGUI_ClippingDlg::updateActorList()
1082 SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1086 _PTR(Study) aStudy = anAppStudy->studyDS();
1093 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1094 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1095 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1097 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1098 aPlaneData.Plane.GetPointer()->myActor->SetVisibility( false );
1100 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1101 vtkActorCollection* anAllActors = aCopy.GetActors();
1102 anAllActors->InitTraversal();
1103 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1104 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1105 if( anActor->hasIO() ) {
1106 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1107 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1108 bool anIsChecked = false;
1109 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1110 for ( ; anIter != anActorList.end(); anIter++ ) {
1111 if( vtkActor* aVTKActorRef = *anIter ) {
1112 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1113 if( anActorRef == anActor ) {
1120 QString aName = QString( aSObj->GetName().c_str() );
1121 QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
1122 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1123 updateActorItem( anItem, true, false );
1131 Update an actor in actor's list
1133 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
1134 bool theUpdateSelectAll,
1135 bool theUpdateClippingPlaneMap )
1137 // update Select All check box
1138 if( theUpdateSelectAll ) {
1139 int aNbItems = ActorList->count(), aNbChecked = 0;
1140 for( int i = 0; i < aNbItems; i++ )
1141 if( QListWidgetItem* anItem = ActorList->item( i ) )
1142 if( anItem->checkState() == Qt::Checked )
1145 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
1146 SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
1147 SelectAllCheckBox->blockSignals( anIsBlocked );
1150 // update clipping plane map
1151 if( theUpdateClippingPlaneMap ) {
1152 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1153 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
1154 if( SMESH_Actor* anActor = anItem->getActor() ) {
1155 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1156 SMESH::TActorList& anActorList = aPlaneData.ActorList;
1157 bool anIsPushed = false;
1158 SMESH::TActorList::iterator anIter = anActorList.begin();
1159 for ( ; anIter != anActorList.end(); anIter++ ) {
1160 if( anActor == *anIter ) {
1165 if( theItem->checkState() == Qt::Checked && !anIsPushed )
1166 anActorList.push_back( anActor );
1167 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
1168 anActorList.remove( anActor );
1170 SMESH::ComputeBounds( anActorList, myBounds );
1171 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1172 myBounds[3], myBounds[4], myBounds[5] );
1179 Get the list of current actors
1181 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1183 SMESH::TActorList anActorList;
1184 for( int i = 0, n = ActorList->count(); i < n; i++ )
1185 if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1186 if( anItem->checkState() == Qt::Checked )
1187 if( SMESH_Actor* anActor = anItem->getActor() )
1188 anActorList.push_back( anActor );
1193 Dump the parameters of clipping planes
1195 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1197 printf( "----------- Plane Data -----------\n" );
1199 SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1200 for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1201 SMESH::TPlaneData aPlaneData = *anIter1;
1202 SMESH::TPlane aPlane = aPlaneData.Plane;
1203 double* aNormal = aPlane->GetNormal();
1204 double* anOrigin = aPlane->GetOrigin();
1205 printf( "Plane N%d:\n", anId );
1206 printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1207 printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1209 SMESH::TActorList anActorList = aPlaneData.ActorList;
1210 SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1211 for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1212 if( vtkActor* aVTKActor = *anIter2 ) {
1213 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1214 printf( " - Actor: '%s'\n", anActor->getName() );
1217 printf( " - Actor: NULL\n");
1220 printf( "----------------------------------\n" );
1224 SLOT on close button click: rejects dialog
1226 void SMESHGUI_ClippingDlg::reject()
1228 //here we can insert actions to do at close.
1233 Set absolute mode of clipping plane
1235 void SMESHGUI_ClippingDlg::onModeAbsolute()
1237 ModeStackedLayout->setCurrentIndex(0);
1238 CurrentMode = SMESH::Absolute;
1240 SetCurrentPlaneParam();
1244 Set relative mode of clipping plane
1246 void SMESHGUI_ClippingDlg::onModeRelative()
1248 ModeStackedLayout->setCurrentIndex(1);
1249 CurrentMode = SMESH::Relative;
1251 SetCurrentPlaneParam();
1255 SLOT on new button click: create a new clipping plane
1257 void SMESHGUI_ClippingDlg::ClickOnNew()
1260 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
1261 SMESH::TPlane aTPlane(aPlane);
1262 aPlane->PlaneMode = CurrentMode;
1263 SMESH::TActorList anActorList;
1264 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1265 vtkActorCollection* anAllActors = aCopy.GetActors();
1266 anAllActors->InitTraversal();
1267 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1268 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1269 anActorList.push_back( anActor );
1271 SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
1273 myPlanes.push_back(aPlaneData);
1276 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1277 aPlane->myActor->SetVisibility( false );
1279 bool anIsBlocked = ActorList->blockSignals( true );
1281 SMESH::ComputeBounds( anActorList, myBounds );
1282 myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2],
1283 myBounds[3],myBounds[4],myBounds[5] );
1285 SetCurrentPlaneParam();
1287 ActorList->blockSignals( anIsBlocked );
1292 SLOT on delete button click: Delete selected clipping plane
1294 void SMESHGUI_ClippingDlg::ClickOnDelete()
1296 if (myPlanes.empty())
1299 int aPlaneIndex = ComboBoxPlanes->currentIndex();
1301 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
1302 SMESH::TPlaneData aPlaneData = *anIter;
1303 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
1304 myPlanes.erase(anIter);
1306 if(AutoApplyCheckBox->isChecked())
1310 SMESH::RenderViewWindow( myViewWindow );
1314 Set current parameters of selected plane
1316 void SMESHGUI_ClippingDlg::onSelectPlane ( int theIndex )
1318 if ( myPlanes.empty() )
1321 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
1322 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1324 myIsSelectPlane = true;
1325 isOpenGLClipping->setChecked( aPlane->IsOpenGLClipping );
1327 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1328 ModeStackedLayout->setCurrentIndex( 0 );
1329 CurrentMode = SMESH::Absolute;
1330 int anOrientation = aPlane->myAbsoluteOrientation;
1331 // Set plane parameters in the dialog
1332 double anOrigin[3], aDir[3];
1333 anOrigin[0] = aPlane->X;
1334 anOrigin[1] = aPlane->Y;
1335 anOrigin[2] = aPlane->Z;
1336 setOrigin( anOrigin );
1337 aDir[0] = aPlane->Dx;
1338 aDir[1] = aPlane->Dy;
1339 aDir[2] = aPlane->Dz;
1340 setDirection( aDir );
1341 CBAbsoluteOrientation->setCurrentIndex( anOrientation );
1342 onSelectAbsoluteOrientation( anOrientation );
1344 else if ( aPlane->PlaneMode == SMESH::Relative ) {
1345 ModeStackedLayout->setCurrentIndex( 1 );
1346 CurrentMode = SMESH::Relative;
1347 SMESH::Orientation anOrientation = aPlane->GetOrientation();
1348 double aRot[2] = { aPlane->myAngle[0], aPlane->myAngle[1] };
1349 // Set plane parameters in the dialog
1350 setDistance( aPlane->GetDistance() );
1351 setRotation( aRot[0], aRot[1] );
1352 switch ( anOrientation ) {
1354 CBRelativeOrientation->setCurrentIndex(0);
1355 onSelectRelativeOrientation(0);
1358 CBRelativeOrientation->setCurrentIndex(1);
1359 onSelectRelativeOrientation(1);
1362 CBRelativeOrientation->setCurrentIndex(2);
1363 onSelectRelativeOrientation(2);
1367 myIsSelectPlane = false;
1368 SMESH::ComputeBounds( aPlaneData.ActorList, myBounds );
1369 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1370 myBounds[3], myBounds[4], myBounds[5] );
1371 SetCurrentPlaneParam();
1374 bool anIsBlocked = ActorList->blockSignals( true );
1376 ActorList->blockSignals( anIsBlocked );
1380 SLOT: called on OpenGLClipping check box toggled
1382 void SMESHGUI_ClippingDlg::onIsOpenGLClipping( bool toggled )
1384 if ( myPlanes.empty() || myIsSelectPlane )
1387 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1388 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1389 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1390 aPlaneData->IsOpenGLClipping = toggled;
1392 if( AutoApplyCheckBox->isChecked() )
1397 SLOT: called on SelectAll check box toggled
1399 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
1401 if( theState == Qt::PartiallyChecked ) {
1402 SelectAllCheckBox->setCheckState( Qt::Checked );
1406 bool anIsBlocked = ActorList->blockSignals( true );
1407 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
1408 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
1409 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
1410 updateActorItem( anItem, false, true );
1413 SelectAllCheckBox->setTristate( false );
1414 ActorList->blockSignals( anIsBlocked );
1415 SetCurrentPlaneParam();
1419 SLOT: called when actor item was changed
1421 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
1423 updateActorItem( theItem, true, true );
1424 SetCurrentPlaneParam();
1428 Restore parameters of selected plane
1430 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
1432 if ( myPlanes.empty() || myIsSelectPlane )
1435 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1437 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1438 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1440 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1441 aPlane->myAbsoluteOrientation = CBAbsoluteOrientation->currentIndex();
1442 aPlane->X = SpinBox_X->value();
1443 aPlane->Y = SpinBox_Y->value();
1444 aPlane->Z = SpinBox_Z->value();
1445 aPlane->Dx = SpinBox_Dx->value();
1446 aPlane->Dy = SpinBox_Dy->value();
1447 aPlane->Dz = SpinBox_Dz->value();
1451 double aDir[2][3] = { {0, 0, 0}, {0, 0, 0} };
1452 static double aCoeff = vtkMath::Pi()/180.0;
1454 double aRot[2] = { getRotation1(), getRotation2() };
1456 if ( aPlane->PlaneMode == SMESH::Absolute )
1457 anOrient = CBAbsoluteOrientation->currentIndex();
1458 else if ( aPlane->PlaneMode == SMESH::Relative )
1459 anOrient = CBRelativeOrientation->currentIndex() + 1;
1461 if ( aPlane->PlaneMode == SMESH::Relative ) {
1462 aPlane->myAngle[0] = aRot[0];
1463 aPlane->myAngle[1] = aRot[1];
1464 aPlane->SetOrientation( SMESH::Orientation( CBRelativeOrientation->currentIndex() ) );
1465 aPlane->SetDistance( getDistance() );
1468 if ( anOrient == 0 ) {
1469 // compute a direction for plane in absolute mode
1470 double znam = sqrt( aPlane->Dx*aPlane->Dx + aPlane->Dy*aPlane->Dy + aPlane->Dz*aPlane->Dz );
1471 double aRotation = acos( aPlane->Dy/znam )/aCoeff;
1472 if ( aPlane->Dy >= 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = 90.0 + aRotation;
1473 else if ( aPlane->Dy >= 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 90.0 - aRotation;
1474 else if ( aPlane->Dy < 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = aRotation - 90.0;
1475 else if ( aPlane->Dy < 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 270.0 - aRotation;
1477 aRotation = acos( aPlane->Dx/znam )/aCoeff;
1478 if ( aPlane->Dx >= 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = 90.0 + aRotation;
1479 else if ( aPlane->Dx >= 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 90.0 - aRotation;
1480 else if ( aPlane->Dx < 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = aRotation - 90.0;
1481 else if ( aPlane->Dx < 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 270.0 - aRotation;
1485 rotationToNormal( aRot, anOrient, aNormal, aDir );
1488 SMESH::TActorList anActorList = aPlaneData.ActorList;
1493 aDistance = getDistance();
1494 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1495 aNormal[0] = aPlane->Dx;
1496 aNormal[1] = aPlane->Dy;
1497 aNormal[2] = aPlane->Dz;
1500 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
1506 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1507 anOrigin[0] = aPlane->X;
1508 anOrigin[1] = aPlane->Y;
1509 anOrigin[2] = aPlane->Z;
1513 aPlane->SetNormal( aNormal );
1514 aPlane->SetOrigin( anOrigin );
1516 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
1517 ( aBounds[2] + aBounds[3] ) / 2.,
1518 ( aBounds[4] + aBounds[5] ) / 2. };
1520 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
1521 pow( aBounds[3] - aBounds[2], 2 ) +
1522 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
1524 double aDelta[2][3] = { { aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel },
1525 { aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel } };
1526 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
1528 double aPnt01[3] = { aPnt[0] - aDelta[0][0] - aDelta[1][0],
1529 aPnt[1] - aDelta[0][1] - aDelta[1][1],
1530 aPnt[2] - aDelta[0][2] - aDelta[1][2] };
1531 double aPnt02[3] = { aPnt01[0] + aNormal[0],
1532 aPnt01[1] + aNormal[1],
1533 aPnt01[2] + aNormal[2] };
1534 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
1536 double aPnt11[3] = { aPnt[0] - aDelta[0][0] + aDelta[1][0],
1537 aPnt[1] - aDelta[0][1] + aDelta[1][1],
1538 aPnt[2] - aDelta[0][2] + aDelta[1][2] };
1539 double aPnt12[3] = { aPnt11[0] + aNormal[0],
1540 aPnt11[1] + aNormal[1],
1541 aPnt11[2] + aNormal[2] };
1542 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1544 double aPnt21[3] = { aPnt[0] + aDelta[0][0] - aDelta[1][0],
1545 aPnt[1] + aDelta[0][1] - aDelta[1][1],
1546 aPnt[2] + aDelta[0][2] - aDelta[1][2] };
1547 double aPnt22[3] = { aPnt21[0] + aNormal[0],
1548 aPnt21[1] + aNormal[1],
1549 aPnt21[2] + aNormal[2] };
1550 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1552 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1554 aPlaneSource->SetNormal( aNormal[0], aNormal[1], aNormal[2] );
1555 aPlaneSource->SetOrigin( aPnt0[0], aPnt0[1], aPnt0[2] );
1556 aPlaneSource->SetPoint1( aPnt1[0], aPnt1[1], aPnt1[2] );
1557 aPlaneSource->SetPoint2( aPnt2[0], aPnt2[1], aPnt2[2] );
1558 aPlaneSource->Update();
1561 setBoundsForPreviewWidget();
1563 myPreviewWidget->SetOrigin( anOrigin );
1564 myPreviewWidget->SetNormal( aNormal );
1566 if(AutoApplyCheckBox->isChecked())
1569 SMESH::RenderViewWindow( myViewWindow );
1573 Set current bounds for preview widget
1575 void SMESHGUI_ClippingDlg::setBoundsForPreviewWidget()
1577 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1578 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1579 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1580 SMESH::TActorList anActorList = aPlaneData.ActorList;
1582 double* anOrigin = aPlane->GetOrigin();
1585 SMESH::ComputeBounds( anActorList, aBounds );
1587 bool isBoundsChanged = false;
1589 if( myIsPreviewMoved ) {
1590 // if widget has moved by hand the bounds can to minimize
1591 if( anOrigin[0] > myBounds[0] && anOrigin[0] < aBounds[0] ) {
1592 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1593 if( anOrigin[0] < myBounds[1] && anOrigin[0] > aBounds[1] ) {
1594 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1595 if( anOrigin[1] > myBounds[2] && anOrigin[1] < aBounds[2] ) {
1596 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1597 if( anOrigin[1] < myBounds[3] && anOrigin[1] > aBounds[3] ) {
1598 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1599 if( anOrigin[2] > myBounds[4] && anOrigin[2] < aBounds[4] ) {
1600 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1601 if( anOrigin[2] < myBounds[5] && anOrigin[2] > aBounds[5] ) {
1602 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1605 // if widget has moved by dialog data the bounds can to take necessary size
1606 if( anOrigin[0] < aBounds[0] ) {
1607 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1608 if( anOrigin[0] > aBounds[1] ) {
1609 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1610 if( anOrigin[1] < aBounds[2] ) {
1611 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1612 if( anOrigin[1] > aBounds[3] ) {
1613 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1614 if( anOrigin[2] < aBounds[4] ) {
1615 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1616 if( anOrigin[2] > aBounds[5] ) {
1617 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1620 if( isBoundsChanged )
1621 myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2],
1622 myBounds[3],myBounds[4],myBounds[5] );
1623 else if( !myIsPreviewMoved )
1624 myPreviewWidget->PlaceWidget( aBounds[0],aBounds[1],aBounds[2],
1625 aBounds[3],aBounds[4],aBounds[5] );
1630 Convert absolute coordinates of plane to relative mode
1632 void SMESHGUI_ClippingDlg::absolutePlaneToRelative ( double theOrigin[3], double theDir[3] )
1636 aRot[0] = getRotation1();
1637 aRot[1] = getRotation2();
1639 double eps = 0.0001;
1641 int anOrientation = CBRelativeOrientation->currentIndex();
1642 double aDirection[3];
1643 double aRotation1, aRotation2;
1644 switch( anOrientation ) {
1646 aDirection[0] = theDir[0] + eps;
1647 aDirection[1] = theDir[1] + eps;
1648 aDirection[2] = theDir[2] + eps;
1649 aRotation1 = atan2( theDir[2], theDir[1] )*180.0/M_PI;
1650 aRotation2 = atan2( theDir[2], theDir[0] )*180.0/M_PI;
1653 aDirection[0] = theDir[1] + eps;
1654 aDirection[1] = theDir[2] + eps;
1655 aDirection[2] = theDir[0] + eps;
1656 aRotation1 = atan2( theDir[0], theDir[2] )*180.0/M_PI;
1657 aRotation2 = atan2( theDir[0], theDir[1] )*180.0/M_PI;
1660 aDirection[0] = theDir[2] + eps;
1661 aDirection[1] = theDir[0] + eps;
1662 aDirection[2] = theDir[1] + eps;
1663 aRotation1 = atan2( theDir[1], theDir[0] )*180.0/M_PI;
1664 aRotation2 = atan2( theDir[1], theDir[2] )*180.0/M_PI;
1668 if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1669 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1670 else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1671 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 90.0; }
1672 else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1673 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 + 90.0; }
1674 else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1675 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 90.0; }
1676 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1677 aRot[0] = aRotation1 - 270.0; aRot[1] = aRotation2 + 90.0; }
1678 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1679 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1680 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1681 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 90.0; }
1682 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1683 aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
1684 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1685 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1686 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1687 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 270.0; }
1688 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1689 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 + 90.0; }
1690 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1691 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
1692 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1693 aRot[0] = aRotation1 - 270.0; aRot[1] = aRotation2 - 270.0; }
1694 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1695 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1696 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1697 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
1698 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1699 aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
1701 SliderRotation1HasMoved( qRound( aRot[0] ) );
1702 SliderRotation1->setValue( qRound( aRot[0] ) );
1703 SliderRotation2HasMoved( qRound( aRot[1] ) );
1704 SliderRotation2->setValue( qRound( aRot[1] ) );
1706 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1707 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1708 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1712 SMESH::ComputeBounds( anActorList, aBounds );
1713 SMESH::PositionToDistance( aBounds, theDir, theOrigin, aDist );
1714 aDist = 1.0 - aDist;
1717 else if( aDist < 0.0 )
1720 SliderDistanceHasMoved( qRound( aDist*100 ) );
1721 SliderDistance->setValue( qRound( aDist*100 ) );
1726 SLOT: called on preview check box toggled
1728 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1730 std::for_each( myPlanes.begin(), myPlanes.end(), TSetVisibility( theIsToggled ) );
1731 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1732 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1733 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1734 aPlaneData->myActor->SetVisibility( false );
1736 myPreviewWidget->On();
1738 myPreviewWidget->Off();
1739 SMESH::RenderViewWindow( myViewWindow );
1743 SLOT: called on Auto Apply check box toggled
1745 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1747 if ( toggled ) ClickOnApply();
1751 SLOT on ok button click: sets cutting plane and closes dialog
1753 void SMESHGUI_ClippingDlg::ClickOnOk()
1761 SLOT on Apply button click: sets cutting plane and update viewer
1763 void SMESHGUI_ClippingDlg::ClickOnApply()
1766 SUIT_OverrideCursor wc;
1768 QWidget *aCurrWid = this->focusWidget();
1769 aCurrWid->clearFocus();
1770 aCurrWid->setFocus();
1772 SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1773 SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
1775 // clean memory allocated for planes
1776 SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
1777 for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
1778 if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
1781 aClippingPlaneInfoList.clear();
1783 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1784 vtkActorCollection* anAllActors = aCopy.GetActors();
1785 anAllActors->InitTraversal();
1786 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1787 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1788 anActor->RemoveAllClippingPlanes();
1790 SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
1791 for( ; anIter2 != myPlanes.end(); anIter2++ ) {
1792 SMESH::TPlaneData aPlaneData = *anIter2;
1793 SMESH::TPlane aPlane = aPlaneData.Plane;
1794 SMESH::TActorList anActorList = aPlaneData.ActorList;
1796 // the check is disabled to support planes with empty actor list
1797 //if( anActorList.empty() )
1800 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1801 anOrientedPlane->ShallowCopy(aPlane.GetPointer());
1802 SMESH::TActorList::iterator anIter3 = anActorList.begin();
1803 for( ; anIter3 != anActorList.end(); anIter3++ )
1804 if( vtkActor* aVTKActor = *anIter3 )
1805 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1806 if( anOrientedPlane->IsOpenGLClipping )
1807 anActor->AddOpenGLClippingPlane( anOrientedPlane->InvertPlane() );
1809 anActor->AddClippingPlane( anOrientedPlane );
1812 SMESH::ClippingPlaneInfo aClippingPlaneInfo;
1813 aClippingPlaneInfo.Plane = anOrientedPlane;
1814 aClippingPlaneInfo.ActorList = anActorList;
1816 aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
1819 SMESH_Actor* anSMESHActor;
1820 anAllActors->InitTraversal();
1821 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1822 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1823 anSMESHActor = anActor;
1824 anActor->SetOpenGLClippingPlane();
1827 SMESH::RenderViewWindow( myViewWindow );
1832 SLOT on help button click: opens a help page
1834 void SMESHGUI_ClippingDlg::ClickOnHelp()
1836 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1838 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1842 platform = "winapplication";
1844 platform = "application";
1846 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1847 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1848 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1850 arg(myHelpFileName));
1855 SLOT: Called when value of slider distance change
1857 void SMESHGUI_ClippingDlg::SliderDistanceHasMoved( int value )
1859 double new_value = value/100.;
1860 TLValueDistance->setText( QString("%1").arg( new_value ) );
1861 SetCurrentPlaneParam();
1865 SLOT: Called when value of slider rotation1 change
1867 void SMESHGUI_ClippingDlg::SliderRotation1HasMoved( int value )
1869 TLValueRotation1->setText( QString("%1\xB0").arg( value ) );
1870 SetCurrentPlaneParam();
1874 SLOT: Called when value of slider rotation2 change
1876 void SMESHGUI_ClippingDlg::SliderRotation2HasMoved( int value )
1878 TLValueRotation2->setText( QString("%1\xB0").arg( value ) );
1879 SetCurrentPlaneParam();
1882 void SMESHGUI_ClippingDlg::onSelectAbsoluteOrientation( int mode )
1884 bool isUserMode = (mode==0);
1886 TextLabelX->setEnabled( isUserMode );
1887 TextLabelY->setEnabled( isUserMode );
1888 TextLabelZ->setEnabled( isUserMode );
1890 SpinBox_X->setEnabled( isUserMode );
1891 SpinBox_Y->setEnabled( isUserMode );
1892 SpinBox_Z->setEnabled( isUserMode );
1894 TextLabelDx->setEnabled( isUserMode );
1895 TextLabelDy->setEnabled( isUserMode );
1896 TextLabelDz->setEnabled( isUserMode );
1898 SpinBox_Dx->setEnabled( isUserMode );
1899 SpinBox_Dy->setEnabled( isUserMode );
1900 SpinBox_Dz->setEnabled( isUserMode );
1905 double aDx = 0, aDy = 0, aDz = 0;
1910 TextLabelZ->setEnabled( true );
1911 SpinBox_Z->setEnabled( true );
1912 SpinBox_Z->setFocus();
1914 else if ( mode == 2 )
1917 TextLabelX->setEnabled( true );
1918 SpinBox_X->setEnabled( true );
1919 SpinBox_X->setFocus();
1921 else if ( mode == 3 )
1924 TextLabelY->setEnabled( true );
1925 SpinBox_Y->setEnabled( true );
1926 SpinBox_Y->setFocus();
1929 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1930 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1931 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1933 if ( aPlaneData->IsInvert == true ) {
1934 aDx = -aDx; aDy = -aDy; aDz = -aDz;
1937 myIsSelectPlane = true;
1938 SpinBox_Dx->setValue( aDx );
1939 SpinBox_Dy->setValue( aDy );
1940 SpinBox_Dz->setValue( aDz );
1941 myIsSelectPlane = false;
1943 SetCurrentPlaneParam();
1947 SLOT: called on orientation of clipping plane in relative mode changed
1949 void SMESHGUI_ClippingDlg::onSelectRelativeOrientation ( int theItem )
1951 if ( myPlanes.empty() )
1954 if ( theItem == 0 ) {
1955 TextLabelRotation1->setText( tr( "ROTATION_AROUND_X_Y2Z" ) );
1956 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Y_X2Z" ) );
1958 else if ( theItem == 1 ) {
1959 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Y_Z2X" ) );
1960 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Z_Y2X" ) );
1962 else if ( theItem == 2 ) {
1963 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Z_X2Y" ) );
1964 TextLabelRotation2->setText( tr( "ROTATION_AROUND_X_Z2Y" ) );
1967 if( (QComboBox*)sender() == CBRelativeOrientation )
1968 SetCurrentPlaneParam();
1972 SLOT on reset button click: sets default values
1974 void SMESHGUI_ClippingDlg::onReset()
1976 myIsSelectPlane = true;
1977 SpinBox_X->setValue(0);
1978 SpinBox_Y->setValue(0);
1979 SpinBox_Z->setValue(0);
1980 myIsSelectPlane = false;
1982 SetCurrentPlaneParam();
1986 SLOT on invert button click: inverts normal of cutting plane
1988 void SMESHGUI_ClippingDlg::onInvert()
1990 double Dx = SpinBox_Dx->value();
1991 double Dy = SpinBox_Dy->value();
1992 double Dz = SpinBox_Dz->value();
1994 myIsSelectPlane = true;
1995 SpinBox_Dx->setValue( -Dx );
1996 SpinBox_Dy->setValue( -Dy );
1997 SpinBox_Dz->setValue( -Dz );
1998 myIsSelectPlane = false;
2000 if ( !myPlanes.empty() ) {
2001 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
2002 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
2003 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
2004 aPlaneData->IsInvert = !aPlaneData->IsInvert;
2006 SetCurrentPlaneParam();