Salome HOME
Merge from V5_1_main branch 24/11/2010
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ClippingDlg.cxx
1 //  Copyright (C) 2007-2010  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);
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     thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible);
198   }
199   int myIsVisible;
200 };
201
202 //=================================================================================
203 // used in SMESHGUI::restoreVisualParameters() to avoid
204 // declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
205 //=================================================================================
206 SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList          theActorList,
207                                                       SVTK_ViewWindow*           theViewWindow,
208                                                       SMESH::Orientation         theOrientation,
209                                                       double                     theDistance,
210                                                       const vtkFloatingPointType theAngle[2])
211 {
212   SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(theViewWindow);
213
214   aPlane->myAngle[0] = theAngle[0];
215   aPlane->myAngle[1] = theAngle[1];
216
217   aPlane->SetOrientation(theOrientation);
218   aPlane->SetDistance(theDistance);
219
220   vtkFloatingPointType aNormal[3];
221   vtkFloatingPointType aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
222   {
223     static double aCoeff = vtkMath::Pi()/180.0;
224
225     vtkFloatingPointType anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
226     vtkFloatingPointType aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
227     aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
228     aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
229
230     switch (theOrientation) {
231     case SMESH::XY:
232       aDir[0][1] = anU[0];
233       aDir[0][2] = aV[0];
234
235       aDir[1][0] = anU[1];
236       aDir[1][2] = aV[1];
237
238       break;
239     case SMESH::YZ:
240       aDir[0][2] = anU[0];
241       aDir[0][0] = aV[0];
242
243       aDir[1][1] = anU[1];
244       aDir[1][0] = aV[1];
245
246       break;
247     case SMESH::ZX:
248       aDir[0][0] = anU[0];
249       aDir[0][1] = aV[0];
250
251       aDir[1][2] = anU[1];
252       aDir[1][1] = aV[1];
253
254       break;
255     }
256
257     vtkMath::Cross(aDir[1],aDir[0],aNormal);
258     vtkMath::Normalize(aNormal);
259     vtkMath::Cross(aNormal,aDir[1],aDir[0]);
260   }
261
262   vtkFloatingPointType aBounds[6];
263   vtkFloatingPointType anOrigin[3];
264   bool anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
265                                                        aNormal,
266                                                        theDistance,
267                                                        aBounds,
268                                                        anOrigin );
269   if( !anIsOk )
270     return NULL;
271
272   aPlane->SetNormal( aNormal );
273   aPlane->SetOrigin( anOrigin );
274
275   vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
276                                    ( aBounds[2] + aBounds[3] ) / 2.,
277                                    ( aBounds[4] + aBounds[5] ) / 2. };
278
279   vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
280                                    pow( aBounds[3] - aBounds[2], 2 ) +
281                                    pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
282
283   vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
284                                        {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
285   vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
286
287   vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
288                                     aPnt[1] - aDelta[0][1] - aDelta[1][1],
289                                     aPnt[2] - aDelta[0][2] - aDelta[1][2]};
290   vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
291                                     aPnt01[1] + aNormal[1],
292                                     aPnt01[2] + aNormal[2]};
293   vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
294
295   vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
296                                     aPnt[1] - aDelta[0][1] + aDelta[1][1],
297                                     aPnt[2] - aDelta[0][2] + aDelta[1][2]};
298   vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
299                                     aPnt11[1] + aNormal[1],
300                                     aPnt11[2] + aNormal[2]};
301   vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
302
303   vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
304                                     aPnt[1] + aDelta[0][1] - aDelta[1][1],
305                                     aPnt[2] + aDelta[0][2] - aDelta[1][2]};
306   vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
307                                     aPnt21[1] + aNormal[1],
308                                     aPnt21[2] + aNormal[2]};
309   vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
310
311   vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
312   aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
313   aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
314   aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
315   aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
316
317   SMESH::TActorList::iterator anIter = theActorList.begin();
318   for ( ; anIter != theActorList.end(); anIter++ )
319     if( vtkActor* aVTKActor = *anIter )
320       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
321         anActor->AddClippingPlane( aPlane );
322
323   return aPlane;
324 }
325
326 //=================================================================================
327 // class    : SMESHGUI_ClippingDlg()
328 // purpose  :
329 //
330 //=================================================================================
331 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
332   QDialog( SMESH::GetDesktop(theModule) ),
333   mySMESHGUI(theModule),
334   myViewWindow(theViewWindow)
335 {
336   setModal( false );
337   setAttribute( Qt::WA_DeleteOnClose, true );
338   setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
339   setSizeGripEnabled(true);
340
341   QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
342   SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
343   SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
344
345   // Controls for selecting, creating, deleting planes
346   QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
347   QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
348   GroupPlanesLayout->setSpacing(SPACING);
349   GroupPlanesLayout->setMargin(MARGIN);
350
351   ComboBoxPlanes = new QComboBox(GroupPlanes);
352
353   buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
354
355   buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
356
357   QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
358
359   ActorList = new QListWidget(GroupPlanes);
360   ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
361
362   SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
363
364   GroupPlanesLayout->addWidget(ComboBoxPlanes,    0, 0);
365   GroupPlanesLayout->addWidget(new QWidget(),     0, 1);
366   GroupPlanesLayout->addWidget(buttonNew,         0, 2);
367   GroupPlanesLayout->addWidget(buttonDelete,      0, 3);
368   GroupPlanesLayout->addWidget(aLabel,            1, 0, 1, 4);
369   GroupPlanesLayout->addWidget(ActorList,         2, 0, 1, 4);
370   GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 4);
371   GroupPlanesLayout->setColumnStretch( 1, 1 );
372
373   // Controls for defining plane parameters
374   QGroupBox* GroupParameters = new QGroupBox(tr("SMESH_PARAMETERS"), this);
375   QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
376   GroupParametersLayout->setSpacing(SPACING);
377   GroupParametersLayout->setMargin(MARGIN);
378
379   TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
380
381   ComboBoxOrientation = new QComboBox(GroupParameters);
382
383   TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
384
385   SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
386
387   TextLabelRot1 = new QLabel(tr("ROTATION_AROUND_X_Y2Z"), GroupParameters);
388
389   SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
390
391   TextLabelRot2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
392
393   SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
394
395   PreviewCheckBox = new QCheckBox(tr("SHOW_PREVIEW"), GroupParameters);
396   PreviewCheckBox->setChecked(true);
397
398   AutoApplyCheckBox = new QCheckBox(tr("AUTO_APPLY"), GroupParameters);
399   AutoApplyCheckBox->setChecked(false);
400
401   GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
402   GroupParametersLayout->addWidget(ComboBoxOrientation,  0, 1);
403   GroupParametersLayout->addWidget(TextLabelDistance,    1, 0);
404   GroupParametersLayout->addWidget(SpinBoxDistance,      1, 1);
405   GroupParametersLayout->addWidget(TextLabelRot1,        2, 0);
406   GroupParametersLayout->addWidget(SpinBoxRot1,          2, 1);
407   GroupParametersLayout->addWidget(TextLabelRot2,        3, 0);
408   GroupParametersLayout->addWidget(SpinBoxRot2,          3, 1);
409   GroupParametersLayout->addWidget(PreviewCheckBox,      4, 0);
410   GroupParametersLayout->addWidget(AutoApplyCheckBox,    4, 1);
411
412   // Controls for "Ok", "Apply" and "Close" button
413   QGroupBox* GroupButtons = new QGroupBox(this);
414   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
415   GroupButtonsLayout->setSpacing(SPACING);
416   GroupButtonsLayout->setMargin(MARGIN);
417   
418   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
419   buttonOk->setAutoDefault(true);
420   buttonOk->setDefault(true);
421   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
422   buttonApply->setAutoDefault(true);
423   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
424   buttonCancel->setAutoDefault(true);
425   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
426   buttonHelp->setAutoDefault(true);
427   GroupButtonsLayout->addWidget(buttonOk);
428   GroupButtonsLayout->addSpacing(10);
429   GroupButtonsLayout->addWidget(buttonApply);
430   GroupButtonsLayout->addSpacing(10);
431   GroupButtonsLayout->addStretch();
432   GroupButtonsLayout->addWidget(buttonCancel);
433   GroupButtonsLayout->addWidget(buttonHelp);
434
435   SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
436   SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
437   SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
438
439   // Initial state
440   SpinBoxDistance->RangeStepAndValidator(0.0, 1.0, 0.01, "length_precision" );
441   SpinBoxRot1->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
442   SpinBoxRot2->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
443
444   ComboBoxOrientation->addItem(tr("ALONG_XY"));
445   ComboBoxOrientation->addItem(tr("ALONG_YZ"));
446   ComboBoxOrientation->addItem(tr("ALONG_ZX"));
447
448   SpinBoxDistance->SetValue(0.5);
449
450   myIsSelectPlane = false;
451
452   initializePlaneData();
453   synchronize();
454
455   myHelpFileName = "clipping_page.html";
456
457   // signals and slots connections :
458   connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
459   connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
460   connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
461   connect(ActorList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onActorItemChanged(QListWidgetItem*)));
462   connect(SelectAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onSelectAll(int)));
463   connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
464   connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
465   connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
466   connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
467   connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
468   connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
469   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
470   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
471   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
472   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
473   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
474   /* to close dialog if study frame change */
475   connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(ClickOnCancel()));
476
477   this->show();
478 }
479
480 //=================================================================================
481 // function : ~SMESHGUI_ClippingDlg()
482 // purpose  :
483 //=================================================================================
484 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
485 {
486   // no need to delete child widgets, Qt does it all for us
487   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
488   if (myViewWindow)
489     SMESH::RenderViewWindow(myViewWindow);
490 }
491
492 double SMESHGUI_ClippingDlg::getDistance() const
493 {
494   return SpinBoxDistance->GetValue();
495 }
496
497 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
498 {
499   SpinBoxDistance->SetValue( theDistance );
500 }
501
502 double SMESHGUI_ClippingDlg::getRotation1() const
503 {
504   return SpinBoxRot1->GetValue();
505 }
506
507 double SMESHGUI_ClippingDlg::getRotation2() const
508 {
509   return SpinBoxRot2->GetValue();
510 }
511
512 //=======================================================================
513 // function : ClickOnApply()
514 // purpose  :
515 //=======================================================================
516 void SMESHGUI_ClippingDlg::ClickOnApply()
517 {
518   if (myViewWindow) {
519     SUIT_OverrideCursor wc;
520     
521     QWidget *aCurrWid = this->focusWidget();
522     aCurrWid->clearFocus();
523     aCurrWid->setFocus();
524
525     SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
526     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
527
528     // clean memory allocated for planes
529     SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
530     for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
531       if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
532         aPlane->Delete();
533
534     aClippingPlaneInfoList.clear();
535
536     VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
537     vtkActorCollection* anAllActors = aCopy.GetActors();
538     anAllActors->InitTraversal();
539     while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
540       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
541         anActor->RemoveAllClippingPlanes();
542
543     SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
544     for( ; anIter2 != myPlanes.end(); anIter2++ ) {
545       SMESH::TPlaneData aPlaneData = *anIter2;
546       SMESH::TPlane aPlane = aPlaneData.Plane;
547       SMESH::TActorList anActorList = aPlaneData.ActorList;
548       if( anActorList.empty() )
549         continue;
550
551       SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
552       anOrientedPlane->ShallowCopy(aPlane.GetPointer());
553
554       SMESH::TActorList::iterator anIter3 = anActorList.begin();
555       for( ; anIter3 != anActorList.end(); anIter3++ )
556         if( vtkActor* aVTKActor = *anIter3 )
557           if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
558             anActor->AddClippingPlane(anOrientedPlane);
559
560       SMESH::ClippingPlaneInfo aClippingPlaneInfo;
561       aClippingPlaneInfo.Plane = anOrientedPlane;
562       aClippingPlaneInfo.ActorList = anActorList;
563
564       aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
565     }
566
567     SMESH::RenderViewWindow( myViewWindow );
568   }
569 }
570
571 //=======================================================================
572 // function : ClickOnOk()
573 // purpose  :
574 //=======================================================================
575 void SMESHGUI_ClippingDlg::ClickOnOk()
576 {
577   ClickOnApply();
578   ClickOnCancel();
579 }
580
581 //=======================================================================
582 // function : ClickOnCancel()
583 // purpose  :
584 //=======================================================================
585 void SMESHGUI_ClippingDlg::ClickOnCancel()
586 {
587   close();
588 }
589
590 //=================================================================================
591 // function : ClickOnHelp()
592 // purpose  :
593 //=================================================================================
594 void SMESHGUI_ClippingDlg::ClickOnHelp()
595 {
596   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
597   if (app) 
598     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
599   else {
600                 QString platform;
601 #ifdef WIN32
602                 platform = "winapplication";
603 #else
604                 platform = "application";
605 #endif
606     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
607                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
608                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
609                                                                  platform)).
610                              arg(myHelpFileName));
611   }
612 }
613
614 //=======================================================================
615 // function : onSelectPlane()
616 // purpose  :
617 //=======================================================================
618 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
619 {
620   if (myPlanes.empty())
621     return;
622
623   SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
624   SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
625
626   // Orientation
627   SMESH::Orientation anOrientation = aPlane->GetOrientation();
628
629   // Rotations
630   double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
631
632   // Set plane parameters in the dialog
633   myIsSelectPlane = true;
634   setDistance(aPlane->GetDistance());
635   setRotation(aRot[0], aRot[1]);
636   switch (anOrientation) {
637   case SMESH::XY:
638     ComboBoxOrientation->setCurrentIndex(0);
639     onSelectOrientation(0);
640     break;
641   case SMESH::YZ:
642     ComboBoxOrientation->setCurrentIndex(1);
643     onSelectOrientation(1);
644     break;
645   case SMESH::ZX:
646     ComboBoxOrientation->setCurrentIndex(2);
647     onSelectOrientation(2);
648     break;
649   }
650   myIsSelectPlane = false;
651
652   // Actors
653   bool anIsBlocked = ActorList->blockSignals( true );
654   updateActorList();
655   ActorList->blockSignals( anIsBlocked );
656 }
657
658 //=======================================================================
659 // function : ClickOnNew()
660 // purpose  :
661 //=======================================================================
662 void SMESHGUI_ClippingDlg::ClickOnNew()
663 {
664   if(myViewWindow){
665     SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
666     SMESH::TPlane aTPlane(aPlane);
667
668     SMESH::TActorList anActorList;
669     VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
670     vtkActorCollection* anAllActors = aCopy.GetActors();
671     anAllActors->InitTraversal();
672     while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
673       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
674         anActorList.push_back( anActor );
675
676     SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
677
678     myPlanes.push_back(aPlaneData);
679
680     if (PreviewCheckBox->isChecked())
681       aTPlane->myActor->VisibilityOn();
682
683     bool anIsBlocked = ActorList->blockSignals( true );
684
685     synchronize();
686     SetCurrentPlaneParam();
687
688     ActorList->blockSignals( anIsBlocked );
689   }
690 }
691
692 //=======================================================================
693 // function : ClickOnDelete()
694 // purpose  :
695 //=======================================================================
696 void SMESHGUI_ClippingDlg::ClickOnDelete()
697 {
698   if (myPlanes.empty())
699     return;
700
701   int aPlaneIndex = ComboBoxPlanes->currentIndex();
702
703   SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
704   SMESH::TPlaneData aPlaneData = *anIter;
705   aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
706   myPlanes.erase(anIter);
707
708   if(AutoApplyCheckBox->isChecked())
709     ClickOnApply();
710
711   synchronize();
712   SMESH::RenderViewWindow( myViewWindow );
713 }
714
715 //=======================================================================
716 // function : updateActorItem()
717 // purpose  :
718 //=======================================================================
719 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
720                                             bool theUpdateSelectAll,
721                                             bool theUpdateClippingPlaneMap )
722 {
723   // update Select All check box
724   if( theUpdateSelectAll ) {
725     int aNbItems = ActorList->count(), aNbChecked = 0;
726     for( int i = 0; i < aNbItems; i++ )
727       if( QListWidgetItem* anItem = ActorList->item( i ) )
728         if( anItem->checkState() == Qt::Checked )
729           aNbChecked++;
730
731     Qt::CheckState aCheckState = Qt::Unchecked;
732     if( aNbChecked == aNbItems )
733       aCheckState = Qt::Checked;
734     else if( aNbChecked > 0 )
735       aCheckState = Qt::PartiallyChecked;
736
737     bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
738     SelectAllCheckBox->setCheckState( aCheckState );
739     SelectAllCheckBox->blockSignals( anIsBlocked );
740   }
741
742   // update clipping plane map
743   if( theUpdateClippingPlaneMap ) {
744     int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
745     if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
746       if( SMESH_Actor* anActor = anItem->getActor() ) {
747         SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
748         SMESH::TActorList& anActorList = aPlaneData.ActorList;
749         bool anIsPushed = false;
750         SMESH::TActorList::iterator anIter = anActorList.begin();
751         for ( ; anIter != anActorList.end(); anIter++ ) {
752           if( anActor == *anIter ) {
753             anIsPushed = true;
754             break;
755           }
756         }
757         if( theItem->checkState() == Qt::Checked && !anIsPushed )
758           anActorList.push_back( anActor );
759         else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
760           anActorList.remove( anActor );
761       }
762     }
763   }
764 }
765
766 //=======================================================================
767 // function : onActorItemChanged()
768 // purpose  :
769 //=======================================================================
770 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
771 {
772   updateActorItem( theItem, true, true );
773   SetCurrentPlaneParam();
774 }
775
776 //=======================================================================
777 // function : onSelectAll()
778 // purpose  :
779 //=======================================================================
780 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
781 {
782   if( theState == Qt::PartiallyChecked ) {
783     SelectAllCheckBox->setCheckState( Qt::Checked );
784     return;
785   }
786
787   bool anIsBlocked = ActorList->blockSignals( true );
788   for( int i = 0, n = ActorList->count(); i < n; i++ ) {
789     if( QListWidgetItem* anItem = ActorList->item( i ) ) {
790       anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
791       updateActorItem( anItem, false, true );
792     }
793   }
794   SelectAllCheckBox->setTristate( false );
795   ActorList->blockSignals( anIsBlocked );
796   SetCurrentPlaneParam();
797 }
798
799 //=======================================================================
800 // function : onSelectOrientation()
801 // purpose  :
802 //=======================================================================
803 void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
804 {
805   if (myPlanes.empty())
806     return;
807
808   if      (theItem == 0) {
809     TextLabelRot1->setText(tr("ROTATION_AROUND_X_Y2Z"));
810     TextLabelRot2->setText(tr("ROTATION_AROUND_Y_X2Z"));
811   }
812   else if (theItem == 1) {
813     TextLabelRot1->setText(tr("ROTATION_AROUND_Y_Z2X"));
814     TextLabelRot2->setText(tr("ROTATION_AROUND_Z_Y2X"));
815   }
816   else if (theItem == 2) {
817     TextLabelRot1->setText(tr("ROTATION_AROUND_Z_X2Y"));
818     TextLabelRot2->setText(tr("ROTATION_AROUND_X_Z2Y"));
819   }
820
821   if((QComboBox*)sender() == ComboBoxOrientation)
822     SetCurrentPlaneParam();
823 }
824
825 //=======================================================================
826 // function : synchronize()
827 // purpose  :
828 //=======================================================================
829 void SMESHGUI_ClippingDlg::synchronize()
830 {
831   int aNbPlanes = myPlanes.size();
832   ComboBoxPlanes->clear();
833
834   QString aName;
835   for(int i = 1; i<=aNbPlanes; i++) {
836     aName = QString(tr("PLANE_NUM")).arg(i);
837     ComboBoxPlanes->addItem(aName);
838   }
839
840   int aPos = ComboBoxPlanes->count() - 1;
841   ComboBoxPlanes->setCurrentIndex(aPos);
842
843   bool anIsControlsEnable = (aPos >= 0);
844   if (anIsControlsEnable) {
845     onSelectPlane(aPos);
846     updateActorList();
847   } else {
848     ComboBoxPlanes->addItem(tr("NO_PLANES"));
849     ActorList->clear();
850     SpinBoxRot1->SetValue(0.0);
851     SpinBoxRot2->SetValue(0.0);
852     SpinBoxDistance->SetValue(0.5);
853   }
854
855   ActorList->setEnabled(anIsControlsEnable);
856   SelectAllCheckBox->setEnabled(anIsControlsEnable);
857   buttonDelete->setEnabled(anIsControlsEnable);
858   // the following 3 controls should be enabled
859   //buttonApply->setEnabled(anIsControlsEnable);
860   //PreviewCheckBox->setEnabled(anIsControlsEnable);
861   //AutoApplyCheckBox->setEnabled(anIsControlsEnable);
862   ComboBoxOrientation->setEnabled(anIsControlsEnable);
863   SpinBoxDistance->setEnabled(anIsControlsEnable);
864   SpinBoxRot1->setEnabled(anIsControlsEnable);
865   SpinBoxRot2->setEnabled(anIsControlsEnable);
866 }
867
868 //=======================================================================
869 // function : setRotation()
870 // purpose  :
871 //=======================================================================
872 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
873 {
874   SpinBoxRot1->SetValue(theRot1);
875   SpinBoxRot2->SetValue(theRot2);
876 }
877
878 //=======================================================================
879 // function : SetCurrentPlaneParam()
880 // purpose  :
881 //=======================================================================
882 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
883 {
884   if (myPlanes.empty() || myIsSelectPlane)
885     return;
886
887   int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
888
889   SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
890   SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
891
892   vtkFloatingPointType aNormal[3];
893   SMESH::Orientation anOrientation;
894   vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
895   {
896     static double aCoeff = vtkMath::Pi()/180.0;
897
898     vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
899     aPlane->myAngle[0] = aRot[0];
900     aPlane->myAngle[1] = aRot[1];
901
902     vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
903     vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
904     aV[0] = aRot[0] > 0? aV[0]: -aV[0];
905     aV[1] = aRot[1] > 0? aV[1]: -aV[1];
906
907     switch (ComboBoxOrientation->currentIndex()) {
908     case 0:
909       anOrientation = SMESH::XY;
910
911       aDir[0][1] = anU[0];
912       aDir[0][2] = aV[0];
913
914       aDir[1][0] = anU[1];
915       aDir[1][2] = aV[1];
916
917       break;
918     case 1:
919       anOrientation = SMESH::YZ;
920
921       aDir[0][2] = anU[0];
922       aDir[0][0] = aV[0];
923
924       aDir[1][1] = anU[1];
925       aDir[1][0] = aV[1];
926
927       break;
928     case 2:
929       anOrientation = SMESH::ZX;
930
931       aDir[0][0] = anU[0];
932       aDir[0][1] = aV[0];
933
934       aDir[1][2] = anU[1];
935       aDir[1][1] = aV[1];
936
937       break;
938     }
939
940     vtkMath::Cross(aDir[1],aDir[0],aNormal);
941     vtkMath::Normalize(aNormal);
942     vtkMath::Cross(aNormal,aDir[1],aDir[0]);
943   }
944
945   aPlane->SetOrientation(anOrientation);
946   aPlane->SetDistance(getDistance());
947
948   SMESH::TActorList anActorList = aPlaneData.ActorList;
949
950   vtkFloatingPointType aBounds[6];
951   vtkFloatingPointType anOrigin[3];
952   bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
953                                                        aNormal,
954                                                        getDistance(),
955                                                        aBounds,
956                                                        anOrigin );
957
958   aPlane->myActor->SetVisibility( anIsOk && PreviewCheckBox->isChecked() );
959
960   if( anIsOk ) {
961     aPlane->SetNormal( aNormal );
962     aPlane->SetOrigin( anOrigin );
963
964     vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
965                                      ( aBounds[2] + aBounds[3] ) / 2.,
966                                      ( aBounds[4] + aBounds[5] ) / 2. };
967
968     vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
969                                      pow( aBounds[3] - aBounds[2], 2 ) +
970                                      pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
971
972     vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
973                                          {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
974     vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
975
976     vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
977                                       aPnt[1] - aDelta[0][1] - aDelta[1][1],
978                                       aPnt[2] - aDelta[0][2] - aDelta[1][2]};
979     vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
980                                       aPnt01[1] + aNormal[1],
981                                       aPnt01[2] + aNormal[2]};
982     vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
983
984     vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
985                                       aPnt[1] - aDelta[0][1] + aDelta[1][1],
986                                       aPnt[2] - aDelta[0][2] + aDelta[1][2]};
987     vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
988                                       aPnt11[1] + aNormal[1],
989                                       aPnt11[2] + aNormal[2]};
990     vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
991
992     vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
993                                       aPnt[1] + aDelta[0][1] - aDelta[1][1],
994                                       aPnt[2] + aDelta[0][2] - aDelta[1][2]};
995     vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
996                                       aPnt21[1] + aNormal[1],
997                                       aPnt21[2] + aNormal[2]};
998     vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
999
1000     vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1001     aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
1002     aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
1003     aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
1004     aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
1005   }
1006
1007   if(AutoApplyCheckBox->isChecked())
1008     ClickOnApply();
1009
1010   SMESH::RenderViewWindow( myViewWindow );
1011 }
1012
1013 //=======================================================================
1014 // function : OnPreviewToggle()
1015 // purpose  :
1016 //=======================================================================
1017 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1018 {
1019   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1020   SMESH::RenderViewWindow( myViewWindow );
1021 }
1022
1023 //=================================================================================
1024 // function : keyPressEvent()
1025 // purpose  :
1026 //=================================================================================
1027 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1028 {
1029   QDialog::keyPressEvent( e );
1030   if ( e->isAccepted() )
1031     return;
1032
1033   if ( e->key() == Qt::Key_F1 ) {
1034     e->accept();
1035     ClickOnHelp();
1036   }
1037 }
1038
1039 //=================================================================================
1040 // function : initializePlaneData()
1041 // purpose  :
1042 //=================================================================================
1043 void SMESHGUI_ClippingDlg::initializePlaneData()
1044 {
1045   const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1046   SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
1047   if( anIter1 != aClippingPlaneInfoMap.end() ) {
1048     const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
1049     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
1050     for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
1051       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
1052       SMESH::TPlane aTPlane( aClippingPlaneInfo.Plane );
1053       SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
1054       myPlanes.push_back( aPlaneData );
1055     }
1056   }
1057   std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
1058 }
1059
1060 //=================================================================================
1061 // function : updateActorList()
1062 // purpose  :
1063 //=================================================================================
1064 void SMESHGUI_ClippingDlg::updateActorList()
1065 {
1066   ActorList->clear();
1067
1068   SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
1069   if( !anAppStudy )
1070     return;
1071
1072   _PTR(Study) aStudy = anAppStudy->studyDS();
1073   if( !aStudy )
1074     return;
1075
1076   if( !myViewWindow )
1077     return;
1078
1079   int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
1080   const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
1081   const SMESH::TActorList& anActorList = aPlaneData.ActorList;
1082
1083   VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
1084   vtkActorCollection* anAllActors = aCopy.GetActors();
1085   anAllActors->InitTraversal();
1086   while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) {
1087     if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
1088       if( anActor->hasIO() ) {
1089         Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1090         if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
1091           bool anIsChecked = false;
1092           SMESH::TActorList::const_iterator anIter = anActorList.begin();
1093           for ( ; anIter != anActorList.end(); anIter++ ) {
1094             if( vtkActor* aVTKActorRef = *anIter ) {
1095               if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
1096                 if( anActorRef == anActor ) {
1097                   anIsChecked = true;
1098                   break;
1099                 }
1100               }
1101             }
1102           }
1103           QString aName = QString( aSObj->GetName().c_str() );
1104           QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
1105           anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
1106           updateActorItem( anItem, true, false );
1107         }
1108       }
1109     }
1110   }
1111 }
1112
1113 //=================================================================================
1114 // function : getCurrentActors()
1115 // purpose  :
1116 //=================================================================================
1117 SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
1118 {
1119   SMESH::TActorList anActorList;
1120   for( int i = 0, n = ActorList->count(); i < n; i++ )
1121     if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
1122       if( anItem->checkState() == Qt::Checked )
1123         if( SMESH_Actor* anActor = anItem->getActor() )
1124           anActorList.push_back( anActor );
1125   return anActorList;
1126 }
1127
1128 //=================================================================================
1129 // function : dumpPlaneData()
1130 // purpose  :
1131 //=================================================================================
1132 void SMESHGUI_ClippingDlg::dumpPlaneData() const
1133 {
1134   printf( "----------- Plane Data -----------\n" );
1135   int anId = 1;
1136   SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
1137   for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
1138     SMESH::TPlaneData aPlaneData = *anIter1;
1139     SMESH::TPlane aPlane = aPlaneData.Plane;
1140     vtkFloatingPointType* aNormal = aPlane->GetNormal();
1141     vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
1142     printf( "Plane N%d:\n", anId );
1143     printf( "  Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1144     printf( "  Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
1145
1146     SMESH::TActorList anActorList = aPlaneData.ActorList;
1147     SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
1148     for ( ; anIter2 != anActorList.end(); anIter2++ ) {
1149       if( vtkActor* aVTKActor = *anIter2 ) {
1150         if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
1151           printf( "  - Actor: '%s'\n", anActor->getName() );
1152       }
1153       else
1154         printf( "  - Actor: NULL\n");
1155     }
1156   }
1157   printf( "----------------------------------\n" );
1158 }