1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : VisuGUI_CutLinesDlg.cxx
26 #include "VisuGUI_CutLinesDlg.h"
28 #include "VISU_ColoredPrs3dFactory.hh"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_ViewTools.h"
33 #include "VisuGUI_InputPane.h"
35 #include "VISU_Gen_i.hh"
36 #include "VISU_CutLines_i.hh"
37 #include "VISU_ColoredPrs3dFactory.hh"
39 #include "VISU_PipeLine.hxx"
40 #include "VISU_PipeLineUtils.hxx"
41 #include "VISU_CutLinesPL.hxx"
43 #include "SVTK_ViewWindow.h"
45 #include "LightApp_Application.h"
46 #include "SalomeApp_Study.h"
47 #include <SalomeApp_DoubleSpinBox.h>
49 #include "SUIT_Desktop.h"
50 #include "SUIT_Session.h"
51 #include "SUIT_MessageBox.h"
52 #include "SUIT_ResourceMgr.h"
55 //#include "OB_Browser.h"
57 #include "VISU_TableDlg.h"
63 #include <QButtonGroup>
66 #include <QPushButton>
67 #include <QHeaderView>
68 #include <QRadioButton>
69 #include <QTableWidget>
71 #include <vtkRenderer.h>
72 #include <vtkPolyData.h>
73 #include <vtkAppendPolyData.h>
74 #include <vtkDataSetMapper.h>
75 #include <vtkGlyph3D.h>
76 #include <vtkPolyDataMapper.h>
77 #include <vtkFloatArray.h>
78 #include <vtkGlyphSource2D.h>
82 VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (SalomeApp_Module* theModule)
83 : VisuGUI_ScalarBarBaseDlg(theModule),
85 myPreviewActorGlyphs(0)
87 setWindowTitle("Cut Lines Definition");
88 setSizeGripEnabled(true);
90 QVBoxLayout* aMainLayout = new QVBoxLayout (this);
91 aMainLayout->setMargin( 7 );
92 aMainLayout->setSpacing(5);
94 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
98 myTabBox = new QTabWidget(this);
101 QFrame* aPlanePane = new QFrame(this);
102 QVBoxLayout* aPlaneLayout = new QVBoxLayout(aPlanePane);
103 aPlaneLayout->setMargin( 5 );
104 aPlaneLayout->setSpacing(6);
106 mySelPlane = new QButtonGroup( aPlanePane);
107 QGroupBox* aGB = new QGroupBox( tr( "TXT_ORIENTATION" ), aPlanePane );
108 QHBoxLayout* aHBLay = new QHBoxLayout( aGB );
109 //mySelPlane->setInsideSpacing( 5 );
110 //mySelPlane->setInsideMargin( 5 );
112 QRadioButton* aBxy = new QRadioButton( tr( "PARALLEL_XOY" ), aGB); // 0
113 QRadioButton* aByz = new QRadioButton( tr( "PARALLEL_YOZ" ), aGB); // 1
114 QRadioButton* aBzx = new QRadioButton( tr( "PARALLEL_ZOX" ), aGB); // 2
115 //aBxy->setChecked(false);
116 //aByz->setChecked(false);
117 aHBLay->addWidget( aBxy );
118 aHBLay->addWidget( aByz );
119 aHBLay->addWidget( aBzx );
121 mySelPlane->addButton( aBxy, 0 );
122 mySelPlane->addButton( aByz, 1 );
123 mySelPlane->addButton( aBzx, 2 );
125 aBzx->setChecked(true);
127 aPlaneLayout->addWidget( aGB );
129 QGroupBox* aRotBox = new QGroupBox( tr( "LBL_ROTATION" ), aPlanePane );
130 //aRotBox->setColumnLayout(2, Qt::Horizontal );
131 QGridLayout* aGridLay = new QGridLayout( aRotBox );
133 myRotXLbl = new QLabel( tr( "LBL_ROT_X" ), aRotBox);
134 aGridLay->addWidget( myRotXLbl, 0, 0 );
135 myRotXSpn = new SalomeApp_DoubleSpinBox( aRotBox );
136 VISU::initSpinBox( myRotXSpn, -45., 45., 5., "angle_precision" );
137 aGridLay->addWidget( myRotXSpn, 0, 1 );
138 myRotXSpn->setValue( 0 );
139 myRotYLbl = new QLabel( tr( "LBL_ROT_Y" ), aRotBox );
140 aGridLay->addWidget( myRotYLbl, 1, 0 );
141 myRotYSpn = new SalomeApp_DoubleSpinBox( aRotBox );
142 VISU::initSpinBox( myRotYSpn, -45., 45., 5., "angle_precision" );
143 aGridLay->addWidget( myRotYSpn, 1, 1 );
144 myRotYSpn->setValue( 0 );
146 aPlaneLayout->addWidget( aRotBox );
148 QGroupBox* aBaseBox = new QGroupBox (tr("BASE_PLANE_POS"), aPlanePane);
149 aHBLay = new QHBoxLayout( aBaseBox );
150 myBasePlanePos = new QLineEdit (aBaseBox);
151 aHBLay->addWidget( myBasePlanePos );
152 mydvalidator = new QDoubleValidator(this);
153 mydvalidator->setDecimals(32);
154 myBasePlanePos->setValidator(mydvalidator);
156 myCBSetDef = new QCheckBox (tr("SET_DEFAULT"),aBaseBox);
157 aHBLay->addWidget( myCBSetDef );
159 aPlaneLayout->addWidget(aBaseBox);
161 QWidget* aPosBox = new QWidget (aPlanePane);
162 aHBLay = new QHBoxLayout( aPosBox );
163 aHBLay->setSpacing(5);
165 aHBLay->addWidget( new QLabel (tr("LBL_POS"), aPosBox) );
166 myPosSpn = new SalomeApp_DoubleSpinBox (aPosBox);
167 VISU::initSpinBox( myPosSpn, 0., 1., .1, "parametric_precision" );
168 myPosSpn->setValue(0.5);
169 aHBLay->addWidget( myPosSpn );
170 aPlaneLayout->addWidget(aPosBox);
172 myPreviewCheck = new QCheckBox (tr("LBL_SHOW_PREVIEW"), aPlanePane);
173 myPreviewCheck->setChecked( aResourceMgr->booleanValue("VISU", "show_preview", false) );
174 aPlaneLayout->addWidget(myPreviewCheck);
176 myAllCurvesInvertedCheck = new QCheckBox(tr("LBL_INVERT_CURVES"), aPlanePane);
177 myAllCurvesInvertedCheck->setChecked(false);
178 aPlaneLayout->addWidget(myAllCurvesInvertedCheck);
180 myUseAbsoluteLengthCheck = new QCheckBox(tr("LBL_ABSOLUTE_LENGTH"), aPlanePane);
181 myUseAbsoluteLengthCheck->setChecked(false);
182 aPlaneLayout->addWidget(myUseAbsoluteLengthCheck);
184 myCreateTable = new QCheckBox (tr("LBL_GENERATE_TABLE"), aPlanePane);
185 myCreateTable->setChecked( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
186 aPlaneLayout->addWidget( myCreateTable );
188 QWidget* aCheckPane = new QWidget(aPlanePane);
189 aHBLay = new QHBoxLayout( aCheckPane );
190 aHBLay->setMargin( 0 );
191 aHBLay->setSpacing( 0 );
192 aHBLay->insertSpacing( 0, 20 );
193 myCurvesCheck = new QCheckBox(tr("LBL_GENERATE_CURVES"), aCheckPane);
194 aHBLay->addWidget( myCurvesCheck );
195 myCurvesCheck->setChecked( aResourceMgr->booleanValue("VISU", "generate_curves", true) );
196 myCurvesCheck->setEnabled( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
197 aPlaneLayout->addWidget( aCheckPane );
199 aPlaneLayout->addStretch();
201 myTabBox->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
204 QFrame* aLinesPane = new QFrame(this);
205 QVBoxLayout* aLinesLayout = new QVBoxLayout( aLinesPane );
206 aLinesLayout->setMargin( 5 );
207 aLinesLayout->setSpacing( 6 );
209 mySelPlane2 = new QButtonGroup( aLinesPane);
210 aGB = new QGroupBox( tr( "TXT_ORIENTATION" ), aLinesPane );
211 aHBLay = new QHBoxLayout( aGB );
212 //mySelPlane2->setInsideSpacing( 5 );
213 //mySelPlane2->setInsideMargin( 5 );
215 QRadioButton* aBxy2 = new QRadioButton( tr( "PARALLEL_XOY" ), aGB); // 0
216 QRadioButton* aByz2 = new QRadioButton( tr( "PARALLEL_YOZ" ), aGB); // 1
217 QRadioButton* aBzx2 = new QRadioButton( tr( "PARALLEL_ZOX" ), aGB); // 2
219 aHBLay->addWidget( aBxy2 );
220 aHBLay->addWidget( aByz2 );
221 aHBLay->addWidget( aBzx2 );
223 mySelPlane2->addButton( aBxy2, 0 );
224 mySelPlane2->addButton( aByz2, 1 );
225 mySelPlane2->addButton( aBzx2, 2 );
227 aBzx2->setEnabled(false);
228 aByz2->setChecked(true);
229 aLinesLayout->addWidget( aGB );
231 QGroupBox* aRotBox2 = new QGroupBox( tr( "LBL_ROTATION" ), aLinesPane );
232 //aRotBox2->setColumnLayout(2, Qt::Horizontal );
233 aGridLay = new QGridLayout( aRotBox2 );
235 myRotXLbl2 = new QLabel( tr( "LBL_ROT_X" ), aRotBox2);
236 aGridLay->addWidget( myRotXLbl2, 0, 0 );
237 myRotXSpn2 = new SalomeApp_DoubleSpinBox( aRotBox2 );
238 VISU::initSpinBox( myRotXSpn2, -45., 45., 5., "angle_precision" );
239 aGridLay->addWidget( myRotXSpn2, 0, 1 );
240 myRotXSpn2->setValue( 0 );
241 myRotYLbl2 = new QLabel( tr( "LBL_ROT_Y" ), aRotBox2 );
242 aGridLay->addWidget( myRotYLbl2, 1, 0 );
243 myRotYSpn2 = new SalomeApp_DoubleSpinBox( aRotBox2 );
244 VISU::initSpinBox( myRotYSpn2, -45., 45., 5., "angle_precision" );
245 aGridLay->addWidget( myRotYSpn2, 1, 1 );
246 myRotYSpn2->setValue( 0 );
247 aLinesLayout->addWidget( aRotBox2 );
249 QWidget* aNbBox = new QWidget(aLinesPane);
250 aHBLay = new QHBoxLayout( aNbBox );
251 aHBLay->setSpacing(5);
252 aHBLay->addWidget( new QLabel( tr( "LBL_NB_PLANS" ), aNbBox ) );
253 myNbSpn = new SalomeApp_DoubleSpinBox( aNbBox );
254 VISU::initSpinBox( myNbSpn, 1., 100., 1., "parametric_precision" );
255 myNbSpn->setValue( 10 );
256 aHBLay->addWidget( myNbSpn );
258 aLinesLayout->addWidget( aNbBox );
260 myPosTable = new QTableWidget(aLinesPane );
261 myPosTable->setMaximumHeight( 227 );
262 myPosTable->setMinimumWidth( 294 );
263 myPosTable->setColumnCount(2);
264 myPosTable->setRowCount(0);
266 myPosTable->setItemDelegateForColumn( 0,
267 new NumDelegateItem( myPosTable, NumDelegateItem::NV_Real) );
269 myPosTable->setEditTriggers( (QAbstractItemView::EditTriggers)(QAbstractItemView::AllEditTriggers &(~QAbstractItemView::CurrentChanged)));
272 aLabels.append( "Position" );
273 aLabels.append( "Set default" );
274 myPosTable->setHorizontalHeaderLabels( aLabels );
276 aLinesLayout->addWidget( myPosTable );
278 QWidget* aPosBox2 = new QWidget(aLinesPane);
279 aHBLay = new QHBoxLayout( aPosBox2 );
280 aHBLay->setSpacing(5);
281 aHBLay->addWidget( new QLabel( tr( "LBL_POS" ), aPosBox2 ) );
282 myPosSpn2 = new SalomeApp_DoubleSpinBox( aPosBox2 );
283 VISU::initSpinBox( myPosSpn2, 0., 1., .1, "parametric_precision" );
284 myPosSpn2->setValue( 0.5 );
285 aHBLay->addWidget( myPosSpn2 );
288 aLinesLayout->addWidget( aPosBox2 );
289 aLinesLayout->addStretch();
291 myTabBox->addTab( aLinesPane, tr("LBL_LINES_CUT") );
293 myInputPane = new VisuGUI_InputPane(VISU::TCUTLINES, theModule, this);
294 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
295 myTabBox->addTab(myInputPane, "Input");
297 aMainLayout->addWidget(myTabBox);
300 QFrame* aBtnBox = new QFrame(this);
301 aHBLay = new QHBoxLayout( aBtnBox );
302 aBtnBox->setFrameStyle(QFrame::Box | QFrame::Sunken);
303 aBtnBox->setLineWidth( 1 );
304 //aHBLay->setAutoAdd( false );
305 aHBLay->setSpacing( 5 );
306 aHBLay->setMargin( 11 );
308 QPushButton* aOkBtn = new QPushButton (tr("BUT_OK"), aBtnBox);
309 aOkBtn->setAutoDefault( TRUE );
310 aOkBtn->setDefault( true );
311 aHBLay->addWidget(aOkBtn);
313 aHBLay->addStretch();
315 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CANCEL"), aBtnBox);
316 aHBLay->addWidget(aCloseBtn);
318 QPushButton* aHelpBtn = new QPushButton(tr("BUT_HELP"), aBtnBox);
319 aHBLay->addWidget(aHelpBtn);
321 aMainLayout->addWidget(aBtnBox);
323 // signals and slots connections
324 connect(mySelPlane , SIGNAL(buttonClicked(int)) , this, SLOT(onPlaneSelect(int)));
325 connect(myCBSetDef , SIGNAL(toggled(bool)) , this, SLOT(setBaseDefault()));
326 connect(myPosSpn , SIGNAL(valueChanged(double)) , this, SLOT(setBaseDefault()));
327 connect(mySelPlane2 , SIGNAL(buttonClicked(int)) , this, SLOT(onCutSelect(int)));
328 connect(myNbSpn , SIGNAL(valueChanged(double)) , this, SLOT(DrawTable()));
329 connect(myPosTable->horizontalHeader(), SIGNAL(sectionClicked(int)) , this, SLOT(setDefault(int)));
330 connect(myPosSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(DrawTable()));
331 connect(myPreviewCheck, SIGNAL(toggled(bool)) , this, SLOT(onPreviewCheck(bool)));
332 connect(myAllCurvesInvertedCheck, SIGNAL(toggled(bool)),this, SLOT(onAllCurvesInvertedCheck(bool)));
333 connect(myPosTable , SIGNAL(cellChanged(int, int)), this, SLOT(onValueChanged(int, int)));
334 connect(myRotXSpn , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
335 connect(myRotYSpn , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
336 connect(myRotXSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
337 connect(myRotYSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
338 connect(myBasePlanePos, SIGNAL(textChanged(const QString&)), this, SLOT(onPlanePos(const QString&)));
339 connect(myCreateTable , SIGNAL(toggled(bool)), myCurvesCheck, SLOT(setEnabled(bool)));
341 connect(aOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
342 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
343 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
349 VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg()
352 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
356 //------------------------------------------------------------------------------
357 void VisuGUI_CutLinesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
361 myPrsCopy = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
363 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
365 myRotXSpn->setValue(myPrsCopy->GetRotateX()*180./M_PI);
366 myRotYSpn->setValue(myPrsCopy->GetRotateY()*180./M_PI);
367 myPosSpn->setValue(myPrsCopy->GetDisplacement());
368 setOrientation(myPrsCopy->GetOrientationType());
370 myNbSpn->setValue( (int)myPrsCopy->GetNbLines() );
371 myRotXSpn2->setValue(myPrsCopy->GetRotateX2()*180./M_PI);
372 myRotYSpn2->setValue(myPrsCopy->GetRotateY2()*180./M_PI);
373 myPosSpn2->setValue(myPrsCopy->GetDisplacement2());
374 setOrientation2(myPrsCopy->GetOrientationType2());
377 myCutLines = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(myPrsCopy, VISU::ColoredPrs3d_i::EDoNotPublish);
378 myCutLines->CopyCurvesInverted(myPrsCopy->GetCurvesInverted());
379 myAllCurvesInvertedCheck->setChecked( myCutLines->IsAllCurvesInverted() );
380 myUseAbsoluteLengthCheck->setChecked( myCutLines->IsUseAbsoluteLength() );
381 myBasePlanePos->setText( QString::number(myCutLines->GetBasePlanePosition()) );
382 myCBSetDef->setChecked(myPrsCopy->IsDefault());
386 if (myPreviewCheck->isChecked()) {
393 myInputPane->initFromPrsObject( myPrsCopy );
394 myTabBox->setCurrentIndex( 0 );
397 //------------------------------------------------------------------------------
398 int VisuGUI_CutLinesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
400 if(!myInputPane->check() || !GetScalarPane()->check())
403 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
404 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
406 myPrsCopy->SetOrientation(getOrientaion(),
407 myRotXSpn->value()*M_PI/180.,
408 myRotYSpn->value()*M_PI/180.);
409 myPrsCopy->SetDisplacement(myPosSpn->value());
410 myPrsCopy->SetNbLines((int)myNbSpn->value());
412 myPrsCopy->SetOrientation2(getOrientaion(false),
413 myRotXSpn2->value()*M_PI/180.,
414 myRotYSpn2->value()*M_PI/180.);
415 myPrsCopy->SetDisplacement2(myPosSpn2->value());
417 if (!myCBSetDef->isChecked())
418 myPrsCopy->SetBasePlanePosition(myBasePlanePos->text().toDouble());
419 else myPrsCopy->SetDefault();
421 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
424 for (int i = 0; i < (int)myNbSpn->value(); ++i)
426 QTableWidgetItem* aItem = myPosTable->item( i, 1 );
427 if (aItem == 0) break;
428 if (aItem->checkState() != Qt::Checked )
430 QVariant aVar = aModel->index( i, 0 ).data();
431 myPrsCopy->SetLinePosition( i, aVar.toDouble() );
434 myPrsCopy->SetDefaultPosition(i);
438 myPrsCopy->SetAllCurvesInverted( myAllCurvesInvertedCheck->isChecked() );
439 myPrsCopy->SetUseAbsoluteLength( myUseAbsoluteLengthCheck->isChecked() );
441 VISU::TSameAsFactory<VISU::TCUTLINES>().Copy(myPrsCopy, thePrs);
446 //------------------------------------------------------------------------------
447 void VisuGUI_CutLinesDlg::createPlanes()
449 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
450 if (aView == NULL) return;
451 if (!(bool)myCutLines) return;
452 if (myPreviewActor != 0) return;
454 storeToPrsObject(myCutLines);
455 myCutLines->GetPipeLine()->Update();
456 vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
457 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
458 aPlaneMapper->SetInput(aPolyData->GetOutput());
459 aPlaneMapper->ScalarVisibilityOff();
461 myPreviewActorGlyphs = SALOME_Actor::New();
462 myPreviewActorGlyphs->PickableOff();
465 myPreviewActor = SALOME_Actor::New();
466 myPreviewActor->PickableOff();
467 myPreviewActor->SetMapper(aPlaneMapper);
468 aPlaneMapper->Delete();
469 aView->AddActor(myPreviewActor);
470 aView->AddActor(myPreviewActorGlyphs);
471 aView->getRenderer()->Render();
475 //------------------------------------------------------------------------------
476 void VisuGUI_CutLinesDlg::deletePlanes()
478 if (myPreviewActor == 0) return;
479 vtkRenderer* aRend = myPreviewActor->GetRenderer();
480 vtkRenderer* aRendGlyphs = myPreviewActorGlyphs->GetRenderer();
482 vtkRenderWindow* aWnd1 = aRend->GetRenderWindow();
483 vtkRenderWindow* aWnd2 = aRendGlyphs->GetRenderWindow();
485 myPreviewActor->RemoveFromRender(aRend);
486 if(aRendGlyphs && aWnd2)
487 myPreviewActorGlyphs->RemoveFromRender(aRendGlyphs);
489 myPreviewActor->Delete();
490 myPreviewActorGlyphs->Delete();
492 myPreviewActorGlyphs = 0;
496 //------------------------------------------------------------------------------
497 void VisuGUI_CutLinesDlg::onPlaneSelect (int theId)
499 QList<QAbstractButton*> aBtns = mySelPlane2->buttons();
500 for (QList<QAbstractButton*>::Iterator it = aBtns.begin();
501 it != aBtns.end(); it++ )
502 (*it)->setEnabled(true);
504 QAbstractButton* aBtn = mySelPlane2->button(theId);
505 aBtn->setEnabled(false);
508 myRotXLbl->setText( tr("LBL_ROT_X"));
509 myRotYLbl->setText( tr("LBL_ROT_Y"));
510 mySelPlane2->button(1)->setChecked(true);
511 onCutSelect(1, false);
514 myRotXLbl->setText( tr("LBL_ROT_Y"));
515 myRotYLbl->setText( tr("LBL_ROT_Z"));
516 mySelPlane2->button(2)->setChecked(true);
517 onCutSelect(2, false);
520 myRotXLbl->setText( tr("LBL_ROT_Z"));
521 myRotYLbl->setText( tr("LBL_ROT_X"));
522 mySelPlane2->button(0)->setChecked(true);
523 onCutSelect(0, false);
525 setBaseDefault(false);
529 //------------------------------------------------------------------------------
530 void VisuGUI_CutLinesDlg::onCutSelect (int theId, bool theUpdate)
534 myRotXLbl2->setText( tr("LBL_ROT_X"));
535 myRotYLbl2->setText( tr("LBL_ROT_Y"));
538 myRotXLbl2->setText( tr("LBL_ROT_Y"));
539 myRotYLbl2->setText( tr("LBL_ROT_Z"));
542 myRotXLbl2->setText( tr("LBL_ROT_Z"));
543 myRotYLbl2->setText( tr("LBL_ROT_X"));
545 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
547 if (theUpdate && myPreviewCheck->isChecked() && (bool)myCutLines) {
554 //------------------------------------------------------------------------------
555 void VisuGUI_CutLinesDlg::setBaseDefault (bool theUpdate)
557 if (!hasInit) return;
559 if (myCBSetDef->isChecked()) {
560 if (!myCutLines->IsDefault()) myCutLines->SetDefault();
561 myCutLines->SetDisplacement(myPosSpn->value());
562 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
564 if (theUpdate && myPreviewCheck->isChecked() && (bool)myCutLines) {
569 vtkFloatingPointType aPos = myCutLines->GetBasePlanePosition();
570 myBasePlanePos->setText( QString::number(aPos) );
571 myBasePlanePos->setEnabled(false);
573 myBasePlanePos->setEnabled(true);
577 //------------------------------------------------------------------------------
578 void VisuGUI_CutLinesDlg::DrawTable()
580 if (!hasInit) return;
582 int aNbRows = myPosTable->rowCount();
583 int aNbPlanes = (int)myNbSpn->value();
585 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
589 myCutLines->SetOrientation(getOrientaion(),
590 myRotXSpn->value()*M_PI/180.,
591 myRotYSpn->value()*M_PI/180.);
593 myCutLines->SetNbLines(aNbPlanes);
594 myCutLines->SetDisplacement2(myPosSpn2->value());
595 myCutLines->SetOrientation2(getOrientaion(false),
596 myRotXSpn2->value()*M_PI/180.,
597 myRotYSpn2->value()*M_PI/180.);
600 for (int i = 0; i < aNbRows; ++i)
602 QTableWidgetItem* aItem = myPosTable->item( i, 1 );
603 if (aItem == 0) break;
604 if (aItem->checkState() != Qt::Checked )
606 QVariant aVar = aModel->index( i, 0 ).data();
607 myCutLines->SetLinePosition(i, aVar.toDouble());
611 //if (aNbPlanes > aNbRows)
612 // myPosTable->addRows(aNbRows, aNbPlanes - aNbRows );
613 //else if (aNbPlanes < aNbRows)
614 //myPosTable->setRowCount(aNbPlanes);
615 if (aNbPlanes > aNbRows)
616 while( aNbPlanes > myPosTable->rowCount() )
617 myPosTable->insertRow( myPosTable->rowCount() );
618 else if (aNbPlanes < aNbRows)
619 myPosTable->setRowCount(aNbPlanes);
621 QString str("Plane# %1");
623 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
624 for (int i = 0; i<aMin; i++)
626 QModelIndex anIndex = aModel->index( i, 0 );
627 aModel->setData( anIndex, QVariant( myCutLines->GetLinePosition(i) ), Qt::DisplayRole );
628 //myPosTable->setText(i, 0, QString::number(myCutLines->GetLinePosition(i)));
629 myPosTable->item( i, 1 )->setCheckState(myCutLines->IsDefaultPosition(i) ? Qt::Checked : Qt::Unchecked );
630 aLabels.append( str.arg(i+1) );
633 //QHeader *vh = myPosTable->verticalHeader();
634 for (int i=aMin; i<aNbPlanes; i++) {
635 /*VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem
636 (myPosTable, QTableItem::OnTyping, QString::number(myCutLines->GetLinePosition(i)));*/
637 QTableWidgetItem* aEditItem = new QTableWidgetItem();
638 aEditItem->setText( QString::number(myCutLines->GetLinePosition(i)) );
639 //aEditItem->setReplaceable(false);
640 //aEditItem->setEnabled(!myCutLines->IsDefaultPosition(i));
641 Qt::ItemFlags aFlags = aEditItem->flags();
642 if ( myCutLines->IsDefaultPosition(i) )
643 aFlags |= Qt::ItemIsEnabled;
645 aFlags &= (~Qt::ItemIsEnabled);
647 myPosTable->setItem(i, 0, aEditItem);
649 /*QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
650 aCheck->setChecked(myCutLines->IsDefaultPosition(i));
651 aCheck->setReplaceable(false);
652 myPosTable->setItem(i, 1, aCheck);*/
654 QTableWidgetItem* aCheck = new QTableWidgetItem();
655 aCheck->setCheckState( myCutLines->IsDefaultPosition(i) ?
656 Qt::Checked : Qt::Unchecked );
657 myPosTable->setItem(i, 1, aCheck);
659 //vh->setLabel( i, str.arg(i+1) );
660 aLabels.append( str.arg(i+1) );
662 myPosTable->setVerticalHeaderLabels( aLabels );
664 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
666 if (myPreviewCheck->isChecked()) {
673 void VisuGUI_CutLinesDlg::updateGlyphs(bool update){
674 if (myPreviewActorGlyphs == 0 ) return;
675 const vtkFloatingPointType *aDirLn = myCutLines->GetSpecificPL()->GetRealDirLn();
676 vtkFloatingPointType aSecondPnt[3];
677 vtkFloatingPointType aBoundCenter[3];
679 vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
680 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
681 aPlaneMapper->SetInput(aPolyData->GetOutput());
682 vtkFloatingPointType bounds[6];
683 aPlaneMapper->GetBounds(bounds);
685 for(int i=0; i<3; i++) aBoundCenter[i] = (bounds[i*2] + bounds[i*2+1])/2.0;
686 for(int i=0; i<3; i++){
687 if (!myAllCurvesInvertedCheck->isChecked())
688 aSecondPnt[i] = aDirLn[i];
690 aSecondPnt[i] = - aDirLn[i];
693 vtkFloatingPointType max_bound = 0;
694 max_bound < bounds[1]-bounds[0] ? max_bound = bounds[1] - bounds[0] : max_bound = max_bound;
695 max_bound < bounds[3]-bounds[2] ? max_bound = bounds[3] - bounds[2] : max_bound = max_bound;
696 max_bound < bounds[5]-bounds[4] ? max_bound = bounds[5] - bounds[4] : max_bound = max_bound;
698 vtkPolyData* profile = vtkPolyData::New();
699 vtkPoints* aPoints = vtkPoints::New();
700 vtkGlyph3D* glyphs = vtkGlyph3D::New();
701 vtkFloatArray *aFloatArray = vtkFloatArray::New();
702 vtkGlyphSource2D* source = vtkGlyphSource2D::New();
705 source->SetGlyphTypeToArrow();
707 aPoints->InsertNextPoint(aBoundCenter);
708 profile->SetPoints(aPoints);
710 aFloatArray->SetNumberOfComponents(3);
711 for(int i=0; i<3 ;i++)
712 aFloatArray->InsertNextValue(aSecondPnt[i]);
714 vtkDataSetAttributes* aDataSetAttributes;
715 aDataSetAttributes = profile->GetPointData();
716 aDataSetAttributes->SetVectors(aFloatArray);
718 glyphs->SetScaleFactor(0.25*max_bound);
719 glyphs->SetVectorModeToUseVector();
720 glyphs->SetScaleModeToScaleByVector();
721 glyphs->SetInput(profile);
722 glyphs->SetSource(source->GetOutput());
724 vtkPolyDataMapper* aGlyphsMapper = vtkPolyDataMapper::New();
725 aGlyphsMapper->ScalarVisibilityOff();
726 aGlyphsMapper->SetInput(glyphs->GetOutput());
728 myPreviewActorGlyphs->SetMapper(aGlyphsMapper);
733 aGlyphsMapper->Delete();
734 aFloatArray->Delete();
736 aPlaneMapper->Delete();
738 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
743 //------------------------------------------------------------------------------
744 void VisuGUI_CutLinesDlg::setDefault (int all)
746 myPosTable->setCurrentCell(0, 0);
747 myPosTable->clearSelection();
749 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
753 if (all == 0) return;
755 for (int i = 0; i < (int)myNbSpn->value(); ++i)
756 myPosTable->item( i, 1 )->setCheckState(Qt::Checked);
758 for (int i = 0; i < (int)myNbSpn->value(); ++i)
760 if ( myPosTable->item( i, 1 )->checkState() == Qt::Checked )
762 myCutLines->SetDefaultPosition(i);
763 QModelIndex anIndex = aModel->index( i, 0 );
764 aModel->setData( anIndex, QVariant( myCutLines->GetLinePosition(i) ), Qt::DisplayRole );
765 //myPosTable->setText( i, 0, QString::number(myCutLines->GetLinePosition(i)));
766 //myPosTable->item( i, 0 )->setEnabled(false);
767 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() &(~Qt::ItemIsEnabled ) );
770 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() | Qt::ItemIsEnabled );
774 //------------------------------------------------------------------------------
775 VISU::CutPlanes::Orientation VisuGUI_CutLinesDlg::getOrientaion (bool IsBasePlane)
784 VISU::CutPlanes::Orientation orient;
785 switch (aBG->id(aBG->checkedButton())) {
787 orient = VISU::CutPlanes::XY;
790 orient = VISU::CutPlanes::YZ;
793 orient = VISU::CutPlanes::ZX;
798 //------------------------------------------------------------------------------
799 void VisuGUI_CutLinesDlg::setOrientation (const VISU::CutPlanes::Orientation orient)
802 case VISU::CutPlanes::XY:
803 mySelPlane->button(0)->setChecked(true);
806 case VISU::CutPlanes::YZ:
807 mySelPlane->button(1)->setChecked(true);
810 case VISU::CutPlanes::ZX:
811 mySelPlane->button(2)->setChecked(true);
816 //------------------------------------------------------------------------------
817 void VisuGUI_CutLinesDlg::setOrientation2 (const VISU::CutPlanes::Orientation orient)
820 case VISU::CutPlanes::XY:
821 mySelPlane2->button(0)->setChecked(true);
824 case VISU::CutPlanes::YZ:
825 mySelPlane2->button(1)->setChecked(true);
828 case VISU::CutPlanes::ZX:
829 mySelPlane2->button(2)->setChecked(true);
834 void VisuGUI_CutLinesDlg::onValueChanged (int theRow, int theCol)
836 /*QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
840 QModelIndex anIndex = aModel->index( theRow, theCol );
844 bool isChanged = !anIndex.data().isNull();
845 myPosTable->item(theRow, 1)->setCheckState(!isChanged ? Qt::Checked : Qt::Unchecked);
846 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
849 if (myPreviewCheck->isChecked())
856 else if (theCol == 1)
858 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
861 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
864 if (myPreviewCheck->isChecked())
870 aModel->setData( anIndex, myCutLines->GetLinePosition(theRow), Qt::DisplayRole );
871 myPosTable->item( theRow, 0 )->setFlags( myPosTable->item( theRow, 0 )->flags() | Qt::ItemIsEnabled );
874 myPosTable->item( theRow, 0 )->setFlags( myPosTable->item( theRow, 0 )->flags() &(~Qt::ItemIsEnabled ) );
877 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
881 if ( !myPosTable->item(theRow, 1) || !myPosTable->item(theRow, 0) )
886 QTableWidgetItem* anItem = myPosTable->item(theRow, theCol);
890 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
893 anIndex = aModel->index( theRow, 0 );
895 //myCutLines->SetLinePosition( theRow, anIndex.data().toDouble());
898 if ( myPreviewCheck->isChecked() )
901 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
903 //myCutLines->GetPipeLine()->Update();
912 anItem = myPosTable->item(theRow, 0);
913 Qt::ItemFlags flags = anItem->flags();
916 myCutLines->SetDefaultPosition(theRow);
917 anIndex = aModel->index( theRow, 0 );
918 aModel->setData( anIndex, myCutLines->GetLinePosition(theRow), Qt::DisplayRole );
920 /*if ( myPreviewCheck->isChecked() )
922 //not needed update presentation, because item->setFlags generates signal cellChanged() again
924 flags &= (~Qt::ItemIsEnabled );
927 flags |= Qt::ItemIsEnabled;
929 anItem->setFlags( flags );
933 void VisuGUI_CutLinesDlg::accept()
935 VisuGUI_ScalarBarBaseDlg::accept();
938 void VisuGUI_CutLinesDlg::reject()
940 VisuGUI_ScalarBarBaseDlg::reject();
943 void VisuGUI_CutLinesDlg::onPreviewCheck (bool thePreview)
945 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
955 /*! Inverting all curves in the table
957 void VisuGUI_CutLinesDlg::onAllCurvesInvertedCheck(bool theInvert)
959 bool anIsAllCurvesInverted = myAllCurvesInvertedCheck->isChecked();
961 myCutLines->SetAllCurvesInverted( anIsAllCurvesInverted );
962 myPrsCopy->SetAllCurvesInverted( anIsAllCurvesInverted );
967 void VisuGUI_CutLinesDlg::onRotation (double theValue)
969 if (!(bool)myCutLines) return;
970 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
972 if (myPreviewCheck->isChecked()) {
979 void VisuGUI_CutLinesDlg::onPlanePos (const QString& theValue)
981 if (!(bool)myCutLines) return;
982 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
984 if (myPreviewCheck->isChecked()) {
991 QString VisuGUI_CutLinesDlg::GetContextHelpFilePath()
993 return "cut_lines_page.html";