Salome HOME
Implementation of the "0022102: EDF 1496 SMESH : Displaying of discrete elements...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ClippingDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_ClippingDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_ClippingDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37
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>
45
46 #include <SALOME_ListIO.hxx>
47
48 #include <SalomeApp_Study.h>
49
50 #include <LightApp_Application.h>
51
52 #include <VTKViewer_Algorithm.h>
53
54 #include <SVTK_ViewWindow.h>
55
56 // Qt includes
57 #include <QLabel>
58 #include <QPushButton>
59 #include <QComboBox>
60 #include <QCheckBox>
61 #include <QVBoxLayout>
62 #include <QHBoxLayout>
63 #include <QGridLayout>
64 #include <QGroupBox>
65 #include <QKeyEvent>
66 #include <QListWidget>
67
68 // VTK includes
69 #include <vtkMath.h>
70 #include <vtkDataSet.h>
71 #include <vtkDataSetMapper.h>
72 #include <vtkPlaneSource.h>
73 #include <vtkProperty.h>
74 #include <vtkRenderer.h>
75
76 #define SPACING 6
77 #define MARGIN  11
78
79 //=================================================================================
80 // class    : OrientedPlane
81 // purpose  :
82 //=================================================================================
83 SMESH::OrientedPlane* SMESH::OrientedPlane::New()
84 {
85   return new OrientedPlane();
86 }
87
88 SMESH::OrientedPlane* SMESH::OrientedPlane::New(SVTK_ViewWindow* theViewWindow)
89 {
90   return new OrientedPlane(theViewWindow);
91 }
92
93 void SMESH::OrientedPlane::ShallowCopy(SMESH::OrientedPlane* theOrientedPlane)
94 {
95   SetNormal(theOrientedPlane->GetNormal());
96   SetOrigin(theOrientedPlane->GetOrigin());
97
98   myOrientation = theOrientedPlane->GetOrientation();
99   myDistance = theOrientedPlane->GetDistance();
100
101   myAngle[0] = theOrientedPlane->myAngle[0];
102   myAngle[1] = theOrientedPlane->myAngle[1];
103
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();
109 }
110
111 SMESH::OrientedPlane::OrientedPlane(SVTK_ViewWindow* theViewWindow):
112   myViewWindow(theViewWindow),
113   myOrientation(SMESH::XY),
114   myDistance(0.5)
115 {
116   Init();
117   myViewWindow->AddActor(myActor, false, false); // don't adjust actors
118 }
119
120 SMESH::OrientedPlane::OrientedPlane():
121   myOrientation(SMESH::XY),
122   myViewWindow(NULL),
123   myDistance(0.5)
124 {
125   Init();
126 }
127
128 void SMESH::OrientedPlane::Init()
129 {
130   myPlaneSource = vtkPlaneSource::New();
131
132   myAngle[0] = myAngle[1] = 0.0;
133
134   // Create and display actor
135   myMapper = vtkDataSetMapper::New();
136   myMapper->SetInputConnection(myPlaneSource->GetOutputPort());
137
138   myActor = SALOME_Actor::New();
139   myActor->VisibilityOff();
140   myActor->PickableOff();
141   myActor->SetInfinitive(true);
142   myActor->SetMapper(myMapper);
143
144   QColor ffc, bfc;
145   int delta;
146   SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "255, 170, 0|-100" ) ;
147  
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);
153   aProp->Delete();
154
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);
160   aBackProp->Delete();
161 }
162
163 SMESH::OrientedPlane::~OrientedPlane()
164 {
165   if (myViewWindow)
166     myViewWindow->RemoveActor(myActor);
167   myActor->Delete();
168     
169   myMapper->RemoveAllInputs();
170   myMapper->Delete();
171
172   // commented: porting to vtk 5.0
173   //    myPlaneSource->UnRegisterAllOutputs();
174   myPlaneSource->Delete();
175 }
176
177 //=================================================================================
178 // class    : ActorItem
179 // purpose  :
180 //=================================================================================
181 class ActorItem : public QListWidgetItem
182 {
183 public:
184   ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) :
185     QListWidgetItem( theName, theListWidget ),
186     myActor( theActor ) {}
187
188   SMESH_Actor* getActor() const { return myActor; }
189
190 private:
191   SMESH_Actor* myActor;
192 };
193
194 //=================================================================================
195 // class    : TSetVisibility
196 // purpose  :
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);
203   }
204   int myIsVisible;
205 };
206
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,
214                                                       double                     theDistance,
215                                                       const double theAngle[2])
216 {
217   SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(theViewWindow);
218
219   aPlane->myAngle[0] = theAngle[0];
220   aPlane->myAngle[1] = theAngle[1];
221
222   aPlane->SetOrientation(theOrientation);
223   aPlane->SetDistance(theDistance);
224
225   double aNormal[3];
226   double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
227   {
228     static double aCoeff = vtkMath::Pi()/180.0;
229
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];
234
235     switch (theOrientation) {
236     case SMESH::XY:
237       aDir[0][1] = anU[0];
238       aDir[0][2] = aV[0];
239
240       aDir[1][0] = anU[1];
241       aDir[1][2] = aV[1];
242
243       break;
244     case SMESH::YZ:
245       aDir[0][2] = anU[0];
246       aDir[0][0] = aV[0];
247
248       aDir[1][1] = anU[1];
249       aDir[1][0] = aV[1];
250
251       break;
252     case SMESH::ZX:
253       aDir[0][0] = anU[0];
254       aDir[0][1] = aV[0];
255
256       aDir[1][2] = anU[1];
257       aDir[1][1] = aV[1];
258
259       break;
260     }
261
262     vtkMath::Cross(aDir[1],aDir[0],aNormal);
263     vtkMath::Normalize(aNormal);
264     vtkMath::Cross(aNormal,aDir[1],aDir[0]);
265   }
266
267   double aBounds[6];
268   double anOrigin[3];
269
270   bool anIsOk = false;
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;
277     anIsOk = true;
278   }
279   else
280     anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
281                                                     aNormal,
282                                                     theDistance,
283                                                     aBounds,
284                                                     anOrigin );
285   if( !anIsOk )
286     return NULL;
287
288   aPlane->SetNormal( aNormal );
289   aPlane->SetOrigin( anOrigin );
290
291   double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
292                                    ( aBounds[2] + aBounds[3] ) / 2.,
293                                    ( aBounds[4] + aBounds[5] ) / 2. };
294
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 );
298
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];
302
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);
310
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);
318
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);
326
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();
333
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 );
339
340   return aPlane;
341 }
342
343 //=================================================================================
344 // class    : SMESHGUI_ClippingDlg()
345 // purpose  :
346 //
347 //=================================================================================
348 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
349   QDialog( SMESH::GetDesktop(theModule) ),
350   mySMESHGUI(theModule),
351   myViewWindow(theViewWindow)
352 {
353   setModal( false );
354   setAttribute( Qt::WA_DeleteOnClose, true );
355   setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
356   setSizeGripEnabled(true);
357
358   QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
359   SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
360   SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
361
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);
367
368   ComboBoxPlanes = new QComboBox(GroupPlanes);
369
370   buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
371
372   buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
373
374   QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
375
376   ActorList = new QListWidget(GroupPlanes);
377   ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
378   
379   SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
380
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 );
389
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);
395
396   TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
397
398   ComboBoxOrientation = new QComboBox(GroupParameters);
399
400   TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
401
402   SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
403
404   TextLabelRot1 = new QLabel(tr("ROTATION_AROUND_X_Y2Z"), GroupParameters);
405
406   SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
407
408   TextLabelRot2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
409
410   SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
411
412   PreviewCheckBox = new QCheckBox(tr("SHOW_PREVIEW"), GroupParameters);
413   PreviewCheckBox->setChecked(true);
414
415   AutoApplyCheckBox = new QCheckBox(tr("AUTO_APPLY"), GroupParameters);
416   AutoApplyCheckBox->setChecked(false);
417
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);
428
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);
434   
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);
451
452   SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
453   SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
454   SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
455
456   // Initial state
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" );
460
461   ComboBoxOrientation->addItem(tr("ALONG_XY"));
462   ComboBoxOrientation->addItem(tr("ALONG_YZ"));
463   ComboBoxOrientation->addItem(tr("ALONG_ZX"));
464
465   SpinBoxDistance->SetValue(0.5);
466
467   myIsSelectPlane = false;
468
469   initializePlaneData();
470   synchronize();
471
472   myHelpFileName = "clipping_page.html";
473
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()));
493
494   this->show();
495 }
496
497 //=================================================================================
498 // function : ~SMESHGUI_ClippingDlg()
499 // purpose  :
500 //=================================================================================
501 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
502 {
503   // no need to delete child widgets, Qt does it all for us
504   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
505   if (myViewWindow)
506     SMESH::RenderViewWindow(myViewWindow);
507 }
508
509 double SMESHGUI_ClippingDlg::getDistance() const
510 {
511   return SpinBoxDistance->GetValue();
512 }
513
514 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
515 {
516   SpinBoxDistance->SetValue( theDistance );
517 }
518
519 double SMESHGUI_ClippingDlg::getRotation1() const
520 {
521   return SpinBoxRot1->GetValue();
522 }
523
524 double SMESHGUI_ClippingDlg::getRotation2() const
525 {
526   return SpinBoxRot2->GetValue();
527 }
528
529 //=======================================================================
530 // function : ClickOnApply()
531 // purpose  :
532 //=======================================================================
533 void SMESHGUI_ClippingDlg::ClickOnApply()
534 {
535   if (myViewWindow) {
536     SUIT_OverrideCursor wc;
537     
538     QWidget *aCurrWid = this->focusWidget();
539     aCurrWid->clearFocus();
540     aCurrWid->setFocus();
541
542     SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
543     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
544
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 )
549         aPlane->Delete();
550
551     aClippingPlaneInfoList.clear();
552
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();
559
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;
565
566       // the check is disabled to support planes with empty actor list
567       //if( anActorList.empty() )
568       //  continue;
569
570       SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
571       anOrientedPlane->ShallowCopy(aPlane.GetPointer());
572
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);
578
579       SMESH::ClippingPlaneInfo aClippingPlaneInfo;
580       aClippingPlaneInfo.Plane = anOrientedPlane;
581       aClippingPlaneInfo.ActorList = anActorList;
582
583       aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
584     }
585
586     SMESH::RenderViewWindow( myViewWindow );
587   }
588 }
589
590 //=======================================================================
591 // function : ClickOnOk()
592 // purpose  :
593 //=======================================================================
594 void SMESHGUI_ClippingDlg::ClickOnOk()
595 {
596   ClickOnApply();
597   reject();
598 }
599
600 //=======================================================================
601 // function : reject()
602 // purpose  :
603 //=======================================================================
604 void SMESHGUI_ClippingDlg::reject()
605 {
606   //here we can insert actions to do at close.
607   QDialog::reject();
608 }
609
610 //=================================================================================
611 // function : ClickOnHelp()
612 // purpose  :
613 //=================================================================================
614 void SMESHGUI_ClippingDlg::ClickOnHelp()
615 {
616   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
617   if (app) 
618     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
619   else {
620                 QString platform;
621 #ifdef WIN32
622                 platform = "winapplication";
623 #else
624                 platform = "application";
625 #endif
626     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
627                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
628                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
629                                                                  platform)).
630                              arg(myHelpFileName));
631   }
632 }
633
634 //=======================================================================
635 // function : onSelectPlane()
636 // purpose  :
637 //=======================================================================
638 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
639 {
640   if (myPlanes.empty())
641     return;
642
643   SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
644   SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
645
646   // Orientation
647   SMESH::Orientation anOrientation = aPlane->GetOrientation();
648
649   // Rotations
650   double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
651
652   // Set plane parameters in the dialog
653   myIsSelectPlane = true;
654   setDistance(aPlane->GetDistance());
655   setRotation(aRot[0], aRot[1]);
656   switch (anOrientation) {
657   case SMESH::XY:
658     ComboBoxOrientation->setCurrentIndex(0);
659     onSelectOrientation(0);
660     break;
661   case SMESH::YZ:
662     ComboBoxOrientation->setCurrentIndex(1);
663     onSelectOrientation(1);
664     break;
665   case SMESH::ZX:
666     ComboBoxOrientation->setCurrentIndex(2);
667     onSelectOrientation(2);
668     break;
669   }
670   myIsSelectPlane = false;
671
672   // Actors
673   bool anIsBlocked = ActorList->blockSignals( true );
674   updateActorList();
675   ActorList->blockSignals( anIsBlocked );
676 }
677
678 //=======================================================================
679 // function : ClickOnNew()
680 // purpose  :
681 //=======================================================================
682 void SMESHGUI_ClippingDlg::ClickOnNew()
683 {
684   if(myViewWindow){
685     SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
686     SMESH::TPlane aTPlane(aPlane);
687
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 );
695
696     SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
697
698     myPlanes.push_back(aPlaneData);
699
700     if (PreviewCheckBox->isChecked())
701       aTPlane->myActor->VisibilityOn();
702
703     bool anIsBlocked = ActorList->blockSignals( true );
704
705     synchronize();
706     SetCurrentPlaneParam();
707
708     ActorList->blockSignals( anIsBlocked );
709   }
710 }
711
712 //=======================================================================
713 // function : ClickOnDelete()
714 // purpose  :
715 //=======================================================================
716 void SMESHGUI_ClippingDlg::ClickOnDelete()
717 {
718   if (myPlanes.empty())
719     return;
720
721   int aPlaneIndex = ComboBoxPlanes->currentIndex();
722
723   SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
724   SMESH::TPlaneData aPlaneData = *anIter;
725   aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
726   myPlanes.erase(anIter);
727
728   if(AutoApplyCheckBox->isChecked())
729     ClickOnApply();
730
731   synchronize();
732   SMESH::RenderViewWindow( myViewWindow );
733 }
734
735 //=======================================================================
736 // function : updateActorItem()
737 // purpose  :
738 //=======================================================================
739 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
740                                             bool theUpdateSelectAll,
741                                             bool theUpdateClippingPlaneMap )
742 {
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 )
749           aNbChecked++;
750
751     bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
752     SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
753     SelectAllCheckBox->blockSignals( anIsBlocked );
754   }
755
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 ) {
767             anIsPushed = true;
768             break;
769           }
770         }
771         if( theItem->checkState() == Qt::Checked && !anIsPushed )
772           anActorList.push_back( anActor );
773         else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
774           anActorList.remove( anActor );
775       }
776     }
777   }
778 }
779
780 //=======================================================================
781 // function : onActorItemChanged()
782 // purpose  :
783 //=======================================================================
784 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
785 {
786   updateActorItem( theItem, true, true );
787   SetCurrentPlaneParam();
788 }
789
790 //=======================================================================
791 // function : onSelectAll()
792 // purpose  :
793 //=======================================================================
794 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
795 {
796   if( theState == Qt::PartiallyChecked ) {
797     SelectAllCheckBox->setCheckState( Qt::Checked );
798     return;
799   }
800
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 );
806     }
807   }
808   SelectAllCheckBox->setTristate( false );
809   ActorList->blockSignals( anIsBlocked );
810   SetCurrentPlaneParam();
811 }
812
813 //=======================================================================
814 // function : onSelectOrientation()
815 // purpose  :
816 //=======================================================================
817 void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
818 {
819   if (myPlanes.empty())
820     return;
821
822   if      (theItem == 0) {
823     TextLabelRot1->setText(tr("ROTATION_AROUND_X_Y2Z"));
824     TextLabelRot2->setText(tr("ROTATION_AROUND_Y_X2Z"));
825   }
826   else if (theItem == 1) {
827     TextLabelRot1->setText(tr("ROTATION_AROUND_Y_Z2X"));
828     TextLabelRot2->setText(tr("ROTATION_AROUND_Z_Y2X"));
829   }
830   else if (theItem == 2) {
831     TextLabelRot1->setText(tr("ROTATION_AROUND_Z_X2Y"));
832     TextLabelRot2->setText(tr("ROTATION_AROUND_X_Z2Y"));
833   }
834
835   if((QComboBox*)sender() == ComboBoxOrientation)
836     SetCurrentPlaneParam();
837 }
838
839 //=======================================================================
840 // function : synchronize()
841 // purpose  :
842 //=======================================================================
843 void SMESHGUI_ClippingDlg::synchronize()
844 {
845   int aNbPlanes = myPlanes.size();
846   ComboBoxPlanes->clear();
847
848   QString aName;
849   for(int i = 1; i<=aNbPlanes; i++) {
850     aName = QString(tr("PLANE_NUM")).arg(i);
851     ComboBoxPlanes->addItem(aName);
852   }
853
854   int aPos = ComboBoxPlanes->count() - 1;
855   ComboBoxPlanes->setCurrentIndex(aPos);
856
857   bool anIsControlsEnable = (aPos >= 0);
858   if (anIsControlsEnable) {
859     onSelectPlane(aPos);
860     updateActorList();
861   } else {
862     ComboBoxPlanes->addItem(tr("NO_PLANES"));
863     ActorList->clear();
864     SpinBoxRot1->SetValue(0.0);
865     SpinBoxRot2->SetValue(0.0);
866     SpinBoxDistance->SetValue(0.5);
867   }
868
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);
880 }
881
882 //=======================================================================
883 // function : setRotation()
884 // purpose  :
885 //=======================================================================
886 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
887 {
888   SpinBoxRot1->SetValue(theRot1);
889   SpinBoxRot2->SetValue(theRot2);
890 }
891
892 //=======================================================================
893 // function : SetCurrentPlaneParam()
894 // purpose  :
895 //=======================================================================
896 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
897 {
898   if (myPlanes.empty() || myIsSelectPlane)
899     return;
900
901   int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
902
903   SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
904   SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
905
906   double aNormal[3];
907   SMESH::Orientation anOrientation;
908   double aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
909   {
910     static double aCoeff = vtkMath::Pi()/180.0;
911
912     double aRot[2] = {getRotation1(), getRotation2()};
913     aPlane->myAngle[0] = aRot[0];
914     aPlane->myAngle[1] = aRot[1];
915
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];
920
921     switch (ComboBoxOrientation->currentIndex()) {
922     case 0:
923       anOrientation = SMESH::XY;
924
925       aDir[0][1] = anU[0];
926       aDir[0][2] = aV[0];
927
928       aDir[1][0] = anU[1];
929       aDir[1][2] = aV[1];
930
931       break;
932     case 1:
933       anOrientation = SMESH::YZ;
934
935       aDir[0][2] = anU[0];
936       aDir[0][0] = aV[0];
937
938       aDir[1][1] = anU[1];
939       aDir[1][0] = aV[1];
940
941       break;
942     case 2:
943       anOrientation = SMESH::ZX;
944
945       aDir[0][0] = anU[0];
946       aDir[0][1] = aV[0];
947
948       aDir[1][2] = anU[1];
949       aDir[1][1] = aV[1];
950
951       break;
952     }
953
954     vtkMath::Cross(aDir[1],aDir[0],aNormal);
955     vtkMath::Normalize(aNormal);
956     vtkMath::Cross(aNormal,aDir[1],aDir[0]);
957   }
958
959   aPlane->SetOrientation(anOrientation);
960   aPlane->SetDistance(getDistance());
961
962   SMESH::TActorList anActorList = aPlaneData.ActorList;
963
964   double aBounds[6];
965   double anOrigin[3];
966   bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
967                                                        aNormal,
968                                                        getDistance(),
969                                                        aBounds,
970                                                        anOrigin );
971
972   aPlane->myActor->SetVisibility( anIsOk && PreviewCheckBox->isChecked() );
973
974   if( anIsOk ) {
975     aPlane->SetNormal( aNormal );
976     aPlane->SetOrigin( anOrigin );
977
978     double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
979                                      ( aBounds[2] + aBounds[3] ) / 2.,
980                                      ( aBounds[4] + aBounds[5] ) / 2. };
981
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 );
985
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];
989
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);
997
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);
1005
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);
1013
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();
1020   }
1021
1022   if(AutoApplyCheckBox->isChecked())
1023     ClickOnApply();
1024
1025   SMESH::RenderViewWindow( myViewWindow );
1026 }
1027
1028 //=======================================================================
1029 // function : OnPreviewToggle()
1030 // purpose  :
1031 //=======================================================================
1032 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1033 {
1034   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1035   SMESH::RenderViewWindow( myViewWindow );
1036 }
1037
1038 //=================================================================================
1039 // function : keyPressEvent()
1040 // purpose  :
1041 //=================================================================================
1042 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1043 {
1044   QDialog::keyPressEvent( e );
1045   if ( e->isAccepted() )
1046     return;
1047
1048   if ( e->key() == Qt::Key_F1 ) {
1049     e->accept();
1050     ClickOnHelp();
1051   }
1052 }
1053
1054 //=================================================================================
1055 // function : initializePlaneData()
1056 // purpose  :
1057 //=================================================================================
1058 void SMESHGUI_ClippingDlg::initializePlaneData()
1059 {
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 );
1072     }
1073   }
1074   std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1075 }
1076
1077 //=================================================================================
1078 // function : updateActorList()
1079 // purpose  :
1080 //=================================================================================
1081 void SMESHGUI_ClippingDlg::updateActorList()
1082 {
1083   ActorList->clear();
1084
1085   SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1086   if( !anAppStudy )
1087     return;
1088
1089   _PTR(Study) aStudy = anAppStudy->studyDS();
1090   if( !aStudy )
1091     return;
1092
1093   if( !myViewWindow )
1094     return;
1095
1096   int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1097   const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1098   const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1099
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 ) {
1114                   anIsChecked = true;
1115                   break;
1116                 }
1117               }
1118             }
1119           }
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 );
1124         }
1125       }
1126     }
1127   }
1128 }
1129
1130 //=================================================================================
1131 // function : getCurrentActors()
1132 // purpose  :
1133 //=================================================================================
1134 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1135 {
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 );
1142   return anActorList;
1143 }
1144
1145 //=================================================================================
1146 // function : dumpPlaneData()
1147 // purpose  :
1148 //=================================================================================
1149 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1150 {
1151   printf( "----------- Plane Data -----------\n" );
1152   int anId = 1;
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] );
1162
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() );
1169       }
1170       else
1171         printf( "  - Actor: NULL\n");
1172     }
1173   }
1174   printf( "----------------------------------\n" );
1175 }
1176
1177 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1178 {
1179   if ( toggled ) ClickOnApply();
1180 }