]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_ClippingDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_ClippingDlg.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include "VisuGUI_ClippingDlg.h"
22
23 #include "VisuGUI.h"
24 #include "VisuGUI_Tools.h"
25 #include "VisuGUI_ViewTools.h"
26
27 #include "VISU_Prs3d_i.hh"
28 #include "VISU_Result_i.hh"
29
30 #include "VISU_PipeLine.hxx"
31
32 #include "LightApp_SelectionMgr.h"
33 #include "LightApp_Application.h"
34
35 #include "SVTK_ViewWindow.h"
36
37 #include "SUIT_Session.h"
38 #include "SUIT_Desktop.h"
39 #include "SUIT_MessageBox.h"
40 #include "SUIT_ResourceMgr.h"
41 #include "SUIT_OverrideCursor.h"
42
43 #include "SALOME_Actor.h"
44
45 // QT Includes
46 #include <qlabel.h>
47 #include <qpushbutton.h>
48 #include <qcombobox.h>
49 #include <qcheckbox.h>
50 #include <qlayout.h>
51 #include <qgroupbox.h>
52 #include <qvalidator.h>
53 #include <qtabwidget.h>
54 #include <qhbuttongroup.h>
55 #include <qradiobutton.h>
56 #include <qspinbox.h>
57
58 // VTK Includes
59 #include <vtkMath.h>
60 #include <vtkCamera.h>
61 #include <vtkRenderer.h>
62 #include <vtkDataSet.h>
63 #include <vtkDataSetMapper.h>
64 #include <vtkImplicitFunction.h>
65 #include <vtkPlaneSource.h>
66 #include <vtkPolyData.h>
67 #include <vtkUnstructuredGrid.h>
68 #include <vtkProperty.h>
69
70 // OCCT Includes
71 #include <gp_Dir.hxx>
72
73 using namespace std;
74
75 namespace VISU {
76   float GetFloat (const QString& theValue, float theDefault)
77   {
78     if (theValue.isEmpty()) return theDefault;
79     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
80     QString aValue = aResourceMgr->stringValue("VISU",theValue);
81     if (aValue.isEmpty()) return theDefault;
82     return aValue.toFloat();
83   }
84
85   void RenderViewWindow (SVTK_ViewWindow* vw)
86   {
87     if (vw) {
88       vw->getRenderer()->ResetCameraClippingRange();
89       vw->Repaint();
90     }
91   }
92
93   void RangeStepAndValidator (QtxDblSpinBox* theSpinBox, double min, double max,
94                               double step, unsigned short decimals)
95   {
96     theSpinBox->setRange(min, max);
97     theSpinBox->setLineStep(step);
98     ((QDoubleValidator*)theSpinBox->validator())->setRange(min, max, decimals);
99   }
100 };
101
102 //=================================================================================
103 //class    : OrientedPlane
104 //purpose  :
105 //=================================================================================
106 OrientedPlane* OrientedPlane::New() 
107 {
108   return new OrientedPlane();
109 }
110
111 OrientedPlane* OrientedPlane::New (SVTK_ViewWindow* vw) 
112 {
113   return new OrientedPlane(vw);
114 }
115
116 void OrientedPlane::SetOrientation(VISU::Orientation theOrientation) 
117 {
118   myOrientation = theOrientation;
119 }
120
121 VISU::Orientation OrientedPlane::GetOrientation() 
122 {
123   return myOrientation;
124 }
125
126 void OrientedPlane::SetDistance(float theDistance) 
127 {
128   myDistance = theDistance;
129 }
130
131 float OrientedPlane::GetDistance() 
132 {
133   return myDistance;
134 }
135
136 void OrientedPlane::ShallowCopy(OrientedPlane* theOrientedPlane)
137 {
138   SetNormal(theOrientedPlane->GetNormal());
139   SetOrigin(theOrientedPlane->GetOrigin());
140   
141   myOrientation = theOrientedPlane->GetOrientation();
142   myDistance = theOrientedPlane->GetDistance();
143   
144   myAngle[0] = theOrientedPlane->myAngle[0];
145   myAngle[1] = theOrientedPlane->myAngle[1];
146   
147   myPlaneSource->SetNormal(theOrientedPlane->myPlaneSource->GetNormal());
148   myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
149   myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
150   myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
151 }
152
153 OrientedPlane::OrientedPlane(SVTK_ViewWindow* vw):
154   myOrientation(VISU::XY),
155   myDistance(0.5),
156   myViewWindow(vw)
157 {
158   Init();
159   myViewWindow->AddActor(myActor);
160 }
161
162 OrientedPlane::OrientedPlane():
163   myOrientation(VISU::XY),
164   myDistance(0.5),
165   myViewWindow(NULL)
166 {
167   Init();
168 }
169
170 void OrientedPlane::Init()
171 {
172   myPlaneSource = vtkPlaneSource::New();
173   
174   myAngle[0] = myAngle[1] = 0.0;
175
176   // Create and display actor
177   myMapper = vtkDataSetMapper::New();
178   myMapper->SetInput(myPlaneSource->GetOutput());
179
180   myActor = SALOME_Actor::New();
181   myActor->VisibilityOff();
182   myActor->PickableOff();
183   myActor->SetInfinitive(true);
184   myActor->SetMapper(myMapper);
185   
186   vtkProperty* aProp = vtkProperty::New();
187   float anRGB[3];
188   
189   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
190   
191   QColor aFillColor = aResourceMgr->colorValue("SMESH", "fill_color", QColor(0, 170, 255));
192   anRGB[0] = aFillColor.red()/255.;
193   anRGB[1] = aFillColor.green()/255.;
194   anRGB[2] = aFillColor.blue()/255.;
195   aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
196   aProp->SetOpacity(0.75);
197   myActor->SetProperty(aProp);
198   aProp->Delete();
199   
200   vtkProperty* aBackProp = vtkProperty::New();
201   QColor aBackFaceColor = aResourceMgr->colorValue("SMESH", "backface_color", QColor(0, 0, 255));//@
202   anRGB[0] = aBackFaceColor.red()/255.;
203   anRGB[1] = aBackFaceColor.green()/255.;
204   anRGB[2] = aBackFaceColor.blue()/255.;
205   aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
206   aBackProp->SetOpacity(0.75);
207   myActor->SetBackfaceProperty(aBackProp);
208   aBackProp->Delete();
209 }
210
211 OrientedPlane::~OrientedPlane()
212 {
213   if ( !myViewWindow.isNull() )
214     myViewWindow->RemoveActor(myActor);
215
216   myActor->Delete();
217
218   myMapper->RemoveAllInputs();
219   myMapper->Delete();
220   
221   // commented: porting to vtk 5.0
222   //myPlaneSource->UnRegisterAllOutputs();
223   myPlaneSource->Delete();
224 }
225
226 struct TSetVisiblity {
227   TSetVisiblity(int theIsVisible): myIsVisible(theIsVisible){}
228   void operator()(VISU::TVTKPlane& theOrientedPlane){
229     theOrientedPlane->myActor->SetVisibility(myIsVisible);
230   }
231   int myIsVisible;
232 };
233
234 //=================================================================================
235 // class    : VisuGUI_ClippingDlg()
236 // purpose  :
237 //
238 //=================================================================================
239 VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule,
240                                           const char* name,
241                                           bool modal,
242                                           WFlags fl)
243   : QDialog(VISU::GetDesktop(theModule), name, modal, WStyle_Customize |
244             WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
245     mySelectionMgr(VISU::GetSelectionMgr(theModule)),
246     myVisuGUI(theModule),
247     myPrs3d(0),
248     myIsSelectPlane(false)
249 {
250   if (!name)
251     setName("VisuGUI_ClippingDlg");
252   setCaption(tr("TITLE"));
253   setSizeGripEnabled(TRUE);
254   QGridLayout* VisuGUI_ClippingDlgLayout = new QGridLayout(this);
255   VisuGUI_ClippingDlgLayout->setSpacing(6);
256   VisuGUI_ClippingDlgLayout->setMargin(11);
257
258   // Controls for selecting, creating, deleting planes
259   QGroupBox* GroupPlanes = new QGroupBox (this, "GroupPlanes");
260   GroupPlanes->setTitle(tr("GRP_PLANES"));
261   GroupPlanes->setColumnLayout(0, Qt::Vertical);
262   GroupPlanes->layout()->setSpacing(0);
263   GroupPlanes->layout()->setMargin(0);
264   QGridLayout* GroupPlanesLayout = new QGridLayout (GroupPlanes->layout());
265   GroupPlanesLayout->setAlignment(Qt::AlignTop);
266   GroupPlanesLayout->setSpacing(6);
267   GroupPlanesLayout->setMargin(11);
268
269   ComboBoxPlanes = new QComboBox (GroupPlanes, "ComboBoxPlanes");
270   GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0);
271
272   QSpacerItem* spacerGP = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
273   GroupPlanesLayout->addItem(spacerGP, 0, 1);
274
275   buttonNew = new QPushButton (GroupPlanes, "buttonNew");
276   buttonNew->setText(tr("BUT_NEW"));
277   GroupPlanesLayout->addWidget(buttonNew, 0, 2);
278
279   buttonDelete = new QPushButton(GroupPlanes, "buttonDelete");
280   buttonDelete->setText(tr("BUT_DELETE"));
281   GroupPlanesLayout->addWidget(buttonDelete, 0, 3);
282
283   // Controls for defining plane parameters
284
285   // Tab pane
286   QGroupBox* GroupParameters = new QGroupBox(this, "GroupParameters");
287   GroupParameters->setTitle(tr("GRP_PARAMETERS"));
288   GroupParameters->setColumnLayout(0, Qt::Vertical);
289   GroupParameters->layout()->setSpacing(0);
290   GroupParameters->layout()->setMargin(0);
291   QGridLayout* GroupParametersLayout = new QGridLayout (GroupParameters->layout());
292   GroupParametersLayout->setAlignment(Qt::AlignTop);
293   GroupParametersLayout->setSpacing(6);
294   GroupParametersLayout->setMargin(11);
295
296   TabPane = new QTabWidget (GroupParameters);
297   TabPane->addTab(createParamsTab()   , tr("TAB_NON_STRUCTURED"));
298   TabPane->addTab(createIJKParamsTab(), tr("TAB_IJK_STRUCTURED"));
299   GroupParametersLayout->addWidget(TabPane, 0, 0);
300
301   // "Show preview" and "Auto Apply" check boxes
302
303   PreviewCheckBox = new QCheckBox (tr("SHOW_PREVIEW_CHK"), this);
304   PreviewCheckBox->setChecked(true);
305
306   AutoApplyCheckBox = new QCheckBox (tr("AUTO_APPLY_CHK"), this);
307   AutoApplyCheckBox->setChecked(false);
308
309   // Controls for "Ok", "Apply" and "Close" button
310   QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons");
311   GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
312                                           (QSizePolicy::SizeType)0, 0, 0,
313                                           GroupButtons->sizePolicy().hasHeightForWidth()));
314   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
315   //GroupButtons->setTitle(tr(""));
316   GroupButtons->setColumnLayout(0, Qt::Vertical);
317   GroupButtons->layout()->setSpacing(0);
318   GroupButtons->layout()->setMargin(0);
319   QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
320   GroupButtonsLayout->setAlignment(Qt::AlignTop);
321   GroupButtonsLayout->setSpacing(6);
322   GroupButtonsLayout->setMargin(11);
323   buttonHelp = new QPushButton (GroupButtons, "buttonHelp");
324   buttonHelp->setText(tr("BUT_HELP"));
325   buttonHelp->setAutoDefault(TRUE);
326   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
327   buttonCancel = new QPushButton (GroupButtons, "buttonCancel");
328   buttonCancel->setText(tr("BUT_CLOSE"));
329   buttonCancel->setAutoDefault(TRUE);
330   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
331   buttonApply = new QPushButton (GroupButtons, "buttonApply");
332   buttonApply->setText(tr("BUT_APPLY"));
333   buttonApply->setAutoDefault(TRUE);
334   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
335   QSpacerItem* spacer_9 = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
336   GroupButtonsLayout->addItem(spacer_9, 0, 2);
337   buttonOk = new QPushButton (GroupButtons, "buttonOk");
338   buttonOk->setText(tr("BUT_OK"));
339   buttonOk->setAutoDefault(TRUE);
340   buttonOk->setDefault(TRUE);
341   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
342
343   VisuGUI_ClippingDlgLayout->addMultiCellWidget(GroupPlanes,     0, 0, 0, 1);
344   VisuGUI_ClippingDlgLayout->addMultiCellWidget(GroupParameters, 1, 1, 0, 1);
345   VisuGUI_ClippingDlgLayout->addWidget(PreviewCheckBox,          2,    0);
346   VisuGUI_ClippingDlgLayout->addWidget(AutoApplyCheckBox,        2,    1);
347   VisuGUI_ClippingDlgLayout->addMultiCellWidget(GroupButtons,    3, 3, 0, 1);
348
349   // Initial state
350   VISU::RangeStepAndValidator(SpinBoxDistance, 0.0, 1.0, 0.01, 3);
351   VISU::RangeStepAndValidator(SpinBoxRot1, -180.0, 180.0, 1, 3);
352   VISU::RangeStepAndValidator(SpinBoxRot2, -180.0, 180.0, 1, 3);
353
354   ComboBoxOrientation->insertItem(tr("PARALLEL_XOY_COMBO_ITEM"));
355   ComboBoxOrientation->insertItem(tr("PARALLEL_YOZ_COMBO_ITEM"));
356   ComboBoxOrientation->insertItem(tr("PARALLEL_ZOX_COMBO_ITEM"));
357
358   SpinBoxDistance->setValue(0.5);
359
360   onSelectionChanged();
361
362   // signals and slots connections :
363   connect(ComboBoxPlanes         , SIGNAL(activated(int))           , this, SLOT(onSelectPlane(int)));
364   connect(buttonNew              , SIGNAL(clicked())                , this, SLOT(ClickOnNew()));
365   connect(buttonDelete           , SIGNAL(clicked())                , this, SLOT(ClickOnDelete()));
366   connect(ComboBoxOrientation    , SIGNAL(activated(int))           , this, SLOT(onSelectOrientation(int)));
367   connect(SpinBoxDistance        , SIGNAL(valueChanged(double))     , this, SLOT(SetCurrentPlaneParam()));
368   connect(SpinBoxRot1            , SIGNAL(valueChanged(double))     , this, SLOT(SetCurrentPlaneParam()));
369   connect(SpinBoxRot2            , SIGNAL(valueChanged(double))     , this, SLOT(SetCurrentPlaneParam()));
370   connect(ButtonGroupIJKAxis     , SIGNAL(clicked(int))             , this, SLOT(onIJKAxisChanged(int)));
371   connect(SpinBoxIJKIndex        , SIGNAL(valueChanged(int))        , this, SLOT(SetCurrentPlaneIJKParam()));
372   connect(CheckBoxIJKPlaneReverse, SIGNAL(toggled(bool))            , this, SLOT(SetCurrentPlaneIJKParam()));
373   connect(TabPane                , SIGNAL(currentChanged (QWidget*)), this, SLOT(onTabChanged(QWidget*)));
374
375   connect(PreviewCheckBox  , SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
376   connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
377
378   connect(buttonOk    , SIGNAL(clicked()), this, SLOT(ClickOnOk()));
379   connect(buttonApply , SIGNAL(clicked()), this, SLOT(ClickOnApply()));
380   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
381   connect(buttonHelp  , SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
382
383   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
384
385   this->show();
386 }
387
388 //=================================================================================
389 // function : ~VisuGUI_ClippingDlg()
390 // purpose  :
391 //=================================================================================
392 VisuGUI_ClippingDlg::~VisuGUI_ClippingDlg()
393 {
394   // no need to delete child widgets, Qt does it all for us
395   SetPrs3d(NULL);
396   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
397   VISU::RenderViewWindow(VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI));
398 }
399
400 //=================================================================================
401 // function : createParamsTab
402 // purpose  :
403 //=================================================================================
404 QWidget* VisuGUI_ClippingDlg::createParamsTab()
405 {
406   QFrame* GroupParameters = new QFrame(this);
407   QGridLayout* GroupParametersLayout = new QGridLayout(GroupParameters);
408   GroupParametersLayout->setAlignment(Qt::AlignTop);
409   GroupParametersLayout->setSpacing(6);
410   GroupParametersLayout->setMargin(11);
411
412   TextLabelOrientation = new QLabel(GroupParameters, "TextLabelOrientation");
413   TextLabelOrientation->setText(tr("LBL_ORIENTATION"));
414   GroupParametersLayout->addWidget(TextLabelOrientation, 0, 0);
415
416   ComboBoxOrientation = new QComboBox(GroupParameters, "ComboBoxOrientation");
417   GroupParametersLayout->addWidget(ComboBoxOrientation, 0, 1);
418
419   TextLabelDistance = new QLabel(GroupParameters, "TextLabelDistance");
420   TextLabelDistance->setText(tr("LBL_DISTANCE"));
421   GroupParametersLayout->addWidget(TextLabelDistance, 1, 0);
422
423   SpinBoxDistance = new QtxDblSpinBox(GroupParameters, "SpinBoxDistance");
424   GroupParametersLayout->addWidget(SpinBoxDistance, 1, 1);
425
426   TextLabelRot1 = new QLabel(GroupParameters, "TextLabelRot1");
427   TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
428   GroupParametersLayout->addWidget(TextLabelRot1, 2, 0);
429
430   SpinBoxRot1 = new QtxDblSpinBox(GroupParameters, "SpinBoxRot1");
431   GroupParametersLayout->addWidget(SpinBoxRot1, 2, 1);
432
433   TextLabelRot2 = new QLabel(GroupParameters, "TextLabelRot2");
434   TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
435   GroupParametersLayout->addWidget(TextLabelRot2, 3, 0);
436
437   SpinBoxRot2 = new QtxDblSpinBox(GroupParameters, "SpinBoxRot2");
438   GroupParametersLayout->addWidget(SpinBoxRot2, 3, 1);
439
440   return GroupParameters;
441 }
442
443 //=================================================================================
444 // function : createIJKParamsTab
445 // purpose  :
446 //=================================================================================
447 QWidget* VisuGUI_ClippingDlg::createIJKParamsTab()
448 {
449   // tab layout
450   WidgetIJKTab = new QFrame(this);
451   QGridLayout* IJKParametersLayout = new QGridLayout(WidgetIJKTab);
452   IJKParametersLayout->setAlignment(Qt::AlignTop);
453   IJKParametersLayout->setSpacing(6);
454   IJKParametersLayout->setMargin(11);
455
456   // Axis group
457   ButtonGroupIJKAxis = new QHButtonGroup (tr("GRP_IJK_AXIS"), WidgetIJKTab);
458   new QRadioButton (tr("I_RADIO_BTN"), ButtonGroupIJKAxis);  // 0
459   new QRadioButton (tr("J_RADIO_BTN"), ButtonGroupIJKAxis);  // 1
460   new QRadioButton (tr("K_RADIO_BTN"), ButtonGroupIJKAxis);  // 2
461   ButtonGroupIJKAxis->setButton(0);
462
463   // Index
464   TextLabelIJKIndex = new QLabel(WidgetIJKTab, "TextLabelIJKIndex");
465   TextLabelIJKIndex->setText(tr("LBL_IJK_INDEX"));
466   SpinBoxIJKIndex = new QSpinBox(WidgetIJKTab, "SpinBoxIJKIndex");
467
468   // Orientation
469   CheckBoxIJKPlaneReverse = new QCheckBox (tr("REVERSE_NORMAL_CHK"), WidgetIJKTab);
470   CheckBoxIJKPlaneReverse->setChecked(false);
471
472   IJKParametersLayout->addMultiCellWidget(ButtonGroupIJKAxis, 0, 0, 0, 1);
473   IJKParametersLayout->addWidget(TextLabelIJKIndex,          1, 0);
474   IJKParametersLayout->addWidget(SpinBoxIJKIndex,            1, 1);
475   IJKParametersLayout->addWidget(CheckBoxIJKPlaneReverse, 2, 0);
476
477   return WidgetIJKTab;
478 }
479
480 //=================================================================================
481 // function : ClickOnApply()
482 // purpose  :
483 //=================================================================================
484 void VisuGUI_ClippingDlg::ClickOnApply()
485 {
486   if (!myPrs3d)
487     return;
488
489   if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI)) {
490     SUIT_OverrideCursor wc;
491
492     QWidget *aCurrWid = this->focusWidget();
493     aCurrWid->clearFocus();
494     aCurrWid->setFocus();
495
496     // Save clipping planes, currently applied to the presentation
497     // to enable restoring this state in case of failure.
498     // Refer to bugs IPAL8849, IPAL8850 for more information.
499     typedef vtkSmartPointer<vtkPlane> TPln;
500     typedef std::vector<TPln> TPlns;
501     bool isFailed = false;
502     TPlns anOldPlanes;
503     int iopl = 0, nbOldPlanes = myPrs3d->GetNumberOfClippingPlanes();
504     for (; iopl < nbOldPlanes; iopl++) {
505       anOldPlanes.push_back(myPrs3d->GetClippingPlane(iopl));
506     }
507
508     // Try to apply new clipping
509     myPrs3d->RemoveAllClippingPlanes();
510
511     VISU::TPlanes::iterator anIter = myPlanes.begin();
512     for (; anIter != myPlanes.end(); anIter++) {
513       OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
514       anOrientedPlane->ShallowCopy(anIter->GetPointer());
515       if (!myPrs3d->AddClippingPlane(anOrientedPlane)) {
516         isFailed = true;
517       }
518       anOrientedPlane->Delete();
519     }
520
521     // Check contents of the resulting (clipped) presentation data
522     if (!isFailed) {
523       VISU_PipeLine* aPL = myPrs3d->GetPipeLine();
524       vtkMapper* aMapper = aPL->GetMapper();
525       vtkDataSet* aPrsData = aMapper->GetInput();
526       aPrsData->Update();
527       if (aPrsData->GetNumberOfCells() < 1) {
528         isFailed = true;
529       }
530     }
531
532     if (isFailed) {
533       // Restore previous clipping state because of failure.
534       myPrs3d->RemoveAllClippingPlanes();
535
536       TPlns::iterator anOldIter = anOldPlanes.begin();
537       for (; anOldIter != anOldPlanes.end(); anOldIter++) {
538         myPrs3d->AddClippingPlane(anOldIter->GetPointer());
539       }
540
541       SUIT_MessageBox::warn1(VISU::GetDesktop(myVisuGUI),
542                              tr("WRN_VISU"),
543                              tr("WRN_EMPTY_RESULTING_PRS"),
544                              tr("BUT_OK") );
545     }
546
547     //VISU::RenderViewWindow(aViewWindow);
548     VISU::RepaintViewWindows(myVisuGUI, myIO);
549   }
550 }
551
552 //=================================================================================
553 // function : ClickOnOk()
554 // purpose  :
555 //=================================================================================
556 void VisuGUI_ClippingDlg::ClickOnOk()
557 {
558   ClickOnApply();
559   ClickOnCancel();
560 }
561
562 //=================================================================================
563 // function : ClickOnCancel()
564 // purpose  :
565 //=================================================================================
566 void VisuGUI_ClippingDlg::ClickOnCancel()
567 {
568   close();
569 }
570
571 //=================================================================================
572 // function : ClickOnHelp()
573 // purpose  :
574 //=================================================================================
575 void VisuGUI_ClippingDlg::ClickOnHelp()
576 {
577   QString aHelpFileName = "clipping_page.html";
578   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
579   if (app)
580     app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
581   else {
582     QString platform;
583 #ifdef WIN32
584     platform = "winapplication";
585 #else
586     platform = "application";
587 #endif
588     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
589                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
590                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
591                            QObject::tr("BUT_OK"));
592   }
593 }
594
595 //=================================================================================
596 // function : onSelectionChanged()
597 // purpose  : Called when selection is changed
598 //=================================================================================
599 void VisuGUI_ClippingDlg::onSelectionChanged()
600 {
601   if(SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI)){
602
603     VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(myVisuGUI);
604     if(aSelectionInfo.empty())
605       return;
606
607     VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
608     VISU::Base_i* aBase = aSelectionItem.myObjectInfo.myBase;
609     if(!aBase) 
610       return;
611   
612     Handle(SALOME_InteractiveObject) anIO = aSelectionItem.myIO;
613     if (!anIO.IsNull()) 
614       myIO = anIO;
615
616     SetPrs3d(dynamic_cast<VISU::Prs3d_i*>(aBase));
617     if (myPrs3d) {
618       std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false));
619       myPlanes.clear();
620
621       CORBA::Float anOffset[3];
622       myPrs3d->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
623
624       vtkIdType anId = 0, anEnd = myPrs3d->GetNumberOfClippingPlanes();
625       for (; anId < anEnd; anId++) {
626         if (vtkImplicitFunction* aFunction = myPrs3d->GetClippingPlane(anId)) {
627           if (OrientedPlane* aPlane = OrientedPlane::SafeDownCast(aFunction)) {
628             OrientedPlane* anOrientedPlane = OrientedPlane::New(aViewWindow);
629             VISU::TVTKPlane aTVTKPlane(anOrientedPlane);
630             anOrientedPlane->Delete();
631             aTVTKPlane->ShallowCopy(aPlane);
632             aTVTKPlane->myActor->SetPosition(anOffset[0],anOffset[1],anOffset[2]);
633             myPlanes.push_back(aTVTKPlane);
634           }
635         }
636       }
637
638       std::for_each(myPlanes.begin(),myPlanes.end(),
639                     TSetVisiblity(PreviewCheckBox->isChecked()));
640     }
641
642     // enable/disable IJK tab
643     TabPane->setTabEnabled(WidgetIJKTab, isStructured());
644     Sinchronize();
645     VISU::RenderViewWindow(aViewWindow);
646   }
647 }
648
649 //=================================================================================
650 // function : onSelectPlane()
651 // purpose  :
652 //=================================================================================
653 void VisuGUI_ClippingDlg::onSelectPlane(int theIndex)
654 {
655   if (!myPrs3d || myPlanes.empty())
656     return;
657
658   OrientedPlane* aPlane = myPlanes[theIndex].GetPointer();
659
660   // Orientation
661   VISU::Orientation anOrientation = aPlane->GetOrientation();
662
663   // Rotations
664   double aRot[2] = {aPlane->myAngle[0], aPlane->myAngle[1]};
665
666   // Set plane parameters in the dialog
667   myIsSelectPlane = true;
668   setDistance(aPlane->GetDistance());
669   setRotation(aRot[0], aRot[1]);
670   int item = 0;
671   switch (anOrientation) {
672   case VISU::XY: item = 0; break;
673   case VISU::YZ: item = 1; break;
674   case VISU::ZX: item = 2; break;
675   }
676   ComboBoxOrientation->setCurrentItem(item);
677
678   bool isIJK = (TabPane->currentPage() == WidgetIJKTab);
679   if (isIJK)
680     setIJKByNonStructured();
681   else
682     onSelectOrientation(item);
683
684   myIsSelectPlane = false;
685 }
686
687 //=================================================================================
688 // function : ClickOnNew()
689 // purpose  :
690 //=================================================================================
691 void VisuGUI_ClippingDlg::ClickOnNew()
692 {
693   VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(myVisuGUI);
694   if(aSelectionInfo.empty())
695     return;
696
697   const VISU::TSelectionItem& aSelectionItem = aSelectionInfo[0];
698   if(!aSelectionItem.myObjectInfo.myBase) 
699     return;
700
701   SetCurrentPlaneParam();
702   
703   if (!myPrs3d)
704     return;
705
706   if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI)) {
707     OrientedPlane* aPlane = OrientedPlane::New(aViewWindow);
708     VISU::TVTKPlane aTVTKPlane(aPlane);
709     myPlanes.push_back(aTVTKPlane);
710
711     CORBA::Float anOffset[3];
712     myPrs3d->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
713     aTVTKPlane->myActor->SetPosition(anOffset[0],anOffset[1],anOffset[2]);
714
715     if (PreviewCheckBox->isChecked())
716       aTVTKPlane->myActor->VisibilityOn();
717
718     Sinchronize();
719     SetCurrentPlaneParam();
720   }
721 }
722
723 //=================================================================================
724 // function : ClickOnDelete()
725 // purpose  :
726 //=================================================================================
727 void VisuGUI_ClippingDlg::ClickOnDelete()
728 {
729   if (!myPrs3d || myPlanes.empty())
730     return;
731
732   int aPlaneIndex = ComboBoxPlanes->currentItem();
733
734   VISU::TPlanes::iterator anIter = myPlanes.begin() + aPlaneIndex;
735   anIter->GetPointer()->myActor->SetVisibility(false);
736   myPlanes.erase(anIter);
737
738   if(AutoApplyCheckBox->isChecked())
739     ClickOnApply();
740
741   Sinchronize();
742   if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI))
743     VISU::RenderViewWindow(aViewWindow);
744 }
745
746 //=================================================================================
747 // function : onSelectOrientation()
748 // purpose  :
749 //=================================================================================
750 void VisuGUI_ClippingDlg::onSelectOrientation(int theItem)
751 {
752   if (myPlanes.empty())
753     return;
754
755   if      (theItem == 0) {
756     TextLabelRot1->setText(tr("LBL_ROTATION_YZ"));
757     TextLabelRot2->setText(tr("LBL_ROTATION_XZ"));
758   }
759   else if (theItem == 1) {
760     TextLabelRot1->setText(tr("LBL_ROTATION_ZX"));
761     TextLabelRot2->setText(tr("LBL_ROTATION_YX"));
762   }
763   else if (theItem == 2) {
764     TextLabelRot1->setText(tr("LBL_ROTATION_XY"));
765     TextLabelRot2->setText(tr("LBL_ROTATION_ZY"));
766   }
767
768   if((QComboBox*)sender() == ComboBoxOrientation)
769     SetCurrentPlaneParam();
770 }
771
772 //=================================================================================
773 // function : Sinchronize()
774 // purpose  : update control values according to plane selection
775 //=================================================================================
776 void VisuGUI_ClippingDlg::Sinchronize()
777 {
778   int aNbPlanes = myPlanes.size();
779   ComboBoxPlanes->clear();
780
781   QString aName;
782   for (int i = 1; i<=aNbPlanes; i++) {
783     aName = QString(tr("PLANES_COMBO_ITEM_i")).arg(i);
784     ComboBoxPlanes->insertItem(aName);
785   }
786
787   int aPos = ComboBoxPlanes->count() - 1;
788   ComboBoxPlanes->setCurrentItem(aPos);
789
790   bool anIsControlsEnable = (aPos >= 0);
791   if (anIsControlsEnable) {
792     onSelectPlane(aPos);
793   } else {
794     ComboBoxPlanes->insertItem(tr("PLANES_COMBO_ITEM_no"));
795     SpinBoxRot1->setValue(0.0);
796     SpinBoxRot2->setValue(0.0);
797     SpinBoxDistance->setValue(0.5);
798   }
799
800   buttonDelete           ->setEnabled(anIsControlsEnable);
801   buttonApply            ->setEnabled(anIsControlsEnable);
802   PreviewCheckBox        ->setEnabled(anIsControlsEnable);
803   AutoApplyCheckBox      ->setEnabled(anIsControlsEnable);
804
805   ComboBoxOrientation    ->setEnabled(anIsControlsEnable);
806   SpinBoxDistance        ->setEnabled(anIsControlsEnable);
807   SpinBoxRot1            ->setEnabled(anIsControlsEnable);
808   SpinBoxRot2            ->setEnabled(anIsControlsEnable);
809
810   ButtonGroupIJKAxis     ->setEnabled(anIsControlsEnable);
811   SpinBoxIJKIndex        ->setEnabled(anIsControlsEnable);
812   CheckBoxIJKPlaneReverse->setEnabled(anIsControlsEnable);
813   //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
814   if(myPrs3d){
815     VISU_PipeLine* aPipeLine = myPrs3d->GetPipeLine();
816     VISU::PIDMapper anIDMapper = aPipeLine->GetIDMapper();
817     if(anIDMapper->IsStructured()){
818       VISU::TIdTypeVector aVec = anIDMapper->GetStructure();
819       switch(aVec.size()){
820       case 1:
821         ButtonGroupIJKAxis->find(0)->setEnabled(true);
822         ButtonGroupIJKAxis->find(1)->setEnabled(false);
823         ButtonGroupIJKAxis->find(2)->setEnabled(false);
824         break;
825       case 2:
826         ButtonGroupIJKAxis->find(0)->setEnabled(true);
827         ButtonGroupIJKAxis->find(1)->setEnabled(true);
828         ButtonGroupIJKAxis->find(2)->setEnabled(false);
829         break;
830       case 3:
831         ButtonGroupIJKAxis->find(0)->setEnabled(true);
832         ButtonGroupIJKAxis->find(1)->setEnabled(true);
833         ButtonGroupIJKAxis->find(2)->setEnabled(true);
834         break;
835       }
836     }
837   }
838   //ENK: 23.11.2006
839 }
840
841 //=================================================================================
842 // function : setRotation()
843 // purpose  :
844 //=================================================================================
845 void VisuGUI_ClippingDlg::setRotation(const double theRot1, const double theRot2)
846 {
847   SpinBoxRot1->setValue(theRot1);
848   SpinBoxRot2->setValue(theRot2);
849 }
850
851 //=================================================================================
852 // function : SetCurrentPlaneParam()
853 // purpose  :
854 //=================================================================================
855 void VisuGUI_ClippingDlg::SetCurrentPlaneParam()
856 {
857   if (myPlanes.empty() || myIsSelectPlane)
858     return;
859
860   int aCurPlaneIndex = ComboBoxPlanes->currentItem();
861
862   OrientedPlane* aPlane = myPlanes[aCurPlaneIndex].GetPointer();
863
864   vtkFloatingPointType aNormal[3];
865   VISU::Orientation anOrientation;
866   vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
867   {
868     static double aCoeff = vtkMath::Pi()/180.0;
869
870     vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
871     aPlane->myAngle[0] = aRot[0];
872     aPlane->myAngle[1] = aRot[1];
873
874     vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
875     vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
876     aV[0] = aRot[0] > 0? aV[0]: -aV[0];
877     aV[1] = aRot[1] > 0? aV[1]: -aV[1];
878
879     switch (ComboBoxOrientation->currentItem()) {
880     case 0:
881       anOrientation = VISU::XY;
882
883       aDir[0][1] = anU[0];
884       aDir[0][2] = aV[0];
885
886       aDir[1][0] = anU[1];
887       aDir[1][2] = aV[1];
888
889       break;
890     case 1:
891       anOrientation = VISU::YZ;
892
893       aDir[0][2] = anU[0];
894       aDir[0][0] = aV[0];
895
896       aDir[1][1] = anU[1];
897       aDir[1][0] = aV[1];
898
899       break;
900     case 2:
901       anOrientation = VISU::ZX;
902
903       aDir[0][0] = anU[0];
904       aDir[0][1] = aV[0];
905
906       aDir[1][2] = anU[1];
907       aDir[1][1] = aV[1];
908
909       break;
910     }
911
912     vtkMath::Cross(aDir[1],aDir[0],aNormal);
913     vtkMath::Normalize(aNormal);
914     vtkMath::Cross(aNormal,aDir[1],aDir[0]);
915   }
916
917   aPlane->SetOrientation(anOrientation);
918   aPlane->SetDistance(getDistance());
919
920   myPrs3d->SetPlaneParam(aNormal, 1. - getDistance(), aPlane);
921
922   vtkDataSet* aDataSet = myPrs3d->GetInput();
923   vtkFloatingPointType *aPnt = aDataSet->GetCenter();
924
925   vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
926   vtkFloatingPointType aDel = aDataSet->GetLength()/2.0;
927
928   vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
929                                        {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
930   vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
931
932   vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
933                                     aPnt[1] - aDelta[0][1] - aDelta[1][1],
934                                     aPnt[2] - aDelta[0][2] - aDelta[1][2]};
935   vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
936                                     aPnt01[1] + aNormal[1],
937                                     aPnt01[2] + aNormal[2]};
938   vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
939
940   vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
941                                     aPnt[1] - aDelta[0][1] + aDelta[1][1],
942                                     aPnt[2] - aDelta[0][2] + aDelta[1][2]};
943   vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
944                                     aPnt11[1] + aNormal[1],
945                                     aPnt11[2] + aNormal[2]};
946   vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
947
948   vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
949                                     aPnt[1] + aDelta[0][1] - aDelta[1][1],
950                                     aPnt[2] + aDelta[0][2] - aDelta[1][2]};
951   vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
952                                     aPnt21[1] + aNormal[1],
953                                     aPnt21[2] + aNormal[2]};
954   vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
955
956   vtkPlaneSource* aPlaneSource = aPlane->myPlaneSource;
957   aPlaneSource->SetNormal(aNormal[0],aNormal[1],aNormal[2]);
958   aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
959   aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
960   aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
961
962   if (AutoApplyCheckBox->isChecked())
963     ClickOnApply();
964
965   if (SVTK_ViewWindow* vw = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI))
966     VISU::RenderViewWindow(vw);
967 }
968
969 //=================================================================================
970 // function : onTabChanged
971 // purpose  :
972 //=================================================================================
973 void VisuGUI_ClippingDlg::onTabChanged(QWidget* newTab)
974 {
975   if (newTab == WidgetIJKTab) // IJK
976     setIJKByNonStructured();
977   else {
978     // set correct labels of rotation spin boxes
979     onSelectOrientation(ComboBoxOrientation->currentItem());
980   }
981 }
982
983 //=================================================================================
984 // function : SetCurrentPlaneIJKParam
985 // purpose  : set non structured parameters by IJK parameters
986 //=================================================================================
987 void VisuGUI_ClippingDlg::SetCurrentPlaneIJKParam()
988 {
989   if (myPlanes.empty() || myIsSelectPlane || !WidgetIJKTab->isEnabled())
990     return;
991
992   VISU::Result_i* result = myPrs3d ? myPrs3d->GetCResult() : 0;
993   if (!result)
994     return;
995
996   // get axis data
997   int i, axId = ButtonGroupIJKAxis->id (ButtonGroupIJKAxis->selected());
998   VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axId;
999   gp_Dir dir;
1000   CORBA::String_var aMeshName = myPrs3d->GetMeshName();
1001   const vector<vtkFloatingPointType> * values =
1002     result->GetAxisInfo(aMeshName.in(), axis, dir);
1003   if (!values)
1004     return;
1005
1006   // find distance;
1007   int index = SpinBoxIJKIndex->value();
1008   vtkFloatingPointType distance = 0;
1009   if (index < values->size())
1010     distance = (*values)[ index ];
1011
1012   // find id of axis closest to dir
1013   // 0  || X-Y - axis Z
1014   // 1  || Y-Z - azis X
1015   // 2  || Z-X - axiz Y
1016   double cos[3] = { gp::DZ() * dir, gp::DX() * dir, gp::DY() * dir };
1017   double maxCos = 0;
1018   for (i = 0; i < 3; ++i) {
1019     if (Abs(cos[ i ]) > Abs (maxCos)) {
1020       maxCos = cos[ i ];
1021       axId = i;
1022     }
1023   }
1024   // find rotation angles
1025   vtkFloatingPointType angle[2];
1026   int rotId[2] = {
1027     (axId == 0) ? 2 : axId - 1,
1028     (axId == 2) ? 0 : axId + 1
1029     };
1030   static double aCoeff = 180.0/vtkMath::Pi();
1031   for (i = 0; i < 2; ++i) {
1032     vtkFloatingPointType cosin = cos[ rotId[ i ]];
1033 //     if (maxCos < 0)
1034 //       cosin = -cosin;
1035     angle[ i ] = asin(cosin) * aCoeff;
1036 //     if (maxCos < 0)
1037 //       angle[ i ] += 180. * (angle[ i ] < 0 ? 1. : -1.);
1038   }
1039   if (CheckBoxIJKPlaneReverse->isChecked()) {
1040     angle[ 0 ] += 180. * (angle[ 0 ] < 0 ? 1. : -1.);
1041     distance = 1. - distance;
1042   }
1043 //   if (maxCos < 0)
1044 //     distance = 1. - distance;
1045
1046   // set paramerets
1047   myIsSelectPlane = true;
1048   ComboBoxOrientation->setCurrentItem(axId);
1049   setRotation(-angle[0], -angle[1]);
1050   setDistance(distance);
1051   myIsSelectPlane = false;
1052
1053   SetCurrentPlaneParam();
1054 }
1055
1056 //=================================================================================
1057 // function : setIJKByNonStructured
1058 // purpose  : convert current non structured parameters to structured ones
1059 //=================================================================================
1060 void VisuGUI_ClippingDlg::setIJKByNonStructured()
1061 {
1062   if (!myPrs3d || myPlanes.empty() || !myPrs3d->GetCResult())
1063     return;
1064
1065   // get plane normal
1066   int planeIndex = ComboBoxPlanes->currentItem();
1067   OrientedPlane* plane = myPlanes[ planeIndex ].GetPointer();
1068   vtkPlaneSource* planeSource = plane->myPlaneSource;
1069   vtkFloatingPointType * planeNormal = planeSource->GetNormal();
1070   gp_Dir normal(planeNormal[0], planeNormal[1], planeNormal[2]);
1071
1072   // find a grid axis most co-directed with plane normal
1073   // and cartesian axis most co-directed with plane normal
1074   int i, maxAx = 0, gridAxId = 0;
1075   gp_Dir dir, gridDir;
1076   double maxDot = 0;
1077   const vector<vtkFloatingPointType> *curValues, *values = 0;
1078   VISU::Result_i* result = myPrs3d->GetCResult();
1079   int aNbAxes = 3;
1080   VISU_PipeLine* aPipeLine = myPrs3d->GetPipeLine();
1081   VISU::PIDMapper anIDMapper = aPipeLine->GetIDMapper();
1082   if(anIDMapper->IsStructured() && !anIDMapper->myType)
1083     aNbAxes = (anIDMapper->GetStructure()).size();
1084   for (i = 0; i < aNbAxes; ++i) {
1085     VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) i;
1086     CORBA::String_var aMeshName = myPrs3d->GetMeshName();
1087     curValues = result->GetAxisInfo(aMeshName.in(), axis, dir);
1088     if (curValues) {
1089       double dot = normal * dir;
1090       //ENK: 23.11.2006 - PAL13176
1091       if(i==0){
1092         maxDot = dot;
1093         gridDir = dir;
1094         values = curValues;
1095         gridAxId = i;
1096       } else if (Abs(dot) >= Abs(maxDot)) {
1097         maxDot = dot;
1098         gridDir = dir;
1099         values = curValues;
1100         gridAxId = i;
1101       }
1102       //ENK: 23.11.2006
1103     }
1104     if (Abs (planeNormal[ maxAx ]) < Abs (planeNormal[ i ]))
1105       maxAx = i;
1106   }
1107   gp_XYZ axDir(0,0,0);
1108   axDir.SetCoord(maxAx + 1, 1.);
1109
1110   // find index value
1111   double v = SpinBoxDistance->value();
1112   // reverse value?
1113 //   bool reverse = (normal * axDir < 0); // normal and axis are opposite
1114 //   if (gridDir * axDir < 0) // grid dir and axis are opposite
1115 //     reverse = !reverse;
1116 //   if (reverse)
1117 //     v = 1. - v;
1118   for (i = 0; i < values->size(); ++i)
1119     if ((*values)[ i ] > v)
1120       break;
1121   if (i == values->size())
1122     --i;
1123   if (i != 0 && (*values)[ i ] - v > v - (*values)[ i - 1])
1124     --i;
1125
1126   // set control values
1127   myIsSelectPlane = true;
1128   CheckBoxIJKPlaneReverse->setChecked(normal * axDir < 0);
1129   SpinBoxIJKIndex->setValue(i);
1130   ButtonGroupIJKAxis->setButton(gridAxId);
1131   onIJKAxisChanged(gridAxId); // update label and range of index
1132   myIsSelectPlane = false;
1133
1134   SetCurrentPlaneIJKParam();
1135 }
1136
1137 //=================================================================================
1138 // function : isStructured
1139 // purpose  : return true if mesh is structured
1140 //=================================================================================
1141 bool VisuGUI_ClippingDlg::isStructured() const
1142 {
1143   VISU::Result_i* result = myPrs3d ? myPrs3d->GetCResult() : 0;
1144   if (result) {
1145     gp_Dir dir;
1146     return result->GetAxisInfo(myPrs3d->GetCMeshName(),
1147                                VISU::Result_i::AXIS_X,
1148                                dir);
1149   }
1150   return false;
1151 }
1152
1153 //=================================================================================
1154 // function : onIJKAxisChanged
1155 // purpose  : update Index range and call SetCurrentPlaneParam()
1156 //=================================================================================
1157 void VisuGUI_ClippingDlg::onIJKAxisChanged(int axisId)
1158 {
1159   // set index range
1160   int maxIndex = 0;
1161   VISU::Result_i* result = myPrs3d ? myPrs3d->GetCResult() : 0;
1162   if (result) {
1163     VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) axisId;
1164     gp_Dir dir;
1165     CORBA::String_var aMeshName = myPrs3d->GetMeshName();
1166     const vector<vtkFloatingPointType> * indices = result->GetAxisInfo(aMeshName.in(),
1167                                                                        axis, dir);
1168     if (indices)
1169       maxIndex = indices->size() - 1;
1170   }
1171   QString text = tr("LBL_IJK_INDEX_TO_arg").arg(maxIndex);
1172   TextLabelIJKIndex->setText(text);
1173   SpinBoxIJKIndex->setRange(0, maxIndex);
1174
1175   if (SpinBoxIJKIndex->value() > maxIndex)
1176     SpinBoxIJKIndex->setValue(0);
1177
1178   SetCurrentPlaneIJKParam();
1179 }
1180
1181 //=================================================================================
1182 // function : OnPreviewToggle()
1183 // purpose  :
1184 //=================================================================================
1185 void VisuGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled)
1186 {
1187   std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled));
1188   if (SVTK_ViewWindow* vw = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI))
1189     VISU::RenderViewWindow(vw);
1190 }
1191
1192
1193 //=================================================================================
1194 // function : keyPressEvent()
1195 // purpose  :
1196 //=================================================================================
1197 void VisuGUI_ClippingDlg::keyPressEvent( QKeyEvent* e )
1198 {
1199   QDialog::keyPressEvent( e );
1200   if ( e->isAccepted() )
1201     return;
1202
1203   if ( e->key() == Key_F1 )
1204     {
1205       e->accept();
1206       ClickOnHelp();
1207     }
1208 }
1209
1210 void VisuGUI_ClippingDlg::SetPrs3d(VISU::Prs3d_i* thePrs)
1211 {
1212   if(thePrs != myPrs3d){
1213     if(myPrs3d)
1214       myPrs3d->Destroy();
1215     if(thePrs)
1216       thePrs->Register();
1217     myPrs3d = thePrs;
1218   } else 
1219     return;
1220 }