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_CutSegmentDlg.cxx
23 // Author : Oleg UVAROV
26 #include "VisuGUI_CutSegmentDlg.h"
29 #include "VisuGUI_Tools.h"
30 #include "VisuGUI_ViewTools.h"
31 #include "VisuGUI_InputPane.h"
33 #include "VISU_Gen_i.hh"
34 #include "VISU_CutSegment_i.hh"
35 #include "VISU_ColoredPrs3dFactory.hh"
37 #include "VISU_PipeLine.hxx"
38 #include "VISU_CutSegmentPL.hxx"
40 #include "SVTK_ViewWindow.h"
42 #include "LightApp_Application.h"
43 #include "SalomeApp_Study.h"
45 #include "SUIT_ResourceMgr.h"
50 #include <QPushButton>
52 #include <vtkAppendPolyData.h>
53 #include <vtkCellArray.h>
54 #include <vtkDataSetMapper.h>
55 #include <vtkFloatArray.h>
56 #include <vtkGlyph3D.h>
57 #include <vtkGlyphSource2D.h>
58 #include <vtkPointData.h>
59 #include <vtkPolyData.h>
60 #include <vtkPolyDataMapper.h>
61 #include <vtkRenderer.h>
65 VisuGUI_CutSegmentDlg::VisuGUI_CutSegmentDlg (SalomeApp_Module* theModule)
66 : VisuGUI_ScalarBarBaseDlg(theModule),
68 myPreviewActorGlyphs(0),
69 myPreviewActorPoints(0)
71 setWindowTitle("Cut Segment Definition");
72 setSizeGripEnabled(true);
74 QVBoxLayout* aMainLayout = new QVBoxLayout (this);
75 aMainLayout->setMargin( 7 );
76 aMainLayout->setSpacing(5);
78 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
82 myTabBox = new QTabWidget(this);
85 QFrame* aCutSegmentPane = new QFrame( this );
87 QGroupBox* aSegmentBox = new QGroupBox( tr( "LBL_SEGMENT" ), aCutSegmentPane );
89 QLabel* aPoint1Label = new QLabel( tr( "LBL_POINT_1" ), aSegmentBox );
90 QLabel* aPoint1XLabel = new QLabel( tr( "LBL_X" ), aSegmentBox );
91 QLabel* aPoint1YLabel = new QLabel( tr( "LBL_Y" ), aSegmentBox );
92 QLabel* aPoint1ZLabel = new QLabel( tr( "LBL_Z" ), aSegmentBox );
93 QLabel* aPoint2Label = new QLabel( tr( "LBL_POINT_2" ), aSegmentBox );
94 QLabel* aPoint2XLabel = new QLabel( tr( "LBL_X" ), aSegmentBox );
95 QLabel* aPoint2YLabel = new QLabel( tr( "LBL_Y" ), aSegmentBox );
96 QLabel* aPoint2ZLabel = new QLabel( tr( "LBL_Z" ), aSegmentBox );
97 for( int i = 0; i < 3; i++ ) {
98 myPoint1.append( new QtxDoubleSpinBox( aSegmentBox ) );
99 myPoint2.append( new QtxDoubleSpinBox( aSegmentBox ) );
102 QListIterator<QtxDoubleSpinBox*> anIter( myPoint1 + myPoint2 );
103 while( anIter.hasNext() ) {
104 QtxDoubleSpinBox* aSpinBox = anIter.next();
105 aSpinBox->setDecimals( 6 );
106 aSpinBox->setMinimumWidth( 100 );
109 QGridLayout* aSegmentBoxLayout = new QGridLayout( aSegmentBox );
110 aSegmentBoxLayout->addWidget( aPoint1Label, 0, 0 );
111 aSegmentBoxLayout->addWidget( aPoint1XLabel, 0, 1 );
112 aSegmentBoxLayout->addWidget( myPoint1[0], 0, 2 );
113 aSegmentBoxLayout->addWidget( aPoint1YLabel, 0, 3 );
114 aSegmentBoxLayout->addWidget( myPoint1[1], 0, 4 );
115 aSegmentBoxLayout->addWidget( aPoint1ZLabel, 0, 5 );
116 aSegmentBoxLayout->addWidget( myPoint1[2], 0, 6 );
117 aSegmentBoxLayout->addWidget( aPoint2Label, 1, 0 );
118 aSegmentBoxLayout->addWidget( aPoint2XLabel, 1, 1 );
119 aSegmentBoxLayout->addWidget( myPoint2[0], 1, 2 );
120 aSegmentBoxLayout->addWidget( aPoint2YLabel, 1, 3 );
121 aSegmentBoxLayout->addWidget( myPoint2[1], 1, 4 );
122 aSegmentBoxLayout->addWidget( aPoint2ZLabel, 1, 5 );
123 aSegmentBoxLayout->addWidget( myPoint2[2], 1, 6 );
125 myPreviewCheck = new QCheckBox( tr( "LBL_SHOW_PREVIEW" ), aCutSegmentPane );
126 myPreviewCheck->setChecked( aResourceMgr->booleanValue( "VISU", "show_preview", false ) );
128 myAllCurvesInvertedCheck = new QCheckBox( tr( "LBL_INVERT_CURVES" ), aCutSegmentPane );
129 myAllCurvesInvertedCheck->setChecked( false );
131 myUseAbsoluteLengthCheck = new QCheckBox( tr( "LBL_ABSOLUTE_LENGTH" ), aCutSegmentPane );
132 myUseAbsoluteLengthCheck->setChecked( false );
134 myCreateTable = new QCheckBox( tr("LBL_GENERATE_TABLE"), aCutSegmentPane );
135 myCreateTable->setChecked( aResourceMgr->booleanValue( "VISU", "generate_data_table", true ) );
137 QWidget* aCheckPane = new QWidget( aCutSegmentPane );
138 myCurvesCheck = new QCheckBox( tr( "LBL_GENERATE_CURVES" ), aCheckPane );
139 myCurvesCheck->setChecked( aResourceMgr->booleanValue( "VISU", "generate_curves", true ) );
140 myCurvesCheck->setEnabled( aResourceMgr->booleanValue( "VISU", "generate_data_table", true ) );
142 QHBoxLayout* aCheckLayout = new QHBoxLayout( aCheckPane );
143 aCheckLayout->setMargin( 0 );
144 aCheckLayout->setSpacing( 0 );
145 aCheckLayout->insertSpacing( 0, 20 );
146 aCheckLayout->addWidget( myCurvesCheck );
148 QVBoxLayout* aCutSegmentLayout = new QVBoxLayout( aCutSegmentPane );
149 aCutSegmentLayout->setMargin( 5 );
150 aCutSegmentLayout->setSpacing( 6 );
151 aCutSegmentLayout->addWidget( aSegmentBox );
152 aCutSegmentLayout->addWidget( myPreviewCheck );
153 aCutSegmentLayout->addWidget( myAllCurvesInvertedCheck );
154 aCutSegmentLayout->addWidget( myUseAbsoluteLengthCheck );
155 aCutSegmentLayout->addWidget( myCreateTable );
156 aCutSegmentLayout->addWidget( aCheckPane );
157 aCutSegmentLayout->addStretch();
159 myTabBox->addTab( aCutSegmentPane, tr("LBL_CUT_SEGMENT") );
161 myInputPane = new VisuGUI_InputPane(VISU::TCUTSEGMENT, theModule, this);
162 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
163 myTabBox->addTab(myInputPane, "Input");
165 aMainLayout->addWidget(myTabBox);
168 QFrame* aBtnBox = new QFrame(this);
169 QHBoxLayout* aHBLay = new QHBoxLayout( aBtnBox );
170 aBtnBox->setFrameStyle(QFrame::Box | QFrame::Sunken);
171 aBtnBox->setLineWidth( 1 );
172 aHBLay->setSpacing( 5 );
173 aHBLay->setMargin( 11 );
175 QPushButton* aOkBtn = new QPushButton (tr("BUT_OK"), aBtnBox);
176 aOkBtn->setAutoDefault( TRUE );
177 aOkBtn->setDefault( true );
178 aHBLay->addWidget(aOkBtn);
180 aHBLay->addStretch();
182 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CANCEL"), aBtnBox);
183 aHBLay->addWidget(aCloseBtn);
185 QPushButton* aHelpBtn = new QPushButton(tr("BUT_HELP"), aBtnBox);
186 aHBLay->addWidget(aHelpBtn);
188 aMainLayout->addWidget(aBtnBox);
190 // signals and slots connections
191 connect(myPreviewCheck, SIGNAL(toggled(bool)) , this, SLOT(onPreviewCheck(bool)));
192 connect(myAllCurvesInvertedCheck, SIGNAL(toggled(bool)),this, SLOT(onAllCurvesInvertedCheck(bool)));
193 for( int i = 0; i < 3; i++ ) {
194 connect(myPoint1[ i ], SIGNAL(valueChanged(double)), this, SLOT(onPointModified()));
195 connect(myPoint2[ i ], SIGNAL(valueChanged(double)), this, SLOT(onPointModified()));
197 connect(myCreateTable , SIGNAL(toggled(bool)), myCurvesCheck, SLOT(setEnabled(bool)));
199 connect(aOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
200 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
201 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
207 VisuGUI_CutSegmentDlg::~VisuGUI_CutSegmentDlg()
210 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
214 //------------------------------------------------------------------------------
215 void VisuGUI_CutSegmentDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
219 myPrsCopy = VISU::TSameAsFactory<VISU::TCUTSEGMENT>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
221 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
224 myCutSegment = VISU::TSameAsFactory<VISU::TCUTSEGMENT>().Create(myPrsCopy, VISU::ColoredPrs3d_i::EDoNotPublish);
225 myCutSegment->CopyCurvesInverted(myPrsCopy->GetCurvesInverted());
226 myAllCurvesInvertedCheck->setChecked( myCutSegment->IsAllCurvesInverted() );
227 myUseAbsoluteLengthCheck->setChecked( myCutSegment->IsUseAbsoluteLength() );
229 vtkDataSet* anInput = myCutSegment->GetPipeLine()->GetInput();
232 vtkFloatingPointType bounds[6];
233 anInput->GetBounds( bounds );
235 for( int i = 0; i < 3; i++ ) {
236 double min = bounds[ 2*i ], max = bounds[ 2*i+1 ];
237 myPoint1[ i ]->setRange( min, max );
238 myPoint2[ i ]->setRange( min, max );
240 myPoint1[ i ]->setSingleStep( ( max - min ) / 10 );
241 myPoint2[ i ]->setSingleStep( ( max - min ) / 10 );
245 myPrsCopy->GetPoint1( p1[0], p1[1], p1[2] );
246 myPrsCopy->GetPoint2( p2[0], p2[1], p2[2] );
248 for( int i = 0; i < 3; i++ ) {
249 myPoint1[i]->setValue( p1[i] );
250 myPoint2[i]->setValue( p2[i] );
254 if (myPreviewCheck->isChecked()) {
261 myInputPane->initFromPrsObject( myPrsCopy );
262 myTabBox->setCurrentIndex( 0 );
265 //------------------------------------------------------------------------------
266 int VisuGUI_CutSegmentDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
268 if(!myInputPane->check() || !GetScalarPane()->check())
271 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
272 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
274 myPrsCopy->SetAllCurvesInverted( myAllCurvesInvertedCheck->isChecked() );
275 myPrsCopy->SetUseAbsoluteLength( myUseAbsoluteLengthCheck->isChecked() );
278 for( int i = 0; i < 3; i++ ) {
279 p1[i] = myPoint1[i]->value();
280 p2[i] = myPoint2[i]->value();
282 myPrsCopy->SetPoint1( p1[0], p1[1], p1[2] );
283 myPrsCopy->SetPoint2( p2[0], p2[1], p2[2] );
285 VISU::TSameAsFactory<VISU::TCUTSEGMENT>().Copy(myPrsCopy, thePrs);
290 //------------------------------------------------------------------------------
291 void VisuGUI_CutSegmentDlg::createPlanes()
293 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
294 if (aView == NULL) return;
295 if (!(bool)myCutSegment) return;
296 if (myPreviewActor != 0) return;
298 storeToPrsObject(myCutSegment);
299 myCutSegment->GetPipeLine()->Update();
300 vtkAppendPolyData* aPolyData = myCutSegment->GetSpecificPL()->GetAppendPolyData();
301 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
302 aPlaneMapper->SetInput(aPolyData->GetOutput());
303 aPlaneMapper->ScalarVisibilityOff();
305 myPreviewActorGlyphs = SALOME_Actor::New();
306 myPreviewActorGlyphs->PickableOff();
309 myPreviewActorPoints = SALOME_Actor::New();
310 myPreviewActorPoints->PickableOff();
313 myPreviewActor = SALOME_Actor::New();
314 myPreviewActor->PickableOff();
315 myPreviewActor->SetMapper(aPlaneMapper);
316 aPlaneMapper->Delete();
317 aView->AddActor(myPreviewActor);
318 aView->AddActor(myPreviewActorGlyphs);
319 aView->AddActor(myPreviewActorPoints);
320 aView->getRenderer()->Render();
324 //------------------------------------------------------------------------------
325 void VisuGUI_CutSegmentDlg::deletePlanes()
327 if (myPreviewActor == 0) return;
328 vtkRenderer* aRend = myPreviewActor->GetRenderer();
329 vtkRenderer* aRendGlyphs = myPreviewActorGlyphs->GetRenderer();
330 vtkRenderer* aRendPoints = myPreviewActorPoints->GetRenderer();
332 vtkRenderWindow* aWnd1 = aRend->GetRenderWindow();
333 vtkRenderWindow* aWnd2 = aRendGlyphs->GetRenderWindow();
334 vtkRenderWindow* aWnd3 = aRendPoints->GetRenderWindow();
336 myPreviewActor->RemoveFromRender(aRend);
337 if(aRendGlyphs && aWnd2)
338 myPreviewActorGlyphs->RemoveFromRender(aRendGlyphs);
339 if(aRendPoints && aWnd3)
340 myPreviewActorPoints->RemoveFromRender(aRendPoints);
342 myPreviewActor->Delete();
343 myPreviewActorGlyphs->Delete();
344 myPreviewActorPoints->Delete();
346 myPreviewActorGlyphs = 0;
347 myPreviewActorPoints = 0;
350 //------------------------------------------------------------------------------
351 void VisuGUI_CutSegmentDlg::updateGlyphs(bool update){
352 if (myPreviewActorGlyphs == 0 ) return;
353 const vtkFloatingPointType *aDirLn = myCutSegment->GetSpecificPL()->GetRealDirLn();
354 vtkFloatingPointType aSecondPnt[3];
355 vtkFloatingPointType aBoundCenter[3];
357 vtkAppendPolyData* aPolyData = myCutSegment->GetSpecificPL()->GetAppendPolyData();
358 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
359 aPlaneMapper->SetInput(aPolyData->GetOutput());
360 vtkFloatingPointType bounds[6];
361 aPlaneMapper->GetBounds(bounds);
363 for(int i=0; i<3; i++) aBoundCenter[i] = (bounds[i*2] + bounds[i*2+1])/2.0;
364 for(int i=0; i<3; i++){
365 if (!myAllCurvesInvertedCheck->isChecked())
366 aSecondPnt[i] = aDirLn[i];
368 aSecondPnt[i] = - aDirLn[i];
371 vtkFloatingPointType max_bound = 0;
372 max_bound < bounds[1]-bounds[0] ? max_bound = bounds[1] - bounds[0] : max_bound = max_bound;
373 max_bound < bounds[3]-bounds[2] ? max_bound = bounds[3] - bounds[2] : max_bound = max_bound;
374 max_bound < bounds[5]-bounds[4] ? max_bound = bounds[5] - bounds[4] : max_bound = max_bound;
376 vtkPolyData* profile = vtkPolyData::New();
377 vtkPoints* aPoints = vtkPoints::New();
378 vtkGlyph3D* glyphs = vtkGlyph3D::New();
379 vtkFloatArray *aFloatArray = vtkFloatArray::New();
380 vtkGlyphSource2D* source = vtkGlyphSource2D::New();
383 source->SetGlyphTypeToArrow();
385 aPoints->InsertNextPoint(aBoundCenter);
386 profile->SetPoints(aPoints);
388 aFloatArray->SetNumberOfComponents(3);
389 for(int i=0; i<3 ;i++)
390 aFloatArray->InsertNextValue(aSecondPnt[i]);
392 vtkDataSetAttributes* aDataSetAttributes;
393 aDataSetAttributes = profile->GetPointData();
394 aDataSetAttributes->SetVectors(aFloatArray);
396 glyphs->SetScaleFactor(0.25*max_bound);
397 glyphs->SetVectorModeToUseVector();
398 glyphs->SetScaleModeToScaleByVector();
399 glyphs->SetInput(profile);
400 glyphs->SetSource(source->GetOutput());
402 vtkPolyDataMapper* aGlyphsMapper = vtkPolyDataMapper::New();
403 aGlyphsMapper->ScalarVisibilityOff();
404 aGlyphsMapper->SetInput(glyphs->GetOutput());
406 myPreviewActorGlyphs->SetMapper(aGlyphsMapper);
411 aGlyphsMapper->Delete();
412 aFloatArray->Delete();
414 aPlaneMapper->Delete();
416 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
421 //------------------------------------------------------------------------------
422 void VisuGUI_CutSegmentDlg::updatePoints( bool update )
424 if( !myPreviewActorPoints )
427 vtkFloatingPointType aPoint1[3], aPoint2[3];
428 myCutSegment->GetSpecificPL()->GetPoint1( aPoint1[0], aPoint1[1], aPoint1[2] );
429 myCutSegment->GetSpecificPL()->GetPoint2( aPoint2[0], aPoint2[1], aPoint2[2] );
431 vtkPoints* aPoints = vtkPoints::New();
432 aPoints->InsertNextPoint( aPoint1 );
433 aPoints->InsertNextPoint( aPoint2 );
435 vtkCellArray* aVerts = vtkCellArray::New();
436 for( vtkIdType i = 0, n = aPoints->GetNumberOfPoints(); i < n; i++ )
437 aVerts->InsertNextCell( 1, &i );
439 vtkPolyData* aProfile = vtkPolyData::New();
440 aProfile->SetPoints( aPoints );
441 aProfile->SetVerts( aVerts );
443 vtkPolyDataMapper* aPointsMapper = vtkPolyDataMapper::New();
444 aPointsMapper->ScalarVisibilityOff();
445 aPointsMapper->SetInput( aProfile );
447 myPreviewActorPoints->SetMapper( aPointsMapper );
448 myPreviewActorPoints->GetProperty()->SetRepresentationToPoints();
449 myPreviewActorPoints->GetProperty()->SetPointSize( 5 );
455 if( SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>() )
460 //------------------------------------------------------------------------------
461 void VisuGUI_CutSegmentDlg::accept()
463 VisuGUI_ScalarBarBaseDlg::accept();
466 //------------------------------------------------------------------------------
467 void VisuGUI_CutSegmentDlg::reject()
469 VisuGUI_ScalarBarBaseDlg::reject();
472 //------------------------------------------------------------------------------
473 void VisuGUI_CutSegmentDlg::onPreviewCheck (bool thePreview)
475 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
485 //------------------------------------------------------------------------------
486 void VisuGUI_CutSegmentDlg::onAllCurvesInvertedCheck(bool theInvert)
488 bool anIsAllCurvesInverted = myAllCurvesInvertedCheck->isChecked();
490 myCutSegment->SetAllCurvesInverted( anIsAllCurvesInverted );
491 myPrsCopy->SetAllCurvesInverted( anIsAllCurvesInverted );
497 //------------------------------------------------------------------------------
498 void VisuGUI_CutSegmentDlg::onPointModified ()
500 if (!(bool)myCutSegment) return;
501 SVTK_ViewWindow* aView = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
503 if (myPreviewCheck->isChecked()) {
510 //------------------------------------------------------------------------------
511 QString VisuGUI_CutSegmentDlg::GetContextHelpFilePath()
513 return "cut_segment_page.html";