1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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 : OperationGUI_ClippingDlg.cxx
23 // Author : Michael Zorin, Open CASCADE S.A.S. (mikhail.zorin@opencascade.com)
26 #include "OperationGUI_ClippingDlg.h"
28 #include <GEOM_DlgRef.h>
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_ViewManager.h>
35 #include <SVTK_ViewWindow.h>
36 #include <SVTK_ViewModel.h>
37 #include <OCCViewer_ViewWindow.h>
38 #include <OCCViewer_ViewPort3d.h>
39 #include <VTKViewer.h>
42 #include <V3d_View.hxx>
46 #include <vtkCamera.h>
47 #include <vtkRenderer.h>
49 //=================================================================================
50 // class : OperationGUI_ClippingDlg()
52 //=================================================================================
53 OperationGUI_ClippingDlg::OperationGUI_ClippingDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
54 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
56 setWindowTitle( tr( "Change clipping range" ) );
58 mainFrame()->GroupConstructors->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->GroupConstructors->close();
60 mainFrame()->GroupBoxName->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->GroupBoxName->close();
63 /***************************************************************/
64 GroupArguments = new QGroupBox( centralWidget() );
65 QGridLayout* GroupArgumentsLayout = new QGridLayout( GroupArguments );
66 GroupArgumentsLayout->setSpacing( 6 );
67 GroupArgumentsLayout->setMargin( 9 );
70 TextLabelNear = new QLabel( tr( "Near" ), GroupArguments );
71 GroupArgumentsLayout->addWidget( TextLabelNear, 0, 0 );
73 SpinBox_Near = new QDoubleSpinBox( GroupArguments );
74 GroupArgumentsLayout->addWidget( SpinBox_Near, 0, 1 );
76 TextLabelFar = new QLabel( tr( "Far" ), GroupArguments );
77 GroupArgumentsLayout->addWidget( TextLabelFar, 0, 2 );
79 SpinBox_Far = new QDoubleSpinBox( GroupArguments );
80 GroupArgumentsLayout->addWidget( SpinBox_Far, 0, 3 );
82 resetButton = new QPushButton( tr( "Reset" ), GroupArguments );
83 GroupArgumentsLayout->addWidget( resetButton, 0, 4 );
85 TypeCB = new QComboBox( GroupArguments );
86 TypeCB->addItem( tr( "OFF" ) );
87 TypeCB->addItem( tr( "BACK" ) );
88 TypeCB->addItem( tr( "FRONT" ) );
89 TypeCB->addItem( tr( "SLICE" ) );
90 GroupArgumentsLayout->addWidget( TypeCB, 1, 0, 1, 5 );
92 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
93 layout->setMargin( 0 ); layout->setSpacing( 6 );
94 layout->addWidget( GroupArguments );
97 initSpinBox( SpinBox_Near, COORD_MIN, COORD_MAX, 10.0, 3 );
98 initSpinBox( SpinBox_Far, COORD_MIN, COORD_MAX, 10.0, 3 );
100 /* signals and slots connections */
101 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
102 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
104 connect( resetButton, SIGNAL( clicked() ), this, SLOT( onReset() ) ) ;
106 setHelpFileName( "none.htm" );
111 //=================================================================================
112 // function : ~ OperationGUI_ClippingDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 OperationGUI_ClippingDlg::~ OperationGUI_ClippingDlg()
117 // no need to delete child widgets, Qt does it all for us
120 //=================================================================================
123 //=================================================================================
124 void OperationGUI_ClippingDlg::Init()
126 SUIT_ViewWindow* anActiveWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
127 if ( !anActiveWindow )
130 if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
131 SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
135 TextLabelNear->setText( tr( "Near" ) );
136 TextLabelFar->setText( tr( "Far" ) );
140 vtkRenderer* aRenderer = aVTKFrame->getRenderer();
141 if ( !aRenderer ) return;
143 vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
144 if ( anActiveCamera == NULL ) {
148 // Find the plane equation for the camera view plane
150 anActiveCamera->GetViewPlaneNormal( vn );
152 anActiveCamera->GetPosition( position );
154 vtkFloatingPointType bounds[6];
155 aRenderer->ComputeVisiblePropBounds( bounds );
158 center[0] = ( bounds[0] + bounds[1] ) / 2.0;
159 center[1] = ( bounds[2] + bounds[3] ) / 2.0;
160 center[2] = ( bounds[4] + bounds[5] ) / 2.0;
162 double width = sqrt( ( bounds[1]-bounds[0] ) * ( bounds[1]-bounds[0] ) +
163 ( bounds[3]-bounds[2] ) * ( bounds[3]-bounds[2] ) +
164 ( bounds[5]-bounds[4] ) * ( bounds[5]-bounds[4] ) );
166 double distance = sqrt( ( position[0]-center[0] ) * ( position[0]-center[0] ) +
167 ( position[1]-center[1] ) * ( position[1]-center[1] ) +
168 ( position[2]-center[2] ) * ( position[2]-center[2] ) );
170 vtkFloatingPointType range[2] = { distance - width/2.0, distance + width/2.0 };
172 SpinBox_Near->setValue( range[0] );
173 SpinBox_Far->setValue( range[1] );
177 else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
178 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
180 TextLabelNear->setText( tr( "Depth" ) );
181 TextLabelFar->setText( tr( "Thickness" ) );
183 Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
185 double depth, thickness;
186 int ztype = view3d->ZClipping( depth, thickness );
187 SpinBox_Near->setValue( depth );
188 SpinBox_Far->setValue( thickness );
189 TypeCB->setCurrentIndex( ztype );
191 //Handle(V3d_Plane) aPlane = new V3d_Plane( aOCCFrame->getViewer()->getViewer3d() ,0, 0, 1, -100);
192 //aPlane->Display(view3d);
197 //=================================================================================
198 // function : ClickOnApply()
200 //=================================================================================
201 bool OperationGUI_ClippingDlg::ClickOnApply()
203 SUIT_ViewWindow* anActiveWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
204 if ( !anActiveWindow )
207 if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
208 SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
212 vtkRenderer* aRenderer = aVTKFrame->getRenderer();
213 if ( !aRenderer ) return false;
215 vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
216 if ( anActiveCamera == NULL ) {
220 vtkFloatingPointType range[2] = { SpinBox_Near->value(), SpinBox_Far->value() };
221 if ( range[0] < 0.0 ) range[0] = 0.0;
222 anActiveCamera->SetClippingRange( range );
226 else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
227 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
229 Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
231 double depth = SpinBox_Near->value();
232 double thickness = SpinBox_Far->value();
233 int aType = TypeCB->currentIndex();
235 view3d->SetZClippingType( V3d_TypeOfZclipping( aType ) );
236 view3d->SetZClippingDepth( depth );
237 view3d->SetZClippingWidth( thickness );
243 //=================================================================================
244 // function : ClickOnOk()
246 //=================================================================================
247 void OperationGUI_ClippingDlg::ClickOnOk()
249 if ( ClickOnApply() )
253 //=================================================================================
254 // function : onActivate()
256 //=================================================================================
257 void OperationGUI_ClippingDlg::onActivate()
259 GEOMBase_Skeleton::ActivateThisDialog();
262 //=================================================================================
263 // function : enterEvent()
265 //=================================================================================
266 void OperationGUI_ClippingDlg::enterEvent( QEvent* )
268 this->setEnabled( true );
271 //=================================================================================
272 // function : closeEvent
274 //=================================================================================
275 void OperationGUI_ClippingDlg::closeEvent( QCloseEvent* e )
277 QDialog::closeEvent( e );
280 //=================================================================================
281 // function : onReset()
283 //=================================================================================
284 void OperationGUI_ClippingDlg::onReset()
286 SUIT_ViewWindow* anActiveWindow =
287 SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
288 if ( !anActiveWindow )
291 if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
292 SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
296 vtkRenderer* aRenderer = aVTKFrame->getRenderer();
297 if ( !aRenderer ) return;
299 vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
300 if ( anActiveCamera == NULL ) {
304 // Find the plane equation for the camera view plane
306 anActiveCamera->GetViewPlaneNormal( vn );
308 anActiveCamera->GetPosition( position );
310 vtkFloatingPointType bounds[6];
311 aRenderer->ComputeVisiblePropBounds( bounds );
314 center[0] = ( bounds[0] + bounds[1] ) / 2.0;
315 center[1] = ( bounds[2] + bounds[3] ) / 2.0;
316 center[2] = ( bounds[4] + bounds[5] ) / 2.0;
318 double width = sqrt( ( bounds[1]-bounds[0] ) * ( bounds[1]-bounds[0] ) +
319 ( bounds[3]-bounds[2] ) * ( bounds[3]-bounds[2] ) +
320 ( bounds[5]-bounds[4] ) * ( bounds[5]-bounds[4] ) );
322 double distance = sqrt( ( position[0]-center[0] ) * ( position[0]-center[0] ) +
323 ( position[1]-center[1] ) * ( position[1]-center[1] ) +
324 ( position[2]-center[2] ) * ( position[2]-center[2] ) );
326 vtkFloatingPointType range[2] = { distance - width/2.0, distance + width/2.0 };
328 SpinBox_Near->setValue( range[0] );
329 SpinBox_Far->setValue( range[1] );
333 else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
334 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
336 TextLabelNear->setText( tr( "Depth" ) );
337 TextLabelFar->setText( tr( "Thickness" ) );
339 Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
341 view3d->SetZClippingType( V3d_TypeOfZclipping( 0 ) );
343 double depth, thickness;
344 int ztype= view3d->ZClipping( depth, thickness );
345 SpinBox_Near->setValue( 0 );
346 SpinBox_Far->setValue( 1000 );
347 TypeCB->setCurrentIndex( ztype );