Salome HOME
Merge with branch V2_2_0_VISU_improvement
[modules/visu.git] / src / VISUGUI / VisuGUI_CutLinesDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : VisuGUI_CutLinesDlg.cxx
8 //  Author : VSV
9 //  Module : VISU
10
11 #include "VisuGUI_CutLinesDlg.h"
12
13 #include "VisuGUI.h"
14 #include "VisuGUI_Tools.h"
15
16 #include "VISU_Gen_i.hh"
17 #include "VISU_CutLines_i.hh"
18
19 #include "VISU_PipeLine.hxx"
20 #include "VISU_CutLinesPL.hxx"
21
22 #include "SVTK_ViewWindow.h"
23
24 #include "SalomeApp_Application.h"
25 #include "SalomeApp_Study.h"
26
27 #include "SUIT_Desktop.h"
28
29 #include "OB_Browser.h"
30
31 #include <qlayout.h>
32 #include <qhbox.h>
33 #include <qtabwidget.h>
34 #include <qhgroupbox.h>
35
36 #include <vtkRenderer.h>
37 #include <vtkPolyData.h>
38 #include <vtkAppendPolyData.h>
39 #include <vtkDataSetMapper.h>
40
41 using namespace std;
42
43 //extern VisuGUI *visuGUI;
44
45 //#define GET_VTK_VIEWWINDOW(aMgr) dynamic_cast<VTKViewer_ViewWindow*>(aMgr->getActiveView())
46
47 bool VisuGUI_CutLinesDlg::MYGenerateTable = true;
48 bool VisuGUI_CutLinesDlg::MYGenerateCurve = true;
49
50 //SalomeApp_Study* study()
51 //{
52 //  return dynamic_cast<SalomeApp_Study*>(VisuGUI::application()->activeStudy());
53 //}
54
55 VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (QWidget* parent, bool theIsCreation, bool theIsModal)
56      : QDialog(parent, "VisuGUI_CutLinesDlg", theIsModal, WStyle_Customize |
57                WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
58        myPreviewActor(0)
59        //,myMgr(VisuGUI::application()->activeViewManager())
60 {
61   //myStudyWnd = myMgr->getActiveView();
62   if (!theIsModal) {
63     setWFlags(getWFlags() | WDestructiveClose);
64   }
65   setCaption("Cut Lines Definition");
66   setSizeGripEnabled(true);
67   myIsCreation = theIsCreation;
68
69   QVBoxLayout* aMainLayout = new QVBoxLayout (this, 7, 6);
70   aMainLayout->setSpacing(5);
71
72   hasInit = false;
73
74   // Tab pane
75   QTabWidget* aTabPane = new QTabWidget(this);
76
77   // Plane of lines
78   QFrame* aPlanePane = new QFrame(this);
79   QVBoxLayout* aPlaneLayout = new QVBoxLayout(aPlanePane, 5, 6);
80
81   mySelPlane = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aPlanePane);
82   mySelPlane->setInsideSpacing( 5 );
83   mySelPlane->setInsideMargin( 5 );
84
85   QRadioButton* aBxy = new QRadioButton( tr( "PARALLEL_XOY" ), mySelPlane);  // 0
86   QRadioButton* aByz = new QRadioButton( tr( "PARALLEL_YOZ" ), mySelPlane);  // 1
87   QRadioButton* aBzx = new QRadioButton( tr( "PARALLEL_ZOX" ), mySelPlane);  // 2
88   aBzx->setChecked(true);
89
90   aPlaneLayout->addWidget( mySelPlane );
91
92   QGroupBox* aRotBox = new QGroupBox( tr( "LBL_ROTATION" ), aPlanePane );
93   aRotBox->setColumnLayout(2, Qt::Horizontal );
94
95   myRotXLbl = new QLabel( tr( "LBL_ROT_X" ), aRotBox);
96   myRotXSpn = new QtxDblSpinBox( -45, 45, 5, aRotBox );
97   myRotXSpn->setValue( 0 );
98   myRotYLbl = new QLabel( tr( "LBL_ROT_Y" ), aRotBox );
99   myRotYSpn = new QtxDblSpinBox( -45, 45, 5, aRotBox );
100   myRotYSpn->setValue( 0 );
101
102   aPlaneLayout->addWidget( aRotBox );
103
104   QHGroupBox* aBaseBox = new QHGroupBox (tr("BASE_PLANE_POS"), aPlanePane);
105   myBasePlanePos = new QLineEdit (aBaseBox);
106   mydvalidator = new QDoubleValidator(this);
107   mydvalidator->setDecimals(32);
108   myBasePlanePos->setValidator(mydvalidator);
109
110   myCBSetDef = new QCheckBox (tr("SET_DEFAULT"),aBaseBox);
111
112   aPlaneLayout->addWidget(aBaseBox);
113
114   QHBox* aPosBox = new QHBox (aPlanePane);
115   aPosBox->setSpacing(5);
116   QLabel* aPosLbl = new QLabel (tr("LBL_POS"), aPosBox);
117   myPosSpn = new QtxDblSpinBox (0, 1, 0.1, aPosBox);
118   myPosSpn->setValue(0.5);
119   aPlaneLayout->addWidget(aPosBox);
120
121   myPreviewCheck = new QCheckBox (tr("LBL_SHOW_PREVIEW"), aPlanePane);
122   myPreviewCheck->setChecked(false);
123   aPlaneLayout->addWidget(myPreviewCheck);
124
125   myCreateTable = new QCheckBox (tr("LBL_GENERATE_TABLE"), aPlanePane);
126   myCreateTable->setChecked(MYGenerateTable);
127   aPlaneLayout->addWidget( myCreateTable );
128
129   QHBox* aCheckPane = new QHBox(aPlanePane);
130   QLabel* aLbl = new QLabel("   ", aCheckPane);
131   aCheckPane->setStretchFactor(aLbl, 0);
132   myCurvesCheck = new QCheckBox(tr("LBL_GENERATE_CURVES"), aCheckPane);
133   aCheckPane->setStretchFactor(aCheckPane, 0);
134   myCurvesCheck->setChecked(MYGenerateCurve);
135   myCurvesCheck->setEnabled(MYGenerateTable);
136   QLabel* aLbl2 = new QLabel("   ", aCheckPane);
137   aCheckPane->setStretchFactor(aLbl2, 1);
138   aPlaneLayout->addWidget( aCheckPane );
139
140   aPlaneLayout->addStretch();
141
142
143   aTabPane->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
144
145   // Number of lines
146   QFrame* aLinesPane = new QFrame(this);
147   QVBoxLayout* aLinesLayout = new QVBoxLayout( aLinesPane, 5, 6 );
148
149   mySelPlane2 = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aLinesPane);
150   mySelPlane2->setInsideSpacing( 5 );
151   mySelPlane2->setInsideMargin( 5 );
152
153   QRadioButton* aBxy2 = new QRadioButton( tr( "PARALLEL_XOY" ), mySelPlane2);  // 0
154   QRadioButton* aByz2 = new QRadioButton( tr( "PARALLEL_YOZ" ), mySelPlane2);  // 1
155   QRadioButton* aBzx2 = new QRadioButton( tr( "PARALLEL_ZOX" ), mySelPlane2);  // 2
156   aBzx2->setEnabled(false);
157   aByz2->setChecked(true);
158   aLinesLayout->addWidget( mySelPlane2 );
159
160   QGroupBox* aRotBox2 = new QGroupBox( tr( "LBL_ROTATION" ), aLinesPane );
161   aRotBox2->setColumnLayout(2, Qt::Horizontal );
162
163   myRotXLbl2 = new QLabel( tr( "LBL_ROT_X" ), aRotBox2);
164   myRotXSpn2 = new QtxDblSpinBox( -45, 45, 5, aRotBox2 );
165   myRotXSpn2->setValue( 0 );
166   myRotYLbl2 = new QLabel( tr( "LBL_ROT_Y" ), aRotBox2 );
167   myRotYSpn2 = new QtxDblSpinBox( -45, 45, 5, aRotBox2 );
168   myRotYSpn2->setValue( 0 );
169   aLinesLayout->addWidget( aRotBox2 );
170
171   QHBox* aNbBox = new QHBox(aLinesPane);
172   aNbBox->setSpacing(5);
173   QLabel* aNbLbl = new QLabel( tr( "LBL_NB_PLANS" ), aNbBox );
174   myNbSpn = new QtxDblSpinBox( 1, 100, 1, aNbBox );
175   myNbSpn->setValue( 10 );
176
177   aLinesLayout->addWidget( aNbBox );
178
179   myPosTable = new QTable(aLinesPane, "Positions of cut planes" );
180   myPosTable->setMaximumHeight( 227 );
181   myPosTable->setMinimumWidth( 294 );
182   myPosTable->setNumCols(2);
183   myPosTable->setNumRows(0);
184
185   QHeader *th = myPosTable->horizontalHeader();
186   th->setLabel( 0, "Position" );
187   th->setLabel( 1, "Set default" );
188
189   aLinesLayout->addWidget( myPosTable );
190
191   QHBox* aPosBox2 = new QHBox(aLinesPane);
192   aPosBox2->setSpacing(5);
193   QLabel* aPosLbl2 = new QLabel( tr( "LBL_POS" ), aPosBox2 );
194   myPosSpn2 = new QtxDblSpinBox( 0, 1, 0.1, aPosBox2 );
195   myPosSpn2->setValue( 0.5 );
196   aLinesLayout->addWidget( aPosBox2 );
197   aLinesLayout->addStretch();
198
199   aTabPane->addTab( aLinesPane, tr("LBL_LINES_CUT") );
200
201   myScalarPane = new VisuGUI_ScalarBarPane(this, false);
202   myScalarPane->setMargin( 5 );
203   aTabPane->addTab(myScalarPane, "Scalar Bar");
204
205   aMainLayout->addWidget(aTabPane);
206
207   // Dialog buttons
208   QHBox* aBtnBox = new QHBox(this);
209   aBtnBox->setFrameStyle(QFrame::Box | QFrame::Sunken);
210   aBtnBox->setLineWidth( 1 );
211   QHBoxLayout* aBtnLayout = (QHBoxLayout*) aBtnBox->layout();
212   aBtnLayout->setAutoAdd( false );
213   aBtnLayout->setSpacing( 5 );
214   aBtnLayout->setMargin( 11 );
215
216   QPushButton* aOkBtn = new QPushButton (tr("BUT_OK"), aBtnBox);
217   aOkBtn->setAutoDefault( TRUE );
218   aOkBtn->setDefault( true );
219   aBtnLayout->addWidget(aOkBtn);
220
221   aBtnLayout->addStretch();
222
223   QPushButton* aCloseBtn = new QPushButton(tr("BUT_CANCEL"), aBtnBox);
224   aBtnLayout->addWidget(aCloseBtn);
225
226   aMainLayout->addWidget(aBtnBox);
227
228   myCutLines = NULL;
229
230   // signals and slots connections
231   connect(mySelPlane    , SIGNAL(clicked(int))          , this, SLOT(onPlaneSelect(int)));
232   connect(myCBSetDef    , SIGNAL(toggled(bool))         , this, SLOT(setBaseDefault()));
233   connect(myPosSpn      , SIGNAL(valueChanged(double))  , this, SLOT(setBaseDefault()));
234   connect(mySelPlane2   , SIGNAL(clicked(int))          , this, SLOT(onCutSelect(int)));
235   connect(myNbSpn       , SIGNAL(valueChanged(double))  , this, SLOT(DrawTable()));
236   connect(th            , SIGNAL(clicked(int))          , this, SLOT(setDefault(int)));
237   connect(myPosSpn2     , SIGNAL(valueChanged(double))  , this, SLOT(DrawTable()));
238   connect(myPreviewCheck, SIGNAL(toggled(bool))         , this, SLOT(onPreviewCheck(bool)));
239   connect(myPosTable    , SIGNAL(valueChanged(int, int)), this, SLOT(onValueChanged(int, int)));
240   connect(myRotXSpn     , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
241   connect(myRotYSpn     , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
242   connect(myRotXSpn2    , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
243   connect(myRotYSpn2    , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
244   connect(myBasePlanePos, SIGNAL(textChanged(const QString&)), this, SLOT(onPlanePos(const QString&)));
245   connect(myCreateTable , SIGNAL(toggled(bool)), myCurvesCheck, SLOT(setEnabled(bool)));
246
247   connect(aOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
248   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
249   //connect(myMgr, SIGNAL(closeAllViews()), this, SLOT(reject()));
250   //connect(VisuGUI::application()->desktop(),
251   //        SIGNAL(windowActivated(SUIT_ViewWindow*)),
252   //        this, SLOT(onWindowActivated(SUIT_ViewWindow*)));
253 }
254
255 /*!
256   Destructor
257 */
258 VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg()
259 {
260   cout<<"### VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg"<<endl;
261   deletePlanes();
262   if (myCutLines) //delete myCutLines;
263     myCutLines->Destroy();
264   if (SVTK_ViewWindow* vf = VISU::GetViewWindow())
265     vf->Repaint();
266 }
267
268 //------------------------------------------------------------------------------
269 void VisuGUI_CutLinesDlg::initFromPrsObject (VISU::CutLines_i* thePrs)
270 {
271   myPrs = thePrs;
272   myScalarPane->initFromPrsObject(thePrs);
273
274   myRotXSpn->setValue(thePrs->GetRotateX()*180./PI);
275   myRotYSpn->setValue(thePrs->GetRotateY()*180./PI);
276   myPosSpn->setValue(thePrs->GetDisplacement());
277   setOrientation(thePrs->GetOrientationType());
278
279   myNbSpn->setValue( (int)thePrs->GetNbLines() );
280   myRotXSpn2->setValue(thePrs->GetRotateX2()*180./PI);
281   myRotYSpn2->setValue(thePrs->GetRotateY2()*180./PI);
282   myPosSpn2->setValue(thePrs->GetDisplacement2());
283   setOrientation2(thePrs->GetOrientationType2());
284
285   hasInit = true;
286   myCutLines = new VISU::CutLines_i(thePrs->GetResult(),false);
287   myCutLines->SameAs(thePrs);
288   myBasePlanePos->setText( QString::number(myCutLines->GetBasePlanePosition()) );
289   myCBSetDef->setChecked(thePrs->IsDefault());
290   DrawTable();
291
292   // Draw Preview
293   if (myPreviewCheck->isChecked()) {
294     createPlanes();
295   }
296 }
297
298 //------------------------------------------------------------------------------
299 int VisuGUI_CutLinesDlg::storeToPrsObject (VISU::CutLines_i* thePrs)
300 {
301   myScalarPane->storeToPrsObject(thePrs);
302
303   thePrs->SetOrientation(getOrientaion(),
304                          myRotXSpn->value()*PI/180.,
305                          myRotYSpn->value()*PI/180.);
306   thePrs->SetDisplacement(myPosSpn->value());
307   thePrs->SetNbLines((int)myNbSpn->value());
308
309   thePrs->SetOrientation2(getOrientaion(false),
310                           myRotXSpn2->value()*PI/180.,
311                           myRotYSpn2->value()*PI/180.);
312   thePrs->SetDisplacement2(myPosSpn2->value());
313
314   if (!myCBSetDef->isChecked())
315     thePrs->SetBasePlanePosition(myBasePlanePos->text().toDouble());
316   else thePrs->SetDefault();
317
318   for (int i = 0; i < (int)myNbSpn->value(); ++i) {
319     if (!((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked())
320       thePrs->SetLinePosition( i, myPosTable->text( i, 0 ).toDouble() );
321     else thePrs->SetDefaultPosition(i);
322   }
323   return 1;
324 }
325
326 //------------------------------------------------------------------------------
327 void VisuGUI_CutLinesDlg::createPlanes()
328 {
329   SVTK_ViewWindow* aView = VISU::GetViewWindow();
330   if (aView == NULL) return;
331   if (myCutLines == NULL) return;
332   if (myPreviewActor != 0) return;
333
334   storeToPrsObject(myCutLines);
335   myCutLines->GetPL()->Update();
336   vtkAppendPolyData* aPolyData = myCutLines->GetCutLinesPL()->GetAppendPolyData();
337   vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
338   aPlaneMapper->SetInput(aPolyData->GetOutput());
339   aPlaneMapper->ScalarVisibilityOff();
340
341   myPreviewActor = SALOME_Actor::New();
342   myPreviewActor->PickableOff();
343   myPreviewActor->SetMapper(aPlaneMapper);
344   aPlaneMapper->Delete();
345   aView->AddActor(myPreviewActor);
346   aView->getRenderer()->Render();
347   aView->onFitAll();
348 }
349
350 //------------------------------------------------------------------------------
351 void VisuGUI_CutLinesDlg::deletePlanes()
352 {
353   if (myPreviewActor == 0) return;
354   if (SVTK_ViewWindow* aView = VISU::GetViewWindow())
355     aView->RemoveActor(myPreviewActor);
356   myPreviewActor->Delete();
357   myPreviewActor = 0;
358 }
359
360
361 //------------------------------------------------------------------------------
362 void VisuGUI_CutLinesDlg::onPlaneSelect (int theId)
363 {
364   for (int i = 0; i < mySelPlane2->count(); i++)
365     mySelPlane2->find(i)->setEnabled(true);
366   QButton* aBtn = mySelPlane2->find(theId);
367   aBtn->setEnabled(false);
368   switch (theId) {
369   case 0:
370     myRotXLbl->setText( tr("LBL_ROT_X"));
371     myRotYLbl->setText( tr("LBL_ROT_Y"));
372     ((QRadioButton*)mySelPlane2->find(1))->setChecked(true);
373     onCutSelect(1, false);
374     break;
375   case 1:
376     myRotXLbl->setText( tr("LBL_ROT_Y"));
377     myRotYLbl->setText( tr("LBL_ROT_Z"));
378     ((QRadioButton*)mySelPlane2->find(2))->setChecked(true);
379     onCutSelect(2, false);
380     break;
381   case 2:
382     myRotXLbl->setText( tr("LBL_ROT_Z"));
383     myRotYLbl->setText( tr("LBL_ROT_X"));
384     ((QRadioButton*)mySelPlane2->find(0))->setChecked(true);
385     onCutSelect(0, false);
386   }
387   setBaseDefault(false);
388   DrawTable();
389 }
390
391 //------------------------------------------------------------------------------
392 void VisuGUI_CutLinesDlg::onCutSelect (int theId, bool theUpdate)
393 {
394   switch (theId) {
395   case 0:
396     myRotXLbl2->setText( tr("LBL_ROT_X"));
397     myRotYLbl2->setText( tr("LBL_ROT_Y"));
398     break;
399   case 1:
400     myRotXLbl2->setText( tr("LBL_ROT_Y"));
401     myRotYLbl2->setText( tr("LBL_ROT_Z"));
402     break;
403   case 2:
404     myRotXLbl2->setText( tr("LBL_ROT_Z"));
405     myRotYLbl2->setText( tr("LBL_ROT_X"));
406   }
407   if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) {
408     if (theUpdate && myPreviewCheck->isChecked() && (myCutLines != NULL)) {
409       /*myCutLines->SetOrientation2(getOrientaion(false),
410                                   myRotXSpn2->value()*PI/180.,
411                                   myRotYSpn2->value()*PI/180.);
412                                   myCutLines->SetDisplacement2(myPosSpn2->value());*/
413       //myCutLines->GetPL()->Update();
414       deletePlanes();
415       createPlanes();
416       //aView->Repaint();
417     }
418   }
419 }
420
421 //------------------------------------------------------------------------------
422 void VisuGUI_CutLinesDlg::setBaseDefault (bool theUpdate)
423 {
424   if (!hasInit) return;
425
426   if (myCBSetDef->isChecked()) {
427     if (!myCutLines->IsDefault()) myCutLines->SetDefault();
428     /*myCutLines->SetOrientation(getOrientaion(),
429                                myRotXSpn->value()*PI/180.,
430                                myRotYSpn->value()*PI/180.);
431                                myCutLines->SetDisplacement(myPosSpn->value());*/
432     /*    float aPos = myCutLines->GetBasePlanePosition();
433     myBasePlanePos->setText( QString::number(aPos) );
434     myBasePlanePos->setEnabled(false);*/
435     if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) {
436       if (theUpdate && myPreviewCheck->isChecked() && (myCutLines != NULL)) {
437         //myCutLines->SetBasePlanePosition(aPos);
438         //        myCutLines->GetPL()->Update();
439         deletePlanes();
440         createPlanes();
441         //aView->Repaint();
442       }
443     }
444     float aPos = myCutLines->GetBasePlanePosition();
445     myBasePlanePos->setText( QString::number(aPos) );
446     myBasePlanePos->setEnabled(false);
447   } else {
448     myBasePlanePos->setEnabled(true);
449   }
450 }
451
452 //------------------------------------------------------------------------------
453 void VisuGUI_CutLinesDlg::DrawTable()
454 {
455   if (!hasInit) return;
456
457   int aNbRows = myPosTable->numRows();
458   int aNbPlanes = (int)myNbSpn->value();
459
460   myCutLines->SetOrientation(getOrientaion(),
461                              myRotXSpn->value()*PI/180.,
462                              myRotYSpn->value()*PI/180.);
463
464   myCutLines->SetNbLines(aNbPlanes);
465   myCutLines->SetDisplacement2(myPosSpn2->value());
466   myCutLines->SetOrientation2(getOrientaion(false),
467                               myRotXSpn2->value()*PI/180.,
468                               myRotYSpn2->value()*PI/180.);
469
470   if (aNbRows>0)
471     for (int i = 0; i < aNbRows; ++i) {
472       QCheckTableItem* aItem = (QCheckTableItem*)myPosTable->item( i, 1 );
473       if (aItem == 0) break;
474       if (!aItem->isChecked())
475         myCutLines->SetLinePosition(i, myPosTable->text(i, 0).toDouble());
476     }
477
478   if (aNbPlanes > aNbRows)
479     myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
480   else if (aNbPlanes < aNbRows)
481     myPosTable->setNumRows(aNbPlanes);
482
483   int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
484   for (int i = 0; i<aMin; i++) {
485     myPosTable->setText(i, 0, QString::number(myCutLines->GetLinePosition(i)));
486     ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(myCutLines->IsDefaultPosition(i));
487   }
488
489   QHeader *vh = myPosTable->verticalHeader();
490   QString str("Plane# %1");
491   for (int i=aMin; i<aNbPlanes; i++) {
492     VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem
493       (myPosTable, QTableItem::OnTyping, QString::number(myCutLines->GetLinePosition(i)));
494     aEditItem->setReplaceable(false);
495     aEditItem->setEnabled(!myCutLines->IsDefaultPosition(i));
496     myPosTable->setItem(i, 0, aEditItem);
497
498     QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
499     aCheck->setChecked(myCutLines->IsDefaultPosition(i));
500     aCheck->setReplaceable(false);
501     myPosTable->setItem(i, 1, aCheck);
502
503     vh->setLabel( i, str.arg(i+1) );
504   }
505   // Update preview
506   if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) {
507     if (myPreviewCheck->isChecked()) {
508       //      myCutLines->GetPL()->Update();
509       deletePlanes();
510       createPlanes();
511       //aView->Repaint();
512     }
513   }
514 }
515
516 //------------------------------------------------------------------------------
517 void VisuGUI_CutLinesDlg::setDefault (int all)
518 {
519   myPosTable->setCurrentCell(-1, 1);
520   myPosTable->clearSelection();
521   if (all == 0) return;
522   if (all == 1)
523     for (int i = 0; i < (int)myNbSpn->value(); ++i)
524       ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
525
526   for (int i = 0; i < (int)myNbSpn->value(); ++i) {
527     if ( ((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked() ) {
528       myCutLines->SetDefaultPosition(i);
529       myPosTable->setText( i, 0, QString::number(myCutLines->GetLinePosition(i)));
530       myPosTable->item( i, 0 )->setEnabled(false);
531     } else
532       myPosTable->item( i, 0 )->setEnabled(true);
533   }
534 }
535
536 //------------------------------------------------------------------------------
537 VISU::CutPlanes::Orientation VisuGUI_CutLinesDlg::getOrientaion (bool IsBasePlane)
538 {
539   QHButtonGroup* aBG;
540
541   if (IsBasePlane)
542     aBG = mySelPlane;
543   else
544     aBG = mySelPlane2;
545
546   VISU::CutPlanes::Orientation orient;
547   switch (aBG->id(aBG->selected())) {
548   case 0:
549     orient = VISU::CutPlanes::XY;
550     break;
551   case 1:
552     orient = VISU::CutPlanes::YZ;
553     break;
554   case 2:
555     orient = VISU::CutPlanes::ZX;
556   }
557   return orient;
558 }
559
560 //------------------------------------------------------------------------------
561 void VisuGUI_CutLinesDlg::setOrientation (const VISU::CutPlanes::Orientation orient)
562 {
563   switch (orient) {
564   case VISU::CutPlanes::XY:
565     ((QRadioButton*)mySelPlane->find(0))->setChecked(true);
566     onPlaneSelect(0);
567     break;
568   case VISU::CutPlanes::YZ:
569     ((QRadioButton*)mySelPlane->find(1))->setChecked(true);
570     onPlaneSelect(1);
571     break;
572   case VISU::CutPlanes::ZX:
573     ((QRadioButton*)mySelPlane->find(2))->setChecked(true);
574     onPlaneSelect(2);
575   }
576 }
577
578 //------------------------------------------------------------------------------
579 void VisuGUI_CutLinesDlg::setOrientation2 (const VISU::CutPlanes::Orientation orient)
580 {
581   switch (orient) {
582   case VISU::CutPlanes::XY:
583     ((QRadioButton*)mySelPlane2->find(0))->setChecked(true);
584     onCutSelect(0);
585     break;
586   case VISU::CutPlanes::YZ:
587     ((QRadioButton*)mySelPlane2->find(1))->setChecked(true);
588     onCutSelect(1);
589     break;
590   case VISU::CutPlanes::ZX:
591     ((QRadioButton*)mySelPlane2->find(2))->setChecked(true);
592     onCutSelect(2);
593   }
594 }
595
596 void VisuGUI_CutLinesDlg::onValueChanged (int theRow, int theCol)
597 {
598   if (theCol == 0) {
599     QString aTxt = myPosTable->text(theRow, 0);
600     bool isChanged = !aTxt.isEmpty();
601     ((QCheckTableItem*)myPosTable->item(theRow, 1))->setChecked(!isChanged);
602
603     if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) {
604       if (myPreviewCheck->isChecked()) {
605         //Update Preview
606         //myCutLines->SetLinePosition( theRow, aTxt.toDouble());
607         //      myCutLines->GetPL()->Update();
608         deletePlanes();
609         createPlanes();
610         //aView->Repaint();
611       }
612     }
613   } else {
614     bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked();
615     if (isDefault) {
616       //myCutLines->SetDefaultPosition(theRow);
617       // myPosTable->setText(theRow, 0, QString::number(myCutLines->GetLinePosition(theRow)));
618
619       if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) {
620         if (myPreviewCheck->isChecked()) {
621           //Update Preview
622           //      myCutLines->GetPL()->Update();
623           deletePlanes();
624           createPlanes();
625           //aView->Repaint();
626         }
627       }
628       myPosTable->setText(theRow, 0, QString::number(myCutLines->GetLinePosition(theRow)));
629     }
630     myPosTable->item(theRow, 0)->setEnabled(!isDefault);
631   }
632 }
633
634 void VisuGUI_CutLinesDlg::accept()
635 {
636   //if ( !VisuGUI::CheckActiveStudyLock() ) {
637   //  reject();
638   //  return;
639   //}
640   MYGenerateTable = myCreateTable->isChecked();
641   MYGenerateCurve = myCurvesCheck->isChecked();
642   //  if (myScalarPane->check()) {
643     /*jfa tmp:((QWidget*)sender())->setDisabled(true);
644     storeToPrsObject(myPrs);
645     if (myIsCreation) {
646       if (isGenerateTable()) {
647         visuGUI->GetVisuGen()->CreateTable(myPrs->GetEntry());
648         if (isGenerateCurves()) {
649           SALOMEDSClient_Study* aStudy = study()->studyDS();
650           SALOMEDSClient_SObject* aSObject = aStudy->FindObjectID(myPrs->GetEntry());
651           if( aSObject ) {
652             SALOMEDSClient_ChildIterator* aIter = aStudy->NewChildIterator( aSObject );
653             SALOMEDSClient_StudyBuilder* aBuilder = aStudy->NewBuilder();
654             for ( ;aIter->More(); aIter->Next()) {
655               SALOMEDSClient_SObject* aTblObj = aIter->Value();
656               if ( aTblObj ) {
657                 SALOMEDSClient_GenericAttribute* anAttr;
658                 if (aTblObj->FindAttribute(anAttr, "AttributeName")) {
659                   visuGUI->CreatePlot(aTblObj);
660                 }
661               }
662             }
663           }
664         }
665       }
666       if (GET_VTK_VIEWWINDOW(myMgr)) {
667         try {
668           visuGUI->CreateActor(myPrs);
669         } catch (...) {
670           reject();
671           return;
672         }
673         GET_VTK_VIEWWINDOW(myMgr)->onFitAll();
674       }
675     } else {
676       visuGUI->RecreateActor(myPrs);
677       if (VTKViewer_ViewWindow* vf = GET_VTK_VIEWWINDOW(myMgr)) {
678         if (vf->getRenderer()->GetActors()->GetNumberOfItems() > 0) {
679           vf->getRenderer()->ResetCameraClippingRange();
680           vf->Repaint();
681         }
682       }
683       // Remove old Table
684       SALOMEDSClient_Study* aStudy = study()->studyDS();
685       SALOMEDSClient_SObject* aSObject = aStudy->FindObjectID(myPrs->GetEntry());
686       if( aSObject ) {
687         SALOMEDSClient_ChildIterator* aIter = aStudy->NewChildIterator( aSObject );
688         SALOMEDSClient_StudyBuilder* aBuilder = aStudy->NewBuilder();
689         for ( ;aIter->More(); aIter->Next()) {
690           SALOMEDSClient_SObject* aTblObj = aIter->Value();
691           if ( aTblObj ) {
692             SALOMEDSClient_GenericAttribute* anAttr;
693             if (aTblObj->FindAttribute(anAttr, "AttributeName")) {
694               aBuilder->RemoveObjectWithChildren(aIter->Value()); // We should have only one child
695               break;
696             }
697           }
698         }
699         if (isGenerateTable()) {
700           visuGUI->GetVisuGen()->CreateTable(aSObject->GetID().c_str());
701           if (isGenerateCurves()) {
702             SALOMEDSClient_Study* aStudy = study()->studyDS();
703             SALOMEDSClient_ChildIterator* aIter = aStudy->NewChildIterator( aSObject );
704             SALOMEDSClient_StudyBuilder* aBuilder = aStudy->NewBuilder();
705             for ( ;aIter->More(); aIter->Next()) {
706               SALOMEDSClient_SObject* aTblObj = aIter->Value();
707               if ( aTblObj ) {
708                 SALOMEDSClient_GenericAttribute* anAttr;
709                 if (aTblObj->FindAttribute(anAttr, "AttributeName")) {
710                   visuGUI->CreatePlot(aTblObj);
711                 }
712               }
713             }
714           }
715         }
716       }
717     }
718     VisuGUI::application()->objectBrowser()->updateTree();*/
719     deletePlanes();
720     QDialog::accept();
721     //  }
722 }
723
724 void VisuGUI_CutLinesDlg::reject()
725 {
726   /*jfa tmp:if (myIsCreation) {
727     myPrs->RemoveFromStudy();
728     VisuGUI::application()->objectBrowser()->updateTree();
729   }*/
730   deletePlanes();
731   QDialog::reject();
732 }
733
734 void VisuGUI_CutLinesDlg::onPreviewCheck (bool thePreview)
735 {
736   if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
737     if (thePreview) {
738       //storeToPrsObject(myCutLines);
739       //      myCutLines->GetPL()->Update();
740       createPlanes();
741       //vf->onFitAll();
742     } else {
743       deletePlanes();
744       vf->Repaint();
745     }
746   }
747 }
748
749 void VisuGUI_CutLinesDlg::onRotation (double theValue)
750 {
751   if (myCutLines == NULL) return;
752   if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) {
753     if (myPreviewCheck->isChecked()) {
754
755       /*myCutLines->SetOrientation(getOrientaion(),
756                                  myRotXSpn->value()*PI/180.,
757                                  myRotYSpn->value()*PI/180.);
758       myCutLines->SetOrientation2(getOrientaion(false),
759                                   myRotXSpn2->value()*PI/180.,
760                                   myRotYSpn2->value()*PI/180.);*/
761       //      myCutLines->GetPL()->Update();
762       deletePlanes();
763       createPlanes();
764       //aView->Repaint();
765     }
766   }
767 }
768
769 void VisuGUI_CutLinesDlg::onPlanePos (const QString& theValue)
770 {
771   if (myCutLines == NULL) return;
772   if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) {
773     if (myPreviewCheck->isChecked()) {
774       //myCutLines->SetBasePlanePosition(theValue.toDouble());
775       //      myCutLines->GetPL()->Update();
776       deletePlanes();
777       createPlanes();
778       //aView->Repaint();
779     }
780   }
781 }
782
783 //jfa tmp:void VisuGUI_CutLinesDlg::onWindowActivated (SUIT_ViewWindow* theWnd)
784 //jfa tmp:{
785 //jfa tmp:  if (theWnd != myStudyWnd)
786 //jfa tmp:    reject();
787 //jfa tmp:}