Salome HOME
Fix for the IPAL22822: Changes of plots in hexa8
[modules/visu.git] / src / VISUGUI / VisuGUI_CutLinesDlg.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 //  File   : VisuGUI_CutLinesDlg.cxx
23 //  Author : VSV
24 //  Module : VISU
25
26 #include "VisuGUI_CutLinesDlg.h"
27
28 #include "VISU_ColoredPrs3dFactory.hh"
29
30 #include "VisuGUI.h"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_ViewTools.h"
33 #include "VisuGUI_InputPane.h"
34
35 #include "VISU_Gen_i.hh"
36 #include "VISU_CutLines_i.hh"
37 #include "VISU_ColoredPrs3dFactory.hh"
38
39 #include "VISU_PipeLine.hxx"
40 #include "VISU_PipeLineUtils.hxx"
41 #include "VISU_CutLinesPL.hxx"
42
43 #include "SVTK_ViewWindow.h"
44
45 #include "LightApp_Application.h"
46 #include "SalomeApp_Study.h"
47 #include <SalomeApp_DoubleSpinBox.h>
48
49 #include "SUIT_Desktop.h"
50 #include "SUIT_Session.h"
51 #include "SUIT_MessageBox.h"
52 #include "SUIT_ResourceMgr.h"
53
54 //TO DO
55 //#include "OB_Browser.h"
56
57 #include "VISU_TableDlg.h"
58
59 #include <QLayout>
60 #include <QTabWidget>
61 #include <QLineEdit>
62 #include <QValidator>
63 #include <QButtonGroup>
64 #include <QKeyEvent>
65 #include <QLabel>
66 #include <QPushButton>
67 #include <QHeaderView>
68 #include <QRadioButton>
69 #include <QTableWidget>
70
71 #include <vtkRenderer.h>
72 #include <vtkPolyData.h>
73 #include <vtkAppendPolyData.h>
74 #include <vtkDataSetMapper.h>
75 #include <vtkGlyph3D.h>
76 #include <vtkPolyDataMapper.h>
77 #include <vtkFloatArray.h>
78 #include <vtkGlyphSource2D.h>
79
80 using namespace std;
81
82 VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (SalomeApp_Module* theModule)
83   : VisuGUI_ScalarBarBaseDlg(theModule),
84     myPreviewActor(0),
85     myPreviewActorGlyphs(0)
86 {
87   setWindowTitle("Cut Lines Definition");
88   setSizeGripEnabled(true);
89
90   QVBoxLayout* aMainLayout = new QVBoxLayout (this);
91   aMainLayout->setMargin( 7 );
92   aMainLayout->setSpacing(5);
93
94   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
95   hasInit = false;  
96
97   // Tab pane
98   myTabBox = new QTabWidget(this);
99
100   // Plane of lines
101   QFrame* aPlanePane = new QFrame(this);
102   QVBoxLayout* aPlaneLayout = new QVBoxLayout(aPlanePane);
103   aPlaneLayout->setMargin( 5 );
104   aPlaneLayout->setSpacing(6);
105
106   mySelPlane = new QButtonGroup( aPlanePane);
107   QGroupBox* aGB = new QGroupBox( tr( "TXT_ORIENTATION" ), aPlanePane );
108   QHBoxLayout* aHBLay = new QHBoxLayout( aGB );
109   //mySelPlane->setInsideSpacing( 5 );
110   //mySelPlane->setInsideMargin( 5 );
111
112   QRadioButton* aBxy = new QRadioButton( tr( "PARALLEL_XOY" ), aGB);  // 0
113   QRadioButton* aByz = new QRadioButton( tr( "PARALLEL_YOZ" ), aGB);  // 1
114   QRadioButton* aBzx = new QRadioButton( tr( "PARALLEL_ZOX" ), aGB);  // 2
115   //aBxy->setChecked(false);
116   //aByz->setChecked(false);
117   aHBLay->addWidget( aBxy );
118   aHBLay->addWidget( aByz );
119   aHBLay->addWidget( aBzx );
120
121   mySelPlane->addButton( aBxy, 0 );
122   mySelPlane->addButton( aByz, 1 );
123   mySelPlane->addButton( aBzx, 2 );
124
125   aBzx->setChecked(true);
126
127   aPlaneLayout->addWidget( aGB );
128
129   QGroupBox* aRotBox = new QGroupBox( tr( "LBL_ROTATION" ), aPlanePane );
130   //aRotBox->setColumnLayout(2, Qt::Horizontal );
131   QGridLayout* aGridLay = new QGridLayout( aRotBox );
132
133   myRotXLbl = new QLabel( tr( "LBL_ROT_X" ), aRotBox);
134   aGridLay->addWidget( myRotXLbl, 0, 0 );
135   myRotXSpn = new SalomeApp_DoubleSpinBox( aRotBox );
136   VISU::initSpinBox( myRotXSpn, -45., 45., 5., "angle_precision" );
137   aGridLay->addWidget( myRotXSpn, 0, 1 );
138   myRotXSpn->setValue( 0 );
139   myRotYLbl = new QLabel( tr( "LBL_ROT_Y" ), aRotBox );
140   aGridLay->addWidget( myRotYLbl, 1, 0 );
141   myRotYSpn = new SalomeApp_DoubleSpinBox( aRotBox );
142   VISU::initSpinBox( myRotYSpn, -45., 45., 5., "angle_precision" );  
143   aGridLay->addWidget( myRotYSpn, 1, 1 );
144   myRotYSpn->setValue( 0 );  
145
146   aPlaneLayout->addWidget( aRotBox );
147
148   QGroupBox* aBaseBox = new QGroupBox (tr("BASE_PLANE_POS"), aPlanePane);
149   aHBLay = new QHBoxLayout( aBaseBox );
150   myBasePlanePos = new QLineEdit (aBaseBox);
151   aHBLay->addWidget( myBasePlanePos );
152   mydvalidator = new QDoubleValidator(this);
153   mydvalidator->setDecimals(32);
154   myBasePlanePos->setValidator(mydvalidator);
155
156   myCBSetDef = new QCheckBox (tr("SET_DEFAULT"),aBaseBox);
157   aHBLay->addWidget( myCBSetDef );
158
159   aPlaneLayout->addWidget(aBaseBox);
160
161   QWidget* aPosBox = new QWidget (aPlanePane);
162   aHBLay = new QHBoxLayout( aPosBox );  
163   aHBLay->setSpacing(5);
164   
165   aHBLay->addWidget( new QLabel (tr("LBL_POS"), aPosBox) );
166   myPosSpn = new SalomeApp_DoubleSpinBox (aPosBox);
167   VISU::initSpinBox( myPosSpn, 0., 1., .1, "parametric_precision" );
168   myPosSpn->setValue(0.5);
169   aHBLay->addWidget( myPosSpn );
170   aPlaneLayout->addWidget(aPosBox);
171
172   myPreviewCheck = new QCheckBox (tr("LBL_SHOW_PREVIEW"), aPlanePane);
173   myPreviewCheck->setChecked( aResourceMgr->booleanValue("VISU", "show_preview", false) );
174   aPlaneLayout->addWidget(myPreviewCheck);
175
176   myAllCurvesInvertedCheck = new QCheckBox(tr("LBL_INVERT_CURVES"), aPlanePane);
177   myAllCurvesInvertedCheck->setChecked(false);
178   aPlaneLayout->addWidget(myAllCurvesInvertedCheck);
179
180   myUseAbsoluteLengthCheck = new QCheckBox(tr("LBL_ABSOLUTE_LENGTH"), aPlanePane);
181   myUseAbsoluteLengthCheck->setChecked(false);
182   aPlaneLayout->addWidget(myUseAbsoluteLengthCheck);
183
184   myCreateTable = new QCheckBox (tr("LBL_GENERATE_TABLE"), aPlanePane);
185   myCreateTable->setChecked( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
186   aPlaneLayout->addWidget( myCreateTable );
187
188   QWidget* aCheckPane = new QWidget(aPlanePane);
189   aHBLay = new QHBoxLayout( aCheckPane );
190   aHBLay->setMargin( 0 );
191   aHBLay->setSpacing( 0 );
192   aHBLay->insertSpacing( 0, 20 );
193   myCurvesCheck = new QCheckBox(tr("LBL_GENERATE_CURVES"), aCheckPane);
194   aHBLay->addWidget( myCurvesCheck );
195   myCurvesCheck->setChecked( aResourceMgr->booleanValue("VISU", "generate_curves", true) );
196   myCurvesCheck->setEnabled( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
197   aPlaneLayout->addWidget( aCheckPane );
198
199   aPlaneLayout->addStretch();
200
201   myTabBox->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
202
203   // Number of lines
204   QFrame* aLinesPane = new QFrame(this);
205   QVBoxLayout* aLinesLayout = new QVBoxLayout( aLinesPane );
206   aLinesLayout->setMargin( 5 );
207   aLinesLayout->setSpacing( 6 );
208
209   mySelPlane2 = new QButtonGroup( aLinesPane);
210   aGB = new QGroupBox( tr( "TXT_ORIENTATION" ), aLinesPane );
211   aHBLay = new QHBoxLayout( aGB );
212   //mySelPlane2->setInsideSpacing( 5 );
213   //mySelPlane2->setInsideMargin( 5 );
214
215   QRadioButton* aBxy2 = new QRadioButton( tr( "PARALLEL_XOY" ), aGB);  // 0
216   QRadioButton* aByz2 = new QRadioButton( tr( "PARALLEL_YOZ" ), aGB);  // 1
217   QRadioButton* aBzx2 = new QRadioButton( tr( "PARALLEL_ZOX" ), aGB);  // 2
218
219   aHBLay->addWidget( aBxy2 );
220   aHBLay->addWidget( aByz2 );
221   aHBLay->addWidget( aBzx2 );
222
223   mySelPlane2->addButton( aBxy2, 0 );
224   mySelPlane2->addButton( aByz2, 1 );
225   mySelPlane2->addButton( aBzx2, 2 );
226   
227   aBzx2->setEnabled(false);
228   aByz2->setChecked(true);
229   aLinesLayout->addWidget( aGB );
230
231   QGroupBox* aRotBox2 = new QGroupBox( tr( "LBL_ROTATION" ), aLinesPane );
232   //aRotBox2->setColumnLayout(2, Qt::Horizontal );
233   aGridLay = new QGridLayout( aRotBox2 );
234
235   myRotXLbl2 = new QLabel( tr( "LBL_ROT_X" ), aRotBox2);
236   aGridLay->addWidget( myRotXLbl2, 0, 0 );
237   myRotXSpn2 = new SalomeApp_DoubleSpinBox( aRotBox2 );
238   VISU::initSpinBox( myRotXSpn2, -45., 45., 5., "angle_precision" );
239   aGridLay->addWidget( myRotXSpn2, 0, 1 );
240   myRotXSpn2->setValue( 0 );
241   myRotYLbl2 = new QLabel( tr( "LBL_ROT_Y" ), aRotBox2 );
242   aGridLay->addWidget( myRotYLbl2, 1, 0 );
243   myRotYSpn2 = new SalomeApp_DoubleSpinBox( aRotBox2 );
244   VISU::initSpinBox( myRotYSpn2, -45., 45., 5., "angle_precision" );
245   aGridLay->addWidget( myRotYSpn2, 1, 1 );
246   myRotYSpn2->setValue( 0 );
247   aLinesLayout->addWidget( aRotBox2 );
248
249   QWidget* aNbBox = new QWidget(aLinesPane);
250   aHBLay = new QHBoxLayout( aNbBox ); 
251   aHBLay->setSpacing(5);
252   aHBLay->addWidget( new QLabel( tr( "LBL_NB_PLANS" ), aNbBox ) );
253   myNbSpn = new SalomeApp_DoubleSpinBox( aNbBox );
254   VISU::initSpinBox( myNbSpn, 1., 100., 1., "parametric_precision" );
255   myNbSpn->setValue( 10 );
256   aHBLay->addWidget( myNbSpn );
257
258   aLinesLayout->addWidget( aNbBox );
259
260   myPosTable = new QTableWidget(aLinesPane );
261   myPosTable->setMaximumHeight( 227 );
262   myPosTable->setMinimumWidth( 294 );
263   myPosTable->setColumnCount(2);
264   myPosTable->setRowCount(0);
265
266   myPosTable->setItemDelegateForColumn( 0,
267          new NumDelegateItem( myPosTable, NumDelegateItem::NV_Real) );
268
269   myPosTable->setEditTriggers( (QAbstractItemView::EditTriggers)(QAbstractItemView::AllEditTriggers &(~QAbstractItemView::CurrentChanged)));
270
271   QStringList aLabels;
272   aLabels.append( "Position" );
273   aLabels.append( "Set default" );
274   myPosTable->setHorizontalHeaderLabels( aLabels );
275   
276   aLinesLayout->addWidget( myPosTable );
277
278   QWidget* aPosBox2 = new QWidget(aLinesPane);
279   aHBLay = new QHBoxLayout( aPosBox2 );
280   aHBLay->setSpacing(5);
281   aHBLay->addWidget( new QLabel( tr( "LBL_POS" ), aPosBox2 ) );
282   myPosSpn2 = new SalomeApp_DoubleSpinBox( aPosBox2 );
283   VISU::initSpinBox( myPosSpn2, 0., 1., .1, "parametric_precision" );
284   myPosSpn2->setValue( 0.5 );
285   aHBLay->addWidget( myPosSpn2 );
286
287   
288   aLinesLayout->addWidget( aPosBox2 );
289   aLinesLayout->addStretch();
290
291   myTabBox->addTab( aLinesPane, tr("LBL_LINES_CUT") );
292
293   myInputPane = new VisuGUI_InputPane(VISU::TCUTLINES, theModule, this);
294   myTabBox->addTab(GetScalarPane(), "Scalar Bar");
295   myTabBox->addTab(myInputPane, "Input");
296
297   aMainLayout->addWidget(myTabBox);
298
299   // Dialog buttons
300   QFrame* aBtnBox = new QFrame(this);
301   aHBLay = new QHBoxLayout( aBtnBox );
302   aBtnBox->setFrameStyle(QFrame::Box | QFrame::Sunken);
303   aBtnBox->setLineWidth( 1 );
304   //aHBLay->setAutoAdd( false );
305   aHBLay->setSpacing( 5 );
306   aHBLay->setMargin( 11 );
307
308   QPushButton* aOkBtn = new QPushButton (tr("BUT_OK"), aBtnBox);
309   aOkBtn->setAutoDefault( TRUE );
310   aOkBtn->setDefault( true );
311   aHBLay->addWidget(aOkBtn);
312
313   aHBLay->addStretch();
314
315   QPushButton* aCloseBtn = new QPushButton(tr("BUT_CANCEL"), aBtnBox);
316   aHBLay->addWidget(aCloseBtn);
317
318   QPushButton* aHelpBtn = new QPushButton(tr("BUT_HELP"), aBtnBox);
319   aHBLay->addWidget(aHelpBtn);
320
321   aMainLayout->addWidget(aBtnBox);
322
323   // signals and slots connections
324   connect(mySelPlane    , SIGNAL(buttonClicked(int))          , this, SLOT(onPlaneSelect(int)));
325   connect(myCBSetDef    , SIGNAL(toggled(bool))         , this, SLOT(setBaseDefault()));
326   connect(myPosSpn      , SIGNAL(valueChanged(double))  , this, SLOT(setBaseDefault()));
327   connect(mySelPlane2   , SIGNAL(buttonClicked(int))          , this, SLOT(onCutSelect(int)));
328   connect(myNbSpn       , SIGNAL(valueChanged(double))  , this, SLOT(DrawTable()));
329   connect(myPosTable->horizontalHeader(), SIGNAL(sectionClicked(int))          , this, SLOT(setDefault(int)));
330   connect(myPosSpn2     , SIGNAL(valueChanged(double))  , this, SLOT(DrawTable()));
331   connect(myPreviewCheck, SIGNAL(toggled(bool))         , this, SLOT(onPreviewCheck(bool)));
332   connect(myAllCurvesInvertedCheck, SIGNAL(toggled(bool)),this, SLOT(onAllCurvesInvertedCheck(bool)));
333   connect(myPosTable    , SIGNAL(cellChanged(int, int)), this, SLOT(onValueChanged(int, int)));
334   connect(myRotXSpn     , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
335   connect(myRotYSpn     , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
336   connect(myRotXSpn2    , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
337   connect(myRotYSpn2    , SIGNAL(valueChanged(double))  , this, SLOT(onRotation(double)));
338   connect(myBasePlanePos, SIGNAL(textChanged(const QString&)), this, SLOT(onPlanePos(const QString&)));
339   connect(myCreateTable , SIGNAL(toggled(bool)), myCurvesCheck, SLOT(setEnabled(bool)));
340
341   connect(aOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
342   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
343   connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
344 }
345
346 /*!
347   Destructor
348 */
349 VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg()
350 {
351   deletePlanes();
352   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
353     vf->Repaint();
354 }
355
356 //------------------------------------------------------------------------------
357 void VisuGUI_CutLinesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
358                                               bool theInit )
359 {
360   if( theInit )
361     myPrsCopy = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
362
363   VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
364
365   myRotXSpn->setValue(myPrsCopy->GetRotateX()*180./M_PI);
366   myRotYSpn->setValue(myPrsCopy->GetRotateY()*180./M_PI);
367   myPosSpn->setValue(myPrsCopy->GetDisplacement());
368   setOrientation(myPrsCopy->GetOrientationType());
369
370   myNbSpn->setValue( (int)myPrsCopy->GetNbLines() );
371   myRotXSpn2->setValue(myPrsCopy->GetRotateX2()*180./M_PI);
372   myRotYSpn2->setValue(myPrsCopy->GetRotateY2()*180./M_PI);
373   myPosSpn2->setValue(myPrsCopy->GetDisplacement2());
374   setOrientation2(myPrsCopy->GetOrientationType2());
375
376   hasInit = true;
377   myCutLines = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(myPrsCopy, VISU::ColoredPrs3d_i::EDoNotPublish);
378   myCutLines->CopyCurvesInverted(myPrsCopy->GetCurvesInverted());
379   myAllCurvesInvertedCheck->setChecked( myCutLines->IsAllCurvesInverted() );
380   myUseAbsoluteLengthCheck->setChecked( myCutLines->IsUseAbsoluteLength() );
381   myBasePlanePos->setText( QString::number(myCutLines->GetBasePlanePosition()) );
382   myCBSetDef->setChecked(myPrsCopy->IsDefault());
383   DrawTable();
384
385   // Draw Preview
386   if (myPreviewCheck->isChecked()) {
387     createPlanes();
388   }
389
390   if( !theInit )
391     return;
392
393   myInputPane->initFromPrsObject( myPrsCopy );
394   myTabBox->setCurrentIndex( 0 );
395 }
396
397 //------------------------------------------------------------------------------
398 int VisuGUI_CutLinesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
399 {
400   if(!myInputPane->check() || !GetScalarPane()->check())
401     return 0;
402   
403   int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
404   anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
405
406   myPrsCopy->SetOrientation(getOrientaion(),
407                             myRotXSpn->value()*M_PI/180.,
408                             myRotYSpn->value()*M_PI/180.);
409   myPrsCopy->SetDisplacement(myPosSpn->value());
410   myPrsCopy->SetNbLines((int)myNbSpn->value());
411
412   myPrsCopy->SetOrientation2(getOrientaion(false),
413                              myRotXSpn2->value()*M_PI/180.,
414                              myRotYSpn2->value()*M_PI/180.);
415   myPrsCopy->SetDisplacement2(myPosSpn2->value());
416
417   if (!myCBSetDef->isChecked())
418     myPrsCopy->SetBasePlanePosition(myBasePlanePos->text().toDouble());
419   else myPrsCopy->SetDefault();
420
421   QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
422   if ( aModel )
423   {
424     for (int i = 0; i < (int)myNbSpn->value(); ++i)
425     {
426       QTableWidgetItem* aItem = myPosTable->item( i, 1 );
427       if (aItem == 0) break;
428       if (aItem->checkState() != Qt::Checked )
429       {        
430         QVariant aVar = aModel->index( i, 0 ).data();
431         myPrsCopy->SetLinePosition( i, aVar.toDouble() );
432       }      
433       else 
434         myPrsCopy->SetDefaultPosition(i);
435     }
436   }
437
438   myPrsCopy->SetAllCurvesInverted( myAllCurvesInvertedCheck->isChecked() );
439   myPrsCopy->SetUseAbsoluteLength( myUseAbsoluteLengthCheck->isChecked() );
440
441   VISU::TSameAsFactory<VISU::TCUTLINES>().Copy(myPrsCopy, thePrs);
442
443   return anIsOk;
444 }
445
446 //------------------------------------------------------------------------------
447 void VisuGUI_CutLinesDlg::createPlanes()
448 {
449   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
450   if (aView == NULL) return;
451   if (!(bool)myCutLines) return;
452   if (myPreviewActor != 0) return;
453
454   storeToPrsObject(myCutLines);
455   myCutLines->GetPipeLine()->Update();
456   vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
457   vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
458   aPlaneMapper->SetInput(aPolyData->GetOutput());
459   aPlaneMapper->ScalarVisibilityOff();
460   
461   myPreviewActorGlyphs = SALOME_Actor::New();
462   myPreviewActorGlyphs->PickableOff();
463   updateGlyphs(false);
464   
465   myPreviewActor = SALOME_Actor::New();
466   myPreviewActor->PickableOff();
467   myPreviewActor->SetMapper(aPlaneMapper);
468   aPlaneMapper->Delete();
469   aView->AddActor(myPreviewActor);
470   aView->AddActor(myPreviewActorGlyphs);
471   aView->getRenderer()->Render();
472   aView->onFitAll();
473 }
474
475 //------------------------------------------------------------------------------
476 void VisuGUI_CutLinesDlg::deletePlanes()
477 {
478   if (myPreviewActor == 0) return;
479   vtkRenderer* aRend       = myPreviewActor->GetRenderer();
480   vtkRenderer* aRendGlyphs = myPreviewActorGlyphs->GetRenderer();
481   
482   vtkRenderWindow* aWnd1 = aRend->GetRenderWindow();
483   vtkRenderWindow* aWnd2 = aRendGlyphs->GetRenderWindow();
484   if(aRend && aWnd1)
485     myPreviewActor->RemoveFromRender(aRend);
486   if(aRendGlyphs && aWnd2)
487     myPreviewActorGlyphs->RemoveFromRender(aRendGlyphs);
488
489   myPreviewActor->Delete();
490   myPreviewActorGlyphs->Delete();
491   myPreviewActor = 0;
492   myPreviewActorGlyphs = 0;
493 }
494
495
496 //------------------------------------------------------------------------------
497 void VisuGUI_CutLinesDlg::onPlaneSelect (int theId)
498 {
499   QList<QAbstractButton*> aBtns = mySelPlane2->buttons();
500   for (QList<QAbstractButton*>::Iterator it = aBtns.begin();
501        it != aBtns.end(); it++ )    
502    (*it)->setEnabled(true);
503   
504   QAbstractButton* aBtn = mySelPlane2->button(theId);
505   aBtn->setEnabled(false);
506   switch (theId) {
507   case 0:
508     myRotXLbl->setText( tr("LBL_ROT_X"));
509     myRotYLbl->setText( tr("LBL_ROT_Y"));
510     mySelPlane2->button(1)->setChecked(true);
511     onCutSelect(1, false);
512     break;
513   case 1:
514     myRotXLbl->setText( tr("LBL_ROT_Y"));
515     myRotYLbl->setText( tr("LBL_ROT_Z"));
516     mySelPlane2->button(2)->setChecked(true);
517     onCutSelect(2, false);
518     break;
519   case 2:
520     myRotXLbl->setText( tr("LBL_ROT_Z"));
521     myRotYLbl->setText( tr("LBL_ROT_X"));
522     mySelPlane2->button(0)->setChecked(true);
523     onCutSelect(0, false);
524   }
525   setBaseDefault(false);
526   DrawTable();
527 }
528
529 //------------------------------------------------------------------------------
530 void VisuGUI_CutLinesDlg::onCutSelect (int theId, bool theUpdate)
531 {
532   switch (theId) {
533   case 0:
534     myRotXLbl2->setText( tr("LBL_ROT_X"));
535     myRotYLbl2->setText( tr("LBL_ROT_Y"));
536     break;
537   case 1:
538     myRotXLbl2->setText( tr("LBL_ROT_Y"));
539     myRotYLbl2->setText( tr("LBL_ROT_Z"));
540     break;
541   case 2:
542     myRotXLbl2->setText( tr("LBL_ROT_Z"));
543     myRotYLbl2->setText( tr("LBL_ROT_X"));
544   }
545   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
546   if (aView) {
547     if (theUpdate && myPreviewCheck->isChecked() && (bool)myCutLines) {
548       deletePlanes();
549       createPlanes();
550     }
551   }
552 }
553
554 //------------------------------------------------------------------------------
555 void VisuGUI_CutLinesDlg::setBaseDefault (bool theUpdate)
556 {
557   if (!hasInit) return;
558
559   if (myCBSetDef->isChecked()) {
560     if (!myCutLines->IsDefault()) myCutLines->SetDefault();
561     myCutLines->SetDisplacement(myPosSpn->value());
562     SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
563     if (aView) {
564       if (theUpdate && myPreviewCheck->isChecked() && (bool)myCutLines) {
565         deletePlanes();
566         createPlanes();
567       }
568     }
569     vtkFloatingPointType aPos = myCutLines->GetBasePlanePosition();
570     myBasePlanePos->setText( QString::number(aPos) );
571     myBasePlanePos->setEnabled(false);
572   } else {
573     myBasePlanePos->setEnabled(true);
574   }
575 }
576
577 //------------------------------------------------------------------------------
578 void VisuGUI_CutLinesDlg::DrawTable()
579 {
580   if (!hasInit) return;
581
582   int aNbRows = myPosTable->rowCount();
583   int aNbPlanes = (int)myNbSpn->value();
584
585   QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
586   if ( !aModel )
587     return;
588
589   myCutLines->SetOrientation(getOrientaion(),
590                              myRotXSpn->value()*M_PI/180.,
591                              myRotYSpn->value()*M_PI/180.);
592
593   myCutLines->SetNbLines(aNbPlanes);
594   myCutLines->SetDisplacement2(myPosSpn2->value());
595   myCutLines->SetOrientation2(getOrientaion(false),
596                               myRotXSpn2->value()*M_PI/180.,
597                               myRotYSpn2->value()*M_PI/180.);
598
599   if (aNbRows>0)
600     for (int i = 0; i < aNbRows; ++i)
601     {
602       QTableWidgetItem* aItem = myPosTable->item( i, 1 );
603       if (aItem == 0) break;
604       if (aItem->checkState() != Qt::Checked )
605       {
606         QVariant aVar = aModel->index( i, 0 ).data();
607         myCutLines->SetLinePosition(i, aVar.toDouble());
608       }
609     }
610
611   //if (aNbPlanes > aNbRows)
612     //  myPosTable->addRows(aNbRows, aNbPlanes - aNbRows );
613   //else if (aNbPlanes < aNbRows)
614   //myPosTable->setRowCount(aNbPlanes);
615   if (aNbPlanes > aNbRows)
616     while( aNbPlanes > myPosTable->rowCount() )
617       myPosTable->insertRow( myPosTable->rowCount() );
618   else if (aNbPlanes < aNbRows)
619     myPosTable->setRowCount(aNbPlanes);
620
621   QString str("Plane# %1");
622   QStringList aLabels;
623   int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
624   for (int i = 0; i<aMin; i++)
625   {
626     QModelIndex anIndex = aModel->index( i, 0 );
627     aModel->setData( anIndex, QVariant( myCutLines->GetLinePosition(i) ), Qt::DisplayRole );
628     //myPosTable->setText(i, 0, QString::number(myCutLines->GetLinePosition(i)));
629     myPosTable->item( i, 1 )->setCheckState(myCutLines->IsDefaultPosition(i) ? Qt::Checked : Qt::Unchecked );
630     aLabels.append( str.arg(i+1) );
631   }
632
633   //QHeader *vh = myPosTable->verticalHeader();
634   for (int i=aMin; i<aNbPlanes; i++) {
635     /*VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem
636       (myPosTable, QTableItem::OnTyping, QString::number(myCutLines->GetLinePosition(i)));*/
637     QTableWidgetItem* aEditItem = new QTableWidgetItem();
638     aEditItem->setText( QString::number(myCutLines->GetLinePosition(i)) );
639     //aEditItem->setReplaceable(false);
640     //aEditItem->setEnabled(!myCutLines->IsDefaultPosition(i));
641     Qt::ItemFlags aFlags = aEditItem->flags();
642     if ( myCutLines->IsDefaultPosition(i) )
643       aFlags |= Qt::ItemIsEnabled;
644     else
645       aFlags &= (~Qt::ItemIsEnabled);
646     
647     myPosTable->setItem(i, 0, aEditItem);
648
649     /*QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
650     aCheck->setChecked(myCutLines->IsDefaultPosition(i));
651     aCheck->setReplaceable(false);
652     myPosTable->setItem(i, 1, aCheck);*/
653
654     QTableWidgetItem* aCheck = new QTableWidgetItem();
655     aCheck->setCheckState( myCutLines->IsDefaultPosition(i) ?
656                            Qt::Checked : Qt::Unchecked );
657     myPosTable->setItem(i, 1, aCheck);
658
659     //vh->setLabel( i, str.arg(i+1) );
660     aLabels.append( str.arg(i+1) );
661   }
662   myPosTable->setVerticalHeaderLabels( aLabels );
663   // Update preview
664   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
665   if (aView) {
666     if (myPreviewCheck->isChecked()) {
667       deletePlanes();
668       createPlanes();
669     }
670   }
671 }
672
673 void VisuGUI_CutLinesDlg::updateGlyphs(bool update){
674   if (myPreviewActorGlyphs == 0 ) return;
675   const vtkFloatingPointType *aDirLn = myCutLines->GetSpecificPL()->GetRealDirLn();
676   vtkFloatingPointType aSecondPnt[3];
677   vtkFloatingPointType aBoundCenter[3];
678
679   vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
680   vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
681   aPlaneMapper->SetInput(aPolyData->GetOutput());
682   vtkFloatingPointType bounds[6];
683   aPlaneMapper->GetBounds(bounds);
684
685   for(int i=0; i<3; i++) aBoundCenter[i] = (bounds[i*2] + bounds[i*2+1])/2.0;
686   for(int i=0; i<3; i++){ 
687     if (!myAllCurvesInvertedCheck->isChecked())
688       aSecondPnt[i] = aDirLn[i];
689     else
690       aSecondPnt[i] = - aDirLn[i];
691   }
692   
693   vtkFloatingPointType max_bound = 0;
694   max_bound < bounds[1]-bounds[0] ? max_bound = bounds[1] - bounds[0] : max_bound = max_bound;
695   max_bound < bounds[3]-bounds[2] ? max_bound = bounds[3] - bounds[2] : max_bound = max_bound;
696   max_bound < bounds[5]-bounds[4] ? max_bound = bounds[5] - bounds[4] : max_bound = max_bound;
697
698   vtkPolyData* profile = vtkPolyData::New();
699   vtkPoints* aPoints = vtkPoints::New();
700   vtkGlyph3D* glyphs = vtkGlyph3D::New();
701   vtkFloatArray *aFloatArray = vtkFloatArray::New();
702   vtkGlyphSource2D* source = vtkGlyphSource2D::New();
703   
704   source->FilledOn();
705   source->SetGlyphTypeToArrow();
706   
707   aPoints->InsertNextPoint(aBoundCenter);
708   profile->SetPoints(aPoints);
709   
710   aFloatArray->SetNumberOfComponents(3);
711   for(int i=0; i<3 ;i++)
712     aFloatArray->InsertNextValue(aSecondPnt[i]);
713   
714   vtkDataSetAttributes* aDataSetAttributes;
715   aDataSetAttributes = profile->GetPointData();
716   aDataSetAttributes->SetVectors(aFloatArray);
717   
718   glyphs->SetScaleFactor(0.25*max_bound);
719   glyphs->SetVectorModeToUseVector();
720   glyphs->SetScaleModeToScaleByVector();
721   glyphs->SetInput(profile);
722   glyphs->SetSource(source->GetOutput());
723
724   vtkPolyDataMapper* aGlyphsMapper = vtkPolyDataMapper::New();
725   aGlyphsMapper->ScalarVisibilityOff();
726   aGlyphsMapper->SetInput(glyphs->GetOutput());
727   
728   myPreviewActorGlyphs->SetMapper(aGlyphsMapper);
729
730   profile->Delete();
731   glyphs->Delete();
732   aPoints->Delete();
733   aGlyphsMapper->Delete();
734   aFloatArray->Delete();
735   source->Delete();
736   aPlaneMapper->Delete();
737
738   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
739     if (update)
740       vf->Repaint();
741 }
742
743 //------------------------------------------------------------------------------
744 void VisuGUI_CutLinesDlg::setDefault (int all)
745 {
746   myPosTable->setCurrentCell(0, 0);
747   myPosTable->clearSelection();
748
749   QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
750   if ( !aModel )
751     return;
752   
753   if (all == 0) return;
754   if (all == 1)
755     for (int i = 0; i < (int)myNbSpn->value(); ++i)
756       myPosTable->item( i, 1 )->setCheckState(Qt::Checked);
757
758   for (int i = 0; i < (int)myNbSpn->value(); ++i)
759   {
760     if ( myPosTable->item( i, 1 )->checkState() == Qt::Checked )
761     {
762       myCutLines->SetDefaultPosition(i);
763       QModelIndex anIndex = aModel->index( i, 0 );
764       aModel->setData( anIndex, QVariant( myCutLines->GetLinePosition(i) ), Qt::DisplayRole );
765       //myPosTable->setText( i, 0, QString::number(myCutLines->GetLinePosition(i)));
766       //myPosTable->item( i, 0 )->setEnabled(false);
767       myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() &(~Qt::ItemIsEnabled ) );
768     }
769     else
770       myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() | Qt::ItemIsEnabled );
771   }
772 }
773
774 //------------------------------------------------------------------------------
775 VISU::CutPlanes::Orientation VisuGUI_CutLinesDlg::getOrientaion (bool IsBasePlane)
776 {
777   QButtonGroup* aBG;
778
779   if (IsBasePlane)
780     aBG = mySelPlane;
781   else
782     aBG = mySelPlane2;
783
784   VISU::CutPlanes::Orientation orient;
785   switch (aBG->id(aBG->checkedButton())) {
786   case 0:
787     orient = VISU::CutPlanes::XY;
788     break;
789   case 1:
790     orient = VISU::CutPlanes::YZ;
791     break;
792   case 2:
793     orient = VISU::CutPlanes::ZX;
794   }
795   return orient;
796 }
797
798 //------------------------------------------------------------------------------
799 void VisuGUI_CutLinesDlg::setOrientation (const VISU::CutPlanes::Orientation orient)
800 {
801   switch (orient) {
802   case VISU::CutPlanes::XY:
803     mySelPlane->button(0)->setChecked(true);
804     onPlaneSelect(0);
805     break;
806   case VISU::CutPlanes::YZ:
807     mySelPlane->button(1)->setChecked(true);
808     onPlaneSelect(1);
809     break;
810   case VISU::CutPlanes::ZX:
811     mySelPlane->button(2)->setChecked(true);
812     onPlaneSelect(2);
813   }
814 }
815
816 //------------------------------------------------------------------------------
817 void VisuGUI_CutLinesDlg::setOrientation2 (const VISU::CutPlanes::Orientation orient)
818 {
819   switch (orient) {
820   case VISU::CutPlanes::XY:
821     mySelPlane2->button(0)->setChecked(true);
822     onCutSelect(0);
823     break;
824   case VISU::CutPlanes::YZ:
825     mySelPlane2->button(1)->setChecked(true);
826     onCutSelect(1);
827     break;
828   case VISU::CutPlanes::ZX:
829     mySelPlane2->button(2)->setChecked(true);
830     onCutSelect(2);
831   }
832 }
833
834 void VisuGUI_CutLinesDlg::onValueChanged (int theRow, int theCol)
835 {
836   /*QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
837   if ( !aModel )
838     return;
839
840   QModelIndex anIndex = aModel->index( theRow, theCol );
841   
842   if (theCol == 0)
843   {
844     bool isChanged = !anIndex.data().isNull();
845     myPosTable->item(theRow, 1)->setCheckState(!isChanged ? Qt::Checked : Qt::Unchecked);
846     SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
847     if (aView)
848     {
849       if (myPreviewCheck->isChecked())
850       {
851         deletePlanes();
852         createPlanes();
853       }
854     }
855   }
856   else if (theCol == 1)
857   {
858     bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
859     if (isDefault)
860     {
861       SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
862       if (aView)
863       {
864         if (myPreviewCheck->isChecked())
865         {
866           deletePlanes();
867           createPlanes();
868         }
869       }
870       aModel->setData( anIndex, myCutLines->GetLinePosition(theRow), Qt::DisplayRole );
871       myPosTable->item( theRow, 0 )->setFlags( myPosTable->item( theRow, 0 )->flags() | Qt::ItemIsEnabled );
872     }
873     else
874       myPosTable->item( theRow, 0 )->setFlags( myPosTable->item( theRow, 0 )->flags() &(~Qt::ItemIsEnabled ) );
875   }*/
876
877   QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
878   if ( !aModel )
879     return;
880   
881   if ( !myPosTable->item(theRow, 1) || !myPosTable->item(theRow, 0) )
882     return;
883
884   QModelIndex anIndex;
885
886   QTableWidgetItem* anItem = myPosTable->item(theRow, theCol);
887   if (!anItem )
888     return;
889
890   bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
891   if (theCol == 0 )
892   {
893     anIndex = aModel->index( theRow, 0 );
894     //if ( !isDefault)
895       //myCutLines->SetLinePosition( theRow, anIndex.data().toDouble());
896           
897             
898     if ( myPreviewCheck->isChecked() )
899     {
900       //Update Preview
901       if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
902       {
903         //myCutLines->GetPipeLine()->Update();
904         deletePlanes();
905         createPlanes();
906         //vf->Repaint();
907       }
908     }
909   }
910   else
911   {
912     anItem = myPosTable->item(theRow, 0);
913     Qt::ItemFlags flags = anItem->flags();
914     if ( isDefault )
915     {
916       myCutLines->SetDefaultPosition(theRow);
917       anIndex = aModel->index( theRow, 0 );
918       aModel->setData( anIndex, myCutLines->GetLinePosition(theRow), Qt::DisplayRole );
919
920       /*if ( myPreviewCheck->isChecked() )
921         {
922         //not needed update presentation, because item->setFlags generates signal cellChanged() again
923         }*/
924       flags &= (~Qt::ItemIsEnabled );
925     }
926     else
927       flags |=  Qt::ItemIsEnabled;
928    
929     anItem->setFlags( flags );
930   }
931 }
932
933 void VisuGUI_CutLinesDlg::accept()
934 {
935   VisuGUI_ScalarBarBaseDlg::accept();
936 }
937
938 void VisuGUI_CutLinesDlg::reject()
939 {
940   VisuGUI_ScalarBarBaseDlg::reject();
941 }
942
943 void VisuGUI_CutLinesDlg::onPreviewCheck (bool thePreview)
944 {
945   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
946     if (thePreview) {
947       createPlanes();
948     } else {
949       deletePlanes();
950       vf->Repaint();
951     }
952   }
953 }
954
955 /*! Inverting all curves in the table
956  */
957 void VisuGUI_CutLinesDlg::onAllCurvesInvertedCheck(bool theInvert)
958 {
959   bool anIsAllCurvesInverted = myAllCurvesInvertedCheck->isChecked();
960
961   myCutLines->SetAllCurvesInverted( anIsAllCurvesInverted );
962   myPrsCopy->SetAllCurvesInverted( anIsAllCurvesInverted );
963
964   updateGlyphs(true);
965 }
966
967 void VisuGUI_CutLinesDlg::onRotation (double theValue)
968 {
969   if (!(bool)myCutLines) return;
970   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
971   if (aView) {
972     if (myPreviewCheck->isChecked()) {
973       deletePlanes();
974       createPlanes();
975     }
976   }
977 }
978
979 void VisuGUI_CutLinesDlg::onPlanePos (const QString& theValue)
980 {
981   if (!(bool)myCutLines) return;
982   SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
983   if (aView) {
984     if (myPreviewCheck->isChecked()) {
985       deletePlanes();
986       createPlanes();
987     }
988   }
989 }
990
991 QString VisuGUI_CutLinesDlg::GetContextHelpFilePath()
992 {
993   return "cut_lines_page.html";
994 }