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