1 // Copyright (C) 2007-2012 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(ClickOnCancel()));
483 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
484 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
485 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
486 /* to close dialog if study frame change */
487 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(ClickOnCancel()));
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 : ClickOnCancel()
598 //=======================================================================
599 void SMESHGUI_ClippingDlg::ClickOnCancel()
604 //=================================================================================
605 // function : ClickOnHelp()
607 //=================================================================================
608 void SMESHGUI_ClippingDlg::ClickOnHelp()
610 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
612 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
616 platform = "winapplication";
618 platform = "application";
620 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
621 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
622 arg(app->resourceMgr()->stringValue("ExternalBrowser",
624 arg(myHelpFileName));
628 //=======================================================================
629 // function : onSelectPlane()
631 //=======================================================================
632 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
634 if (myPlanes.empty())
637 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
638 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
641 SMESH::Orientation anOrientation = aPlane->GetOrientation();
644 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
646 // Set plane parameters in the dialog
647 myIsSelectPlane = true;
648 setDistance(aPlane->GetDistance());
649 setRotation(aRot[0], aRot[1]);
650 switch (anOrientation) {
652 ComboBoxOrientation->setCurrentIndex(0);
653 onSelectOrientation(0);
656 ComboBoxOrientation->setCurrentIndex(1);
657 onSelectOrientation(1);
660 ComboBoxOrientation->setCurrentIndex(2);
661 onSelectOrientation(2);
664 myIsSelectPlane = false;
667 bool anIsBlocked = ActorList->blockSignals( true );
669 ActorList->blockSignals( anIsBlocked );
672 //=======================================================================
673 // function : ClickOnNew()
675 //=======================================================================
676 void SMESHGUI_ClippingDlg::ClickOnNew()
679 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
680 SMESH::TPlane aTPlane(aPlane);
682 SMESH::TActorList anActorList;
683 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
684 vtkActorCollection* anAllActors = aCopy.GetActors();
685 anAllActors->InitTraversal();
686 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
687 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
688 anActorList.push_back( anActor );
690 SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
692 myPlanes.push_back(aPlaneData);
694 if (PreviewCheckBox->isChecked())
695 aTPlane->myActor->VisibilityOn();
697 bool anIsBlocked = ActorList->blockSignals( true );
700 SetCurrentPlaneParam();
702 ActorList->blockSignals( anIsBlocked );
706 //=======================================================================
707 // function : ClickOnDelete()
709 //=======================================================================
710 void SMESHGUI_ClippingDlg::ClickOnDelete()
712 if (myPlanes.empty())
715 int aPlaneIndex = ComboBoxPlanes->currentIndex();
717 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
718 SMESH::TPlaneData aPlaneData = *anIter;
719 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
720 myPlanes.erase(anIter);
722 if(AutoApplyCheckBox->isChecked())
726 SMESH::RenderViewWindow( myViewWindow );
729 //=======================================================================
730 // function : updateActorItem()
732 //=======================================================================
733 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
734 bool theUpdateSelectAll,
735 bool theUpdateClippingPlaneMap )
737 // update Select All check box
738 if( theUpdateSelectAll ) {
739 int aNbItems = ActorList->count(), aNbChecked = 0;
740 for( int i = 0; i < aNbItems; i++ )
741 if( QListWidgetItem* anItem = ActorList->item( i ) )
742 if( anItem->checkState() == Qt::Checked )
745 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
746 SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
747 SelectAllCheckBox->blockSignals( anIsBlocked );
750 // update clipping plane map
751 if( theUpdateClippingPlaneMap ) {
752 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
753 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
754 if( SMESH_Actor* anActor = anItem->getActor() ) {
755 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
756 SMESH::TActorList& anActorList = aPlaneData.ActorList;
757 bool anIsPushed = false;
758 SMESH::TActorList::iterator anIter = anActorList.begin();
759 for ( ; anIter != anActorList.end(); anIter++ ) {
760 if( anActor == *anIter ) {
765 if( theItem->checkState() == Qt::Checked && !anIsPushed )
766 anActorList.push_back( anActor );
767 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
768 anActorList.remove( anActor );
774 //=======================================================================
775 // function : onActorItemChanged()
777 //=======================================================================
778 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
780 updateActorItem( theItem, true, true );
781 SetCurrentPlaneParam();
784 //=======================================================================
785 // function : onSelectAll()
787 //=======================================================================
788 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
790 if( theState == Qt::PartiallyChecked ) {
791 SelectAllCheckBox->setCheckState( Qt::Checked );
795 bool anIsBlocked = ActorList->blockSignals( true );
796 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
797 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
798 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
799 updateActorItem( anItem, false, true );
802 SelectAllCheckBox->setTristate( false );
803 ActorList->blockSignals( anIsBlocked );
804 SetCurrentPlaneParam();
807 //=======================================================================
808 // function : onSelectOrientation()
810 //=======================================================================
811 void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
813 if (myPlanes.empty())
817 TextLabelRot1->setText(tr("ROTATION_AROUND_X_Y2Z"));
818 TextLabelRot2->setText(tr("ROTATION_AROUND_Y_X2Z"));
820 else if (theItem == 1) {
821 TextLabelRot1->setText(tr("ROTATION_AROUND_Y_Z2X"));
822 TextLabelRot2->setText(tr("ROTATION_AROUND_Z_Y2X"));
824 else if (theItem == 2) {
825 TextLabelRot1->setText(tr("ROTATION_AROUND_Z_X2Y"));
826 TextLabelRot2->setText(tr("ROTATION_AROUND_X_Z2Y"));
829 if((QComboBox*)sender() == ComboBoxOrientation)
830 SetCurrentPlaneParam();
833 //=======================================================================
834 // function : synchronize()
836 //=======================================================================
837 void SMESHGUI_ClippingDlg::synchronize()
839 int aNbPlanes = myPlanes.size();
840 ComboBoxPlanes->clear();
843 for(int i = 1; i<=aNbPlanes; i++) {
844 aName = QString(tr("PLANE_NUM")).arg(i);
845 ComboBoxPlanes->addItem(aName);
848 int aPos = ComboBoxPlanes->count() - 1;
849 ComboBoxPlanes->setCurrentIndex(aPos);
851 bool anIsControlsEnable = (aPos >= 0);
852 if (anIsControlsEnable) {
856 ComboBoxPlanes->addItem(tr("NO_PLANES"));
858 SpinBoxRot1->SetValue(0.0);
859 SpinBoxRot2->SetValue(0.0);
860 SpinBoxDistance->SetValue(0.5);
863 ActorList->setEnabled(anIsControlsEnable);
864 SelectAllCheckBox->setEnabled(anIsControlsEnable);
865 buttonDelete->setEnabled(anIsControlsEnable);
866 // the following 3 controls should be enabled
867 //buttonApply->setEnabled(anIsControlsEnable);
868 //PreviewCheckBox->setEnabled(anIsControlsEnable);
869 //AutoApplyCheckBox->setEnabled(anIsControlsEnable);
870 ComboBoxOrientation->setEnabled(anIsControlsEnable);
871 SpinBoxDistance->setEnabled(anIsControlsEnable);
872 SpinBoxRot1->setEnabled(anIsControlsEnable);
873 SpinBoxRot2->setEnabled(anIsControlsEnable);
876 //=======================================================================
877 // function : setRotation()
879 //=======================================================================
880 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
882 SpinBoxRot1->SetValue(theRot1);
883 SpinBoxRot2->SetValue(theRot2);
886 //=======================================================================
887 // function : SetCurrentPlaneParam()
889 //=======================================================================
890 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
892 if (myPlanes.empty() || myIsSelectPlane)
895 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
897 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
898 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
900 vtkFloatingPointType aNormal[3];
901 SMESH::Orientation anOrientation;
902 vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
904 static double aCoeff = vtkMath::Pi()/180.0;
906 vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
907 aPlane->myAngle[0] = aRot[0];
908 aPlane->myAngle[1] = aRot[1];
910 vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
911 vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
912 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
913 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
915 switch (ComboBoxOrientation->currentIndex()) {
917 anOrientation = SMESH::XY;
927 anOrientation = SMESH::YZ;
937 anOrientation = SMESH::ZX;
948 vtkMath::Cross(aDir[1],aDir[0],aNormal);
949 vtkMath::Normalize(aNormal);
950 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
953 aPlane->SetOrientation(anOrientation);
954 aPlane->SetDistance(getDistance());
956 SMESH::TActorList anActorList = aPlaneData.ActorList;
958 vtkFloatingPointType aBounds[6];
959 vtkFloatingPointType anOrigin[3];
960 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
966 aPlane->myActor->SetVisibility( anIsOk && PreviewCheckBox->isChecked() );
969 aPlane->SetNormal( aNormal );
970 aPlane->SetOrigin( anOrigin );
972 vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
973 ( aBounds[2] + aBounds[3] ) / 2.,
974 ( aBounds[4] + aBounds[5] ) / 2. };
976 vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
977 pow( aBounds[3] - aBounds[2], 2 ) +
978 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
980 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
981 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
982 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
984 vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
985 aPnt[1] - aDelta[0][1] - aDelta[1][1],
986 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
987 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
988 aPnt01[1] + aNormal[1],
989 aPnt01[2] + aNormal[2]};
990 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
992 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
993 aPnt[1] - aDelta[0][1] + aDelta[1][1],
994 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
995 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
996 aPnt11[1] + aNormal[1],
997 aPnt11[2] + aNormal[2]};
998 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1000 vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
1001 aPnt[1] + aDelta[0][1] - aDelta[1][1],
1002 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
1003 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
1004 aPnt21[1] + aNormal[1],
1005 aPnt21[2] + aNormal[2]};
1006 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1008 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1009 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
1010 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
1011 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
1012 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
1015 if(AutoApplyCheckBox->isChecked())
1018 SMESH::RenderViewWindow( myViewWindow );
1021 //=======================================================================
1022 // function : OnPreviewToggle()
1024 //=======================================================================
1025 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1027 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1028 SMESH::RenderViewWindow( myViewWindow );
1031 //=================================================================================
1032 // function : keyPressEvent()
1034 //=================================================================================
1035 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1037 QDialog::keyPressEvent( e );
1038 if ( e->isAccepted() )
1041 if ( e->key() == Qt::Key_F1 ) {
1047 //=================================================================================
1048 // function : initializePlaneData()
1050 //=================================================================================
1051 void SMESHGUI_ClippingDlg::initializePlaneData()
1053 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1054 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
1055 if( anIter1 != aClippingPlaneInfoMap.end() ) {
1056 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
1057 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
1058 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
1059 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
1060 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1061 anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
1062 SMESH::TPlane aTPlane( anOrientedPlane );
1063 SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
1064 myPlanes.push_back( aPlaneData );
1067 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1070 //=================================================================================
1071 // function : updateActorList()
1073 //=================================================================================
1074 void SMESHGUI_ClippingDlg::updateActorList()
1078 SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1082 _PTR(Study) aStudy = anAppStudy->studyDS();
1089 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1090 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1091 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1093 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1094 vtkActorCollection* anAllActors = aCopy.GetActors();
1095 anAllActors->InitTraversal();
1096 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1097 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1098 if( anActor->hasIO() ) {
1099 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1100 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1101 bool anIsChecked = false;
1102 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1103 for ( ; anIter != anActorList.end(); anIter++ ) {
1104 if( vtkActor* aVTKActorRef = *anIter ) {
1105 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1106 if( anActorRef == anActor ) {
1113 QString aName = QString( aSObj->GetName().c_str() );
1114 QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
1115 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1116 updateActorItem( anItem, true, false );
1123 //=================================================================================
1124 // function : getCurrentActors()
1126 //=================================================================================
1127 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1129 SMESH::TActorList anActorList;
1130 for( int i = 0, n = ActorList->count(); i < n; i++ )
1131 if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1132 if( anItem->checkState() == Qt::Checked )
1133 if( SMESH_Actor* anActor = anItem->getActor() )
1134 anActorList.push_back( anActor );
1138 //=================================================================================
1139 // function : dumpPlaneData()
1141 //=================================================================================
1142 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1144 printf( "----------- Plane Data -----------\n" );
1146 SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1147 for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1148 SMESH::TPlaneData aPlaneData = *anIter1;
1149 SMESH::TPlane aPlane = aPlaneData.Plane;
1150 vtkFloatingPointType* aNormal = aPlane->GetNormal();
1151 vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
1152 printf( "Plane N%d:\n", anId );
1153 printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1154 printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1156 SMESH::TActorList anActorList = aPlaneData.ActorList;
1157 SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1158 for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1159 if( vtkActor* aVTKActor = *anIter2 ) {
1160 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1161 printf( " - Actor: '%s'\n", anActor->getName() );
1164 printf( " - Actor: NULL\n");
1167 printf( "----------------------------------\n" );
1170 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1172 if ( toggled ) ClickOnApply();