1 // Copyright (C) 2007-2010 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);
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 thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible);
202 //=================================================================================
203 // used in SMESHGUI::restoreVisualParameters() to avoid
204 // declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
205 //=================================================================================
206 SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList theActorList,
207 SVTK_ViewWindow* theViewWindow,
208 SMESH::Orientation theOrientation,
210 const vtkFloatingPointType theAngle[2])
212 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(theViewWindow);
214 aPlane->myAngle[0] = theAngle[0];
215 aPlane->myAngle[1] = theAngle[1];
217 aPlane->SetOrientation(theOrientation);
218 aPlane->SetDistance(theDistance);
220 vtkFloatingPointType aNormal[3];
221 vtkFloatingPointType aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
223 static double aCoeff = vtkMath::Pi()/180.0;
225 vtkFloatingPointType anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
226 vtkFloatingPointType aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
227 aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
228 aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
230 switch (theOrientation) {
257 vtkMath::Cross(aDir[1],aDir[0],aNormal);
258 vtkMath::Normalize(aNormal);
259 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
262 vtkFloatingPointType aBounds[6];
263 vtkFloatingPointType anOrigin[3];
264 bool anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
272 aPlane->SetNormal( aNormal );
273 aPlane->SetOrigin( anOrigin );
275 vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
276 ( aBounds[2] + aBounds[3] ) / 2.,
277 ( aBounds[4] + aBounds[5] ) / 2. };
279 vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
280 pow( aBounds[3] - aBounds[2], 2 ) +
281 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
283 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
284 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
285 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
287 vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
288 aPnt[1] - aDelta[0][1] - aDelta[1][1],
289 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
290 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
291 aPnt01[1] + aNormal[1],
292 aPnt01[2] + aNormal[2]};
293 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
295 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
296 aPnt[1] - aDelta[0][1] + aDelta[1][1],
297 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
298 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
299 aPnt11[1] + aNormal[1],
300 aPnt11[2] + aNormal[2]};
301 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
303 vtkFloatingPointType aPnt21[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 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
307 aPnt21[1] + aNormal[1],
308 aPnt21[2] + aNormal[2]};
309 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
311 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
312 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
313 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
314 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
315 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
317 SMESH::TActorList::iterator anIter = theActorList.begin();
318 for ( ; anIter != theActorList.end(); anIter++ )
319 if( vtkActor* aVTKActor = *anIter )
320 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
321 anActor->AddClippingPlane( aPlane );
326 //=================================================================================
327 // class : SMESHGUI_ClippingDlg()
330 //=================================================================================
331 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
332 QDialog( SMESH::GetDesktop(theModule) ),
333 mySMESHGUI(theModule),
334 myViewWindow(theViewWindow)
337 setAttribute( Qt::WA_DeleteOnClose, true );
338 setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
339 setSizeGripEnabled(true);
341 QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
342 SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
343 SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
345 // Controls for selecting, creating, deleting planes
346 QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
347 QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
348 GroupPlanesLayout->setSpacing(SPACING);
349 GroupPlanesLayout->setMargin(MARGIN);
351 ComboBoxPlanes = new QComboBox(GroupPlanes);
353 buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
355 buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
357 QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
359 ActorList = new QListWidget(GroupPlanes);
360 ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
362 SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
364 GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
365 GroupPlanesLayout->addWidget(new QWidget(), 0, 1);
366 GroupPlanesLayout->addWidget(buttonNew, 0, 2);
367 GroupPlanesLayout->addWidget(buttonDelete, 0, 3);
368 GroupPlanesLayout->addWidget(aLabel, 1, 0, 1, 4);
369 GroupPlanesLayout->addWidget(ActorList, 2, 0, 1, 4);
370 GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 4);
371 GroupPlanesLayout->setColumnStretch( 1, 1 );
373 // Controls for defining plane parameters
374 QGroupBox* GroupParameters = new QGroupBox(tr("SMESH_PARAMETERS"), this);
375 QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
376 GroupParametersLayout->setSpacing(SPACING);
377 GroupParametersLayout->setMargin(MARGIN);
379 TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
381 ComboBoxOrientation = new QComboBox(GroupParameters);
383 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
385 SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
387 TextLabelRot1 = new QLabel(tr("ROTATION_AROUND_X_Y2Z"), GroupParameters);
389 SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
391 TextLabelRot2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
393 SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
395 PreviewCheckBox = new QCheckBox(tr("SHOW_PREVIEW"), GroupParameters);
396 PreviewCheckBox->setChecked(true);
398 AutoApplyCheckBox = new QCheckBox(tr("AUTO_APPLY"), GroupParameters);
399 AutoApplyCheckBox->setChecked(false);
401 GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
402 GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
403 GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
404 GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
405 GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
406 GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
407 GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
408 GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
409 GroupParametersLayout->addWidget(PreviewCheckBox, 4, 0);
410 GroupParametersLayout->addWidget(AutoApplyCheckBox, 4, 1);
412 // Controls for "Ok", "Apply" and "Close" button
413 QGroupBox* GroupButtons = new QGroupBox(this);
414 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
415 GroupButtonsLayout->setSpacing(SPACING);
416 GroupButtonsLayout->setMargin(MARGIN);
418 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
419 buttonOk->setAutoDefault(true);
420 buttonOk->setDefault(true);
421 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
422 buttonApply->setAutoDefault(true);
423 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
424 buttonCancel->setAutoDefault(true);
425 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
426 buttonHelp->setAutoDefault(true);
427 GroupButtonsLayout->addWidget(buttonOk);
428 GroupButtonsLayout->addSpacing(10);
429 GroupButtonsLayout->addWidget(buttonApply);
430 GroupButtonsLayout->addSpacing(10);
431 GroupButtonsLayout->addStretch();
432 GroupButtonsLayout->addWidget(buttonCancel);
433 GroupButtonsLayout->addWidget(buttonHelp);
435 SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
436 SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
437 SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
440 SpinBoxDistance->RangeStepAndValidator(0.0, 1.0, 0.01, "length_precision" );
441 SpinBoxRot1->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
442 SpinBoxRot2->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
444 ComboBoxOrientation->addItem(tr("ALONG_XY"));
445 ComboBoxOrientation->addItem(tr("ALONG_YZ"));
446 ComboBoxOrientation->addItem(tr("ALONG_ZX"));
448 SpinBoxDistance->SetValue(0.5);
450 myIsSelectPlane = false;
452 initializePlaneData();
455 myHelpFileName = "clipping_page.html";
457 // signals and slots connections :
458 connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
459 connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
460 connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
461 connect(ActorList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onActorItemChanged(QListWidgetItem*)));
462 connect(SelectAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onSelectAll(int)));
463 connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
464 connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
465 connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
466 connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
467 connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
468 connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
469 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
470 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
471 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
472 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
473 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
474 /* to close dialog if study frame change */
475 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(ClickOnCancel()));
480 //=================================================================================
481 // function : ~SMESHGUI_ClippingDlg()
483 //=================================================================================
484 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
486 // no need to delete child widgets, Qt does it all for us
487 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
489 SMESH::RenderViewWindow(myViewWindow);
492 double SMESHGUI_ClippingDlg::getDistance() const
494 return SpinBoxDistance->GetValue();
497 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
499 SpinBoxDistance->SetValue( theDistance );
502 double SMESHGUI_ClippingDlg::getRotation1() const
504 return SpinBoxRot1->GetValue();
507 double SMESHGUI_ClippingDlg::getRotation2() const
509 return SpinBoxRot2->GetValue();
512 //=======================================================================
513 // function : ClickOnApply()
515 //=======================================================================
516 void SMESHGUI_ClippingDlg::ClickOnApply()
519 SUIT_OverrideCursor wc;
521 QWidget *aCurrWid = this->focusWidget();
522 aCurrWid->clearFocus();
523 aCurrWid->setFocus();
525 SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
526 SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
528 // clean memory allocated for planes
529 SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
530 for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
531 if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
534 aClippingPlaneInfoList.clear();
536 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
537 vtkActorCollection* anAllActors = aCopy.GetActors();
538 anAllActors->InitTraversal();
539 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
540 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
541 anActor->RemoveAllClippingPlanes();
543 SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
544 for( ; anIter2 != myPlanes.end(); anIter2++ ) {
545 SMESH::TPlaneData aPlaneData = *anIter2;
546 SMESH::TPlane aPlane = aPlaneData.Plane;
547 SMESH::TActorList anActorList = aPlaneData.ActorList;
548 if( anActorList.empty() )
551 SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
552 anOrientedPlane->ShallowCopy(aPlane.GetPointer());
554 SMESH::TActorList::iterator anIter3 = anActorList.begin();
555 for( ; anIter3 != anActorList.end(); anIter3++ )
556 if( vtkActor* aVTKActor = *anIter3 )
557 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
558 anActor->AddClippingPlane(anOrientedPlane);
560 SMESH::ClippingPlaneInfo aClippingPlaneInfo;
561 aClippingPlaneInfo.Plane = anOrientedPlane;
562 aClippingPlaneInfo.ActorList = anActorList;
564 aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
567 SMESH::RenderViewWindow( myViewWindow );
571 //=======================================================================
572 // function : ClickOnOk()
574 //=======================================================================
575 void SMESHGUI_ClippingDlg::ClickOnOk()
581 //=======================================================================
582 // function : ClickOnCancel()
584 //=======================================================================
585 void SMESHGUI_ClippingDlg::ClickOnCancel()
590 //=================================================================================
591 // function : ClickOnHelp()
593 //=================================================================================
594 void SMESHGUI_ClippingDlg::ClickOnHelp()
596 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
598 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
602 platform = "winapplication";
604 platform = "application";
606 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
607 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
608 arg(app->resourceMgr()->stringValue("ExternalBrowser",
610 arg(myHelpFileName));
614 //=======================================================================
615 // function : onSelectPlane()
617 //=======================================================================
618 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
620 if (myPlanes.empty())
623 SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
624 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
627 SMESH::Orientation anOrientation = aPlane->GetOrientation();
630 double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
632 // Set plane parameters in the dialog
633 myIsSelectPlane = true;
634 setDistance(aPlane->GetDistance());
635 setRotation(aRot[0], aRot[1]);
636 switch (anOrientation) {
638 ComboBoxOrientation->setCurrentIndex(0);
639 onSelectOrientation(0);
642 ComboBoxOrientation->setCurrentIndex(1);
643 onSelectOrientation(1);
646 ComboBoxOrientation->setCurrentIndex(2);
647 onSelectOrientation(2);
650 myIsSelectPlane = false;
653 bool anIsBlocked = ActorList->blockSignals( true );
655 ActorList->blockSignals( anIsBlocked );
658 //=======================================================================
659 // function : ClickOnNew()
661 //=======================================================================
662 void SMESHGUI_ClippingDlg::ClickOnNew()
665 SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
666 SMESH::TPlane aTPlane(aPlane);
668 SMESH::TActorList anActorList;
669 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
670 vtkActorCollection* anAllActors = aCopy.GetActors();
671 anAllActors->InitTraversal();
672 while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
673 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
674 anActorList.push_back( anActor );
676 SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
678 myPlanes.push_back(aPlaneData);
680 if (PreviewCheckBox->isChecked())
681 aTPlane->myActor->VisibilityOn();
683 bool anIsBlocked = ActorList->blockSignals( true );
686 SetCurrentPlaneParam();
688 ActorList->blockSignals( anIsBlocked );
692 //=======================================================================
693 // function : ClickOnDelete()
695 //=======================================================================
696 void SMESHGUI_ClippingDlg::ClickOnDelete()
698 if (myPlanes.empty())
701 int aPlaneIndex = ComboBoxPlanes->currentIndex();
703 SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
704 SMESH::TPlaneData aPlaneData = *anIter;
705 aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
706 myPlanes.erase(anIter);
708 if(AutoApplyCheckBox->isChecked())
712 SMESH::RenderViewWindow( myViewWindow );
715 //=======================================================================
716 // function : updateActorItem()
718 //=======================================================================
719 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
720 bool theUpdateSelectAll,
721 bool theUpdateClippingPlaneMap )
723 // update Select All check box
724 if( theUpdateSelectAll ) {
725 int aNbItems = ActorList->count(), aNbChecked = 0;
726 for( int i = 0; i < aNbItems; i++ )
727 if( QListWidgetItem* anItem = ActorList->item( i ) )
728 if( anItem->checkState() == Qt::Checked )
731 Qt::CheckState aCheckState = Qt::Unchecked;
732 if( aNbChecked == aNbItems )
733 aCheckState = Qt::Checked;
734 else if( aNbChecked > 0 )
735 aCheckState = Qt::PartiallyChecked;
737 bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
738 SelectAllCheckBox->setCheckState( aCheckState );
739 SelectAllCheckBox->blockSignals( anIsBlocked );
742 // update clipping plane map
743 if( theUpdateClippingPlaneMap ) {
744 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
745 if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
746 if( SMESH_Actor* anActor = anItem->getActor() ) {
747 SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
748 SMESH::TActorList& anActorList = aPlaneData.ActorList;
749 bool anIsPushed = false;
750 SMESH::TActorList::iterator anIter = anActorList.begin();
751 for ( ; anIter != anActorList.end(); anIter++ ) {
752 if( anActor == *anIter ) {
757 if( theItem->checkState() == Qt::Checked && !anIsPushed )
758 anActorList.push_back( anActor );
759 else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
760 anActorList.remove( anActor );
766 //=======================================================================
767 // function : onActorItemChanged()
769 //=======================================================================
770 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
772 updateActorItem( theItem, true, true );
773 SetCurrentPlaneParam();
776 //=======================================================================
777 // function : onSelectAll()
779 //=======================================================================
780 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
782 if( theState == Qt::PartiallyChecked ) {
783 SelectAllCheckBox->setCheckState( Qt::Checked );
787 bool anIsBlocked = ActorList->blockSignals( true );
788 for( int i = 0, n = ActorList->count(); i < n; i++ ) {
789 if( QListWidgetItem* anItem = ActorList->item( i ) ) {
790 anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
791 updateActorItem( anItem, false, true );
794 SelectAllCheckBox->setTristate( false );
795 ActorList->blockSignals( anIsBlocked );
796 SetCurrentPlaneParam();
799 //=======================================================================
800 // function : onSelectOrientation()
802 //=======================================================================
803 void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
805 if (myPlanes.empty())
809 TextLabelRot1->setText(tr("ROTATION_AROUND_X_Y2Z"));
810 TextLabelRot2->setText(tr("ROTATION_AROUND_Y_X2Z"));
812 else if (theItem == 1) {
813 TextLabelRot1->setText(tr("ROTATION_AROUND_Y_Z2X"));
814 TextLabelRot2->setText(tr("ROTATION_AROUND_Z_Y2X"));
816 else if (theItem == 2) {
817 TextLabelRot1->setText(tr("ROTATION_AROUND_Z_X2Y"));
818 TextLabelRot2->setText(tr("ROTATION_AROUND_X_Z2Y"));
821 if((QComboBox*)sender() == ComboBoxOrientation)
822 SetCurrentPlaneParam();
825 //=======================================================================
826 // function : synchronize()
828 //=======================================================================
829 void SMESHGUI_ClippingDlg::synchronize()
831 int aNbPlanes = myPlanes.size();
832 ComboBoxPlanes->clear();
835 for(int i = 1; i<=aNbPlanes; i++) {
836 aName = QString(tr("PLANE_NUM")).arg(i);
837 ComboBoxPlanes->addItem(aName);
840 int aPos = ComboBoxPlanes->count() - 1;
841 ComboBoxPlanes->setCurrentIndex(aPos);
843 bool anIsControlsEnable = (aPos >= 0);
844 if (anIsControlsEnable) {
848 ComboBoxPlanes->addItem(tr("NO_PLANES"));
850 SpinBoxRot1->SetValue(0.0);
851 SpinBoxRot2->SetValue(0.0);
852 SpinBoxDistance->SetValue(0.5);
855 ActorList->setEnabled(anIsControlsEnable);
856 SelectAllCheckBox->setEnabled(anIsControlsEnable);
857 buttonDelete->setEnabled(anIsControlsEnable);
858 // the following 3 controls should be enabled
859 //buttonApply->setEnabled(anIsControlsEnable);
860 //PreviewCheckBox->setEnabled(anIsControlsEnable);
861 //AutoApplyCheckBox->setEnabled(anIsControlsEnable);
862 ComboBoxOrientation->setEnabled(anIsControlsEnable);
863 SpinBoxDistance->setEnabled(anIsControlsEnable);
864 SpinBoxRot1->setEnabled(anIsControlsEnable);
865 SpinBoxRot2->setEnabled(anIsControlsEnable);
868 //=======================================================================
869 // function : setRotation()
871 //=======================================================================
872 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
874 SpinBoxRot1->SetValue(theRot1);
875 SpinBoxRot2->SetValue(theRot2);
878 //=======================================================================
879 // function : SetCurrentPlaneParam()
881 //=======================================================================
882 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
884 if (myPlanes.empty() || myIsSelectPlane)
887 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
889 SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
890 SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
892 vtkFloatingPointType aNormal[3];
893 SMESH::Orientation anOrientation;
894 vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
896 static double aCoeff = vtkMath::Pi()/180.0;
898 vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
899 aPlane->myAngle[0] = aRot[0];
900 aPlane->myAngle[1] = aRot[1];
902 vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
903 vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
904 aV[0] = aRot[0] > 0? aV[0]: -aV[0];
905 aV[1] = aRot[1] > 0? aV[1]: -aV[1];
907 switch (ComboBoxOrientation->currentIndex()) {
909 anOrientation = SMESH::XY;
919 anOrientation = SMESH::YZ;
929 anOrientation = SMESH::ZX;
940 vtkMath::Cross(aDir[1],aDir[0],aNormal);
941 vtkMath::Normalize(aNormal);
942 vtkMath::Cross(aNormal,aDir[1],aDir[0]);
945 aPlane->SetOrientation(anOrientation);
946 aPlane->SetDistance(getDistance());
948 SMESH::TActorList anActorList = aPlaneData.ActorList;
950 vtkFloatingPointType aBounds[6];
951 vtkFloatingPointType anOrigin[3];
952 bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
958 aPlane->myActor->SetVisibility( anIsOk && PreviewCheckBox->isChecked() );
961 aPlane->SetNormal( aNormal );
962 aPlane->SetOrigin( anOrigin );
964 vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
965 ( aBounds[2] + aBounds[3] ) / 2.,
966 ( aBounds[4] + aBounds[5] ) / 2. };
968 vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
969 pow( aBounds[3] - aBounds[2], 2 ) +
970 pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
972 vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
973 {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
974 vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
976 vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
977 aPnt[1] - aDelta[0][1] - aDelta[1][1],
978 aPnt[2] - aDelta[0][2] - aDelta[1][2]};
979 vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
980 aPnt01[1] + aNormal[1],
981 aPnt01[2] + aNormal[2]};
982 vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
984 vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
985 aPnt[1] - aDelta[0][1] + aDelta[1][1],
986 aPnt[2] - aDelta[0][2] + aDelta[1][2]};
987 vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
988 aPnt11[1] + aNormal[1],
989 aPnt11[2] + aNormal[2]};
990 vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
992 vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
993 aPnt[1] + aDelta[0][1] - aDelta[1][1],
994 aPnt[2] + aDelta[0][2] - aDelta[1][2]};
995 vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
996 aPnt21[1] + aNormal[1],
997 aPnt21[2] + aNormal[2]};
998 vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1000 vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1001 aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
1002 aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
1003 aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
1004 aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
1007 if(AutoApplyCheckBox->isChecked())
1010 SMESH::RenderViewWindow( myViewWindow );
1013 //=======================================================================
1014 // function : OnPreviewToggle()
1016 //=======================================================================
1017 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1019 std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1020 SMESH::RenderViewWindow( myViewWindow );
1023 //=================================================================================
1024 // function : keyPressEvent()
1026 //=================================================================================
1027 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1029 QDialog::keyPressEvent( e );
1030 if ( e->isAccepted() )
1033 if ( e->key() == Qt::Key_F1 ) {
1039 //=================================================================================
1040 // function : initializePlaneData()
1042 //=================================================================================
1043 void SMESHGUI_ClippingDlg::initializePlaneData()
1045 const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1046 SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
1047 if( anIter1 != aClippingPlaneInfoMap.end() ) {
1048 const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
1049 SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
1050 for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
1051 const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
1052 SMESH::TPlane aTPlane( aClippingPlaneInfo.Plane );
1053 SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
1054 myPlanes.push_back( aPlaneData );
1057 std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1060 //=================================================================================
1061 // function : updateActorList()
1063 //=================================================================================
1064 void SMESHGUI_ClippingDlg::updateActorList()
1068 SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1072 _PTR(Study) aStudy = anAppStudy->studyDS();
1079 int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1080 const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1081 const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1083 VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1084 vtkActorCollection* anAllActors = aCopy.GetActors();
1085 anAllActors->InitTraversal();
1086 while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1087 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1088 if( anActor->hasIO() ) {
1089 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1090 if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1091 bool anIsChecked = false;
1092 SMESH::TActorList::const_iterator anIter = anActorList.begin();
1093 for ( ; anIter != anActorList.end(); anIter++ ) {
1094 if( vtkActor* aVTKActorRef = *anIter ) {
1095 if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1096 if( anActorRef == anActor ) {
1103 QString aName = QString( aSObj->GetName().c_str() );
1104 QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
1105 anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1106 updateActorItem( anItem, true, false );
1113 //=================================================================================
1114 // function : getCurrentActors()
1116 //=================================================================================
1117 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1119 SMESH::TActorList anActorList;
1120 for( int i = 0, n = ActorList->count(); i < n; i++ )
1121 if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1122 if( anItem->checkState() == Qt::Checked )
1123 if( SMESH_Actor* anActor = anItem->getActor() )
1124 anActorList.push_back( anActor );
1128 //=================================================================================
1129 // function : dumpPlaneData()
1131 //=================================================================================
1132 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1134 printf( "----------- Plane Data -----------\n" );
1136 SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1137 for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1138 SMESH::TPlaneData aPlaneData = *anIter1;
1139 SMESH::TPlane aPlane = aPlaneData.Plane;
1140 vtkFloatingPointType* aNormal = aPlane->GetNormal();
1141 vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
1142 printf( "Plane N%d:\n", anId );
1143 printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1144 printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1146 SMESH::TActorList anActorList = aPlaneData.ActorList;
1147 SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1148 for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1149 if( vtkActor* aVTKActor = *anIter2 ) {
1150 if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1151 printf( " - Actor: '%s'\n", anActor->getName() );
1154 printf( " - Actor: NULL\n");
1157 printf( "----------------------------------\n" );