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