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