Salome HOME
Merge from V6_main 01/04/2013
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ClippingDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_ClippingDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_ClippingDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37
38 // SALOME GUI includes
39 #include <SUIT_Desktop.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_OverrideCursor.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_ViewManager.h>
45
46 #include <SALOME_ListIO.hxx>
47
48 #include <SalomeApp_Study.h>
49
50 #include <LightApp_Application.h>
51
52 #include <VTKViewer_Algorithm.h>
53
54 #include <SVTK_ViewWindow.h>
55
56 // Qt includes
57 #include <QLabel>
58 #include <QPushButton>
59 #include <QComboBox>
60 #include <QCheckBox>
61 #include <QVBoxLayout>
62 #include <QHBoxLayout>
63 #include <QGridLayout>
64 #include <QGroupBox>
65 #include <QKeyEvent>
66 #include <QListWidget>
67
68 // VTK includes
69 #include <vtkMath.h>
70 #include <vtkDataSet.h>
71 #include <vtkDataSetMapper.h>
72 #include <vtkPlaneSource.h>
73 #include <vtkProperty.h>
74 #include <vtkRenderer.h>
75
76 #define SPACING 6
77 #define MARGIN  11
78
79 //=================================================================================
80 // class    : OrientedPlane
81 // purpose  :
82 //=================================================================================
83 SMESH::OrientedPlane* SMESH::OrientedPlane::New()
84 {
85   return new OrientedPlane();
86 }
87
88 SMESH::OrientedPlane* SMESH::OrientedPlane::New(SVTK_ViewWindow* theViewWindow)
89 {
90   return new OrientedPlane(theViewWindow);
91 }
92
93 void SMESH::OrientedPlane::ShallowCopy(SMESH::OrientedPlane* theOrientedPlane)
94 {
95   SetNormal(theOrientedPlane->GetNormal());
96   SetOrigin(theOrientedPlane->GetOrigin());
97
98   myOrientation = theOrientedPlane->GetOrientation();
99   myDistance = theOrientedPlane->GetDistance();
100
101   myAngle[0] = theOrientedPlane->myAngle[0];
102   myAngle[1] = theOrientedPlane->myAngle[1];
103
104   myPlaneSource->SetNormal(theOrientedPlane->myPlaneSource->GetNormal());
105   myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
106   myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
107   myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
108   myPlaneSource->Update();
109 }
110
111 SMESH::OrientedPlane::OrientedPlane(SVTK_ViewWindow* theViewWindow):
112   myViewWindow(theViewWindow),
113   myOrientation(SMESH::XY),
114   myDistance(0.5)
115 {
116   Init();
117   myViewWindow->AddActor(myActor, false, false); // don't adjust actors
118 }
119
120 SMESH::OrientedPlane::OrientedPlane():
121   myOrientation(SMESH::XY),
122   myViewWindow(NULL),
123   myDistance(0.5)
124 {
125   Init();
126 }
127
128 void SMESH::OrientedPlane::Init()
129 {
130   myPlaneSource = vtkPlaneSource::New();
131
132   myAngle[0] = myAngle[1] = 0.0;
133
134   // Create and display actor
135   myMapper = vtkDataSetMapper::New();
136   myMapper->SetInputConnection(myPlaneSource->GetOutputPort());
137
138   myActor = SALOME_Actor::New();
139   myActor->VisibilityOff();
140   myActor->PickableOff();
141   myActor->SetInfinitive(true);
142   myActor->SetMapper(myMapper);
143
144   double anRGB[3];
145   vtkProperty* aProp = vtkProperty::New();
146   SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
147   aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
148   aProp->SetOpacity(0.75);
149   myActor->SetProperty(aProp);
150   aProp->Delete();
151
152   vtkProperty* aBackProp = vtkProperty::New();
153   SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
154   aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
155   aBackProp->SetOpacity(0.75);
156   myActor->SetBackfaceProperty(aBackProp);
157   aBackProp->Delete();
158 }
159
160 SMESH::OrientedPlane::~OrientedPlane()
161 {
162   if (myViewWindow)
163     myViewWindow->RemoveActor(myActor);
164   myActor->Delete();
165     
166   myMapper->RemoveAllInputs();
167   myMapper->Delete();
168
169   // commented: porting to vtk 5.0
170   //    myPlaneSource->UnRegisterAllOutputs();
171   myPlaneSource->Delete();
172 }
173
174 //=================================================================================
175 // class    : ActorItem
176 // purpose  :
177 //=================================================================================
178 class ActorItem : public QListWidgetItem
179 {
180 public:
181   ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) :
182     QListWidgetItem( theName, theListWidget ),
183     myActor( theActor ) {}
184
185   SMESH_Actor* getActor() const { return myActor; }
186
187 private:
188   SMESH_Actor* myActor;
189 };
190
191 //=================================================================================
192 // class    : TSetVisibility
193 // purpose  :
194 //=================================================================================
195 struct TSetVisibility {
196   TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){}
197   void operator()(SMESH::TPlaneData& thePlaneData){
198     bool anIsEmpty = thePlaneData.ActorList.empty();
199     thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty);
200   }
201   int myIsVisible;
202 };
203
204 //=================================================================================
205 // used in SMESHGUI::restoreVisualParameters() to avoid
206 // declaration of OrientedPlane outside of SMESHGUI_ClippingDlg.cxx
207 //=================================================================================
208 SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList          theActorList,
209                                                       SVTK_ViewWindow*           theViewWindow,
210                                                       SMESH::Orientation         theOrientation,
211                                                       double                     theDistance,
212                                                       const double theAngle[2])
213 {
214   SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(theViewWindow);
215
216   aPlane->myAngle[0] = theAngle[0];
217   aPlane->myAngle[1] = theAngle[1];
218
219   aPlane->SetOrientation(theOrientation);
220   aPlane->SetDistance(theDistance);
221
222   double aNormal[3];
223   double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
224   {
225     static double aCoeff = vtkMath::Pi()/180.0;
226
227     double anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
228     double aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
229     aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
230     aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
231
232     switch (theOrientation) {
233     case SMESH::XY:
234       aDir[0][1] = anU[0];
235       aDir[0][2] = aV[0];
236
237       aDir[1][0] = anU[1];
238       aDir[1][2] = aV[1];
239
240       break;
241     case SMESH::YZ:
242       aDir[0][2] = anU[0];
243       aDir[0][0] = aV[0];
244
245       aDir[1][1] = anU[1];
246       aDir[1][0] = aV[1];
247
248       break;
249     case SMESH::ZX:
250       aDir[0][0] = anU[0];
251       aDir[0][1] = aV[0];
252
253       aDir[1][2] = anU[1];
254       aDir[1][1] = aV[1];
255
256       break;
257     }
258
259     vtkMath::Cross(aDir[1],aDir[0],aNormal);
260     vtkMath::Normalize(aNormal);
261     vtkMath::Cross(aNormal,aDir[1],aDir[0]);
262   }
263
264   double aBounds[6];
265   double anOrigin[3];
266
267   bool anIsOk = false;
268   if( theActorList.empty() ) {
269     // to support planes with empty actor list we should create
270     // a nullified plane that will be initialized later 
271     anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
272     aBounds[0] = aBounds[2] = aBounds[4] = 0;
273     aBounds[1] = aBounds[3] = aBounds[5] = 0;
274     anIsOk = true;
275   }
276   else
277     anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
278                                                     aNormal,
279                                                     theDistance,
280                                                     aBounds,
281                                                     anOrigin );
282   if( !anIsOk )
283     return NULL;
284
285   aPlane->SetNormal( aNormal );
286   aPlane->SetOrigin( anOrigin );
287
288   double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
289                                    ( aBounds[2] + aBounds[3] ) / 2.,
290                                    ( aBounds[4] + aBounds[5] ) / 2. };
291
292   double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
293                                    pow( aBounds[3] - aBounds[2], 2 ) +
294                                    pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
295
296   double aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
297                                        {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
298   double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
299
300   double aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
301                                     aPnt[1] - aDelta[0][1] - aDelta[1][1],
302                                     aPnt[2] - aDelta[0][2] - aDelta[1][2]};
303   double aPnt02[3] = {aPnt01[0] + aNormal[0],
304                                     aPnt01[1] + aNormal[1],
305                                     aPnt01[2] + aNormal[2]};
306   vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
307
308   double aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
309                                     aPnt[1] - aDelta[0][1] + aDelta[1][1],
310                                     aPnt[2] - aDelta[0][2] + aDelta[1][2]};
311   double aPnt12[3] = {aPnt11[0] + aNormal[0],
312                                     aPnt11[1] + aNormal[1],
313                                     aPnt11[2] + aNormal[2]};
314   vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
315
316   double aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
317                                     aPnt[1] + aDelta[0][1] - aDelta[1][1],
318                                     aPnt[2] + aDelta[0][2] - aDelta[1][2]};
319   double aPnt22[3] = {aPnt21[0] + aNormal[0],
320                                     aPnt21[1] + aNormal[1],
321                                     aPnt21[2] + aNormal[2]};
322   vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
323
324   vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
325   aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
326   aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
327   aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
328   aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
329   aPlaneSource->Update();
330
331   SMESH::TActorList::iterator anIter = theActorList.begin();
332   for ( ; anIter != theActorList.end(); anIter++ )
333     if( vtkActor* aVTKActor = *anIter )
334       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
335         anActor->AddClippingPlane( aPlane );
336
337   return aPlane;
338 }
339
340 //=================================================================================
341 // class    : SMESHGUI_ClippingDlg()
342 // purpose  :
343 //
344 //=================================================================================
345 SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow* theViewWindow ):
346   QDialog( SMESH::GetDesktop(theModule) ),
347   mySMESHGUI(theModule),
348   myViewWindow(theViewWindow)
349 {
350   setModal( false );
351   setAttribute( Qt::WA_DeleteOnClose, true );
352   setWindowTitle(tr("SMESH_CLIPPING_TITLE"));
353   setSizeGripEnabled(true);
354
355   QVBoxLayout* SMESHGUI_ClippingDlgLayout = new QVBoxLayout(this);
356   SMESHGUI_ClippingDlgLayout->setSpacing(SPACING);
357   SMESHGUI_ClippingDlgLayout->setMargin(MARGIN);
358
359   // Controls for selecting, creating, deleting planes
360   QGroupBox* GroupPlanes = new QGroupBox(tr("CLIP_PLANES"), this);
361   QGridLayout* GroupPlanesLayout = new QGridLayout(GroupPlanes);
362   GroupPlanesLayout->setSpacing(SPACING);
363   GroupPlanesLayout->setMargin(MARGIN);
364
365   ComboBoxPlanes = new QComboBox(GroupPlanes);
366
367   buttonNew = new QPushButton(tr("SMESH_BUT_NEW"), GroupPlanes);
368
369   buttonDelete = new QPushButton(tr("SMESH_BUT_DELETE"), GroupPlanes);
370
371   QLabel* aLabel = new QLabel(tr("MESHES_SUBMESHES_GROUPS"), GroupPlanes);
372
373   ActorList = new QListWidget(GroupPlanes);
374   ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
375   
376   SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
377
378   GroupPlanesLayout->addWidget(ComboBoxPlanes,    0, 0);
379   GroupPlanesLayout->addWidget(new QWidget(),     0, 1);
380   GroupPlanesLayout->addWidget(buttonNew,         0, 2);
381   GroupPlanesLayout->addWidget(buttonDelete,      0, 3);
382   GroupPlanesLayout->addWidget(aLabel,            1, 0, 1, 4);
383   GroupPlanesLayout->addWidget(ActorList,         2, 0, 1, 4);
384   GroupPlanesLayout->addWidget(SelectAllCheckBox, 3, 0, 1, 4);
385   GroupPlanesLayout->setColumnStretch( 1, 1 );
386
387   // Controls for defining plane parameters
388   QGroupBox* GroupParameters = new QGroupBox(tr("SMESH_PARAMETERS"), this);
389   QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
390   GroupParametersLayout->setSpacing(SPACING);
391   GroupParametersLayout->setMargin(MARGIN);
392
393   TextLabelOrientation = new QLabel(tr("SMESH_ORIENTATION"), GroupParameters);
394
395   ComboBoxOrientation = new QComboBox(GroupParameters);
396
397   TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupParameters);
398
399   SpinBoxDistance = new SMESHGUI_SpinBox(GroupParameters);
400
401   TextLabelRot1 = new QLabel(tr("ROTATION_AROUND_X_Y2Z"), GroupParameters);
402
403   SpinBoxRot1 = new SMESHGUI_SpinBox(GroupParameters);
404
405   TextLabelRot2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters);
406
407   SpinBoxRot2 = new SMESHGUI_SpinBox(GroupParameters);
408
409   PreviewCheckBox = new QCheckBox(tr("SHOW_PREVIEW"), GroupParameters);
410   PreviewCheckBox->setChecked(true);
411
412   AutoApplyCheckBox = new QCheckBox(tr("AUTO_APPLY"), GroupParameters);
413   AutoApplyCheckBox->setChecked(false);
414
415   GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
416   GroupParametersLayout->addWidget(ComboBoxOrientation,  0, 1);
417   GroupParametersLayout->addWidget(TextLabelDistance,    1, 0);
418   GroupParametersLayout->addWidget(SpinBoxDistance,      1, 1);
419   GroupParametersLayout->addWidget(TextLabelRot1,        2, 0);
420   GroupParametersLayout->addWidget(SpinBoxRot1,          2, 1);
421   GroupParametersLayout->addWidget(TextLabelRot2,        3, 0);
422   GroupParametersLayout->addWidget(SpinBoxRot2,          3, 1);
423   GroupParametersLayout->addWidget(PreviewCheckBox,      4, 0);
424   GroupParametersLayout->addWidget(AutoApplyCheckBox,    4, 1);
425
426   // Controls for "Ok", "Apply" and "Close" button
427   QGroupBox* GroupButtons = new QGroupBox(this);
428   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
429   GroupButtonsLayout->setSpacing(SPACING);
430   GroupButtonsLayout->setMargin(MARGIN);
431   
432   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
433   buttonOk->setAutoDefault(true);
434   buttonOk->setDefault(true);
435   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
436   buttonApply->setAutoDefault(true);
437   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
438   buttonCancel->setAutoDefault(true);
439   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
440   buttonHelp->setAutoDefault(true);
441   GroupButtonsLayout->addWidget(buttonOk);
442   GroupButtonsLayout->addSpacing(10);
443   GroupButtonsLayout->addWidget(buttonApply);
444   GroupButtonsLayout->addSpacing(10);
445   GroupButtonsLayout->addStretch();
446   GroupButtonsLayout->addWidget(buttonCancel);
447   GroupButtonsLayout->addWidget(buttonHelp);
448
449   SMESHGUI_ClippingDlgLayout->addWidget(GroupPlanes);
450   SMESHGUI_ClippingDlgLayout->addWidget(GroupParameters);
451   SMESHGUI_ClippingDlgLayout->addWidget(GroupButtons);
452
453   // Initial state
454   SpinBoxDistance->RangeStepAndValidator(0.0, 1.0, 0.01, "length_precision" );
455   SpinBoxRot1->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
456   SpinBoxRot2->RangeStepAndValidator(-180.0, 180.0, 1, "angle_precision" );
457
458   ComboBoxOrientation->addItem(tr("ALONG_XY"));
459   ComboBoxOrientation->addItem(tr("ALONG_YZ"));
460   ComboBoxOrientation->addItem(tr("ALONG_ZX"));
461
462   SpinBoxDistance->SetValue(0.5);
463
464   myIsSelectPlane = false;
465
466   initializePlaneData();
467   synchronize();
468
469   myHelpFileName = "clipping_page.html";
470
471   // signals and slots connections :
472   connect(ComboBoxPlanes, SIGNAL(activated(int)), this, SLOT(onSelectPlane(int)));
473   connect(buttonNew, SIGNAL(clicked()), this, SLOT(ClickOnNew()));
474   connect(buttonDelete, SIGNAL(clicked()), this, SLOT(ClickOnDelete()));
475   connect(ActorList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(onActorItemChanged(QListWidgetItem*)));
476   connect(SelectAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onSelectAll(int)));
477   connect(ComboBoxOrientation, SIGNAL(activated(int)), this, SLOT(onSelectOrientation(int)));
478   connect(SpinBoxDistance, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
479   connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
480   connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
481   connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
482   connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(onAutoApply(bool)));
483   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
484   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
485   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
486   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
487   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
488   /* to close dialog if study frame change */
489   connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), this, SLOT(reject()));
490
491   this->show();
492 }
493
494 //=================================================================================
495 // function : ~SMESHGUI_ClippingDlg()
496 // purpose  :
497 //=================================================================================
498 SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg()
499 {
500   // no need to delete child widgets, Qt does it all for us
501   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(false));
502   if (myViewWindow)
503     SMESH::RenderViewWindow(myViewWindow);
504 }
505
506 double SMESHGUI_ClippingDlg::getDistance() const
507 {
508   return SpinBoxDistance->GetValue();
509 }
510
511 void SMESHGUI_ClippingDlg::setDistance( const double theDistance )
512 {
513   SpinBoxDistance->SetValue( theDistance );
514 }
515
516 double SMESHGUI_ClippingDlg::getRotation1() const
517 {
518   return SpinBoxRot1->GetValue();
519 }
520
521 double SMESHGUI_ClippingDlg::getRotation2() const
522 {
523   return SpinBoxRot2->GetValue();
524 }
525
526 //=======================================================================
527 // function : ClickOnApply()
528 // purpose  :
529 //=======================================================================
530 void SMESHGUI_ClippingDlg::ClickOnApply()
531 {
532   if (myViewWindow) {
533     SUIT_OverrideCursor wc;
534     
535     QWidget *aCurrWid = this->focusWidget();
536     aCurrWid->clearFocus();
537     aCurrWid->setFocus();
538
539     SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
540     SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = aClippingPlaneInfoMap[ myViewWindow->getViewManager() ];
541
542     // clean memory allocated for planes
543     SMESHGUI_ClippingPlaneInfoList::iterator anIter1 = aClippingPlaneInfoList.begin();
544     for( ; anIter1 != aClippingPlaneInfoList.end(); anIter1++ )
545       if( SMESH::OrientedPlane* aPlane = (*anIter1).Plane )
546         aPlane->Delete();
547
548     aClippingPlaneInfoList.clear();
549
550     VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
551     vtkActorCollection* anAllActors = aCopy.GetActors();
552     anAllActors->InitTraversal();
553     while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
554       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
555         anActor->RemoveAllClippingPlanes();
556
557     SMESH::TPlaneDataVector::iterator anIter2 = myPlanes.begin();
558     for( ; anIter2 != myPlanes.end(); anIter2++ ) {
559       SMESH::TPlaneData aPlaneData = *anIter2;
560       SMESH::TPlane aPlane = aPlaneData.Plane;
561       SMESH::TActorList anActorList = aPlaneData.ActorList;
562
563       // the check is disabled to support planes with empty actor list
564       //if( anActorList.empty() )
565       //  continue;
566
567       SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
568       anOrientedPlane->ShallowCopy(aPlane.GetPointer());
569
570       SMESH::TActorList::iterator anIter3 = anActorList.begin();
571       for( ; anIter3 != anActorList.end(); anIter3++ )
572         if( vtkActor* aVTKActor = *anIter3 )
573           if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
574             anActor->AddClippingPlane(anOrientedPlane);
575
576       SMESH::ClippingPlaneInfo aClippingPlaneInfo;
577       aClippingPlaneInfo.Plane = anOrientedPlane;
578       aClippingPlaneInfo.ActorList = anActorList;
579
580       aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
581     }
582
583     SMESH::RenderViewWindow( myViewWindow );
584   }
585 }
586
587 //=======================================================================
588 // function : ClickOnOk()
589 // purpose  :
590 //=======================================================================
591 void SMESHGUI_ClippingDlg::ClickOnOk()
592 {
593   ClickOnApply();
594   reject();
595 }
596
597 //=======================================================================
598 // function : reject()
599 // purpose  :
600 //=======================================================================
601 void SMESHGUI_ClippingDlg::reject()
602 {
603   //here we can insert actions to do at close.
604   QDialog::reject();
605 }
606
607 //=================================================================================
608 // function : ClickOnHelp()
609 // purpose  :
610 //=================================================================================
611 void SMESHGUI_ClippingDlg::ClickOnHelp()
612 {
613   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
614   if (app) 
615     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
616   else {
617                 QString platform;
618 #ifdef WIN32
619                 platform = "winapplication";
620 #else
621                 platform = "application";
622 #endif
623     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
624                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
625                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
626                                                                  platform)).
627                              arg(myHelpFileName));
628   }
629 }
630
631 //=======================================================================
632 // function : onSelectPlane()
633 // purpose  :
634 //=======================================================================
635 void SMESHGUI_ClippingDlg::onSelectPlane (int theIndex)
636 {
637   if (myPlanes.empty())
638     return;
639
640   SMESH::TPlaneData aPlaneData = myPlanes[theIndex];
641   SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
642
643   // Orientation
644   SMESH::Orientation anOrientation = aPlane->GetOrientation();
645
646   // Rotations
647   double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
648
649   // Set plane parameters in the dialog
650   myIsSelectPlane = true;
651   setDistance(aPlane->GetDistance());
652   setRotation(aRot[0], aRot[1]);
653   switch (anOrientation) {
654   case SMESH::XY:
655     ComboBoxOrientation->setCurrentIndex(0);
656     onSelectOrientation(0);
657     break;
658   case SMESH::YZ:
659     ComboBoxOrientation->setCurrentIndex(1);
660     onSelectOrientation(1);
661     break;
662   case SMESH::ZX:
663     ComboBoxOrientation->setCurrentIndex(2);
664     onSelectOrientation(2);
665     break;
666   }
667   myIsSelectPlane = false;
668
669   // Actors
670   bool anIsBlocked = ActorList->blockSignals( true );
671   updateActorList();
672   ActorList->blockSignals( anIsBlocked );
673 }
674
675 //=======================================================================
676 // function : ClickOnNew()
677 // purpose  :
678 //=======================================================================
679 void SMESHGUI_ClippingDlg::ClickOnNew()
680 {
681   if(myViewWindow){
682     SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow);
683     SMESH::TPlane aTPlane(aPlane);
684
685     SMESH::TActorList anActorList;
686     VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() );
687     vtkActorCollection* anAllActors = aCopy.GetActors();
688     anAllActors->InitTraversal();
689     while( vtkActor* aVTKActor = anAllActors->GetNextActor() )
690       if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
691         anActorList.push_back( anActor );
692
693     SMESH::TPlaneData aPlaneData(aTPlane, anActorList);
694
695     myPlanes.push_back(aPlaneData);
696
697     if (PreviewCheckBox->isChecked())
698       aTPlane->myActor->VisibilityOn();
699
700     bool anIsBlocked = ActorList->blockSignals( true );
701
702     synchronize();
703     SetCurrentPlaneParam();
704
705     ActorList->blockSignals( anIsBlocked );
706   }
707 }
708
709 //=======================================================================
710 // function : ClickOnDelete()
711 // purpose  :
712 //=======================================================================
713 void SMESHGUI_ClippingDlg::ClickOnDelete()
714 {
715   if (myPlanes.empty())
716     return;
717
718   int aPlaneIndex = ComboBoxPlanes->currentIndex();
719
720   SMESH::TPlaneDataVector::iterator anIter = myPlanes.begin() + aPlaneIndex;
721   SMESH::TPlaneData aPlaneData = *anIter;
722   aPlaneData.Plane.GetPointer()->myActor->SetVisibility(false);
723   myPlanes.erase(anIter);
724
725   if(AutoApplyCheckBox->isChecked())
726     ClickOnApply();
727
728   synchronize();
729   SMESH::RenderViewWindow( myViewWindow );
730 }
731
732 //=======================================================================
733 // function : updateActorItem()
734 // purpose  :
735 //=======================================================================
736 void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
737                                             bool theUpdateSelectAll,
738                                             bool theUpdateClippingPlaneMap )
739 {
740   // update Select All check box
741   if( theUpdateSelectAll ) {
742     int aNbItems = ActorList->count(), aNbChecked = 0;
743     for( int i = 0; i < aNbItems; i++ )
744       if( QListWidgetItem* anItem = ActorList->item( i ) )
745         if( anItem->checkState() == Qt::Checked )
746           aNbChecked++;
747
748     bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
749     SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
750     SelectAllCheckBox->blockSignals( anIsBlocked );
751   }
752
753   // update clipping plane map
754   if( theUpdateClippingPlaneMap ) {
755     int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
756     if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
757       if( SMESH_Actor* anActor = anItem->getActor() ) {
758         SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
759         SMESH::TActorList& anActorList = aPlaneData.ActorList;
760         bool anIsPushed = false;
761         SMESH::TActorList::iterator anIter = anActorList.begin();
762         for ( ; anIter != anActorList.end(); anIter++ ) {
763           if( anActor == *anIter ) {
764             anIsPushed = true;
765             break;
766           }
767         }
768         if( theItem->checkState() == Qt::Checked && !anIsPushed )
769           anActorList.push_back( anActor );
770         else if( theItem->checkState() == Qt::Unchecked && anIsPushed )
771           anActorList.remove( anActor );
772       }
773     }
774   }
775 }
776
777 //=======================================================================
778 // function : onActorItemChanged()
779 // purpose  :
780 //=======================================================================
781 void SMESHGUI_ClippingDlg::onActorItemChanged( QListWidgetItem* theItem )
782 {
783   updateActorItem( theItem, true, true );
784   SetCurrentPlaneParam();
785 }
786
787 //=======================================================================
788 // function : onSelectAll()
789 // purpose  :
790 //=======================================================================
791 void SMESHGUI_ClippingDlg::onSelectAll( int theState )
792 {
793   if( theState == Qt::PartiallyChecked ) {
794     SelectAllCheckBox->setCheckState( Qt::Checked );
795     return;
796   }
797
798   bool anIsBlocked = ActorList->blockSignals( true );
799   for( int i = 0, n = ActorList->count(); i < n; i++ ) {
800     if( QListWidgetItem* anItem = ActorList->item( i ) ) {
801       anItem->setCheckState( theState == Qt::Checked ? Qt::Checked : Qt::Unchecked );
802       updateActorItem( anItem, false, true );
803     }
804   }
805   SelectAllCheckBox->setTristate( false );
806   ActorList->blockSignals( anIsBlocked );
807   SetCurrentPlaneParam();
808 }
809
810 //=======================================================================
811 // function : onSelectOrientation()
812 // purpose  :
813 //=======================================================================
814 void SMESHGUI_ClippingDlg::onSelectOrientation (int theItem)
815 {
816   if (myPlanes.empty())
817     return;
818
819   if      (theItem == 0) {
820     TextLabelRot1->setText(tr("ROTATION_AROUND_X_Y2Z"));
821     TextLabelRot2->setText(tr("ROTATION_AROUND_Y_X2Z"));
822   }
823   else if (theItem == 1) {
824     TextLabelRot1->setText(tr("ROTATION_AROUND_Y_Z2X"));
825     TextLabelRot2->setText(tr("ROTATION_AROUND_Z_Y2X"));
826   }
827   else if (theItem == 2) {
828     TextLabelRot1->setText(tr("ROTATION_AROUND_Z_X2Y"));
829     TextLabelRot2->setText(tr("ROTATION_AROUND_X_Z2Y"));
830   }
831
832   if((QComboBox*)sender() == ComboBoxOrientation)
833     SetCurrentPlaneParam();
834 }
835
836 //=======================================================================
837 // function : synchronize()
838 // purpose  :
839 //=======================================================================
840 void SMESHGUI_ClippingDlg::synchronize()
841 {
842   int aNbPlanes = myPlanes.size();
843   ComboBoxPlanes->clear();
844
845   QString aName;
846   for(int i = 1; i<=aNbPlanes; i++) {
847     aName = QString(tr("PLANE_NUM")).arg(i);
848     ComboBoxPlanes->addItem(aName);
849   }
850
851   int aPos = ComboBoxPlanes->count() - 1;
852   ComboBoxPlanes->setCurrentIndex(aPos);
853
854   bool anIsControlsEnable = (aPos >= 0);
855   if (anIsControlsEnable) {
856     onSelectPlane(aPos);
857     updateActorList();
858   } else {
859     ComboBoxPlanes->addItem(tr("NO_PLANES"));
860     ActorList->clear();
861     SpinBoxRot1->SetValue(0.0);
862     SpinBoxRot2->SetValue(0.0);
863     SpinBoxDistance->SetValue(0.5);
864   }
865
866   ActorList->setEnabled(anIsControlsEnable);
867   SelectAllCheckBox->setEnabled(anIsControlsEnable);
868   buttonDelete->setEnabled(anIsControlsEnable);
869   // the following 3 controls should be enabled
870   //buttonApply->setEnabled(anIsControlsEnable);
871   //PreviewCheckBox->setEnabled(anIsControlsEnable);
872   //AutoApplyCheckBox->setEnabled(anIsControlsEnable);
873   ComboBoxOrientation->setEnabled(anIsControlsEnable);
874   SpinBoxDistance->setEnabled(anIsControlsEnable);
875   SpinBoxRot1->setEnabled(anIsControlsEnable);
876   SpinBoxRot2->setEnabled(anIsControlsEnable);
877 }
878
879 //=======================================================================
880 // function : setRotation()
881 // purpose  :
882 //=======================================================================
883 void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2)
884 {
885   SpinBoxRot1->SetValue(theRot1);
886   SpinBoxRot2->SetValue(theRot2);
887 }
888
889 //=======================================================================
890 // function : SetCurrentPlaneParam()
891 // purpose  :
892 //=======================================================================
893 void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
894 {
895   if (myPlanes.empty() || myIsSelectPlane)
896     return;
897
898   int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
899
900   SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
901   SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
902
903   double aNormal[3];
904   SMESH::Orientation anOrientation;
905   double aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
906   {
907     static double aCoeff = vtkMath::Pi()/180.0;
908
909     double aRot[2] = {getRotation1(), getRotation2()};
910     aPlane->myAngle[0] = aRot[0];
911     aPlane->myAngle[1] = aRot[1];
912
913     double anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
914     double aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
915     aV[0] = aRot[0] > 0? aV[0]: -aV[0];
916     aV[1] = aRot[1] > 0? aV[1]: -aV[1];
917
918     switch (ComboBoxOrientation->currentIndex()) {
919     case 0:
920       anOrientation = SMESH::XY;
921
922       aDir[0][1] = anU[0];
923       aDir[0][2] = aV[0];
924
925       aDir[1][0] = anU[1];
926       aDir[1][2] = aV[1];
927
928       break;
929     case 1:
930       anOrientation = SMESH::YZ;
931
932       aDir[0][2] = anU[0];
933       aDir[0][0] = aV[0];
934
935       aDir[1][1] = anU[1];
936       aDir[1][0] = aV[1];
937
938       break;
939     case 2:
940       anOrientation = SMESH::ZX;
941
942       aDir[0][0] = anU[0];
943       aDir[0][1] = aV[0];
944
945       aDir[1][2] = anU[1];
946       aDir[1][1] = aV[1];
947
948       break;
949     }
950
951     vtkMath::Cross(aDir[1],aDir[0],aNormal);
952     vtkMath::Normalize(aNormal);
953     vtkMath::Cross(aNormal,aDir[1],aDir[0]);
954   }
955
956   aPlane->SetOrientation(anOrientation);
957   aPlane->SetDistance(getDistance());
958
959   SMESH::TActorList anActorList = aPlaneData.ActorList;
960
961   double aBounds[6];
962   double anOrigin[3];
963   bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
964                                                        aNormal,
965                                                        getDistance(),
966                                                        aBounds,
967                                                        anOrigin );
968
969   aPlane->myActor->SetVisibility( anIsOk && PreviewCheckBox->isChecked() );
970
971   if( anIsOk ) {
972     aPlane->SetNormal( aNormal );
973     aPlane->SetOrigin( anOrigin );
974
975     double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
976                                      ( aBounds[2] + aBounds[3] ) / 2.,
977                                      ( aBounds[4] + aBounds[5] ) / 2. };
978
979     double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
980                                      pow( aBounds[3] - aBounds[2], 2 ) +
981                                      pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
982
983     double aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
984                                          {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
985     double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
986
987     double aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
988                                       aPnt[1] - aDelta[0][1] - aDelta[1][1],
989                                       aPnt[2] - aDelta[0][2] - aDelta[1][2]};
990     double aPnt02[3] = {aPnt01[0] + aNormal[0],
991                                       aPnt01[1] + aNormal[1],
992                                       aPnt01[2] + aNormal[2]};
993     vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
994
995     double aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
996                                       aPnt[1] - aDelta[0][1] + aDelta[1][1],
997                                       aPnt[2] - aDelta[0][2] + aDelta[1][2]};
998     double aPnt12[3] = {aPnt11[0] + aNormal[0],
999                                       aPnt11[1] + aNormal[1],
1000                                       aPnt11[2] + aNormal[2]};
1001     vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
1002
1003     double aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
1004                                       aPnt[1] + aDelta[0][1] - aDelta[1][1],
1005                                       aPnt[2] + aDelta[0][2] - aDelta[1][2]};
1006     double aPnt22[3] = {aPnt21[0] + aNormal[0],
1007                                       aPnt21[1] + aNormal[1],
1008                                       aPnt21[2] + aNormal[2]};
1009     vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
1010
1011     vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
1012     aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
1013     aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
1014     aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
1015     aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
1016     aPlaneSource->Update();
1017   }
1018
1019   if(AutoApplyCheckBox->isChecked())
1020     ClickOnApply();
1021
1022   SMESH::RenderViewWindow( myViewWindow );
1023 }
1024
1025 //=======================================================================
1026 // function : OnPreviewToggle()
1027 // purpose  :
1028 //=======================================================================
1029 void SMESHGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1030 {
1031   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisibility(theIsToggled));
1032   SMESH::RenderViewWindow( myViewWindow );
1033 }
1034
1035 //=================================================================================
1036 // function : keyPressEvent()
1037 // purpose  :
1038 //=================================================================================
1039 void SMESHGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1040 {
1041   QDialog::keyPressEvent( e );
1042   if ( e->isAccepted() )
1043     return;
1044
1045   if ( e->key() == Qt::Key_F1 ) {
1046     e->accept();
1047     ClickOnHelp();
1048   }
1049 }
1050
1051 //=================================================================================
1052 // function : initializePlaneData()
1053 // purpose  :
1054 //=================================================================================
1055 void SMESHGUI_ClippingDlg::initializePlaneData()
1056 {
1057   const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
1058   SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
1059   if( anIter1 != aClippingPlaneInfoMap.end() ) {
1060     const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
1061     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
1062     for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
1063       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
1064       SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
1065       anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
1066       SMESH::TPlane aTPlane( anOrientedPlane );
1067       SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
1068       myPlanes.push_back( aPlaneData );
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     double* aNormal = aPlane->GetNormal();
1155     double* anOrigin = aPlane->GetOrigin();
1156     printf( "Plane N%d:\n", anId );
1157     printf( "  Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
1158     printf( "  Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
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 }
1173
1174 void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
1175 {
1176   if ( toggled ) ClickOnApply();
1177 }