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();
235 Definition of class ActorItem
237 class ActorItem : public QListWidgetItem
240 ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) :
241 QListWidgetItem( theName, theListWidget ),
242 myActor( theActor ) {}
244 SMESH_Actor* getActor() const { return myActor; }
247 SMESH_Actor* myActor;
251 Definition of class TSetVisibility
253 struct TSetVisibility {
254 // Set visibility of cutting plane
255 TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){}
256 void operator()(SMESH::TPlaneData& thePlaneData){
257 bool anIsEmpty = thePlaneData.ActorList.empty();
258 thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty);
263 /*********************************************************************************
264 ********************* class SMESHGUI_ClippingDlg *********************
265 *********************************************************************************/
270 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
271 QDialog( SMESH::GetDesktop(theModule) ),
272 mySMESHGUI(theModule),
273 myViewWindow(theViewWindow)
276 setAttribute( Qt::WA_DeleteOnClose, true );
277 setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
278 setSizeGripEnabled(true);
280 myPreviewWidget = vtkImplicitPlaneWidget::New();
281 myCallback = vtkCallbackCommand::New();
282 myCallback->SetClientData( this );
283 myCallback->SetCallback( SMESHGUI_ClippingDlg::ProcessEvents );
284 myPreviewWidget = createPreviewWidget();
286 myIsPreviewMoved = false;
288 QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
289 SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
290 SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
292 // Controls for selecting, creating, deleting planes
293 QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
294 QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
295 GroupPlanesLayout->setSpacing(SPACING);
296 GroupPlanesLayout->setMargin(MARGIN);
298 ComboBoxPlanes = new QComboBox(GroupPlanes);
300 isOpenGLClipping = new QCheckBox( GroupPlanes );
301 isOpenGLClipping->setText( tr( "IS_OPENGL_CLIPPING" ) );
303 buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
305 MenuMode = new QMenu( "MenuMode", buttonNew );
306 MenuMode->addAction( tr( "ABSOLUTE" ), this, SLOT( onModeAbsolute() ) );
307 MenuMode->addAction( tr( "RELATIVE" ), this, SLOT( onModeRelative() ) );
308 buttonNew->setMenu( MenuMode );
309 CurrentMode = SMESH::Absolute;
311 buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
313 QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
315 ActorList = new QListWidget(GroupPlanes);
316 ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
318 SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
320 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
321 GroupPlanesLayout->addWidget(isOpenGLClipping, 0, 1);
322 GroupPlanesLayout->addWidget(new QWidget(), 0, 2);
323 GroupPlanesLayout->addWidget(buttonNew, 0, 3);
324 GroupPlanesLayout->addWidget(buttonDelete, 0, 4);
325 GroupPlanesLayout->addWidget(aLabel, 1, 0, 1, 5);
326 GroupPlanesLayout->addWidget(ActorList, 2, 0, 1, 5);
327 GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 5);
328 GroupPlanesLayout->setColumnStretch( 1, 1 );
330 ModeStackedLayout = new QStackedLayout();
332 // Controls for defining plane parameters
333 /********************** Mode Absolute **********************/
334 /* Controls for absolute mode of clipping plane:
335 X, Y, Z - coordinates of the intersection of cutting plane and the three axes
336 Dx, Dy, Dz - components of normal to the cutting plane
337 Orientation - direction of cutting plane
339 const double min = -1e+7;
340 const double max = 1e+7;
341 const double step = 5;
342 const int precision = -7;
345 QGroupBox* GroupAbsolutePoint = new QGroupBox( this );
346 GroupAbsolutePoint->setObjectName( "GroupPoint" );
347 GroupAbsolutePoint->setTitle( tr("BASE_POINT") );
348 QGridLayout* GroupPointLayout = new QGridLayout( GroupAbsolutePoint );
349 GroupPointLayout->setAlignment( Qt::AlignTop );
350 GroupPointLayout->setSpacing( 6 ); GroupPointLayout->setMargin( 11 );
352 TextLabelX = new QLabel( GroupAbsolutePoint );
353 TextLabelX->setObjectName( "TextLabelX" );
354 TextLabelX->setText( tr("X:") );
355 GroupPointLayout->addWidget( TextLabelX, 0, 0 );
357 SpinBox_X = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
358 SpinBox_X->setObjectName("SpinBox_X" );
359 SpinBox_X->setPrecision( precision );
360 GroupPointLayout->addWidget( SpinBox_X, 0, 1 );
362 TextLabelY = new QLabel( GroupAbsolutePoint );
363 TextLabelY->setObjectName( "TextLabelY" );
364 TextLabelY->setText( tr("Y:") );
365 GroupPointLayout->addWidget( TextLabelY, 0, 2 );
367 SpinBox_Y = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
368 SpinBox_Y->setObjectName("SpinBox_Y" );
369 SpinBox_Y->setPrecision( precision );
370 GroupPointLayout->addWidget( SpinBox_Y, 0, 3 );
372 TextLabelZ = new QLabel( GroupAbsolutePoint );
373 TextLabelZ->setObjectName( "TextLabelZ" );
374 TextLabelZ->setText( tr("Z:") );
375 GroupPointLayout->addWidget( TextLabelZ, 0, 4 );
377 SpinBox_Z = new QtxDoubleSpinBox( min, max, step, GroupAbsolutePoint );
378 SpinBox_Z->setObjectName("SpinBox_Z" );
379 SpinBox_Z->setPrecision( precision );
380 GroupPointLayout->addWidget( SpinBox_Z, 0, 5 );
382 resetButton = new QPushButton( GroupAbsolutePoint );
383 resetButton->setObjectName( "resetButton" );
384 resetButton->setText( tr( "RESET" ) );
385 GroupPointLayout->addWidget( resetButton, 0, 6 );
388 GroupAbsoluteDirection = new QGroupBox( this );
389 GroupAbsoluteDirection->setObjectName( "GroupDirection" );
390 GroupAbsoluteDirection->setTitle( tr("DIRECTION") );
391 QGridLayout* GroupDirectionLayout = new QGridLayout( GroupAbsoluteDirection );
392 GroupDirectionLayout->setAlignment( Qt::AlignTop );
393 GroupDirectionLayout->setSpacing( 6 );
394 GroupDirectionLayout->setMargin( 11 );
396 TextLabelDx = new QLabel( GroupAbsoluteDirection );
397 TextLabelDx->setObjectName( "TextLabelDx" );
398 TextLabelDx->setText( tr("Dx:") );
399 GroupDirectionLayout->addWidget( TextLabelDx, 0, 0 );
401 SpinBox_Dx = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
402 SpinBox_Dx->setObjectName("SpinBox_Dx" );
403 SpinBox_Dx->setPrecision( precision );
404 GroupDirectionLayout->addWidget( SpinBox_Dx, 0, 1 );
406 TextLabelDy = new QLabel( GroupAbsoluteDirection );
407 TextLabelDy->setObjectName( "TextLabelDy" );
408 TextLabelDy->setText( tr("Dy:") );
409 GroupDirectionLayout->addWidget( TextLabelDy, 0, 2 );
411 SpinBox_Dy = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
412 SpinBox_Dy->setObjectName("SpinBox_Dy" );
413 SpinBox_Dy->setPrecision( precision );
414 GroupDirectionLayout->addWidget( SpinBox_Dy, 0, 3 );
416 TextLabelDz = new QLabel( GroupAbsoluteDirection );
417 TextLabelDz->setObjectName( "TextLabelDz" );
418 TextLabelDz->setText( tr("Dz:") );
419 GroupDirectionLayout->addWidget( TextLabelDz, 0, 4 );
421 SpinBox_Dz = new QtxDoubleSpinBox( min, max, step, GroupAbsoluteDirection );
422 SpinBox_Dz->setObjectName("SpinBox_Dz" );
423 SpinBox_Dz->setPrecision( precision );
424 GroupDirectionLayout->addWidget( SpinBox_Dz, 0, 5 );
426 invertButton = new QPushButton( GroupAbsoluteDirection );
427 invertButton->setObjectName( "invertButton" );
428 invertButton->setText( tr( "INVERT" ) );
429 GroupDirectionLayout->addWidget( invertButton, 0, 6 );
431 CBAbsoluteOrientation = new QComboBox( GroupAbsoluteDirection );
432 CBAbsoluteOrientation->setObjectName( "AbsoluteOrientation" );
433 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "CUSTOM" ) );
434 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||X-Y" ) );
435 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Y-Z" ) );
436 CBAbsoluteOrientation->insertItem( CBAbsoluteOrientation->count(), tr( "||Z-X" ) );
437 GroupDirectionLayout->addWidget( CBAbsoluteOrientation, 1, 0, 1, 6 );
439 QVBoxLayout* ModeActiveLayout = new QVBoxLayout();
440 ModeActiveLayout->setMargin( 11 ); ModeActiveLayout->setSpacing( 6 );
441 ModeActiveLayout->addWidget( GroupAbsolutePoint );
442 ModeActiveLayout->addWidget( GroupAbsoluteDirection );
444 QWidget* ModeActiveWidget = new QWidget( this );
445 ModeActiveWidget->setLayout( ModeActiveLayout );
447 /********************** Mode Relative **********************/
448 /* Controls for relative mode of clipping plane:
449 Distance - Value from 0 to 1.
450 Specifies the distance from the minimum value in a given direction of bounding box to the current position
451 Rotation1, Rotation2 - turn angles of cutting plane in given directions
452 Orientation - direction of cutting plane
454 QGroupBox* GroupParameters = new QGroupBox( tr("SMESH_PARAMETERS"), this );
455 QGridLayout* GroupParametersLayout = new QGridLayout( GroupParameters );
456 GroupParametersLayout->setMargin( 11 ); GroupParametersLayout->setSpacing( 6 );
458 TextLabelOrientation = new QLabel( tr("SMESH_ORIENTATION"), GroupParameters);
459 TextLabelOrientation->setObjectName( "TextLabelOrientation" );
460 GroupParametersLayout->addWidget( TextLabelOrientation, 0, 0 );
462 CBRelativeOrientation = new QComboBox(GroupParameters);
463 CBRelativeOrientation->setObjectName( "RelativeOrientation" );
464 CBRelativeOrientation->addItem( tr("ALONG_XY") );
465 CBRelativeOrientation->addItem( tr("ALONG_YZ") );
466 CBRelativeOrientation->addItem( tr("ALONG_ZX") );
467 GroupParametersLayout->addWidget( CBRelativeOrientation, 0, 1 );
469 TextLabelDistance = new QLabel( tr("SMESH_DISTANCE"), GroupParameters );
470 TextLabelDistance->setObjectName( "TextLabelDistance" );
471 GroupParametersLayout->addWidget( TextLabelDistance, 1, 0 );
473 SpinSliderDistance = new QtxDoubleSpinSlider( 0., 1., 0.01, GroupParameters );
474 SpinSliderDistance->setObjectName( "SpinSliderDistance" );
475 SpinSliderDistance->setPrecision( precision );
476 QFont fnt = SpinSliderDistance->font(); fnt.setBold( true ); SpinSliderDistance->setFont( fnt );
477 GroupParametersLayout->addWidget( SpinSliderDistance, 1, 1 );
479 QString aUnitRot = "\xB0";
481 TextLabelRotation1 = new QLabel( tr("ROTATION_AROUND_X_Y2Z"), GroupParameters );
482 TextLabelRotation1->setObjectName( "TextLabelRotation1" );
483 GroupParametersLayout->addWidget( TextLabelRotation1, 2, 0 );
485 SpinSliderRotation1 = new QtxIntSpinSlider( -180, 180, 1, GroupParameters );
486 SpinSliderRotation1->setObjectName( "SpinSliderRotation1" );
487 SpinSliderRotation1->setUnit( aUnitRot );
488 SpinSliderRotation1->setFont( fnt );
489 GroupParametersLayout->addWidget( SpinSliderRotation1, 2, 1 );
491 TextLabelRotation2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
492 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
493 TextLabelRotation2->setObjectName( "TextLabelRotation2" );
494 GroupParametersLayout->addWidget( TextLabelRotation2, 3, 0 );
496 SpinSliderRotation2 = new QtxIntSpinSlider( -180, 180, 1, GroupParameters );
497 SpinSliderRotation2->setObjectName( "SpinSliderRotation2" );
498 SpinSliderRotation2->setUnit( aUnitRot );
499 SpinSliderRotation2->setFont( fnt );
500 GroupParametersLayout->addWidget( SpinSliderRotation2, 3, 1 );
502 /***************************************************************/
503 QWidget* CheckBoxWidget = new QWidget( this );
504 QHBoxLayout* CheckBoxLayout = new QHBoxLayout( CheckBoxWidget );
506 PreviewCheckBox = new QCheckBox( tr("SHOW_PREVIEW"), CheckBoxWidget );
507 PreviewCheckBox->setObjectName( "PreviewCheckBox" );
508 PreviewCheckBox->setChecked( true );
509 CheckBoxLayout->addWidget( PreviewCheckBox, 0, Qt::AlignCenter );
511 AutoApplyCheckBox = new QCheckBox( tr("AUTO_APPLY"), CheckBoxWidget );
512 AutoApplyCheckBox->setObjectName( "AutoApplyCheckBox" );
513 CheckBoxLayout->addWidget( AutoApplyCheckBox, 0, Qt::AlignCenter );
515 /***************************************************************/
516 // Controls for "Ok", "Apply" and "Close" button
517 QGroupBox* GroupButtons = new QGroupBox(this);
518 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
519 GroupButtonsLayout->setSpacing(SPACING);
520 GroupButtonsLayout->setMargin(MARGIN);
522 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
523 buttonOk->setAutoDefault( true );
524 buttonOk->setDefault( true );
525 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
526 buttonApply->setAutoDefault( true );
527 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
528 buttonCancel->setAutoDefault( true );
529 buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
530 buttonHelp->setAutoDefault( true );
531 GroupButtonsLayout->addWidget( buttonOk );
532 GroupButtonsLayout->addSpacing(10);
533 GroupButtonsLayout->addWidget( buttonApply );
534 GroupButtonsLayout->addSpacing(10);
535 GroupButtonsLayout->addStretch();
536 GroupButtonsLayout->addWidget( buttonCancel );
537 GroupButtonsLayout->addWidget( buttonHelp );
539 ModeStackedLayout->addWidget( ModeActiveWidget );
540 ModeStackedLayout->addWidget( GroupParameters );
542 SMESHGUI_ClippingDlgLayout->addWidget( GroupPlanes );
543 SMESHGUI_ClippingDlgLayout->addLayout( ModeStackedLayout );
544 SMESHGUI_ClippingDlgLayout->addWidget( CheckBoxWidget );
545 SMESHGUI_ClippingDlgLayout->addWidget( GroupButtons );
550 myIsSelectPlane = false;
552 myHelpFileName = "clipping_page.html";
554 // signals and slots connections :
555 connect( ComboBoxPlanes, SIGNAL( activated( int ) ), this, SLOT( onSelectPlane( int ) ) );
556 connect( isOpenGLClipping, SIGNAL( toggled( bool ) ), this, SLOT( onIsOpenGLClipping( bool ) ) );
557 connect( buttonNew, SIGNAL( clicked() ), buttonNew, SLOT( showMenu() ) );
558 connect( buttonDelete, SIGNAL( clicked() ), this, SLOT( ClickOnDelete() ) );
559 connect( ActorList, SIGNAL( itemChanged( QListWidgetItem* ) ), this, SLOT( onActorItemChanged( QListWidgetItem*) ) );
560 connect( SelectAllCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( onSelectAll( int ) ) );
562 connect( invertButton, SIGNAL (clicked() ), this, SLOT( onInvert() ) ) ;
563 connect( resetButton, SIGNAL (clicked() ), this, SLOT( onReset() ) );
564 connect( SpinBox_X, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
565 connect( SpinBox_Y, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
566 connect( SpinBox_Z, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
567 connect( SpinBox_Dx, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
568 connect( SpinBox_Dy, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
569 connect( SpinBox_Dz, SIGNAL ( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
570 connect( CBAbsoluteOrientation, SIGNAL ( activated ( int ) ), this, SLOT( onSelectAbsoluteOrientation( int ) ) ) ;
572 connect( CBRelativeOrientation, SIGNAL( activated( int ) ), this, SLOT( onSelectRelativeOrientation( int ) ) );
573 connect( SpinSliderDistance, SIGNAL( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) );
574 connect( SpinSliderRotation1, SIGNAL( valueChanged( int ) ), this, SLOT( SetCurrentPlaneParam() ) );
575 connect( SpinSliderRotation2, SIGNAL( valueChanged( int ) ), this, SLOT( SetCurrentPlaneParam() ) );
577 connect( PreviewCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( OnPreviewToggle( bool ) ) );
578 connect( AutoApplyCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( onAutoApply( bool ) ) );
579 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
580 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
581 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
582 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
583 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( reject() ) );
584 /* to close dialog if study frame change */
585 connect( mySMESHGUI, SIGNAL ( SignalStudyFrameChanged() ), this, SLOT( reject() ) );
587 initializePlaneData();
595 Destroys the object and frees any allocated resources
597 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
599 // no need to delete child widgets, Qt does it all for us
600 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
602 SMESH::RenderViewWindow(myViewWindow);
604 for ( size_t i = 0; i < myPlanes.size(); i++ ) {
605 SMESH::TPlaneData aPlaneData = myPlanes[i];
606 aPlaneData.Plane->Delete();
609 if ( myPreviewWidget ) {
610 myPreviewWidget->Off();
611 myPreviewWidget->Delete();
614 myCallback->Delete();
616 myViewWindow->Repaint();
620 Get distance for cutting plane in relative mode
622 double SMESHGUI_ClippingDlg::getDistance() const
624 return SpinSliderDistance->value();
628 Set distance of cutting plane in relative mode
630 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
632 SpinSliderDistance->setValue( theDistance );
636 Get rotation1 for cutting plane in relative mode
638 double SMESHGUI_ClippingDlg::getRotation1() const
640 return SpinSliderRotation1->value();
644 Get rotation2 for cutting plane in relative mode
646 double SMESHGUI_ClippingDlg::getRotation2() const
648 return SpinSliderRotation2->value();
652 Set angles of clipping plane in relative mode
654 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
656 SpinSliderRotation1->setValue( int(floor(theRot1)) );
657 SpinSliderRotation2->setValue( int(floor(theRot2)) );
661 Set coordinates of origin point in dialog box
663 void SMESHGUI_ClippingDlg::setOrigin( double theVal[3] )
665 int anOrientation = CBAbsoluteOrientation->currentIndex();
666 if( anOrientation == 0 || anOrientation == 2 )
667 SpinBox_X->setValue( theVal[0] );
668 if( anOrientation == 0 || anOrientation == 3 )
669 SpinBox_Y->setValue( theVal[1] );
670 if( anOrientation == 0 || anOrientation == 1 )
671 SpinBox_Z->setValue( theVal[2] );
675 Set coordinates of normal vector in dialog box
677 void SMESHGUI_ClippingDlg::setDirection( double theVal[3] )
679 int anOrientation = CBAbsoluteOrientation->currentIndex();
680 if( anOrientation == 0 ) {
681 SpinBox_Dx->setValue( theVal[0] );
682 SpinBox_Dy->setValue( theVal[1] );
683 SpinBox_Dz->setValue( theVal[2] );
688 Create a new widget for preview clipping plane
690 vtkImplicitPlaneWidget* SMESHGUI_ClippingDlg::createPreviewWidget()
692 vtkImplicitPlaneWidget* aPlaneWgt = vtkImplicitPlaneWidget::New();
694 aPlaneWgt->SetInteractor( myViewWindow->getInteractor() );
695 aPlaneWgt->SetPlaceFactor( SIZEFACTOR );
696 aPlaneWgt->ScaleEnabledOff();
697 aPlaneWgt->SetOrigin( 0, 0, 0 );
698 aPlaneWgt->SetNormal( -1, -1, -1 );
702 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
704 aPlaneWgt->GetPlaneProperty()->SetColor( anRGB[0],anRGB[1],anRGB[2] );
705 aPlaneWgt->GetPlaneProperty()->SetOpacity( 0.2 );;
707 aPlaneWgt->GetSelectedPlaneProperty()->SetColor( anRGB[0],anRGB[1],anRGB[2] );
708 aPlaneWgt->GetSelectedPlaneProperty()->SetOpacity( 0.2 );
709 aPlaneWgt->GetSelectedPlaneProperty()->SetLineWidth( 2.0 );
711 aPlaneWgt->AddObserver(vtkCommand::InteractionEvent, myCallback, 0.);
717 Translate two angles of plane to normal
719 void rotationToNormal ( double theRotation[2],
722 double theDir[2][3] )
724 static double aCoeff = M_PI/180.0;
726 double anU[2] = { cos( aCoeff * theRotation[0] ), cos( aCoeff * theRotation[1] ) };
727 double aV[2] = { sqrt( 1.0 - anU[0]*anU[0] ), sqrt( 1.0 - anU[1] * anU[1] ) };
728 aV[0] = theRotation[0] > 0? aV[0]: -aV[0];
729 aV[1] = theRotation[1] > 0? aV[1]: -aV[1];
731 switch ( theOrientation ) {
734 theDir[0][1] = anU[0];
735 theDir[0][2] = aV[0];
736 theDir[1][0] = anU[1];
737 theDir[1][2] = aV[1];
740 theDir[0][2] = anU[0];
741 theDir[0][0] = aV[0];
742 theDir[1][1] = anU[1];
743 theDir[1][0] = aV[1];
746 theDir[0][0] = anU[0];
747 theDir[0][1] = aV[0];
748 theDir[1][2] = anU[1];
749 theDir[1][1] = aV[1];
753 vtkMath::Cross( theDir[1], theDir[0], theNormal );
754 vtkMath::Normalize( theNormal );
755 vtkMath::Cross( theNormal, theDir[1], theDir[0] );
759 Used in SMESHGUI::restoreVisualParameters() to avoid
760 Declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
762 bool SMESHGUI_ClippingDlg::AddPlane ( SMESH::TActorList theActorList,
763 SMESH::OrientedPlane* thePlane )
766 double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
767 static double aCoeff = vtkMath::Pi()/180.0;
769 int anOrientation = 0;
770 if ( thePlane->PlaneMode == SMESH::Absolute )
771 anOrientation = thePlane->myAbsoluteOrientation;
772 else if ( thePlane->PlaneMode == SMESH::Relative )
773 anOrientation = thePlane->myRelativeOrientation + 1;
775 if ( anOrientation == 0 ) {
776 // compute a direction for plane in absolute mode
777 double znam = sqrt( thePlane->Dx*thePlane->Dx + thePlane->Dy*thePlane->Dy + thePlane->Dz*thePlane->Dz );
778 double aRotation = acos( thePlane->Dy/znam )/aCoeff;
779 if ( thePlane->Dy >= 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[0] = 90.0 + aRotation;
780 else if ( thePlane->Dy >= 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[0] = 90.0 - aRotation;
781 else if ( thePlane->Dy < 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[0] = aRotation - 90.0;
782 else if ( thePlane->Dy < 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[0] = 270.0 - aRotation;
784 aRotation = acos( thePlane->Dx/znam )/aCoeff;
785 if ( thePlane->Dx >= 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[1] = 90.0 + aRotation;
786 else if ( thePlane->Dx >= 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[1] = 90.0 - aRotation;
787 else if ( thePlane->Dx < 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[1] = aRotation - 90.0;
788 else if ( thePlane->Dx < 0.0 && thePlane->Dz < 0.0 ) thePlane->myAngle[1] = 270.0 - aRotation;
792 rotationToNormal( thePlane->myAngle, anOrientation, aNormal, aDir );
797 if ( thePlane->PlaneMode == SMESH::Absolute ) {
798 aNormal[0] = thePlane->Dx;
799 aNormal[1] = thePlane->Dy;
800 aNormal[2] = thePlane->Dz;
804 if( theActorList.empty() ) {
805 // to support planes with empty actor list we should create
806 // a nullified plane that will be initialized later
807 anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
808 aBounds[0] = aBounds[2] = aBounds[4] = 0;
809 aBounds[1] = aBounds[3] = aBounds[5] = 0;
813 anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
815 thePlane->myDistance,
821 if ( thePlane->PlaneMode == SMESH::Absolute ) {
822 anOrigin[0] = thePlane->X;
823 anOrigin[1] = thePlane->Y;
824 anOrigin[2] = thePlane->Z;
826 thePlane->SetNormal( aNormal );
827 thePlane->SetOrigin( anOrigin );
830 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
831 ( aBounds[2] + aBounds[3] ) / 2.,
832 ( aBounds[4] + aBounds[5] ) / 2. };
834 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
835 pow( aBounds[3] - aBounds[2], 2 ) +
836 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
838 double aDelta[2][3] = { { aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel },
839 { aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel } };
840 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
842 double aPnt01[3] = { aPnt[0] - aDelta[0][0] - aDelta[1][0],
843 aPnt[1] - aDelta[0][1] - aDelta[1][1],
844 aPnt[2] - aDelta[0][2] - aDelta[1][2] };
845 double aPnt02[3] = { aPnt01[0] + aNormal[0],
846 aPnt01[1] + aNormal[1],
847 aPnt01[2] + aNormal[2] };
848 vtkPlane::IntersectWithLine( aPnt01, aPnt02, aNormal, anOrigin, aParam, aPnt0 );
850 double aPnt11[3] = { aPnt[0] - aDelta[0][0] + aDelta[1][0],
851 aPnt[1] - aDelta[0][1] + aDelta[1][1],
852 aPnt[2] - aDelta[0][2] + aDelta[1][2] };
853 double aPnt12[3] = { aPnt11[0] + aNormal[0],
854 aPnt11[1] + aNormal[1],
855 aPnt11[2] + aNormal[2] };
856 vtkPlane::IntersectWithLine( aPnt11, aPnt12, aNormal, anOrigin, aParam, aPnt1);
858 double aPnt21[3] = { aPnt[0] + aDelta[0][0] - aDelta[1][0],
859 aPnt[1] + aDelta[0][1] - aDelta[1][1],
860 aPnt[2] + aDelta[0][2] - aDelta[1][2] };
861 double aPnt22[3] = { aPnt21[0] + aNormal[0],
862 aPnt21[1] + aNormal[1],
863 aPnt21[2] + aNormal[2] };
864 vtkPlane::IntersectWithLine( aPnt21, aPnt22, aNormal, anOrigin, aParam, aPnt2);
866 vtkPlaneSource* aPlaneSource = thePlane->myPlaneSource;
867 aPlaneSource->SetNormal( aNormal[0], aNormal[1], aNormal[2] );
868 aPlaneSource->SetOrigin( aPnt0[0], aPnt0[1], aPnt0[2] );
869 aPlaneSource->SetPoint1( aPnt1[0], aPnt1[1], aPnt1[2] );
870 aPlaneSource->SetPoint2( aPnt2[0], aPnt2[1], aPnt2[2] );
871 aPlaneSource->Update();
873 SMESH::TActorList::iterator anIter = theActorList.begin();
874 for ( ; anIter != theActorList.end(); anIter++ )
875 if( vtkActor* aVTKActor = *anIter )
876 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
877 if( thePlane->IsOpenGLClipping )
878 anActor->AddOpenGLClippingPlane( thePlane->InvertPlane() );
880 anActor->AddClippingPlane( thePlane );
887 Custom handling of events
889 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
891 QDialog::keyPressEvent( e );
892 if ( e->isAccepted() )
895 if ( e->key() == Qt::Key_F1 ) {
902 Handles the char preview widget activation event
904 void SMESHGUI_ClippingDlg::ProcessEvents( vtkObject* theObject,
905 unsigned long theEvent,
907 void* vtkNotUsed( theCallData ) )
909 vtkImplicitPlaneWidget* aWidget = vtkImplicitPlaneWidget::SafeDownCast( theObject );
910 if ( aWidget == NULL ) return;
911 if ( theClientData == NULL ) return;
913 SMESHGUI_ClippingDlg* aDlg = (SMESHGUI_ClippingDlg*) theClientData;
919 case vtkCommand::InteractionEvent:
920 aWidget->GetOrigin( anOrigin );
921 aWidget->GetNormal( aDir );
923 aDlg->myIsSelectPlane = true;
925 if( aDlg->CurrentMode == SMESH::Absolute ) {
926 aDlg->setOrigin( anOrigin );
927 aDlg->setDirection( aDir );
928 aDlg->myIsPreviewMoved = true;
930 else if( aDlg->CurrentMode == SMESH::Relative ) {
931 aDlg->absolutePlaneToRelative( anOrigin, aDir );
933 aDlg->myIsSelectPlane = false;
935 aDlg->SetCurrentPlaneParam();
936 aDlg->myIsPreviewMoved = false;
942 Initialize the planes's data when the dialog opened
944 void SMESHGUI_ClippingDlg::initializePlaneData()
946 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
947 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
948 if( anIter1 != aClippingPlaneInfoMap.end() ) {
949 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
950 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
951 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
952 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
953 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
954 anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
955 SMESH::TPlane aTPlane( anOrientedPlane );
956 SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
957 myPlanes.push_back( aPlaneData );
960 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
961 if( myPlanes.size() )
962 myPreviewWidget->SetEnabled( PreviewCheckBox->isChecked() );
966 Initialization of initial values of widgets
968 void SMESHGUI_ClippingDlg::initParam()
970 SpinBox_X->setValue( 0.0 );
971 SpinBox_Y->setValue( 0.0 );
972 SpinBox_Z->setValue( 0.0 );
974 SpinBox_Dx->setValue( 1.0 );
975 SpinBox_Dy->setValue( 1.0 );
976 SpinBox_Dz->setValue( 1.0 );
978 CBAbsoluteOrientation->setCurrentIndex(0);
980 SpinSliderDistance->setValue( 0.5 );
981 SpinSliderRotation1->setValue( 0 );
982 SpinSliderRotation2->setValue( 0 );
983 CBRelativeOrientation->setCurrentIndex( 0 );
987 Synchronize dialog's widgets with data
989 void SMESHGUI_ClippingDlg::synchronize()
991 int aNbPlanes = myPlanes.size();
992 ComboBoxPlanes->clear();
995 for( int i = 1; i<=aNbPlanes; i++ ) {
996 aName = QString( tr( "PLANE_NUM" ) ).arg(i);
997 ComboBoxPlanes->addItem( aName );
1000 int aPos = ComboBoxPlanes->count() - 1;
1001 ComboBoxPlanes->setCurrentIndex( aPos );
1003 bool anIsControlsEnable = ( aPos >= 0 );
1004 if ( anIsControlsEnable ) {
1005 onSelectPlane( aPos );
1007 if( PreviewCheckBox->isChecked() )
1008 myPreviewWidget->On();
1011 ComboBoxPlanes->addItem( tr( "NO_PLANES" ) );
1014 if( PreviewCheckBox->isChecked() )
1015 myPreviewWidget->Off();
1018 isOpenGLClipping->setEnabled( anIsControlsEnable );
1019 ActorList->setEnabled( anIsControlsEnable );
1020 SelectAllCheckBox->setEnabled( anIsControlsEnable );
1021 buttonDelete->setEnabled( anIsControlsEnable );
1022 if ( CurrentMode == SMESH::Absolute ) {
1023 SpinBox_X->setEnabled( anIsControlsEnable );
1024 SpinBox_Y->setEnabled( anIsControlsEnable );
1025 SpinBox_Z->setEnabled( anIsControlsEnable );
1026 SpinBox_Dx->setEnabled( anIsControlsEnable );
1027 SpinBox_Dy->setEnabled( anIsControlsEnable );
1028 SpinBox_Dz->setEnabled( anIsControlsEnable );
1029 CBAbsoluteOrientation->setEnabled( anIsControlsEnable );
1030 invertButton->setEnabled( anIsControlsEnable );
1031 resetButton->setEnabled( anIsControlsEnable );
1033 else if ( CurrentMode == SMESH::Relative ) {
1034 CBRelativeOrientation->setEnabled( anIsControlsEnable );
1035 SpinSliderDistance->setEnabled( anIsControlsEnable );
1036 SpinSliderRotation1->setEnabled( anIsControlsEnable );
1037 SpinSliderRotation2->setEnabled( anIsControlsEnable );
1042 Update the list of actors
1044 void SMESHGUI_ClippingDlg::updateActorList()
1048 SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1052 _PTR(Study) aStudy = anAppStudy->studyDS();
1059 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1060 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1061 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1063 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1064 aPlaneData.Plane.GetPointer()->myActor->SetVisibility( false );
1066 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1067 vtkActorCollection* anAllActors = aCopy.GetActors();
1068 anAllActors->InitTraversal();
1069 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1070 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1071 if( anActor->hasIO() ) {
1072 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1073 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1074 bool anIsChecked = false;
1075 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1076 for ( ; anIter != anActorList.end(); anIter++ ) {
1077 if( vtkActor* aVTKActorRef = *anIter ) {
1078 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1079 if( anActorRef == anActor ) {
1086 QString aName = QString( aSObj->GetName().c_str() );
1087 QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
1088 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1089 updateActorItem( anItem, true, false );
1097 Update an actor in actor's list
1099 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
1100 bool theUpdateSelectAll,
1101 bool theUpdateClippingPlaneMap )
1103 // update Select All check box
1104 if( theUpdateSelectAll ) {
1105 int aNbItems = ActorList->count(), aNbChecked = 0;
1106 for( int i = 0; i < aNbItems; i++ )
1107 if( QListWidgetItem* anItem = ActorList->item( i ) )
1108 if( anItem->checkState() == Qt::Checked )
1111 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
1112 SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
1113 SelectAllCheckBox->blockSignals( anIsBlocked );
1116 // update clipping plane map
1117 if( theUpdateClippingPlaneMap ) {
1118 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1119 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
1120 if( SMESH_Actor* anActor = anItem->getActor() ) {
1121 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1122 SMESH::TActorList& anActorList = aPlaneData.ActorList;
1123 bool anIsPushed = false;
1124 SMESH::TActorList::iterator anIter = anActorList.begin();
1125 for ( ; anIter != anActorList.end(); anIter++ ) {
1126 if( anActor == *anIter ) {
1131 if( theItem->checkState() == Qt::Checked && !anIsPushed )
1132 anActorList.push_back( anActor );
1133 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
1134 anActorList.remove( anActor );
1136 if( SMESH::ComputeBounds( anActorList, myBounds ) ) {
1137 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1138 myBounds[3], myBounds[4], myBounds[5] );
1139 if( PreviewCheckBox->isChecked() )
1140 myPreviewWidget->On();
1143 myPreviewWidget->Off();
1150 Get the list of current actors
1152 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1154 SMESH::TActorList anActorList;
1155 for( int i = 0, n = ActorList->count(); i < n; i++ )
1156 if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1157 if( anItem->checkState() == Qt::Checked )
1158 if( SMESH_Actor* anActor = anItem->getActor() )
1159 anActorList.push_back( anActor );
1164 Dump the parameters of clipping planes
1166 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1168 printf( "----------- Plane Data -----------\n" );
1170 SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1171 for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1172 SMESH::TPlaneData aPlaneData = *anIter1;
1173 SMESH::TPlane aPlane = aPlaneData.Plane;
1174 double* aNormal = aPlane->GetNormal();
1175 double* anOrigin = aPlane->GetOrigin();
1176 printf( "Plane N%d:\n", anId );
1177 printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1178 printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1180 SMESH::TActorList anActorList = aPlaneData.ActorList;
1181 SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1182 for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1183 if( vtkActor* aVTKActor = *anIter2 ) {
1184 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1185 printf( " - Actor: '%s'\n", anActor->getName() );
1188 printf( " - Actor: NULL\n");
1191 printf( "----------------------------------\n" );
1195 SLOT on close button click: rejects dialog
1197 void SMESHGUI_ClippingDlg::reject()
1199 //here we can insert actions to do at close.
1204 Set absolute mode of clipping plane
1206 void SMESHGUI_ClippingDlg::onModeAbsolute()
1208 ModeStackedLayout->setCurrentIndex(0);
1209 CurrentMode = SMESH::Absolute;
1211 SetCurrentPlaneParam();
1215 Set relative mode of clipping plane
1217 void SMESHGUI_ClippingDlg::onModeRelative()
1219 ModeStackedLayout->setCurrentIndex(1);
1220 CurrentMode = SMESH::Relative;
1222 SetCurrentPlaneParam();
1226 SLOT on new button click: create a new clipping plane
1228 void SMESHGUI_ClippingDlg::ClickOnNew()
1231 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
1232 SMESH::TPlane aTPlane(aPlane);
1233 aPlane->PlaneMode = CurrentMode;
1234 SMESH::TActorList anActorList;
1235 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1236 vtkActorCollection* anAllActors = aCopy.GetActors();
1237 anAllActors->InitTraversal();
1238 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1239 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1240 anActorList.push_back( anActor );
1242 SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
1244 myPlanes.push_back(aPlaneData);
1247 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1248 aPlane->myActor->SetVisibility( false );
1250 bool anIsBlocked = ActorList->blockSignals( true );
1252 if( SMESH::ComputeBounds( anActorList, myBounds ) ) {
1253 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1254 myBounds[3], myBounds[4], myBounds[5] );
1255 if( PreviewCheckBox->isChecked() )
1256 myPreviewWidget->On();
1259 myPreviewWidget->Off();
1262 SetCurrentPlaneParam();
1264 ActorList->blockSignals( anIsBlocked );
1269 SLOT on delete button click: Delete selected clipping plane
1271 void SMESHGUI_ClippingDlg::ClickOnDelete()
1273 if (myPlanes.empty())
1276 int aPlaneIndex = ComboBoxPlanes->currentIndex();
1278 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
1279 SMESH::TPlaneData aPlaneData = *anIter;
1280 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
1281 myPlanes.erase(anIter);
1283 if(AutoApplyCheckBox->isChecked())
1287 SMESH::RenderViewWindow( myViewWindow );
1291 Set current parameters of selected plane
1293 void SMESHGUI_ClippingDlg::onSelectPlane ( int theIndex )
1295 if ( myPlanes.empty() )
1298 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
1299 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1301 myIsSelectPlane = true;
1302 isOpenGLClipping->setChecked( aPlane->IsOpenGLClipping );
1304 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1305 ModeStackedLayout->setCurrentIndex( 0 );
1306 CurrentMode = SMESH::Absolute;
1307 int anOrientation = aPlane->myAbsoluteOrientation;
1308 // Set plane parameters in the dialog
1309 double anOrigin[3], aDir[3];
1310 anOrigin[0] = aPlane->X;
1311 anOrigin[1] = aPlane->Y;
1312 anOrigin[2] = aPlane->Z;
1313 setOrigin( anOrigin );
1314 aDir[0] = aPlane->Dx;
1315 aDir[1] = aPlane->Dy;
1316 aDir[2] = aPlane->Dz;
1317 setDirection( aDir );
1318 CBAbsoluteOrientation->setCurrentIndex( anOrientation );
1319 onSelectAbsoluteOrientation( anOrientation );
1321 else if ( aPlane->PlaneMode == SMESH::Relative ) {
1322 ModeStackedLayout->setCurrentIndex( 1 );
1323 CurrentMode = SMESH::Relative;
1324 SMESH::Orientation anOrientation = aPlane->GetOrientation();
1325 double aRot[2] = { aPlane->myAngle[0], aPlane->myAngle[1] };
1326 // Set plane parameters in the dialog
1327 setDistance( aPlane->GetDistance() );
1328 setRotation( aRot[0], aRot[1] );
1329 switch ( anOrientation ) {
1331 CBRelativeOrientation->setCurrentIndex(0);
1332 onSelectRelativeOrientation(0);
1335 CBRelativeOrientation->setCurrentIndex(1);
1336 onSelectRelativeOrientation(1);
1339 CBRelativeOrientation->setCurrentIndex(2);
1340 onSelectRelativeOrientation(2);
1344 myIsSelectPlane = false;
1346 if( SMESH::ComputeBounds( aPlaneData.ActorList, myBounds ) ) {
1347 myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2],
1348 myBounds[3], myBounds[4], myBounds[5] );
1349 if( PreviewCheckBox->isChecked() )
1350 myPreviewWidget->On();
1353 myPreviewWidget->Off();
1355 SetCurrentPlaneParam();
1358 bool anIsBlocked = ActorList->blockSignals( true );
1360 ActorList->blockSignals( anIsBlocked );
1364 SLOT: called on OpenGLClipping check box toggled
1366 void SMESHGUI_ClippingDlg::onIsOpenGLClipping( bool toggled )
1368 if ( myPlanes.empty() || myIsSelectPlane )
1371 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1372 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1373 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1374 aPlaneData->IsOpenGLClipping = toggled;
1376 if( AutoApplyCheckBox->isChecked() )
1381 SLOT: called on SelectAll check box toggled
1383 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
1385 if( theState == Qt::PartiallyChecked ) {
1386 SelectAllCheckBox->setCheckState( Qt::Checked );
1390 bool anIsBlocked = ActorList->blockSignals( true );
1391 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
1392 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
1393 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
1394 updateActorItem( anItem, false, true );
1397 SelectAllCheckBox->setTristate( false );
1398 ActorList->blockSignals( anIsBlocked );
1399 SetCurrentPlaneParam();
1403 SLOT: called when actor item was changed
1405 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
1407 updateActorItem( theItem, true, true );
1408 SetCurrentPlaneParam();
1412 Restore parameters of selected plane
1414 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
1416 if ( myPlanes.empty() || myIsSelectPlane )
1419 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1421 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1422 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1424 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1425 aPlane->myAbsoluteOrientation = CBAbsoluteOrientation->currentIndex();
1426 aPlane->X = SpinBox_X->value();
1427 aPlane->Y = SpinBox_Y->value();
1428 aPlane->Z = SpinBox_Z->value();
1429 aPlane->Dx = SpinBox_Dx->value();
1430 aPlane->Dy = SpinBox_Dy->value();
1431 aPlane->Dz = SpinBox_Dz->value();
1435 double aDir[2][3] = { {0, 0, 0}, {0, 0, 0} };
1436 static double aCoeff = vtkMath::Pi()/180.0;
1438 double aRot[2] = { getRotation1(), getRotation2() };
1440 if ( aPlane->PlaneMode == SMESH::Absolute )
1441 anOrient = CBAbsoluteOrientation->currentIndex();
1442 else if ( aPlane->PlaneMode == SMESH::Relative )
1443 anOrient = CBRelativeOrientation->currentIndex() + 1;
1445 if ( aPlane->PlaneMode == SMESH::Relative ) {
1446 aPlane->myAngle[0] = aRot[0];
1447 aPlane->myAngle[1] = aRot[1];
1448 aPlane->SetOrientation( SMESH::Orientation( CBRelativeOrientation->currentIndex() ) );
1449 aPlane->SetDistance( getDistance() );
1452 if ( anOrient == 0 ) {
1453 // compute a direction for plane in absolute mode
1454 double znam = sqrt( aPlane->Dx*aPlane->Dx + aPlane->Dy*aPlane->Dy + aPlane->Dz*aPlane->Dz );
1455 double aRotation = acos( aPlane->Dy/znam )/aCoeff;
1456 if ( aPlane->Dy >= 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = 90.0 + aRotation;
1457 else if ( aPlane->Dy >= 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 90.0 - aRotation;
1458 else if ( aPlane->Dy < 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = aRotation - 90.0;
1459 else if ( aPlane->Dy < 0.0 && aPlane->Dz < 0.0 ) aRot[0] = 270.0 - aRotation;
1461 aRotation = acos( aPlane->Dx/znam )/aCoeff;
1462 if ( aPlane->Dx >= 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = 90.0 + aRotation;
1463 else if ( aPlane->Dx >= 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 90.0 - aRotation;
1464 else if ( aPlane->Dx < 0.0 && aPlane->Dz >= 0.0 ) aRot[1] = aRotation - 90.0;
1465 else if ( aPlane->Dx < 0.0 && aPlane->Dz < 0.0 ) aRot[1] = 270.0 - aRotation;
1469 rotationToNormal( aRot, anOrient, aNormal, aDir );
1472 SMESH::TActorList anActorList = aPlaneData.ActorList;
1477 aDistance = getDistance();
1478 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1479 aNormal[0] = aPlane->Dx;
1480 aNormal[1] = aPlane->Dy;
1481 aNormal[2] = aPlane->Dz;
1484 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
1490 if ( aPlane->PlaneMode == SMESH::Absolute ) {
1491 anOrigin[0] = aPlane->X;
1492 anOrigin[1] = aPlane->Y;
1493 anOrigin[2] = aPlane->Z;
1497 aPlane->SetNormal( aNormal );
1498 aPlane->SetOrigin( anOrigin );
1500 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
1501 ( aBounds[2] + aBounds[3] ) / 2.,
1502 ( aBounds[4] + aBounds[5] ) / 2. };
1504 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
1505 pow( aBounds[3] - aBounds[2], 2 ) +
1506 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
1508 double aDelta[2][3] = { { aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel },
1509 { aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel } };
1510 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
1512 double aPnt01[3] = { aPnt[0] - aDelta[0][0] - aDelta[1][0],
1513 aPnt[1] - aDelta[0][1] - aDelta[1][1],
1514 aPnt[2] - aDelta[0][2] - aDelta[1][2] };
1515 double aPnt02[3] = { aPnt01[0] + aNormal[0],
1516 aPnt01[1] + aNormal[1],
1517 aPnt01[2] + aNormal[2] };
1518 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
1520 double aPnt11[3] = { aPnt[0] - aDelta[0][0] + aDelta[1][0],
1521 aPnt[1] - aDelta[0][1] + aDelta[1][1],
1522 aPnt[2] - aDelta[0][2] + aDelta[1][2] };
1523 double aPnt12[3] = { aPnt11[0] + aNormal[0],
1524 aPnt11[1] + aNormal[1],
1525 aPnt11[2] + aNormal[2] };
1526 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1528 double aPnt21[3] = { aPnt[0] + aDelta[0][0] - aDelta[1][0],
1529 aPnt[1] + aDelta[0][1] - aDelta[1][1],
1530 aPnt[2] + aDelta[0][2] - aDelta[1][2] };
1531 double aPnt22[3] = { aPnt21[0] + aNormal[0],
1532 aPnt21[1] + aNormal[1],
1533 aPnt21[2] + aNormal[2] };
1534 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1536 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1538 aPlaneSource->SetNormal( aNormal[0], aNormal[1], aNormal[2] );
1539 aPlaneSource->SetOrigin( aPnt0[0], aPnt0[1], aPnt0[2] );
1540 aPlaneSource->SetPoint1( aPnt1[0], aPnt1[1], aPnt1[2] );
1541 aPlaneSource->SetPoint2( aPnt2[0], aPnt2[1], aPnt2[2] );
1542 aPlaneSource->Update();
1545 setBoundsForPreviewWidget();
1547 myPreviewWidget->SetOrigin( anOrigin );
1548 myPreviewWidget->SetNormal( aNormal );
1550 if(AutoApplyCheckBox->isChecked())
1553 SMESH::RenderViewWindow( myViewWindow );
1557 Set current bounds for preview widget
1559 void SMESHGUI_ClippingDlg::setBoundsForPreviewWidget()
1561 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1562 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
1563 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
1564 SMESH::TActorList anActorList = aPlaneData.ActorList;
1566 double* anOrigin = aPlane->GetOrigin();
1569 SMESH::ComputeBounds( anActorList, aBounds );
1571 bool isBoundsChanged = false;
1573 if( myIsPreviewMoved ) {
1574 // if widget has moved by hand the bounds can to minimize
1575 if( anOrigin[0] > myBounds[0] && anOrigin[0] < aBounds[0] ) {
1576 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1577 if( anOrigin[0] < myBounds[1] && anOrigin[0] > aBounds[1] ) {
1578 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1579 if( anOrigin[1] > myBounds[2] && anOrigin[1] < aBounds[2] ) {
1580 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1581 if( anOrigin[1] < myBounds[3] && anOrigin[1] > aBounds[3] ) {
1582 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1583 if( anOrigin[2] > myBounds[4] && anOrigin[2] < aBounds[4] ) {
1584 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1585 if( anOrigin[2] < myBounds[5] && anOrigin[2] > aBounds[5] ) {
1586 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1589 // if widget has moved by dialog data the bounds can to take necessary size
1590 if( anOrigin[0] < aBounds[0] ) {
1591 myBounds[0] = anOrigin[0]; isBoundsChanged = true; }
1592 if( anOrigin[0] > aBounds[1] ) {
1593 myBounds[1] = anOrigin[0]; isBoundsChanged = true; }
1594 if( anOrigin[1] < aBounds[2] ) {
1595 myBounds[2] = anOrigin[1]; isBoundsChanged = true; }
1596 if( anOrigin[1] > aBounds[3] ) {
1597 myBounds[3] = anOrigin[1]; isBoundsChanged = true; }
1598 if( anOrigin[2] < aBounds[4] ) {
1599 myBounds[4] = anOrigin[2]; isBoundsChanged = true; }
1600 if( anOrigin[2] > aBounds[5] ) {
1601 myBounds[5] = anOrigin[2]; isBoundsChanged = true; }
1604 if( isBoundsChanged )
1605 myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2],
1606 myBounds[3],myBounds[4],myBounds[5] );
1607 else if( !myIsPreviewMoved )
1608 myPreviewWidget->PlaceWidget( aBounds[0],aBounds[1],aBounds[2],
1609 aBounds[3],aBounds[4],aBounds[5] );
1614 Convert absolute coordinates of plane to relative mode
1616 void SMESHGUI_ClippingDlg::absolutePlaneToRelative ( double theOrigin[3], double theDir[3] )
1620 aRot[0] = getRotation1();
1621 aRot[1] = getRotation2();
1623 double eps = 0.0001;
1625 int anOrientation = CBRelativeOrientation->currentIndex();
1626 double aDirection[3] = { 0.,0.,0. };
1627 double aRotation1 = 0, aRotation2 = 0;
1628 switch( anOrientation ) {
1630 aDirection[0] = theDir[0] + eps;
1631 aDirection[1] = theDir[1] + eps;
1632 aDirection[2] = theDir[2] + eps;
1633 aRotation1 = atan2( theDir[2], theDir[1] )*180.0/M_PI;
1634 aRotation2 = atan2( theDir[2], theDir[0] )*180.0/M_PI;
1637 aDirection[0] = theDir[1] + eps;
1638 aDirection[1] = theDir[2] + eps;
1639 aDirection[2] = theDir[0] + eps;
1640 aRotation1 = atan2( theDir[0], theDir[2] )*180.0/M_PI;
1641 aRotation2 = atan2( theDir[0], theDir[1] )*180.0/M_PI;
1644 aDirection[0] = theDir[2] + eps;
1645 aDirection[1] = theDir[0] + eps;
1646 aDirection[2] = theDir[1] + eps;
1647 aRotation1 = atan2( theDir[1], theDir[0] )*180.0/M_PI;
1648 aRotation2 = atan2( theDir[1], theDir[2] )*180.0/M_PI;
1652 if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1653 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1654 else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1655 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 90.0; }
1656 else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1657 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 + 90.0; }
1658 else if( aDirection[0] > 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1659 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 90.0; }
1660 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1661 aRot[0] = aRotation1 - 270.0; aRot[1] = aRotation2 + 90.0; }
1662 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1663 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1664 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1665 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 90.0; }
1666 else if( aDirection[0] > 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1667 aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
1668 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1669 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1670 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1671 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 - 270.0; }
1672 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1673 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 + 90.0; }
1674 else if( aDirection[0] < 0 && aDirection[1] > 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1675 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
1676 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] <= 0 ) {
1677 aRot[0] = aRotation1 - 270.0; aRot[1] = aRotation2 - 270.0; }
1678 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] > 0 && aRot[0] > 0 ) {
1679 aRot[0] = aRotation1 - 90.0; aRot[1] = aRotation2 - 90.0; }
1680 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] <= 0 ) {
1681 aRot[0] = aRotation1 + 90.0; aRot[1] = aRotation2 + 270.0; }
1682 else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) {
1683 aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; }
1685 SpinSliderRotation1->setValue( qRound( aRot[0] ) );
1686 SpinSliderRotation2->setValue( qRound( aRot[1] ) );
1688 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1689 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1690 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1694 SMESH::ComputeBounds( anActorList, aBounds );
1695 SMESH::PositionToDistance( aBounds, theDir, theOrigin, aDist );
1696 aDist = 1.0 - aDist;
1699 else if( aDist < 0.0 )
1702 SpinSliderDistance->setValue( qRound( aDist*100 ) );
1707 SLOT: called on preview check box toggled
1709 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1711 std::for_each( myPlanes.begin(), myPlanes.end(), TSetVisibility( theIsToggled ) );
1712 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1713 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1714 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1715 aPlaneData->myActor->SetVisibility( false );
1717 myPreviewWidget->On();
1719 myPreviewWidget->Off();
1720 SMESH::RenderViewWindow( myViewWindow );
1724 SLOT: called on Auto Apply check box toggled
1726 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1728 if ( toggled ) ClickOnApply();
1732 SLOT on ok button click: sets cutting plane and closes dialog
1734 void SMESHGUI_ClippingDlg::ClickOnOk()
1742 SLOT on Apply button click: sets cutting plane and update viewer
1744 void SMESHGUI_ClippingDlg::ClickOnApply()
1747 SUIT_OverrideCursor wc;
1749 QWidget *aCurrWid = this->focusWidget();
1750 aCurrWid->clearFocus();
1751 aCurrWid->setFocus();
1753 SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1754 SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
1756 // clean memory allocated for planes
1757 SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
1758 for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
1759 if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
1762 aClippingPlaneInfoList.clear();
1764 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1765 vtkActorCollection* anAllActors = aCopy.GetActors();
1766 anAllActors->InitTraversal();
1767 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1768 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1769 anActor->RemoveAllClippingPlanes();
1771 SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
1772 for( ; anIter2 != myPlanes.end(); anIter2++ ) {
1773 SMESH::TPlaneData aPlaneData = *anIter2;
1774 SMESH::TPlane aPlane = aPlaneData.Plane;
1775 SMESH::TActorList anActorList = aPlaneData.ActorList;
1777 // the check is disabled to support planes with empty actor list
1778 //if( anActorList.empty() )
1781 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1782 anOrientedPlane->ShallowCopy(aPlane.GetPointer());
1783 SMESH::TActorList::iterator anIter3 = anActorList.begin();
1784 for( ; anIter3 != anActorList.end(); anIter3++ )
1785 if( vtkActor* aVTKActor = *anIter3 )
1786 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1787 if( anOrientedPlane->IsOpenGLClipping )
1788 anActor->AddOpenGLClippingPlane( anOrientedPlane->InvertPlane() );
1790 anActor->AddClippingPlane( anOrientedPlane );
1793 SMESH::ClippingPlaneInfo aClippingPlaneInfo;
1794 aClippingPlaneInfo.Plane = anOrientedPlane;
1795 aClippingPlaneInfo.ActorList = anActorList;
1797 aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
1800 anAllActors->InitTraversal();
1801 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
1802 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1803 anActor->SetOpenGLClippingPlane();
1806 SMESH::RenderViewWindow( myViewWindow );
1811 SLOT on help button click: opens a help page
1813 void SMESHGUI_ClippingDlg::ClickOnHelp()
1815 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1817 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1821 platform = "winapplication";
1823 platform = "application";
1825 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1826 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1827 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1829 arg(myHelpFileName));
1833 void SMESHGUI_ClippingDlg::onSelectAbsoluteOrientation( int mode )
1835 bool isUserMode = (mode==0);
1837 TextLabelX->setEnabled( isUserMode );
1838 TextLabelY->setEnabled( isUserMode );
1839 TextLabelZ->setEnabled( isUserMode );
1841 SpinBox_X->setEnabled( isUserMode );
1842 SpinBox_Y->setEnabled( isUserMode );
1843 SpinBox_Z->setEnabled( isUserMode );
1845 TextLabelDx->setEnabled( isUserMode );
1846 TextLabelDy->setEnabled( isUserMode );
1847 TextLabelDz->setEnabled( isUserMode );
1849 SpinBox_Dx->setEnabled( isUserMode );
1850 SpinBox_Dy->setEnabled( isUserMode );
1851 SpinBox_Dz->setEnabled( isUserMode );
1856 double aDx = 0, aDy = 0, aDz = 0;
1861 TextLabelZ->setEnabled( true );
1862 SpinBox_Z->setEnabled( true );
1863 SpinBox_Z->setFocus();
1865 else if ( mode == 2 )
1868 TextLabelX->setEnabled( true );
1869 SpinBox_X->setEnabled( true );
1870 SpinBox_X->setFocus();
1872 else if ( mode == 3 )
1875 TextLabelY->setEnabled( true );
1876 SpinBox_Y->setEnabled( true );
1877 SpinBox_Y->setFocus();
1880 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1881 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1882 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1884 if ( aPlaneData->IsInvert == true ) {
1885 aDx = -aDx; aDy = -aDy; aDz = -aDz;
1888 myIsSelectPlane = true;
1889 SpinBox_Dx->setValue( aDx );
1890 SpinBox_Dy->setValue( aDy );
1891 SpinBox_Dz->setValue( aDz );
1892 myIsSelectPlane = false;
1894 SetCurrentPlaneParam();
1898 SLOT: called on orientation of clipping plane in relative mode changed
1900 void SMESHGUI_ClippingDlg::onSelectRelativeOrientation ( int theItem )
1902 if ( myPlanes.empty() )
1905 if ( theItem == 0 ) {
1906 TextLabelRotation1->setText( tr( "ROTATION_AROUND_X_Y2Z" ) );
1907 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Y_X2Z" ) );
1909 else if ( theItem == 1 ) {
1910 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Y_Z2X" ) );
1911 TextLabelRotation2->setText( tr( "ROTATION_AROUND_Z_Y2X" ) );
1913 else if ( theItem == 2 ) {
1914 TextLabelRotation1->setText( tr( "ROTATION_AROUND_Z_X2Y" ) );
1915 TextLabelRotation2->setText( tr( "ROTATION_AROUND_X_Z2Y" ) );
1918 if( (QComboBox*)sender() == CBRelativeOrientation )
1919 SetCurrentPlaneParam();
1923 SLOT on reset button click: sets default values
1925 void SMESHGUI_ClippingDlg::onReset()
1927 myIsSelectPlane = true;
1928 SpinBox_X->setValue(0);
1929 SpinBox_Y->setValue(0);
1930 SpinBox_Z->setValue(0);
1931 myIsSelectPlane = false;
1933 SetCurrentPlaneParam();
1937 SLOT on invert button click: inverts normal of cutting plane
1939 void SMESHGUI_ClippingDlg::onInvert()
1941 double Dx = SpinBox_Dx->value();
1942 double Dy = SpinBox_Dy->value();
1943 double Dz = SpinBox_Dz->value();
1945 myIsSelectPlane = true;
1946 SpinBox_Dx->setValue( -Dx );
1947 SpinBox_Dy->setValue( -Dy );
1948 SpinBox_Dz->setValue( -Dz );
1949 myIsSelectPlane = false;
1951 if ( !myPlanes.empty() ) {
1952 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1953 SMESH::TPlaneData aPlane = myPlanes[aCurPlaneIndex];
1954 SMESH::OrientedPlane* aPlaneData = aPlane.Plane.GetPointer();
1955 aPlaneData->IsInvert = !aPlaneData->IsInvert;
1957 SetCurrentPlaneParam();