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);
145 vtkProperty* aProp = vtkProperty::New();
146 SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
147 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
148 aProp->SetOpacity(0.75);
149 myActor->SetProperty(aProp);
152 vtkProperty* aBackProp = vtkProperty::New();
153 SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
154 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
155 aBackProp->SetOpacity(0.75);
156 myActor->SetBackfaceProperty(aBackProp);
160 SMESH::OrientedPlane::~OrientedPlane()
163 myViewWindow->RemoveActor(myActor);
166 myMapper->RemoveAllInputs();
169 // commented: porting to vtk 5.0
170 // myPlaneSource->UnRegisterAllOutputs();
171 myPlaneSource->Delete();
174 //=================================================================================
177 //=================================================================================
178 class ActorItem : public QListWidgetItem
181 ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) :
182 QListWidgetItem( theName, theListWidget ),
183 myActor( theActor ) {}
185 SMESH_Actor* getActor() const { return myActor; }
188 SMESH_Actor* myActor;
191 //=================================================================================
192 // class : TSetVisibility
194 //=================================================================================
195 struct TSetVisibility {
196 TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){}
197 void operator()(SMESH::TPlaneData& thePlaneData){
198 bool anIsEmpty = thePlaneData.ActorList.empty();
199 thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty);
204 //=================================================================================
205 // used in SMESHGUI::restoreVisualParameters() to avoid
206 // declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
207 //=================================================================================
208 SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList theActorList,
209 SVTK_ViewWindow* theViewWindow,
210 SMESH::Orientation theOrientation,
212 const double theAngle[2])
214 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(theViewWindow);
216 aPlane->myAngle[0] = theAngle[0];
217 aPlane->myAngle[1] = theAngle[1];
219 aPlane->SetOrientation(theOrientation);
220 aPlane->SetDistance(theDistance);
223 double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
225 static double aCoeff = vtkMath::Pi()/180.0;
227 double anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
228 double aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
229 aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
230 aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
232 switch (theOrientation) {
259 vtkMath::Cross(aDir[1],aDir[0],aNormal);
260 vtkMath::Normalize(aNormal);
261 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
268 if( theActorList.empty() ) {
269 // to support planes with empty actor list we should create
270 // a nullified plane that will be initialized later
271 anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
272 aBounds[0] = aBounds[2] = aBounds[4] = 0;
273 aBounds[1] = aBounds[3] = aBounds[5] = 0;
277 anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
285 aPlane->SetNormal( aNormal );
286 aPlane->SetOrigin( anOrigin );
288 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
289 ( aBounds[2] + aBounds[3] ) / 2.,
290 ( aBounds[4] + aBounds[5] ) / 2. };
292 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
293 pow( aBounds[3] - aBounds[2], 2 ) +
294 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
296 double aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
297 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
298 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
300 double aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
301 aPnt[1] - aDelta[0][1] - aDelta[1][1],
302 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
303 double aPnt02[3] = {aPnt01[0] + aNormal[0],
304 aPnt01[1] + aNormal[1],
305 aPnt01[2] + aNormal[2]};
306 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
308 double aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
309 aPnt[1] - aDelta[0][1] + aDelta[1][1],
310 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
311 double aPnt12[3] = {aPnt11[0] + aNormal[0],
312 aPnt11[1] + aNormal[1],
313 aPnt11[2] + aNormal[2]};
314 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
316 double aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
317 aPnt[1] + aDelta[0][1] - aDelta[1][1],
318 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
319 double aPnt22[3] = {aPnt21[0] + aNormal[0],
320 aPnt21[1] + aNormal[1],
321 aPnt21[2] + aNormal[2]};
322 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
324 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
325 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
326 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
327 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
328 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
329 aPlaneSource->Update();
331 SMESH::TActorList::iterator anIter = theActorList.begin();
332 for ( ; anIter != theActorList.end(); anIter++ )
333 if( vtkActor* aVTKActor = *anIter )
334 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
335 anActor->AddClippingPlane( aPlane );
340 //=================================================================================
341 // class : SMESHGUI_ClippingDlg()
344 //=================================================================================
345 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
346 QDialog( SMESH::GetDesktop(theModule) ),
347 mySMESHGUI(theModule),
348 myViewWindow(theViewWindow)
351 setAttribute( Qt::WA_DeleteOnClose, true );
352 setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
353 setSizeGripEnabled(true);
355 QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
356 SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
357 SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
359 // Controls for selecting, creating, deleting planes
360 QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
361 QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
362 GroupPlanesLayout->setSpacing(SPACING);
363 GroupPlanesLayout->setMargin(MARGIN);
365 ComboBoxPlanes = new QComboBox(GroupPlanes);
367 buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
369 buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
371 QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
373 ActorList = new QListWidget(GroupPlanes);
374 ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
376 SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
378 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
379 GroupPlanesLayout->addWidget(new QWidget(), 0, 1);
380 GroupPlanesLayout->addWidget(buttonNew, 0, 2);
381 GroupPlanesLayout->addWidget(buttonDelete, 0, 3);
382 GroupPlanesLayout->addWidget(aLabel, 1, 0, 1, 4);
383 GroupPlanesLayout->addWidget(ActorList, 2, 0, 1, 4);
384 GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 4);
385 GroupPlanesLayout->setColumnStretch( 1, 1 );
387 // Controls for defining plane parameters
388 QGroupBox* GroupParameters = new QGroupBox(tr("SMESH_PARAMETERS"), this);
389 QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
390 GroupParametersLayout->setSpacing(SPACING);
391 GroupParametersLayout->setMargin(MARGIN);
393 TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
395 ComboBoxOrientation = new QComboBox(GroupParameters);
397 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
399 SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
401 TextLabelRot1 = new QLabel(tr("ROTATION_AROUND_X_Y2Z"), GroupParameters);
403 SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
405 TextLabelRot2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
407 SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
409 PreviewCheckBox = new QCheckBox(tr("SHOW_PREVIEW"), GroupParameters);
410 PreviewCheckBox->setChecked(true);
412 AutoApplyCheckBox = new QCheckBox(tr("AUTO_APPLY"), GroupParameters);
413 AutoApplyCheckBox->setChecked(false);
415 GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
416 GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
417 GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
418 GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
419 GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
420 GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
421 GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
422 GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
423 GroupParametersLayout->addWidget(PreviewCheckBox, 4, 0);
424 GroupParametersLayout->addWidget(AutoApplyCheckBox, 4, 1);
426 // Controls for "Ok", "Apply" and "Close" button
427 QGroupBox* GroupButtons = new QGroupBox(this);
428 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
429 GroupButtonsLayout->setSpacing(SPACING);
430 GroupButtonsLayout->setMargin(MARGIN);
432 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
433 buttonOk->setAutoDefault(true);
434 buttonOk->setDefault(true);
435 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
436 buttonApply->setAutoDefault(true);
437 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
438 buttonCancel->setAutoDefault(true);
439 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
440 buttonHelp->setAutoDefault(true);
441 GroupButtonsLayout->addWidget(buttonOk);
442 GroupButtonsLayout->addSpacing(10);
443 GroupButtonsLayout->addWidget(buttonApply);
444 GroupButtonsLayout->addSpacing(10);
445 GroupButtonsLayout->addStretch();
446 GroupButtonsLayout->addWidget(buttonCancel);
447 GroupButtonsLayout->addWidget(buttonHelp);
449 SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
450 SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
451 SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
454 SpinBoxDistance->RangeStepAndValidator(0.0, 1.0, 0.01, "length_precision" );
455 SpinBoxRot1->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
456 SpinBoxRot2->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
458 ComboBoxOrientation->addItem(tr("ALONG_XY"));
459 ComboBoxOrientation->addItem(tr("ALONG_YZ"));
460 ComboBoxOrientation->addItem(tr("ALONG_ZX"));
462 SpinBoxDistance->SetValue(0.5);
464 myIsSelectPlane = false;
466 initializePlaneData();
469 myHelpFileName = "clipping_page.html";
471 // signals and slots connections :
472 connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
473 connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
474 connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
475 connect(ActorList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onActorItemChanged(QListWidgetItem*)));
476 connect(SelectAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onSelectAll(int)));
477 connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
478 connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
479 connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
480 connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
481 connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
482 connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(onAutoApply(bool)));
483 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
484 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
485 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
486 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
487 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
488 /* to close dialog if study frame change */
489 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(reject()));
494 //=================================================================================
495 // function : ~SMESHGUI_ClippingDlg()
497 //=================================================================================
498 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
500 // no need to delete child widgets, Qt does it all for us
501 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
503 SMESH::RenderViewWindow(myViewWindow);
506 double SMESHGUI_ClippingDlg::getDistance() const
508 return SpinBoxDistance->GetValue();
511 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
513 SpinBoxDistance->SetValue( theDistance );
516 double SMESHGUI_ClippingDlg::getRotation1() const
518 return SpinBoxRot1->GetValue();
521 double SMESHGUI_ClippingDlg::getRotation2() const
523 return SpinBoxRot2->GetValue();
526 //=======================================================================
527 // function : ClickOnApply()
529 //=======================================================================
530 void SMESHGUI_ClippingDlg::ClickOnApply()
533 SUIT_OverrideCursor wc;
535 QWidget *aCurrWid = this->focusWidget();
536 aCurrWid->clearFocus();
537 aCurrWid->setFocus();
539 SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
540 SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
542 // clean memory allocated for planes
543 SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
544 for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
545 if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
548 aClippingPlaneInfoList.clear();
550 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
551 vtkActorCollection* anAllActors = aCopy.GetActors();
552 anAllActors->InitTraversal();
553 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
554 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
555 anActor->RemoveAllClippingPlanes();
557 SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
558 for( ; anIter2 != myPlanes.end(); anIter2++ ) {
559 SMESH::TPlaneData aPlaneData = *anIter2;
560 SMESH::TPlane aPlane = aPlaneData.Plane;
561 SMESH::TActorList anActorList = aPlaneData.ActorList;
563 // the check is disabled to support planes with empty actor list
564 //if( anActorList.empty() )
567 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
568 anOrientedPlane->ShallowCopy(aPlane.GetPointer());
570 SMESH::TActorList::iterator anIter3 = anActorList.begin();
571 for( ; anIter3 != anActorList.end(); anIter3++ )
572 if( vtkActor* aVTKActor = *anIter3 )
573 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
574 anActor->AddClippingPlane(anOrientedPlane);
576 SMESH::ClippingPlaneInfo aClippingPlaneInfo;
577 aClippingPlaneInfo.Plane = anOrientedPlane;
578 aClippingPlaneInfo.ActorList = anActorList;
580 aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
583 SMESH::RenderViewWindow( myViewWindow );
587 //=======================================================================
588 // function : ClickOnOk()
590 //=======================================================================
591 void SMESHGUI_ClippingDlg::ClickOnOk()
597 //=======================================================================
598 // function : reject()
600 //=======================================================================
601 void SMESHGUI_ClippingDlg::reject()
603 //here we can insert actions to do at close.
607 //=================================================================================
608 // function : ClickOnHelp()
610 //=================================================================================
611 void SMESHGUI_ClippingDlg::ClickOnHelp()
613 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
615 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
619 platform = "winapplication";
621 platform = "application";
623 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
624 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
625 arg(app->resourceMgr()->stringValue("ExternalBrowser",
627 arg(myHelpFileName));
631 //=======================================================================
632 // function : onSelectPlane()
634 //=======================================================================
635 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
637 if (myPlanes.empty())
640 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
641 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
644 SMESH::Orientation anOrientation = aPlane->GetOrientation();
647 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
649 // Set plane parameters in the dialog
650 myIsSelectPlane = true;
651 setDistance(aPlane->GetDistance());
652 setRotation(aRot[0], aRot[1]);
653 switch (anOrientation) {
655 ComboBoxOrientation->setCurrentIndex(0);
656 onSelectOrientation(0);
659 ComboBoxOrientation->setCurrentIndex(1);
660 onSelectOrientation(1);
663 ComboBoxOrientation->setCurrentIndex(2);
664 onSelectOrientation(2);
667 myIsSelectPlane = false;
670 bool anIsBlocked = ActorList->blockSignals( true );
672 ActorList->blockSignals( anIsBlocked );
675 //=======================================================================
676 // function : ClickOnNew()
678 //=======================================================================
679 void SMESHGUI_ClippingDlg::ClickOnNew()
682 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
683 SMESH::TPlane aTPlane(aPlane);
685 SMESH::TActorList anActorList;
686 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
687 vtkActorCollection* anAllActors = aCopy.GetActors();
688 anAllActors->InitTraversal();
689 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
690 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
691 anActorList.push_back( anActor );
693 SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
695 myPlanes.push_back(aPlaneData);
697 if (PreviewCheckBox->isChecked())
698 aTPlane->myActor->VisibilityOn();
700 bool anIsBlocked = ActorList->blockSignals( true );
703 SetCurrentPlaneParam();
705 ActorList->blockSignals( anIsBlocked );
709 //=======================================================================
710 // function : ClickOnDelete()
712 //=======================================================================
713 void SMESHGUI_ClippingDlg::ClickOnDelete()
715 if (myPlanes.empty())
718 int aPlaneIndex = ComboBoxPlanes->currentIndex();
720 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
721 SMESH::TPlaneData aPlaneData = *anIter;
722 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
723 myPlanes.erase(anIter);
725 if(AutoApplyCheckBox->isChecked())
729 SMESH::RenderViewWindow( myViewWindow );
732 //=======================================================================
733 // function : updateActorItem()
735 //=======================================================================
736 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
737 bool theUpdateSelectAll,
738 bool theUpdateClippingPlaneMap )
740 // update Select All check box
741 if( theUpdateSelectAll ) {
742 int aNbItems = ActorList->count(), aNbChecked = 0;
743 for( int i = 0; i < aNbItems; i++ )
744 if( QListWidgetItem* anItem = ActorList->item( i ) )
745 if( anItem->checkState() == Qt::Checked )
748 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
749 SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
750 SelectAllCheckBox->blockSignals( anIsBlocked );
753 // update clipping plane map
754 if( theUpdateClippingPlaneMap ) {
755 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
756 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
757 if( SMESH_Actor* anActor = anItem->getActor() ) {
758 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
759 SMESH::TActorList& anActorList = aPlaneData.ActorList;
760 bool anIsPushed = false;
761 SMESH::TActorList::iterator anIter = anActorList.begin();
762 for ( ; anIter != anActorList.end(); anIter++ ) {
763 if( anActor == *anIter ) {
768 if( theItem->checkState() == Qt::Checked && !anIsPushed )
769 anActorList.push_back( anActor );
770 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
771 anActorList.remove( anActor );
777 //=======================================================================
778 // function : onActorItemChanged()
780 //=======================================================================
781 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
783 updateActorItem( theItem, true, true );
784 SetCurrentPlaneParam();
787 //=======================================================================
788 // function : onSelectAll()
790 //=======================================================================
791 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
793 if( theState == Qt::PartiallyChecked ) {
794 SelectAllCheckBox->setCheckState( Qt::Checked );
798 bool anIsBlocked = ActorList->blockSignals( true );
799 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
800 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
801 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
802 updateActorItem( anItem, false, true );
805 SelectAllCheckBox->setTristate( false );
806 ActorList->blockSignals( anIsBlocked );
807 SetCurrentPlaneParam();
810 //=======================================================================
811 // function : onSelectOrientation()
813 //=======================================================================
814 void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
816 if (myPlanes.empty())
820 TextLabelRot1->setText(tr("ROTATION_AROUND_X_Y2Z"));
821 TextLabelRot2->setText(tr("ROTATION_AROUND_Y_X2Z"));
823 else if (theItem == 1) {
824 TextLabelRot1->setText(tr("ROTATION_AROUND_Y_Z2X"));
825 TextLabelRot2->setText(tr("ROTATION_AROUND_Z_Y2X"));
827 else if (theItem == 2) {
828 TextLabelRot1->setText(tr("ROTATION_AROUND_Z_X2Y"));
829 TextLabelRot2->setText(tr("ROTATION_AROUND_X_Z2Y"));
832 if((QComboBox*)sender() == ComboBoxOrientation)
833 SetCurrentPlaneParam();
836 //=======================================================================
837 // function : synchronize()
839 //=======================================================================
840 void SMESHGUI_ClippingDlg::synchronize()
842 int aNbPlanes = myPlanes.size();
843 ComboBoxPlanes->clear();
846 for(int i = 1; i<=aNbPlanes; i++) {
847 aName = QString(tr("PLANE_NUM")).arg(i);
848 ComboBoxPlanes->addItem(aName);
851 int aPos = ComboBoxPlanes->count() - 1;
852 ComboBoxPlanes->setCurrentIndex(aPos);
854 bool anIsControlsEnable = (aPos >= 0);
855 if (anIsControlsEnable) {
859 ComboBoxPlanes->addItem(tr("NO_PLANES"));
861 SpinBoxRot1->SetValue(0.0);
862 SpinBoxRot2->SetValue(0.0);
863 SpinBoxDistance->SetValue(0.5);
866 ActorList->setEnabled(anIsControlsEnable);
867 SelectAllCheckBox->setEnabled(anIsControlsEnable);
868 buttonDelete->setEnabled(anIsControlsEnable);
869 // the following 3 controls should be enabled
870 //buttonApply->setEnabled(anIsControlsEnable);
871 //PreviewCheckBox->setEnabled(anIsControlsEnable);
872 //AutoApplyCheckBox->setEnabled(anIsControlsEnable);
873 ComboBoxOrientation->setEnabled(anIsControlsEnable);
874 SpinBoxDistance->setEnabled(anIsControlsEnable);
875 SpinBoxRot1->setEnabled(anIsControlsEnable);
876 SpinBoxRot2->setEnabled(anIsControlsEnable);
879 //=======================================================================
880 // function : setRotation()
882 //=======================================================================
883 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
885 SpinBoxRot1->SetValue(theRot1);
886 SpinBoxRot2->SetValue(theRot2);
889 //=======================================================================
890 // function : SetCurrentPlaneParam()
892 //=======================================================================
893 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
895 if (myPlanes.empty() || myIsSelectPlane)
898 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
900 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
901 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
904 SMESH::Orientation anOrientation;
905 double aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
907 static double aCoeff = vtkMath::Pi()/180.0;
909 double aRot[2] = {getRotation1(), getRotation2()};
910 aPlane->myAngle[0] = aRot[0];
911 aPlane->myAngle[1] = aRot[1];
913 double anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
914 double aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
915 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
916 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
918 switch (ComboBoxOrientation->currentIndex()) {
920 anOrientation = SMESH::XY;
930 anOrientation = SMESH::YZ;
940 anOrientation = SMESH::ZX;
951 vtkMath::Cross(aDir[1],aDir[0],aNormal);
952 vtkMath::Normalize(aNormal);
953 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
956 aPlane->SetOrientation(anOrientation);
957 aPlane->SetDistance(getDistance());
959 SMESH::TActorList anActorList = aPlaneData.ActorList;
963 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
969 aPlane->myActor->SetVisibility( anIsOk && PreviewCheckBox->isChecked() );
972 aPlane->SetNormal( aNormal );
973 aPlane->SetOrigin( anOrigin );
975 double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
976 ( aBounds[2] + aBounds[3] ) / 2.,
977 ( aBounds[4] + aBounds[5] ) / 2. };
979 double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
980 pow( aBounds[3] - aBounds[2], 2 ) +
981 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
983 double aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
984 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
985 double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
987 double aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
988 aPnt[1] - aDelta[0][1] - aDelta[1][1],
989 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
990 double aPnt02[3] = {aPnt01[0] + aNormal[0],
991 aPnt01[1] + aNormal[1],
992 aPnt01[2] + aNormal[2]};
993 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
995 double aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
996 aPnt[1] - aDelta[0][1] + aDelta[1][1],
997 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
998 double aPnt12[3] = {aPnt11[0] + aNormal[0],
999 aPnt11[1] + aNormal[1],
1000 aPnt11[2] + aNormal[2]};
1001 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1003 double aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
1004 aPnt[1] + aDelta[0][1] - aDelta[1][1],
1005 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
1006 double aPnt22[3] = {aPnt21[0] + aNormal[0],
1007 aPnt21[1] + aNormal[1],
1008 aPnt21[2] + aNormal[2]};
1009 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1011 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1012 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
1013 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
1014 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
1015 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
1016 aPlaneSource->Update();
1019 if(AutoApplyCheckBox->isChecked())
1022 SMESH::RenderViewWindow( myViewWindow );
1025 //=======================================================================
1026 // function : OnPreviewToggle()
1028 //=======================================================================
1029 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1031 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1032 SMESH::RenderViewWindow( myViewWindow );
1035 //=================================================================================
1036 // function : keyPressEvent()
1038 //=================================================================================
1039 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1041 QDialog::keyPressEvent( e );
1042 if ( e->isAccepted() )
1045 if ( e->key() == Qt::Key_F1 ) {
1051 //=================================================================================
1052 // function : initializePlaneData()
1054 //=================================================================================
1055 void SMESHGUI_ClippingDlg::initializePlaneData()
1057 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1058 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
1059 if( anIter1 != aClippingPlaneInfoMap.end() ) {
1060 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
1061 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
1062 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
1063 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
1064 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1065 anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
1066 SMESH::TPlane aTPlane( anOrientedPlane );
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 double* aNormal = aPlane->GetNormal();
1155 double* 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" );
1174 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1176 if ( toggled ) ClickOnApply();