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->setFocusPolicy( Qt::NoFocus );
480 SliderDistance->setMinimumSize( 300, 0 );
481 SliderDistance->setMinimum( 0 );
482 SliderDistance->setMaximum( 100 );
483 SliderDistance->setSingleStep( 1 );
484 SliderDistance->setPageStep( 10 );
485 SliderDistance->setTracking( false );
486 GroupParametersLayout->addWidget( SliderDistance, 2, 1 );
488 TLValueRotation1 = new QLabel( GroupParameters );
489 TLValueRotation1->setObjectName( "TLValueRotation1" );
490 TLValueRotation1->setAlignment( Qt::AlignCenter );
491 TLValueRotation1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
492 TLValueRotation1->setFont( fnt );
493 GroupParametersLayout->addWidget( TLValueRotation1, 3, 1 );
495 TextLabelRotation1 = new QLabel( tr("ROTATION_AROUND_X_Y2Z"), GroupParameters );
496 TextLabelRotation1->setObjectName( "TextLabelRotation1" );
497 GroupParametersLayout->addWidget( TextLabelRotation1, 4, 0 );
499 SliderRotation1 = new QSlider( Qt::Horizontal, GroupParameters );
500 SliderRotation1->setObjectName( "SliderRotation1" );
501 SliderRotation1->setFocusPolicy( Qt::NoFocus );
502 SliderRotation1->setMinimumSize( 300, 0 );
503 SliderRotation1->setMinimum( -180 );
504 SliderRotation1->setMaximum( 180 );
505 SliderRotation1->setSingleStep( 1 );
506 SliderRotation1->setPageStep( 10 );
507 SliderRotation1->setTracking(false);
508 GroupParametersLayout->addWidget( SliderRotation1, 4, 1 );
510 TLValueRotation2 = new QLabel( GroupParameters );
511 TLValueRotation2->setObjectName( "TLValueRotation2" );
512 TLValueRotation2->setAlignment( Qt::AlignCenter );
513 TLValueRotation2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
514 TLValueRotation2->setFont( fnt );
515 GroupParametersLayout->addWidget( TLValueRotation2, 5, 1 );
517 TextLabelRotation2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
518 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
519 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
520 GroupParametersLayout->addWidget( TextLabelRotation2, 6, 0 );
522 SliderRotation2 = new QSlider( Qt::Horizontal, GroupParameters );
523 SliderRotation2->setObjectName( "SliderRotation2" );
524 SliderRotation2->setFocusPolicy( Qt::NoFocus );
525 SliderRotation2->setMinimumSize( 300, 0 );
526 SliderRotation2->setMinimum( -180 );
527 SliderRotation2->setMaximum( 180 );
528 SliderRotation2->setSingleStep( 1 );
529 SliderRotation2->setPageStep( 10 );
530 SliderRotation2->setTracking(false);
531 GroupParametersLayout->addWidget( SliderRotation2, 6, 1 );
533 /***************************************************************/
534 QWidget* CheckBoxWidget = new QWidget( this );
535 QHBoxLayout* CheckBoxLayout = new QHBoxLayout( CheckBoxWidget );
537 PreviewCheckBox = new QCheckBox( tr("SHOW_PREVIEW"), CheckBoxWidget );
538 PreviewCheckBox->setObjectName( "PreviewCheckBox" );
539 PreviewCheckBox->setChecked( true );
540 CheckBoxLayout->addWidget( PreviewCheckBox, 0, Qt::AlignCenter );
542 AutoApplyCheckBox = new QCheckBox( tr("AUTO_APPLY"), CheckBoxWidget );
543 AutoApplyCheckBox->setObjectName( "AutoApplyCheckBox" );
544 CheckBoxLayout->addWidget( AutoApplyCheckBox, 0, Qt::AlignCenter );
546 /***************************************************************/
547 // Controls for "Ok", "Apply" and "Close" button
548 QGroupBox* GroupButtons = new QGroupBox(this);
549 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
550 GroupButtonsLayout->setSpacing(SPACING);
551 GroupButtonsLayout->setMargin(MARGIN);
553 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
554 buttonOk->setAutoDefault( true );
555 buttonOk->setDefault( true );
556 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
557 buttonApply->setAutoDefault( true );
558 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
559 buttonCancel->setAutoDefault( true );
560 buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
561 buttonHelp->setAutoDefault( true );
562 GroupButtonsLayout->addWidget( buttonOk );
563 GroupButtonsLayout->addSpacing(10);
564 GroupButtonsLayout->addWidget( buttonApply );
565 GroupButtonsLayout->addSpacing(10);
566 GroupButtonsLayout->addStretch();
567 GroupButtonsLayout->addWidget( buttonCancel );
568 GroupButtonsLayout->addWidget( buttonHelp );
570 ModeStackedLayout->addWidget( ModeActiveWidget );
571 ModeStackedLayout->addWidget( GroupParameters );
573 SMESHGUI_ClippingDlgLayout->addWidget( GroupPlanes );
574 SMESHGUI_ClippingDlgLayout->addLayout( ModeStackedLayout );
575 SMESHGUI_ClippingDlgLayout->addWidget( CheckBoxWidget );
576 SMESHGUI_ClippingDlgLayout->addWidget( GroupButtons );
581 myIsSelectPlane = false;
583 myHelpFileName = "clipping_page.html";
585 // signals and slots connections :
586 connect( ComboBoxPlanes, SIGNAL( activated( int ) ), this, SLOT( onSelectPlane( int ) ) );
587 connect( isOpenGLClipping, SIGNAL( toggled( bool ) ), this, SLOT( onIsOpenGLClipping( bool ) ) );
588 connect( buttonNew, SIGNAL( clicked() ), buttonNew, SLOT( showMenu() ) );
589 connect( buttonDelete, SIGNAL( clicked() ), this, SLOT( ClickOnDelete() ) );
590 connect( ActorList, SIGNAL( itemChanged( QListWidgetItem* ) ), this, SLOT( onActorItemChanged( QListWidgetItem*) ) );
591 connect( SelectAllCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( onSelectAll( int ) ) );
593 connect( invertButton, SIGNAL (clicked() ), this, SLOT( onInvert() ) ) ;
594 connect( resetButton, SIGNAL (clicked() ), this, SLOT( onReset() ) );
595 connect( SpinBox_X, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
596 connect( SpinBox_Y, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
597 connect( SpinBox_Z, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
598 connect( SpinBox_Dx, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
599 connect( SpinBox_Dy, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
600 connect( SpinBox_Dz, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
601 connect( CBAbsoluteOrientation, SIGNAL ( activated ( int ) ), this, SLOT( onSelectAbsoluteOrientation( int ) ) ) ;
603 connect( CBRelativeOrientation, SIGNAL( activated( int ) ), this, SLOT( onSelectRelativeOrientation( int ) ) );
604 connect( SliderDistance, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) );
605 connect( SliderDistance, SIGNAL( valueChanged( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) );
606 connect( SliderRotation1, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) );
607 connect( SliderRotation1, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) );
608 connect( SliderRotation2, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) );
609 connect( SliderRotation2, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) );
611 connect( PreviewCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( OnPreviewToggle( bool ) ) );
612 connect( AutoApplyCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( onAutoApply( bool ) ) );
613 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
614 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
615 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
616 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
617 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( reject() ) );
618 /* to close dialog if study frame change */
619 connect( mySMESHGUI, SIGNAL ( SignalStudyFrameChanged() ), this, SLOT( reject() ) );
621 initializePlaneData();
629 Destroys the object and frees any allocated resources
631 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
633 // no need to delete child widgets, Qt does it all for us
634 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
636 SMESH::RenderViewWindow(myViewWindow);
638 for( int i=0; i< myPlanes.size(); i++ ) {
639 SMESH::TPlaneData aPlaneData = myPlanes[i];
640 aPlaneData.Plane->Delete();
643 if (myPreviewWidget) {
644 myPreviewWidget->Off();
645 myPreviewWidget->Delete();
648 myCallback->Delete();
650 myViewWindow->Repaint();
654 Get distance for cutting plane in relative mode
656 double SMESHGUI_ClippingDlg::getDistance() const
658 return TLValueDistance->text().toDouble();
662 Set distance of cutting plane in relative mode
664 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
666 SliderDistance->setValue( theDistance*100 );
670 Get rotation1 for cutting plane in relative mode
672 double SMESHGUI_ClippingDlg::getRotation1() const
674 return TLValueRotation1->text().remove("\xB0").toInt();
678 Get rotation2 for cutting plane in relative mode
680 double SMESHGUI_ClippingDlg::getRotation2() const
682 return TLValueRotation2->text().remove("\xB0").toInt();
686 Set angles of clipping plane in relative mode
688 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
690 SliderRotation1->setValue( theRot1 );
691 SliderRotation2->setValue( theRot2 );
695 Set coordinates of origin point in dialog box
697 void SMESHGUI_ClippingDlg::setOrigin( double theVal[3] )
699 int anOrientation = CBAbsoluteOrientation->currentIndex();
700 if( anOrientation == 0 || anOrientation == 2 )
701 SpinBox_X->setValue( theVal[0] );
702 if( anOrientation == 0 || anOrientation == 3 )
703 SpinBox_Y->setValue( theVal[1] );
704 if( anOrientation == 0 || anOrientation == 1 )
705 SpinBox_Z->setValue( theVal[2] );
709 Set coordinates of normal vector in dialog box
711 void SMESHGUI_ClippingDlg::setDirection( double theVal[3] )
713 int anOrientation = CBAbsoluteOrientation->currentIndex();
714 if( anOrientation == 0 ) {
715 SpinBox_Dx->setValue( theVal[0] );
716 SpinBox_Dy->setValue( theVal[1] );
717 SpinBox_Dz->setValue( theVal[2] );
722 Create a new widget for preview clipping plane
724 vtkImplicitPlaneWidget* SMESHGUI_ClippingDlg::createPreviewWidget()
726 vtkImplicitPlaneWidget* aPlaneWgt = vtkImplicitPlaneWidget::New();
728 aPlaneWgt->SetInteractor( myViewWindow->getInteractor() );
729 aPlaneWgt->SetPlaceFactor( SIZEFACTOR );
730 aPlaneWgt->ScaleEnabledOff();
731 aPlaneWgt->SetOrigin( 0, 0, 0 );
732 aPlaneWgt->SetNormal( -1, -1, -1 );
736 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
738 aPlaneWgt->GetPlaneProperty()->SetColor( anRGB[0],anRGB[1],anRGB[2] );
739 aPlaneWgt->GetPlaneProperty()->SetOpacity( 0.2 );;
741 aPlaneWgt->GetSelectedPlaneProperty()->SetColor( anRGB[0],anRGB[1],anRGB[2] );
742 aPlaneWgt->GetSelectedPlaneProperty()->SetOpacity( 0.2 );
743 aPlaneWgt->GetSelectedPlaneProperty()->SetLineWidth( 2.0 );
745 aPlaneWgt->AddObserver(vtkCommand::InteractionEvent, myCallback, 0.);
751 Translate two angles of plane to normal
753 void rotationToNormal ( double theRotation[2],
756 double theDir[2][3] )
758 static double aCoeff = M_PI/180.0;
760 double anU[2] = { cos( aCoeff * theRotation[0] ), cos( aCoeff * theRotation[1] ) };
761 double aV[2] = { sqrt( 1.0 - anU[0]*anU[0] ), sqrt( 1.0 - anU[1] * anU[1] ) };
762 aV[0] = theRotation[0] > 0? aV[0]: -aV[0];
763 aV[1] = theRotation[1] > 0? aV[1]: -aV[1];
765 switch ( theOrientation ) {
768 theDir[0][1] = anU[0];
769 theDir[0][2] = aV[0];
770 theDir[1][0] = anU[1];
771 theDir[1][2] = aV[1];
774 theDir[0][2] = anU[0];
775 theDir[0][0] = aV[0];
776 theDir[1][1] = anU[1];
777 theDir[1][0] = aV[1];
780 theDir[0][0] = anU[0];
781 theDir[0][1] = aV[0];
782 theDir[1][2] = anU[1];
783 theDir[1][1] = aV[1];
787 vtkMath::Cross( theDir[1], theDir[0], theNormal );
788 vtkMath::Normalize( theNormal );
789 vtkMath::Cross( theNormal, theDir[1], theDir[0] );
793 Used in SMESHGUI::restoreVisualParameters() to avoid
794 Declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
796 bool SMESHGUI_ClippingDlg::AddPlane ( SMESH::TActorList theActorList,
797 SMESH::OrientedPlane* thePlane )
800 double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
801 static double aCoeff = vtkMath::Pi()/180.0;
804 if ( thePlane->PlaneMode == SMESH::Absolute )
805 anOrientation = thePlane->myAbsoluteOrientation;
806 else if ( thePlane->PlaneMode == SMESH::Relative )
807 anOrientation = thePlane->myRelativeOrientation + 1;
809 if ( anOrientation == 0 ) {
810 // compute a direction for plane in absolute mode
811 double znam = sqrt( thePlane->Dx*thePlane->Dx + thePlane->Dy*thePlane->Dy + thePlane->Dz*thePlane->Dz );
812 double aRotation = acos( thePlane->Dy/znam )/aCoeff;
813 if ( thePlane->Dy >= 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[0] = 90.0 + aRotation;
814 else if ( thePlane->Dy >= 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[0] = 90.0 - aRotation;
815 else if ( thePlane->Dy < 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[0] = aRotation - 90.0;
816 else if ( thePlane->Dy < 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[0] = 270.0 - aRotation;
818 aRotation = acos( thePlane->Dx/znam )/aCoeff;
819 if ( thePlane->Dx >= 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[1] = 90.0 + aRotation;
820 else if ( thePlane->Dx >= 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[1] = 90.0 - aRotation;
821 else if ( thePlane->Dx < 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[1] = aRotation - 90.0;
822 else if ( thePlane->Dx < 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[1] = 270.0 - aRotation;
826 rotationToNormal( thePlane->myAngle, anOrientation, aNormal, aDir );
831 if ( thePlane->PlaneMode == SMESH::Absolute ) {
832 aNormal[0] = thePlane->Dx;
833 aNormal[1] = thePlane->Dy;
834 aNormal[2] = thePlane->Dz;
838 if( theActorList.empty() ) {
839 // to support planes with empty actor list we should create
840 // a nullified plane that will be initialized later
841 anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
842 aBounds[0] = aBounds[2] = aBounds[4] = 0;
843 aBounds[1] = aBounds[3] = aBounds[5] = 0;
847 anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
849 thePlane->myDistance,
855 if ( thePlane->PlaneMode == SMESH::Absolute ) {
856 anOrigin[0] = thePlane->X;
857 anOrigin[1] = thePlane->Y;
858 anOrigin[2] = thePlane->Z;
860 thePlane->SetNormal( aNormal );
861 thePlane->SetOrigin( anOrigin );
864 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
865 ( aBounds[2] + aBounds[3] ) / 2.,
866 ( aBounds[4] + aBounds[5] ) / 2. };
868 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
869 pow( aBounds[3] - aBounds[2], 2 ) +
870 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
872 double aDelta[2][3] = { { aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel },
873 { aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel } };
874 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
876 double aPnt01[3] = { aPnt[0] - aDelta[0][0] - aDelta[1][0],
877 aPnt[1] - aDelta[0][1] - aDelta[1][1],
878 aPnt[2] - aDelta[0][2] - aDelta[1][2] };
879 double aPnt02[3] = { aPnt01[0] + aNormal[0],
880 aPnt01[1] + aNormal[1],
881 aPnt01[2] + aNormal[2] };
882 vtkPlane::IntersectWithLine( aPnt01, aPnt02, aNormal, anOrigin, aParam, aPnt0 );
884 double aPnt11[3] = { aPnt[0] - aDelta[0][0] + aDelta[1][0],
885 aPnt[1] - aDelta[0][1] + aDelta[1][1],
886 aPnt[2] - aDelta[0][2] + aDelta[1][2] };
887 double aPnt12[3] = { aPnt11[0] + aNormal[0],
888 aPnt11[1] + aNormal[1],
889 aPnt11[2] + aNormal[2] };
890 vtkPlane::IntersectWithLine( aPnt11, aPnt12, aNormal, anOrigin, aParam, aPnt1);
892 double aPnt21[3] = { aPnt[0] + aDelta[0][0] - aDelta[1][0],
893 aPnt[1] + aDelta[0][1] - aDelta[1][1],
894 aPnt[2] + aDelta[0][2] - aDelta[1][2] };
895 double aPnt22[3] = { aPnt21[0] + aNormal[0],
896 aPnt21[1] + aNormal[1],
897 aPnt21[2] + aNormal[2] };
898 vtkPlane::IntersectWithLine( aPnt21, aPnt22, aNormal, anOrigin, aParam, aPnt2);
900 vtkPlaneSource* aPlaneSource = thePlane->myPlaneSource;
901 aPlaneSource->SetNormal( aNormal[0], aNormal[1], aNormal[2] );
902 aPlaneSource->SetOrigin( aPnt0[0], aPnt0[1], aPnt0[2] );
903 aPlaneSource->SetPoint1( aPnt1[0], aPnt1[1], aPnt1[2] );
904 aPlaneSource->SetPoint2( aPnt2[0], aPnt2[1], aPnt2[2] );
905 aPlaneSource->Update();
907 SMESH::TActorList::iterator anIter = theActorList.begin();
908 for ( ; anIter != theActorList.end(); anIter++ )
909 if( vtkActor* aVTKActor = *anIter )
910 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
911 if( thePlane->IsOpenGLClipping )
912 anActor->AddOpenGLClippingPlane( thePlane->InvertPlane() );
914 anActor->AddClippingPlane( thePlane );
921 Custom handling of events
923 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
925 QDialog::keyPressEvent( e );
926 if ( e->isAccepted() )
929 if ( e->key() == Qt::Key_F1 ) {
936 Handles the char preview widget activation event
938 void SMESHGUI_ClippingDlg::ProcessEvents( vtkObject* theObject,
939 unsigned long theEvent,
941 void* vtkNotUsed( theCallData ) )
943 vtkImplicitPlaneWidget* aWidget = vtkImplicitPlaneWidget::SafeDownCast( theObject );
944 if ( aWidget == NULL ) return;
945 if ( theClientData == NULL ) return;
947 SMESHGUI_ClippingDlg* aDlg = (SMESHGUI_ClippingDlg*) theClientData;
953 case vtkCommand::InteractionEvent:
954 aWidget->GetOrigin( anOrigin );
955 aWidget->GetNormal( aDir );
957 aDlg->myIsSelectPlane = true;
959 if( aDlg->CurrentMode == SMESH::Absolute ) {
960 aDlg->setOrigin( anOrigin );
961 aDlg->setDirection( aDir );
962 aDlg->myIsPreviewMoved = true;
964 else if( aDlg->CurrentMode == SMESH::Relative ) {
965 aDlg->absolutePlaneToRelative( anOrigin, aDir );
967 aDlg->myIsSelectPlane = false;
969 aDlg->SetCurrentPlaneParam();
970 aDlg->myIsPreviewMoved = false;
976 Initialize the planes's data when the dialog opened
978 void SMESHGUI_ClippingDlg::initializePlaneData()
980 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
981 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
982 if( anIter1 != aClippingPlaneInfoMap.end() ) {
983 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
984 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
985 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
986 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
987 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
988 anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
989 SMESH::TPlane aTPlane( anOrientedPlane );
990 SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
991 myPlanes.push_back( aPlaneData );
994 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
995 if( myPlanes.size() )
996 myPreviewWidget->SetEnabled( PreviewCheckBox->isChecked() );
1000 Initialization of initial values of widgets
1002 void SMESHGUI_ClippingDlg::initParam()
1004 SpinBox_X->setValue( 0.0 );
1005 SpinBox_Y->setValue( 0.0 );
1006 SpinBox_Z->setValue( 0.0 );
1008 SpinBox_Dx->setValue( 1.0 );
1009 SpinBox_Dy->setValue( 1.0 );
1010 SpinBox_Dz->setValue( 1.0 );
1012 CBAbsoluteOrientation->setCurrentIndex(0);
1014 TLValueDistance->setText( "0.5" );
1015 TLValueRotation1->setText( "0\xB0" );
1016 TLValueRotation2->setText( "0\xB0" );
1017 CBRelativeOrientation->setCurrentIndex( 0 );
1018 SliderDistance->setValue( 50 );
1019 SliderRotation1->setValue( 0 );
1020 SliderRotation2->setValue( 0 );
1024 Synchronize dialog's widgets with data
1026 void SMESHGUI_ClippingDlg::synchronize()
1028 int aNbPlanes = myPlanes.size();
1029 ComboBoxPlanes->clear();
1032 for( int i = 1; i<=aNbPlanes; i++ ) {
1033 aName = QString( tr( "PLANE_NUM" ) ).arg(i);
1034 ComboBoxPlanes->addItem( aName );
1037 int aPos = ComboBoxPlanes->count() - 1;
1038 ComboBoxPlanes->setCurrentIndex( aPos );
1040 bool anIsControlsEnable = ( aPos >= 0 );
1041 if ( anIsControlsEnable ) {
1042 onSelectPlane( aPos );
1044 if( PreviewCheckBox->isChecked() )
1045 myPreviewWidget->On();
1048 ComboBoxPlanes->addItem( tr( "NO_PLANES" ) );
1051 if( PreviewCheckBox->isChecked() )
1052 myPreviewWidget->Off();
1055 isOpenGLClipping->setEnabled( anIsControlsEnable );
1056 ActorList->setEnabled( anIsControlsEnable );
1057 SelectAllCheckBox->setEnabled( anIsControlsEnable );
1058 buttonDelete->setEnabled( anIsControlsEnable );
1059 if ( CurrentMode == SMESH::Absolute ) {
1060 SpinBox_X->setEnabled( anIsControlsEnable );
1061 SpinBox_Y->setEnabled( anIsControlsEnable );
1062 SpinBox_Z->setEnabled( anIsControlsEnable );
1063 SpinBox_Dx->setEnabled( anIsControlsEnable );
1064 SpinBox_Dy->setEnabled( anIsControlsEnable );
1065 SpinBox_Dz->setEnabled( anIsControlsEnable );
1066 CBAbsoluteOrientation->setEnabled( anIsControlsEnable );
1067 invertButton->setEnabled( anIsControlsEnable );
1068 resetButton->setEnabled( anIsControlsEnable );
1070 else if ( CurrentMode == SMESH::Relative ) {
1071 CBRelativeOrientation->setEnabled( anIsControlsEnable );
1072 SliderDistance->setEnabled( anIsControlsEnable );
1073 SliderRotation1->setEnabled( anIsControlsEnable );
1074 SliderRotation2->setEnabled( anIsControlsEnable );
1079 Update the list of actors
1081 void SMESHGUI_ClippingDlg::updateActorList()
1085 SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1089 _PTR(Study) aStudy = anAppStudy->studyDS();
1096 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1097 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1098 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1100 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1101 aPlaneData.Plane.GetPointer()->myActor->SetVisibility( false );
1103 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1104 vtkActorCollection* anAllActors = aCopy.GetActors();
1105 anAllActors->InitTraversal();
1106 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1107 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1108 if( anActor->hasIO() ) {
1109 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1110 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1111 bool anIsChecked = false;
1112 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1113 for ( ; anIter != anActorList.end(); anIter++ ) {
1114 if( vtkActor* aVTKActorRef = *anIter ) {
1115 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1116 if( anActorRef == anActor ) {
1123 QString aName = QString( aSObj->GetName().c_str() );
1124 QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
1125 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1126 updateActorItem( anItem, true, false );
1134 Update an actor in actor's list
1136 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
1137 bool theUpdateSelectAll,
1138 bool theUpdateClippingPlaneMap )
1140 // update Select All check box
1141 if( theUpdateSelectAll ) {
1142 int aNbItems = ActorList->count(), aNbChecked = 0;
1143 for( int i = 0; i < aNbItems; i++ )
1144 if( QListWidgetItem* anItem = ActorList->item( i ) )
1145 if( anItem->checkState() == Qt::Checked )
1148 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
1149 SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
1150 SelectAllCheckBox->blockSignals( anIsBlocked );
1153 // update clipping plane map
1154 if( theUpdateClippingPlaneMap ) {
1155 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1156 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
1157 if( SMESH_Actor* anActor = anItem->getActor() ) {
1158 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1159 SMESH::TActorList& anActorList = aPlaneData.ActorList;
1160 bool anIsPushed = false;
1161 SMESH::TActorList::iterator anIter = anActorList.begin();
1162 for ( ; anIter != anActorList.end(); anIter++ ) {
1163 if( anActor == *anIter ) {
1168 if( theItem->checkState() == Qt::Checked && !anIsPushed )
1169 anActorList.push_back( anActor );
1170 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
1171 anActorList.remove( anActor );
1173 SMESH::ComputeBounds( anActorList, myBounds );
1174 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1175 myBounds[3], myBounds[4], myBounds[5] );
1182 Get the list of current actors
1184 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1186 SMESH::TActorList anActorList;
1187 for( int i = 0, n = ActorList->count(); i < n; i++ )
1188 if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1189 if( anItem->checkState() == Qt::Checked )
1190 if( SMESH_Actor* anActor = anItem->getActor() )
1191 anActorList.push_back( anActor );
1196 Dump the parameters of clipping planes
1198 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1200 printf( "----------- Plane Data -----------\n" );
1202 SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1203 for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1204 SMESH::TPlaneData aPlaneData = *anIter1;
1205 SMESH::TPlane aPlane = aPlaneData.Plane;
1206 double* aNormal = aPlane->GetNormal();
1207 double* anOrigin = aPlane->GetOrigin();
1208 printf( "Plane N%d:\n", anId );
1209 printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1210 printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1212 SMESH::TActorList anActorList = aPlaneData.ActorList;
1213 SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1214 for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1215 if( vtkActor* aVTKActor = *anIter2 ) {
1216 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1217 printf( " - Actor: '%s'\n", anActor->getName() );
1220 printf( " - Actor: NULL\n");
1223 printf( "----------------------------------\n" );
1227 SLOT on close button click: rejects dialog
1229 void SMESHGUI_ClippingDlg::reject()
1231 //here we can insert actions to do at close.
1236 Set absolute mode of clipping plane
1238 void SMESHGUI_ClippingDlg::onModeAbsolute()
1240 ModeStackedLayout->setCurrentIndex(0);
1241 CurrentMode = SMESH::Absolute;
1243 SetCurrentPlaneParam();
1247 Set relative mode of clipping plane
1249 void SMESHGUI_ClippingDlg::onModeRelative()
1251 ModeStackedLayout->setCurrentIndex(1);
1252 CurrentMode = SMESH::Relative;
1254 SetCurrentPlaneParam();
1258 SLOT on new button click: create a new clipping plane
1260 void SMESHGUI_ClippingDlg::ClickOnNew()
1263 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
1264 SMESH::TPlane aTPlane(aPlane);
1265 aPlane->PlaneMode = CurrentMode;
1266 SMESH::TActorList anActorList;
1267 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1268 vtkActorCollection* anAllActors = aCopy.GetActors();
1269 anAllActors->InitTraversal();
1270 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1271 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1272 anActorList.push_back( anActor );
1274 SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
1276 myPlanes.push_back(aPlaneData);
1279 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1280 aPlane->myActor->SetVisibility( false );
1282 bool anIsBlocked = ActorList->blockSignals( true );
1284 SMESH::ComputeBounds( anActorList, myBounds );
1285 myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2],
1286 myBounds[3],myBounds[4],myBounds[5] );
1288 SetCurrentPlaneParam();
1290 ActorList->blockSignals( anIsBlocked );
1295 SLOT on delete button click: Delete selected clipping plane
1297 void SMESHGUI_ClippingDlg::ClickOnDelete()
1299 if (myPlanes.empty())
1302 int aPlaneIndex = ComboBoxPlanes->currentIndex();
1304 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
1305 SMESH::TPlaneData aPlaneData = *anIter;
1306 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
1307 myPlanes.erase(anIter);
1309 if(AutoApplyCheckBox->isChecked())
1313 SMESH::RenderViewWindow( myViewWindow );
1317 Set current parameters of selected plane
1319 void SMESHGUI_ClippingDlg::onSelectPlane ( int theIndex )
1321 if ( myPlanes.empty() )
1324 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
1325 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1327 myIsSelectPlane = true;
1328 isOpenGLClipping->setChecked( aPlane->IsOpenGLClipping );
1330 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1331 ModeStackedLayout->setCurrentIndex( 0 );
1332 CurrentMode = SMESH::Absolute;
1333 int anOrientation = aPlane->myAbsoluteOrientation;
1334 // Set plane parameters in the dialog
1335 double anOrigin[3], aDir[3];
1336 anOrigin[0] = aPlane->X;
1337 anOrigin[1] = aPlane->Y;
1338 anOrigin[2] = aPlane->Z;
1339 setOrigin( anOrigin );
1340 aDir[0] = aPlane->Dx;
1341 aDir[1] = aPlane->Dy;
1342 aDir[2] = aPlane->Dz;
1343 setDirection( aDir );
1344 CBAbsoluteOrientation->setCurrentIndex( anOrientation );
1345 onSelectAbsoluteOrientation( anOrientation );
1347 else if ( aPlane->PlaneMode == SMESH::Relative ) {
1348 ModeStackedLayout->setCurrentIndex( 1 );
1349 CurrentMode = SMESH::Relative;
1350 SMESH::Orientation anOrientation = aPlane->GetOrientation();
1351 double aRot[2] = { aPlane->myAngle[0], aPlane->myAngle[1] };
1352 // Set plane parameters in the dialog
1353 setDistance( aPlane->GetDistance() );
1354 setRotation( aRot[0], aRot[1] );
1355 switch ( anOrientation ) {
1357 CBRelativeOrientation->setCurrentIndex(0);
1358 onSelectRelativeOrientation(0);
1361 CBRelativeOrientation->setCurrentIndex(1);
1362 onSelectRelativeOrientation(1);
1365 CBRelativeOrientation->setCurrentIndex(2);
1366 onSelectRelativeOrientation(2);
1370 myIsSelectPlane = false;
1371 SMESH::ComputeBounds( aPlaneData.ActorList, myBounds );
1372 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1373 myBounds[3], myBounds[4], myBounds[5] );
1374 SetCurrentPlaneParam();
1377 bool anIsBlocked = ActorList->blockSignals( true );
1379 ActorList->blockSignals( anIsBlocked );
1383 SLOT: called on OpenGLClipping check box toggled
1385 void SMESHGUI_ClippingDlg::onIsOpenGLClipping( bool toggled )
1387 if ( myPlanes.empty() || myIsSelectPlane )
1390 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1391 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1392 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1393 aPlaneData->IsOpenGLClipping = toggled;
1395 if( AutoApplyCheckBox->isChecked() )
1400 SLOT: called on SelectAll check box toggled
1402 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
1404 if( theState == Qt::PartiallyChecked ) {
1405 SelectAllCheckBox->setCheckState( Qt::Checked );
1409 bool anIsBlocked = ActorList->blockSignals( true );
1410 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
1411 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
1412 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
1413 updateActorItem( anItem, false, true );
1416 SelectAllCheckBox->setTristate( false );
1417 ActorList->blockSignals( anIsBlocked );
1418 SetCurrentPlaneParam();
1422 SLOT: called when actor item was changed
1424 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
1426 updateActorItem( theItem, true, true );
1427 SetCurrentPlaneParam();
1431 Restore parameters of selected plane
1433 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
1435 if ( myPlanes.empty() || myIsSelectPlane )
1438 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1440 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1441 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1443 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1444 aPlane->myAbsoluteOrientation = CBAbsoluteOrientation->currentIndex();
1445 aPlane->X = SpinBox_X->value();
1446 aPlane->Y = SpinBox_Y->value();
1447 aPlane->Z = SpinBox_Z->value();
1448 aPlane->Dx = SpinBox_Dx->value();
1449 aPlane->Dy = SpinBox_Dy->value();
1450 aPlane->Dz = SpinBox_Dz->value();
1454 double aDir[2][3] = { {0, 0, 0}, {0, 0, 0} };
1455 static double aCoeff = vtkMath::Pi()/180.0;
1457 double aRot[2] = { getRotation1(), getRotation2() };
1459 if ( aPlane->PlaneMode == SMESH::Absolute )
1460 anOrient = CBAbsoluteOrientation->currentIndex();
1461 else if ( aPlane->PlaneMode == SMESH::Relative )
1462 anOrient = CBRelativeOrientation->currentIndex() + 1;
1464 if ( aPlane->PlaneMode == SMESH::Relative ) {
1465 aPlane->myAngle[0] = aRot[0];
1466 aPlane->myAngle[1] = aRot[1];
1467 aPlane->SetOrientation( SMESH::Orientation( CBRelativeOrientation->currentIndex() ) );
1468 aPlane->SetDistance( getDistance() );
1471 if ( anOrient == 0 ) {
1472 // compute a direction for plane in absolute mode
1473 double znam = sqrt( aPlane->Dx*aPlane->Dx + aPlane->Dy*aPlane->Dy + aPlane->Dz*aPlane->Dz );
1474 double aRotation = acos( aPlane->Dy/znam )/aCoeff;
1475 if ( aPlane->Dy >= 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = 90.0 + aRotation;
1476 else if ( aPlane->Dy >= 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 90.0 - aRotation;
1477 else if ( aPlane->Dy < 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = aRotation - 90.0;
1478 else if ( aPlane->Dy < 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 270.0 - aRotation;
1480 aRotation = acos( aPlane->Dx/znam )/aCoeff;
1481 if ( aPlane->Dx >= 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = 90.0 + aRotation;
1482 else if ( aPlane->Dx >= 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 90.0 - aRotation;
1483 else if ( aPlane->Dx < 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = aRotation - 90.0;
1484 else if ( aPlane->Dx < 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 270.0 - aRotation;
1488 rotationToNormal( aRot, anOrient, aNormal, aDir );
1491 SMESH::TActorList anActorList = aPlaneData.ActorList;
1496 aDistance = getDistance();
1497 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1498 aNormal[0] = aPlane->Dx;
1499 aNormal[1] = aPlane->Dy;
1500 aNormal[2] = aPlane->Dz;
1503 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
1509 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1510 anOrigin[0] = aPlane->X;
1511 anOrigin[1] = aPlane->Y;
1512 anOrigin[2] = aPlane->Z;
1516 aPlane->SetNormal( aNormal );
1517 aPlane->SetOrigin( anOrigin );
1519 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
1520 ( aBounds[2] + aBounds[3] ) / 2.,
1521 ( aBounds[4] + aBounds[5] ) / 2. };
1523 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
1524 pow( aBounds[3] - aBounds[2], 2 ) +
1525 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
1527 double aDelta[2][3] = { { aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel },
1528 { aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel } };
1529 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
1531 double aPnt01[3] = { aPnt[0] - aDelta[0][0] - aDelta[1][0],
1532 aPnt[1] - aDelta[0][1] - aDelta[1][1],
1533 aPnt[2] - aDelta[0][2] - aDelta[1][2] };
1534 double aPnt02[3] = { aPnt01[0] + aNormal[0],
1535 aPnt01[1] + aNormal[1],
1536 aPnt01[2] + aNormal[2] };
1537 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
1539 double aPnt11[3] = { aPnt[0] - aDelta[0][0] + aDelta[1][0],
1540 aPnt[1] - aDelta[0][1] + aDelta[1][1],
1541 aPnt[2] - aDelta[0][2] + aDelta[1][2] };
1542 double aPnt12[3] = { aPnt11[0] + aNormal[0],
1543 aPnt11[1] + aNormal[1],
1544 aPnt11[2] + aNormal[2] };
1545 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1547 double aPnt21[3] = { aPnt[0] + aDelta[0][0] - aDelta[1][0],
1548 aPnt[1] + aDelta[0][1] - aDelta[1][1],
1549 aPnt[2] + aDelta[0][2] - aDelta[1][2] };
1550 double aPnt22[3] = { aPnt21[0] + aNormal[0],
1551 aPnt21[1] + aNormal[1],
1552 aPnt21[2] + aNormal[2] };
1553 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1555 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1557 aPlaneSource->SetNormal( aNormal[0], aNormal[1], aNormal[2] );
1558 aPlaneSource->SetOrigin( aPnt0[0], aPnt0[1], aPnt0[2] );
1559 aPlaneSource->SetPoint1( aPnt1[0], aPnt1[1], aPnt1[2] );
1560 aPlaneSource->SetPoint2( aPnt2[0], aPnt2[1], aPnt2[2] );
1561 aPlaneSource->Update();
1564 setBoundsForPreviewWidget();
1566 myPreviewWidget->SetOrigin( anOrigin );
1567 myPreviewWidget->SetNormal( aNormal );
1569 if(AutoApplyCheckBox->isChecked())
1572 SMESH::RenderViewWindow( myViewWindow );
1576 Set current bounds for preview widget
1578 void SMESHGUI_ClippingDlg::setBoundsForPreviewWidget()
1580 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1581 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1582 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1583 SMESH::TActorList anActorList = aPlaneData.ActorList;
1585 double* anOrigin = aPlane->GetOrigin();
1588 SMESH::ComputeBounds( anActorList, aBounds );
1590 bool isBoundsChanged = false;
1592 if( myIsPreviewMoved ) {
1593 // if widget has moved by hand the bounds can to minimize
1594 if( anOrigin[0] > myBounds[0] && anOrigin[0] < aBounds[0] ) {
1595 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1596 if( anOrigin[0] < myBounds[1] && anOrigin[0] > aBounds[1] ) {
1597 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1598 if( anOrigin[1] > myBounds[2] && anOrigin[1] < aBounds[2] ) {
1599 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1600 if( anOrigin[1] < myBounds[3] && anOrigin[1] > aBounds[3] ) {
1601 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1602 if( anOrigin[2] > myBounds[4] && anOrigin[2] < aBounds[4] ) {
1603 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1604 if( anOrigin[2] < myBounds[5] && anOrigin[2] > aBounds[5] ) {
1605 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1608 // if widget has moved by dialog data the bounds can to take necessary size
1609 if( anOrigin[0] < aBounds[0] ) {
1610 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1611 if( anOrigin[0] > aBounds[1] ) {
1612 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1613 if( anOrigin[1] < aBounds[2] ) {
1614 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1615 if( anOrigin[1] > aBounds[3] ) {
1616 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1617 if( anOrigin[2] < aBounds[4] ) {
1618 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1619 if( anOrigin[2] > aBounds[5] ) {
1620 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1623 if( isBoundsChanged )
1624 myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2],
1625 myBounds[3],myBounds[4],myBounds[5] );
1626 else if( !myIsPreviewMoved )
1627 myPreviewWidget->PlaceWidget( aBounds[0],aBounds[1],aBounds[2],
1628 aBounds[3],aBounds[4],aBounds[5] );
1633 Convert absolute coordinates of plane to relative mode
1635 void SMESHGUI_ClippingDlg::absolutePlaneToRelative ( double theOrigin[3], double theDir[3] )
1639 aRot[0] = getRotation1();
1640 aRot[1] = getRotation2();
1642 double eps = 0.0001;
1644 int anOrientation = CBRelativeOrientation->currentIndex();
1645 double aDirection[3];
1646 double aRotation1, aRotation2;
1647 switch( anOrientation ) {
1649 aDirection[0] = theDir[0] + eps;
1650 aDirection[1] = theDir[1] + eps;
1651 aDirection[2] = theDir[2] + eps;
1652 aRotation1 = atan2( theDir[2], theDir[1] )*180.0/M_PI;
1653 aRotation2 = atan2( theDir[2], theDir[0] )*180.0/M_PI;
1656 aDirection[0] = theDir[1] + eps;
1657 aDirection[1] = theDir[2] + eps;
1658 aDirection[2] = theDir[0] + eps;
1659 aRotation1 = atan2( theDir[0], theDir[2] )*180.0/M_PI;
1660 aRotation2 = atan2( theDir[0], theDir[1] )*180.0/M_PI;
1663 aDirection[0] = theDir[2] + eps;
1664 aDirection[1] = theDir[0] + eps;
1665 aDirection[2] = theDir[1] + eps;
1666 aRotation1 = atan2( theDir[1], theDir[0] )*180.0/M_PI;
1667 aRotation2 = atan2( theDir[1], theDir[2] )*180.0/M_PI;
1671 if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1672 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1673 else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1674 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 90.0; }
1675 else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1676 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 + 90.0; }
1677 else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1678 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 90.0; }
1679 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1680 aRot[0] = aRotation1 - 270.0; aRot[1] = aRotation2 + 90.0; }
1681 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1682 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1683 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1684 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 90.0; }
1685 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1686 aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
1687 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1688 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1689 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1690 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 270.0; }
1691 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1692 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 + 90.0; }
1693 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1694 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
1695 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1696 aRot[0] = aRotation1 - 270.0; aRot[1] = aRotation2 - 270.0; }
1697 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1698 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1699 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1700 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
1701 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1702 aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
1704 SliderRotation1HasMoved( qRound( aRot[0] ) );
1705 SliderRotation1->setValue( qRound( aRot[0] ) );
1706 SliderRotation2HasMoved( qRound( aRot[1] ) );
1707 SliderRotation2->setValue( qRound( aRot[1] ) );
1709 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1710 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1711 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1715 SMESH::ComputeBounds( anActorList, aBounds );
1716 SMESH::PositionToDistance( aBounds, theDir, theOrigin, aDist );
1717 aDist = 1.0 - aDist;
1720 else if( aDist < 0.0 )
1723 SliderDistanceHasMoved( qRound( aDist*100 ) );
1724 SliderDistance->setValue( qRound( aDist*100 ) );
1729 SLOT: called on preview check box toggled
1731 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1733 std::for_each( myPlanes.begin(), myPlanes.end(), TSetVisibility( theIsToggled ) );
1734 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1735 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1736 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1737 aPlaneData->myActor->SetVisibility( false );
1739 myPreviewWidget->On();
1741 myPreviewWidget->Off();
1742 SMESH::RenderViewWindow( myViewWindow );
1746 SLOT: called on Auto Apply check box toggled
1748 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1750 if ( toggled ) ClickOnApply();
1754 SLOT on ok button click: sets cutting plane and closes dialog
1756 void SMESHGUI_ClippingDlg::ClickOnOk()
1764 SLOT on Apply button click: sets cutting plane and update viewer
1766 void SMESHGUI_ClippingDlg::ClickOnApply()
1769 SUIT_OverrideCursor wc;
1771 QWidget *aCurrWid = this->focusWidget();
1772 aCurrWid->clearFocus();
1773 aCurrWid->setFocus();
1775 SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1776 SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
1778 // clean memory allocated for planes
1779 SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
1780 for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
1781 if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
1784 aClippingPlaneInfoList.clear();
1786 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1787 vtkActorCollection* anAllActors = aCopy.GetActors();
1788 anAllActors->InitTraversal();
1789 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1790 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1791 anActor->RemoveAllClippingPlanes();
1793 SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
1794 for( ; anIter2 != myPlanes.end(); anIter2++ ) {
1795 SMESH::TPlaneData aPlaneData = *anIter2;
1796 SMESH::TPlane aPlane = aPlaneData.Plane;
1797 SMESH::TActorList anActorList = aPlaneData.ActorList;
1799 // the check is disabled to support planes with empty actor list
1800 //if( anActorList.empty() )
1803 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1804 anOrientedPlane->ShallowCopy(aPlane.GetPointer());
1805 SMESH::TActorList::iterator anIter3 = anActorList.begin();
1806 for( ; anIter3 != anActorList.end(); anIter3++ )
1807 if( vtkActor* aVTKActor = *anIter3 )
1808 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1809 if( anOrientedPlane->IsOpenGLClipping )
1810 anActor->AddOpenGLClippingPlane( anOrientedPlane->InvertPlane() );
1812 anActor->AddClippingPlane( anOrientedPlane );
1815 SMESH::ClippingPlaneInfo aClippingPlaneInfo;
1816 aClippingPlaneInfo.Plane = anOrientedPlane;
1817 aClippingPlaneInfo.ActorList = anActorList;
1819 aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
1822 SMESH_Actor* anSMESHActor;
1823 anAllActors->InitTraversal();
1824 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1825 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1826 anSMESHActor = anActor;
1827 anActor->SetOpenGLClippingPlane();
1830 SMESH::RenderViewWindow( myViewWindow );
1835 SLOT on help button click: opens a help page
1837 void SMESHGUI_ClippingDlg::ClickOnHelp()
1839 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1841 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1845 platform = "winapplication";
1847 platform = "application";
1849 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1850 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1851 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1853 arg(myHelpFileName));
1858 SLOT: Called when value of slider distance change
1860 void SMESHGUI_ClippingDlg::SliderDistanceHasMoved( int value )
1862 double new_value = value/100.;
1863 TLValueDistance->setText( QString("%1").arg( new_value ) );
1864 SetCurrentPlaneParam();
1868 SLOT: Called when value of slider rotation1 change
1870 void SMESHGUI_ClippingDlg::SliderRotation1HasMoved( int value )
1872 TLValueRotation1->setText( QString("%1\xB0").arg( value ) );
1873 SetCurrentPlaneParam();
1877 SLOT: Called when value of slider rotation2 change
1879 void SMESHGUI_ClippingDlg::SliderRotation2HasMoved( int value )
1881 TLValueRotation2->setText( QString("%1\xB0").arg( value ) );
1882 SetCurrentPlaneParam();
1885 void SMESHGUI_ClippingDlg::onSelectAbsoluteOrientation( int mode )
1887 bool isUserMode = (mode==0);
1889 TextLabelX->setEnabled( isUserMode );
1890 TextLabelY->setEnabled( isUserMode );
1891 TextLabelZ->setEnabled( isUserMode );
1893 SpinBox_X->setEnabled( isUserMode );
1894 SpinBox_Y->setEnabled( isUserMode );
1895 SpinBox_Z->setEnabled( isUserMode );
1897 TextLabelDx->setEnabled( isUserMode );
1898 TextLabelDy->setEnabled( isUserMode );
1899 TextLabelDz->setEnabled( isUserMode );
1901 SpinBox_Dx->setEnabled( isUserMode );
1902 SpinBox_Dy->setEnabled( isUserMode );
1903 SpinBox_Dz->setEnabled( isUserMode );
1908 double aDx = 0, aDy = 0, aDz = 0;
1913 TextLabelZ->setEnabled( true );
1914 SpinBox_Z->setEnabled( true );
1915 SpinBox_Z->setFocus();
1917 else if ( mode == 2 )
1920 TextLabelX->setEnabled( true );
1921 SpinBox_X->setEnabled( true );
1922 SpinBox_X->setFocus();
1924 else if ( mode == 3 )
1927 TextLabelY->setEnabled( true );
1928 SpinBox_Y->setEnabled( true );
1929 SpinBox_Y->setFocus();
1932 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1933 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1934 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1936 if ( aPlaneData->IsInvert == true ) {
1937 aDx = -aDx; aDy = -aDy; aDz = -aDz;
1940 myIsSelectPlane = true;
1941 SpinBox_Dx->setValue( aDx );
1942 SpinBox_Dy->setValue( aDy );
1943 SpinBox_Dz->setValue( aDz );
1944 myIsSelectPlane = false;
1946 SetCurrentPlaneParam();
1950 SLOT: called on orientation of clipping plane in relative mode changed
1952 void SMESHGUI_ClippingDlg::onSelectRelativeOrientation ( int theItem )
1954 if ( myPlanes.empty() )
1957 if ( theItem == 0 ) {
1958 TextLabelRotation1->setText( tr( "ROTATION_AROUND_X_Y2Z" ) );
1959 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Y_X2Z" ) );
1961 else if ( theItem == 1 ) {
1962 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Y_Z2X" ) );
1963 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Z_Y2X" ) );
1965 else if ( theItem == 2 ) {
1966 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Z_X2Y" ) );
1967 TextLabelRotation2->setText( tr( "ROTATION_AROUND_X_Z2Y" ) );
1970 if( (QComboBox*)sender() == CBRelativeOrientation )
1971 SetCurrentPlaneParam();
1975 SLOT on reset button click: sets default values
1977 void SMESHGUI_ClippingDlg::onReset()
1979 myIsSelectPlane = true;
1980 SpinBox_X->setValue(0);
1981 SpinBox_Y->setValue(0);
1982 SpinBox_Z->setValue(0);
1983 myIsSelectPlane = false;
1985 SetCurrentPlaneParam();
1989 SLOT on invert button click: inverts normal of cutting plane
1991 void SMESHGUI_ClippingDlg::onInvert()
1993 double Dx = SpinBox_Dx->value();
1994 double Dy = SpinBox_Dy->value();
1995 double Dz = SpinBox_Dz->value();
1997 myIsSelectPlane = true;
1998 SpinBox_Dx->setValue( -Dx );
1999 SpinBox_Dy->setValue( -Dy );
2000 SpinBox_Dz->setValue( -Dz );
2001 myIsSelectPlane = false;
2003 if ( !myPlanes.empty() ) {
2004 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
2005 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
2006 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
2007 aPlaneData->IsInvert = !aPlaneData->IsInvert;
2009 SetCurrentPlaneParam();