1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_ClippingDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
28 #include "SMESHGUI_ClippingDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_SpinBox.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
38 // SALOME GUI includes
39 #include <SUIT_Desktop.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_OverrideCursor.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_ViewManager.h>
46 #include <SALOME_ListIO.hxx>
48 #include <SalomeApp_Study.h>
50 #include <LightApp_Application.h>
52 #include <VTKViewer_Algorithm.h>
54 #include <SVTK_ViewWindow.h>
58 #include <QPushButton>
61 #include <QVBoxLayout>
62 #include <QHBoxLayout>
63 #include <QGridLayout>
66 #include <QListWidget>
70 #include <vtkDataSet.h>
71 #include <vtkDataSetMapper.h>
72 #include <vtkPlaneSource.h>
73 #include <vtkProperty.h>
74 #include <vtkRenderer.h>
79 //=================================================================================
80 // class : OrientedPlane
82 //=================================================================================
83 SMESH::OrientedPlane* SMESH::OrientedPlane::New()
85 return new OrientedPlane();
88 SMESH::OrientedPlane* SMESH::OrientedPlane::New(SVTK_ViewWindow* theViewWindow)
90 return new OrientedPlane(theViewWindow);
93 void SMESH::OrientedPlane::ShallowCopy(SMESH::OrientedPlane* theOrientedPlane)
95 SetNormal(theOrientedPlane->GetNormal());
96 SetOrigin(theOrientedPlane->GetOrigin());
98 myOrientation = theOrientedPlane->GetOrientation();
99 myDistance = theOrientedPlane->GetDistance();
101 myAngle[0] = theOrientedPlane->myAngle[0];
102 myAngle[1] = theOrientedPlane->myAngle[1];
104 myPlaneSource->SetNormal(theOrientedPlane->myPlaneSource->GetNormal());
105 myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
106 myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
107 myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
110 SMESH::OrientedPlane::OrientedPlane(SVTK_ViewWindow* theViewWindow):
111 myViewWindow(theViewWindow),
112 myOrientation(SMESH::XY),
116 myViewWindow->AddActor(myActor, false, false); // don't adjust actors
119 SMESH::OrientedPlane::OrientedPlane():
120 myOrientation(SMESH::XY),
127 void SMESH::OrientedPlane::Init()
129 myPlaneSource = vtkPlaneSource::New();
131 myAngle[0] = myAngle[1] = 0.0;
133 // Create and display actor
134 myMapper = vtkDataSetMapper::New();
135 myMapper->SetInput(myPlaneSource->GetOutput());
137 myActor = SALOME_Actor::New();
138 myActor->VisibilityOff();
139 myActor->PickableOff();
140 myActor->SetInfinitive(true);
141 myActor->SetMapper(myMapper);
143 vtkFloatingPointType anRGB[3];
144 vtkProperty* aProp = vtkProperty::New();
145 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
146 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
147 aProp->SetOpacity(0.75);
148 myActor->SetProperty(aProp);
151 vtkProperty* aBackProp = vtkProperty::New();
152 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
153 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
154 aBackProp->SetOpacity(0.75);
155 myActor->SetBackfaceProperty(aBackProp);
159 SMESH::OrientedPlane::~OrientedPlane()
162 myViewWindow->RemoveActor(myActor);
165 myMapper->RemoveAllInputs();
168 // commented: porting to vtk 5.0
169 // myPlaneSource->UnRegisterAllOutputs();
170 myPlaneSource->Delete();
173 //=================================================================================
176 //=================================================================================
177 class ActorItem : public QListWidgetItem
180 ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) :
181 QListWidgetItem( theName, theListWidget ),
182 myActor( theActor ) {}
184 SMESH_Actor* getActor() const { return myActor; }
187 SMESH_Actor* myActor;
190 //=================================================================================
191 // class : TSetVisibility
193 //=================================================================================
194 struct TSetVisibility {
195 TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){}
196 void operator()(SMESH::TPlaneData& thePlaneData){
197 bool anIsEmpty = thePlaneData.ActorList.empty();
198 thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty);
203 //=================================================================================
204 // used in SMESHGUI::restoreVisualParameters() to avoid
205 // declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
206 //=================================================================================
207 SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList theActorList,
208 SVTK_ViewWindow* theViewWindow,
209 SMESH::Orientation theOrientation,
211 const vtkFloatingPointType theAngle[2])
213 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(theViewWindow);
215 aPlane->myAngle[0] = theAngle[0];
216 aPlane->myAngle[1] = theAngle[1];
218 aPlane->SetOrientation(theOrientation);
219 aPlane->SetDistance(theDistance);
221 vtkFloatingPointType aNormal[3];
222 vtkFloatingPointType aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
224 static double aCoeff = vtkMath::Pi()/180.0;
226 vtkFloatingPointType anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
227 vtkFloatingPointType aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
228 aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
229 aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
231 switch (theOrientation) {
258 vtkMath::Cross(aDir[1],aDir[0],aNormal);
259 vtkMath::Normalize(aNormal);
260 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
263 vtkFloatingPointType aBounds[6];
264 vtkFloatingPointType anOrigin[3];
267 if( theActorList.empty() ) {
268 // to support planes with empty actor list we should create
269 // a nullified plane that will be initialized later
270 anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
271 aBounds[0] = aBounds[2] = aBounds[4] = 0;
272 aBounds[1] = aBounds[3] = aBounds[5] = 0;
276 anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
284 aPlane->SetNormal( aNormal );
285 aPlane->SetOrigin( anOrigin );
287 vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
288 ( aBounds[2] + aBounds[3] ) / 2.,
289 ( aBounds[4] + aBounds[5] ) / 2. };
291 vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
292 pow( aBounds[3] - aBounds[2], 2 ) +
293 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
295 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
296 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
297 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
299 vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
300 aPnt[1] - aDelta[0][1] - aDelta[1][1],
301 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
302 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
303 aPnt01[1] + aNormal[1],
304 aPnt01[2] + aNormal[2]};
305 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
307 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
308 aPnt[1] - aDelta[0][1] + aDelta[1][1],
309 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
310 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
311 aPnt11[1] + aNormal[1],
312 aPnt11[2] + aNormal[2]};
313 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
315 vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
316 aPnt[1] + aDelta[0][1] - aDelta[1][1],
317 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
318 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
319 aPnt21[1] + aNormal[1],
320 aPnt21[2] + aNormal[2]};
321 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
323 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
324 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
325 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
326 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
327 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
329 SMESH::TActorList::iterator anIter = theActorList.begin();
330 for ( ; anIter != theActorList.end(); anIter++ )
331 if( vtkActor* aVTKActor = *anIter )
332 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
333 anActor->AddClippingPlane( aPlane );
338 //=================================================================================
339 // class : SMESHGUI_ClippingDlg()
342 //=================================================================================
343 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
344 QDialog( SMESH::GetDesktop(theModule) ),
345 mySMESHGUI(theModule),
346 myViewWindow(theViewWindow)
349 setAttribute( Qt::WA_DeleteOnClose, true );
350 setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
351 setSizeGripEnabled(true);
353 QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
354 SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
355 SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
357 // Controls for selecting, creating, deleting planes
358 QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
359 QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
360 GroupPlanesLayout->setSpacing(SPACING);
361 GroupPlanesLayout->setMargin(MARGIN);
363 ComboBoxPlanes = new QComboBox(GroupPlanes);
365 buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
367 buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
369 QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
371 ActorList = new QListWidget(GroupPlanes);
372 ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
374 SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
376 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
377 GroupPlanesLayout->addWidget(new QWidget(), 0, 1);
378 GroupPlanesLayout->addWidget(buttonNew, 0, 2);
379 GroupPlanesLayout->addWidget(buttonDelete, 0, 3);
380 GroupPlanesLayout->addWidget(aLabel, 1, 0, 1, 4);
381 GroupPlanesLayout->addWidget(ActorList, 2, 0, 1, 4);
382 GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 4);
383 GroupPlanesLayout->setColumnStretch( 1, 1 );
385 // Controls for defining plane parameters
386 QGroupBox* GroupParameters = new QGroupBox(tr("SMESH_PARAMETERS"), this);
387 QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
388 GroupParametersLayout->setSpacing(SPACING);
389 GroupParametersLayout->setMargin(MARGIN);
391 TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
393 ComboBoxOrientation = new QComboBox(GroupParameters);
395 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
397 SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
399 TextLabelRot1 = new QLabel(tr("ROTATION_AROUND_X_Y2Z"), GroupParameters);
401 SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
403 TextLabelRot2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
405 SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
407 PreviewCheckBox = new QCheckBox(tr("SHOW_PREVIEW"), GroupParameters);
408 PreviewCheckBox->setChecked(true);
410 AutoApplyCheckBox = new QCheckBox(tr("AUTO_APPLY"), GroupParameters);
411 AutoApplyCheckBox->setChecked(false);
413 GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
414 GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
415 GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
416 GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
417 GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
418 GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
419 GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
420 GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
421 GroupParametersLayout->addWidget(PreviewCheckBox, 4, 0);
422 GroupParametersLayout->addWidget(AutoApplyCheckBox, 4, 1);
424 // Controls for "Ok", "Apply" and "Close" button
425 QGroupBox* GroupButtons = new QGroupBox(this);
426 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
427 GroupButtonsLayout->setSpacing(SPACING);
428 GroupButtonsLayout->setMargin(MARGIN);
430 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
431 buttonOk->setAutoDefault(true);
432 buttonOk->setDefault(true);
433 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
434 buttonApply->setAutoDefault(true);
435 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
436 buttonCancel->setAutoDefault(true);
437 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
438 buttonHelp->setAutoDefault(true);
439 GroupButtonsLayout->addWidget(buttonOk);
440 GroupButtonsLayout->addSpacing(10);
441 GroupButtonsLayout->addWidget(buttonApply);
442 GroupButtonsLayout->addSpacing(10);
443 GroupButtonsLayout->addStretch();
444 GroupButtonsLayout->addWidget(buttonCancel);
445 GroupButtonsLayout->addWidget(buttonHelp);
447 SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
448 SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
449 SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
452 SpinBoxDistance->RangeStepAndValidator(0.0, 1.0, 0.01, "length_precision" );
453 SpinBoxRot1->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
454 SpinBoxRot2->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
456 ComboBoxOrientation->addItem(tr("ALONG_XY"));
457 ComboBoxOrientation->addItem(tr("ALONG_YZ"));
458 ComboBoxOrientation->addItem(tr("ALONG_ZX"));
460 SpinBoxDistance->SetValue(0.5);
462 myIsSelectPlane = false;
464 initializePlaneData();
467 myHelpFileName = "clipping_page.html";
469 // signals and slots connections :
470 connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
471 connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
472 connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
473 connect(ActorList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onActorItemChanged(QListWidgetItem*)));
474 connect(SelectAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onSelectAll(int)));
475 connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
476 connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
477 connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
478 connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
479 connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
480 connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(onAutoApply(bool)));
481 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
482 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
483 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
484 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
485 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
486 /* to close dialog if study frame change */
487 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(reject()));
492 //=================================================================================
493 // function : ~SMESHGUI_ClippingDlg()
495 //=================================================================================
496 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
498 // no need to delete child widgets, Qt does it all for us
499 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
501 SMESH::RenderViewWindow(myViewWindow);
504 double SMESHGUI_ClippingDlg::getDistance() const
506 return SpinBoxDistance->GetValue();
509 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
511 SpinBoxDistance->SetValue( theDistance );
514 double SMESHGUI_ClippingDlg::getRotation1() const
516 return SpinBoxRot1->GetValue();
519 double SMESHGUI_ClippingDlg::getRotation2() const
521 return SpinBoxRot2->GetValue();
524 //=======================================================================
525 // function : ClickOnApply()
527 //=======================================================================
528 void SMESHGUI_ClippingDlg::ClickOnApply()
531 SUIT_OverrideCursor wc;
533 QWidget *aCurrWid = this->focusWidget();
534 aCurrWid->clearFocus();
535 aCurrWid->setFocus();
537 SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
538 SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
540 // clean memory allocated for planes
541 SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
542 for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
543 if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
546 aClippingPlaneInfoList.clear();
548 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
549 vtkActorCollection* anAllActors = aCopy.GetActors();
550 anAllActors->InitTraversal();
551 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
552 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
553 anActor->RemoveAllClippingPlanes();
555 SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
556 for( ; anIter2 != myPlanes.end(); anIter2++ ) {
557 SMESH::TPlaneData aPlaneData = *anIter2;
558 SMESH::TPlane aPlane = aPlaneData.Plane;
559 SMESH::TActorList anActorList = aPlaneData.ActorList;
561 // the check is disabled to support planes with empty actor list
562 //if( anActorList.empty() )
565 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
566 anOrientedPlane->ShallowCopy(aPlane.GetPointer());
568 SMESH::TActorList::iterator anIter3 = anActorList.begin();
569 for( ; anIter3 != anActorList.end(); anIter3++ )
570 if( vtkActor* aVTKActor = *anIter3 )
571 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
572 anActor->AddClippingPlane(anOrientedPlane);
574 SMESH::ClippingPlaneInfo aClippingPlaneInfo;
575 aClippingPlaneInfo.Plane = anOrientedPlane;
576 aClippingPlaneInfo.ActorList = anActorList;
578 aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
581 SMESH::RenderViewWindow( myViewWindow );
585 //=======================================================================
586 // function : ClickOnOk()
588 //=======================================================================
589 void SMESHGUI_ClippingDlg::ClickOnOk()
595 //=======================================================================
596 // function : reject()
598 //=======================================================================
599 void SMESHGUI_ClippingDlg::reject()
601 //here we can insert actions to do at close.
605 //=================================================================================
606 // function : ClickOnHelp()
608 //=================================================================================
609 void SMESHGUI_ClippingDlg::ClickOnHelp()
611 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
613 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
617 platform = "winapplication";
619 platform = "application";
621 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
622 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
623 arg(app->resourceMgr()->stringValue("ExternalBrowser",
625 arg(myHelpFileName));
629 //=======================================================================
630 // function : onSelectPlane()
632 //=======================================================================
633 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
635 if (myPlanes.empty())
638 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
639 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
642 SMESH::Orientation anOrientation = aPlane->GetOrientation();
645 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
647 // Set plane parameters in the dialog
648 myIsSelectPlane = true;
649 setDistance(aPlane->GetDistance());
650 setRotation(aRot[0], aRot[1]);
651 switch (anOrientation) {
653 ComboBoxOrientation->setCurrentIndex(0);
654 onSelectOrientation(0);
657 ComboBoxOrientation->setCurrentIndex(1);
658 onSelectOrientation(1);
661 ComboBoxOrientation->setCurrentIndex(2);
662 onSelectOrientation(2);
665 myIsSelectPlane = false;
668 bool anIsBlocked = ActorList->blockSignals( true );
670 ActorList->blockSignals( anIsBlocked );
673 //=======================================================================
674 // function : ClickOnNew()
676 //=======================================================================
677 void SMESHGUI_ClippingDlg::ClickOnNew()
680 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
681 SMESH::TPlane aTPlane(aPlane);
683 SMESH::TActorList anActorList;
684 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
685 vtkActorCollection* anAllActors = aCopy.GetActors();
686 anAllActors->InitTraversal();
687 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
688 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
689 anActorList.push_back( anActor );
691 SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
693 myPlanes.push_back(aPlaneData);
695 if (PreviewCheckBox->isChecked())
696 aTPlane->myActor->VisibilityOn();
698 bool anIsBlocked = ActorList->blockSignals( true );
701 SetCurrentPlaneParam();
703 ActorList->blockSignals( anIsBlocked );
707 //=======================================================================
708 // function : ClickOnDelete()
710 //=======================================================================
711 void SMESHGUI_ClippingDlg::ClickOnDelete()
713 if (myPlanes.empty())
716 int aPlaneIndex = ComboBoxPlanes->currentIndex();
718 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
719 SMESH::TPlaneData aPlaneData = *anIter;
720 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
721 myPlanes.erase(anIter);
723 if(AutoApplyCheckBox->isChecked())
727 SMESH::RenderViewWindow( myViewWindow );
730 //=======================================================================
731 // function : updateActorItem()
733 //=======================================================================
734 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
735 bool theUpdateSelectAll,
736 bool theUpdateClippingPlaneMap )
738 // update Select All check box
739 if( theUpdateSelectAll ) {
740 int aNbItems = ActorList->count(), aNbChecked = 0;
741 for( int i = 0; i < aNbItems; i++ )
742 if( QListWidgetItem* anItem = ActorList->item( i ) )
743 if( anItem->checkState() == Qt::Checked )
746 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
747 SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
748 SelectAllCheckBox->blockSignals( anIsBlocked );
751 // update clipping plane map
752 if( theUpdateClippingPlaneMap ) {
753 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
754 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
755 if( SMESH_Actor* anActor = anItem->getActor() ) {
756 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
757 SMESH::TActorList& anActorList = aPlaneData.ActorList;
758 bool anIsPushed = false;
759 SMESH::TActorList::iterator anIter = anActorList.begin();
760 for ( ; anIter != anActorList.end(); anIter++ ) {
761 if( anActor == *anIter ) {
766 if( theItem->checkState() == Qt::Checked && !anIsPushed )
767 anActorList.push_back( anActor );
768 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
769 anActorList.remove( anActor );
775 //=======================================================================
776 // function : onActorItemChanged()
778 //=======================================================================
779 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
781 updateActorItem( theItem, true, true );
782 SetCurrentPlaneParam();
785 //=======================================================================
786 // function : onSelectAll()
788 //=======================================================================
789 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
791 if( theState == Qt::PartiallyChecked ) {
792 SelectAllCheckBox->setCheckState( Qt::Checked );
796 bool anIsBlocked = ActorList->blockSignals( true );
797 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
798 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
799 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
800 updateActorItem( anItem, false, true );
803 SelectAllCheckBox->setTristate( false );
804 ActorList->blockSignals( anIsBlocked );
805 SetCurrentPlaneParam();
808 //=======================================================================
809 // function : onSelectOrientation()
811 //=======================================================================
812 void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
814 if (myPlanes.empty())
818 TextLabelRot1->setText(tr("ROTATION_AROUND_X_Y2Z"));
819 TextLabelRot2->setText(tr("ROTATION_AROUND_Y_X2Z"));
821 else if (theItem == 1) {
822 TextLabelRot1->setText(tr("ROTATION_AROUND_Y_Z2X"));
823 TextLabelRot2->setText(tr("ROTATION_AROUND_Z_Y2X"));
825 else if (theItem == 2) {
826 TextLabelRot1->setText(tr("ROTATION_AROUND_Z_X2Y"));
827 TextLabelRot2->setText(tr("ROTATION_AROUND_X_Z2Y"));
830 if((QComboBox*)sender() == ComboBoxOrientation)
831 SetCurrentPlaneParam();
834 //=======================================================================
835 // function : synchronize()
837 //=======================================================================
838 void SMESHGUI_ClippingDlg::synchronize()
840 int aNbPlanes = myPlanes.size();
841 ComboBoxPlanes->clear();
844 for(int i = 1; i<=aNbPlanes; i++) {
845 aName = QString(tr("PLANE_NUM")).arg(i);
846 ComboBoxPlanes->addItem(aName);
849 int aPos = ComboBoxPlanes->count() - 1;
850 ComboBoxPlanes->setCurrentIndex(aPos);
852 bool anIsControlsEnable = (aPos >= 0);
853 if (anIsControlsEnable) {
857 ComboBoxPlanes->addItem(tr("NO_PLANES"));
859 SpinBoxRot1->SetValue(0.0);
860 SpinBoxRot2->SetValue(0.0);
861 SpinBoxDistance->SetValue(0.5);
864 ActorList->setEnabled(anIsControlsEnable);
865 SelectAllCheckBox->setEnabled(anIsControlsEnable);
866 buttonDelete->setEnabled(anIsControlsEnable);
867 // the following 3 controls should be enabled
868 //buttonApply->setEnabled(anIsControlsEnable);
869 //PreviewCheckBox->setEnabled(anIsControlsEnable);
870 //AutoApplyCheckBox->setEnabled(anIsControlsEnable);
871 ComboBoxOrientation->setEnabled(anIsControlsEnable);
872 SpinBoxDistance->setEnabled(anIsControlsEnable);
873 SpinBoxRot1->setEnabled(anIsControlsEnable);
874 SpinBoxRot2->setEnabled(anIsControlsEnable);
877 //=======================================================================
878 // function : setRotation()
880 //=======================================================================
881 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
883 SpinBoxRot1->SetValue(theRot1);
884 SpinBoxRot2->SetValue(theRot2);
887 //=======================================================================
888 // function : SetCurrentPlaneParam()
890 //=======================================================================
891 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
893 if (myPlanes.empty() || myIsSelectPlane)
896 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
898 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
899 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
901 vtkFloatingPointType aNormal[3];
902 SMESH::Orientation anOrientation;
903 vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
905 static double aCoeff = vtkMath::Pi()/180.0;
907 vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
908 aPlane->myAngle[0] = aRot[0];
909 aPlane->myAngle[1] = aRot[1];
911 vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
912 vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
913 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
914 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
916 switch (ComboBoxOrientation->currentIndex()) {
918 anOrientation = SMESH::XY;
928 anOrientation = SMESH::YZ;
938 anOrientation = SMESH::ZX;
949 vtkMath::Cross(aDir[1],aDir[0],aNormal);
950 vtkMath::Normalize(aNormal);
951 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
954 aPlane->SetOrientation(anOrientation);
955 aPlane->SetDistance(getDistance());
957 SMESH::TActorList anActorList = aPlaneData.ActorList;
959 vtkFloatingPointType aBounds[6];
960 vtkFloatingPointType anOrigin[3];
961 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
967 aPlane->myActor->SetVisibility( anIsOk && PreviewCheckBox->isChecked() );
970 aPlane->SetNormal( aNormal );
971 aPlane->SetOrigin( anOrigin );
973 vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
974 ( aBounds[2] + aBounds[3] ) / 2.,
975 ( aBounds[4] + aBounds[5] ) / 2. };
977 vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
978 pow( aBounds[3] - aBounds[2], 2 ) +
979 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
981 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
982 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
983 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
985 vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
986 aPnt[1] - aDelta[0][1] - aDelta[1][1],
987 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
988 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
989 aPnt01[1] + aNormal[1],
990 aPnt01[2] + aNormal[2]};
991 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
993 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
994 aPnt[1] - aDelta[0][1] + aDelta[1][1],
995 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
996 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
997 aPnt11[1] + aNormal[1],
998 aPnt11[2] + aNormal[2]};
999 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1001 vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
1002 aPnt[1] + aDelta[0][1] - aDelta[1][1],
1003 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
1004 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
1005 aPnt21[1] + aNormal[1],
1006 aPnt21[2] + aNormal[2]};
1007 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1009 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1010 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
1011 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
1012 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
1013 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
1016 if(AutoApplyCheckBox->isChecked())
1019 SMESH::RenderViewWindow( myViewWindow );
1022 //=======================================================================
1023 // function : OnPreviewToggle()
1025 //=======================================================================
1026 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1028 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1029 SMESH::RenderViewWindow( myViewWindow );
1032 //=================================================================================
1033 // function : keyPressEvent()
1035 //=================================================================================
1036 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1038 QDialog::keyPressEvent( e );
1039 if ( e->isAccepted() )
1042 if ( e->key() == Qt::Key_F1 ) {
1048 //=================================================================================
1049 // function : initializePlaneData()
1051 //=================================================================================
1052 void SMESHGUI_ClippingDlg::initializePlaneData()
1054 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1055 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
1056 if( anIter1 != aClippingPlaneInfoMap.end() ) {
1057 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
1058 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
1059 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
1060 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
1061 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1062 anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
1063 SMESH::TPlane aTPlane( anOrientedPlane );
1064 SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
1065 myPlanes.push_back( aPlaneData );
1068 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1071 //=================================================================================
1072 // function : updateActorList()
1074 //=================================================================================
1075 void SMESHGUI_ClippingDlg::updateActorList()
1079 SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1083 _PTR(Study) aStudy = anAppStudy->studyDS();
1090 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1091 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1092 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1094 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1095 vtkActorCollection* anAllActors = aCopy.GetActors();
1096 anAllActors->InitTraversal();
1097 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1098 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1099 if( anActor->hasIO() ) {
1100 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1101 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1102 bool anIsChecked = false;
1103 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1104 for ( ; anIter != anActorList.end(); anIter++ ) {
1105 if( vtkActor* aVTKActorRef = *anIter ) {
1106 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1107 if( anActorRef == anActor ) {
1114 QString aName = QString( aSObj->GetName().c_str() );
1115 QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
1116 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1117 updateActorItem( anItem, true, false );
1124 //=================================================================================
1125 // function : getCurrentActors()
1127 //=================================================================================
1128 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1130 SMESH::TActorList anActorList;
1131 for( int i = 0, n = ActorList->count(); i < n; i++ )
1132 if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1133 if( anItem->checkState() == Qt::Checked )
1134 if( SMESH_Actor* anActor = anItem->getActor() )
1135 anActorList.push_back( anActor );
1139 //=================================================================================
1140 // function : dumpPlaneData()
1142 //=================================================================================
1143 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1145 printf( "----------- Plane Data -----------\n" );
1147 SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1148 for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1149 SMESH::TPlaneData aPlaneData = *anIter1;
1150 SMESH::TPlane aPlane = aPlaneData.Plane;
1151 vtkFloatingPointType* aNormal = aPlane->GetNormal();
1152 vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
1153 printf( "Plane N%d:\n", anId );
1154 printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1155 printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1157 SMESH::TActorList anActorList = aPlaneData.ActorList;
1158 SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1159 for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1160 if( vtkActor* aVTKActor = *anIter2 ) {
1161 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1162 printf( " - Actor: '%s'\n", anActor->getName() );
1165 printf( " - Actor: NULL\n");
1168 printf( "----------------------------------\n" );
1171 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1173 if ( toggled ) ClickOnApply();