1 // Copyright (C) 2007-2016 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_page.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 SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1075 _PTR(Study) aStudy = anAppStudy->studyDS();
1082 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1083 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1084 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1086 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1087 aPlaneData.Plane.GetPointer()->myActor->SetVisibility( false );
1089 std::map< std::string, QListWidgetItem* > itemMap; // used to sort items by entry
1091 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1092 vtkActorCollection* anAllActors = aCopy.GetActors();
1093 anAllActors->InitTraversal();
1094 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1095 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1096 if( anActor->hasIO() ) {
1097 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1098 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1099 bool anIsChecked = false;
1100 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1101 for ( ; anIter != anActorList.end(); anIter++ ) {
1102 if( vtkActor* aVTKActorRef = *anIter ) {
1103 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1104 if( anActorRef == anActor ) {
1111 QString aName = QString( aSObj->GetName().c_str() );
1112 QString aFatherName = getFatherName( aSObj );
1113 if ( !aFatherName.isEmpty() )
1114 aName = aFatherName + " / " + aName;
1115 aName += QString(" (%1)").arg( aSObj->GetID().c_str() );
1116 QListWidgetItem* anItem = new ActorItem( anActor, aName, 0 );
1117 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1118 itemMap.insert( std::make_pair( aSObj->GetID(), anItem ));
1123 std::map< std::string, QListWidgetItem* >::iterator s2i = itemMap.begin();
1124 for ( ; s2i != itemMap.end(); ++s2i )
1126 QListWidgetItem* anItem = s2i->second;
1127 ActorList->addItem( anItem );
1129 updateActorItem( 0, true, false );
1133 Update an actor in actor's list
1135 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
1136 bool theUpdateSelectAll,
1137 bool theUpdateClippingPlaneMap )
1139 // update Select All check box
1140 if( theUpdateSelectAll ) {
1141 int aNbItems = ActorList->count(), aNbChecked = 0;
1142 for( int i = 0; i < aNbItems; i++ )
1143 if( QListWidgetItem* anItem = ActorList->item( i ) )
1144 if( anItem->checkState() == Qt::Checked )
1147 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
1148 SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
1149 SelectAllCheckBox->blockSignals( anIsBlocked );
1152 // update clipping plane map
1153 if( theUpdateClippingPlaneMap ) {
1154 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1155 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
1156 if( SMESH_Actor* anActor = anItem->getActor() ) {
1157 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1158 SMESH::TActorList& anActorList = aPlaneData.ActorList;
1159 bool anIsPushed = false;
1160 SMESH::TActorList::iterator anIter = anActorList.begin();
1161 for ( ; anIter != anActorList.end(); anIter++ ) {
1162 if( anActor == *anIter ) {
1167 if( theItem->checkState() == Qt::Checked && !anIsPushed )
1168 anActorList.push_back( anActor );
1169 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
1170 anActorList.remove( anActor );
1172 if( SMESH::ComputeBounds( anActorList, myBounds ) ) {
1173 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1174 myBounds[3], myBounds[4], myBounds[5] );
1175 if( PreviewCheckBox->isChecked() )
1176 myPreviewWidget->On();
1179 myPreviewWidget->Off();
1186 Get the list of current actors
1188 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1190 SMESH::TActorList anActorList;
1191 for( int i = 0, n = ActorList->count(); i < n; i++ )
1192 if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1193 if( anItem->checkState() == Qt::Checked )
1194 if( SMESH_Actor* anActor = anItem->getActor() )
1195 anActorList.push_back( anActor );
1200 Dump the parameters of clipping planes
1202 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1204 printf( "----------- Plane Data -----------\n" );
1206 SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1207 for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1208 SMESH::TPlaneData aPlaneData = *anIter1;
1209 SMESH::TPlane aPlane = aPlaneData.Plane;
1210 double* aNormal = aPlane->GetNormal();
1211 double* anOrigin = aPlane->GetOrigin();
1212 printf( "Plane N%d:\n", anId );
1213 printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1214 printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1216 SMESH::TActorList anActorList = aPlaneData.ActorList;
1217 SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1218 for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1219 if( vtkActor* aVTKActor = *anIter2 ) {
1220 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1221 printf( " - Actor: '%s'\n", anActor->getName() );
1224 printf( " - Actor: NULL\n");
1227 printf( "----------------------------------\n" );
1231 SLOT on close button click: rejects dialog
1233 void SMESHGUI_ClippingDlg::reject()
1235 //here we can insert actions to do at close.
1240 Set absolute mode of clipping plane
1242 void SMESHGUI_ClippingDlg::onModeAbsolute()
1244 ModeStackedLayout->setCurrentIndex(0);
1245 CurrentMode = SMESH::Absolute;
1247 SetCurrentPlaneParam();
1251 Set relative mode of clipping plane
1253 void SMESHGUI_ClippingDlg::onModeRelative()
1255 ModeStackedLayout->setCurrentIndex(1);
1256 CurrentMode = SMESH::Relative;
1258 SetCurrentPlaneParam();
1262 SLOT on new button click: create a new clipping plane
1264 void SMESHGUI_ClippingDlg::ClickOnNew()
1267 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
1268 SMESH::TPlane aTPlane(aPlane);
1269 aPlane->PlaneMode = CurrentMode;
1270 SMESH::TActorList anActorList, aVisibleActorList;
1271 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1272 vtkActorCollection* anAllActors = aCopy.GetActors();
1273 anAllActors->InitTraversal();
1274 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1275 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1277 anActorList.push_back( anActor );
1278 if ( anActor->GetVisibility() )
1279 aVisibleActorList.push_back( anActor );
1281 SMESH::TPlaneData aPlaneData(aTPlane,
1282 aVisibleActorList.empty() ? anActorList : aVisibleActorList);
1283 myPlanes.push_back(aPlaneData);
1286 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1287 aPlane->myActor->SetVisibility( false );
1289 bool anIsBlocked = ActorList->blockSignals( true );
1291 if( SMESH::ComputeBounds( anActorList, myBounds ) ) {
1292 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1293 myBounds[3], myBounds[4], myBounds[5] );
1294 if( PreviewCheckBox->isChecked() )
1295 myPreviewWidget->On();
1298 myPreviewWidget->Off();
1301 SetCurrentPlaneParam();
1303 ActorList->blockSignals( anIsBlocked );
1308 SLOT on delete button click: Delete selected clipping plane
1310 void SMESHGUI_ClippingDlg::ClickOnDelete()
1312 if (myPlanes.empty())
1315 int aPlaneIndex = ComboBoxPlanes->currentIndex();
1317 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
1318 SMESH::TPlaneData aPlaneData = *anIter;
1319 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
1320 myPlanes.erase(anIter);
1322 if(AutoApplyCheckBox->isChecked())
1326 SMESH::RenderViewWindow( myViewWindow );
1330 Set current parameters of selected plane
1332 void SMESHGUI_ClippingDlg::onSelectPlane ( int theIndex )
1334 if ( myPlanes.empty() )
1337 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
1338 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1340 myIsSelectPlane = true;
1341 isOpenGLClipping->setChecked( aPlane->IsOpenGLClipping );
1343 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1344 ModeStackedLayout->setCurrentIndex( 0 );
1345 CurrentMode = SMESH::Absolute;
1346 int anOrientation = aPlane->myAbsoluteOrientation;
1347 // Set plane parameters in the dialog
1348 double anOrigin[3], aDir[3];
1349 anOrigin[0] = aPlane->X;
1350 anOrigin[1] = aPlane->Y;
1351 anOrigin[2] = aPlane->Z;
1352 setOrigin( anOrigin );
1353 aDir[0] = aPlane->Dx;
1354 aDir[1] = aPlane->Dy;
1355 aDir[2] = aPlane->Dz;
1356 setDirection( aDir );
1357 CBAbsoluteOrientation->setCurrentIndex( anOrientation );
1358 onSelectAbsoluteOrientation( anOrientation );
1360 else if ( aPlane->PlaneMode == SMESH::Relative ) {
1361 ModeStackedLayout->setCurrentIndex( 1 );
1362 CurrentMode = SMESH::Relative;
1363 SMESH::Orientation anOrientation = aPlane->GetOrientation();
1364 double aRot[2] = { aPlane->myAngle[0], aPlane->myAngle[1] };
1365 // Set plane parameters in the dialog
1366 setDistance( aPlane->GetDistance() );
1367 setRotation( aRot[0], aRot[1] );
1368 switch ( anOrientation ) {
1370 CBRelativeOrientation->setCurrentIndex(0);
1371 onSelectRelativeOrientation(0);
1374 CBRelativeOrientation->setCurrentIndex(1);
1375 onSelectRelativeOrientation(1);
1378 CBRelativeOrientation->setCurrentIndex(2);
1379 onSelectRelativeOrientation(2);
1383 myIsSelectPlane = false;
1385 if( SMESH::ComputeBounds( aPlaneData.ActorList, myBounds ) ) {
1386 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1387 myBounds[3], myBounds[4], myBounds[5] );
1388 if( PreviewCheckBox->isChecked() )
1389 myPreviewWidget->On();
1392 myPreviewWidget->Off();
1394 SetCurrentPlaneParam();
1397 bool anIsBlocked = ActorList->blockSignals( true );
1399 ActorList->blockSignals( anIsBlocked );
1403 SLOT: called on OpenGLClipping check box toggled
1405 void SMESHGUI_ClippingDlg::onIsOpenGLClipping( bool toggled )
1407 if ( myPlanes.empty() || myIsSelectPlane )
1410 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1411 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1412 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1413 aPlaneData->IsOpenGLClipping = toggled;
1415 if( AutoApplyCheckBox->isChecked() )
1420 SLOT: called on SelectAll check box toggled
1422 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
1424 if( theState == Qt::PartiallyChecked ) {
1425 SelectAllCheckBox->setCheckState( Qt::Checked );
1429 bool anIsBlocked = ActorList->blockSignals( true );
1430 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
1431 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
1432 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
1433 updateActorItem( anItem, false, true );
1436 SelectAllCheckBox->setTristate( false );
1437 ActorList->blockSignals( anIsBlocked );
1438 SetCurrentPlaneParam();
1442 SLOT: called when actor item was changed
1444 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
1446 updateActorItem( theItem, true, true );
1447 SetCurrentPlaneParam();
1451 Restore parameters of selected plane
1453 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
1455 if ( myPlanes.empty() || myIsSelectPlane )
1458 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1460 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1461 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1463 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1464 aPlane->myAbsoluteOrientation = CBAbsoluteOrientation->currentIndex();
1465 aPlane->X = SpinBox_X->value();
1466 aPlane->Y = SpinBox_Y->value();
1467 aPlane->Z = SpinBox_Z->value();
1468 aPlane->Dx = SpinBox_Dx->value();
1469 aPlane->Dy = SpinBox_Dy->value();
1470 aPlane->Dz = SpinBox_Dz->value();
1474 double aDir[2][3] = { {0, 0, 0}, {0, 0, 0} };
1475 static double aCoeff = vtkMath::Pi()/180.0;
1477 double aRot[2] = { getRotation1(), getRotation2() };
1479 if ( aPlane->PlaneMode == SMESH::Absolute )
1480 anOrient = CBAbsoluteOrientation->currentIndex();
1481 else if ( aPlane->PlaneMode == SMESH::Relative )
1482 anOrient = CBRelativeOrientation->currentIndex() + 1;
1484 if ( aPlane->PlaneMode == SMESH::Relative ) {
1485 aPlane->myAngle[0] = aRot[0];
1486 aPlane->myAngle[1] = aRot[1];
1487 aPlane->SetOrientation( SMESH::Orientation( CBRelativeOrientation->currentIndex() ) );
1488 aPlane->SetDistance( getDistance() );
1491 if ( anOrient == 0 ) {
1492 // compute a direction for plane in absolute mode
1493 double znam = sqrt( aPlane->Dx*aPlane->Dx + aPlane->Dy*aPlane->Dy + aPlane->Dz*aPlane->Dz );
1494 double aRotation = acos( aPlane->Dy/znam )/aCoeff;
1495 if ( aPlane->Dy >= 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = 90.0 + aRotation;
1496 else if ( aPlane->Dy >= 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 90.0 - aRotation;
1497 else if ( aPlane->Dy < 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = aRotation - 90.0;
1498 else if ( aPlane->Dy < 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 270.0 - aRotation;
1500 aRotation = acos( aPlane->Dx/znam )/aCoeff;
1501 if ( aPlane->Dx >= 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = 90.0 + aRotation;
1502 else if ( aPlane->Dx >= 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 90.0 - aRotation;
1503 else if ( aPlane->Dx < 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = aRotation - 90.0;
1504 else if ( aPlane->Dx < 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 270.0 - aRotation;
1508 rotationToNormal( aRot, anOrient, aNormal, aDir );
1511 SMESH::TActorList anActorList = aPlaneData.ActorList;
1516 aDistance = getDistance();
1517 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1518 aNormal[0] = aPlane->Dx;
1519 aNormal[1] = aPlane->Dy;
1520 aNormal[2] = aPlane->Dz;
1523 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
1529 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1530 anOrigin[0] = aPlane->X;
1531 anOrigin[1] = aPlane->Y;
1532 anOrigin[2] = aPlane->Z;
1536 aPlane->SetNormal( aNormal );
1537 aPlane->SetOrigin( anOrigin );
1539 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
1540 ( aBounds[2] + aBounds[3] ) / 2.,
1541 ( aBounds[4] + aBounds[5] ) / 2. };
1543 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
1544 pow( aBounds[3] - aBounds[2], 2 ) +
1545 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
1547 double aDelta[2][3] = { { aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel },
1548 { aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel } };
1549 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
1551 double aPnt01[3] = { aPnt[0] - aDelta[0][0] - aDelta[1][0],
1552 aPnt[1] - aDelta[0][1] - aDelta[1][1],
1553 aPnt[2] - aDelta[0][2] - aDelta[1][2] };
1554 double aPnt02[3] = { aPnt01[0] + aNormal[0],
1555 aPnt01[1] + aNormal[1],
1556 aPnt01[2] + aNormal[2] };
1557 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
1559 double aPnt11[3] = { aPnt[0] - aDelta[0][0] + aDelta[1][0],
1560 aPnt[1] - aDelta[0][1] + aDelta[1][1],
1561 aPnt[2] - aDelta[0][2] + aDelta[1][2] };
1562 double aPnt12[3] = { aPnt11[0] + aNormal[0],
1563 aPnt11[1] + aNormal[1],
1564 aPnt11[2] + aNormal[2] };
1565 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1567 double aPnt21[3] = { aPnt[0] + aDelta[0][0] - aDelta[1][0],
1568 aPnt[1] + aDelta[0][1] - aDelta[1][1],
1569 aPnt[2] + aDelta[0][2] - aDelta[1][2] };
1570 double aPnt22[3] = { aPnt21[0] + aNormal[0],
1571 aPnt21[1] + aNormal[1],
1572 aPnt21[2] + aNormal[2] };
1573 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1575 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1577 aPlaneSource->SetNormal( aNormal[0], aNormal[1], aNormal[2] );
1578 aPlaneSource->SetOrigin( aPnt0[0], aPnt0[1], aPnt0[2] );
1579 aPlaneSource->SetPoint1( aPnt1[0], aPnt1[1], aPnt1[2] );
1580 aPlaneSource->SetPoint2( aPnt2[0], aPnt2[1], aPnt2[2] );
1581 aPlaneSource->Update();
1584 setBoundsForPreviewWidget();
1586 myPreviewWidget->SetOrigin( anOrigin );
1587 myPreviewWidget->SetNormal( aNormal );
1589 if(AutoApplyCheckBox->isChecked())
1592 SMESH::RenderViewWindow( myViewWindow );
1596 Set current bounds for preview widget
1598 void SMESHGUI_ClippingDlg::setBoundsForPreviewWidget()
1600 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1601 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1602 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1603 SMESH::TActorList anActorList = aPlaneData.ActorList;
1605 double* anOrigin = aPlane->GetOrigin();
1608 SMESH::ComputeBounds( anActorList, aBounds );
1610 bool isBoundsChanged = false;
1612 if( myIsPreviewMoved ) {
1613 // if widget has moved by hand the bounds can to minimize
1614 if( anOrigin[0] > myBounds[0] && anOrigin[0] < aBounds[0] ) {
1615 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1616 if( anOrigin[0] < myBounds[1] && anOrigin[0] > aBounds[1] ) {
1617 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1618 if( anOrigin[1] > myBounds[2] && anOrigin[1] < aBounds[2] ) {
1619 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1620 if( anOrigin[1] < myBounds[3] && anOrigin[1] > aBounds[3] ) {
1621 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1622 if( anOrigin[2] > myBounds[4] && anOrigin[2] < aBounds[4] ) {
1623 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1624 if( anOrigin[2] < myBounds[5] && anOrigin[2] > aBounds[5] ) {
1625 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1628 // if widget has moved by dialog data the bounds can to take necessary size
1629 if( anOrigin[0] < aBounds[0] ) {
1630 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1631 if( anOrigin[0] > aBounds[1] ) {
1632 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1633 if( anOrigin[1] < aBounds[2] ) {
1634 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1635 if( anOrigin[1] > aBounds[3] ) {
1636 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1637 if( anOrigin[2] < aBounds[4] ) {
1638 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1639 if( anOrigin[2] > aBounds[5] ) {
1640 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1643 if( isBoundsChanged )
1644 myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2],
1645 myBounds[3],myBounds[4],myBounds[5] );
1646 else if( !myIsPreviewMoved )
1647 myPreviewWidget->PlaceWidget( aBounds[0],aBounds[1],aBounds[2],
1648 aBounds[3],aBounds[4],aBounds[5] );
1653 Convert absolute coordinates of plane to relative mode
1655 void SMESHGUI_ClippingDlg::absolutePlaneToRelative ( double theOrigin[3], double theDir[3] )
1659 aRot[0] = getRotation1();
1660 aRot[1] = getRotation2();
1662 double eps = 0.0001;
1664 int anOrientation = CBRelativeOrientation->currentIndex();
1665 double aDirection[3] = { 0.,0.,0. };
1666 double aRotation1 = 0, aRotation2 = 0;
1667 switch( anOrientation ) {
1669 aDirection[0] = theDir[0] + eps;
1670 aDirection[1] = theDir[1] + eps;
1671 aDirection[2] = theDir[2] + eps;
1672 aRotation1 = atan2( theDir[2], theDir[1] )*180.0/M_PI;
1673 aRotation2 = atan2( theDir[2], theDir[0] )*180.0/M_PI;
1676 aDirection[0] = theDir[1] + eps;
1677 aDirection[1] = theDir[2] + eps;
1678 aDirection[2] = theDir[0] + eps;
1679 aRotation1 = atan2( theDir[0], theDir[2] )*180.0/M_PI;
1680 aRotation2 = atan2( theDir[0], theDir[1] )*180.0/M_PI;
1683 aDirection[0] = theDir[2] + eps;
1684 aDirection[1] = theDir[0] + eps;
1685 aDirection[2] = theDir[1] + eps;
1686 aRotation1 = atan2( theDir[1], theDir[0] )*180.0/M_PI;
1687 aRotation2 = atan2( theDir[1], theDir[2] )*180.0/M_PI;
1691 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 - 90.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 - 270.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 - 90.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 + 270.0; aRot[1] = aRotation2 + 90.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 - 90.0; aRot[1] = aRotation2 + 90.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 + 270.0; }
1715 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1716 aRot[0] = aRotation1 - 270.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 - 90.0; aRot[1] = aRotation2 - 90.0; }
1719 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1720 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
1721 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1722 aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
1724 SpinSliderRotation1->setValue( qRound( aRot[0] ) );
1725 SpinSliderRotation2->setValue( qRound( aRot[1] ) );
1727 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1728 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1729 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1733 SMESH::ComputeBounds( anActorList, aBounds );
1734 SMESH::PositionToDistance( aBounds, theDir, theOrigin, aDist );
1735 aDist = 1.0 - aDist;
1738 else if( aDist < 0.0 )
1741 SpinSliderDistance->setValue( qRound( aDist*100 ) );
1746 SLOT: called on preview check box toggled
1748 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1750 std::for_each( myPlanes.begin(), myPlanes.end(), TSetVisibility( theIsToggled ) );
1751 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1752 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1753 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1754 aPlaneData->myActor->SetVisibility( false );
1756 myPreviewWidget->On();
1758 myPreviewWidget->Off();
1759 SMESH::RenderViewWindow( myViewWindow );
1763 SLOT: called on Auto Apply check box toggled
1765 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1767 if ( toggled ) ClickOnApply();
1771 SLOT on ok button click: sets cutting plane and closes dialog
1773 void SMESHGUI_ClippingDlg::ClickOnOk()
1781 SLOT on Apply button click: sets cutting plane and update viewer
1783 void SMESHGUI_ClippingDlg::ClickOnApply()
1786 SUIT_OverrideCursor wc;
1788 QWidget *aCurrWid = this->focusWidget();
1789 aCurrWid->clearFocus();
1790 aCurrWid->setFocus();
1792 SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1793 SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
1795 // clean memory allocated for planes
1796 SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
1797 for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
1798 if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
1801 aClippingPlaneInfoList.clear();
1803 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1804 vtkActorCollection* anAllActors = aCopy.GetActors();
1805 anAllActors->InitTraversal();
1806 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1807 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1808 anActor->RemoveAllClippingPlanes();
1810 SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
1811 for( ; anIter2 != myPlanes.end(); anIter2++ ) {
1812 SMESH::TPlaneData aPlaneData = *anIter2;
1813 SMESH::TPlane aPlane = aPlaneData.Plane;
1814 SMESH::TActorList anActorList = aPlaneData.ActorList;
1816 // the check is disabled to support planes with empty actor list
1817 //if( anActorList.empty() )
1820 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1821 anOrientedPlane->ShallowCopy(aPlane.GetPointer());
1822 SMESH::TActorList::iterator anIter3 = anActorList.begin();
1823 for( ; anIter3 != anActorList.end(); anIter3++ )
1824 if( vtkActor* aVTKActor = *anIter3 )
1825 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1826 if( anOrientedPlane->IsOpenGLClipping )
1827 anActor->AddOpenGLClippingPlane( anOrientedPlane->InvertPlane() );
1829 anActor->AddClippingPlane( anOrientedPlane );
1832 SMESH::ClippingPlaneInfo aClippingPlaneInfo;
1833 aClippingPlaneInfo.Plane = anOrientedPlane;
1834 aClippingPlaneInfo.ActorList = anActorList;
1836 aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
1839 anAllActors->InitTraversal();
1840 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1841 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1842 anActor->SetOpenGLClippingPlane();
1845 SMESH::RenderViewWindow( myViewWindow );
1850 SLOT on help button click: opens a help page
1852 void SMESHGUI_ClippingDlg::ClickOnHelp()
1854 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1856 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1860 platform = "winapplication";
1862 platform = "application";
1864 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1865 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1866 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1868 arg(myHelpFileName));
1872 void SMESHGUI_ClippingDlg::onSelectAbsoluteOrientation( int mode )
1874 bool isUserMode = (mode==0);
1876 TextLabelX->setEnabled( isUserMode );
1877 TextLabelY->setEnabled( isUserMode );
1878 TextLabelZ->setEnabled( isUserMode );
1880 SpinBox_X->setEnabled( isUserMode );
1881 SpinBox_Y->setEnabled( isUserMode );
1882 SpinBox_Z->setEnabled( isUserMode );
1884 TextLabelDx->setEnabled( isUserMode );
1885 TextLabelDy->setEnabled( isUserMode );
1886 TextLabelDz->setEnabled( isUserMode );
1888 SpinBox_Dx->setEnabled( isUserMode );
1889 SpinBox_Dy->setEnabled( isUserMode );
1890 SpinBox_Dz->setEnabled( isUserMode );
1895 double aDx = 0, aDy = 0, aDz = 0;
1900 TextLabelZ->setEnabled( true );
1901 SpinBox_Z->setEnabled( true );
1902 SpinBox_Z->setFocus();
1904 else if ( mode == 2 )
1907 TextLabelX->setEnabled( true );
1908 SpinBox_X->setEnabled( true );
1909 SpinBox_X->setFocus();
1911 else if ( mode == 3 )
1914 TextLabelY->setEnabled( true );
1915 SpinBox_Y->setEnabled( true );
1916 SpinBox_Y->setFocus();
1919 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1920 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1921 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1923 if ( aPlaneData->IsInvert == true ) {
1924 aDx = -aDx; aDy = -aDy; aDz = -aDz;
1927 myIsSelectPlane = true;
1928 SpinBox_Dx->setValue( aDx );
1929 SpinBox_Dy->setValue( aDy );
1930 SpinBox_Dz->setValue( aDz );
1931 myIsSelectPlane = false;
1933 SetCurrentPlaneParam();
1937 SLOT: called on orientation of clipping plane in relative mode changed
1939 void SMESHGUI_ClippingDlg::onSelectRelativeOrientation ( int theItem )
1941 if ( myPlanes.empty() )
1944 if ( theItem == 0 ) {
1945 TextLabelRotation1->setText( tr( "ROTATION_AROUND_X_Y2Z" ) );
1946 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Y_X2Z" ) );
1948 else if ( theItem == 1 ) {
1949 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Y_Z2X" ) );
1950 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Z_Y2X" ) );
1952 else if ( theItem == 2 ) {
1953 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Z_X2Y" ) );
1954 TextLabelRotation2->setText( tr( "ROTATION_AROUND_X_Z2Y" ) );
1957 if( (QComboBox*)sender() == CBRelativeOrientation )
1958 SetCurrentPlaneParam();
1962 SLOT on reset button click: sets default values
1964 void SMESHGUI_ClippingDlg::onReset()
1966 myIsSelectPlane = true;
1967 SpinBox_X->setValue(0);
1968 SpinBox_Y->setValue(0);
1969 SpinBox_Z->setValue(0);
1970 myIsSelectPlane = false;
1972 SetCurrentPlaneParam();
1976 SLOT on invert button click: inverts normal of cutting plane
1978 void SMESHGUI_ClippingDlg::onInvert()
1980 double Dx = SpinBox_Dx->value();
1981 double Dy = SpinBox_Dy->value();
1982 double Dz = SpinBox_Dz->value();
1984 myIsSelectPlane = true;
1985 SpinBox_Dx->setValue( -Dx );
1986 SpinBox_Dy->setValue( -Dy );
1987 SpinBox_Dz->setValue( -Dz );
1988 myIsSelectPlane = false;
1990 if ( !myPlanes.empty() ) {
1991 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1992 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1993 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1994 aPlaneData->IsInvert = !aPlaneData->IsInvert;
1996 SetCurrentPlaneParam();