2 // File : SALOMEGUI_NonIsometricDlg.cxx
3 // Created : Thu Dec 18 12:01:00 2002
4 // Author : Vasily Rusyaev
5 // Project : SALOME PRO
7 // Copyright : Open CASCADE
10 #include "VisuGUI_NonIsometricDlg.h"
12 #include <qgroupbox.h>
14 #include <qpushbutton.h>
16 #include <qcombobox.h>
19 //#include <qapplication.h>
21 #include "QAD_SpinBoxDbl.h"
22 #include "utilities.h"
24 #include "QAD_Application.h"
25 #include "QAD_Desktop.h"
26 #include "QAD_StudyFrame.h"
27 #include "QAD_RightFrame.h"
28 #include "VTKViewer_ViewFrame.h"
29 #include "VISU_Actor.h"
31 #include <vtkTransformPolyDataFilter.h>
32 #include <vtkDataSetMapper.h>
37 VisuGUI_NonIsometricDlg::VisuGUI_NonIsometricDlg( QWidget* parent, const char* name, bool modal, WFlags fl )
38 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
41 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame();
42 VTKViewer_NonIsometricTransform *aTransform = NULL;
43 if ( sf->getTypeView() == VIEW_VTK )
45 VTKViewer_ViewFrame* vf = (VTKViewer_ViewFrame*) ( sf->getRightFrame()->getViewFrame() );
46 aTransform = vf->getNonIsometricTransform();
50 setName( "NonIsometricDlg" );
51 setCaption( tr( "Scaling" ) );
52 setSizeGripEnabled( TRUE );
54 // Create layout for this dialog
55 QGridLayout* layoutDlg = new QGridLayout( this );
56 layoutDlg->setSpacing(6);
57 layoutDlg->setMargin(11);
59 // Create croup box with grid layout
60 QGroupBox* GroupBox = new QGroupBox( this, "GroupBox" );
62 QGridLayout* glGroupBox = new QGridLayout( GroupBox );
63 glGroupBox->setMargin(11);
64 glGroupBox->setSpacing(6);
66 //Create font: 14pnts, bold, italic
67 //It will be used for all labels in this group box
68 QFont m_font14bi = font();
69 m_font14bi.setPointSize((int)(m_font14bi.pointSize()*1.4));
70 // m_font14bi.setItalic( TRUE );
71 m_font14bi.setBold( TRUE );
73 // Create "Choose function" label
74 QLabel* TextLabel1 = new QLabel( tr( "Choose function:" ), GroupBox, "TextLabel1" );
75 glGroupBox->addWidget ( TextLabel1, 1, 0 );
77 // Create "Type the coefficient" label
78 QLabel* TextLabel2 = new QLabel( tr( "Coefficient:" ), GroupBox, "TextLabel2" );
79 glGroupBox->addWidget ( TextLabel2, 2, 0 );
81 // Create "Applying function" label
82 QLabel* TextLabel3 = new QLabel( tr( "Applying function:" ), GroupBox, "TextLabel3" );
83 glGroupBox->addWidget ( TextLabel3, 3, 0 );
85 glGroupBox->addColSpacing ( 1, 10 );
88 QLabel* TextLabelX = new QLabel( "X", GroupBox, "TextLabelX" );
89 TextLabelX->setAlignment( int( QLabel::AlignCenter ) );
90 //NRI TextLabelX->setFont( m_font14bi );
91 glGroupBox->addWidget ( TextLabelX, 0, 2 );
93 // Create combobox for selecting scaling function on a X axis
94 m_cbXfunction = new QComboBox( FALSE, GroupBox, "m_cbXFunction");
95 m_cbXfunction->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
96 m_cbXfunction->setMinimumWidth( 80 );
97 glGroupBox->addWidget(m_cbXfunction, 1, 2 );
99 // Create double spinbox for changing coef. in the scaling function on a X axis
100 m_sbXcoeff = new QAD_SpinBoxDbl( GroupBox, "m_sbXcoeff" );
101 m_sbXcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
102 m_sbXcoeff->setMinimumWidth( 80 );
103 glGroupBox->addWidget(m_sbXcoeff, 2, 2 );
105 // Create informative label about the applying scaling function on a X axis
106 m_lXFunction = new QLabel( GroupBox, "m_lXFunction" );
107 //NRI m_lXFunction->setFont( m_font14bi );
108 m_lXFunction->setAlignment( int( QLabel::AlignCenter ) );
109 glGroupBox->addWidget(m_lXFunction, 3, 2 );
111 FillComboBox( m_cbXfunction );
114 QLabel* TextLabelY = new QLabel( "Y", GroupBox, "TextLabelY" );
115 TextLabelY->setAlignment( int( QLabel::AlignCenter ) );
116 //NRI TextLabelY->setFont( m_font14bi );
117 glGroupBox->addWidget ( TextLabelY, 0, 3 );
119 // Create combobox for selecting scaling function on a Y axis
120 m_cbYfunction = new QComboBox( FALSE, GroupBox, "m_cbYFunction");
121 m_cbYfunction->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
122 m_cbYfunction->setMinimumWidth( 80 );
123 glGroupBox->addWidget(m_cbYfunction, 1, 3 );
125 // Create double spinbox for changing coef. in the scaling function on a Y axis
126 m_sbYcoeff = new QAD_SpinBoxDbl( GroupBox, "m_sbYcoeff" );
127 m_sbYcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
128 m_sbYcoeff->setMinimumWidth( 80 );
129 glGroupBox->addWidget(m_sbYcoeff, 2, 3 );
131 // Create informative label about the applying scaling function on a Y axis
132 m_lYFunction = new QLabel( GroupBox, "m_lYFunction" );
133 m_lYFunction->setAlignment( int( QLabel::AlignCenter ) );
134 //NRI m_lYFunction->setFont( m_font14bi );
135 glGroupBox->addWidget(m_lYFunction, 3, 3 );
137 FillComboBox( m_cbYfunction );
140 QLabel* TextLabelZ = new QLabel( "Z", GroupBox, "TextLabelZ" );
141 TextLabelZ->setAlignment( int( QLabel::AlignCenter ) );
142 //NRI TextLabelZ->setFont( m_font14bi );
143 glGroupBox->addWidget ( TextLabelZ, 0, 4 );
145 // Create combobox for selecting scaling function on a Z axis
146 m_cbZfunction = new QComboBox( FALSE, GroupBox, "m_cbZFunction");
147 m_cbZfunction->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
148 m_cbZfunction->setMinimumWidth( 80 );
149 glGroupBox->addWidget(m_cbZfunction, 1, 4 );
151 // Create double spinbox for changing coef. in the scaling function on a Z axis
152 m_sbZcoeff = new QAD_SpinBoxDbl( GroupBox, "m_sbZcoeff" );
153 m_sbZcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
154 m_sbZcoeff->setMinimumWidth( 80 );
155 glGroupBox->addWidget(m_sbZcoeff, 2, 4 );
157 // Create informative label about the applying scaling function on a Z axis
158 m_lZFunction = new QLabel( GroupBox, "m_lZFunction" );
159 m_lZFunction->setAlignment( int( QLabel::AlignCenter ) );
160 //NRI m_lZFunction->setFont( m_font14bi );
161 glGroupBox->addWidget(m_lZFunction, 3, 4 );
163 FillComboBox( m_cbZfunction );
166 int item = aTransform->GetFunctionType(AxisFunction::XAxis);
167 m_cbXfunction->setCurrentItem(item);
169 m_sbXcoeff ->setEnabled (TRUE);
170 FunctionChanged( m_cbXfunction);
172 item = aTransform->GetFunctionType(AxisFunction::YAxis);
173 m_cbYfunction->setCurrentItem(item);
175 m_sbYcoeff ->setEnabled (TRUE);
176 FunctionChanged( m_cbYfunction );
178 item = aTransform->GetFunctionType(AxisFunction::ZAxis);
179 m_cbZfunction->setCurrentItem(item);
181 m_sbZcoeff ->setEnabled (TRUE);
182 FunctionChanged( m_cbZfunction);
184 m_sbXcoeff -> setValue(aTransform->GetCoeff(AxisFunction::XAxis));
185 m_sbYcoeff -> setValue(aTransform->GetCoeff(AxisFunction::YAxis));
186 m_sbZcoeff -> setValue(aTransform->GetCoeff(AxisFunction::ZAxis));
189 // Create <Reset> button
190 QPushButton* m_bReset = new QPushButton( tr( "&Reset" ), GroupBox, "m_bReset" );
191 glGroupBox->addWidget( m_bReset, 4, 4 );
193 layoutDlg->addWidget(GroupBox,0,0);
195 // OK, CANCEL, Apply button
196 QGroupBox* aWgt = new QGroupBox( this );
197 QHBoxLayout* aHBoxLayout = new QHBoxLayout( aWgt );
198 aHBoxLayout->setMargin(11);
199 aHBoxLayout->setSpacing(6);
201 // Create <OK> button
202 QPushButton* m_bOk = new QPushButton( tr( "O&K" ), aWgt, "m_bOk" );
203 m_bOk->setDefault( TRUE );
204 m_bOk->setAutoDefault( TRUE );
205 aHBoxLayout->addWidget( m_bOk );
206 aHBoxLayout->addStretch();
208 // Create <Apply> button
209 QPushButton* m_bApply = new QPushButton( tr( "&Apply" ), aWgt, "m_bApply" );
210 m_bApply->setAutoDefault( TRUE );
211 aHBoxLayout->addWidget( m_bApply );
212 aHBoxLayout->addStretch();
214 // Create <Cancel> button
215 QPushButton* m_bCancel = new QPushButton( tr( "&Cancel" ), aWgt, "m_bCancel" );
216 m_bCancel->setAutoDefault( TRUE );
217 aHBoxLayout->addWidget( m_bCancel );
219 layoutDlg->addWidget(aWgt,1,0);
221 // signals and slots connections
222 connect( m_bCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
223 connect( m_bOk, SIGNAL( clicked() ), this, SLOT( onClickOk( ) ) );
224 connect( m_bApply, SIGNAL( clicked() ), this, SLOT( onClickApply( ) ) );
225 connect( m_bReset, SIGNAL( clicked() ), this, SLOT( onClickReset( ) ) );
229 * Destroys the object and frees any allocated resources
231 VisuGUI_NonIsometricDlg::~VisuGUI_NonIsometricDlg()
233 // no need to delete child widgets, Qt does it all for us
236 void VisuGUI_NonIsometricDlg::onClickOk()
244 void VisuGUI_NonIsometricDlg::onClickApply()
246 bool changed = false;
247 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame();
248 if ( sf->getTypeView() == VIEW_VTK )
250 int Xfunction = m_cbXfunction->currentItem();
251 int Yfunction = m_cbYfunction->currentItem();
252 int Zfunction = m_cbZfunction->currentItem();
255 VTKViewer_ViewFrame* vf = (VTKViewer_ViewFrame*) ( sf->getRightFrame()->getViewFrame() );
256 VTKViewer_NonIsometricTransform *aTransform = vf->getNonIsometricTransform();
258 vtkRenderer* Renderer = vf->getRenderer();
259 vtkActorCollection* theActors = Renderer->GetActors();
260 theActors->InitTraversal();
261 vtkActor *actor = theActors->GetNextActor();
263 aTransform->SetFunction( AxisFunction::XAxis,
264 (VTKViewer_NonIsometricTransform::Function) Xfunction,
265 m_sbXcoeff->value() );
267 aTransform->SetFunction( AxisFunction::YAxis,
268 (VTKViewer_NonIsometricTransform::Function) Yfunction,
269 m_sbYcoeff->value() );
271 aTransform->SetFunction( AxisFunction::ZAxis,
272 (VTKViewer_NonIsometricTransform::Function) Zfunction,
273 m_sbZcoeff->value() );
277 //SALOME_Actor* pSA = dynamic_cast<SALOME_Actor*> (actor);
278 SALOME_Actor* pSA = dynamic_cast<VISU_Actor*> (actor);
281 //MESSAGE (actor->GetMapper()->GetClassName ())
282 vtkPolyDataMapper* mapper = NULL;
283 vtkMapper* initialMapper = pSA->GetInitialMapper();
284 if ( initialMapper == NULL )
285 initialMapper = actor->GetMapper();
286 if ( initialMapper->IsA("vtkDataSetMapper") )
287 mapper = vtkDataSetMapper::SafeDownCast( initialMapper )->GetPolyDataMapper ();
289 mapper = vtkPolyDataMapper::SafeDownCast( initialMapper );
290 //MESSAGE (mapper->GetClassName ())
294 //create transformation
297 vtkTransformPolyDataFilter *aTransformFilter = vtkTransformPolyDataFilter::New();
298 aTransformFilter->SetInput ( mapper->GetInput() );
299 aTransformFilter->SetTransform (aTransform);
302 vtkDataSetMapper *aMapper = vtkDataSetMapper::New();
303 aMapper->SetInput (aTransformFilter->GetOutput());
304 aMapper->ShallowCopy ( actor->GetMapper());
307 actor->SetMapper (aMapper);
309 aTransformFilter->Delete();
314 actor = theActors->GetNextActor();
318 //in order to improve perfomance
319 if ( !Xfunction && !Yfunction && !Zfunction )
320 vf->setNonIsometricTransform( NULL );
324 void VisuGUI_NonIsometricDlg::onClickReset()
326 //it's workaround for QComboBox - it doesn't send activated signal using setCurrentItem function
327 //therefore we connect on highlighted signal, use setCurrentItem() and disconnect highlighted signal
329 connect (m_cbXfunction, SIGNAL( highlighted ( const QString& ) ), this, SLOT( onFunctionChanged ( ) ) );
331 m_cbXfunction->setCurrentItem ( 0 );
332 m_cbXfunction->disconnect( SIGNAL( highlighted ( const QString& ) ) );
334 connect (m_cbYfunction, SIGNAL( highlighted ( const QString& ) ), this, SLOT( onFunctionChanged ( ) ) );
335 m_cbYfunction->setCurrentItem ( 0 );
336 m_cbYfunction->disconnect( SIGNAL( highlighted ( const QString& ) ) );
338 connect (m_cbZfunction, SIGNAL( highlighted ( const QString& ) ), this, SLOT( onFunctionChanged ( ) ) );
339 m_cbZfunction->setCurrentItem ( 0 );
340 m_cbZfunction->disconnect( SIGNAL( highlighted ( const QString& ) ) );
343 //Populates combobox and makes all needed connects
344 void VisuGUI_NonIsometricDlg::FillComboBox(QComboBox* cb)
346 cb->insertItem( tr ("None") );
347 cb->insertItem ( tr ("Linear") );
348 // cb->insertItem ( tr ("Logarithmic") );
351 connect (cb, SIGNAL( activated ( const QString& ) ), this, SLOT( onFunctionChanged ( ) ) );
353 //it's workaround for QComboBox - it doesn't send activated signal using setCurrentItem function
354 //therefore we connect on highlighted signal, use setCurrentItem() and disconnect highlighted signal
355 cb->setCurrentItem ( 1 );
356 connect (cb, SIGNAL( highlighted ( const QString& ) ), this, SLOT( onFunctionChanged ( ) ) );
357 cb->setCurrentItem ( 0 );
358 cb->disconnect( SIGNAL( highlighted ( const QString& ) ) );
362 void VisuGUI_NonIsometricDlg::onFunctionChanged()
365 const QComboBox* cbFunction = (const QComboBox* ) sender();
366 FunctionChanged(cbFunction);
369 void VisuGUI_NonIsometricDlg::FunctionChanged(const QComboBox* cbFunction )
372 const QString & function = cbFunction-> currentText();
373 QAD_SpinBoxDbl* sbCoeff;
377 //this variable stores index in bounds array for vtkRenderer
383 if (cbFunction == m_cbXfunction)
385 sbCoeff = m_sbXcoeff;
386 lFunction = m_lXFunction;
391 if (cbFunction == m_cbYfunction)
393 sbCoeff = m_sbYcoeff;
394 lFunction = m_lYFunction;
399 if (cbFunction == m_cbZfunction)
401 sbCoeff = m_sbZcoeff;
402 lFunction = m_lZFunction;
409 sbCoeff->setEnabled (TRUE);
412 if ( function == tr ("None") )
414 sbCoeff->setMinValue( 1.0 );
415 sbCoeff->setMaxValue( 1.0 );
416 sbCoeff->setValue( 1.0 );
417 sbCoeff->setEnabled ( FALSE );
418 formula += QString(" = ");
420 lFunction->setText( formula );
423 if ( function == tr ("Linear") )
425 sbCoeff->setMinValue( -1.7E308 );
426 sbCoeff->setMaxValue( 1.7E+308 );
427 // sbCoeff->setValue( 1.0 );
428 formula += QString(" = k");
430 lFunction->setText( formula );
433 if ( function == tr ("Logarithmic") )
436 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame();
437 if ( sf->getTypeView() == VIEW_VTK )
439 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
441 Renderer->ComputeVisiblePropBounds (bounds);
442 //we use following formula lg (x+a) and x+a >= 1
445 if ( bounds[boundIndex] > 0 && bounds[boundIndex+1] > 0 )
446 minValue = 1 - bounds[boundIndex+1];
448 minValue = 1 - bounds[boundIndex];
449 MESSAGE ( "Bounds " << bounds[0] << " " << bounds[1] << " " << bounds[2] << " " << bounds[3] << " " << bounds[4] << " " << bounds[5] << " " )
450 sbCoeff->setMinValue( minValue );
451 sbCoeff->setMaxValue( 1.7E+308 );
452 sbCoeff->setValue( minValue );
453 formula += QString(" = lg(");
455 formula += QString("+a), a >= %1").arg( minValue );
459 sbCoeff->setEnabled (FALSE);
462 lFunction->setText( formula );