1 // Copyright (C) 2007-2011 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(ClickOnApply()));
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 Qt::CheckState aCheckState = Qt::Unchecked;
746 if( aNbChecked == aNbItems )
747 aCheckState = Qt::Checked;
748 else if( aNbChecked > 0 )
749 aCheckState = Qt::PartiallyChecked;
751 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
752 SelectAllCheckBox->setCheckState( aCheckState );
753 SelectAllCheckBox->blockSignals( anIsBlocked );
756 // update clipping plane map
757 if( theUpdateClippingPlaneMap ) {
758 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
759 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
760 if( SMESH_Actor* anActor = anItem->getActor() ) {
761 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
762 SMESH::TActorList& anActorList = aPlaneData.ActorList;
763 bool anIsPushed = false;
764 SMESH::TActorList::iterator anIter = anActorList.begin();
765 for ( ; anIter != anActorList.end(); anIter++ ) {
766 if( anActor == *anIter ) {
771 if( theItem->checkState() == Qt::Checked && !anIsPushed )
772 anActorList.push_back( anActor );
773 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
774 anActorList.remove( anActor );
780 //=======================================================================
781 // function : onActorItemChanged()
783 //=======================================================================
784 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
786 updateActorItem( theItem, true, true );
787 SetCurrentPlaneParam();
790 //=======================================================================
791 // function : onSelectAll()
793 //=======================================================================
794 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
796 if( theState == Qt::PartiallyChecked ) {
797 SelectAllCheckBox->setCheckState( Qt::Checked );
801 bool anIsBlocked = ActorList->blockSignals( true );
802 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
803 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
804 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
805 updateActorItem( anItem, false, true );
808 SelectAllCheckBox->setTristate( false );
809 ActorList->blockSignals( anIsBlocked );
810 SetCurrentPlaneParam();
813 //=======================================================================
814 // function : onSelectOrientation()
816 //=======================================================================
817 void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
819 if (myPlanes.empty())
823 TextLabelRot1->setText(tr("ROTATION_AROUND_X_Y2Z"));
824 TextLabelRot2->setText(tr("ROTATION_AROUND_Y_X2Z"));
826 else if (theItem == 1) {
827 TextLabelRot1->setText(tr("ROTATION_AROUND_Y_Z2X"));
828 TextLabelRot2->setText(tr("ROTATION_AROUND_Z_Y2X"));
830 else if (theItem == 2) {
831 TextLabelRot1->setText(tr("ROTATION_AROUND_Z_X2Y"));
832 TextLabelRot2->setText(tr("ROTATION_AROUND_X_Z2Y"));
835 if((QComboBox*)sender() == ComboBoxOrientation)
836 SetCurrentPlaneParam();
839 //=======================================================================
840 // function : synchronize()
842 //=======================================================================
843 void SMESHGUI_ClippingDlg::synchronize()
845 int aNbPlanes = myPlanes.size();
846 ComboBoxPlanes->clear();
849 for(int i = 1; i<=aNbPlanes; i++) {
850 aName = QString(tr("PLANE_NUM")).arg(i);
851 ComboBoxPlanes->addItem(aName);
854 int aPos = ComboBoxPlanes->count() - 1;
855 ComboBoxPlanes->setCurrentIndex(aPos);
857 bool anIsControlsEnable = (aPos >= 0);
858 if (anIsControlsEnable) {
862 ComboBoxPlanes->addItem(tr("NO_PLANES"));
864 SpinBoxRot1->SetValue(0.0);
865 SpinBoxRot2->SetValue(0.0);
866 SpinBoxDistance->SetValue(0.5);
869 ActorList->setEnabled(anIsControlsEnable);
870 SelectAllCheckBox->setEnabled(anIsControlsEnable);
871 buttonDelete->setEnabled(anIsControlsEnable);
872 // the following 3 controls should be enabled
873 //buttonApply->setEnabled(anIsControlsEnable);
874 //PreviewCheckBox->setEnabled(anIsControlsEnable);
875 //AutoApplyCheckBox->setEnabled(anIsControlsEnable);
876 ComboBoxOrientation->setEnabled(anIsControlsEnable);
877 SpinBoxDistance->setEnabled(anIsControlsEnable);
878 SpinBoxRot1->setEnabled(anIsControlsEnable);
879 SpinBoxRot2->setEnabled(anIsControlsEnable);
882 //=======================================================================
883 // function : setRotation()
885 //=======================================================================
886 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
888 SpinBoxRot1->SetValue(theRot1);
889 SpinBoxRot2->SetValue(theRot2);
892 //=======================================================================
893 // function : SetCurrentPlaneParam()
895 //=======================================================================
896 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
898 if (myPlanes.empty() || myIsSelectPlane)
901 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
903 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
904 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
906 vtkFloatingPointType aNormal[3];
907 SMESH::Orientation anOrientation;
908 vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
910 static double aCoeff = vtkMath::Pi()/180.0;
912 vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
913 aPlane->myAngle[0] = aRot[0];
914 aPlane->myAngle[1] = aRot[1];
916 vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
917 vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
918 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
919 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
921 switch (ComboBoxOrientation->currentIndex()) {
923 anOrientation = SMESH::XY;
933 anOrientation = SMESH::YZ;
943 anOrientation = SMESH::ZX;
954 vtkMath::Cross(aDir[1],aDir[0],aNormal);
955 vtkMath::Normalize(aNormal);
956 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
959 aPlane->SetOrientation(anOrientation);
960 aPlane->SetDistance(getDistance());
962 SMESH::TActorList anActorList = aPlaneData.ActorList;
964 vtkFloatingPointType aBounds[6];
965 vtkFloatingPointType anOrigin[3];
966 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
972 aPlane->myActor->SetVisibility( anIsOk && PreviewCheckBox->isChecked() );
975 aPlane->SetNormal( aNormal );
976 aPlane->SetOrigin( anOrigin );
978 vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
979 ( aBounds[2] + aBounds[3] ) / 2.,
980 ( aBounds[4] + aBounds[5] ) / 2. };
982 vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
983 pow( aBounds[3] - aBounds[2], 2 ) +
984 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
986 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
987 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
988 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
990 vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
991 aPnt[1] - aDelta[0][1] - aDelta[1][1],
992 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
993 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
994 aPnt01[1] + aNormal[1],
995 aPnt01[2] + aNormal[2]};
996 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
998 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
999 aPnt[1] - aDelta[0][1] + aDelta[1][1],
1000 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
1001 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
1002 aPnt11[1] + aNormal[1],
1003 aPnt11[2] + aNormal[2]};
1004 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1006 vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
1007 aPnt[1] + aDelta[0][1] - aDelta[1][1],
1008 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
1009 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
1010 aPnt21[1] + aNormal[1],
1011 aPnt21[2] + aNormal[2]};
1012 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1014 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1015 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
1016 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
1017 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
1018 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
1021 if(AutoApplyCheckBox->isChecked())
1024 SMESH::RenderViewWindow( myViewWindow );
1027 //=======================================================================
1028 // function : OnPreviewToggle()
1030 //=======================================================================
1031 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1033 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1034 SMESH::RenderViewWindow( myViewWindow );
1037 //=================================================================================
1038 // function : keyPressEvent()
1040 //=================================================================================
1041 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1043 QDialog::keyPressEvent( e );
1044 if ( e->isAccepted() )
1047 if ( e->key() == Qt::Key_F1 ) {
1053 //=================================================================================
1054 // function : initializePlaneData()
1056 //=================================================================================
1057 void SMESHGUI_ClippingDlg::initializePlaneData()
1059 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1060 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
1061 if( anIter1 != aClippingPlaneInfoMap.end() ) {
1062 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
1063 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
1064 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
1065 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
1066 SMESH::TPlane aTPlane( aClippingPlaneInfo.Plane );
1067 SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
1068 myPlanes.push_back( aPlaneData );
1071 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1074 //=================================================================================
1075 // function : updateActorList()
1077 //=================================================================================
1078 void SMESHGUI_ClippingDlg::updateActorList()
1082 SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1086 _PTR(Study) aStudy = anAppStudy->studyDS();
1093 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1094 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1095 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1097 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1098 vtkActorCollection* anAllActors = aCopy.GetActors();
1099 anAllActors->InitTraversal();
1100 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1101 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1102 if( anActor->hasIO() ) {
1103 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1104 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1105 bool anIsChecked = false;
1106 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1107 for ( ; anIter != anActorList.end(); anIter++ ) {
1108 if( vtkActor* aVTKActorRef = *anIter ) {
1109 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1110 if( anActorRef == anActor ) {
1117 QString aName = QString( aSObj->GetName().c_str() );
1118 QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
1119 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1120 updateActorItem( anItem, true, false );
1127 //=================================================================================
1128 // function : getCurrentActors()
1130 //=================================================================================
1131 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1133 SMESH::TActorList anActorList;
1134 for( int i = 0, n = ActorList->count(); i < n; i++ )
1135 if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1136 if( anItem->checkState() == Qt::Checked )
1137 if( SMESH_Actor* anActor = anItem->getActor() )
1138 anActorList.push_back( anActor );
1142 //=================================================================================
1143 // function : dumpPlaneData()
1145 //=================================================================================
1146 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1148 printf( "----------- Plane Data -----------\n" );
1150 SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1151 for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1152 SMESH::TPlaneData aPlaneData = *anIter1;
1153 SMESH::TPlane aPlane = aPlaneData.Plane;
1154 vtkFloatingPointType* aNormal = aPlane->GetNormal();
1155 vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
1156 printf( "Plane N%d:\n", anId );
1157 printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1158 printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1160 SMESH::TActorList anActorList = aPlaneData.ActorList;
1161 SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1162 for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1163 if( vtkActor* aVTKActor = *anIter2 ) {
1164 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1165 printf( " - Actor: '%s'\n", anActor->getName() );
1168 printf( " - Actor: NULL\n");
1171 printf( "----------------------------------\n" );