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