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());
108 myPlaneSource->Update();
111 SMESH::OrientedPlane::OrientedPlane(SVTK_ViewWindow* theViewWindow):
112 myViewWindow(theViewWindow),
113 myOrientation(SMESH::XY),
117 myViewWindow->AddActor(myActor, false, false); // don't adjust actors
120 SMESH::OrientedPlane::OrientedPlane():
121 myOrientation(SMESH::XY),
128 void SMESH::OrientedPlane::Init()
130 myPlaneSource = vtkPlaneSource::New();
132 myAngle[0] = myAngle[1] = 0.0;
134 // Create and display actor
135 myMapper = vtkDataSetMapper::New();
136 myMapper->SetInputConnection(myPlaneSource->GetOutputPort());
138 myActor = SALOME_Actor::New();
139 myActor->VisibilityOff();
140 myActor->PickableOff();
141 myActor->SetInfinitive(true);
142 myActor->SetMapper(myMapper);
146 SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "255, 170, 0|-100" ) ;
148 vtkProperty* aProp = vtkProperty::New();
149 SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "255, 170, 0|-100" ) ;
150 aProp->SetColor(ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255.);
151 aProp->SetOpacity(0.75);
152 myActor->SetProperty(aProp);
155 vtkProperty* aBackProp = vtkProperty::New();
156 bfc = Qtx::mainColorToSecondary(ffc, delta);
157 aBackProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255.);
158 aBackProp->SetOpacity(0.75);
159 myActor->SetBackfaceProperty(aBackProp);
163 SMESH::OrientedPlane::~OrientedPlane()
166 myViewWindow->RemoveActor(myActor);
169 myMapper->RemoveAllInputs();
172 // commented: porting to vtk 5.0
173 // myPlaneSource->UnRegisterAllOutputs();
174 myPlaneSource->Delete();
177 //=================================================================================
180 //=================================================================================
181 class ActorItem : public QListWidgetItem
184 ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) :
185 QListWidgetItem( theName, theListWidget ),
186 myActor( theActor ) {}
188 SMESH_Actor* getActor() const { return myActor; }
191 SMESH_Actor* myActor;
194 //=================================================================================
195 // class : TSetVisibility
197 //=================================================================================
198 struct TSetVisibility {
199 TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){}
200 void operator()(SMESH::TPlaneData& thePlaneData){
201 bool anIsEmpty = thePlaneData.ActorList.empty();
202 thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty);
207 //=================================================================================
208 // used in SMESHGUI::restoreVisualParameters() to avoid
209 // declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
210 //=================================================================================
211 SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList theActorList,
212 SVTK_ViewWindow* theViewWindow,
213 SMESH::Orientation theOrientation,
215 const double theAngle[2])
217 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(theViewWindow);
219 aPlane->myAngle[0] = theAngle[0];
220 aPlane->myAngle[1] = theAngle[1];
222 aPlane->SetOrientation(theOrientation);
223 aPlane->SetDistance(theDistance);
226 double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
228 static double aCoeff = vtkMath::Pi()/180.0;
230 double anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
231 double aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
232 aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
233 aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
235 switch (theOrientation) {
262 vtkMath::Cross(aDir[1],aDir[0],aNormal);
263 vtkMath::Normalize(aNormal);
264 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
271 if( theActorList.empty() ) {
272 // to support planes with empty actor list we should create
273 // a nullified plane that will be initialized later
274 anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
275 aBounds[0] = aBounds[2] = aBounds[4] = 0;
276 aBounds[1] = aBounds[3] = aBounds[5] = 0;
280 anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
288 aPlane->SetNormal( aNormal );
289 aPlane->SetOrigin( anOrigin );
291 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
292 ( aBounds[2] + aBounds[3] ) / 2.,
293 ( aBounds[4] + aBounds[5] ) / 2. };
295 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
296 pow( aBounds[3] - aBounds[2], 2 ) +
297 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
299 double aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
300 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
301 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
303 double aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
304 aPnt[1] - aDelta[0][1] - aDelta[1][1],
305 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
306 double aPnt02[3] = {aPnt01[0] + aNormal[0],
307 aPnt01[1] + aNormal[1],
308 aPnt01[2] + aNormal[2]};
309 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
311 double aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
312 aPnt[1] - aDelta[0][1] + aDelta[1][1],
313 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
314 double aPnt12[3] = {aPnt11[0] + aNormal[0],
315 aPnt11[1] + aNormal[1],
316 aPnt11[2] + aNormal[2]};
317 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
319 double aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
320 aPnt[1] + aDelta[0][1] - aDelta[1][1],
321 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
322 double aPnt22[3] = {aPnt21[0] + aNormal[0],
323 aPnt21[1] + aNormal[1],
324 aPnt21[2] + aNormal[2]};
325 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
327 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
328 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
329 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
330 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
331 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
332 aPlaneSource->Update();
334 SMESH::TActorList::iterator anIter = theActorList.begin();
335 for ( ; anIter != theActorList.end(); anIter++ )
336 if( vtkActor* aVTKActor = *anIter )
337 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
338 anActor->AddClippingPlane( aPlane );
343 //=================================================================================
344 // class : SMESHGUI_ClippingDlg()
347 //=================================================================================
348 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
349 QDialog( SMESH::GetDesktop(theModule) ),
350 mySMESHGUI(theModule),
351 myViewWindow(theViewWindow)
354 setAttribute( Qt::WA_DeleteOnClose, true );
355 setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
356 setSizeGripEnabled(true);
358 QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
359 SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
360 SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
362 // Controls for selecting, creating, deleting planes
363 QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
364 QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
365 GroupPlanesLayout->setSpacing(SPACING);
366 GroupPlanesLayout->setMargin(MARGIN);
368 ComboBoxPlanes = new QComboBox(GroupPlanes);
370 buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
372 buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
374 QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
376 ActorList = new QListWidget(GroupPlanes);
377 ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
379 SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
381 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
382 GroupPlanesLayout->addWidget(new QWidget(), 0, 1);
383 GroupPlanesLayout->addWidget(buttonNew, 0, 2);
384 GroupPlanesLayout->addWidget(buttonDelete, 0, 3);
385 GroupPlanesLayout->addWidget(aLabel, 1, 0, 1, 4);
386 GroupPlanesLayout->addWidget(ActorList, 2, 0, 1, 4);
387 GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 4);
388 GroupPlanesLayout->setColumnStretch( 1, 1 );
390 // Controls for defining plane parameters
391 QGroupBox* GroupParameters = new QGroupBox(tr("SMESH_PARAMETERS"), this);
392 QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
393 GroupParametersLayout->setSpacing(SPACING);
394 GroupParametersLayout->setMargin(MARGIN);
396 TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
398 ComboBoxOrientation = new QComboBox(GroupParameters);
400 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
402 SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
404 TextLabelRot1 = new QLabel(tr("ROTATION_AROUND_X_Y2Z"), GroupParameters);
406 SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
408 TextLabelRot2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
410 SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
412 PreviewCheckBox = new QCheckBox(tr("SHOW_PREVIEW"), GroupParameters);
413 PreviewCheckBox->setChecked(true);
415 AutoApplyCheckBox = new QCheckBox(tr("AUTO_APPLY"), GroupParameters);
416 AutoApplyCheckBox->setChecked(false);
418 GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
419 GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
420 GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
421 GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
422 GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
423 GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
424 GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
425 GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
426 GroupParametersLayout->addWidget(PreviewCheckBox, 4, 0);
427 GroupParametersLayout->addWidget(AutoApplyCheckBox, 4, 1);
429 // Controls for "Ok", "Apply" and "Close" button
430 QGroupBox* GroupButtons = new QGroupBox(this);
431 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
432 GroupButtonsLayout->setSpacing(SPACING);
433 GroupButtonsLayout->setMargin(MARGIN);
435 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
436 buttonOk->setAutoDefault(true);
437 buttonOk->setDefault(true);
438 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
439 buttonApply->setAutoDefault(true);
440 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
441 buttonCancel->setAutoDefault(true);
442 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
443 buttonHelp->setAutoDefault(true);
444 GroupButtonsLayout->addWidget(buttonOk);
445 GroupButtonsLayout->addSpacing(10);
446 GroupButtonsLayout->addWidget(buttonApply);
447 GroupButtonsLayout->addSpacing(10);
448 GroupButtonsLayout->addStretch();
449 GroupButtonsLayout->addWidget(buttonCancel);
450 GroupButtonsLayout->addWidget(buttonHelp);
452 SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
453 SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
454 SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
457 SpinBoxDistance->RangeStepAndValidator(0.0, 1.0, 0.01, "length_precision" );
458 SpinBoxRot1->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
459 SpinBoxRot2->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
461 ComboBoxOrientation->addItem(tr("ALONG_XY"));
462 ComboBoxOrientation->addItem(tr("ALONG_YZ"));
463 ComboBoxOrientation->addItem(tr("ALONG_ZX"));
465 SpinBoxDistance->SetValue(0.5);
467 myIsSelectPlane = false;
469 initializePlaneData();
472 myHelpFileName = "clipping_page.html";
474 // signals and slots connections :
475 connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
476 connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
477 connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
478 connect(ActorList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onActorItemChanged(QListWidgetItem*)));
479 connect(SelectAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onSelectAll(int)));
480 connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
481 connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
482 connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
483 connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
484 connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
485 connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(onAutoApply(bool)));
486 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
487 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
488 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
489 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
490 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
491 /* to close dialog if study frame change */
492 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(reject()));
497 //=================================================================================
498 // function : ~SMESHGUI_ClippingDlg()
500 //=================================================================================
501 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
503 // no need to delete child widgets, Qt does it all for us
504 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
506 SMESH::RenderViewWindow(myViewWindow);
509 double SMESHGUI_ClippingDlg::getDistance() const
511 return SpinBoxDistance->GetValue();
514 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
516 SpinBoxDistance->SetValue( theDistance );
519 double SMESHGUI_ClippingDlg::getRotation1() const
521 return SpinBoxRot1->GetValue();
524 double SMESHGUI_ClippingDlg::getRotation2() const
526 return SpinBoxRot2->GetValue();
529 //=======================================================================
530 // function : ClickOnApply()
532 //=======================================================================
533 void SMESHGUI_ClippingDlg::ClickOnApply()
536 SUIT_OverrideCursor wc;
538 QWidget *aCurrWid = this->focusWidget();
539 aCurrWid->clearFocus();
540 aCurrWid->setFocus();
542 SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
543 SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
545 // clean memory allocated for planes
546 SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
547 for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
548 if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
551 aClippingPlaneInfoList.clear();
553 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
554 vtkActorCollection* anAllActors = aCopy.GetActors();
555 anAllActors->InitTraversal();
556 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
557 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
558 anActor->RemoveAllClippingPlanes();
560 SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
561 for( ; anIter2 != myPlanes.end(); anIter2++ ) {
562 SMESH::TPlaneData aPlaneData = *anIter2;
563 SMESH::TPlane aPlane = aPlaneData.Plane;
564 SMESH::TActorList anActorList = aPlaneData.ActorList;
566 // the check is disabled to support planes with empty actor list
567 //if( anActorList.empty() )
570 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
571 anOrientedPlane->ShallowCopy(aPlane.GetPointer());
573 SMESH::TActorList::iterator anIter3 = anActorList.begin();
574 for( ; anIter3 != anActorList.end(); anIter3++ )
575 if( vtkActor* aVTKActor = *anIter3 )
576 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
577 anActor->AddClippingPlane(anOrientedPlane);
579 SMESH::ClippingPlaneInfo aClippingPlaneInfo;
580 aClippingPlaneInfo.Plane = anOrientedPlane;
581 aClippingPlaneInfo.ActorList = anActorList;
583 aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
586 SMESH::RenderViewWindow( myViewWindow );
590 //=======================================================================
591 // function : ClickOnOk()
593 //=======================================================================
594 void SMESHGUI_ClippingDlg::ClickOnOk()
600 //=======================================================================
601 // function : reject()
603 //=======================================================================
604 void SMESHGUI_ClippingDlg::reject()
606 //here we can insert actions to do at close.
610 //=================================================================================
611 // function : ClickOnHelp()
613 //=================================================================================
614 void SMESHGUI_ClippingDlg::ClickOnHelp()
616 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
618 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
622 platform = "winapplication";
624 platform = "application";
626 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
627 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
628 arg(app->resourceMgr()->stringValue("ExternalBrowser",
630 arg(myHelpFileName));
634 //=======================================================================
635 // function : onSelectPlane()
637 //=======================================================================
638 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
640 if (myPlanes.empty())
643 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
644 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
647 SMESH::Orientation anOrientation = aPlane->GetOrientation();
650 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
652 // Set plane parameters in the dialog
653 myIsSelectPlane = true;
654 setDistance(aPlane->GetDistance());
655 setRotation(aRot[0], aRot[1]);
656 switch (anOrientation) {
658 ComboBoxOrientation->setCurrentIndex(0);
659 onSelectOrientation(0);
662 ComboBoxOrientation->setCurrentIndex(1);
663 onSelectOrientation(1);
666 ComboBoxOrientation->setCurrentIndex(2);
667 onSelectOrientation(2);
670 myIsSelectPlane = false;
673 bool anIsBlocked = ActorList->blockSignals( true );
675 ActorList->blockSignals( anIsBlocked );
678 //=======================================================================
679 // function : ClickOnNew()
681 //=======================================================================
682 void SMESHGUI_ClippingDlg::ClickOnNew()
685 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
686 SMESH::TPlane aTPlane(aPlane);
688 SMESH::TActorList anActorList;
689 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
690 vtkActorCollection* anAllActors = aCopy.GetActors();
691 anAllActors->InitTraversal();
692 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
693 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
694 anActorList.push_back( anActor );
696 SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
698 myPlanes.push_back(aPlaneData);
700 if (PreviewCheckBox->isChecked())
701 aTPlane->myActor->VisibilityOn();
703 bool anIsBlocked = ActorList->blockSignals( true );
706 SetCurrentPlaneParam();
708 ActorList->blockSignals( anIsBlocked );
712 //=======================================================================
713 // function : ClickOnDelete()
715 //=======================================================================
716 void SMESHGUI_ClippingDlg::ClickOnDelete()
718 if (myPlanes.empty())
721 int aPlaneIndex = ComboBoxPlanes->currentIndex();
723 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
724 SMESH::TPlaneData aPlaneData = *anIter;
725 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
726 myPlanes.erase(anIter);
728 if(AutoApplyCheckBox->isChecked())
732 SMESH::RenderViewWindow( myViewWindow );
735 //=======================================================================
736 // function : updateActorItem()
738 //=======================================================================
739 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
740 bool theUpdateSelectAll,
741 bool theUpdateClippingPlaneMap )
743 // update Select All check box
744 if( theUpdateSelectAll ) {
745 int aNbItems = ActorList->count(), aNbChecked = 0;
746 for( int i = 0; i < aNbItems; i++ )
747 if( QListWidgetItem* anItem = ActorList->item( i ) )
748 if( anItem->checkState() == Qt::Checked )
751 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
752 SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
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();
907 SMESH::Orientation anOrientation;
908 double aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
910 static double aCoeff = vtkMath::Pi()/180.0;
912 double aRot[2] = {getRotation1(), getRotation2()};
913 aPlane->myAngle[0] = aRot[0];
914 aPlane->myAngle[1] = aRot[1];
916 double anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
917 double 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;
966 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
972 aPlane->myActor->SetVisibility( anIsOk && PreviewCheckBox->isChecked() );
975 aPlane->SetNormal( aNormal );
976 aPlane->SetOrigin( anOrigin );
978 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
979 ( aBounds[2] + aBounds[3] ) / 2.,
980 ( aBounds[4] + aBounds[5] ) / 2. };
982 double 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 double 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 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
990 double 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 double 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 double 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 double 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 double 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 double 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]);
1019 aPlaneSource->Update();
1022 if(AutoApplyCheckBox->isChecked())
1025 SMESH::RenderViewWindow( myViewWindow );
1028 //=======================================================================
1029 // function : OnPreviewToggle()
1031 //=======================================================================
1032 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1034 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1035 SMESH::RenderViewWindow( myViewWindow );
1038 //=================================================================================
1039 // function : keyPressEvent()
1041 //=================================================================================
1042 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1044 QDialog::keyPressEvent( e );
1045 if ( e->isAccepted() )
1048 if ( e->key() == Qt::Key_F1 ) {
1054 //=================================================================================
1055 // function : initializePlaneData()
1057 //=================================================================================
1058 void SMESHGUI_ClippingDlg::initializePlaneData()
1060 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1061 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
1062 if( anIter1 != aClippingPlaneInfoMap.end() ) {
1063 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
1064 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
1065 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
1066 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
1067 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1068 anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
1069 SMESH::TPlane aTPlane( anOrientedPlane );
1070 SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
1071 myPlanes.push_back( aPlaneData );
1074 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1077 //=================================================================================
1078 // function : updateActorList()
1080 //=================================================================================
1081 void SMESHGUI_ClippingDlg::updateActorList()
1085 SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1089 _PTR(Study) aStudy = anAppStudy->studyDS();
1096 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1097 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1098 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1100 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1101 vtkActorCollection* anAllActors = aCopy.GetActors();
1102 anAllActors->InitTraversal();
1103 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1104 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1105 if( anActor->hasIO() ) {
1106 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1107 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1108 bool anIsChecked = false;
1109 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1110 for ( ; anIter != anActorList.end(); anIter++ ) {
1111 if( vtkActor* aVTKActorRef = *anIter ) {
1112 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1113 if( anActorRef == anActor ) {
1120 QString aName = QString( aSObj->GetName().c_str() );
1121 QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
1122 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1123 updateActorItem( anItem, true, false );
1130 //=================================================================================
1131 // function : getCurrentActors()
1133 //=================================================================================
1134 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1136 SMESH::TActorList anActorList;
1137 for( int i = 0, n = ActorList->count(); i < n; i++ )
1138 if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1139 if( anItem->checkState() == Qt::Checked )
1140 if( SMESH_Actor* anActor = anItem->getActor() )
1141 anActorList.push_back( anActor );
1145 //=================================================================================
1146 // function : dumpPlaneData()
1148 //=================================================================================
1149 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1151 printf( "----------- Plane Data -----------\n" );
1153 SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1154 for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1155 SMESH::TPlaneData aPlaneData = *anIter1;
1156 SMESH::TPlane aPlane = aPlaneData.Plane;
1157 double* aNormal = aPlane->GetNormal();
1158 double* anOrigin = aPlane->GetOrigin();
1159 printf( "Plane N%d:\n", anId );
1160 printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1161 printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1163 SMESH::TActorList anActorList = aPlaneData.ActorList;
1164 SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1165 for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1166 if( vtkActor* aVTKActor = *anIter2 ) {
1167 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1168 printf( " - Actor: '%s'\n", anActor->getName() );
1171 printf( " - Actor: NULL\n");
1174 printf( "----------------------------------\n" );
1177 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1179 if ( toggled ) ClickOnApply();