1 // Copyright (C) 2007-2008 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"
48 #include "SUIT_Desktop.h"
49 #include "SUIT_Session.h"
50 #include "SUIT_MessageBox.h"
51 #include "SUIT_ResourceMgr.h"
54 //#include "OB_Browser.h"
56 #include "VisuGUI_TableDlg.h"
62 #include <QButtonGroup>
65 #include <QPushButton>
66 #include <QHeaderView>
67 #include <QRadioButton>
68 #include <QTableWidget>
70 #include <vtkRenderer.h>
71 #include <vtkPolyData.h>
72 #include <vtkAppendPolyData.h>
73 #include <vtkDataSetMapper.h>
74 #include <vtkGlyph3D.h>
75 #include <vtkPolyDataMapper.h>
76 #include <vtkFloatArray.h>
77 #include <vtkGlyphSource2D.h>
81 VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (SalomeApp_Module* theModule)
82 : VisuGUI_ScalarBarBaseDlg(theModule),
84 myPreviewActorGlyphs(0)
86 setWindowTitle("Cut Lines Definition");
87 setSizeGripEnabled(true);
89 QVBoxLayout* aMainLayout = new QVBoxLayout (this);
90 aMainLayout->setMargin( 7 );
91 aMainLayout->setSpacing(5);
93 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
97 myTabBox = new QTabWidget(this);
100 QFrame* aPlanePane = new QFrame(this);
101 QVBoxLayout* aPlaneLayout = new QVBoxLayout(aPlanePane);
102 aPlaneLayout->setMargin( 5 );
103 aPlaneLayout->setSpacing(6);
105 mySelPlane = new QButtonGroup( aPlanePane);
106 QGroupBox* aGB = new QGroupBox( tr( "TXT_ORIENTATION" ), aPlanePane );
107 QHBoxLayout* aHBLay = new QHBoxLayout( aGB );
108 //mySelPlane->setInsideSpacing( 5 );
109 //mySelPlane->setInsideMargin( 5 );
111 QRadioButton* aBxy = new QRadioButton( tr( "PARALLEL_XOY" ), aGB); // 0
112 QRadioButton* aByz = new QRadioButton( tr( "PARALLEL_YOZ" ), aGB); // 1
113 QRadioButton* aBzx = new QRadioButton( tr( "PARALLEL_ZOX" ), aGB); // 2
114 //aBxy->setChecked(false);
115 //aByz->setChecked(false);
116 aHBLay->addWidget( aBxy );
117 aHBLay->addWidget( aByz );
118 aHBLay->addWidget( aBzx );
120 mySelPlane->addButton( aBxy, 0 );
121 mySelPlane->addButton( aByz, 1 );
122 mySelPlane->addButton( aBzx, 2 );
124 aBzx->setChecked(true);
126 aPlaneLayout->addWidget( aGB );
128 QGroupBox* aRotBox = new QGroupBox( tr( "LBL_ROTATION" ), aPlanePane );
129 //aRotBox->setColumnLayout(2, Qt::Horizontal );
130 QGridLayout* aGridLay = new QGridLayout( aRotBox );
132 myRotXLbl = new QLabel( tr( "LBL_ROT_X" ), aRotBox);
133 aGridLay->addWidget( myRotXLbl, 0, 0 );
134 myRotXSpn = new QtxDoubleSpinBox( -45, 45, 5, aRotBox );
135 aGridLay->addWidget( myRotXSpn, 0, 1 );
136 myRotXSpn->setValue( 0 );
137 myRotYLbl = new QLabel( tr( "LBL_ROT_Y" ), aRotBox );
138 aGridLay->addWidget( myRotYLbl, 1, 0 );
139 myRotYSpn = new QtxDoubleSpinBox( -45, 45, 5, aRotBox );
140 aGridLay->addWidget( myRotYSpn, 1, 1 );
141 myRotYSpn->setValue( 0 );
143 aPlaneLayout->addWidget( aRotBox );
145 QGroupBox* aBaseBox = new QGroupBox (tr("BASE_PLANE_POS"), aPlanePane);
146 aHBLay = new QHBoxLayout( aBaseBox );
147 myBasePlanePos = new QLineEdit (aBaseBox);
148 aHBLay->addWidget( myBasePlanePos );
149 mydvalidator = new QDoubleValidator(this);
150 mydvalidator->setDecimals(32);
151 myBasePlanePos->setValidator(mydvalidator);
153 myCBSetDef = new QCheckBox (tr("SET_DEFAULT"),aBaseBox);
154 aHBLay->addWidget( myCBSetDef );
156 aPlaneLayout->addWidget(aBaseBox);
158 QWidget* aPosBox = new QWidget (aPlanePane);
159 aHBLay = new QHBoxLayout( aPosBox );
160 aHBLay->setSpacing(5);
162 aHBLay->addWidget( new QLabel (tr("LBL_POS"), aPosBox) );
163 myPosSpn = new QtxDoubleSpinBox (0, 1, 0.1, aPosBox);
164 myPosSpn->setValue(0.5);
165 aHBLay->addWidget( myPosSpn );
166 aPlaneLayout->addWidget(aPosBox);
168 myPreviewCheck = new QCheckBox (tr("LBL_SHOW_PREVIEW"), aPlanePane);
169 myPreviewCheck->setChecked( aResourceMgr->booleanValue("VISU", "show_preview", false) );
170 aPlaneLayout->addWidget(myPreviewCheck);
172 myAllCurvesInvertedCheck = new QCheckBox(tr("LBL_INVERT_CURVES"), aPlanePane);
173 myAllCurvesInvertedCheck->setChecked(false);
174 aPlaneLayout->addWidget(myAllCurvesInvertedCheck);
176 myUseAbsoluteLengthCheck = new QCheckBox(tr("LBL_ABSOLUTE_LENGTH"), aPlanePane);
177 myUseAbsoluteLengthCheck->setChecked(false);
178 aPlaneLayout->addWidget(myUseAbsoluteLengthCheck);
180 myCreateTable = new QCheckBox (tr("LBL_GENERATE_TABLE"), aPlanePane);
181 myCreateTable->setChecked( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
182 aPlaneLayout->addWidget( myCreateTable );
184 QWidget* aCheckPane = new QWidget(aPlanePane);
185 aHBLay = new QHBoxLayout( aCheckPane );
186 aHBLay->setMargin( 0 );
187 aHBLay->setSpacing( 0 );
188 aHBLay->insertSpacing( 0, 20 );
189 myCurvesCheck = new QCheckBox(tr("LBL_GENERATE_CURVES"), aCheckPane);
190 aHBLay->addWidget( myCurvesCheck );
191 myCurvesCheck->setChecked( aResourceMgr->booleanValue("VISU", "generate_curves", true) );
192 myCurvesCheck->setEnabled( aResourceMgr->booleanValue("VISU", "generate_data_table", true) );
193 aPlaneLayout->addWidget( aCheckPane );
195 aPlaneLayout->addStretch();
197 myTabBox->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
200 QFrame* aLinesPane = new QFrame(this);
201 QVBoxLayout* aLinesLayout = new QVBoxLayout( aLinesPane );
202 aLinesLayout->setMargin( 5 );
203 aLinesLayout->setSpacing( 6 );
205 mySelPlane2 = new QButtonGroup( aLinesPane);
206 aGB = new QGroupBox( tr( "TXT_ORIENTATION" ), aLinesPane );
207 aHBLay = new QHBoxLayout( aGB );
208 //mySelPlane2->setInsideSpacing( 5 );
209 //mySelPlane2->setInsideMargin( 5 );
211 QRadioButton* aBxy2 = new QRadioButton( tr( "PARALLEL_XOY" ), aGB); // 0
212 QRadioButton* aByz2 = new QRadioButton( tr( "PARALLEL_YOZ" ), aGB); // 1
213 QRadioButton* aBzx2 = new QRadioButton( tr( "PARALLEL_ZOX" ), aGB); // 2
215 aHBLay->addWidget( aBxy2 );
216 aHBLay->addWidget( aByz2 );
217 aHBLay->addWidget( aBzx2 );
219 mySelPlane2->addButton( aBxy2, 0 );
220 mySelPlane2->addButton( aByz2, 1 );
221 mySelPlane2->addButton( aBzx2, 2 );
223 aBzx2->setEnabled(false);
224 aByz2->setChecked(true);
225 aLinesLayout->addWidget( aGB );
227 QGroupBox* aRotBox2 = new QGroupBox( tr( "LBL_ROTATION" ), aLinesPane );
228 //aRotBox2->setColumnLayout(2, Qt::Horizontal );
229 aGridLay = new QGridLayout( aRotBox2 );
231 myRotXLbl2 = new QLabel( tr( "LBL_ROT_X" ), aRotBox2);
232 aGridLay->addWidget( myRotXLbl2, 0, 0 );
233 myRotXSpn2 = new QtxDoubleSpinBox( -45, 45, 5, aRotBox2 );
234 aGridLay->addWidget( myRotXSpn2, 0, 1 );
235 myRotXSpn2->setValue( 0 );
236 myRotYLbl2 = new QLabel( tr( "LBL_ROT_Y" ), aRotBox2 );
237 aGridLay->addWidget( myRotYLbl2, 1, 0 );
238 myRotYSpn2 = new QtxDoubleSpinBox( -45, 45, 5, aRotBox2 );
239 aGridLay->addWidget( myRotYSpn2, 1, 1 );
240 myRotYSpn2->setValue( 0 );
241 aLinesLayout->addWidget( aRotBox2 );
243 QWidget* aNbBox = new QWidget(aLinesPane);
244 aHBLay = new QHBoxLayout( aNbBox );
245 aHBLay->setSpacing(5);
246 aHBLay->addWidget( new QLabel( tr( "LBL_NB_PLANS" ), aNbBox ) );
247 myNbSpn = new QtxDoubleSpinBox( 1, 100, 1, aNbBox );
248 myNbSpn->setValue( 10 );
249 aHBLay->addWidget( myNbSpn );
251 aLinesLayout->addWidget( aNbBox );
253 myPosTable = new QTableWidget(aLinesPane );
254 myPosTable->setMaximumHeight( 227 );
255 myPosTable->setMinimumWidth( 294 );
256 myPosTable->setColumnCount(2);
257 myPosTable->setRowCount(0);
259 myPosTable->setItemDelegateForColumn( 0,
260 new NumDelegateItem( myPosTable, NumDelegateItem::NV_Real) );
262 myPosTable->setEditTriggers( (QAbstractItemView::EditTriggers)(QAbstractItemView::AllEditTriggers &(~QAbstractItemView::CurrentChanged)));
265 aLabels.append( "Position" );
266 aLabels.append( "Set default" );
267 myPosTable->setHorizontalHeaderLabels( aLabels );
269 aLinesLayout->addWidget( myPosTable );
271 QWidget* aPosBox2 = new QWidget(aLinesPane);
272 aHBLay = new QHBoxLayout( aPosBox2 );
273 aHBLay->setSpacing(5);
274 aHBLay->addWidget( new QLabel( tr( "LBL_POS" ), aPosBox2 ) );
275 myPosSpn2 = new QtxDoubleSpinBox( 0, 1, 0.1, aPosBox2 );
276 myPosSpn2->setValue( 0.5 );
277 aHBLay->addWidget( myPosSpn2 );
280 aLinesLayout->addWidget( aPosBox2 );
281 aLinesLayout->addStretch();
283 myTabBox->addTab( aLinesPane, tr("LBL_LINES_CUT") );
285 myInputPane = new VisuGUI_InputPane(VISU::TCUTLINES, theModule, this);
286 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
287 myTabBox->addTab(myInputPane, "Input");
289 aMainLayout->addWidget(myTabBox);
292 QFrame* aBtnBox = new QFrame(this);
293 aHBLay = new QHBoxLayout( aBtnBox );
294 aBtnBox->setFrameStyle(QFrame::Box | QFrame::Sunken);
295 aBtnBox->setLineWidth( 1 );
296 //aHBLay->setAutoAdd( false );
297 aHBLay->setSpacing( 5 );
298 aHBLay->setMargin( 11 );
300 QPushButton* aOkBtn = new QPushButton (tr("BUT_OK"), aBtnBox);
301 aOkBtn->setAutoDefault( TRUE );
302 aOkBtn->setDefault( true );
303 aHBLay->addWidget(aOkBtn);
305 aHBLay->addStretch();
307 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CANCEL"), aBtnBox);
308 aHBLay->addWidget(aCloseBtn);
310 QPushButton* aHelpBtn = new QPushButton(tr("BUT_HELP"), aBtnBox);
311 aHBLay->addWidget(aHelpBtn);
313 aMainLayout->addWidget(aBtnBox);
315 // signals and slots connections
316 connect(mySelPlane , SIGNAL(buttonClicked(int)) , this, SLOT(onPlaneSelect(int)));
317 connect(myCBSetDef , SIGNAL(toggled(bool)) , this, SLOT(setBaseDefault()));
318 connect(myPosSpn , SIGNAL(valueChanged(double)) , this, SLOT(setBaseDefault()));
319 connect(mySelPlane2 , SIGNAL(buttonClicked(int)) , this, SLOT(onCutSelect(int)));
320 connect(myNbSpn , SIGNAL(valueChanged(double)) , this, SLOT(DrawTable()));
321 connect(myPosTable->horizontalHeader(), SIGNAL(sectionClicked(int)) , this, SLOT(setDefault(int)));
322 connect(myPosSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(DrawTable()));
323 connect(myPreviewCheck, SIGNAL(toggled(bool)) , this, SLOT(onPreviewCheck(bool)));
324 connect(myAllCurvesInvertedCheck, SIGNAL(toggled(bool)),this, SLOT(onAllCurvesInvertedCheck(bool)));
325 connect(myPosTable , SIGNAL(cellChanged(int, int)), this, SLOT(onValueChanged(int, int)));
326 connect(myRotXSpn , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
327 connect(myRotYSpn , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
328 connect(myRotXSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
329 connect(myRotYSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double)));
330 connect(myBasePlanePos, SIGNAL(textChanged(const QString&)), this, SLOT(onPlanePos(const QString&)));
331 connect(myCreateTable , SIGNAL(toggled(bool)), myCurvesCheck, SLOT(setEnabled(bool)));
333 connect(aOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
334 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
335 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
341 VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg()
344 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
348 //------------------------------------------------------------------------------
349 void VisuGUI_CutLinesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
353 myPrsCopy = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
355 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
357 myRotXSpn->setValue(myPrsCopy->GetRotateX()*180./PI);
358 myRotYSpn->setValue(myPrsCopy->GetRotateY()*180./PI);
359 myPosSpn->setValue(myPrsCopy->GetDisplacement());
360 setOrientation(myPrsCopy->GetOrientationType());
362 myNbSpn->setValue( (int)myPrsCopy->GetNbLines() );
363 myRotXSpn2->setValue(myPrsCopy->GetRotateX2()*180./PI);
364 myRotYSpn2->setValue(myPrsCopy->GetRotateY2()*180./PI);
365 myPosSpn2->setValue(myPrsCopy->GetDisplacement2());
366 setOrientation2(myPrsCopy->GetOrientationType2());
369 myCutLines = VISU::TSameAsFactory<VISU::TCUTLINES>().Create(myPrsCopy, VISU::ColoredPrs3d_i::EDoNotPublish);
370 myCutLines->CopyCurvesInverted(myPrsCopy->GetCurvesInverted());
371 myAllCurvesInvertedCheck->setChecked( myCutLines->IsAllCurvesInverted() );
372 myUseAbsoluteLengthCheck->setChecked( myCutLines->IsUseAbsoluteLength() );
373 myBasePlanePos->setText( QString::number(myCutLines->GetBasePlanePosition()) );
374 myCBSetDef->setChecked(myPrsCopy->IsDefault());
378 if (myPreviewCheck->isChecked()) {
385 myInputPane->initFromPrsObject( myPrsCopy );
386 myTabBox->setCurrentIndex( 0 );
389 //------------------------------------------------------------------------------
390 int VisuGUI_CutLinesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
392 if(!myInputPane->check() || !GetScalarPane()->check())
395 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
396 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
398 myPrsCopy->SetOrientation(getOrientaion(),
399 myRotXSpn->value()*PI/180.,
400 myRotYSpn->value()*PI/180.);
401 myPrsCopy->SetDisplacement(myPosSpn->value());
402 myPrsCopy->SetNbLines((int)myNbSpn->value());
404 myPrsCopy->SetOrientation2(getOrientaion(false),
405 myRotXSpn2->value()*PI/180.,
406 myRotYSpn2->value()*PI/180.);
407 myPrsCopy->SetDisplacement2(myPosSpn2->value());
409 if (!myCBSetDef->isChecked())
410 myPrsCopy->SetBasePlanePosition(myBasePlanePos->text().toDouble());
411 else myPrsCopy->SetDefault();
413 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
416 for (int i = 0; i < (int)myNbSpn->value(); ++i)
418 QTableWidgetItem* aItem = myPosTable->item( i, 1 );
419 if (aItem == 0) break;
420 if (aItem->checkState() != Qt::Checked )
422 QVariant aVar = aModel->index( i, 0 ).data();
423 myPrsCopy->SetLinePosition( i, aVar.toDouble() );
426 myPrsCopy->SetDefaultPosition(i);
430 myPrsCopy->SetAllCurvesInverted( myAllCurvesInvertedCheck->isChecked() );
431 myPrsCopy->SetUseAbsoluteLength( myUseAbsoluteLengthCheck->isChecked() );
433 VISU::TSameAsFactory<VISU::TCUTLINES>().Copy(myPrsCopy, thePrs);
438 //------------------------------------------------------------------------------
439 void VisuGUI_CutLinesDlg::createPlanes()
441 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
442 if (aView == NULL) return;
443 if (!(bool)myCutLines) return;
444 if (myPreviewActor != 0) return;
446 storeToPrsObject(myCutLines);
447 myCutLines->GetPipeLine()->Update();
448 vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
449 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
450 aPlaneMapper->SetInput(aPolyData->GetOutput());
451 aPlaneMapper->ScalarVisibilityOff();
453 myPreviewActorGlyphs = SALOME_Actor::New();
454 myPreviewActorGlyphs->PickableOff();
457 myPreviewActor = SALOME_Actor::New();
458 myPreviewActor->PickableOff();
459 myPreviewActor->SetMapper(aPlaneMapper);
460 aPlaneMapper->Delete();
461 aView->AddActor(myPreviewActor);
462 aView->AddActor(myPreviewActorGlyphs);
463 aView->getRenderer()->Render();
467 //------------------------------------------------------------------------------
468 void VisuGUI_CutLinesDlg::deletePlanes()
470 if (myPreviewActor == 0) return;
471 vtkRenderer* aRend = myPreviewActor->GetRenderer();
472 vtkRenderer* aRendGlyphs = myPreviewActorGlyphs->GetRenderer();
474 vtkRenderWindow* aWnd1 = aRend->GetRenderWindow();
475 vtkRenderWindow* aWnd2 = aRendGlyphs->GetRenderWindow();
477 myPreviewActor->RemoveFromRender(aRend);
478 if(aRendGlyphs && aWnd2)
479 myPreviewActorGlyphs->RemoveFromRender(aRendGlyphs);
481 myPreviewActor->Delete();
482 myPreviewActorGlyphs->Delete();
484 myPreviewActorGlyphs = 0;
488 //------------------------------------------------------------------------------
489 void VisuGUI_CutLinesDlg::onPlaneSelect (int theId)
491 QList<QAbstractButton*> aBtns = mySelPlane2->buttons();
492 for (QList<QAbstractButton*>::Iterator it = aBtns.begin();
493 it != aBtns.end(); it++ )
494 (*it)->setEnabled(true);
496 QAbstractButton* aBtn = mySelPlane2->button(theId);
497 aBtn->setEnabled(false);
500 myRotXLbl->setText( tr("LBL_ROT_X"));
501 myRotYLbl->setText( tr("LBL_ROT_Y"));
502 mySelPlane2->button(1)->setChecked(true);
503 onCutSelect(1, false);
506 myRotXLbl->setText( tr("LBL_ROT_Y"));
507 myRotYLbl->setText( tr("LBL_ROT_Z"));
508 mySelPlane2->button(2)->setChecked(true);
509 onCutSelect(2, false);
512 myRotXLbl->setText( tr("LBL_ROT_Z"));
513 myRotYLbl->setText( tr("LBL_ROT_X"));
514 mySelPlane2->button(0)->setChecked(true);
515 onCutSelect(0, false);
517 setBaseDefault(false);
521 //------------------------------------------------------------------------------
522 void VisuGUI_CutLinesDlg::onCutSelect (int theId, bool theUpdate)
526 myRotXLbl2->setText( tr("LBL_ROT_X"));
527 myRotYLbl2->setText( tr("LBL_ROT_Y"));
530 myRotXLbl2->setText( tr("LBL_ROT_Y"));
531 myRotYLbl2->setText( tr("LBL_ROT_Z"));
534 myRotXLbl2->setText( tr("LBL_ROT_Z"));
535 myRotYLbl2->setText( tr("LBL_ROT_X"));
537 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
539 if (theUpdate && myPreviewCheck->isChecked() && (bool)myCutLines) {
546 //------------------------------------------------------------------------------
547 void VisuGUI_CutLinesDlg::setBaseDefault (bool theUpdate)
549 if (!hasInit) return;
551 if (myCBSetDef->isChecked()) {
552 if (!myCutLines->IsDefault()) myCutLines->SetDefault();
553 myCutLines->SetDisplacement(myPosSpn->value());
554 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
556 if (theUpdate && myPreviewCheck->isChecked() && (bool)myCutLines) {
561 vtkFloatingPointType aPos = myCutLines->GetBasePlanePosition();
562 myBasePlanePos->setText( QString::number(aPos) );
563 myBasePlanePos->setEnabled(false);
565 myBasePlanePos->setEnabled(true);
569 //------------------------------------------------------------------------------
570 void VisuGUI_CutLinesDlg::DrawTable()
572 if (!hasInit) return;
574 int aNbRows = myPosTable->rowCount();
575 int aNbPlanes = (int)myNbSpn->value();
577 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
581 myCutLines->SetOrientation(getOrientaion(),
582 myRotXSpn->value()*PI/180.,
583 myRotYSpn->value()*PI/180.);
585 myCutLines->SetNbLines(aNbPlanes);
586 myCutLines->SetDisplacement2(myPosSpn2->value());
587 myCutLines->SetOrientation2(getOrientaion(false),
588 myRotXSpn2->value()*PI/180.,
589 myRotYSpn2->value()*PI/180.);
592 for (int i = 0; i < aNbRows; ++i)
594 QTableWidgetItem* aItem = myPosTable->item( i, 1 );
595 if (aItem == 0) break;
596 if (aItem->checkState() != Qt::Checked )
598 QVariant aVar = aModel->index( i, 0 ).data();
599 myCutLines->SetLinePosition(i, aVar.toDouble());
603 //if (aNbPlanes > aNbRows)
604 // myPosTable->addRows(aNbRows, aNbPlanes - aNbRows );
605 //else if (aNbPlanes < aNbRows)
606 //myPosTable->setRowCount(aNbPlanes);
607 if (aNbPlanes > aNbRows)
608 while( aNbPlanes > myPosTable->rowCount() )
609 myPosTable->insertRow( myPosTable->rowCount() );
610 else if (aNbPlanes < aNbRows)
611 myPosTable->setRowCount(aNbPlanes);
613 QString str("Plane# %1");
615 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
616 for (int i = 0; i<aMin; i++)
618 QModelIndex anIndex = aModel->index( i, 0 );
619 aModel->setData( anIndex, QVariant( myCutLines->GetLinePosition(i) ), Qt::DisplayRole );
620 //myPosTable->setText(i, 0, QString::number(myCutLines->GetLinePosition(i)));
621 myPosTable->item( i, 1 )->setCheckState(myCutLines->IsDefaultPosition(i) ? Qt::Checked : Qt::Unchecked );
622 aLabels.append( str.arg(i+1) );
625 //QHeader *vh = myPosTable->verticalHeader();
626 for (int i=aMin; i<aNbPlanes; i++) {
627 /*VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem
628 (myPosTable, QTableItem::OnTyping, QString::number(myCutLines->GetLinePosition(i)));*/
629 QTableWidgetItem* aEditItem = new QTableWidgetItem();
630 aEditItem->setText( QString::number(myCutLines->GetLinePosition(i)) );
631 //aEditItem->setReplaceable(false);
632 //aEditItem->setEnabled(!myCutLines->IsDefaultPosition(i));
633 Qt::ItemFlags aFlags = aEditItem->flags();
634 if ( myCutLines->IsDefaultPosition(i) )
635 aFlags |= Qt::ItemIsEnabled;
637 aFlags &= (~Qt::ItemIsEnabled);
639 myPosTable->setItem(i, 0, aEditItem);
641 /*QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
642 aCheck->setChecked(myCutLines->IsDefaultPosition(i));
643 aCheck->setReplaceable(false);
644 myPosTable->setItem(i, 1, aCheck);*/
646 QTableWidgetItem* aCheck = new QTableWidgetItem();
647 aCheck->setCheckState( myCutLines->IsDefaultPosition(i) ?
648 Qt::Checked : Qt::Unchecked );
649 myPosTable->setItem(i, 1, aCheck);
651 //vh->setLabel( i, str.arg(i+1) );
652 aLabels.append( str.arg(i+1) );
654 myPosTable->setVerticalHeaderLabels( aLabels );
656 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
658 if (myPreviewCheck->isChecked()) {
665 void VisuGUI_CutLinesDlg::updateGlyphs(bool update){
666 if (myPreviewActorGlyphs == 0 ) return;
667 const vtkFloatingPointType *aDirLn = myCutLines->GetSpecificPL()->GetRealDirLn();
668 vtkFloatingPointType aSecondPnt[3];
669 vtkFloatingPointType aBoundCenter[3];
671 vtkAppendPolyData* aPolyData = myCutLines->GetSpecificPL()->GetAppendPolyData();
672 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
673 aPlaneMapper->SetInput(aPolyData->GetOutput());
674 vtkFloatingPointType bounds[6];
675 aPlaneMapper->GetBounds(bounds);
677 for(int i=0; i<3; i++) aBoundCenter[i] = (bounds[i*2] + bounds[i*2+1])/2.0;
678 for(int i=0; i<3; i++){
679 if (!myAllCurvesInvertedCheck->isChecked())
680 aSecondPnt[i] = aDirLn[i];
682 aSecondPnt[i] = - aDirLn[i];
685 vtkFloatingPointType max_bound = 0;
686 max_bound < bounds[1]-bounds[0] ? max_bound = bounds[1] - bounds[0] : max_bound = max_bound;
687 max_bound < bounds[3]-bounds[2] ? max_bound = bounds[3] - bounds[2] : max_bound = max_bound;
688 max_bound < bounds[5]-bounds[4] ? max_bound = bounds[5] - bounds[4] : max_bound = max_bound;
690 vtkPolyData* profile = vtkPolyData::New();
691 vtkPoints* aPoints = vtkPoints::New();
692 vtkGlyph3D* glyphs = vtkGlyph3D::New();
693 vtkFloatArray *aFloatArray = vtkFloatArray::New();
694 vtkGlyphSource2D* source = vtkGlyphSource2D::New();
697 source->SetGlyphTypeToArrow();
699 aPoints->InsertNextPoint(aBoundCenter);
700 profile->SetPoints(aPoints);
702 aFloatArray->SetNumberOfComponents(3);
703 for(int i=0; i<3 ;i++)
704 aFloatArray->InsertNextValue(aSecondPnt[i]);
706 vtkDataSetAttributes* aDataSetAttributes;
707 aDataSetAttributes = profile->GetPointData();
708 aDataSetAttributes->SetVectors(aFloatArray);
710 glyphs->SetScaleFactor(0.25*max_bound);
711 glyphs->SetVectorModeToUseVector();
712 glyphs->SetScaleModeToScaleByVector();
713 glyphs->SetInput(profile);
714 glyphs->SetSource(source->GetOutput());
716 vtkPolyDataMapper* aGlyphsMapper = vtkPolyDataMapper::New();
717 aGlyphsMapper->ScalarVisibilityOff();
718 aGlyphsMapper->SetInput(glyphs->GetOutput());
720 myPreviewActorGlyphs->SetMapper(aGlyphsMapper);
725 aGlyphsMapper->Delete();
726 aFloatArray->Delete();
728 aPlaneMapper->Delete();
730 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
735 //------------------------------------------------------------------------------
736 void VisuGUI_CutLinesDlg::setDefault (int all)
738 myPosTable->setCurrentCell(0, 0);
739 myPosTable->clearSelection();
741 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
745 if (all == 0) return;
747 for (int i = 0; i < (int)myNbSpn->value(); ++i)
748 myPosTable->item( i, 1 )->setCheckState(Qt::Checked);
750 for (int i = 0; i < (int)myNbSpn->value(); ++i)
752 if ( myPosTable->item( i, 1 )->checkState() == Qt::Checked )
754 myCutLines->SetDefaultPosition(i);
755 QModelIndex anIndex = aModel->index( i, 0 );
756 aModel->setData( anIndex, QVariant( myCutLines->GetLinePosition(i) ), Qt::DisplayRole );
757 //myPosTable->setText( i, 0, QString::number(myCutLines->GetLinePosition(i)));
758 //myPosTable->item( i, 0 )->setEnabled(false);
759 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() &(~Qt::ItemIsEnabled ) );
762 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() | Qt::ItemIsEnabled );
766 //------------------------------------------------------------------------------
767 VISU::CutPlanes::Orientation VisuGUI_CutLinesDlg::getOrientaion (bool IsBasePlane)
776 VISU::CutPlanes::Orientation orient;
777 switch (aBG->id(aBG->checkedButton())) {
779 orient = VISU::CutPlanes::XY;
782 orient = VISU::CutPlanes::YZ;
785 orient = VISU::CutPlanes::ZX;
790 //------------------------------------------------------------------------------
791 void VisuGUI_CutLinesDlg::setOrientation (const VISU::CutPlanes::Orientation orient)
794 case VISU::CutPlanes::XY:
795 mySelPlane->button(0)->setChecked(true);
798 case VISU::CutPlanes::YZ:
799 mySelPlane->button(1)->setChecked(true);
802 case VISU::CutPlanes::ZX:
803 mySelPlane->button(2)->setChecked(true);
808 //------------------------------------------------------------------------------
809 void VisuGUI_CutLinesDlg::setOrientation2 (const VISU::CutPlanes::Orientation orient)
812 case VISU::CutPlanes::XY:
813 mySelPlane2->button(0)->setChecked(true);
816 case VISU::CutPlanes::YZ:
817 mySelPlane2->button(1)->setChecked(true);
820 case VISU::CutPlanes::ZX:
821 mySelPlane2->button(2)->setChecked(true);
826 void VisuGUI_CutLinesDlg::onValueChanged (int theRow, int theCol)
828 /*QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
832 QModelIndex anIndex = aModel->index( theRow, theCol );
836 bool isChanged = !anIndex.data().isNull();
837 myPosTable->item(theRow, 1)->setCheckState(!isChanged ? Qt::Checked : Qt::Unchecked);
838 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
841 if (myPreviewCheck->isChecked())
848 else if (theCol == 1)
850 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
853 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
856 if (myPreviewCheck->isChecked())
862 aModel->setData( anIndex, myCutLines->GetLinePosition(theRow), Qt::DisplayRole );
863 myPosTable->item( theRow, 0 )->setFlags( myPosTable->item( theRow, 0 )->flags() | Qt::ItemIsEnabled );
866 myPosTable->item( theRow, 0 )->setFlags( myPosTable->item( theRow, 0 )->flags() &(~Qt::ItemIsEnabled ) );
869 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
873 if ( !myPosTable->item(theRow, 1) || !myPosTable->item(theRow, 0) )
878 QTableWidgetItem* anItem = myPosTable->item(theRow, theCol);
882 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
885 anIndex = aModel->index( theRow, 0 );
887 //myCutLines->SetLinePosition( theRow, anIndex.data().toDouble());
890 if ( myPreviewCheck->isChecked() )
893 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
895 //myCutLines->GetPipeLine()->Update();
904 anItem = myPosTable->item(theRow, 0);
905 Qt::ItemFlags flags = anItem->flags();
908 myCutLines->SetDefaultPosition(theRow);
909 anIndex = aModel->index( theRow, 0 );
910 aModel->setData( anIndex, myCutLines->GetLinePosition(theRow), Qt::DisplayRole );
912 /*if ( myPreviewCheck->isChecked() )
914 //not needed update presentation, because item->setFlags generates signal cellChanged() again
916 flags &= (~Qt::ItemIsEnabled );
919 flags |= Qt::ItemIsEnabled;
921 anItem->setFlags( flags );
925 void VisuGUI_CutLinesDlg::accept()
927 VisuGUI_ScalarBarBaseDlg::accept();
930 void VisuGUI_CutLinesDlg::reject()
932 VisuGUI_ScalarBarBaseDlg::reject();
935 void VisuGUI_CutLinesDlg::onPreviewCheck (bool thePreview)
937 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
947 /*! Inverting all curves in the table
949 void VisuGUI_CutLinesDlg::onAllCurvesInvertedCheck(bool theInvert)
951 bool anIsAllCurvesInverted = myAllCurvesInvertedCheck->isChecked();
953 myCutLines->SetAllCurvesInverted( anIsAllCurvesInverted );
954 myPrsCopy->SetAllCurvesInverted( anIsAllCurvesInverted );
959 void VisuGUI_CutLinesDlg::onRotation (double theValue)
961 if (!(bool)myCutLines) return;
962 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
964 if (myPreviewCheck->isChecked()) {
971 void VisuGUI_CutLinesDlg::onPlanePos (const QString& theValue)
973 if (!(bool)myCutLines) return;
974 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
976 if (myPreviewCheck->isChecked()) {
983 QString VisuGUI_CutLinesDlg::GetContextHelpFilePath()
985 return "cut_lines_page.html";