]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_SegmentationCursorDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VVTK / VVTK_SegmentationCursorDlg.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
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. 
8 // 
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. 
13 // 
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 
17 // 
18 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : VVTK_SegmentationCursorDlg.cxx
21 //  Author : Oleg Uvarov
22 //  Module : VISU
23
24 #include "VVTK_SegmentationCursorDlg.h"
25 #include "VVTK_PrimitiveBox.h"
26 #include "VVTK_SizeBox.h"
27
28 #include "VISU_GaussPtsAct.h"
29 #include "VISU_GaussPtsSettings.h"
30
31 #include "VISU_WidgetCtrl.hxx"
32 #include "VISU_PlanesWidget.hxx"
33 #include "VISU_SphereWidget.hxx"
34
35 #include "VISU_GaussPointsPL.hxx"
36 #include "VISU_OpenGLPointSpriteMapper.hxx"
37
38 #include "LightApp_Application.h"
39 #include "SUIT_MessageBox.h"
40 #include "SUIT_ResourceMgr.h"
41 #include "SUIT_Session.h"
42
43 #include "SVTK_RenderWindowInteractor.h"
44
45 #include <vtkActorCollection.h>
46 #include <vtkCallbackCommand.h>
47 #include <vtkObjectFactory.h>
48 #include <vtkRenderer.h>
49 #include <vtkRenderWindowInteractor.h>
50 #include <vtkSmartPointer.h>
51 #include <vtkImageData.h>
52
53 #include "utilities.h"
54
55 #include <qbuttongroup.h>
56 #include <qcolordialog.h>
57 #include <qfiledialog.h>
58 #include <qgroupbox.h>
59 #include <qlabel.h>
60 #include <qlayout.h>
61 #include <qlineedit.h>
62 #include <qpushbutton.h>
63 #include <qradiobutton.h>
64 #include <qtabwidget.h>
65 #include <qvbox.h>
66
67 #include "QtxAction.h"
68 #include "QtxDblSpinBox.h"
69 #include "QtxIntSpinBox.h"
70
71 //----------------------------------------------------------------
72 VVTK_SegmentationCursorDlg::VVTK_SegmentationCursorDlg( QWidget* parent, const char* name )
73   :QDialog( parent, name, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
74    myEventCallbackCommand( vtkCallbackCommand::New() ),
75    myInsideCursorSettings( VISU_InsideCursorSettings::New() ),
76    myOutsideCursorSettings( VISU_OutsideCursorSettings::New() ),
77    myIsPlaneSegmentation( true ),
78    myWidgetCtrl(NULL),
79    myInteractor(NULL)
80 {
81   myPriority = 0.0;
82   myEventCallbackCommand->Delete();
83   myEventCallbackCommand->SetClientData(this); 
84   myEventCallbackCommand->SetCallback(VVTK_SegmentationCursorDlg::ProcessEvents);
85
86   myInsideCursorSettings->AddObserver(VISU::UpdateFromSettingsEvent, 
87                                       myEventCallbackCommand.GetPointer(), 
88                                       myPriority);
89
90   setCaption( tr( "SEGMENTATION_CURSOR_DLG_TITLE" ) );
91   setSizeGripEnabled(TRUE);
92
93   QVBoxLayout* TopLayout = new QVBoxLayout( this );
94   TopLayout->setSpacing(6);
95   TopLayout->setMargin(11);
96
97   myTabBox = new QTabWidget( this );
98
99   // Segmentation cursor pane
100   mySegmentationCursorBox = new QVBox( this );
101   mySegmentationCursorBox->setMargin(11);
102   mySegmentationCursorBox->setSpacing(6);
103   mySegmentationCursorBox->layout()->setAlignment(Qt::AlignTop);
104
105   // Origin
106   myOriginGroup = new QGroupBox( tr( "ORIGIN_TITLE" ), mySegmentationCursorBox, "OriginGroup" );
107   myOriginGroup->setColumnLayout( 0, Qt::Vertical );
108   myOriginGroup->layout()->setSpacing( 0 );
109   myOriginGroup->layout()->setMargin( 0 );
110
111   QGridLayout* OriginGroupLayout = new QGridLayout( myOriginGroup->layout() );
112   OriginGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
113   OriginGroupLayout->setSpacing(6);
114   OriginGroupLayout->setMargin(11);
115
116   QLabel* XOriginLabel = new QLabel( tr( "ORIGIN_X" ), myOriginGroup );
117   myXOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
118   myXOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
119   myXOriginSpinBox->setMinimumWidth( 100 );
120   myXOriginSpinBox->setValue( 0.0 );
121
122   QLabel* YOriginLabel = new QLabel( tr( "ORIGIN_Y" ), myOriginGroup );
123   myYOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
124   myYOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
125   myYOriginSpinBox->setMinimumWidth( 100 );
126   myYOriginSpinBox->setValue( 0.0 );
127
128   QLabel* ZOriginLabel = new QLabel( tr( "ORIGIN_Z" ), myOriginGroup );
129   myZOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
130   //myZOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
131   myZOriginSpinBox->setMinimumWidth( 100 );
132   myZOriginSpinBox->setValue( 1.0 );
133
134   OriginGroupLayout->addWidget(   XOriginLabel,   0, 0 );
135   OriginGroupLayout->addWidget( myXOriginSpinBox, 0, 1 );
136   OriginGroupLayout->addWidget(   YOriginLabel,   0, 2 );
137   OriginGroupLayout->addWidget( myYOriginSpinBox, 0, 3 );
138   OriginGroupLayout->addWidget(   ZOriginLabel,   0, 4 );
139   OriginGroupLayout->addWidget( myZOriginSpinBox, 0, 5 );
140
141   // Direction ( Plane Segmentation )
142   myDirectionGroup = new QGroupBox( tr( "DIRECTION_TITLE" ), mySegmentationCursorBox, "DirectionGroup" );
143   myDirectionGroup->setColumnLayout( 0, Qt::Vertical );
144   myDirectionGroup->layout()->setSpacing( 0 );
145   myDirectionGroup->layout()->setMargin( 0 );
146
147   QGridLayout* DirectionGroupLayout = new QGridLayout( myDirectionGroup->layout() );
148   DirectionGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
149   DirectionGroupLayout->setSpacing(6);
150   DirectionGroupLayout->setMargin(11);
151
152   QLabel* DXDirectionLabel = new QLabel( tr( "DIRECTION_DX" ), myDirectionGroup );
153   myDXDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
154   myDXDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
155   myDXDirectionSpinBox->setMinimumWidth( 100 );
156   myDXDirectionSpinBox->setValue( 0.0 );
157
158   QLabel* DYDirectionLabel = new QLabel( tr( "DIRECTION_DY" ), myDirectionGroup );
159   myDYDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
160   myDYDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
161   myDYDirectionSpinBox->setMinimumWidth( 100 );
162   myDYDirectionSpinBox->setValue( 0.0 );
163
164   QLabel* DZDirectionLabel = new QLabel( tr( "DIRECTION_DZ" ), myDirectionGroup );
165   myDZDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
166   myDZDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
167   myDZDirectionSpinBox->setMinimumWidth( 100 );
168   myDZDirectionSpinBox->setValue( 1.0 );
169
170   DirectionGroupLayout->addWidget(   DXDirectionLabel,   0, 0 );
171   DirectionGroupLayout->addWidget( myDXDirectionSpinBox, 0, 1 );
172   DirectionGroupLayout->addWidget(   DYDirectionLabel,   0, 2 );
173   DirectionGroupLayout->addWidget( myDYDirectionSpinBox, 0, 3 );
174   DirectionGroupLayout->addWidget(   DZDirectionLabel,   0, 4 );
175   DirectionGroupLayout->addWidget( myDZDirectionSpinBox, 0, 5 );
176
177   // Depth ( Plane Segmentation )
178   myDepthGroup = new QGroupBox( tr( "DEPTH_TITLE" ), mySegmentationCursorBox, "DepthGroup" );
179   myDepthGroup->setColumnLayout( 0, Qt::Vertical );
180   myDepthGroup->layout()->setSpacing( 0 );
181   myDepthGroup->layout()->setMargin( 0 );
182
183   QGridLayout* DepthGroupLayout = new QGridLayout( myDepthGroup->layout() );
184   DepthGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
185   DepthGroupLayout->setSpacing(6);
186   DepthGroupLayout->setMargin(11);
187
188   QLabel* DepthLabel = new QLabel( tr( "DEPTH" ), myDepthGroup );
189   myDepthSpinBox = new QtxDblSpinBox( 0.0, VTK_LARGE_FLOAT, 0.1, myDepthGroup );
190   myDepthSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
191   myDepthSpinBox->setMinimumWidth( 100 );
192   myDepthSpinBox->setValue( 1.0 );
193
194   DepthGroupLayout->addWidget(   DepthLabel,   0, 0 );
195   DepthGroupLayout->addWidget( myDepthSpinBox, 0, 1 );
196
197   // Radius ( Sphere Segmentation )
198   myRadiusGroup = new QGroupBox( tr( "RADIUS_TITLE" ), mySegmentationCursorBox, "RadiusGroup" );
199   myRadiusGroup->setColumnLayout( 0, Qt::Vertical );
200   myRadiusGroup->layout()->setSpacing( 0 );
201   myRadiusGroup->layout()->setMargin( 0 );
202
203   QGridLayout* RadiusGroupLayout = new QGridLayout( myRadiusGroup->layout() );
204   RadiusGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
205   RadiusGroupLayout->setSpacing(6);
206   RadiusGroupLayout->setMargin(11);
207
208   QLabel* RadiusLabel = new QLabel( tr( "RADIUS" ),myRadiusGroup  );
209   myRadiusSpinBox = new QtxDblSpinBox( 0.0, 1000.0, 1.0,myRadiusGroup  );
210   myRadiusSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
211   myRadiusSpinBox->setMinimumWidth( 100 );
212   myRadiusSpinBox->setValue( 100.0 );
213
214   QLabel* RatioLabel = new QLabel( tr( "RATIO" ), myRadiusGroup );
215   myRatioSpinBox = new QtxDblSpinBox( 0.1, 10.0, 0.1,myRadiusGroup  );
216   myRatioSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
217   myRatioSpinBox->setMinimumWidth( 100 );
218   myRatioSpinBox->setValue( 2.0 );
219
220   RadiusGroupLayout->addWidget( RadiusLabel,     0, 0 );
221   RadiusGroupLayout->addWidget( myRadiusSpinBox, 0, 1 );
222   RadiusGroupLayout->addWidget( RatioLabel,      0, 2 );
223   RadiusGroupLayout->addWidget( myRatioSpinBox,  0, 3 );
224
225
226   myTabBox->addTab( mySegmentationCursorBox, tr( "SEGMENTATION_CURSOR_TAB" ) );
227
228
229   // Gauss points pane
230   myGaussPointsBox = new QVBox( this );
231   myGaussPointsBox->setMargin(11);
232   myGaussPointsBox->setSpacing(6);
233
234   // Inside Gauss points
235   QGroupBox* anInsideGroup = new QGroupBox( tr( "INSIDE_GAUSS_POINTS" ), myGaussPointsBox );
236   anInsideGroup->setColumnLayout( 0, Qt::Vertical );
237   anInsideGroup->layout()->setSpacing( 0 );
238   anInsideGroup->layout()->setMargin( 0 );
239
240   QGridLayout* anInsideGroupLayout = new QGridLayout( anInsideGroup->layout() );
241   anInsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
242   anInsideGroupLayout->setSpacing(6);
243   anInsideGroupLayout->setMargin(11);
244
245   // Primitive
246   myInsidePrimitiveBox = new VVTK_PrimitiveBox( anInsideGroup );
247
248   // Size
249   myInsideSizeBox = new VVTK_SizeBox( anInsideGroup );
250   myInsideSizeBox->setType( VVTK_SizeBox::Inside );
251
252   anInsideGroupLayout->addWidget( myInsidePrimitiveBox, 0, 0 );
253   anInsideGroupLayout->addWidget( myInsideSizeBox, 1, 0 );
254
255   // Outside Gauss points
256   QGroupBox* anOutsideGroup = new QGroupBox( tr( "OUTSIDE_GAUSS_POINTS" ), myGaussPointsBox );
257   anOutsideGroup->setColumnLayout( 0, Qt::Vertical );
258   anOutsideGroup->layout()->setSpacing( 0 );
259   anOutsideGroup->layout()->setMargin( 0 );
260
261   QGridLayout* anOutsideGroupLayout = new QGridLayout( anOutsideGroup->layout() );
262   anOutsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
263   anOutsideGroupLayout->setSpacing(6);
264   anOutsideGroupLayout->setMargin(11);
265
266   // Primitive
267   myOutsidePrimitiveBox = new VVTK_PrimitiveBox( anOutsideGroup );
268
269   // Size
270   myOutsideSizeBox = new VVTK_SizeBox( anOutsideGroup );
271   myOutsideSizeBox->setType( VVTK_SizeBox::Outside );
272
273   anOutsideGroupLayout->addWidget( myOutsidePrimitiveBox, 0, 0 );
274   anOutsideGroupLayout->addWidget( myOutsideSizeBox, 1, 0 );
275
276
277   // Magnification
278   QGroupBox* MagnificationGroup = new QGroupBox ( tr( "MAGNIFICATION_TITLE" ), myGaussPointsBox, "MagnificationGroup" );
279   MagnificationGroup->setColumnLayout(0, Qt::Vertical );
280   MagnificationGroup->layout()->setSpacing( 0 );
281   MagnificationGroup->layout()->setMargin( 0 );
282
283   QGridLayout* MagnificationGroupLayout = new QGridLayout (MagnificationGroup->layout());
284   MagnificationGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
285   MagnificationGroupLayout->setSpacing(6);
286   MagnificationGroupLayout->setMargin(11);
287
288   myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), MagnificationGroup );
289   myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, MagnificationGroup );
290   myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
291
292   MagnificationGroupLayout->addWidget( myMagnificationLabel, 0, 0 );
293   MagnificationGroupLayout->addWidget( myMagnificationSpinBox, 0, 1 );
294
295   // Increment
296   myIncrementLabel = new QLabel( tr( "INCREMENT" ), MagnificationGroup );
297   myIncrementSpinBox = new QtxDblSpinBox( 0.01, 10, 0.1, MagnificationGroup );
298   myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
299
300   MagnificationGroupLayout->addWidget( myIncrementLabel, 0, 2 );
301   MagnificationGroupLayout->addWidget( myIncrementSpinBox, 0, 3 );
302
303
304   myTabBox->addTab( myGaussPointsBox, tr( "GAUSS_POINTS_TAB" ) );
305   myTabBox->showPage( myGaussPointsBox );
306
307
308   // Common buttons ===========================================================
309   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
310   GroupButtons->setColumnLayout(0, Qt::Vertical );
311   GroupButtons->layout()->setSpacing( 0 );
312   GroupButtons->layout()->setMargin( 0 );
313   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
314   GroupButtonsLayout->setAlignment( Qt::AlignTop );
315   GroupButtonsLayout->setSpacing( 6 );
316   GroupButtonsLayout->setMargin( 11 );
317
318   QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons, "buttonApply" );
319   buttonApply->setAutoDefault( TRUE );
320   buttonApply->setDefault( TRUE );
321   GroupButtonsLayout->addWidget( buttonApply, 0, 0 );
322   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
323
324   QPushButton* buttonClose = new QPushButton( tr( "&Close" ) , GroupButtons, "buttonClose" );
325   buttonClose->setAutoDefault( TRUE );
326   GroupButtonsLayout->addWidget( buttonClose, 0, 2 );
327
328   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
329   buttonHelp->setAutoDefault( TRUE );
330   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
331
332   TopLayout->addWidget( myTabBox );
333   TopLayout->addWidget( GroupButtons );
334
335   connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) );
336   connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) );
337   connect( buttonHelp,  SIGNAL( clicked() ), this, SLOT( onClickHelp() ) );
338
339   connect(parent, SIGNAL(Show( QShowEvent * )), this, SLOT(onParentShow()));
340   connect(parent, SIGNAL(Hide( QHideEvent * )), this, SLOT(onParentHide()));
341 }
342
343 VVTK_SegmentationCursorDlg::~VVTK_SegmentationCursorDlg()
344 {
345   SetWidgetCtrl(NULL);
346 }
347
348 float VVTK_SegmentationCursorDlg::getMagnification() const
349 {
350   return myMagnificationSpinBox->value() / 100.0;
351 }
352
353 void VVTK_SegmentationCursorDlg::setMagnification( float theMagnification )
354 {
355   myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) );
356 }
357
358 float VVTK_SegmentationCursorDlg::getIncrement() const
359 {
360   return myIncrementSpinBox->value();
361 }
362
363 void VVTK_SegmentationCursorDlg::setIncrement( float theIncrement )
364 {
365   myIncrementSpinBox->setValue( theIncrement );
366 }
367
368
369 void VVTK_SegmentationCursorDlg::SetWidgetCtrl( VISU_WidgetCtrl* theWidgetCtrl )
370 {
371   if(myWidgetCtrl == theWidgetCtrl)
372     return;
373
374   if(myWidgetCtrl)
375     myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
376
377   myWidgetCtrl = theWidgetCtrl;
378
379   if(theWidgetCtrl)
380     theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent, 
381                                myEventCallbackCommand.GetPointer(), 
382                                myPriority);
383 }
384
385 void VVTK_SegmentationCursorDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
386                                                unsigned long theEvent,
387                                                void* theClientData, 
388                                                void* vtkNotUsed(theCallData))
389 {
390   VVTK_SegmentationCursorDlg* self = reinterpret_cast<VVTK_SegmentationCursorDlg*>(theClientData);
391
392   switch(theEvent){
393   case vtkCommand::EndInteractionEvent:
394     self->UpdateSegmentation();
395     break;
396   case VISU::UpdateFromSettingsEvent:
397     self->GetOutsideCursorSettings()->SetMagnification( self->GetInsideCursorSettings()->GetMagnification() );
398     self->GetOutsideCursorSettings()->SetIncrement( self->GetInsideCursorSettings()->GetIncrement() );
399
400     self->UpdateInsideGaussPoints();
401     self->UpdateOutsideGaussPoints();
402
403     self->GetInsideCursorSettings()->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL);
404     self->GetOutsideCursorSettings()->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL);
405     break;
406   }
407 }
408
409 void VVTK_SegmentationCursorDlg::UpdateSegmentation()
410 {
411   if( myIsPlaneSegmentation )
412   {
413     myDirectionGroup->show();
414     myDepthGroup->show();
415     myRadiusGroup->hide();
416
417     VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget();
418     vtkFloatingPointType origin[3];
419     pPlanesWidget->GetOrigin( origin );
420     myXOriginSpinBox->setValue( origin[0] );
421     myYOriginSpinBox->setValue( origin[1] );
422     myZOriginSpinBox->setValue( origin[2] );
423
424     vtkFloatingPointType normal[3];
425     pPlanesWidget->GetNormal( normal );
426     myDXDirectionSpinBox->setValue( normal[0] );
427     myDYDirectionSpinBox->setValue( normal[1] );
428     myDZDirectionSpinBox->setValue( normal[2] );
429
430     myDepthSpinBox->setValue( pPlanesWidget->Distance() );
431   }
432   else
433   {
434     myDirectionGroup->hide();
435     myDepthGroup->hide();
436     myRadiusGroup->show();
437     
438     VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget();
439     vtkFloatingPointType origin[3], aRadius;
440     pSphereWidget->GetCenter(origin);
441     myXOriginSpinBox->setValue( origin[0] );
442     myYOriginSpinBox->setValue( origin[1] );
443     myZOriginSpinBox->setValue( origin[2] );
444     aRadius=pSphereWidget->GetRadius();
445     myRadiusSpinBox->setValue(aRadius);
446     myRatioSpinBox->setValue(pSphereWidget->GetRatio());
447   }
448 }
449
450 void VVTK_SegmentationCursorDlg::UpdateInsideGaussPoints()
451 {
452   int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
453   vtkFloatingPointType aClamp = 200.0;
454   QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/sprite_texture.bmp";
455   QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/sprite_alpha.bmp";
456   vtkFloatingPointType anAlphaThreshold = 0.1;
457   int aResolution = 8;
458   int aMinSize = 3;
459   int aMaxSize = 33;
460   int aMagnification = 100;
461   vtkFloatingPointType anIncrement = 2.0;
462
463   if( !myInsideCursorSettings->GetInitial() )
464   {
465     myInsidePrimitiveBox->setPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
466     myInsidePrimitiveBox->setClamp( myInsideCursorSettings->GetClamp() );
467     myInsidePrimitiveBox->setMainTexture( myInsideMainTexture );
468     myInsidePrimitiveBox->setAlphaTexture( myInsideAlphaTexture );
469     myInsidePrimitiveBox->setAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
470     myInsidePrimitiveBox->setResolution( myInsideCursorSettings->GetResolution() );
471
472     myInsideSizeBox->setMinSize( myInsideCursorSettings->GetMinSize() );
473     myInsideSizeBox->setMaxSize( myInsideCursorSettings->GetMaxSize() );
474
475     this->setMagnification( myInsideCursorSettings->GetMagnification() );
476     this->setIncrement( myInsideCursorSettings->GetIncrement() );
477
478     return;
479   }
480
481   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
482
483   aPrimitiveType = aResourceMgr->integerValue( "VISU", "inside_point_sprite_primitive_type", aPrimitiveType );
484   myInsidePrimitiveBox->setPrimitiveType( aPrimitiveType );
485
486   aClamp = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_clamp", aClamp );
487   myInsidePrimitiveBox->setClamp( aClamp );
488
489   aMainTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_main_texture", aMainTexture );
490   myInsidePrimitiveBox->setMainTexture( aMainTexture );
491
492   anAlphaTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_alpha_texture", anAlphaTexture );
493   myInsidePrimitiveBox->setAlphaTexture( anAlphaTexture );
494
495   anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_alpha_threshold", anAlphaThreshold );
496   myInsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold );
497
498   aResolution = aResourceMgr->integerValue( "VISU", "inside_geom_sphere_resolution", aResolution );
499   myInsidePrimitiveBox->setResolution( aResolution );
500
501   aMinSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_min_size", aMinSize );
502   myInsideSizeBox->setMinSize( aMinSize / 100.0 );
503
504   aMaxSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_max_size", aMaxSize );
505   myInsideSizeBox->setMaxSize( aMaxSize / 100.0 );
506
507   aMagnification = aResourceMgr->integerValue( "VISU", "inside_point_sprite_magnification", aMagnification );
508   this->setMagnification( aMagnification / 100.0 );
509
510   anIncrement = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_increment", anIncrement );
511   this->setIncrement( anIncrement );
512
513   myInsidePrimitiveBox->setFaceLimit( 50000 );
514
515   ApplyInsideGaussPoints();
516 }
517
518 void VVTK_SegmentationCursorDlg::UpdateOutsideGaussPoints()
519 {
520   vtkFloatingPointType aClamp = 256.0;
521   int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
522   QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/sprite_texture.bmp";
523   QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/sprite_alpha.bmp";
524   vtkFloatingPointType anAlphaThreshold = 0.1;
525   int aResolution = 8;
526   int aSize = 25;
527   bool aUniform = false;
528   QColor aColor = Qt::blue;
529
530   if( !myOutsideCursorSettings->GetInitial() )
531   {
532     myOutsidePrimitiveBox->setPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
533     myOutsidePrimitiveBox->setClamp( myOutsideCursorSettings->GetClamp() );
534     myOutsidePrimitiveBox->setMainTexture( myOutsideMainTexture );
535     myOutsidePrimitiveBox->setAlphaTexture( myOutsideAlphaTexture );
536     myOutsidePrimitiveBox->setAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
537     myOutsidePrimitiveBox->setResolution( myOutsideCursorSettings->GetResolution() );
538
539     myOutsideSizeBox->setOutsideSize( myOutsideCursorSettings->GetSize() );
540     myOutsideSizeBox->setUniform( myOutsideCursorSettings->GetUniform() );
541
542     vtkFloatingPointType* aColor = myOutsideCursorSettings->GetColor();
543     myOutsideSizeBox->setColor( QColor( ( int )( aColor[0] * 255.0 ),
544                                         ( int )( aColor[1] * 255.0 ),
545                                         ( int )( aColor[2] * 255.0 ) ) );
546
547     return;
548   }
549
550   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
551
552   aPrimitiveType = aResourceMgr->integerValue( "VISU", "outside_point_sprite_primitive_type", aPrimitiveType );
553   myOutsidePrimitiveBox->setPrimitiveType( aPrimitiveType );
554
555   aClamp = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_clamp", aClamp );
556   myOutsidePrimitiveBox->setClamp( aClamp );
557
558   aMainTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_main_texture", aMainTexture );
559   myOutsidePrimitiveBox->setMainTexture( aMainTexture );
560
561   anAlphaTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_alpha_texture", anAlphaTexture );
562   myOutsidePrimitiveBox->setAlphaTexture( anAlphaTexture );
563
564   anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_alpha_threshold", anAlphaThreshold );
565   myOutsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold );
566
567   aResolution = aResourceMgr->integerValue( "VISU", "outside_geom_sphere_resolution", aResolution );
568   myOutsidePrimitiveBox->setResolution( aResolution );
569
570   aSize = aResourceMgr->integerValue( "VISU", "outside_point_sprite_size", aSize );
571   myOutsideSizeBox->setOutsideSize( aSize / 100.0 );
572
573   aUniform = aResourceMgr->booleanValue( "VISU", "outside_point_sprite_uniform", aUniform );
574   myOutsideSizeBox->setUniform( aUniform );
575
576   aColor = aResourceMgr->colorValue( "VISU", "outside_point_sprite_color", aColor );
577   myOutsideSizeBox->setColor( aColor );
578
579   myOutsidePrimitiveBox->setFaceLimit( 50000 );
580
581   ApplyOutsideGaussPoints();
582 }
583
584 VISU_InsideCursorSettings* VVTK_SegmentationCursorDlg::GetInsideCursorSettings()
585 {
586   return myInsideCursorSettings.GetPointer();
587 }
588
589 VISU_OutsideCursorSettings* VVTK_SegmentationCursorDlg::GetOutsideCursorSettings()
590 {
591   return myOutsideCursorSettings.GetPointer();
592 }
593
594 VISU::TTextureValue 
595 VVTK_SegmentationCursorDlg
596 ::MakeImageData( bool theInside,
597                  const QString& theMainTexture, 
598                  const QString& theAlphaTexture )
599 {
600   if( theInside )
601   {
602     bool updateMainTexture = myInsideMainTexture != theMainTexture;
603     bool updateAlphaTexture = myInsideAlphaTexture != theAlphaTexture;
604     if( !updateMainTexture && !updateAlphaTexture )
605       return 0;
606
607     myInsideMainTexture = theMainTexture;
608     myInsideAlphaTexture = theAlphaTexture;
609   }
610   else
611   {
612     bool updateMainTexture = myOutsideMainTexture != theMainTexture;
613     bool updateAlphaTexture = myOutsideAlphaTexture != theAlphaTexture;
614     if( !updateMainTexture && !updateAlphaTexture )
615       return 0;
616
617     myOutsideMainTexture = theMainTexture;
618     myOutsideAlphaTexture = theAlphaTexture;
619   }
620
621   return VISU::GetTexture( theMainTexture.latin1(), 
622                            theAlphaTexture.latin1());
623 }
624
625 void VVTK_SegmentationCursorDlg::onClickApply()
626 {
627   if( myTabBox->currentPage() == mySegmentationCursorBox )
628     ApplySegmentationCursor();
629   else
630   {
631     QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
632     aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
633     aWarning.append( "Can you please confirm that you want to continue anyway?" );
634     bool toApply = CheckNumberOfFaces() ||
635       SUIT_MessageBox::warn2( this, tr( "Warning" ), aWarning,
636                               tr( "&OK" ), tr( "&Cancel" ), 0, 1, 1 ) == 0;
637
638     if( toApply )
639     {
640       ApplyInsideGaussPoints();
641       ApplyOutsideGaussPoints();
642     }
643   }
644 }
645
646 void VVTK_SegmentationCursorDlg::ApplySegmentationCursor()
647 {
648   if( myIsPlaneSegmentation )
649   {
650     VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget();
651     vtkFloatingPointType origin[3];
652     origin[0] = myXOriginSpinBox->value();
653     origin[1] = myYOriginSpinBox->value();
654     origin[2] = myZOriginSpinBox->value();
655     pPlanesWidget->SetOrigin( origin );
656
657     vtkFloatingPointType normal[3];
658     normal[0] = myDXDirectionSpinBox->value();
659     normal[1] = myDYDirectionSpinBox->value();
660     normal[2] = myDZDirectionSpinBox->value();
661     
662     if( normal[0] == 0.0 && normal[1] == 0.0 && normal[2] == 0.0 )
663     {
664       normal[2] = 1.0;
665       myDZDirectionSpinBox->setValue( 1.0 );
666     }
667     pPlanesWidget->SetNormal( normal );
668
669     pPlanesWidget->SetDistance( myDepthSpinBox->value() );
670     
671     myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
672     myWidgetCtrl->GetInteractor()->Render();
673   }
674   else
675   {
676     VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget();
677     vtkFloatingPointType origin[3], aRadius;
678     origin[0] = myXOriginSpinBox->value();
679     origin[1] = myYOriginSpinBox->value();
680     origin[2] = myZOriginSpinBox->value();
681     pSphereWidget->SetCenter(origin);
682     
683     aRadius=myRadiusSpinBox->value();
684     pSphereWidget->SetRadius(aRadius);
685
686     pSphereWidget->SetRatio(myRatioSpinBox->value());
687
688     myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
689     myWidgetCtrl->GetInteractor()->Render();
690   }
691 }
692
693 void VVTK_SegmentationCursorDlg::ApplyInsideGaussPoints()
694 {
695   QString anInsideMainTexture = myInsidePrimitiveBox->getMainTexture();
696   QString anInsideAlphaTexture = myInsidePrimitiveBox->getAlphaTexture();
697   VISU::TTextureValue aTexture = MakeImageData( true, anInsideMainTexture, anInsideAlphaTexture );
698
699   if( aTexture.GetPointer() )
700     myInsideCursorSettings->SetTexture( aTexture.GetPointer() );
701
702   myInsideCursorSettings->SetInitial( false );
703   myInsideCursorSettings->SetPrimitiveType( myInsidePrimitiveBox->getPrimitiveType() );
704   myInsideCursorSettings->SetClamp( myInsidePrimitiveBox->getClamp() );
705   myInsideCursorSettings->SetAlphaThreshold( myInsidePrimitiveBox->getAlphaThreshold() );
706   myInsideCursorSettings->SetResolution( myInsidePrimitiveBox->getResolution() );
707
708   myInsideCursorSettings->SetMinSize( myInsideSizeBox->getMinSize() );
709   myInsideCursorSettings->SetMaxSize( myInsideSizeBox->getMaxSize() );
710
711   myInsideCursorSettings->SetMagnification( this->getMagnification() );
712   myInsideCursorSettings->SetIncrement( this->getIncrement() );
713
714   myInsideCursorSettings->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL);
715 }
716
717 void VVTK_SegmentationCursorDlg::ApplyOutsideGaussPoints()
718 {
719   QString anOutsideMainTexture = myOutsidePrimitiveBox->getMainTexture();
720   QString anOutsideAlphaTexture = myOutsidePrimitiveBox->getAlphaTexture();
721   VISU::TTextureValue aTexture = MakeImageData( false, anOutsideMainTexture, anOutsideAlphaTexture );
722
723   if( aTexture.GetPointer() )
724     myOutsideCursorSettings->SetTexture( aTexture.GetPointer() );
725
726   myOutsideCursorSettings->SetInitial( false );
727   myOutsideCursorSettings->SetPrimitiveType( myOutsidePrimitiveBox->getPrimitiveType() );
728   myOutsideCursorSettings->SetClamp( myOutsidePrimitiveBox->getClamp() );
729   myOutsideCursorSettings->SetAlphaThreshold( myOutsidePrimitiveBox->getAlphaThreshold() );
730   myOutsideCursorSettings->SetResolution( myOutsidePrimitiveBox->getResolution() );
731
732   myOutsideCursorSettings->SetSize( myOutsideSizeBox->getOutsideSize() );
733   myOutsideCursorSettings->SetUniform( myOutsideSizeBox->getUniform() );
734
735   QColor aButtonColor = myOutsideSizeBox->getColor();
736   vtkFloatingPointType aColor[3];
737   aColor[0] = aButtonColor.red() / 255.0;
738   aColor[1] = aButtonColor.green() / 255.0;
739   aColor[2] = aButtonColor.blue() / 255.0;
740   myOutsideCursorSettings->SetColor( aColor );
741
742   myOutsideCursorSettings->SetMagnification( this->getMagnification() );
743   myOutsideCursorSettings->SetIncrement( this->getIncrement() );
744
745   myOutsideCursorSettings->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL);
746 }
747
748 void VVTK_SegmentationCursorDlg::onClickClose()
749 {
750   myPlaneAction->setOn( false );
751   mySphereAction->setOn( false );
752
753   emit scgClose();
754
755   reject();
756 }
757
758 void VVTK_SegmentationCursorDlg::onClickHelp()
759 {
760   QString aHelpFileName = "segmentation.htm";
761   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
762   if (app)
763     app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
764   else {
765                 QString platform;
766 #ifdef WIN32
767                 platform = "winapplication";
768 #else
769                 platform = "application";
770 #endif
771     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
772                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
773                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
774                            QObject::tr("BUT_OK"));
775   }
776 }
777
778 void VVTK_SegmentationCursorDlg::done( int r )
779 {
780   myPlaneAction->setOn( false );
781   mySphereAction->setOn( false );
782
783   emit scgClose();
784
785   QDialog::done( r );
786 }
787
788 void VVTK_SegmentationCursorDlg::onParentShow()
789 {
790   if(myPlaneAction->isOn() || mySphereAction->isOn())
791     show();
792   else
793     hide();
794 }
795
796 void VVTK_SegmentationCursorDlg::onParentHide()
797 {
798   hide();
799 }
800
801 bool VVTK_SegmentationCursorDlg::CheckNumberOfFaces()
802 {
803   if( !myInteractor )
804     return false;
805
806   vtkRenderer* aRenderer = myInteractor->getRenderer();
807
808   if( !aRenderer )
809     return false;
810
811   int aNumberOfPoints = 0;
812
813   vtkActor* anActor;
814   vtkActorCollection* anActColl = aRenderer->GetActors();
815   for( anActColl->InitTraversal(); ( anActor = anActColl->GetNextActor() ) != NULL; )
816   {
817     if( VISU_GaussPtsAct1* aGaussActor = VISU_GaussPtsAct1::SafeDownCast( anActor ) )
818       aNumberOfPoints += aGaussActor->GetInput()->GetNumberOfCells();
819   }
820   return !( myInsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere &&
821             aNumberOfPoints * myInsidePrimitiveBox->getFaceNumber() * 2 > myInsidePrimitiveBox->getFaceLimit() ||
822             myOutsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere &&
823             aNumberOfPoints * myOutsidePrimitiveBox->getFaceNumber() > myOutsidePrimitiveBox->getFaceLimit() );
824 }
825
826 void VVTK_SegmentationCursorDlg::keyPressEvent( QKeyEvent* e )
827 {
828   QDialog::keyPressEvent( e );
829   if ( e->isAccepted() )
830     return;
831
832   if ( e->key() == Key_F1 )
833     {
834       e->accept();
835       onClickHelp();
836     }
837 }