1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VisuGUI_CutLinesDlg.cxx
24 #include "VisuGUI_CutLinesDlg.h"
27 #include "VisuGUI_Tools.h"
28 #include "VisuGUI_ViewTools.h"
30 #include "VISU_Gen_i.hh"
31 #include "VISU_CutLines_i.hh"
33 #include "VISU_PipeLine.hxx"
34 #include "VISU_PipeLineUtils.hxx"
35 #include "VISU_CutLinesPL.hxx"
37 #include "SVTK_ViewWindow.h"
39 #include "LightApp_Application.h"
40 #include "SalomeApp_Study.h"
42 #include "SUIT_Desktop.h"
43 #include "SUIT_Session.h"
44 #include "SUIT_MessageBox.h"
45 #include "SUIT_ResourceMgr.h"
47 #include "OB_Browser.h"
51 #include <qtabwidget.h>
52 #include <qhgroupbox.h>
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>
65 bool VisuGUI_CutLinesDlg::MYGenerateTable = true;
66 bool VisuGUI_CutLinesDlg::MYGenerateCurve = true;
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)
73 setCaption("Cut Lines Definition");
74 setSizeGripEnabled(true);
76 QVBoxLayout* aMainLayout = new QVBoxLayout (this, 7, 6);
77 aMainLayout->setSpacing(5);
82 QTabWidget* aTabPane = new QTabWidget(this);
85 QFrame* aPlanePane = new QFrame(this);
86 QVBoxLayout* aPlaneLayout = new QVBoxLayout(aPlanePane, 5, 6);
88 mySelPlane = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aPlanePane);
89 mySelPlane->setInsideSpacing( 5 );
90 mySelPlane->setInsideMargin( 5 );
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);
99 aPlaneLayout->addWidget( mySelPlane );
101 QGroupBox* aRotBox = new QGroupBox( tr( "LBL_ROTATION" ), aPlanePane );
102 aRotBox->setColumnLayout(2, Qt::Horizontal );
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 );
111 aPlaneLayout->addWidget( aRotBox );
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);
119 myCBSetDef = new QCheckBox (tr("SET_DEFAULT"),aBaseBox);
121 aPlaneLayout->addWidget(aBaseBox);
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);
130 myPreviewCheck = new QCheckBox (tr("LBL_SHOW_PREVIEW"), aPlanePane);
131 myPreviewCheck->setChecked(false);
132 aPlaneLayout->addWidget(myPreviewCheck);
134 myAllCurvesInvertedCheck = new QCheckBox(tr("LBL_INVERT_CURVES"), aPlanePane);
135 myAllCurvesInvertedCheck->setChecked(false);
136 aPlaneLayout->addWidget(myAllCurvesInvertedCheck);
138 myCreateTable = new QCheckBox (tr("LBL_GENERATE_TABLE"), aPlanePane);
139 myCreateTable->setChecked(MYGenerateTable);
140 aPlaneLayout->addWidget( myCreateTable );
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 );
153 aPlaneLayout->addStretch();
156 aTabPane->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
159 QFrame* aLinesPane = new QFrame(this);
160 QVBoxLayout* aLinesLayout = new QVBoxLayout( aLinesPane, 5, 6 );
162 mySelPlane2 = new QHButtonGroup( tr( "TXT_ORIENTATION" ), aLinesPane);
163 mySelPlane2->setInsideSpacing( 5 );
164 mySelPlane2->setInsideMargin( 5 );
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 );
173 QGroupBox* aRotBox2 = new QGroupBox( tr( "LBL_ROTATION" ), aLinesPane );
174 aRotBox2->setColumnLayout(2, Qt::Horizontal );
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 );
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 );
190 aLinesLayout->addWidget( aNbBox );
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);
198 QHeader *th = myPosTable->horizontalHeader();
199 th->setLabel( 0, "Position" );
200 th->setLabel( 1, "Set default" );
202 aLinesLayout->addWidget( myPosTable );
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();
212 aTabPane->addTab( aLinesPane, tr("LBL_LINES_CUT") );
214 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
215 myScalarPane->setMargin( 5 );
216 aTabPane->addTab(myScalarPane, "Scalar Bar");
218 aMainLayout->addWidget(aTabPane);
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 );
229 QPushButton* aOkBtn = new QPushButton (tr("BUT_OK"), aBtnBox);
230 aOkBtn->setAutoDefault( TRUE );
231 aOkBtn->setDefault( true );
232 aBtnLayout->addWidget(aOkBtn);
234 aBtnLayout->addStretch();
236 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CANCEL"), aBtnBox);
237 aBtnLayout->addWidget(aCloseBtn);
239 QPushButton* aHelpBtn = new QPushButton(tr("BUT_HELP"), aBtnBox);
240 aBtnLayout->addWidget(aHelpBtn);
242 aMainLayout->addWidget(aBtnBox);
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)));
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*)));
276 VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg()
278 cout<<"### VisuGUI_CutLinesDlg::~VisuGUI_CutLinesDlg"<<endl;
280 if (myCutLines) //delete myCutLines;
281 myCutLines->Destroy();
282 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
286 //------------------------------------------------------------------------------
287 void VisuGUI_CutLinesDlg::initFromPrsObject (VISU::CutLines_i* thePrs)
290 myScalarPane->initFromPrsObject(thePrs);
292 myRotXSpn->setValue(thePrs->GetRotateX()*180./PI);
293 myRotYSpn->setValue(thePrs->GetRotateY()*180./PI);
294 myPosSpn->setValue(thePrs->GetDisplacement());
295 setOrientation(thePrs->GetOrientationType());
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());
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());
313 if (myPreviewCheck->isChecked()) {
318 //------------------------------------------------------------------------------
319 int VisuGUI_CutLinesDlg::storeToPrsObject (VISU::CutLines_i* thePrs)
321 myScalarPane->storeToPrsObject(thePrs);
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());
329 thePrs->SetOrientation2(getOrientaion(false),
330 myRotXSpn2->value()*PI/180.,
331 myRotYSpn2->value()*PI/180.);
332 thePrs->SetDisplacement2(myPosSpn2->value());
334 if (!myCBSetDef->isChecked())
335 thePrs->SetBasePlanePosition(myBasePlanePos->text().toDouble());
336 else thePrs->SetDefault();
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);
343 if (myAllCurvesInvertedCheck->isChecked())
344 thePrs->SetAllCurvesInverted(true);
348 //------------------------------------------------------------------------------
349 void VisuGUI_CutLinesDlg::createPlanes()
351 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
352 if (aView == NULL) return;
353 if (myCutLines == NULL) return;
354 if (myPreviewActor != 0) return;
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();
363 myPreviewActorGlyphs = SALOME_Actor::New();
364 myPreviewActorGlyphs->PickableOff();
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();
377 //------------------------------------------------------------------------------
378 void VisuGUI_CutLinesDlg::deletePlanes()
380 if (myPreviewActor == 0) return;
381 SVTK_ViewWindow* aView;
382 vtkRenderer* aRend = myPreviewActor->GetRenderer();
383 vtkRenderer* aRendGlyphs = myPreviewActorGlyphs->GetRenderer();
385 vtkRenderWindow* aWnd1 = aRend->GetRenderWindow();
386 vtkRenderWindow* aWnd2 = aRendGlyphs->GetRenderWindow();
388 myPreviewActor->RemoveFromRender(aRend);
389 if(aRendGlyphs && aWnd2)
390 myPreviewActorGlyphs->RemoveFromRender(aRendGlyphs);
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);
398 myPreviewActor->Delete();
399 myPreviewActorGlyphs->Delete();
401 myPreviewActorGlyphs = 0;
405 //------------------------------------------------------------------------------
406 void VisuGUI_CutLinesDlg::onPlaneSelect (int theId)
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);
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);
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);
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);
431 setBaseDefault(false);
435 //------------------------------------------------------------------------------
436 void VisuGUI_CutLinesDlg::onCutSelect (int theId, bool theUpdate)
440 myRotXLbl2->setText( tr("LBL_ROT_X"));
441 myRotYLbl2->setText( tr("LBL_ROT_Y"));
444 myRotXLbl2->setText( tr("LBL_ROT_Y"));
445 myRotYLbl2->setText( tr("LBL_ROT_Z"));
448 myRotXLbl2->setText( tr("LBL_ROT_Z"));
449 myRotYLbl2->setText( tr("LBL_ROT_X"));
451 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
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();
466 //------------------------------------------------------------------------------
467 void VisuGUI_CutLinesDlg::setBaseDefault (bool theUpdate)
469 if (!hasInit) return;
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>();
482 if (theUpdate && myPreviewCheck->isChecked() && (myCutLines != NULL)) {
483 //myCutLines->SetBasePlanePosition(aPos);
484 // myCutLines->GetPL()->Update();
490 vtkFloatingPointType aPos = myCutLines->GetBasePlanePosition();
491 myBasePlanePos->setText( QString::number(aPos) );
492 myBasePlanePos->setEnabled(false);
494 myBasePlanePos->setEnabled(true);
498 //------------------------------------------------------------------------------
499 void VisuGUI_CutLinesDlg::DrawTable()
501 if (!hasInit) return;
503 int aNbRows = myPosTable->numRows();
504 int aNbPlanes = (int)myNbSpn->value();
506 myCutLines->SetOrientation(getOrientaion(),
507 myRotXSpn->value()*PI/180.,
508 myRotYSpn->value()*PI/180.);
510 myCutLines->SetNbLines(aNbPlanes);
511 myCutLines->SetDisplacement2(myPosSpn2->value());
512 myCutLines->SetOrientation2(getOrientaion(false),
513 myRotXSpn2->value()*PI/180.,
514 myRotYSpn2->value()*PI/180.);
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());
524 if (aNbPlanes > aNbRows)
525 myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
526 else if (aNbPlanes < aNbRows)
527 myPosTable->setNumRows(aNbPlanes);
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));
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);
544 QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
545 aCheck->setChecked(myCutLines->IsDefaultPosition(i));
546 aCheck->setReplaceable(false);
547 myPosTable->setItem(i, 1, aCheck);
549 vh->setLabel( i, str.arg(i+1) );
552 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
554 if (myPreviewCheck->isChecked()) {
555 // myCutLines->GetPL()->Update();
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];
570 vtkAppendPolyData* aPolyData = myCutLines->GetCutLinesPL()->GetAppendPolyData();
571 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
572 aPlaneMapper->SetInput(aPolyData->GetOutput());
573 vtkFloatingPointType bounds[6];
574 aPlaneMapper->GetBounds(bounds);
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];
581 aSecondPnt[i] = - aDirLn[i];
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;
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();
596 source->SetGlyphTypeToArrow();
598 aPoints->InsertNextPoint(aBoundCenter);
599 profile->SetPoints(aPoints);
601 aFloatArray->SetNumberOfComponents(3);
602 for(int i=0; i<3 ;i++)
603 aFloatArray->InsertNextValue(aSecondPnt[i]);
605 vtkDataSetAttributes* aDataSetAttributes;
606 aDataSetAttributes = profile->GetPointData();
607 aDataSetAttributes->SetVectors(aFloatArray);
609 glyphs->SetScaleFactor(0.25*max_bound);
610 glyphs->SetVectorModeToUseVector();
611 glyphs->SetScaleModeToScaleByVector();
612 glyphs->SetInput(profile);
613 glyphs->SetSource(source->GetOutput());
615 vtkPolyDataMapper* aGlyphsMapper = vtkPolyDataMapper::New();
616 aGlyphsMapper->ScalarVisibilityOff();
617 aGlyphsMapper->SetInput(glyphs->GetOutput());
619 myPreviewActorGlyphs->SetMapper(aGlyphsMapper);
624 aGlyphsMapper->Delete();
625 aFloatArray->Delete();
627 aPlaneMapper->Delete();
629 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
634 //------------------------------------------------------------------------------
635 void VisuGUI_CutLinesDlg::setDefault (int all)
637 myPosTable->setCurrentCell(-1, 1);
638 myPosTable->clearSelection();
639 if (all == 0) return;
641 for (int i = 0; i < (int)myNbSpn->value(); ++i)
642 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
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);
650 myPosTable->item( i, 0 )->setEnabled(true);
654 //------------------------------------------------------------------------------
655 VISU::CutPlanes::Orientation VisuGUI_CutLinesDlg::getOrientaion (bool IsBasePlane)
664 VISU::CutPlanes::Orientation orient;
665 switch (aBG->id(aBG->selected())) {
667 orient = VISU::CutPlanes::XY;
670 orient = VISU::CutPlanes::YZ;
673 orient = VISU::CutPlanes::ZX;
678 //------------------------------------------------------------------------------
679 void VisuGUI_CutLinesDlg::setOrientation (const VISU::CutPlanes::Orientation orient)
682 case VISU::CutPlanes::XY:
683 ((QRadioButton*)mySelPlane->find(0))->setChecked(true);
686 case VISU::CutPlanes::YZ:
687 ((QRadioButton*)mySelPlane->find(1))->setChecked(true);
690 case VISU::CutPlanes::ZX:
691 ((QRadioButton*)mySelPlane->find(2))->setChecked(true);
696 //------------------------------------------------------------------------------
697 void VisuGUI_CutLinesDlg::setOrientation2 (const VISU::CutPlanes::Orientation orient)
700 case VISU::CutPlanes::XY:
701 ((QRadioButton*)mySelPlane2->find(0))->setChecked(true);
704 case VISU::CutPlanes::YZ:
705 ((QRadioButton*)mySelPlane2->find(1))->setChecked(true);
708 case VISU::CutPlanes::ZX:
709 ((QRadioButton*)mySelPlane2->find(2))->setChecked(true);
714 void VisuGUI_CutLinesDlg::onValueChanged (int theRow, int theCol)
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>();
722 if (myPreviewCheck->isChecked()) {
724 //myCutLines->SetLinePosition( theRow, aTxt.toDouble());
725 // myCutLines->GetPL()->Update();
731 } else if (theCol == 1){
732 bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked();
734 //myCutLines->SetDefaultPosition(theRow);
735 // myPosTable->setText(theRow, 0, QString::number(myCutLines->GetLinePosition(theRow)));
736 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
738 if (myPreviewCheck->isChecked()) {
740 // myCutLines->GetPL()->Update();
746 myPosTable->setText(theRow, 0, QString::number(myCutLines->GetLinePosition(theRow)));
748 myPosTable->item(theRow, 0)->setEnabled(!isDefault);
752 void VisuGUI_CutLinesDlg::accept()
754 //if ( !VisuGUI::CheckActiveStudyLock() ) {
758 MYGenerateTable = myCreateTable->isChecked();
759 MYGenerateCurve = myCurvesCheck->isChecked();
760 // if (myScalarPane->check()) {
761 /*jfa tmp:((QWidget*)sender())->setDisabled(true);
762 storeToPrsObject(myPrs);
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());
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();
775 SALOMEDSClient_GenericAttribute* anAttr;
776 if (aTblObj->FindAttribute(anAttr, "AttributeName")) {
777 visuGUI->CreatePlot(aTblObj);
784 if (GET_VTK_VIEWWINDOW(myMgr)) {
786 visuGUI->CreateActor(myPrs);
791 GET_VTK_VIEWWINDOW(myMgr)->onFitAll();
794 visuGUI->RecreateActor(myPrs);
795 if (VTKViewer_ViewWindow* vf = GET_VTK_VIEWWINDOW(myMgr)) {
796 if (vf->getRenderer()->GetActors()->GetNumberOfItems() > 0) {
797 vf->getRenderer()->ResetCameraClippingRange();
802 SALOMEDSClient_Study* aStudy = study()->studyDS();
803 SALOMEDSClient_SObject* aSObject = aStudy->FindObjectID(myPrs->GetEntry());
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();
810 SALOMEDSClient_GenericAttribute* anAttr;
811 if (aTblObj->FindAttribute(anAttr, "AttributeName")) {
812 aBuilder->RemoveObjectWithChildren(aIter->Value()); // We should have only one child
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();
826 SALOMEDSClient_GenericAttribute* anAttr;
827 if (aTblObj->FindAttribute(anAttr, "AttributeName")) {
828 visuGUI->CreatePlot(aTblObj);
836 VisuGUI::application()->objectBrowser()->updateTree();*/
837 myScalarPane->deletePreview();
843 void VisuGUI_CutLinesDlg::reject()
845 /*jfa tmp:if (myIsCreation) {
846 myPrs->RemoveFromStudy();
847 VisuGUI::application()->objectBrowser()->updateTree();
849 myScalarPane->deletePreview();
854 void VisuGUI_CutLinesDlg::onPreviewCheck (bool thePreview)
856 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
858 //storeToPrsObject(myCutLines);
859 // myCutLines->GetPL()->Update();
869 /*! Inverting all curves in the table
871 void VisuGUI_CutLinesDlg::onAllCurvesInvertedCheck(bool theInvert)
873 if (myAllCurvesInvertedCheck->isChecked()){
874 myCutLines->SetAllCurvesInverted(true);
875 myPrs->SetAllCurvesInverted(true);
878 myCutLines->SetAllCurvesInverted(false);
879 myPrs->SetAllCurvesInverted(false);
884 void VisuGUI_CutLinesDlg::onRotation (double theValue)
886 if (myCutLines == NULL) return;
887 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
889 if (myPreviewCheck->isChecked()) {
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();
905 void VisuGUI_CutLinesDlg::onPlanePos (const QString& theValue)
907 if (myCutLines == NULL) return;
908 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
910 if (myPreviewCheck->isChecked()) {
911 //myCutLines->SetBasePlanePosition(theValue.toDouble());
912 // myCutLines->GetPL()->Update();
920 void VisuGUI_CutLinesDlg::onHelp()
922 QString aHelpFileName = "/files/cut_lines_presentation.htm";
923 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
925 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
926 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
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"));
936 //jfa tmp:void VisuGUI_CutLinesDlg::onWindowActivated (SUIT_ViewWindow* theWnd)
938 //jfa tmp: if (theWnd != myStudyWnd)