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