1 // Copyright (C) 2007-2010 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
23 // File : VisuGUI_CutLinesDlg.cxx
27 #include "VisuGUI_CutLinesDlg.h"
29 #include "VISU_ColoredPrs3dFactory.hh"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_ViewTools.h"
34 #include "VisuGUI_InputPane.h"
36 #include "VISU_Gen_i.hh"
37 #include "VISU_CutLines_i.hh"
38 #include "VISU_ColoredPrs3dFactory.hh"
40 #include "VISU_PipeLine.hxx"
41 #include "VISU_PipeLineUtils.hxx"
42 #include "VISU_CutLinesPL.hxx"
44 #include "SVTK_ViewWindow.h"
46 #include "LightApp_Application.h"
47 #include "SalomeApp_Study.h"
48 #include <SalomeApp_DoubleSpinBox.h>
50 #include "SUIT_Desktop.h"
51 #include "SUIT_Session.h"
52 #include "SUIT_MessageBox.h"
53 #include "SUIT_ResourceMgr.h"
56 //#include "OB_Browser.h"
58 #include "VISU_TableDlg.h"
64 #include <QButtonGroup>
67 #include <QPushButton>
68 #include <QHeaderView>
69 #include <QRadioButton>
70 #include <QTableWidget>
72 #include <vtkRenderer.h>
73 #include <vtkPolyData.h>
74 #include <vtkAppendPolyData.h>
75 #include <vtkDataSetMapper.h>
76 #include <vtkGlyph3D.h>
77 #include <vtkPolyDataMapper.h>
78 #include <vtkFloatArray.h>
79 #include <vtkGlyphSource2D.h>
83 VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (SalomeApp_Module* theModule)
84 : VisuGUI_ScalarBarBaseDlg(theModule),
86 myPreviewActorGlyphs(0)
88 setWindowTitle("Cut Lines Definition");
89 setSizeGripEnabled(true);
91 QVBoxLayout* aMainLayout = new QVBoxLayout (this);
92 aMainLayout->setMargin( 7 );
93 aMainLayout->setSpacing(5);
95 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
99 myTabBox = new QTabWidget(this);
102 QFrame* aPlanePane = new QFrame(this);
103 QVBoxLayout* aPlaneLayout = new QVBoxLayout(aPlanePane);
104 aPlaneLayout->setMargin( 5 );
105 aPlaneLayout->setSpacing(6);
107 mySelPlane = new QButtonGroup( aPlanePane);
108 QGroupBox* aGB = new QGroupBox( tr( "TXT_ORIENTATION" ), aPlanePane );
109 QHBoxLayout* aHBLay = new QHBoxLayout( aGB );
110 //mySelPlane->setInsideSpacing( 5 );
111 //mySelPlane->setInsideMargin( 5 );
113 QRadioButton* aBxy = new QRadioButton( tr( "PARALLEL_XOY" ), aGB); // 0
114 QRadioButton* aByz = new QRadioButton( tr( "PARALLEL_YOZ" ), aGB); // 1
115 QRadioButton* aBzx = new QRadioButton( tr( "PARALLEL_ZOX" ), aGB); // 2
116 //aBxy->setChecked(false);
117 //aByz->setChecked(false);
118 aHBLay->addWidget( aBxy );
119 aHBLay->addWidget( aByz );
120 aHBLay->addWidget( aBzx );
122 mySelPlane->addButton( aBxy, 0 );
123 mySelPlane->addButton( aByz, 1 );
124 mySelPlane->addButton( aBzx, 2 );
126 aBzx->setChecked(true);
128 aPlaneLayout->addWidget( aGB );
130 QGroupBox* aRotBox = new QGroupBox( tr( "LBL_ROTATION" ), aPlanePane );
131 //aRotBox->setColumnLayout(2, Qt::Horizontal );
132 QGridLayout* aGridLay = new QGridLayout( aRotBox );
134 myRotXLbl = new QLabel( tr( "LBL_ROT_X" ), aRotBox);
135 aGridLay->addWidget( myRotXLbl, 0, 0 );
136 myRotXSpn = new SalomeApp_DoubleSpinBox( aRotBox );
137 VISU::initSpinBox( myRotXSpn, -45., 45., 5., "angle_precision" );
138 aGridLay->addWidget( myRotXSpn, 0, 1 );
139 myRotXSpn->setValue( 0 );
140 myRotYLbl = new QLabel( tr( "LBL_ROT_Y" ), aRotBox );
141 aGridLay->addWidget( myRotYLbl, 1, 0 );
142 myRotYSpn = new SalomeApp_DoubleSpinBox( aRotBox );
143 VISU::initSpinBox( myRotYSpn, -45., 45., 5., "angle_precision" );
144 aGridLay->addWidget( myRotYSpn, 1, 1 );
145 myRotYSpn->setValue( 0 );
147 aPlaneLayout->addWidget( aRotBox );
149 QGroupBox* aBaseBox = new QGroupBox (tr("BASE_PLANE_POS"), aPlanePane);
150 aHBLay = new QHBoxLayout( aBaseBox );
151 myBasePlanePos = new QLineEdit (aBaseBox);
152 aHBLay->addWidget( myBasePlanePos );
153 mydvalidator = new QDoubleValidator(this);
154 mydvalidator->setDecimals(32);
155 myBasePlanePos->setValidator(mydvalidator);
157 myCBSetDef = new QCheckBox (tr("SET_DEFAULT"),aBaseBox);
158 aHBLay->addWidget( myCBSetDef );
160 aPlaneLayout->addWidget(aBaseBox);
162 QWidget* aPosBox = new QWidget (aPlanePane);
163 aHBLay = new QHBoxLayout( aPosBox );
164 aHBLay->setSpacing(5);
166 aHBLay->addWidget( new QLabel (tr("LBL_POS"), aPosBox) );
167 myPosSpn = new SalomeApp_DoubleSpinBox (aPosBox);
168 VISU::initSpinBox( myPosSpn, 0., 1., .1, "parametric_precision" );
169 myPosSpn->setValue(0.5);
170 aHBLay->addWidget( myPosSpn );
171 aPlaneLayout->addWidget(aPosBox);
173 myPreviewCheck = new QCheckBox (tr("LBL_SHOW_PREVIEW"), aPlanePane);
174 myPreviewCheck->setChecked( aResourceMgr->booleanValue("VISU", "show_preview", false) );
175 aPlaneLayout->addWidget(myPreviewCheck);
177 myAllCurvesInvertedCheck = new QCheckBox(tr("LBL_INVERT_CURVES"), aPlanePane);
178 myAllCurvesInvertedCheck->setChecked(false);
179 aPlaneLayout->addWidget(myAllCurvesInvertedCheck);
181 myUseAbsoluteLengthCheck = new QCheckBox(tr("LBL_ABSOLUTE_LENGTH"), aPlanePane);
182 myUseAbsoluteLengthCheck->setChecked(false);
183 aPlaneLayout->addWidget(myUseAbsoluteLengthCheck);
185 myCreateTable = new QCheckBox (tr("LBL_GENERATE_TABLE"), aPlanePane);
186 myCreateTable->setChecked( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
187 aPlaneLayout->addWidget( myCreateTable );
189 QWidget* aCheckPane = new QWidget(aPlanePane);
190 aHBLay = new QHBoxLayout( aCheckPane );
191 aHBLay->setMargin( 0 );
192 aHBLay->setSpacing( 0 );
193 aHBLay->insertSpacing( 0, 20 );
194 myCurvesCheck = new QCheckBox(tr("LBL_GENERATE_CURVES"), aCheckPane);
195 aHBLay->addWidget( myCurvesCheck );
196 myCurvesCheck->setChecked( aResourceMgr->booleanValue("VISU", "generate_curves", true) );
197 myCurvesCheck->setEnabled( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
198 aPlaneLayout->addWidget( aCheckPane );
200 aPlaneLayout->addStretch();
202 myTabBox->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
205 QFrame* aLinesPane = new QFrame(this);
206 QVBoxLayout* aLinesLayout = new QVBoxLayout( aLinesPane );
207 aLinesLayout->setMargin( 5 );
208 aLinesLayout->setSpacing( 6 );
210 mySelPlane2 = new QButtonGroup( aLinesPane);
211 aGB = new QGroupBox( tr( "TXT_ORIENTATION" ), aLinesPane );
212 aHBLay = new QHBoxLayout( aGB );
213 //mySelPlane2->setInsideSpacing( 5 );
214 //mySelPlane2->setInsideMargin( 5 );
216 QRadioButton* aBxy2 = new QRadioButton( tr( "PARALLEL_XOY" ), aGB); // 0
217 QRadioButton* aByz2 = new QRadioButton( tr( "PARALLEL_YOZ" ), aGB); // 1
218 QRadioButton* aBzx2 = new QRadioButton( tr( "PARALLEL_ZOX" ), aGB); // 2
220 aHBLay->addWidget( aBxy2 );
221 aHBLay->addWidget( aByz2 );
222 aHBLay->addWidget( aBzx2 );
224 mySelPlane2->addButton( aBxy2, 0 );
225 mySelPlane2->addButton( aByz2, 1 );
226 mySelPlane2->addButton( aBzx2, 2 );
228 aBzx2->setEnabled(false);
229 aByz2->setChecked(true);
230 aLinesLayout->addWidget( aGB );
232 QGroupBox* aRotBox2 = new QGroupBox( tr( "LBL_ROTATION" ), aLinesPane );
233 //aRotBox2->setColumnLayout(2, Qt::Horizontal );
234 aGridLay = new QGridLayout( aRotBox2 );
236 myRotXLbl2 = new QLabel( tr( "LBL_ROT_X" ), aRotBox2);
237 aGridLay->addWidget( myRotXLbl2, 0, 0 );
238 myRotXSpn2 = new SalomeApp_DoubleSpinBox( aRotBox2 );
239 VISU::initSpinBox( myRotXSpn2, -45., 45., 5., "angle_precision" );
240 aGridLay->addWidget( myRotXSpn2, 0, 1 );
241 myRotXSpn2->setValue( 0 );
242 myRotYLbl2 = new QLabel( tr( "LBL_ROT_Y" ), aRotBox2 );
243 aGridLay->addWidget( myRotYLbl2, 1, 0 );
244 myRotYSpn2 = new SalomeApp_DoubleSpinBox( aRotBox2 );
245 VISU::initSpinBox( myRotYSpn2, -45., 45., 5., "angle_precision" );
246 aGridLay->addWidget( myRotYSpn2, 1, 1 );
247 myRotYSpn2->setValue( 0 );
248 aLinesLayout->addWidget( aRotBox2 );
250 QWidget* aNbBox = new QWidget(aLinesPane);
251 aHBLay = new QHBoxLayout( aNbBox );
252 aHBLay->setSpacing(5);
253 aHBLay->addWidget( new QLabel( tr( "LBL_NB_PLANS" ), aNbBox ) );
254 myNbSpn = new SalomeApp_DoubleSpinBox( aNbBox );
255 VISU::initSpinBox( myNbSpn, 1., 100., 1., "parametric_precision" );
256 myNbSpn->setValue( 10 );
257 aHBLay->addWidget( myNbSpn );
259 aLinesLayout->addWidget( aNbBox );
261 myPosTable = new QTableWidget(aLinesPane );
262 myPosTable->setMaximumHeight( 227 );
263 myPosTable->setMinimumWidth( 294 );
264 myPosTable->setColumnCount(2);
265 myPosTable->setRowCount(0);
267 myPosTable->setItemDelegateForColumn( 0,
268 new NumDelegateItem( myPosTable, NumDelegateItem::NV_Real) );
270 myPosTable->setEditTriggers( (QAbstractItemView::EditTriggers)(QAbstractItemView::AllEditTriggers &(~QAbstractItemView::CurrentChanged)));
273 aLabels.append( "Position" );
274 aLabels.append( "Set default" );
275 myPosTable->setHorizontalHeaderLabels( aLabels );
277 aLinesLayout->addWidget( myPosTable );
279 QWidget* aPosBox2 = new QWidget(aLinesPane);
280 aHBLay = new QHBoxLayout( aPosBox2 );
281 aHBLay->setSpacing(5);
282 aHBLay->addWidget( new QLabel( tr( "LBL_POS" ), aPosBox2 ) );
283 myPosSpn2 = new SalomeApp_DoubleSpinBox( aPosBox2 );
284 VISU::initSpinBox( myPosSpn2, 0., 1., .1, "parametric_precision" );
285 myPosSpn2->setValue( 0.5 );
286 aHBLay->addWidget( myPosSpn2 );
289 aLinesLayout->addWidget( aPosBox2 );
290 aLinesLayout->addStretch();
292 myTabBox->addTab( aLinesPane, tr("LBL_LINES_CUT") );
294 myInputPane = new VisuGUI_InputPane(VISU::TCUTLINES, theModule, this);
295 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
296 myTabBox->addTab(myInputPane, "Input");
298 aMainLayout->addWidget(myTabBox);
301 QFrame* aBtnBox = new QFrame(this);
302 aHBLay = new QHBoxLayout( aBtnBox );
303 aBtnBox->setFrameStyle(QFrame::Box | QFrame::Sunken);
304 aBtnBox->setLineWidth( 1 );
305 //aHBLay->setAutoAdd( false );
306 aHBLay->setSpacing( 5 );
307 aHBLay->setMargin( 11 );
309 QPushButton* aOkBtn = new QPushButton (tr("BUT_OK"), aBtnBox);
310 aOkBtn->setAutoDefault( TRUE );
311 aOkBtn->setDefault( true );
312 aHBLay->addWidget(aOkBtn);
314 aHBLay->addStretch();
316 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CANCEL"), aBtnBox);
317 aHBLay->addWidget(aCloseBtn);
319 QPushButton* aHelpBtn = new QPushButton(tr("BUT_HELP"), aBtnBox);
320 aHBLay->addWidget(aHelpBtn);
322 aMainLayout->addWidget(aBtnBox);
324 // signals and slots connections
325 connect(mySelPlane , SIGNAL(buttonClicked(int)) , this, SLOT(onPlaneSelect(int)));
326 connect(myCBSetDef , SIGNAL(toggled(bool)) , this, SLOT(setBaseDefault()));
327 connect(myPosSpn , SIGNAL(valueChanged(double)) , this, SLOT(setBaseDefault()));
328 connect(mySelPlane2 , SIGNAL(buttonClicked(int)) , this, SLOT(onCutSelect(int)));
329 connect(myNbSpn , SIGNAL(valueChanged(double)) , this, SLOT(DrawTable()));
330 connect(myPosTable->horizontalHeader(), SIGNAL(sectionClicked(int)) , this, SLOT(setDefault(int)));
331 connect(myPosSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(DrawTable()));
332 connect(myPreviewCheck, SIGNAL(toggled(bool)) , this, SLOT(onPreviewCheck(bool)));
333 connect(myAllCurvesInvertedCheck, SIGNAL(toggled(bool)),this, SLOT(onAllCurvesInvertedCheck(bool)));
334 connect(myPosTable , SIGNAL(cellChanged(int, int)), this, SLOT(onValueChanged(int, int)));
335 connect(myRotXSpn , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
336 connect(myRotYSpn , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
337 connect(myRotXSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
338 connect(myRotYSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
339 connect(myBasePlanePos, SIGNAL(textChanged(const QString&)), this, SLOT(onPlanePos(const QString&)));
340 connect(myCreateTable , SIGNAL(toggled(bool)), myCurvesCheck, SLOT(setEnabled(bool)));
342 connect(aOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
343 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
344 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
350 VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg()
353 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
357 //------------------------------------------------------------------------------
358 void VisuGUI_CutLinesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
362 myPrsCopy = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
364 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
366 myRotXSpn->setValue(myPrsCopy->GetRotateX()*180./PI);
367 myRotYSpn->setValue(myPrsCopy->GetRotateY()*180./PI);
368 myPosSpn->setValue(myPrsCopy->GetDisplacement());
369 setOrientation(myPrsCopy->GetOrientationType());
371 myNbSpn->setValue( (int)myPrsCopy->GetNbLines() );
372 myRotXSpn2->setValue(myPrsCopy->GetRotateX2()*180./PI);
373 myRotYSpn2->setValue(myPrsCopy->GetRotateY2()*180./PI);
374 myPosSpn2->setValue(myPrsCopy->GetDisplacement2());
375 setOrientation2(myPrsCopy->GetOrientationType2());
378 myCutLines = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(myPrsCopy, VISU::ColoredPrs3d_i::EDoNotPublish);
379 myCutLines->CopyCurvesInverted(myPrsCopy->GetCurvesInverted());
380 myAllCurvesInvertedCheck->setChecked( myCutLines->IsAllCurvesInverted() );
381 myUseAbsoluteLengthCheck->setChecked( myCutLines->IsUseAbsoluteLength() );
382 myBasePlanePos->setText( QString::number(myCutLines->GetBasePlanePosition()) );
383 myCBSetDef->setChecked(myPrsCopy->IsDefault());
387 if (myPreviewCheck->isChecked()) {
394 myInputPane->initFromPrsObject( myPrsCopy );
395 myTabBox->setCurrentIndex( 0 );
398 //------------------------------------------------------------------------------
399 int VisuGUI_CutLinesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
401 if(!myInputPane->check() || !GetScalarPane()->check())
404 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
405 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
407 myPrsCopy->SetOrientation(getOrientaion(),
408 myRotXSpn->value()*PI/180.,
409 myRotYSpn->value()*PI/180.);
410 myPrsCopy->SetDisplacement(myPosSpn->value());
411 myPrsCopy->SetNbLines((int)myNbSpn->value());
413 myPrsCopy->SetOrientation2(getOrientaion(false),
414 myRotXSpn2->value()*PI/180.,
415 myRotYSpn2->value()*PI/180.);
416 myPrsCopy->SetDisplacement2(myPosSpn2->value());
418 if (!myCBSetDef->isChecked())
419 myPrsCopy->SetBasePlanePosition(myBasePlanePos->text().toDouble());
420 else myPrsCopy->SetDefault();
422 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
425 for (int i = 0; i < (int)myNbSpn->value(); ++i)
427 QTableWidgetItem* aItem = myPosTable->item( i, 1 );
428 if (aItem == 0) break;
429 if (aItem->checkState() != Qt::Checked )
431 QVariant aVar = aModel->index( i, 0 ).data();
432 myPrsCopy->SetLinePosition( i, aVar.toDouble() );
435 myPrsCopy->SetDefaultPosition(i);
439 myPrsCopy->SetAllCurvesInverted( myAllCurvesInvertedCheck->isChecked() );
440 myPrsCopy->SetUseAbsoluteLength( myUseAbsoluteLengthCheck->isChecked() );
442 VISU::TSameAsFactory<VISU::TCUTLINES>().Copy(myPrsCopy, thePrs);
447 //------------------------------------------------------------------------------
448 void VisuGUI_CutLinesDlg::createPlanes()
450 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
451 if (aView == NULL) return;
452 if (!(bool)myCutLines) return;
453 if (myPreviewActor != 0) return;
455 storeToPrsObject(myCutLines);
456 myCutLines->GetPipeLine()->Update();
457 vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
458 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
459 aPlaneMapper->SetInput(aPolyData->GetOutput());
460 aPlaneMapper->ScalarVisibilityOff();
462 myPreviewActorGlyphs = SALOME_Actor::New();
463 myPreviewActorGlyphs->PickableOff();
466 myPreviewActor = SALOME_Actor::New();
467 myPreviewActor->PickableOff();
468 myPreviewActor->SetMapper(aPlaneMapper);
469 aPlaneMapper->Delete();
470 aView->AddActor(myPreviewActor);
471 aView->AddActor(myPreviewActorGlyphs);
472 aView->getRenderer()->Render();
476 //------------------------------------------------------------------------------
477 void VisuGUI_CutLinesDlg::deletePlanes()
479 if (myPreviewActor == 0) return;
480 vtkRenderer* aRend = myPreviewActor->GetRenderer();
481 vtkRenderer* aRendGlyphs = myPreviewActorGlyphs->GetRenderer();
483 vtkRenderWindow* aWnd1 = aRend->GetRenderWindow();
484 vtkRenderWindow* aWnd2 = aRendGlyphs->GetRenderWindow();
486 myPreviewActor->RemoveFromRender(aRend);
487 if(aRendGlyphs && aWnd2)
488 myPreviewActorGlyphs->RemoveFromRender(aRendGlyphs);
490 myPreviewActor->Delete();
491 myPreviewActorGlyphs->Delete();
493 myPreviewActorGlyphs = 0;
497 //------------------------------------------------------------------------------
498 void VisuGUI_CutLinesDlg::onPlaneSelect (int theId)
500 QList<QAbstractButton*> aBtns = mySelPlane2->buttons();
501 for (QList<QAbstractButton*>::Iterator it = aBtns.begin();
502 it != aBtns.end(); it++ )
503 (*it)->setEnabled(true);
505 QAbstractButton* aBtn = mySelPlane2->button(theId);
506 aBtn->setEnabled(false);
509 myRotXLbl->setText( tr("LBL_ROT_X"));
510 myRotYLbl->setText( tr("LBL_ROT_Y"));
511 mySelPlane2->button(1)->setChecked(true);
512 onCutSelect(1, false);
515 myRotXLbl->setText( tr("LBL_ROT_Y"));
516 myRotYLbl->setText( tr("LBL_ROT_Z"));
517 mySelPlane2->button(2)->setChecked(true);
518 onCutSelect(2, false);
521 myRotXLbl->setText( tr("LBL_ROT_Z"));
522 myRotYLbl->setText( tr("LBL_ROT_X"));
523 mySelPlane2->button(0)->setChecked(true);
524 onCutSelect(0, false);
526 setBaseDefault(false);
530 //------------------------------------------------------------------------------
531 void VisuGUI_CutLinesDlg::onCutSelect (int theId, bool theUpdate)
535 myRotXLbl2->setText( tr("LBL_ROT_X"));
536 myRotYLbl2->setText( tr("LBL_ROT_Y"));
539 myRotXLbl2->setText( tr("LBL_ROT_Y"));
540 myRotYLbl2->setText( tr("LBL_ROT_Z"));
543 myRotXLbl2->setText( tr("LBL_ROT_Z"));
544 myRotYLbl2->setText( tr("LBL_ROT_X"));
546 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
548 if (theUpdate && myPreviewCheck->isChecked() && (bool)myCutLines) {
555 //------------------------------------------------------------------------------
556 void VisuGUI_CutLinesDlg::setBaseDefault (bool theUpdate)
558 if (!hasInit) return;
560 if (myCBSetDef->isChecked()) {
561 if (!myCutLines->IsDefault()) myCutLines->SetDefault();
562 myCutLines->SetDisplacement(myPosSpn->value());
563 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
565 if (theUpdate && myPreviewCheck->isChecked() && (bool)myCutLines) {
570 vtkFloatingPointType aPos = myCutLines->GetBasePlanePosition();
571 myBasePlanePos->setText( QString::number(aPos) );
572 myBasePlanePos->setEnabled(false);
574 myBasePlanePos->setEnabled(true);
578 //------------------------------------------------------------------------------
579 void VisuGUI_CutLinesDlg::DrawTable()
581 if (!hasInit) return;
583 int aNbRows = myPosTable->rowCount();
584 int aNbPlanes = (int)myNbSpn->value();
586 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
590 myCutLines->SetOrientation(getOrientaion(),
591 myRotXSpn->value()*PI/180.,
592 myRotYSpn->value()*PI/180.);
594 myCutLines->SetNbLines(aNbPlanes);
595 myCutLines->SetDisplacement2(myPosSpn2->value());
596 myCutLines->SetOrientation2(getOrientaion(false),
597 myRotXSpn2->value()*PI/180.,
598 myRotYSpn2->value()*PI/180.);
601 for (int i = 0; i < aNbRows; ++i)
603 QTableWidgetItem* aItem = myPosTable->item( i, 1 );
604 if (aItem == 0) break;
605 if (aItem->checkState() != Qt::Checked )
607 QVariant aVar = aModel->index( i, 0 ).data();
608 myCutLines->SetLinePosition(i, aVar.toDouble());
612 //if (aNbPlanes > aNbRows)
613 // myPosTable->addRows(aNbRows, aNbPlanes - aNbRows );
614 //else if (aNbPlanes < aNbRows)
615 //myPosTable->setRowCount(aNbPlanes);
616 if (aNbPlanes > aNbRows)
617 while( aNbPlanes > myPosTable->rowCount() )
618 myPosTable->insertRow( myPosTable->rowCount() );
619 else if (aNbPlanes < aNbRows)
620 myPosTable->setRowCount(aNbPlanes);
622 QString str("Plane# %1");
624 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
625 for (int i = 0; i<aMin; i++)
627 QModelIndex anIndex = aModel->index( i, 0 );
628 aModel->setData( anIndex, QVariant( myCutLines->GetLinePosition(i) ), Qt::DisplayRole );
629 //myPosTable->setText(i, 0, QString::number(myCutLines->GetLinePosition(i)));
630 myPosTable->item( i, 1 )->setCheckState(myCutLines->IsDefaultPosition(i) ? Qt::Checked : Qt::Unchecked );
631 aLabels.append( str.arg(i+1) );
634 //QHeader *vh = myPosTable->verticalHeader();
635 for (int i=aMin; i<aNbPlanes; i++) {
636 /*VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem
637 (myPosTable, QTableItem::OnTyping, QString::number(myCutLines->GetLinePosition(i)));*/
638 QTableWidgetItem* aEditItem = new QTableWidgetItem();
639 aEditItem->setText( QString::number(myCutLines->GetLinePosition(i)) );
640 //aEditItem->setReplaceable(false);
641 //aEditItem->setEnabled(!myCutLines->IsDefaultPosition(i));
642 Qt::ItemFlags aFlags = aEditItem->flags();
643 if ( myCutLines->IsDefaultPosition(i) )
644 aFlags |= Qt::ItemIsEnabled;
646 aFlags &= (~Qt::ItemIsEnabled);
648 myPosTable->setItem(i, 0, aEditItem);
650 /*QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
651 aCheck->setChecked(myCutLines->IsDefaultPosition(i));
652 aCheck->setReplaceable(false);
653 myPosTable->setItem(i, 1, aCheck);*/
655 QTableWidgetItem* aCheck = new QTableWidgetItem();
656 aCheck->setCheckState( myCutLines->IsDefaultPosition(i) ?
657 Qt::Checked : Qt::Unchecked );
658 myPosTable->setItem(i, 1, aCheck);
660 //vh->setLabel( i, str.arg(i+1) );
661 aLabels.append( str.arg(i+1) );
663 myPosTable->setVerticalHeaderLabels( aLabels );
665 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
667 if (myPreviewCheck->isChecked()) {
674 void VisuGUI_CutLinesDlg::updateGlyphs(bool update){
675 if (myPreviewActorGlyphs == 0 ) return;
676 const vtkFloatingPointType *aDirLn = myCutLines->GetSpecificPL()->GetRealDirLn();
677 vtkFloatingPointType aSecondPnt[3];
678 vtkFloatingPointType aBoundCenter[3];
680 vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
681 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
682 aPlaneMapper->SetInput(aPolyData->GetOutput());
683 vtkFloatingPointType bounds[6];
684 aPlaneMapper->GetBounds(bounds);
686 for(int i=0; i<3; i++) aBoundCenter[i] = (bounds[i*2] + bounds[i*2+1])/2.0;
687 for(int i=0; i<3; i++){
688 if (!myAllCurvesInvertedCheck->isChecked())
689 aSecondPnt[i] = aDirLn[i];
691 aSecondPnt[i] = - aDirLn[i];
694 vtkFloatingPointType max_bound = 0;
695 max_bound < bounds[1]-bounds[0] ? max_bound = bounds[1] - bounds[0] : max_bound = max_bound;
696 max_bound < bounds[3]-bounds[2] ? max_bound = bounds[3] - bounds[2] : max_bound = max_bound;
697 max_bound < bounds[5]-bounds[4] ? max_bound = bounds[5] - bounds[4] : max_bound = max_bound;
699 vtkPolyData* profile = vtkPolyData::New();
700 vtkPoints* aPoints = vtkPoints::New();
701 vtkGlyph3D* glyphs = vtkGlyph3D::New();
702 vtkFloatArray *aFloatArray = vtkFloatArray::New();
703 vtkGlyphSource2D* source = vtkGlyphSource2D::New();
706 source->SetGlyphTypeToArrow();
708 aPoints->InsertNextPoint(aBoundCenter);
709 profile->SetPoints(aPoints);
711 aFloatArray->SetNumberOfComponents(3);
712 for(int i=0; i<3 ;i++)
713 aFloatArray->InsertNextValue(aSecondPnt[i]);
715 vtkDataSetAttributes* aDataSetAttributes;
716 aDataSetAttributes = profile->GetPointData();
717 aDataSetAttributes->SetVectors(aFloatArray);
719 glyphs->SetScaleFactor(0.25*max_bound);
720 glyphs->SetVectorModeToUseVector();
721 glyphs->SetScaleModeToScaleByVector();
722 glyphs->SetInput(profile);
723 glyphs->SetSource(source->GetOutput());
725 vtkPolyDataMapper* aGlyphsMapper = vtkPolyDataMapper::New();
726 aGlyphsMapper->ScalarVisibilityOff();
727 aGlyphsMapper->SetInput(glyphs->GetOutput());
729 myPreviewActorGlyphs->SetMapper(aGlyphsMapper);
734 aGlyphsMapper->Delete();
735 aFloatArray->Delete();
737 aPlaneMapper->Delete();
739 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
744 //------------------------------------------------------------------------------
745 void VisuGUI_CutLinesDlg::setDefault (int all)
747 myPosTable->setCurrentCell(0, 0);
748 myPosTable->clearSelection();
750 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
754 if (all == 0) return;
756 for (int i = 0; i < (int)myNbSpn->value(); ++i)
757 myPosTable->item( i, 1 )->setCheckState(Qt::Checked);
759 for (int i = 0; i < (int)myNbSpn->value(); ++i)
761 if ( myPosTable->item( i, 1 )->checkState() == Qt::Checked )
763 myCutLines->SetDefaultPosition(i);
764 QModelIndex anIndex = aModel->index( i, 0 );
765 aModel->setData( anIndex, QVariant( myCutLines->GetLinePosition(i) ), Qt::DisplayRole );
766 //myPosTable->setText( i, 0, QString::number(myCutLines->GetLinePosition(i)));
767 //myPosTable->item( i, 0 )->setEnabled(false);
768 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() &(~Qt::ItemIsEnabled ) );
771 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() | Qt::ItemIsEnabled );
775 //------------------------------------------------------------------------------
776 VISU::CutPlanes::Orientation VisuGUI_CutLinesDlg::getOrientaion (bool IsBasePlane)
785 VISU::CutPlanes::Orientation orient;
786 switch (aBG->id(aBG->checkedButton())) {
788 orient = VISU::CutPlanes::XY;
791 orient = VISU::CutPlanes::YZ;
794 orient = VISU::CutPlanes::ZX;
799 //------------------------------------------------------------------------------
800 void VisuGUI_CutLinesDlg::setOrientation (const VISU::CutPlanes::Orientation orient)
803 case VISU::CutPlanes::XY:
804 mySelPlane->button(0)->setChecked(true);
807 case VISU::CutPlanes::YZ:
808 mySelPlane->button(1)->setChecked(true);
811 case VISU::CutPlanes::ZX:
812 mySelPlane->button(2)->setChecked(true);
817 //------------------------------------------------------------------------------
818 void VisuGUI_CutLinesDlg::setOrientation2 (const VISU::CutPlanes::Orientation orient)
821 case VISU::CutPlanes::XY:
822 mySelPlane2->button(0)->setChecked(true);
825 case VISU::CutPlanes::YZ:
826 mySelPlane2->button(1)->setChecked(true);
829 case VISU::CutPlanes::ZX:
830 mySelPlane2->button(2)->setChecked(true);
835 void VisuGUI_CutLinesDlg::onValueChanged (int theRow, int theCol)
837 /*QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
841 QModelIndex anIndex = aModel->index( theRow, theCol );
845 bool isChanged = !anIndex.data().isNull();
846 myPosTable->item(theRow, 1)->setCheckState(!isChanged ? Qt::Checked : Qt::Unchecked);
847 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
850 if (myPreviewCheck->isChecked())
857 else if (theCol == 1)
859 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
862 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
865 if (myPreviewCheck->isChecked())
871 aModel->setData( anIndex, myCutLines->GetLinePosition(theRow), Qt::DisplayRole );
872 myPosTable->item( theRow, 0 )->setFlags( myPosTable->item( theRow, 0 )->flags() | Qt::ItemIsEnabled );
875 myPosTable->item( theRow, 0 )->setFlags( myPosTable->item( theRow, 0 )->flags() &(~Qt::ItemIsEnabled ) );
878 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
882 if ( !myPosTable->item(theRow, 1) || !myPosTable->item(theRow, 0) )
887 QTableWidgetItem* anItem = myPosTable->item(theRow, theCol);
891 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
894 anIndex = aModel->index( theRow, 0 );
896 //myCutLines->SetLinePosition( theRow, anIndex.data().toDouble());
899 if ( myPreviewCheck->isChecked() )
902 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
904 //myCutLines->GetPipeLine()->Update();
913 anItem = myPosTable->item(theRow, 0);
914 Qt::ItemFlags flags = anItem->flags();
917 myCutLines->SetDefaultPosition(theRow);
918 anIndex = aModel->index( theRow, 0 );
919 aModel->setData( anIndex, myCutLines->GetLinePosition(theRow), Qt::DisplayRole );
921 /*if ( myPreviewCheck->isChecked() )
923 //not needed update presentation, because item->setFlags generates signal cellChanged() again
925 flags &= (~Qt::ItemIsEnabled );
928 flags |= Qt::ItemIsEnabled;
930 anItem->setFlags( flags );
934 void VisuGUI_CutLinesDlg::accept()
936 VisuGUI_ScalarBarBaseDlg::accept();
939 void VisuGUI_CutLinesDlg::reject()
941 VisuGUI_ScalarBarBaseDlg::reject();
944 void VisuGUI_CutLinesDlg::onPreviewCheck (bool thePreview)
946 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
956 /*! Inverting all curves in the table
958 void VisuGUI_CutLinesDlg::onAllCurvesInvertedCheck(bool theInvert)
960 bool anIsAllCurvesInverted = myAllCurvesInvertedCheck->isChecked();
962 myCutLines->SetAllCurvesInverted( anIsAllCurvesInverted );
963 myPrsCopy->SetAllCurvesInverted( anIsAllCurvesInverted );
968 void VisuGUI_CutLinesDlg::onRotation (double theValue)
970 if (!(bool)myCutLines) return;
971 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
973 if (myPreviewCheck->isChecked()) {
980 void VisuGUI_CutLinesDlg::onPlanePos (const QString& theValue)
982 if (!(bool)myCutLines) return;
983 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
985 if (myPreviewCheck->isChecked()) {
992 QString VisuGUI_CutLinesDlg::GetContextHelpFilePath()
994 return "cut_lines_page.html";