Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ClippingDlg.cxx
1 // Copyright (C) 2007-2011  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 }
109
110 SMESH::OrientedPlane::OrientedPlane(SVTK_ViewWindow* theViewWindow):
111   myViewWindow(theViewWindow),
112   myOrientation(SMESH::XY),
113   myDistance(0.5)
114 {
115   Init();
116   myViewWindow->AddActor(myActor, false, false); // don't adjust actors
117 }
118
119 SMESH::OrientedPlane::OrientedPlane():
120   myOrientation(SMESH::XY),
121   myViewWindow(NULL),
122   myDistance(0.5)
123 {
124   Init();
125 }
126
127 void SMESH::OrientedPlane::Init()
128 {
129   myPlaneSource = vtkPlaneSource::New();
130
131   myAngle[0] = myAngle[1] = 0.0;
132
133   // Create and display actor
134   myMapper = vtkDataSetMapper::New();
135   myMapper->SetInput(myPlaneSource->GetOutput());
136
137   myActor = SALOME_Actor::New();
138   myActor->VisibilityOff();
139   myActor->PickableOff();
140   myActor->SetInfinitive(true);
141   myActor->SetMapper(myMapper);
142
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);
149   aProp->Delete();
150
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);
156   aBackProp->Delete();
157 }
158
159 SMESH::OrientedPlane::~OrientedPlane()
160 {
161   if (myViewWindow)
162     myViewWindow->RemoveActor(myActor);
163   myActor->Delete();
164     
165   myMapper->RemoveAllInputs();
166   myMapper->Delete();
167
168   // commented: porting to vtk 5.0
169   //    myPlaneSource->UnRegisterAllOutputs();
170   myPlaneSource->Delete();
171 }
172
173 //=================================================================================
174 // class    : ActorItem
175 // purpose  :
176 //=================================================================================
177 class ActorItem : public QListWidgetItem
178 {
179 public:
180   ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) :
181     QListWidgetItem( theName, theListWidget ),
182     myActor( theActor ) {}
183
184   SMESH_Actor* getActor() const { return myActor; }
185
186 private:
187   SMESH_Actor* myActor;
188 };
189
190 //=================================================================================
191 // class    : TSetVisibility
192 // purpose  :
193 //=================================================================================
194 struct TSetVisibility {
195   TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){}
196   void operator()(SMESH::TPlaneData& thePlaneData){
197     bool anIsEmpty = thePlaneData.ActorList.empty();
198     thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty);
199   }
200   int myIsVisible;
201 };
202
203 //=================================================================================
204 // used in SMESHGUI::restoreVisualParameters() to avoid
205 // declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
206 //=================================================================================
207 SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList          theActorList,
208                                                       SVTK_ViewWindow*           theViewWindow,
209                                                       SMESH::Orientation         theOrientation,
210                                                       double                     theDistance,
211                                                       const vtkFloatingPointType theAngle[2])
212 {
213   SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(theViewWindow);
214
215   aPlane->myAngle[0] = theAngle[0];
216   aPlane->myAngle[1] = theAngle[1];
217
218   aPlane->SetOrientation(theOrientation);
219   aPlane->SetDistance(theDistance);
220
221   vtkFloatingPointType aNormal[3];
222   vtkFloatingPointType aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
223   {
224     static double aCoeff = vtkMath::Pi()/180.0;
225
226     vtkFloatingPointType anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
227     vtkFloatingPointType aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
228     aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
229     aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
230
231     switch (theOrientation) {
232     case SMESH::XY:
233       aDir[0][1] = anU[0];
234       aDir[0][2] = aV[0];
235
236       aDir[1][0] = anU[1];
237       aDir[1][2] = aV[1];
238
239       break;
240     case SMESH::YZ:
241       aDir[0][2] = anU[0];
242       aDir[0][0] = aV[0];
243
244       aDir[1][1] = anU[1];
245       aDir[1][0] = aV[1];
246
247       break;
248     case SMESH::ZX:
249       aDir[0][0] = anU[0];
250       aDir[0][1] = aV[0];
251
252       aDir[1][2] = anU[1];
253       aDir[1][1] = aV[1];
254
255       break;
256     }
257
258     vtkMath::Cross(aDir[1],aDir[0],aNormal);
259     vtkMath::Normalize(aNormal);
260     vtkMath::Cross(aNormal,aDir[1],aDir[0]);
261   }
262
263   vtkFloatingPointType aBounds[6];
264   vtkFloatingPointType anOrigin[3];
265
266   bool anIsOk = false;
267   if( theActorList.empty() ) {
268     // to support planes with empty actor list we should create
269     // a nullified plane that will be initialized later 
270     anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
271     aBounds[0] = aBounds[2] = aBounds[4] = 0;
272     aBounds[1] = aBounds[3] = aBounds[5] = 0;
273     anIsOk = true;
274   }
275   else
276     anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
277                                                     aNormal,
278                                                     theDistance,
279                                                     aBounds,
280                                                     anOrigin );
281   if( !anIsOk )
282     return NULL;
283
284   aPlane->SetNormal( aNormal );
285   aPlane->SetOrigin( anOrigin );
286
287   vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
288                                    ( aBounds[2] + aBounds[3] ) / 2.,
289                                    ( aBounds[4] + aBounds[5] ) / 2. };
290
291   vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
292                                    pow( aBounds[3] - aBounds[2], 2 ) +
293                                    pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
294
295   vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
296                                        {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
297   vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
298
299   vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
300                                     aPnt[1] - aDelta[0][1] - aDelta[1][1],
301                                     aPnt[2] - aDelta[0][2] - aDelta[1][2]};
302   vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
303                                     aPnt01[1] + aNormal[1],
304                                     aPnt01[2] + aNormal[2]};
305   vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
306
307   vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
308                                     aPnt[1] - aDelta[0][1] + aDelta[1][1],
309                                     aPnt[2] - aDelta[0][2] + aDelta[1][2]};
310   vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
311                                     aPnt11[1] + aNormal[1],
312                                     aPnt11[2] + aNormal[2]};
313   vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
314
315   vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
316                                     aPnt[1] + aDelta[0][1] - aDelta[1][1],
317                                     aPnt[2] + aDelta[0][2] - aDelta[1][2]};
318   vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
319                                     aPnt21[1] + aNormal[1],
320                                     aPnt21[2] + aNormal[2]};
321   vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
322
323   vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
324   aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
325   aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
326   aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
327   aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
328
329   SMESH::TActorList::iterator anIter = theActorList.begin();
330   for ( ; anIter != theActorList.end(); anIter++ )
331     if( vtkActor* aVTKActor = *anIter )
332       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
333         anActor->AddClippingPlane( aPlane );
334
335   return aPlane;
336 }
337
338 //=================================================================================
339 // class    : SMESHGUI_ClippingDlg()
340 // purpose  :
341 //
342 //=================================================================================
343 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
344   QDialog( SMESH::GetDesktop(theModule) ),
345   mySMESHGUI(theModule),
346   myViewWindow(theViewWindow)
347 {
348   setModal( false );
349   setAttribute( Qt::WA_DeleteOnClose, true );
350   setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
351   setSizeGripEnabled(true);
352
353   QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
354   SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
355   SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
356
357   // Controls for selecting, creating, deleting planes
358   QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
359   QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
360   GroupPlanesLayout->setSpacing(SPACING);
361   GroupPlanesLayout->setMargin(MARGIN);
362
363   ComboBoxPlanes = new QComboBox(GroupPlanes);
364
365   buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
366
367   buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
368
369   QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
370
371   ActorList = new QListWidget(GroupPlanes);
372   ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
373
374   SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
375
376   GroupPlanesLayout->addWidget(ComboBoxPlanes,    0, 0);
377   GroupPlanesLayout->addWidget(new QWidget(),     0, 1);
378   GroupPlanesLayout->addWidget(buttonNew,         0, 2);
379   GroupPlanesLayout->addWidget(buttonDelete,      0, 3);
380   GroupPlanesLayout->addWidget(aLabel,            1, 0, 1, 4);
381   GroupPlanesLayout->addWidget(ActorList,         2, 0, 1, 4);
382   GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 4);
383   GroupPlanesLayout->setColumnStretch( 1, 1 );
384
385   // Controls for defining plane parameters
386   QGroupBox* GroupParameters = new QGroupBox(tr("SMESH_PARAMETERS"), this);
387   QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
388   GroupParametersLayout->setSpacing(SPACING);
389   GroupParametersLayout->setMargin(MARGIN);
390
391   TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
392
393   ComboBoxOrientation = new QComboBox(GroupParameters);
394
395   TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
396
397   SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
398
399   TextLabelRot1 = new QLabel(tr("ROTATION_AROUND_X_Y2Z"), GroupParameters);
400
401   SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
402
403   TextLabelRot2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
404
405   SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
406
407   PreviewCheckBox = new QCheckBox(tr("SHOW_PREVIEW"), GroupParameters);
408   PreviewCheckBox->setChecked(true);
409
410   AutoApplyCheckBox = new QCheckBox(tr("AUTO_APPLY"), GroupParameters);
411   AutoApplyCheckBox->setChecked(false);
412
413   GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
414   GroupParametersLayout->addWidget(ComboBoxOrientation,  0, 1);
415   GroupParametersLayout->addWidget(TextLabelDistance,    1, 0);
416   GroupParametersLayout->addWidget(SpinBoxDistance,      1, 1);
417   GroupParametersLayout->addWidget(TextLabelRot1,        2, 0);
418   GroupParametersLayout->addWidget(SpinBoxRot1,          2, 1);
419   GroupParametersLayout->addWidget(TextLabelRot2,        3, 0);
420   GroupParametersLayout->addWidget(SpinBoxRot2,          3, 1);
421   GroupParametersLayout->addWidget(PreviewCheckBox,      4, 0);
422   GroupParametersLayout->addWidget(AutoApplyCheckBox,    4, 1);
423
424   // Controls for "Ok", "Apply" and "Close" button
425   QGroupBox* GroupButtons = new QGroupBox(this);
426   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
427   GroupButtonsLayout->setSpacing(SPACING);
428   GroupButtonsLayout->setMargin(MARGIN);
429   
430   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
431   buttonOk->setAutoDefault(true);
432   buttonOk->setDefault(true);
433   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
434   buttonApply->setAutoDefault(true);
435   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
436   buttonCancel->setAutoDefault(true);
437   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
438   buttonHelp->setAutoDefault(true);
439   GroupButtonsLayout->addWidget(buttonOk);
440   GroupButtonsLayout->addSpacing(10);
441   GroupButtonsLayout->addWidget(buttonApply);
442   GroupButtonsLayout->addSpacing(10);
443   GroupButtonsLayout->addStretch();
444   GroupButtonsLayout->addWidget(buttonCancel);
445   GroupButtonsLayout->addWidget(buttonHelp);
446
447   SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
448   SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
449   SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
450
451   // Initial state
452   SpinBoxDistance->RangeStepAndValidator(0.0, 1.0, 0.01, "length_precision" );
453   SpinBoxRot1->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
454   SpinBoxRot2->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
455
456   ComboBoxOrientation->addItem(tr("ALONG_XY"));
457   ComboBoxOrientation->addItem(tr("ALONG_YZ"));
458   ComboBoxOrientation->addItem(tr("ALONG_ZX"));
459
460   SpinBoxDistance->SetValue(0.5);
461
462   myIsSelectPlane = false;
463
464   initializePlaneData();
465   synchronize();
466
467   myHelpFileName = "clipping_page.html";
468
469   // signals and slots connections :
470   connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
471   connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
472   connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
473   connect(ActorList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onActorItemChanged(QListWidgetItem*)));
474   connect(SelectAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onSelectAll(int)));
475   connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
476   connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
477   connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
478   connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
479   connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
480   connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
481   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
482   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
483   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
484   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
485   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
486   /* to close dialog if study frame change */
487   connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(ClickOnCancel()));
488
489   this->show();
490 }
491
492 //=================================================================================
493 // function : ~SMESHGUI_ClippingDlg()
494 // purpose  :
495 //=================================================================================
496 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
497 {
498   // no need to delete child widgets, Qt does it all for us
499   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
500   if (myViewWindow)
501     SMESH::RenderViewWindow(myViewWindow);
502 }
503
504 double SMESHGUI_ClippingDlg::getDistance() const
505 {
506   return SpinBoxDistance->GetValue();
507 }
508
509 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
510 {
511   SpinBoxDistance->SetValue( theDistance );
512 }
513
514 double SMESHGUI_ClippingDlg::getRotation1() const
515 {
516   return SpinBoxRot1->GetValue();
517 }
518
519 double SMESHGUI_ClippingDlg::getRotation2() const
520 {
521   return SpinBoxRot2->GetValue();
522 }
523
524 //=======================================================================
525 // function : ClickOnApply()
526 // purpose  :
527 //=======================================================================
528 void SMESHGUI_ClippingDlg::ClickOnApply()
529 {
530   if (myViewWindow) {
531     SUIT_OverrideCursor wc;
532     
533     QWidget *aCurrWid = this->focusWidget();
534     aCurrWid->clearFocus();
535     aCurrWid->setFocus();
536
537     SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
538     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
539
540     // clean memory allocated for planes
541     SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
542     for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
543       if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
544         aPlane->Delete();
545
546     aClippingPlaneInfoList.clear();
547
548     VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
549     vtkActorCollection* anAllActors = aCopy.GetActors();
550     anAllActors->InitTraversal();
551     while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
552       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
553         anActor->RemoveAllClippingPlanes();
554
555     SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
556     for( ; anIter2 != myPlanes.end(); anIter2++ ) {
557       SMESH::TPlaneData aPlaneData = *anIter2;
558       SMESH::TPlane aPlane = aPlaneData.Plane;
559       SMESH::TActorList anActorList = aPlaneData.ActorList;
560
561       // the check is disabled to support planes with empty actor list
562       //if( anActorList.empty() )
563       //  continue;
564
565       SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
566       anOrientedPlane->ShallowCopy(aPlane.GetPointer());
567
568       SMESH::TActorList::iterator anIter3 = anActorList.begin();
569       for( ; anIter3 != anActorList.end(); anIter3++ )
570         if( vtkActor* aVTKActor = *anIter3 )
571           if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
572             anActor->AddClippingPlane(anOrientedPlane);
573
574       SMESH::ClippingPlaneInfo aClippingPlaneInfo;
575       aClippingPlaneInfo.Plane = anOrientedPlane;
576       aClippingPlaneInfo.ActorList = anActorList;
577
578       aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
579     }
580
581     SMESH::RenderViewWindow( myViewWindow );
582   }
583 }
584
585 //=======================================================================
586 // function : ClickOnOk()
587 // purpose  :
588 //=======================================================================
589 void SMESHGUI_ClippingDlg::ClickOnOk()
590 {
591   ClickOnApply();
592   ClickOnCancel();
593 }
594
595 //=======================================================================
596 // function : ClickOnCancel()
597 // purpose  :
598 //=======================================================================
599 void SMESHGUI_ClippingDlg::ClickOnCancel()
600 {
601   close();
602 }
603
604 //=================================================================================
605 // function : ClickOnHelp()
606 // purpose  :
607 //=================================================================================
608 void SMESHGUI_ClippingDlg::ClickOnHelp()
609 {
610   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
611   if (app) 
612     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
613   else {
614                 QString platform;
615 #ifdef WIN32
616                 platform = "winapplication";
617 #else
618                 platform = "application";
619 #endif
620     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
621                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
622                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
623                                                                  platform)).
624                              arg(myHelpFileName));
625   }
626 }
627
628 //=======================================================================
629 // function : onSelectPlane()
630 // purpose  :
631 //=======================================================================
632 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
633 {
634   if (myPlanes.empty())
635     return;
636
637   SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
638   SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
639
640   // Orientation
641   SMESH::Orientation anOrientation = aPlane->GetOrientation();
642
643   // Rotations
644   double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
645
646   // Set plane parameters in the dialog
647   myIsSelectPlane = true;
648   setDistance(aPlane->GetDistance());
649   setRotation(aRot[0], aRot[1]);
650   switch (anOrientation) {
651   case SMESH::XY:
652     ComboBoxOrientation->setCurrentIndex(0);
653     onSelectOrientation(0);
654     break;
655   case SMESH::YZ:
656     ComboBoxOrientation->setCurrentIndex(1);
657     onSelectOrientation(1);
658     break;
659   case SMESH::ZX:
660     ComboBoxOrientation->setCurrentIndex(2);
661     onSelectOrientation(2);
662     break;
663   }
664   myIsSelectPlane = false;
665
666   // Actors
667   bool anIsBlocked = ActorList->blockSignals( true );
668   updateActorList();
669   ActorList->blockSignals( anIsBlocked );
670 }
671
672 //=======================================================================
673 // function : ClickOnNew()
674 // purpose  :
675 //=======================================================================
676 void SMESHGUI_ClippingDlg::ClickOnNew()
677 {
678   if(myViewWindow){
679     SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
680     SMESH::TPlane aTPlane(aPlane);
681
682     SMESH::TActorList anActorList;
683     VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
684     vtkActorCollection* anAllActors = aCopy.GetActors();
685     anAllActors->InitTraversal();
686     while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
687       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
688         anActorList.push_back( anActor );
689
690     SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
691
692     myPlanes.push_back(aPlaneData);
693
694     if (PreviewCheckBox->isChecked())
695       aTPlane->myActor->VisibilityOn();
696
697     bool anIsBlocked = ActorList->blockSignals( true );
698
699     synchronize();
700     SetCurrentPlaneParam();
701
702     ActorList->blockSignals( anIsBlocked );
703   }
704 }
705
706 //=======================================================================
707 // function : ClickOnDelete()
708 // purpose  :
709 //=======================================================================
710 void SMESHGUI_ClippingDlg::ClickOnDelete()
711 {
712   if (myPlanes.empty())
713     return;
714
715   int aPlaneIndex = ComboBoxPlanes->currentIndex();
716
717   SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
718   SMESH::TPlaneData aPlaneData = *anIter;
719   aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
720   myPlanes.erase(anIter);
721
722   if(AutoApplyCheckBox->isChecked())
723     ClickOnApply();
724
725   synchronize();
726   SMESH::RenderViewWindow( myViewWindow );
727 }
728
729 //=======================================================================
730 // function : updateActorItem()
731 // purpose  :
732 //=======================================================================
733 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
734                                             bool theUpdateSelectAll,
735                                             bool theUpdateClippingPlaneMap )
736 {
737   // update Select All check box
738   if( theUpdateSelectAll ) {
739     int aNbItems = ActorList->count(), aNbChecked = 0;
740     for( int i = 0; i < aNbItems; i++ )
741       if( QListWidgetItem* anItem = ActorList->item( i ) )
742         if( anItem->checkState() == Qt::Checked )
743           aNbChecked++;
744
745     Qt::CheckState aCheckState = Qt::Unchecked;
746     if( aNbChecked == aNbItems )
747       aCheckState = Qt::Checked;
748     else if( aNbChecked > 0 )
749       aCheckState = Qt::PartiallyChecked;
750
751     bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
752     SelectAllCheckBox->setCheckState( aCheckState );
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   vtkFloatingPointType aNormal[3];
907   SMESH::Orientation anOrientation;
908   vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
909   {
910     static double aCoeff = vtkMath::Pi()/180.0;
911
912     vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
913     aPlane->myAngle[0] = aRot[0];
914     aPlane->myAngle[1] = aRot[1];
915
916     vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
917     vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
918     aV[0] = aRot[0] > 0? aV[0]: -aV[0];
919     aV[1] = aRot[1] > 0? aV[1]: -aV[1];
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   vtkFloatingPointType aBounds[6];
965   vtkFloatingPointType 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     vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
979                                      ( aBounds[2] + aBounds[3] ) / 2.,
980                                      ( aBounds[4] + aBounds[5] ) / 2. };
981
982     vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
983                                      pow( aBounds[3] - aBounds[2], 2 ) +
984                                      pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
985
986     vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
987                                          {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
988     vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
989
990     vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
991                                       aPnt[1] - aDelta[0][1] - aDelta[1][1],
992                                       aPnt[2] - aDelta[0][2] - aDelta[1][2]};
993     vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
994                                       aPnt01[1] + aNormal[1],
995                                       aPnt01[2] + aNormal[2]};
996     vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
997
998     vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
999                                       aPnt[1] - aDelta[0][1] + aDelta[1][1],
1000                                       aPnt[2] - aDelta[0][2] + aDelta[1][2]};
1001     vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
1002                                       aPnt11[1] + aNormal[1],
1003                                       aPnt11[2] + aNormal[2]};
1004     vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1005
1006     vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
1007                                       aPnt[1] + aDelta[0][1] - aDelta[1][1],
1008                                       aPnt[2] + aDelta[0][2] - aDelta[1][2]};
1009     vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
1010                                       aPnt21[1] + aNormal[1],
1011                                       aPnt21[2] + aNormal[2]};
1012     vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
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   }
1020
1021   if(AutoApplyCheckBox->isChecked())
1022     ClickOnApply();
1023
1024   SMESH::RenderViewWindow( myViewWindow );
1025 }
1026
1027 //=======================================================================
1028 // function : OnPreviewToggle()
1029 // purpose  :
1030 //=======================================================================
1031 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1032 {
1033   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1034   SMESH::RenderViewWindow( myViewWindow );
1035 }
1036
1037 //=================================================================================
1038 // function : keyPressEvent()
1039 // purpose  :
1040 //=================================================================================
1041 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1042 {
1043   QDialog::keyPressEvent( e );
1044   if ( e->isAccepted() )
1045     return;
1046
1047   if ( e->key() == Qt::Key_F1 ) {
1048     e->accept();
1049     ClickOnHelp();
1050   }
1051 }
1052
1053 //=================================================================================
1054 // function : initializePlaneData()
1055 // purpose  :
1056 //=================================================================================
1057 void SMESHGUI_ClippingDlg::initializePlaneData()
1058 {
1059   const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1060   SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
1061   if( anIter1 != aClippingPlaneInfoMap.end() ) {
1062     const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
1063     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
1064     for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
1065       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
1066       SMESH::TPlane aTPlane( aClippingPlaneInfo.Plane );
1067       SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
1068       myPlanes.push_back( aPlaneData );
1069     }
1070   }
1071   std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1072 }
1073
1074 //=================================================================================
1075 // function : updateActorList()
1076 // purpose  :
1077 //=================================================================================
1078 void SMESHGUI_ClippingDlg::updateActorList()
1079 {
1080   ActorList->clear();
1081
1082   SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1083   if( !anAppStudy )
1084     return;
1085
1086   _PTR(Study) aStudy = anAppStudy->studyDS();
1087   if( !aStudy )
1088     return;
1089
1090   if( !myViewWindow )
1091     return;
1092
1093   int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1094   const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1095   const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1096
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 ) {
1111                   anIsChecked = true;
1112                   break;
1113                 }
1114               }
1115             }
1116           }
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 );
1121         }
1122       }
1123     }
1124   }
1125 }
1126
1127 //=================================================================================
1128 // function : getCurrentActors()
1129 // purpose  :
1130 //=================================================================================
1131 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1132 {
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 );
1139   return anActorList;
1140 }
1141
1142 //=================================================================================
1143 // function : dumpPlaneData()
1144 // purpose  :
1145 //=================================================================================
1146 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1147 {
1148   printf( "----------- Plane Data -----------\n" );
1149   int anId = 1;
1150   SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1151   for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1152     SMESH::TPlaneData aPlaneData = *anIter1;
1153     SMESH::TPlane aPlane = aPlaneData.Plane;
1154     vtkFloatingPointType* aNormal = aPlane->GetNormal();
1155     vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
1156     printf( "Plane N%d:\n", anId );
1157     printf( "  Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1158     printf( "  Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1159
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() );
1166       }
1167       else
1168         printf( "  - Actor: NULL\n");
1169     }
1170   }
1171   printf( "----------------------------------\n" );
1172 }