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