]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_CutLinesDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_CutLinesDlg.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : VisuGUI_CutLinesDlg.cxx
21 //  Author : VSV
22 //  Module : VISU
23
24 #include "VisuGUI_CutLinesDlg.h"
25
26 #include "VISU_ColoredPrs3dFactory.hh"
27
28 #include "VisuGUI.h"
29 #include "VisuGUI_Tools.h"
30 #include "VisuGUI_ViewTools.h"
31 #include "VisuGUI_InputPane.h"
32
33 #include "VISU_Gen_i.hh"
34 #include "VISU_CutLines_i.hh"
35 #include "VISU_ColoredPrs3dFactory.hh"
36
37 #include "VISU_PipeLine.hxx"
38 #include "VISU_PipeLineUtils.hxx"
39 #include "VISU_CutLinesPL.hxx"
40
41 #include "SVTK_ViewWindow.h"
42
43 #include "LightApp_Application.h"
44 #include "SalomeApp_Study.h"
45
46 #include "SUIT_Desktop.h"
47 #include "SUIT_Session.h"
48 #include "SUIT_MessageBox.h"
49 #include "SUIT_ResourceMgr.h"
50
51 #include "OB_Browser.h"
52
53 #include <qlayout.h>
54 #include <qhbox.h>
55 #include <qtabwidget.h>
56 #include <qhgroupbox.h>
57 #include <qlineedit.h>
58 #include <qlabel.h>
59 #include <qpushbutton.h>
60
61 #include <vtkRenderer.h>
62 #include <vtkPolyData.h>
63 #include <vtkAppendPolyData.h>
64 #include <vtkDataSetMapper.h>
65 #include <vtkGlyph3D.h>
66 #include <vtkPolyDataMapper.h>
67 #include <vtkFloatArray.h>
68 #include <vtkGlyphSource2D.h>
69
70 using namespace std;
71
72 VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (SalomeApp_Module* theModule)
73   : VisuGUI_ScalarBarBaseDlg(theModule),
74     myPreviewActor(0),
75     myPreviewActorGlyphs(0)
76 {
77   setCaption("Cut Lines Definition");
78   setSizeGripEnabled(true);
79
80   QVBoxLayout* aMainLayout = new QVBoxLayout (this, 7, 6);
81   aMainLayout->setSpacing(5);
82
83   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
84   hasInit = false;
85
86   // Tab pane
87   myTabBox = new QTabWidget(this);
88
89   // Plane of lines
90   QFrame* aPlanePane = new QFrame(this);
91   QVBoxLayout* aPlaneLayout = new QVBoxLayout(aPlanePane, 5, 6);
92
93   mySelPlane = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aPlanePane);
94   mySelPlane->setInsideSpacing( 5 );
95   mySelPlane->setInsideMargin( 5 );
96
97   QRadioButton* aBxy = new QRadioButton( tr( "PARALLEL_XOY" ), mySelPlane);  // 0
98   QRadioButton* aByz = new QRadioButton( tr( "PARALLEL_YOZ" ), mySelPlane);  // 1
99   QRadioButton* aBzx = new QRadioButton( tr( "PARALLEL_ZOX" ), mySelPlane);  // 2
100   aBxy->setChecked(false);
101   aByz->setChecked(false);
102   aBzx->setChecked(true);
103
104   aPlaneLayout->addWidget( mySelPlane );
105
106   QGroupBox* aRotBox = new QGroupBox( tr( "LBL_ROTATION" ), aPlanePane );
107   aRotBox->setColumnLayout(2, Qt::Horizontal );
108
109   myRotXLbl = new QLabel( tr( "LBL_ROT_X" ), aRotBox);
110   myRotXSpn = new QtxDblSpinBox( -45, 45, 5, aRotBox );
111   myRotXSpn->setValue( 0 );
112   myRotYLbl = new QLabel( tr( "LBL_ROT_Y" ), aRotBox );
113   myRotYSpn = new QtxDblSpinBox( -45, 45, 5, aRotBox );
114   myRotYSpn->setValue( 0 );
115
116   aPlaneLayout->addWidget( aRotBox );
117
118   QHGroupBox* aBaseBox = new QHGroupBox (tr("BASE_PLANE_POS"), aPlanePane);
119   myBasePlanePos = new QLineEdit (aBaseBox);
120   mydvalidator = new QDoubleValidator(this);
121   mydvalidator->setDecimals(32);
122   myBasePlanePos->setValidator(mydvalidator);
123
124   myCBSetDef = new QCheckBox (tr("SET_DEFAULT"),aBaseBox);
125
126   aPlaneLayout->addWidget(aBaseBox);
127
128   QHBox* aPosBox = new QHBox (aPlanePane);
129   aPosBox->setSpacing(5);
130   new QLabel (tr("LBL_POS"), aPosBox);
131   myPosSpn = new QtxDblSpinBox (0, 1, 0.1, aPosBox);
132   myPosSpn->setValue(0.5);
133   aPlaneLayout->addWidget(aPosBox);
134
135   myPreviewCheck = new QCheckBox (tr("LBL_SHOW_PREVIEW"), aPlanePane);
136   myPreviewCheck->setChecked( aResourceMgr->booleanValue("VISU", "show_preview", false) );
137   aPlaneLayout->addWidget(myPreviewCheck);
138
139   myAllCurvesInvertedCheck = new QCheckBox(tr("LBL_INVERT_CURVES"), aPlanePane);
140   myAllCurvesInvertedCheck->setChecked(false);
141   aPlaneLayout->addWidget(myAllCurvesInvertedCheck);
142
143   myUseAbsoluteLengthCheck = new QCheckBox(tr("LBL_ABSOLUTE_LENGTH"), aPlanePane);
144   myUseAbsoluteLengthCheck->setChecked(false);
145   aPlaneLayout->addWidget(myUseAbsoluteLengthCheck);
146
147   myCreateTable = new QCheckBox (tr("LBL_GENERATE_TABLE"), aPlanePane);
148   myCreateTable->setChecked( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
149   aPlaneLayout->addWidget( myCreateTable );
150
151   QHBox* aCheckPane = new QHBox(aPlanePane);
152   QLabel* aLbl = new QLabel("   ", aCheckPane);
153   aCheckPane->setStretchFactor(aLbl, 0);
154   myCurvesCheck = new QCheckBox(tr("LBL_GENERATE_CURVES"), aCheckPane);
155   aCheckPane->setStretchFactor(aCheckPane, 0);
156   myCurvesCheck->setChecked( aResourceMgr->booleanValue("VISU", "generate_curves", true) );
157   myCurvesCheck->setEnabled( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
158   QLabel* aLbl2 = new QLabel("   ", aCheckPane);
159   aCheckPane->setStretchFactor(aLbl2, 1);
160   aPlaneLayout->addWidget( aCheckPane );
161
162   aPlaneLayout->addStretch();
163
164
165   myTabBox->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
166
167   // Number of lines
168   QFrame* aLinesPane = new QFrame(this);
169   QVBoxLayout* aLinesLayout = new QVBoxLayout( aLinesPane, 5, 6 );
170
171   mySelPlane2 = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aLinesPane);
172   mySelPlane2->setInsideSpacing( 5 );
173   mySelPlane2->setInsideMargin( 5 );
174
175   QRadioButton* aBxy2 = new QRadioButton( tr( "PARALLEL_XOY" ), mySelPlane2);  // 0
176   QRadioButton* aByz2 = new QRadioButton( tr( "PARALLEL_YOZ" ), mySelPlane2);  // 1
177   QRadioButton* aBzx2 = new QRadioButton( tr( "PARALLEL_ZOX" ), mySelPlane2);  // 2
178   aBzx2->setEnabled(false);
179   aByz2->setChecked(true);
180   aLinesLayout->addWidget( mySelPlane2 );
181
182   QGroupBox* aRotBox2 = new QGroupBox( tr( "LBL_ROTATION" ), aLinesPane );
183   aRotBox2->setColumnLayout(2, Qt::Horizontal );
184
185   myRotXLbl2 = new QLabel( tr( "LBL_ROT_X" ), aRotBox2);
186   myRotXSpn2 = new QtxDblSpinBox( -45, 45, 5, aRotBox2 );
187   myRotXSpn2->setValue( 0 );
188   myRotYLbl2 = new QLabel( tr( "LBL_ROT_Y" ), aRotBox2 );
189   myRotYSpn2 = new QtxDblSpinBox( -45, 45, 5, aRotBox2 );
190   myRotYSpn2->setValue( 0 );
191   aLinesLayout->addWidget( aRotBox2 );
192
193   QHBox* aNbBox = new QHBox(aLinesPane);
194   aNbBox->setSpacing(5);
195   new QLabel( tr( "LBL_NB_PLANS" ), aNbBox );
196   myNbSpn = new QtxDblSpinBox( 1, 100, 1, aNbBox );
197   myNbSpn->setValue( 10 );
198
199   aLinesLayout->addWidget( aNbBox );
200
201   myPosTable = new QTable(aLinesPane, "Positions of cut planes" );
202   myPosTable->setMaximumHeight( 227 );
203   myPosTable->setMinimumWidth( 294 );
204   myPosTable->setNumCols(2);
205   myPosTable->setNumRows(0);
206
207   QHeader *th = myPosTable->horizontalHeader();
208   th->setLabel( 0, "Position" );
209   th->setLabel( 1, "Set default" );
210
211   aLinesLayout->addWidget( myPosTable );
212
213   QHBox* aPosBox2 = new QHBox(aLinesPane);
214   aPosBox2->setSpacing(5);
215   new QLabel( tr( "LBL_POS" ), aPosBox2 );
216   myPosSpn2 = new QtxDblSpinBox( 0, 1, 0.1, aPosBox2 );
217   myPosSpn2->setValue( 0.5 );
218   aLinesLayout->addWidget( aPosBox2 );
219   aLinesLayout->addStretch();
220
221   myTabBox->addTab( aLinesPane, tr("LBL_LINES_CUT") );
222
223   myInputPane = new VisuGUI_InputPane(VISU::TCUTLINES, theModule, this);
224   myTabBox->addTab(GetScalarPane(), "Scalar Bar");
225   myTabBox->addTab(myInputPane, "Input");
226
227   aMainLayout->addWidget(myTabBox);
228
229   // Dialog buttons
230   QHBox* aBtnBox = new QHBox(this);
231   aBtnBox->setFrameStyle(QFrame::Box | QFrame::Sunken);
232   aBtnBox->setLineWidth( 1 );
233   QHBoxLayout* aBtnLayout = (QHBoxLayout*) aBtnBox->layout();
234   aBtnLayout->setAutoAdd( false );
235   aBtnLayout->setSpacing( 5 );
236   aBtnLayout->setMargin( 11 );
237
238   QPushButton* aOkBtn = new QPushButton (tr("BUT_OK"), aBtnBox);
239   aOkBtn->setAutoDefault( TRUE );
240   aOkBtn->setDefault( true );
241   aBtnLayout->addWidget(aOkBtn);
242
243   aBtnLayout->addStretch();
244
245   QPushButton* aCloseBtn = new QPushButton(tr("BUT_CANCEL"), aBtnBox);
246   aBtnLayout->addWidget(aCloseBtn);
247
248   QPushButton* aHelpBtn = new QPushButton(tr("BUT_HELP"), aBtnBox);
249   aBtnLayout->addWidget(aHelpBtn);
250
251   aMainLayout->addWidget(aBtnBox);
252
253   // signals and slots connections
254   connect(mySelPlane    , SIGNAL(clicked(int))          , this, SLOT(onPlaneSelect(int)));
255   connect(myCBSetDef    , SIGNAL(toggled(bool))         , this, SLOT(setBaseDefault()));
256   connect(myPosSpn      , SIGNAL(valueChanged(double))  , this, SLOT(setBaseDefault()));
257   connect(mySelPlane2   , SIGNAL(clicked(int))          , this, SLOT(onCutSelect(int)));
258   connect(myNbSpn       , SIGNAL(valueChanged(double))  , this, SLOT(DrawTable()));
259   connect(th            , SIGNAL(clicked(int))          , this, SLOT(setDefault(int)));
260   connect(myPosSpn2     , SIGNAL(valueChanged(double))  , this, SLOT(DrawTable()));
261   connect(myPreviewCheck, SIGNAL(toggled(bool))         , this, SLOT(onPreviewCheck(bool)));
262   connect(myAllCurvesInvertedCheck, SIGNAL(toggled(bool)),this, SLOT(onAllCurvesInvertedCheck(bool)));
263   connect(myPosTable    , SIGNAL(valueChanged(int, int)), this, SLOT(onValueChanged(int, int)));
264   connect(myRotXSpn     , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
265   connect(myRotYSpn     , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
266   connect(myRotXSpn2    , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
267   connect(myRotYSpn2    , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
268   connect(myBasePlanePos, SIGNAL(textChanged(const QString&)), this, SLOT(onPlanePos(const QString&)));
269   connect(myCreateTable , SIGNAL(toggled(bool)), myCurvesCheck, SLOT(setEnabled(bool)));
270
271   connect(aOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
272   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
273   connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
274 }
275
276 /*!
277   Destructor
278 */
279 VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg()
280 {
281   deletePlanes();
282   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
283     vf->Repaint();
284 }
285
286 //------------------------------------------------------------------------------
287 void VisuGUI_CutLinesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
288                                               bool theInit )
289 {
290   if( theInit )
291     myPrsCopy = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
292
293   VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
294
295   myRotXSpn->setValue(myPrsCopy->GetRotateX()*180./PI);
296   myRotYSpn->setValue(myPrsCopy->GetRotateY()*180./PI);
297   myPosSpn->setValue(myPrsCopy->GetDisplacement());
298   setOrientation(myPrsCopy->GetOrientationType());
299
300   myNbSpn->setValue( (int)myPrsCopy->GetNbLines() );
301   myRotXSpn2->setValue(myPrsCopy->GetRotateX2()*180./PI);
302   myRotYSpn2->setValue(myPrsCopy->GetRotateY2()*180./PI);
303   myPosSpn2->setValue(myPrsCopy->GetDisplacement2());
304   setOrientation2(myPrsCopy->GetOrientationType2());
305
306   hasInit = true;
307   myCutLines = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(myPrsCopy, VISU::ColoredPrs3d_i::EDoNotPublish);
308   myCutLines->CopyCurvesInverted(myPrsCopy->GetCurvesInverted());
309   myAllCurvesInvertedCheck->setChecked( myCutLines->IsAllCurvesInverted() );
310   myUseAbsoluteLengthCheck->setChecked( myCutLines->IsUseAbsoluteLength() );
311   myBasePlanePos->setText( QString::number(myCutLines->GetBasePlanePosition()) );
312   myCBSetDef->setChecked(myPrsCopy->IsDefault());
313   DrawTable();
314
315   // Draw Preview
316   if (myPreviewCheck->isChecked()) {
317     createPlanes();
318   }
319
320   if( !theInit )
321     return;
322
323   myInputPane->initFromPrsObject( myPrsCopy );
324   myTabBox->setCurrentPage( 0 );
325 }
326
327 //------------------------------------------------------------------------------
328 int VisuGUI_CutLinesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
329 {
330   if(!myInputPane->check() || !GetScalarPane()->check())
331     return 0;
332
333   int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
334   anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
335
336   myPrsCopy->SetOrientation(getOrientaion(),
337                             myRotXSpn->value()*PI/180.,
338                             myRotYSpn->value()*PI/180.);
339   myPrsCopy->SetDisplacement(myPosSpn->value());
340   myPrsCopy->SetNbLines((int)myNbSpn->value());
341
342   myPrsCopy->SetOrientation2(getOrientaion(false),
343                              myRotXSpn2->value()*PI/180.,
344                              myRotYSpn2->value()*PI/180.);
345   myPrsCopy->SetDisplacement2(myPosSpn2->value());
346
347   if (!myCBSetDef->isChecked())
348     myPrsCopy->SetBasePlanePosition(myBasePlanePos->text().toDouble());
349   else myPrsCopy->SetDefault();
350
351   for (int i = 0; i < (int)myNbSpn->value(); ++i) {
352     if (!((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked())
353       myPrsCopy->SetLinePosition( i, myPosTable->text( i, 0 ).toDouble() );
354     else 
355       myPrsCopy->SetDefaultPosition(i);
356   }
357
358   myPrsCopy->SetAllCurvesInverted( myAllCurvesInvertedCheck->isChecked() );
359   myPrsCopy->SetUseAbsoluteLength( myUseAbsoluteLengthCheck->isChecked() );
360
361   VISU::TSameAsFactory<VISU::TCUTLINES>().Copy(myPrsCopy, thePrs);
362
363   return anIsOk;
364 }
365
366 //------------------------------------------------------------------------------
367 void VisuGUI_CutLinesDlg::createPlanes()
368 {
369   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
370   if (aView == NULL) return;
371   if (!myCutLines) return;
372   if (myPreviewActor != 0) return;
373
374   storeToPrsObject(myCutLines);
375   myCutLines->GetPipeLine()->Update();
376   vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
377   vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
378   aPlaneMapper->SetInput(aPolyData->GetOutput());
379   aPlaneMapper->ScalarVisibilityOff();
380
381   myPreviewActorGlyphs = SALOME_Actor::New();
382   myPreviewActorGlyphs->PickableOff();
383   updateGlyphs(false);
384
385   myPreviewActor = SALOME_Actor::New();
386   myPreviewActor->PickableOff();
387   myPreviewActor->SetMapper(aPlaneMapper);
388   aPlaneMapper->Delete();
389   aView->AddActor(myPreviewActor);
390   aView->AddActor(myPreviewActorGlyphs);
391   aView->getRenderer()->Render();
392   aView->onFitAll();
393 }
394
395 //------------------------------------------------------------------------------
396 void VisuGUI_CutLinesDlg::deletePlanes()
397 {
398   if (myPreviewActor == 0) return;
399   vtkRenderer* aRend       = myPreviewActor->GetRenderer();
400   vtkRenderer* aRendGlyphs = myPreviewActorGlyphs->GetRenderer();
401
402   vtkRenderWindow* aWnd1 = aRend->GetRenderWindow();
403   vtkRenderWindow* aWnd2 = aRendGlyphs->GetRenderWindow();
404   if(aRend && aWnd1)
405     myPreviewActor->RemoveFromRender(aRend);
406   if(aRendGlyphs && aWnd2)
407     myPreviewActorGlyphs->RemoveFromRender(aRendGlyphs);
408
409   myPreviewActor->Delete();
410   myPreviewActorGlyphs->Delete();
411   myPreviewActor = 0;
412   myPreviewActorGlyphs = 0;
413 }
414
415
416 //------------------------------------------------------------------------------
417 void VisuGUI_CutLinesDlg::onPlaneSelect (int theId)
418 {
419   for (int i = 0; i < mySelPlane2->count(); i++)
420     mySelPlane2->find(i)->setEnabled(true);
421   QButton* aBtn = mySelPlane2->find(theId);
422   aBtn->setEnabled(false);
423   switch (theId) {
424   case 0:
425     myRotXLbl->setText( tr("LBL_ROT_X"));
426     myRotYLbl->setText( tr("LBL_ROT_Y"));
427     ((QRadioButton*)mySelPlane2->find(1))->setChecked(true);
428     onCutSelect(1, false);
429     break;
430   case 1:
431     myRotXLbl->setText( tr("LBL_ROT_Y"));
432     myRotYLbl->setText( tr("LBL_ROT_Z"));
433     ((QRadioButton*)mySelPlane2->find(2))->setChecked(true);
434     onCutSelect(2, false);
435     break;
436   case 2:
437     myRotXLbl->setText( tr("LBL_ROT_Z"));
438     myRotYLbl->setText( tr("LBL_ROT_X"));
439     ((QRadioButton*)mySelPlane2->find(0))->setChecked(true);
440     onCutSelect(0, false);
441   }
442   setBaseDefault(false);
443   DrawTable();
444 }
445
446 //------------------------------------------------------------------------------
447 void VisuGUI_CutLinesDlg::onCutSelect (int theId, bool theUpdate)
448 {
449   switch (theId) {
450   case 0:
451     myRotXLbl2->setText( tr("LBL_ROT_X"));
452     myRotYLbl2->setText( tr("LBL_ROT_Y"));
453     break;
454   case 1:
455     myRotXLbl2->setText( tr("LBL_ROT_Y"));
456     myRotYLbl2->setText( tr("LBL_ROT_Z"));
457     break;
458   case 2:
459     myRotXLbl2->setText( tr("LBL_ROT_Z"));
460     myRotYLbl2->setText( tr("LBL_ROT_X"));
461   }
462   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
463   if (aView) {
464     if (theUpdate && myPreviewCheck->isChecked() && myCutLines) {
465       deletePlanes();
466       createPlanes();
467     }
468   }
469 }
470
471 //------------------------------------------------------------------------------
472 void VisuGUI_CutLinesDlg::setBaseDefault (bool theUpdate)
473 {
474   if (!hasInit) return;
475
476   if (myCBSetDef->isChecked()) {
477     if (!myCutLines->IsDefault()) myCutLines->SetDefault();
478     myCutLines->SetDisplacement(myPosSpn->value());
479     SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
480     if (aView) {
481       if (theUpdate && myPreviewCheck->isChecked() && myCutLines) {
482         deletePlanes();
483         createPlanes();
484       }
485     }
486     vtkFloatingPointType aPos = myCutLines->GetBasePlanePosition();
487     myBasePlanePos->setText( QString::number(aPos) );
488     myBasePlanePos->setEnabled(false);
489   } else {
490     myBasePlanePos->setEnabled(true);
491   }
492 }
493
494 //------------------------------------------------------------------------------
495 void VisuGUI_CutLinesDlg::DrawTable()
496 {
497   if (!hasInit) return;
498
499   int aNbRows = myPosTable->numRows();
500   int aNbPlanes = (int)myNbSpn->value();
501
502   myCutLines->SetOrientation(getOrientaion(),
503                              myRotXSpn->value()*PI/180.,
504                              myRotYSpn->value()*PI/180.);
505
506   myCutLines->SetNbLines(aNbPlanes);
507   myCutLines->SetDisplacement2(myPosSpn2->value());
508   myCutLines->SetOrientation2(getOrientaion(false),
509                               myRotXSpn2->value()*PI/180.,
510                               myRotYSpn2->value()*PI/180.);
511
512   if (aNbRows>0)
513     for (int i = 0; i < aNbRows; ++i) {
514       QCheckTableItem* aItem = (QCheckTableItem*)myPosTable->item( i, 1 );
515       if (aItem == 0) break;
516       if (!aItem->isChecked())
517         myCutLines->SetLinePosition(i, myPosTable->text(i, 0).toDouble());
518     }
519
520   if (aNbPlanes > aNbRows)
521     myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
522   else if (aNbPlanes < aNbRows)
523     myPosTable->setNumRows(aNbPlanes);
524
525   int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
526   for (int i = 0; i<aMin; i++) {
527     myPosTable->setText(i, 0, QString::number(myCutLines->GetLinePosition(i)));
528     ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(myCutLines->IsDefaultPosition(i));
529   }
530
531   QHeader *vh = myPosTable->verticalHeader();
532   QString str("Plane# %1");
533   for (int i=aMin; i<aNbPlanes; i++) {
534     VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem
535       (myPosTable, QTableItem::OnTyping, QString::number(myCutLines->GetLinePosition(i)));
536     aEditItem->setReplaceable(false);
537     aEditItem->setEnabled(!myCutLines->IsDefaultPosition(i));
538     myPosTable->setItem(i, 0, aEditItem);
539
540     QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
541     aCheck->setChecked(myCutLines->IsDefaultPosition(i));
542     aCheck->setReplaceable(false);
543     myPosTable->setItem(i, 1, aCheck);
544
545     vh->setLabel( i, str.arg(i+1) );
546   }
547   // Update preview
548   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
549   if (aView) {
550     if (myPreviewCheck->isChecked()) {
551       deletePlanes();
552       createPlanes();
553     }
554   }
555 }
556
557 void VisuGUI_CutLinesDlg::updateGlyphs(bool update){
558   if (myPreviewActorGlyphs == 0 ) return;
559   const vtkFloatingPointType *aDirLn = myCutLines->GetSpecificPL()->GetRealDirLn();
560   vtkFloatingPointType aSecondPnt[3];
561   vtkFloatingPointType aBoundCenter[3];
562
563   vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
564   vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
565   aPlaneMapper->SetInput(aPolyData->GetOutput());
566   vtkFloatingPointType bounds[6];
567   aPlaneMapper->GetBounds(bounds);
568
569   for(int i=0; i<3; i++) aBoundCenter[i] = (bounds[i*2] + bounds[i*2+1])/2.0;
570   for(int i=0; i<3; i++){
571     if (!myAllCurvesInvertedCheck->isChecked())
572       aSecondPnt[i] = aDirLn[i];
573     else
574       aSecondPnt[i] = - aDirLn[i];
575   }
576
577   vtkFloatingPointType max_bound = 0;
578   max_bound < bounds[1]-bounds[0] ? max_bound = bounds[1] - bounds[0] : max_bound = max_bound;
579   max_bound < bounds[3]-bounds[2] ? max_bound = bounds[3] - bounds[2] : max_bound = max_bound;
580   max_bound < bounds[5]-bounds[4] ? max_bound = bounds[5] - bounds[4] : max_bound = max_bound;
581
582   vtkPolyData* profile = vtkPolyData::New();
583   vtkPoints* aPoints = vtkPoints::New();
584   vtkGlyph3D* glyphs = vtkGlyph3D::New();
585   vtkFloatArray *aFloatArray = vtkFloatArray::New();
586   vtkGlyphSource2D* source = vtkGlyphSource2D::New();
587   
588   source->FilledOn();
589   source->SetGlyphTypeToArrow();
590   
591   aPoints->InsertNextPoint(aBoundCenter);
592   profile->SetPoints(aPoints);
593   
594   aFloatArray->SetNumberOfComponents(3);
595   for(int i=0; i<3 ;i++)
596     aFloatArray->InsertNextValue(aSecondPnt[i]);
597   
598   vtkDataSetAttributes* aDataSetAttributes;
599   aDataSetAttributes = profile->GetPointData();
600   aDataSetAttributes->SetVectors(aFloatArray);
601   
602   glyphs->SetScaleFactor(0.25*max_bound);
603   glyphs->SetVectorModeToUseVector();
604   glyphs->SetScaleModeToScaleByVector();
605   glyphs->SetInput(profile);
606   glyphs->SetSource(source->GetOutput());
607
608   vtkPolyDataMapper* aGlyphsMapper = vtkPolyDataMapper::New();
609   aGlyphsMapper->ScalarVisibilityOff();
610   aGlyphsMapper->SetInput(glyphs->GetOutput());
611   
612   myPreviewActorGlyphs->SetMapper(aGlyphsMapper);
613
614   profile->Delete();
615   glyphs->Delete();
616   aPoints->Delete();
617   aGlyphsMapper->Delete();
618   aFloatArray->Delete();
619   source->Delete();
620   aPlaneMapper->Delete();
621
622   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
623     if (update)
624       vf->Repaint();
625 }
626
627 //------------------------------------------------------------------------------
628 void VisuGUI_CutLinesDlg::setDefault (int all)
629 {
630   myPosTable->setCurrentCell(-1, 1);
631   myPosTable->clearSelection();
632   if (all == 0) return;
633   if (all == 1)
634     for (int i = 0; i < (int)myNbSpn->value(); ++i)
635       ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
636
637   for (int i = 0; i < (int)myNbSpn->value(); ++i) {
638     if ( ((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked() ) {
639       myCutLines->SetDefaultPosition(i);
640       myPosTable->setText( i, 0, QString::number(myCutLines->GetLinePosition(i)));
641       myPosTable->item( i, 0 )->setEnabled(false);
642     } else
643       myPosTable->item( i, 0 )->setEnabled(true);
644   }
645 }
646
647 //------------------------------------------------------------------------------
648 VISU::CutPlanes::Orientation VisuGUI_CutLinesDlg::getOrientaion (bool IsBasePlane)
649 {
650   QHButtonGroup* aBG;
651
652   if (IsBasePlane)
653     aBG = mySelPlane;
654   else
655     aBG = mySelPlane2;
656
657   VISU::CutPlanes::Orientation orient;
658   switch (aBG->id(aBG->selected())) {
659   case 0:
660     orient = VISU::CutPlanes::XY;
661     break;
662   case 1:
663     orient = VISU::CutPlanes::YZ;
664     break;
665   case 2:
666     orient = VISU::CutPlanes::ZX;
667   }
668   return orient;
669 }
670
671 //------------------------------------------------------------------------------
672 void VisuGUI_CutLinesDlg::setOrientation (const VISU::CutPlanes::Orientation orient)
673 {
674   switch (orient) {
675   case VISU::CutPlanes::XY:
676     ((QRadioButton*)mySelPlane->find(0))->setChecked(true);
677     onPlaneSelect(0);
678     break;
679   case VISU::CutPlanes::YZ:
680     ((QRadioButton*)mySelPlane->find(1))->setChecked(true);
681     onPlaneSelect(1);
682     break;
683   case VISU::CutPlanes::ZX:
684     ((QRadioButton*)mySelPlane->find(2))->setChecked(true);
685     onPlaneSelect(2);
686   }
687 }
688
689 //------------------------------------------------------------------------------
690 void VisuGUI_CutLinesDlg::setOrientation2 (const VISU::CutPlanes::Orientation orient)
691 {
692   switch (orient) {
693   case VISU::CutPlanes::XY:
694     ((QRadioButton*)mySelPlane2->find(0))->setChecked(true);
695     onCutSelect(0);
696     break;
697   case VISU::CutPlanes::YZ:
698     ((QRadioButton*)mySelPlane2->find(1))->setChecked(true);
699     onCutSelect(1);
700     break;
701   case VISU::CutPlanes::ZX:
702     ((QRadioButton*)mySelPlane2->find(2))->setChecked(true);
703     onCutSelect(2);
704   }
705 }
706
707 void VisuGUI_CutLinesDlg::onValueChanged (int theRow, int theCol)
708 {
709   if (theCol == 0) {
710     QString aTxt = myPosTable->text(theRow, 0);
711     bool isChanged = !aTxt.isEmpty();
712     ((QCheckTableItem*)myPosTable->item(theRow, 1))->setChecked(!isChanged);
713     SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
714     if (aView) {
715       if (myPreviewCheck->isChecked()) {
716         deletePlanes();
717         createPlanes();
718       }
719     }
720   } else if (theCol == 1){
721     bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked();
722     if (isDefault) {
723       SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
724       if (aView) {
725         if (myPreviewCheck->isChecked()) {
726           deletePlanes();
727           createPlanes();
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   VisuGUI_ScalarBarBaseDlg::accept();
739 }
740
741 void VisuGUI_CutLinesDlg::reject()
742 {
743   VisuGUI_ScalarBarBaseDlg::reject();
744 }
745
746 void VisuGUI_CutLinesDlg::onPreviewCheck (bool thePreview)
747 {
748   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
749     if (thePreview) {
750       createPlanes();
751     } else {
752       deletePlanes();
753       vf->Repaint();
754     }
755   }
756 }
757
758 /*! Inverting all curves in the table
759  */
760 void VisuGUI_CutLinesDlg::onAllCurvesInvertedCheck(bool theInvert)
761 {
762   bool anIsAllCurvesInverted = myAllCurvesInvertedCheck->isChecked();
763
764   myCutLines->SetAllCurvesInverted( anIsAllCurvesInverted );
765   myPrsCopy->SetAllCurvesInverted( anIsAllCurvesInverted );
766
767   updateGlyphs(true);
768 }
769
770 void VisuGUI_CutLinesDlg::onRotation (double theValue)
771 {
772   if (!myCutLines) return;
773   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
774   if (aView) {
775     if (myPreviewCheck->isChecked()) {
776       deletePlanes();
777       createPlanes();
778     }
779   }
780 }
781
782 void VisuGUI_CutLinesDlg::onPlanePos (const QString& theValue)
783 {
784   if (!myCutLines) return;
785   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
786   if (aView) {
787     if (myPreviewCheck->isChecked()) {
788       deletePlanes();
789       createPlanes();
790     }
791   }
792 }
793
794 QString VisuGUI_CutLinesDlg::GetContextHelpFilePath()
795 {
796   return "cut_lines_page.html";
797 }