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"
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>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewWindow.h>
40 #include <OCCViewer_ViewPort3d.h>
42 #include <VTKViewer.h>
45 #include <V3d_View.hxx>
49 #include <vtkCamera.h>
50 #include <vtkRenderer.h>
52 //=================================================================================
53 // class : OperationGUI_ClippingDlg()
55 //=================================================================================
56 OperationGUI_ClippingDlg::OperationGUI_ClippingDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
57 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
59 setWindowTitle( tr( "Change clipping range" ) );
61 mainFrame()->GroupConstructors->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->GroupConstructors->close();
63 mainFrame()->GroupBoxName->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->GroupBoxName->close();
66 /***************************************************************/
67 GroupArguments = new QGroupBox( centralWidget() );
68 QGridLayout* GroupArgumentsLayout = new QGridLayout( GroupArguments );
69 GroupArgumentsLayout->setSpacing( 6 );
70 GroupArgumentsLayout->setMargin( 9 );
73 TextLabelNear = new QLabel( tr( "Near" ), GroupArguments );
74 GroupArgumentsLayout->addWidget( TextLabelNear, 0, 0 );
76 SpinBox_Near = new QDoubleSpinBox( GroupArguments );
77 GroupArgumentsLayout->addWidget( SpinBox_Near, 0, 1 );
79 TextLabelFar = new QLabel( tr( "Far" ), GroupArguments );
80 GroupArgumentsLayout->addWidget( TextLabelFar, 0, 2 );
82 SpinBox_Far = new QDoubleSpinBox( GroupArguments );
83 GroupArgumentsLayout->addWidget( SpinBox_Far, 0, 3 );
85 resetButton = new QPushButton( tr( "Reset" ), GroupArguments );
86 GroupArgumentsLayout->addWidget( resetButton, 0, 4 );
88 TypeCB = new QComboBox( GroupArguments );
89 TypeCB->addItem( tr( "OFF" ) );
90 TypeCB->addItem( tr( "BACK" ) );
91 TypeCB->addItem( tr( "FRONT" ) );
92 TypeCB->addItem( tr( "SLICE" ) );
93 GroupArgumentsLayout->addWidget( TypeCB, 1, 0, 1, 5 );
95 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
96 layout->setMargin( 0 ); layout->setSpacing( 6 );
97 layout->addWidget( GroupArguments );
100 initSpinBox( SpinBox_Near, COORD_MIN, COORD_MAX, 10.0, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
101 initSpinBox( SpinBox_Far, COORD_MIN, COORD_MAX, 10.0, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
103 /* signals and slots connections */
104 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
105 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
107 connect( resetButton, SIGNAL( clicked() ), this, SLOT( onReset() ) ) ;
109 setHelpFileName( "none.htm" );
114 //=================================================================================
115 // function : ~ OperationGUI_ClippingDlg()
116 // purpose : Destroys the object and frees any allocated resources
117 //=================================================================================
118 OperationGUI_ClippingDlg::~ OperationGUI_ClippingDlg()
120 // no need to delete child widgets, Qt does it all for us
123 //=================================================================================
126 //=================================================================================
127 void OperationGUI_ClippingDlg::Init()
129 SUIT_ViewWindow* anActiveWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
130 if ( !anActiveWindow )
133 if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
134 SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
138 TextLabelNear->setText( tr( "Near" ) );
139 TextLabelFar->setText( tr( "Far" ) );
143 vtkRenderer* aRenderer = aVTKFrame->getRenderer();
144 if ( !aRenderer ) return;
146 vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
147 if ( anActiveCamera == NULL ) {
151 // Find the plane equation for the camera view plane
153 anActiveCamera->GetViewPlaneNormal( vn );
155 anActiveCamera->GetPosition( position );
157 vtkFloatingPointType bounds[6];
158 aRenderer->ComputeVisiblePropBounds( bounds );
161 center[0] = ( bounds[0] + bounds[1] ) / 2.0;
162 center[1] = ( bounds[2] + bounds[3] ) / 2.0;
163 center[2] = ( bounds[4] + bounds[5] ) / 2.0;
165 double width = sqrt( ( bounds[1]-bounds[0] ) * ( bounds[1]-bounds[0] ) +
166 ( bounds[3]-bounds[2] ) * ( bounds[3]-bounds[2] ) +
167 ( bounds[5]-bounds[4] ) * ( bounds[5]-bounds[4] ) );
169 double distance = sqrt( ( position[0]-center[0] ) * ( position[0]-center[0] ) +
170 ( position[1]-center[1] ) * ( position[1]-center[1] ) +
171 ( position[2]-center[2] ) * ( position[2]-center[2] ) );
173 vtkFloatingPointType range[2] = { distance - width/2.0, distance + width/2.0 };
175 SpinBox_Near->setValue( range[0] );
176 SpinBox_Far->setValue( range[1] );
180 else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
181 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
183 TextLabelNear->setText( tr( "Depth" ) );
184 TextLabelFar->setText( tr( "Thickness" ) );
186 Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
188 double depth, thickness;
189 int ztype = view3d->ZClipping( depth, thickness );
190 SpinBox_Near->setValue( depth );
191 SpinBox_Far->setValue( thickness );
192 TypeCB->setCurrentIndex( ztype );
194 //Handle(V3d_Plane) aPlane = new V3d_Plane( aOCCFrame->getViewer()->getViewer3d() ,0, 0, 1, -100);
195 //aPlane->Display(view3d);
200 //=================================================================================
201 // function : ClickOnApply()
203 //=================================================================================
204 bool OperationGUI_ClippingDlg::ClickOnApply()
206 SUIT_ViewWindow* anActiveWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
207 if ( !anActiveWindow )
210 if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
211 SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
215 vtkRenderer* aRenderer = aVTKFrame->getRenderer();
216 if ( !aRenderer ) return false;
218 vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
219 if ( anActiveCamera == NULL ) {
223 vtkFloatingPointType range[2] = { SpinBox_Near->value(), SpinBox_Far->value() };
224 if ( range[0] < 0.0 ) range[0] = 0.0;
225 anActiveCamera->SetClippingRange( range );
229 else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
230 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
232 Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
234 double depth = SpinBox_Near->value();
235 double thickness = SpinBox_Far->value();
236 int aType = TypeCB->currentIndex();
238 view3d->SetZClippingType( V3d_TypeOfZclipping( aType ) );
239 view3d->SetZClippingDepth( depth );
240 view3d->SetZClippingWidth( thickness );
246 //=================================================================================
247 // function : ClickOnOk()
249 //=================================================================================
250 void OperationGUI_ClippingDlg::ClickOnOk()
252 if ( ClickOnApply() )
256 //=================================================================================
257 // function : onActivate()
259 //=================================================================================
260 void OperationGUI_ClippingDlg::onActivate()
262 GEOMBase_Skeleton::ActivateThisDialog();
265 //=================================================================================
266 // function : enterEvent()
268 //=================================================================================
269 void OperationGUI_ClippingDlg::enterEvent( QEvent* )
271 this->setEnabled( true );
274 //=================================================================================
275 // function : onReset()
277 //=================================================================================
278 void OperationGUI_ClippingDlg::onReset()
280 SUIT_ViewWindow* anActiveWindow =
281 SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
282 if ( !anActiveWindow )
285 if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
286 SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
290 vtkRenderer* aRenderer = aVTKFrame->getRenderer();
291 if ( !aRenderer ) return;
293 vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
294 if ( anActiveCamera == NULL ) {
298 // Find the plane equation for the camera view plane
300 anActiveCamera->GetViewPlaneNormal( vn );
302 anActiveCamera->GetPosition( position );
304 vtkFloatingPointType bounds[6];
305 aRenderer->ComputeVisiblePropBounds( bounds );
308 center[0] = ( bounds[0] + bounds[1] ) / 2.0;
309 center[1] = ( bounds[2] + bounds[3] ) / 2.0;
310 center[2] = ( bounds[4] + bounds[5] ) / 2.0;
312 double width = sqrt( ( bounds[1]-bounds[0] ) * ( bounds[1]-bounds[0] ) +
313 ( bounds[3]-bounds[2] ) * ( bounds[3]-bounds[2] ) +
314 ( bounds[5]-bounds[4] ) * ( bounds[5]-bounds[4] ) );
316 double distance = sqrt( ( position[0]-center[0] ) * ( position[0]-center[0] ) +
317 ( position[1]-center[1] ) * ( position[1]-center[1] ) +
318 ( position[2]-center[2] ) * ( position[2]-center[2] ) );
320 vtkFloatingPointType range[2] = { distance - width/2.0, distance + width/2.0 };
322 SpinBox_Near->setValue( range[0] );
323 SpinBox_Far->setValue( range[1] );
327 else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
328 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
330 TextLabelNear->setText( tr( "Depth" ) );
331 TextLabelFar->setText( tr( "Thickness" ) );
333 Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
335 view3d->SetZClippingType( V3d_TypeOfZclipping( 0 ) );
337 double depth, thickness;
338 int ztype= view3d->ZClipping( depth, thickness );
339 SpinBox_Near->setValue( 0 );
340 SpinBox_Far->setValue( 1000 );
341 TypeCB->setCurrentIndex( ztype );