1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // 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 <QtxDoubleSpinSlider.h>
36 #include <QtxIntSpinSlider.h>
38 #include <SMESH_Actor.h>
39 #include <SMESH_ActorUtils.h>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_OverrideCursor.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_ViewManager.h>
49 #include <SALOME_ListIO.hxx>
51 #include <SalomeApp_Study.h>
53 #include <LightApp_Application.h>
55 #include <VTKViewer_Algorithm.h>
57 #include <SVTK_ViewWindow.h>
58 #include <SVTK_RenderWindowInteractor.h>
62 #include <QPushButton>
65 #include <QVBoxLayout>
66 #include <QHBoxLayout>
67 #include <QGridLayout>
70 #include <QListWidget>
71 #include <QStackedLayout>
77 #include <vtkDataSet.h>
78 #include <vtkDataSetMapper.h>
79 #include <vtkPlaneSource.h>
80 #include <vtkProperty.h>
81 #include <vtkRenderer.h>
82 #include <vtkCallbackCommand.h>
83 #include <vtkImplicitPlaneWidget.h>
87 #define SIZEFACTOR 1.1
90 Create new object of class OrientedPlane
92 SMESH::OrientedPlane* SMESH::OrientedPlane::New()
94 return new OrientedPlane();
98 Create new object of class OrientedPlane
100 SMESH::OrientedPlane* SMESH::OrientedPlane::New( SVTK_ViewWindow* theViewWindow )
102 return new OrientedPlane( theViewWindow );
106 Copy the object of class OrientedPlane
108 void SMESH::OrientedPlane::ShallowCopy( SMESH::OrientedPlane* theOrientedPlane )
110 SetNormal( theOrientedPlane->GetNormal() );
111 SetOrigin( theOrientedPlane->GetOrigin() );
113 myRelativeOrientation = theOrientedPlane->GetOrientation();
114 myDistance = theOrientedPlane->GetDistance();
116 IsOpenGLClipping = theOrientedPlane->IsOpenGLClipping;
118 myAngle[0] = theOrientedPlane->myAngle[0];
119 myAngle[1] = theOrientedPlane->myAngle[1];
121 myAbsoluteOrientation = theOrientedPlane->myAbsoluteOrientation;
122 X = theOrientedPlane->X;
123 Y = theOrientedPlane->Y;
124 Z = theOrientedPlane->Z;
125 Dx = theOrientedPlane->Dx;
126 Dy = theOrientedPlane->Dy;
127 Dz = theOrientedPlane->Dz;
129 PlaneMode = theOrientedPlane->PlaneMode;
131 myPlaneSource->SetNormal( theOrientedPlane->myPlaneSource->GetNormal() );
132 myPlaneSource->SetOrigin( theOrientedPlane->myPlaneSource->GetOrigin() );
133 myPlaneSource->SetPoint1( theOrientedPlane->myPlaneSource->GetPoint1() );
134 myPlaneSource->SetPoint2( theOrientedPlane->myPlaneSource->GetPoint2() );
135 myPlaneSource->Update();
139 Invert current clipping plane in contrary direction
141 SMESH::OrientedPlane* SMESH::OrientedPlane::InvertPlane()
143 OrientedPlane* aPlane = new OrientedPlane();
144 aPlane->ShallowCopy( this );
145 double* aNormal = aPlane->GetNormal();
146 for( int i=0; i<3; i++ )
147 aNormal[i] = -aNormal[i];
148 aPlane->SetNormal( aNormal );
153 Constructor of class OrientedPlane
155 SMESH::OrientedPlane::OrientedPlane(SVTK_ViewWindow* theViewWindow):
156 myViewWindow(theViewWindow)
159 myViewWindow->AddActor(myActor, false, false); // don't adjust actors
163 Constructor of class OrientedPlane
165 SMESH::OrientedPlane::OrientedPlane():
172 Initialize parameters of class OrientedPlane
174 void SMESH::OrientedPlane::Init()
176 myPlaneSource = vtkPlaneSource::New();
178 PlaneMode = SMESH::Absolute;
181 myAbsoluteOrientation = 0; // CUSTOM
182 myRelativeOrientation = SMESH::XY;
184 myAngle[0] = myAngle[1] = 0.0;
186 IsOpenGLClipping = false;
188 // Create and display actor
189 myMapper = vtkDataSetMapper::New();
190 myMapper->SetInputConnection(myPlaneSource->GetOutputPort());
192 myActor = SALOME_Actor::New();
193 myActor->VisibilityOff();
194 myActor->PickableOff();
195 myActor->SetInfinitive(true);
196 myActor->SetMapper(myMapper);
200 SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "255, 170, 0|-100" ) ;
202 vtkProperty* aProp = vtkProperty::New();
203 SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "255, 170, 0|-100" ) ;
204 aProp->SetColor(ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255.);
205 aProp->SetOpacity(0.75);
206 myActor->SetProperty(aProp);
209 vtkProperty* aBackProp = vtkProperty::New();
210 bfc = Qtx::mainColorToSecondary(ffc, delta);
211 aBackProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255.);
212 aBackProp->SetOpacity(0.75);
213 myActor->SetBackfaceProperty(aBackProp);
218 Destructor of class OrientedPlane
220 SMESH::OrientedPlane::~OrientedPlane()
223 myViewWindow->RemoveActor(myActor);
226 myMapper->RemoveAllInputs();
229 // commented: porting to vtk 5.0
230 // myPlaneSource->UnRegisterAllOutputs();
231 myPlaneSource->Delete();
237 Definition of class ActorItem
239 class ActorItem : public QListWidgetItem
242 ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) :
243 QListWidgetItem( theName, theListWidget ),
244 myActor( theActor ) {}
246 SMESH_Actor* getActor() const { return myActor; }
249 SMESH_Actor* myActor;
253 Definition of class TSetVisibility
255 struct TSetVisibility {
256 // Set visibility of cutting plane
257 TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){}
258 void operator()(SMESH::TPlaneData& thePlaneData){
259 bool anIsEmpty = thePlaneData.ActorList.empty();
260 thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty);
266 /*********************************************************************************
267 ********************* class SMESHGUI_ClippingDlg *********************
268 *********************************************************************************/
273 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
274 QDialog( SMESH::GetDesktop(theModule) ),
275 mySMESHGUI(theModule),
276 myViewWindow(theViewWindow)
279 setAttribute( Qt::WA_DeleteOnClose, true );
280 setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
281 setSizeGripEnabled(true);
283 myPreviewWidget = vtkImplicitPlaneWidget::New();
284 myCallback = vtkCallbackCommand::New();
285 myCallback->SetClientData( this );
286 myCallback->SetCallback( SMESHGUI_ClippingDlg::ProcessEvents );
287 myPreviewWidget = createPreviewWidget();
289 myIsPreviewMoved = false;
291 QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
292 SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
293 SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
295 // Controls for selecting, creating, deleting planes
296 QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
297 QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
298 GroupPlanesLayout->setSpacing(SPACING);
299 GroupPlanesLayout->setMargin(MARGIN);
301 ComboBoxPlanes = new QComboBox(GroupPlanes);
303 isOpenGLClipping = new QCheckBox( GroupPlanes );
304 isOpenGLClipping->setText( tr( "IS_OPENGL_CLIPPING" ) );
306 buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
308 MenuMode = new QMenu( "MenuMode", buttonNew );
309 MenuMode->addAction( tr( "ABSOLUTE" ), this, SLOT( onModeAbsolute() ) );
310 MenuMode->addAction( tr( "RELATIVE" ), this, SLOT( onModeRelative() ) );
311 buttonNew->setMenu( MenuMode );
312 CurrentMode = SMESH::Absolute;
314 buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
316 QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
318 ActorList = new QListWidget(GroupPlanes);
319 ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
321 SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
323 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
324 GroupPlanesLayout->addWidget(isOpenGLClipping, 0, 1);
325 GroupPlanesLayout->addWidget(new QWidget(), 0, 2);
326 GroupPlanesLayout->addWidget(buttonNew, 0, 3);
327 GroupPlanesLayout->addWidget(buttonDelete, 0, 4);
328 GroupPlanesLayout->addWidget(aLabel, 1, 0, 1, 5);
329 GroupPlanesLayout->addWidget(ActorList, 2, 0, 1, 5);
330 GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 5);
331 GroupPlanesLayout->setColumnStretch( 1, 1 );
333 ModeStackedLayout = new QStackedLayout();
335 // Controls for defining plane parameters
336 /********************** Mode Absolute **********************/
337 /* Controls for absolute mode of clipping plane:
338 X, Y, Z - coordinates of the intersection of cutting plane and the three axes
339 Dx, Dy, Dz - components of normal to the cutting plane
340 Orientation - direction of cutting plane
342 const double min = -1e+7;
343 const double max = 1e+7;
344 const double step = 5;
345 const int precision = -7;
348 QGroupBox* GroupAbsolutePoint = new QGroupBox( this );
349 GroupAbsolutePoint->setObjectName( "GroupPoint" );
350 GroupAbsolutePoint->setTitle( tr("BASE_POINT") );
351 QGridLayout* GroupPointLayout = new QGridLayout( GroupAbsolutePoint );
352 GroupPointLayout->setAlignment( Qt::AlignTop );
353 GroupPointLayout->setSpacing( 6 ); GroupPointLayout->setMargin( 11 );
355 TextLabelX = new QLabel( GroupAbsolutePoint );
356 TextLabelX->setObjectName( "TextLabelX" );
357 TextLabelX->setText( tr("X:") );
358 GroupPointLayout->addWidget( TextLabelX, 0, 0 );
360 SpinBox_X = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
361 SpinBox_X->setObjectName("SpinBox_X" );
362 SpinBox_X->setPrecision( precision );
363 GroupPointLayout->addWidget( SpinBox_X, 0, 1 );
365 TextLabelY = new QLabel( GroupAbsolutePoint );
366 TextLabelY->setObjectName( "TextLabelY" );
367 TextLabelY->setText( tr("Y:") );
368 GroupPointLayout->addWidget( TextLabelY, 0, 2 );
370 SpinBox_Y = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
371 SpinBox_Y->setObjectName("SpinBox_Y" );
372 SpinBox_Y->setPrecision( precision );
373 GroupPointLayout->addWidget( SpinBox_Y, 0, 3 );
375 TextLabelZ = new QLabel( GroupAbsolutePoint );
376 TextLabelZ->setObjectName( "TextLabelZ" );
377 TextLabelZ->setText( tr("Z:") );
378 GroupPointLayout->addWidget( TextLabelZ, 0, 4 );
380 SpinBox_Z = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
381 SpinBox_Z->setObjectName("SpinBox_Z" );
382 SpinBox_Z->setPrecision( precision );
383 GroupPointLayout->addWidget( SpinBox_Z, 0, 5 );
385 resetButton = new QPushButton( GroupAbsolutePoint );
386 resetButton->setObjectName( "resetButton" );
387 resetButton->setText( tr( "RESET" ) );
388 GroupPointLayout->addWidget( resetButton, 0, 6 );
391 GroupAbsoluteDirection = new QGroupBox( this );
392 GroupAbsoluteDirection->setObjectName( "GroupDirection" );
393 GroupAbsoluteDirection->setTitle( tr("DIRECTION") );
394 QGridLayout* GroupDirectionLayout = new QGridLayout( GroupAbsoluteDirection );
395 GroupDirectionLayout->setAlignment( Qt::AlignTop );
396 GroupDirectionLayout->setSpacing( 6 );
397 GroupDirectionLayout->setMargin( 11 );
399 TextLabelDx = new QLabel( GroupAbsoluteDirection );
400 TextLabelDx->setObjectName( "TextLabelDx" );
401 TextLabelDx->setText( tr("Dx:") );
402 GroupDirectionLayout->addWidget( TextLabelDx, 0, 0 );
404 SpinBox_Dx = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
405 SpinBox_Dx->setObjectName("SpinBox_Dx" );
406 SpinBox_Dx->setPrecision( precision );
407 GroupDirectionLayout->addWidget( SpinBox_Dx, 0, 1 );
409 TextLabelDy = new QLabel( GroupAbsoluteDirection );
410 TextLabelDy->setObjectName( "TextLabelDy" );
411 TextLabelDy->setText( tr("Dy:") );
412 GroupDirectionLayout->addWidget( TextLabelDy, 0, 2 );
414 SpinBox_Dy = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
415 SpinBox_Dy->setObjectName("SpinBox_Dy" );
416 SpinBox_Dy->setPrecision( precision );
417 GroupDirectionLayout->addWidget( SpinBox_Dy, 0, 3 );
419 TextLabelDz = new QLabel( GroupAbsoluteDirection );
420 TextLabelDz->setObjectName( "TextLabelDz" );
421 TextLabelDz->setText( tr("Dz:") );
422 GroupDirectionLayout->addWidget( TextLabelDz, 0, 4 );
424 SpinBox_Dz = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
425 SpinBox_Dz->setObjectName("SpinBox_Dz" );
426 SpinBox_Dz->setPrecision( precision );
427 GroupDirectionLayout->addWidget( SpinBox_Dz, 0, 5 );
429 invertButton = new QPushButton( GroupAbsoluteDirection );
430 invertButton->setObjectName( "invertButton" );
431 invertButton->setText( tr( "INVERT" ) );
432 GroupDirectionLayout->addWidget( invertButton, 0, 6 );
434 CBAbsoluteOrientation = new QComboBox( GroupAbsoluteDirection );
435 CBAbsoluteOrientation->setObjectName( "AbsoluteOrientation" );
436 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "CUSTOM" ) );
437 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||X-Y" ) );
438 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Y-Z" ) );
439 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Z-X" ) );
440 GroupDirectionLayout->addWidget( CBAbsoluteOrientation, 1, 0, 1, 6 );
442 QVBoxLayout* ModeActiveLayout = new QVBoxLayout();
443 ModeActiveLayout->setMargin( 11 ); ModeActiveLayout->setSpacing( 6 );
444 ModeActiveLayout->addWidget( GroupAbsolutePoint );
445 ModeActiveLayout->addWidget( GroupAbsoluteDirection );
447 QWidget* ModeActiveWidget = new QWidget( this );
448 ModeActiveWidget->setLayout( ModeActiveLayout );
450 /********************** Mode Relative **********************/
451 /* Controls for relative mode of clipping plane:
452 Distance - Value from 0 to 1.
453 Specifies the distance from the minimum value in a given direction of bounding box to the current position
454 Rotation1, Rotation2 - turn angles of cutting plane in given directions
455 Orientation - direction of cutting plane
457 QGroupBox* GroupParameters = new QGroupBox( tr("SMESH_PARAMETERS"), this );
458 QGridLayout* GroupParametersLayout = new QGridLayout( GroupParameters );
459 GroupParametersLayout->setMargin( 11 ); GroupParametersLayout->setSpacing( 6 );
461 TextLabelOrientation = new QLabel( tr("SMESH_ORIENTATION"), GroupParameters);
462 TextLabelOrientation->setObjectName( "TextLabelOrientation" );
463 GroupParametersLayout->addWidget( TextLabelOrientation, 0, 0 );
465 CBRelativeOrientation = new QComboBox(GroupParameters);
466 CBRelativeOrientation->setObjectName( "RelativeOrientation" );
467 CBRelativeOrientation->addItem( tr("ALONG_XY") );
468 CBRelativeOrientation->addItem( tr("ALONG_YZ") );
469 CBRelativeOrientation->addItem( tr("ALONG_ZX") );
470 GroupParametersLayout->addWidget( CBRelativeOrientation, 0, 1 );
472 TextLabelDistance = new QLabel( tr("SMESH_DISTANCE"), GroupParameters );
473 TextLabelDistance->setObjectName( "TextLabelDistance" );
474 GroupParametersLayout->addWidget( TextLabelDistance, 1, 0 );
476 SpinSliderDistance = new QtxDoubleSpinSlider( 0., 1., 0.01, GroupParameters );
477 SpinSliderDistance->setObjectName( "SpinSliderDistance" );
478 SpinSliderDistance->setPrecision( precision );
479 QFont fnt = SpinSliderDistance->font(); fnt.setBold( true ); SpinSliderDistance->setFont( fnt );
480 GroupParametersLayout->addWidget( SpinSliderDistance, 1, 1 );
482 QString aUnitRot = QString(QChar(0xB0));
484 TextLabelRotation1 = new QLabel( tr("ROTATION_AROUND_X_Y2Z"), GroupParameters );
485 TextLabelRotation1->setObjectName( "TextLabelRotation1" );
486 GroupParametersLayout->addWidget( TextLabelRotation1, 2, 0 );
488 SpinSliderRotation1 = new QtxIntSpinSlider( -180, 180, 1, GroupParameters );
489 SpinSliderRotation1->setObjectName( "SpinSliderRotation1" );
490 SpinSliderRotation1->setUnit( aUnitRot );
491 SpinSliderRotation1->setFont( fnt );
492 GroupParametersLayout->addWidget( SpinSliderRotation1, 2, 1 );
494 TextLabelRotation2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
495 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
496 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
497 GroupParametersLayout->addWidget( TextLabelRotation2, 3, 0 );
499 SpinSliderRotation2 = new QtxIntSpinSlider( -180, 180, 1, GroupParameters );
500 SpinSliderRotation2->setObjectName( "SpinSliderRotation2" );
501 SpinSliderRotation2->setUnit( aUnitRot );
502 SpinSliderRotation2->setFont( fnt );
503 GroupParametersLayout->addWidget( SpinSliderRotation2, 3, 1 );
505 /***************************************************************/
506 QWidget* CheckBoxWidget = new QWidget( this );
507 QHBoxLayout* CheckBoxLayout = new QHBoxLayout( CheckBoxWidget );
509 PreviewCheckBox = new QCheckBox( tr("SHOW_PREVIEW"), CheckBoxWidget );
510 PreviewCheckBox->setObjectName( "PreviewCheckBox" );
511 PreviewCheckBox->setChecked( true );
512 CheckBoxLayout->addWidget( PreviewCheckBox, 0, Qt::AlignCenter );
514 AutoApplyCheckBox = new QCheckBox( tr("AUTO_APPLY"), CheckBoxWidget );
515 AutoApplyCheckBox->setObjectName( "AutoApplyCheckBox" );
516 CheckBoxLayout->addWidget( AutoApplyCheckBox, 0, Qt::AlignCenter );
518 /***************************************************************/
519 // Controls for "Ok", "Apply" and "Close" button
520 QGroupBox* GroupButtons = new QGroupBox(this);
521 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
522 GroupButtonsLayout->setSpacing(SPACING);
523 GroupButtonsLayout->setMargin(MARGIN);
525 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
526 buttonOk->setAutoDefault( true );
527 buttonOk->setDefault( true );
528 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
529 buttonApply->setAutoDefault( true );
530 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
531 buttonCancel->setAutoDefault( true );
532 buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
533 buttonHelp->setAutoDefault( true );
534 GroupButtonsLayout->addWidget( buttonOk );
535 GroupButtonsLayout->addSpacing(10);
536 GroupButtonsLayout->addWidget( buttonApply );
537 GroupButtonsLayout->addSpacing(10);
538 GroupButtonsLayout->addStretch();
539 GroupButtonsLayout->addWidget( buttonCancel );
540 GroupButtonsLayout->addWidget( buttonHelp );
542 ModeStackedLayout->addWidget( ModeActiveWidget );
543 ModeStackedLayout->addWidget( GroupParameters );
545 SMESHGUI_ClippingDlgLayout->addWidget( GroupPlanes );
546 SMESHGUI_ClippingDlgLayout->addLayout( ModeStackedLayout );
547 SMESHGUI_ClippingDlgLayout->addWidget( CheckBoxWidget );
548 SMESHGUI_ClippingDlgLayout->addWidget( GroupButtons );
553 myIsSelectPlane = false;
555 myHelpFileName = "clipping.html";
557 // signals and slots connections :
558 connect( ComboBoxPlanes, SIGNAL( activated( int ) ), this, SLOT( onSelectPlane( int ) ) );
559 connect( isOpenGLClipping, SIGNAL( toggled( bool ) ), this, SLOT( onIsOpenGLClipping( bool ) ) );
560 connect( buttonNew, SIGNAL( clicked() ), buttonNew, SLOT( showMenu() ) );
561 connect( buttonDelete, SIGNAL( clicked() ), this, SLOT( ClickOnDelete() ) );
562 connect( ActorList, SIGNAL( itemChanged( QListWidgetItem* ) ), this, SLOT( onActorItemChanged( QListWidgetItem*) ) );
563 connect( SelectAllCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( onSelectAll( int ) ) );
565 connect( invertButton, SIGNAL (clicked() ), this, SLOT( onInvert() ) ) ;
566 connect( resetButton, SIGNAL (clicked() ), this, SLOT( onReset() ) );
567 connect( SpinBox_X, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
568 connect( SpinBox_Y, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
569 connect( SpinBox_Z, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
570 connect( SpinBox_Dx, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
571 connect( SpinBox_Dy, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
572 connect( SpinBox_Dz, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
573 connect( CBAbsoluteOrientation, SIGNAL ( activated ( int ) ), this, SLOT( onSelectAbsoluteOrientation( int ) ) ) ;
575 connect( CBRelativeOrientation, SIGNAL( activated( int ) ), this, SLOT( onSelectRelativeOrientation( int ) ) );
576 connect( SpinSliderDistance, SIGNAL( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
577 connect( SpinSliderRotation1, SIGNAL( valueChanged( int ) ), this, SLOT( SetCurrentPlaneParam() ) );
578 connect( SpinSliderRotation2, SIGNAL( valueChanged( int ) ), this, SLOT( SetCurrentPlaneParam() ) );
580 connect( PreviewCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( OnPreviewToggle( bool ) ) );
581 connect( AutoApplyCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( onAutoApply( bool ) ) );
582 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
583 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
584 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
585 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
586 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( reject() ) );
587 /* to close dialog if study frame change */
588 connect( mySMESHGUI, SIGNAL ( SignalStudyFrameChanged() ), this, SLOT( reject() ) );
590 initializePlaneData();
598 Destroys the object and frees any allocated resources
600 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
602 // no need to delete child widgets, Qt does it all for us
603 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
605 SMESH::RenderViewWindow(myViewWindow);
607 for ( size_t i = 0; i < myPlanes.size(); i++ ) {
608 SMESH::TPlaneData aPlaneData = myPlanes[i];
609 aPlaneData.Plane->Delete();
612 if ( myPreviewWidget ) {
613 myPreviewWidget->Off();
614 myPreviewWidget->Delete();
617 myCallback->Delete();
619 myViewWindow->Repaint();
623 Get distance for cutting plane in relative mode
625 double SMESHGUI_ClippingDlg::getDistance() const
627 return SpinSliderDistance->value();
631 Set distance of cutting plane in relative mode
633 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
635 SpinSliderDistance->setValue( theDistance );
639 Get rotation1 for cutting plane in relative mode
641 double SMESHGUI_ClippingDlg::getRotation1() const
643 return SpinSliderRotation1->value();
647 Get rotation2 for cutting plane in relative mode
649 double SMESHGUI_ClippingDlg::getRotation2() const
651 return SpinSliderRotation2->value();
655 Set angles of clipping plane in relative mode
657 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
659 SpinSliderRotation1->setValue( int(floor(theRot1)) );
660 SpinSliderRotation2->setValue( int(floor(theRot2)) );
664 Set coordinates of origin point in dialog box
666 void SMESHGUI_ClippingDlg::setOrigin( double theVal[3] )
668 int anOrientation = CBAbsoluteOrientation->currentIndex();
669 if( anOrientation == 0 || anOrientation == 2 )
670 SpinBox_X->setValue( theVal[0] );
671 if( anOrientation == 0 || anOrientation == 3 )
672 SpinBox_Y->setValue( theVal[1] );
673 if( anOrientation == 0 || anOrientation == 1 )
674 SpinBox_Z->setValue( theVal[2] );
678 Set coordinates of normal vector in dialog box
680 void SMESHGUI_ClippingDlg::setDirection( double theVal[3] )
682 int anOrientation = CBAbsoluteOrientation->currentIndex();
683 if( anOrientation == 0 ) {
684 SpinBox_Dx->setValue( theVal[0] );
685 SpinBox_Dy->setValue( theVal[1] );
686 SpinBox_Dz->setValue( theVal[2] );
691 Create a new widget for preview clipping plane
693 vtkImplicitPlaneWidget* SMESHGUI_ClippingDlg::createPreviewWidget()
695 vtkImplicitPlaneWidget* aPlaneWgt = vtkImplicitPlaneWidget::New();
697 aPlaneWgt->SetInteractor( myViewWindow->getInteractor() );
698 aPlaneWgt->SetPlaceFactor( SIZEFACTOR );
699 aPlaneWgt->ScaleEnabledOff();
700 aPlaneWgt->SetOrigin( 0, 0, 0 );
701 aPlaneWgt->SetNormal( -1, -1, -1 );
705 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
707 aPlaneWgt->GetPlaneProperty()->SetColor( anRGB[0],anRGB[1],anRGB[2] );
708 aPlaneWgt->GetPlaneProperty()->SetOpacity( 0.2 );;
710 aPlaneWgt->GetSelectedPlaneProperty()->SetColor( anRGB[0],anRGB[1],anRGB[2] );
711 aPlaneWgt->GetSelectedPlaneProperty()->SetOpacity( 0.2 );
712 aPlaneWgt->GetSelectedPlaneProperty()->SetLineWidth( 2.0 );
714 aPlaneWgt->AddObserver(vtkCommand::InteractionEvent, myCallback, 0.);
722 Translate two angles of plane to normal
724 void rotationToNormal ( double theRotation[2],
727 double theDir[2][3] )
729 static double aCoeff = M_PI/180.0;
731 double anU[2] = { cos( aCoeff * theRotation[0] ), cos( aCoeff * theRotation[1] ) };
732 double aV[2] = { sqrt( 1.0 - anU[0]*anU[0] ), sqrt( 1.0 - anU[1] * anU[1] ) };
733 aV[0] = theRotation[0] > 0? aV[0]: -aV[0];
734 aV[1] = theRotation[1] > 0? aV[1]: -aV[1];
736 switch ( theOrientation ) {
739 theDir[0][1] = anU[0];
740 theDir[0][2] = aV[0];
741 theDir[1][0] = anU[1];
742 theDir[1][2] = aV[1];
745 theDir[0][2] = anU[0];
746 theDir[0][0] = aV[0];
747 theDir[1][1] = anU[1];
748 theDir[1][0] = aV[1];
751 theDir[0][0] = anU[0];
752 theDir[0][1] = aV[0];
753 theDir[1][2] = anU[1];
754 theDir[1][1] = aV[1];
758 vtkMath::Cross( theDir[1], theDir[0], theNormal );
759 vtkMath::Normalize( theNormal );
760 vtkMath::Cross( theNormal, theDir[1], theDir[0] );
764 * \brief Return a name of a father mesh if any
766 QString getFatherName( _PTR(SObject)& theSObj )
768 _PTR(SComponent) objComponent = theSObj->GetFatherComponent();
769 const int theMeshDepth = 1 + objComponent->Depth();
770 if ( theSObj->Depth() <= theMeshDepth )
771 return QString(); // theSObj is a mesh
773 _PTR(SObject) sobj = theSObj->GetFather();
774 while ( sobj && sobj->Depth() > theMeshDepth )
775 sobj = sobj->GetFather();
777 return sobj ? sobj->GetName().c_str() : "";
782 Used in SMESHGUI::restoreVisualParameters() to avoid
783 Declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
785 bool SMESHGUI_ClippingDlg::AddPlane ( SMESH::TActorList theActorList,
786 SMESH::OrientedPlane* thePlane )
789 double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
790 static double aCoeff = vtkMath::Pi()/180.0;
792 int anOrientation = 0;
793 if ( thePlane->PlaneMode == SMESH::Absolute )
794 anOrientation = thePlane->myAbsoluteOrientation;
795 else if ( thePlane->PlaneMode == SMESH::Relative )
796 anOrientation = thePlane->myRelativeOrientation + 1;
798 if ( anOrientation == 0 ) {
799 // compute a direction for plane in absolute mode
800 double znam = sqrt( thePlane->Dx*thePlane->Dx + thePlane->Dy*thePlane->Dy + thePlane->Dz*thePlane->Dz );
801 double aRotation = acos( thePlane->Dy/znam )/aCoeff;
802 if ( thePlane->Dy >= 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[0] = 90.0 + aRotation;
803 else if ( thePlane->Dy >= 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[0] = 90.0 - aRotation;
804 else if ( thePlane->Dy < 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[0] = aRotation - 90.0;
805 else if ( thePlane->Dy < 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[0] = 270.0 - aRotation;
807 aRotation = acos( thePlane->Dx/znam )/aCoeff;
808 if ( thePlane->Dx >= 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[1] = 90.0 + aRotation;
809 else if ( thePlane->Dx >= 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[1] = 90.0 - aRotation;
810 else if ( thePlane->Dx < 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[1] = aRotation - 90.0;
811 else if ( thePlane->Dx < 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[1] = 270.0 - aRotation;
815 rotationToNormal( thePlane->myAngle, anOrientation, aNormal, aDir );
820 if ( thePlane->PlaneMode == SMESH::Absolute ) {
821 aNormal[0] = thePlane->Dx;
822 aNormal[1] = thePlane->Dy;
823 aNormal[2] = thePlane->Dz;
827 if( theActorList.empty() ) {
828 // to support planes with empty actor list we should create
829 // a nullified plane that will be initialized later
830 anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
831 aBounds[0] = aBounds[2] = aBounds[4] = 0;
832 aBounds[1] = aBounds[3] = aBounds[5] = 0;
836 anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
838 thePlane->myDistance,
844 if ( thePlane->PlaneMode == SMESH::Absolute ) {
845 anOrigin[0] = thePlane->X;
846 anOrigin[1] = thePlane->Y;
847 anOrigin[2] = thePlane->Z;
849 thePlane->SetNormal( aNormal );
850 thePlane->SetOrigin( anOrigin );
853 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
854 ( aBounds[2] + aBounds[3] ) / 2.,
855 ( aBounds[4] + aBounds[5] ) / 2. };
857 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
858 pow( aBounds[3] - aBounds[2], 2 ) +
859 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
861 double aDelta[2][3] = { { aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel },
862 { aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel } };
863 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
865 double aPnt01[3] = { aPnt[0] - aDelta[0][0] - aDelta[1][0],
866 aPnt[1] - aDelta[0][1] - aDelta[1][1],
867 aPnt[2] - aDelta[0][2] - aDelta[1][2] };
868 double aPnt02[3] = { aPnt01[0] + aNormal[0],
869 aPnt01[1] + aNormal[1],
870 aPnt01[2] + aNormal[2] };
871 vtkPlane::IntersectWithLine( aPnt01, aPnt02, aNormal, anOrigin, aParam, aPnt0 );
873 double aPnt11[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 aPnt12[3] = { aPnt11[0] + aNormal[0],
877 aPnt11[1] + aNormal[1],
878 aPnt11[2] + aNormal[2] };
879 vtkPlane::IntersectWithLine( aPnt11, aPnt12, aNormal, anOrigin, aParam, aPnt1);
881 double aPnt21[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 aPnt22[3] = { aPnt21[0] + aNormal[0],
885 aPnt21[1] + aNormal[1],
886 aPnt21[2] + aNormal[2] };
887 vtkPlane::IntersectWithLine( aPnt21, aPnt22, aNormal, anOrigin, aParam, aPnt2);
889 vtkPlaneSource* aPlaneSource = thePlane->myPlaneSource;
890 aPlaneSource->SetNormal( aNormal[0], aNormal[1], aNormal[2] );
891 aPlaneSource->SetOrigin( aPnt0[0], aPnt0[1], aPnt0[2] );
892 aPlaneSource->SetPoint1( aPnt1[0], aPnt1[1], aPnt1[2] );
893 aPlaneSource->SetPoint2( aPnt2[0], aPnt2[1], aPnt2[2] );
894 aPlaneSource->Update();
896 SMESH::TActorList::iterator anIter = theActorList.begin();
897 for ( ; anIter != theActorList.end(); anIter++ )
898 if( vtkActor* aVTKActor = *anIter )
899 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
900 if( thePlane->IsOpenGLClipping )
901 anActor->AddOpenGLClippingPlane( thePlane->InvertPlane() );
903 anActor->AddClippingPlane( thePlane );
910 Custom handling of events
912 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
914 QDialog::keyPressEvent( e );
915 if ( e->isAccepted() )
918 if ( e->key() == Qt::Key_F1 ) {
925 Handles the char preview widget activation event
927 void SMESHGUI_ClippingDlg::ProcessEvents( vtkObject* theObject,
928 unsigned long theEvent,
930 void* vtkNotUsed( theCallData ) )
932 vtkImplicitPlaneWidget* aWidget = vtkImplicitPlaneWidget::SafeDownCast( theObject );
933 if ( aWidget == NULL ) return;
934 if ( theClientData == NULL ) return;
936 SMESHGUI_ClippingDlg* aDlg = (SMESHGUI_ClippingDlg*) theClientData;
942 case vtkCommand::InteractionEvent:
943 aWidget->GetOrigin( anOrigin );
944 aWidget->GetNormal( aDir );
946 aDlg->myIsSelectPlane = true;
948 if( aDlg->CurrentMode == SMESH::Absolute ) {
949 aDlg->setOrigin( anOrigin );
950 aDlg->setDirection( aDir );
951 aDlg->myIsPreviewMoved = true;
953 else if( aDlg->CurrentMode == SMESH::Relative ) {
954 aDlg->absolutePlaneToRelative( anOrigin, aDir );
956 aDlg->myIsSelectPlane = false;
958 aDlg->SetCurrentPlaneParam();
959 aDlg->myIsPreviewMoved = false;
965 Initialize the planes's data when the dialog opened
967 void SMESHGUI_ClippingDlg::initializePlaneData()
969 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
970 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
971 if( anIter1 != aClippingPlaneInfoMap.end() ) {
972 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
973 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
974 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
975 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
976 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
977 anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
978 SMESH::TPlane aTPlane( anOrientedPlane );
979 SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
980 myPlanes.push_back( aPlaneData );
983 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
984 if( myPlanes.size() )
985 myPreviewWidget->SetEnabled( PreviewCheckBox->isChecked() );
989 Initialization of initial values of widgets
991 void SMESHGUI_ClippingDlg::initParam()
993 SpinBox_X->setValue( 0.0 );
994 SpinBox_Y->setValue( 0.0 );
995 SpinBox_Z->setValue( 0.0 );
997 SpinBox_Dx->setValue( 1.0 );
998 SpinBox_Dy->setValue( 1.0 );
999 SpinBox_Dz->setValue( 1.0 );
1001 CBAbsoluteOrientation->setCurrentIndex(0);
1003 SpinSliderDistance->setValue( 0.5 );
1004 SpinSliderRotation1->setValue( 0 );
1005 SpinSliderRotation2->setValue( 0 );
1006 CBRelativeOrientation->setCurrentIndex( 0 );
1010 Synchronize dialog's widgets with data
1012 void SMESHGUI_ClippingDlg::synchronize()
1014 int aNbPlanes = myPlanes.size();
1015 ComboBoxPlanes->clear();
1018 for( int i = 1; i<=aNbPlanes; i++ ) {
1019 aName = QString( tr( "PLANE_NUM" ) ).arg(i);
1020 ComboBoxPlanes->addItem( aName );
1023 int aPos = ComboBoxPlanes->count() - 1;
1024 ComboBoxPlanes->setCurrentIndex( aPos );
1026 bool anIsControlsEnable = ( aPos >= 0 );
1027 if ( anIsControlsEnable ) {
1028 onSelectPlane( aPos );
1030 if( PreviewCheckBox->isChecked() )
1031 myPreviewWidget->On();
1034 ComboBoxPlanes->addItem( tr( "NO_PLANES" ) );
1037 if( PreviewCheckBox->isChecked() )
1038 myPreviewWidget->Off();
1041 isOpenGLClipping->setEnabled( anIsControlsEnable );
1042 ActorList->setEnabled( anIsControlsEnable );
1043 SelectAllCheckBox->setEnabled( anIsControlsEnable );
1044 buttonDelete->setEnabled( anIsControlsEnable );
1045 if ( CurrentMode == SMESH::Absolute ) {
1046 SpinBox_X->setEnabled( anIsControlsEnable );
1047 SpinBox_Y->setEnabled( anIsControlsEnable );
1048 SpinBox_Z->setEnabled( anIsControlsEnable );
1049 SpinBox_Dx->setEnabled( anIsControlsEnable );
1050 SpinBox_Dy->setEnabled( anIsControlsEnable );
1051 SpinBox_Dz->setEnabled( anIsControlsEnable );
1052 CBAbsoluteOrientation->setEnabled( anIsControlsEnable );
1053 invertButton->setEnabled( anIsControlsEnable );
1054 resetButton->setEnabled( anIsControlsEnable );
1056 else if ( CurrentMode == SMESH::Relative ) {
1057 CBRelativeOrientation->setEnabled( anIsControlsEnable );
1058 SpinSliderDistance->setEnabled( anIsControlsEnable );
1059 SpinSliderRotation1->setEnabled( anIsControlsEnable );
1060 SpinSliderRotation2->setEnabled( anIsControlsEnable );
1065 Update the list of actors
1067 void SMESHGUI_ClippingDlg::updateActorList()
1071 _PTR(Study) aStudy = SMESH::getStudy();
1078 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1079 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1080 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1082 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1083 aPlaneData.Plane.GetPointer()->myActor->SetVisibility( false );
1085 std::map< std::string, QListWidgetItem* > itemMap; // used to sort items by entry
1087 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1088 vtkActorCollection* anAllActors = aCopy.GetActors();
1089 anAllActors->InitTraversal();
1090 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1091 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1092 if( anActor->hasIO() ) {
1093 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1094 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1095 bool anIsChecked = false;
1096 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1097 for ( ; anIter != anActorList.end(); anIter++ ) {
1098 if( vtkActor* aVTKActorRef = *anIter ) {
1099 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1100 if( anActorRef == anActor ) {
1107 QString aName = QString( aSObj->GetName().c_str() );
1108 QString aFatherName = getFatherName( aSObj );
1109 if ( !aFatherName.isEmpty() )
1110 aName = aFatherName + " / " + aName;
1111 aName += QString(" (%1)").arg( aSObj->GetID().c_str() );
1112 QListWidgetItem* anItem = new ActorItem( anActor, aName, 0 );
1113 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1114 itemMap.insert( std::make_pair( aSObj->GetID(), anItem ));
1119 std::map< std::string, QListWidgetItem* >::iterator s2i = itemMap.begin();
1120 for ( ; s2i != itemMap.end(); ++s2i )
1122 QListWidgetItem* anItem = s2i->second;
1123 ActorList->addItem( anItem );
1125 updateActorItem( 0, true, false );
1129 Update an actor in actor's list
1131 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
1132 bool theUpdateSelectAll,
1133 bool theUpdateClippingPlaneMap )
1135 // update Select All check box
1136 if( theUpdateSelectAll ) {
1137 int aNbItems = ActorList->count(), aNbChecked = 0;
1138 for( int i = 0; i < aNbItems; i++ )
1139 if( QListWidgetItem* anItem = ActorList->item( i ) )
1140 if( anItem->checkState() == Qt::Checked )
1143 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
1144 SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
1145 SelectAllCheckBox->blockSignals( anIsBlocked );
1148 // update clipping plane map
1149 if( theUpdateClippingPlaneMap ) {
1150 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1151 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
1152 if( SMESH_Actor* anActor = anItem->getActor() ) {
1153 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1154 SMESH::TActorList& anActorList = aPlaneData.ActorList;
1155 bool anIsPushed = false;
1156 SMESH::TActorList::iterator anIter = anActorList.begin();
1157 for ( ; anIter != anActorList.end(); anIter++ ) {
1158 if( anActor == *anIter ) {
1163 if( theItem->checkState() == Qt::Checked && !anIsPushed )
1164 anActorList.push_back( anActor );
1165 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
1166 anActorList.remove( anActor );
1168 if( SMESH::ComputeBounds( anActorList, myBounds ) ) {
1169 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1170 myBounds[3], myBounds[4], myBounds[5] );
1171 if( PreviewCheckBox->isChecked() )
1172 myPreviewWidget->On();
1175 myPreviewWidget->Off();
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, aVisibleActorList;
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 ) )
1273 anActorList.push_back( anActor );
1274 if ( anActor->GetVisibility() )
1275 aVisibleActorList.push_back( anActor );
1277 SMESH::TPlaneData aPlaneData(aTPlane,
1278 aVisibleActorList.empty() ? anActorList : aVisibleActorList);
1279 myPlanes.push_back(aPlaneData);
1282 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1283 aPlane->myActor->SetVisibility( false );
1285 bool anIsBlocked = ActorList->blockSignals( true );
1287 if( SMESH::ComputeBounds( anActorList, myBounds ) ) {
1288 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1289 myBounds[3], myBounds[4], myBounds[5] );
1290 if( PreviewCheckBox->isChecked() )
1291 myPreviewWidget->On();
1294 myPreviewWidget->Off();
1297 SetCurrentPlaneParam();
1299 ActorList->blockSignals( anIsBlocked );
1304 SLOT on delete button click: Delete selected clipping plane
1306 void SMESHGUI_ClippingDlg::ClickOnDelete()
1308 if (myPlanes.empty())
1311 int aPlaneIndex = ComboBoxPlanes->currentIndex();
1313 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
1314 SMESH::TPlaneData aPlaneData = *anIter;
1315 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
1316 myPlanes.erase(anIter);
1318 if(AutoApplyCheckBox->isChecked())
1322 SMESH::RenderViewWindow( myViewWindow );
1326 Set current parameters of selected plane
1328 void SMESHGUI_ClippingDlg::onSelectPlane ( int theIndex )
1330 if ( myPlanes.empty() )
1333 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
1334 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1336 myIsSelectPlane = true;
1337 isOpenGLClipping->setChecked( aPlane->IsOpenGLClipping );
1339 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1340 ModeStackedLayout->setCurrentIndex( 0 );
1341 CurrentMode = SMESH::Absolute;
1342 int anOrientation = aPlane->myAbsoluteOrientation;
1343 // Set plane parameters in the dialog
1344 double anOrigin[3], aDir[3];
1345 anOrigin[0] = aPlane->X;
1346 anOrigin[1] = aPlane->Y;
1347 anOrigin[2] = aPlane->Z;
1348 setOrigin( anOrigin );
1349 aDir[0] = aPlane->Dx;
1350 aDir[1] = aPlane->Dy;
1351 aDir[2] = aPlane->Dz;
1352 setDirection( aDir );
1353 CBAbsoluteOrientation->setCurrentIndex( anOrientation );
1354 onSelectAbsoluteOrientation( anOrientation );
1356 else if ( aPlane->PlaneMode == SMESH::Relative ) {
1357 ModeStackedLayout->setCurrentIndex( 1 );
1358 CurrentMode = SMESH::Relative;
1359 SMESH::Orientation anOrientation = aPlane->GetOrientation();
1360 double aRot[2] = { aPlane->myAngle[0], aPlane->myAngle[1] };
1361 // Set plane parameters in the dialog
1362 setDistance( aPlane->GetDistance() );
1363 setRotation( aRot[0], aRot[1] );
1364 switch ( anOrientation ) {
1366 CBRelativeOrientation->setCurrentIndex(0);
1367 onSelectRelativeOrientation(0);
1370 CBRelativeOrientation->setCurrentIndex(1);
1371 onSelectRelativeOrientation(1);
1374 CBRelativeOrientation->setCurrentIndex(2);
1375 onSelectRelativeOrientation(2);
1379 myIsSelectPlane = false;
1381 if( SMESH::ComputeBounds( aPlaneData.ActorList, myBounds ) ) {
1382 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1383 myBounds[3], myBounds[4], myBounds[5] );
1384 if( PreviewCheckBox->isChecked() )
1385 myPreviewWidget->On();
1388 myPreviewWidget->Off();
1390 SetCurrentPlaneParam();
1393 bool anIsBlocked = ActorList->blockSignals( true );
1395 ActorList->blockSignals( anIsBlocked );
1399 SLOT: called on OpenGLClipping check box toggled
1401 void SMESHGUI_ClippingDlg::onIsOpenGLClipping( bool toggled )
1403 if ( myPlanes.empty() || myIsSelectPlane )
1406 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1407 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1408 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1409 aPlaneData->IsOpenGLClipping = toggled;
1411 if( AutoApplyCheckBox->isChecked() )
1416 SLOT: called on SelectAll check box toggled
1418 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
1420 if( theState == Qt::PartiallyChecked ) {
1421 SelectAllCheckBox->setCheckState( Qt::Checked );
1425 bool anIsBlocked = ActorList->blockSignals( true );
1426 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
1427 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
1428 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
1429 updateActorItem( anItem, false, true );
1432 SelectAllCheckBox->setTristate( false );
1433 ActorList->blockSignals( anIsBlocked );
1434 SetCurrentPlaneParam();
1438 SLOT: called when actor item was changed
1440 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
1442 updateActorItem( theItem, true, true );
1443 SetCurrentPlaneParam();
1447 Restore parameters of selected plane
1449 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
1451 if ( myPlanes.empty() || myIsSelectPlane )
1454 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1456 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1457 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1459 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1460 aPlane->myAbsoluteOrientation = CBAbsoluteOrientation->currentIndex();
1461 aPlane->X = SpinBox_X->value();
1462 aPlane->Y = SpinBox_Y->value();
1463 aPlane->Z = SpinBox_Z->value();
1464 aPlane->Dx = SpinBox_Dx->value();
1465 aPlane->Dy = SpinBox_Dy->value();
1466 aPlane->Dz = SpinBox_Dz->value();
1470 double aDir[2][3] = { {0, 0, 0}, {0, 0, 0} };
1471 static double aCoeff = vtkMath::Pi()/180.0;
1473 double aRot[2] = { getRotation1(), getRotation2() };
1475 if ( aPlane->PlaneMode == SMESH::Absolute )
1476 anOrient = CBAbsoluteOrientation->currentIndex();
1477 else if ( aPlane->PlaneMode == SMESH::Relative )
1478 anOrient = CBRelativeOrientation->currentIndex() + 1;
1480 if ( aPlane->PlaneMode == SMESH::Relative ) {
1481 aPlane->myAngle[0] = aRot[0];
1482 aPlane->myAngle[1] = aRot[1];
1483 aPlane->SetOrientation( SMESH::Orientation( CBRelativeOrientation->currentIndex() ) );
1484 aPlane->SetDistance( getDistance() );
1487 if ( anOrient == 0 ) {
1488 // compute a direction for plane in absolute mode
1489 double znam = sqrt( aPlane->Dx*aPlane->Dx + aPlane->Dy*aPlane->Dy + aPlane->Dz*aPlane->Dz );
1490 double aRotation = acos( aPlane->Dy/znam )/aCoeff;
1491 if ( aPlane->Dy >= 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = 90.0 + aRotation;
1492 else if ( aPlane->Dy >= 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 90.0 - aRotation;
1493 else if ( aPlane->Dy < 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = aRotation - 90.0;
1494 else if ( aPlane->Dy < 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 270.0 - aRotation;
1496 aRotation = acos( aPlane->Dx/znam )/aCoeff;
1497 if ( aPlane->Dx >= 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = 90.0 + aRotation;
1498 else if ( aPlane->Dx >= 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 90.0 - aRotation;
1499 else if ( aPlane->Dx < 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = aRotation - 90.0;
1500 else if ( aPlane->Dx < 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 270.0 - aRotation;
1504 rotationToNormal( aRot, anOrient, aNormal, aDir );
1507 SMESH::TActorList anActorList = aPlaneData.ActorList;
1512 aDistance = getDistance();
1513 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1514 aNormal[0] = aPlane->Dx;
1515 aNormal[1] = aPlane->Dy;
1516 aNormal[2] = aPlane->Dz;
1519 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
1525 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1526 anOrigin[0] = aPlane->X;
1527 anOrigin[1] = aPlane->Y;
1528 anOrigin[2] = aPlane->Z;
1532 aPlane->SetNormal( aNormal );
1533 aPlane->SetOrigin( anOrigin );
1535 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
1536 ( aBounds[2] + aBounds[3] ) / 2.,
1537 ( aBounds[4] + aBounds[5] ) / 2. };
1539 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
1540 pow( aBounds[3] - aBounds[2], 2 ) +
1541 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
1543 double aDelta[2][3] = { { aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel },
1544 { aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel } };
1545 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
1547 double aPnt01[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 aPnt02[3] = { aPnt01[0] + aNormal[0],
1551 aPnt01[1] + aNormal[1],
1552 aPnt01[2] + aNormal[2] };
1553 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
1555 double aPnt11[3] = { aPnt[0] - aDelta[0][0] + aDelta[1][0],
1556 aPnt[1] - aDelta[0][1] + aDelta[1][1],
1557 aPnt[2] - aDelta[0][2] + aDelta[1][2] };
1558 double aPnt12[3] = { aPnt11[0] + aNormal[0],
1559 aPnt11[1] + aNormal[1],
1560 aPnt11[2] + aNormal[2] };
1561 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1563 double aPnt21[3] = { aPnt[0] + aDelta[0][0] - aDelta[1][0],
1564 aPnt[1] + aDelta[0][1] - aDelta[1][1],
1565 aPnt[2] + aDelta[0][2] - aDelta[1][2] };
1566 double aPnt22[3] = { aPnt21[0] + aNormal[0],
1567 aPnt21[1] + aNormal[1],
1568 aPnt21[2] + aNormal[2] };
1569 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1571 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1573 aPlaneSource->SetNormal( aNormal[0], aNormal[1], aNormal[2] );
1574 aPlaneSource->SetOrigin( aPnt0[0], aPnt0[1], aPnt0[2] );
1575 aPlaneSource->SetPoint1( aPnt1[0], aPnt1[1], aPnt1[2] );
1576 aPlaneSource->SetPoint2( aPnt2[0], aPnt2[1], aPnt2[2] );
1577 aPlaneSource->Update();
1580 setBoundsForPreviewWidget();
1582 myPreviewWidget->SetOrigin( anOrigin );
1583 myPreviewWidget->SetNormal( aNormal );
1585 if(AutoApplyCheckBox->isChecked())
1588 SMESH::RenderViewWindow( myViewWindow );
1592 Set current bounds for preview widget
1594 void SMESHGUI_ClippingDlg::setBoundsForPreviewWidget()
1596 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1597 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1598 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1599 SMESH::TActorList anActorList = aPlaneData.ActorList;
1601 double* anOrigin = aPlane->GetOrigin();
1604 SMESH::ComputeBounds( anActorList, aBounds );
1606 bool isBoundsChanged = false;
1608 if( myIsPreviewMoved ) {
1609 // if widget has moved by hand the bounds can to minimize
1610 if( anOrigin[0] > myBounds[0] && anOrigin[0] < aBounds[0] ) {
1611 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1612 if( anOrigin[0] < myBounds[1] && anOrigin[0] > aBounds[1] ) {
1613 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1614 if( anOrigin[1] > myBounds[2] && anOrigin[1] < aBounds[2] ) {
1615 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1616 if( anOrigin[1] < myBounds[3] && anOrigin[1] > aBounds[3] ) {
1617 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1618 if( anOrigin[2] > myBounds[4] && anOrigin[2] < aBounds[4] ) {
1619 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1620 if( anOrigin[2] < myBounds[5] && anOrigin[2] > aBounds[5] ) {
1621 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1624 // if widget has moved by dialog data the bounds can to take necessary size
1625 if( anOrigin[0] < aBounds[0] ) {
1626 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1627 if( anOrigin[0] > aBounds[1] ) {
1628 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1629 if( anOrigin[1] < aBounds[2] ) {
1630 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1631 if( anOrigin[1] > aBounds[3] ) {
1632 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1633 if( anOrigin[2] < aBounds[4] ) {
1634 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1635 if( anOrigin[2] > aBounds[5] ) {
1636 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1639 if( isBoundsChanged )
1640 myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2],
1641 myBounds[3],myBounds[4],myBounds[5] );
1642 else if( !myIsPreviewMoved )
1643 myPreviewWidget->PlaceWidget( aBounds[0],aBounds[1],aBounds[2],
1644 aBounds[3],aBounds[4],aBounds[5] );
1649 Convert absolute coordinates of plane to relative mode
1651 void SMESHGUI_ClippingDlg::absolutePlaneToRelative ( double theOrigin[3], double theDir[3] )
1655 aRot[0] = getRotation1();
1656 aRot[1] = getRotation2();
1658 double eps = 0.0001;
1660 int anOrientation = CBRelativeOrientation->currentIndex();
1661 double aDirection[3] = { 0.,0.,0. };
1662 double aRotation1 = 0, aRotation2 = 0;
1663 switch( anOrientation ) {
1665 aDirection[0] = theDir[0] + eps;
1666 aDirection[1] = theDir[1] + eps;
1667 aDirection[2] = theDir[2] + eps;
1668 aRotation1 = atan2( theDir[2], theDir[1] )*180.0/M_PI;
1669 aRotation2 = atan2( theDir[2], theDir[0] )*180.0/M_PI;
1672 aDirection[0] = theDir[1] + eps;
1673 aDirection[1] = theDir[2] + eps;
1674 aDirection[2] = theDir[0] + eps;
1675 aRotation1 = atan2( theDir[0], theDir[2] )*180.0/M_PI;
1676 aRotation2 = atan2( theDir[0], theDir[1] )*180.0/M_PI;
1679 aDirection[0] = theDir[2] + eps;
1680 aDirection[1] = theDir[0] + eps;
1681 aDirection[2] = theDir[1] + eps;
1682 aRotation1 = atan2( theDir[1], theDir[0] )*180.0/M_PI;
1683 aRotation2 = atan2( theDir[1], theDir[2] )*180.0/M_PI;
1687 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 + 90.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 - 90.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 + 90.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 - 90.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; }
1703 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1704 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1705 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1706 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 270.0; }
1707 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1708 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 + 90.0; }
1709 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1710 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
1711 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1712 aRot[0] = aRotation1 - 270.0; aRot[1] = aRotation2 - 270.0; }
1713 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1714 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1715 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1716 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
1717 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1718 aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
1720 SpinSliderRotation1->setValue( qRound( aRot[0] ) );
1721 SpinSliderRotation2->setValue( qRound( aRot[1] ) );
1723 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1724 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1725 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1729 SMESH::ComputeBounds( anActorList, aBounds );
1730 SMESH::PositionToDistance( aBounds, theDir, theOrigin, aDist );
1731 aDist = 1.0 - aDist;
1734 else if( aDist < 0.0 )
1737 SpinSliderDistance->setValue( qRound( aDist*100 ) );
1742 SLOT: called on preview check box toggled
1744 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1746 std::for_each( myPlanes.begin(), myPlanes.end(), TSetVisibility( theIsToggled ) );
1747 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1748 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1749 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1750 aPlaneData->myActor->SetVisibility( false );
1752 myPreviewWidget->On();
1754 myPreviewWidget->Off();
1755 SMESH::RenderViewWindow( myViewWindow );
1759 SLOT: called on Auto Apply check box toggled
1761 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1763 if ( toggled ) ClickOnApply();
1767 SLOT on ok button click: sets cutting plane and closes dialog
1769 void SMESHGUI_ClippingDlg::ClickOnOk()
1777 SLOT on Apply button click: sets cutting plane and update viewer
1779 void SMESHGUI_ClippingDlg::ClickOnApply()
1782 SUIT_OverrideCursor wc;
1784 QWidget *aCurrWid = this->focusWidget();
1785 aCurrWid->clearFocus();
1786 aCurrWid->setFocus();
1788 SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1789 SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
1791 // clean memory allocated for planes
1792 SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
1793 for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
1794 if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
1797 aClippingPlaneInfoList.clear();
1799 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1800 vtkActorCollection* anAllActors = aCopy.GetActors();
1801 anAllActors->InitTraversal();
1802 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1803 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1804 anActor->RemoveAllClippingPlanes();
1806 SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
1807 for( ; anIter2 != myPlanes.end(); anIter2++ ) {
1808 SMESH::TPlaneData aPlaneData = *anIter2;
1809 SMESH::TPlane aPlane = aPlaneData.Plane;
1810 SMESH::TActorList anActorList = aPlaneData.ActorList;
1812 // the check is disabled to support planes with empty actor list
1813 //if( anActorList.empty() )
1816 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1817 anOrientedPlane->ShallowCopy(aPlane.GetPointer());
1818 SMESH::TActorList::iterator anIter3 = anActorList.begin();
1819 for( ; anIter3 != anActorList.end(); anIter3++ )
1820 if( vtkActor* aVTKActor = *anIter3 )
1821 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1822 if( anOrientedPlane->IsOpenGLClipping )
1823 anActor->AddOpenGLClippingPlane( anOrientedPlane->InvertPlane() );
1825 anActor->AddClippingPlane( anOrientedPlane );
1828 SMESH::ClippingPlaneInfo aClippingPlaneInfo;
1829 aClippingPlaneInfo.Plane = anOrientedPlane;
1830 aClippingPlaneInfo.ActorList = anActorList;
1832 aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
1835 anAllActors->InitTraversal();
1836 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1837 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1838 anActor->SetOpenGLClippingPlane();
1841 SMESH::RenderViewWindow( myViewWindow );
1846 SLOT on help button click: opens a help page
1848 void SMESHGUI_ClippingDlg::ClickOnHelp()
1850 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1852 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1856 platform = "winapplication";
1858 platform = "application";
1860 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1861 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1862 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1864 arg(myHelpFileName));
1868 void SMESHGUI_ClippingDlg::onSelectAbsoluteOrientation( int mode )
1870 bool isUserMode = (mode==0);
1872 TextLabelX->setEnabled( isUserMode );
1873 TextLabelY->setEnabled( isUserMode );
1874 TextLabelZ->setEnabled( isUserMode );
1876 SpinBox_X->setEnabled( isUserMode );
1877 SpinBox_Y->setEnabled( isUserMode );
1878 SpinBox_Z->setEnabled( isUserMode );
1880 TextLabelDx->setEnabled( isUserMode );
1881 TextLabelDy->setEnabled( isUserMode );
1882 TextLabelDz->setEnabled( isUserMode );
1884 SpinBox_Dx->setEnabled( isUserMode );
1885 SpinBox_Dy->setEnabled( isUserMode );
1886 SpinBox_Dz->setEnabled( isUserMode );
1891 double aDx = 0, aDy = 0, aDz = 0;
1896 TextLabelZ->setEnabled( true );
1897 SpinBox_Z->setEnabled( true );
1898 SpinBox_Z->setFocus();
1900 else if ( mode == 2 )
1903 TextLabelX->setEnabled( true );
1904 SpinBox_X->setEnabled( true );
1905 SpinBox_X->setFocus();
1907 else if ( mode == 3 )
1910 TextLabelY->setEnabled( true );
1911 SpinBox_Y->setEnabled( true );
1912 SpinBox_Y->setFocus();
1915 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1916 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1917 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1919 if ( aPlaneData->IsInvert == true ) {
1920 aDx = -aDx; aDy = -aDy; aDz = -aDz;
1923 myIsSelectPlane = true;
1924 SpinBox_Dx->setValue( aDx );
1925 SpinBox_Dy->setValue( aDy );
1926 SpinBox_Dz->setValue( aDz );
1927 myIsSelectPlane = false;
1929 SetCurrentPlaneParam();
1933 SLOT: called on orientation of clipping plane in relative mode changed
1935 void SMESHGUI_ClippingDlg::onSelectRelativeOrientation ( int theItem )
1937 if ( myPlanes.empty() )
1940 if ( theItem == 0 ) {
1941 TextLabelRotation1->setText( tr( "ROTATION_AROUND_X_Y2Z" ) );
1942 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Y_X2Z" ) );
1944 else if ( theItem == 1 ) {
1945 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Y_Z2X" ) );
1946 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Z_Y2X" ) );
1948 else if ( theItem == 2 ) {
1949 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Z_X2Y" ) );
1950 TextLabelRotation2->setText( tr( "ROTATION_AROUND_X_Z2Y" ) );
1953 if( (QComboBox*)sender() == CBRelativeOrientation )
1954 SetCurrentPlaneParam();
1958 SLOT on reset button click: sets default values
1960 void SMESHGUI_ClippingDlg::onReset()
1962 myIsSelectPlane = true;
1963 SpinBox_X->setValue(0);
1964 SpinBox_Y->setValue(0);
1965 SpinBox_Z->setValue(0);
1966 myIsSelectPlane = false;
1968 SetCurrentPlaneParam();
1972 SLOT on invert button click: inverts normal of cutting plane
1974 void SMESHGUI_ClippingDlg::onInvert()
1976 double Dx = SpinBox_Dx->value();
1977 double Dy = SpinBox_Dy->value();
1978 double Dz = SpinBox_Dz->value();
1980 myIsSelectPlane = true;
1981 SpinBox_Dx->setValue( -Dx );
1982 SpinBox_Dy->setValue( -Dy );
1983 SpinBox_Dz->setValue( -Dz );
1984 myIsSelectPlane = false;
1986 if ( !myPlanes.empty() ) {
1987 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1988 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1989 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1990 aPlaneData->IsInvert = !aPlaneData->IsInvert;
1992 SetCurrentPlaneParam();