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