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