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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : OperationGUI_ClippingDlg.cxx
24 // Author : Michael Zorin, Open CASCADE S.A.S. (mikhail.zorin@opencascade.com)
26 #include "OperationGUI_ClippingDlg.h"
29 #include <GeometryGUI.h>
31 #include <SalomeApp_DoubleSpinBox.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ViewManager.h>
36 #include <SVTK_ViewWindow.h>
37 #include <SVTK_ViewModel.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <OCCViewer_ViewWindow.h>
41 #include <OCCViewer_ViewPort3d.h>
43 #include <VTKViewer.h>
46 #include <V3d_View.hxx>
50 #include <vtkCamera.h>
51 #include <vtkRenderer.h>
53 //=================================================================================
54 // class : OperationGUI_ClippingDlg()
56 //=================================================================================
57 OperationGUI_ClippingDlg::OperationGUI_ClippingDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
58 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
60 setWindowTitle( tr( "Change clipping range" ) );
62 mainFrame()->GroupConstructors->setAttribute( Qt::WA_DeleteOnClose );
63 mainFrame()->GroupConstructors->close();
64 mainFrame()->GroupBoxName->setAttribute( Qt::WA_DeleteOnClose );
65 mainFrame()->GroupBoxName->close();
67 /***************************************************************/
68 GroupArguments = new QGroupBox( centralWidget() );
69 QGridLayout* GroupArgumentsLayout = new QGridLayout( GroupArguments );
70 GroupArgumentsLayout->setSpacing( 6 );
71 GroupArgumentsLayout->setMargin( 9 );
74 TextLabelNear = new QLabel( tr( "Near" ), GroupArguments );
75 GroupArgumentsLayout->addWidget( TextLabelNear, 0, 0 );
77 SpinBox_Near = new SalomeApp_DoubleSpinBox( GroupArguments );
78 initSpinBox( SpinBox_Near, COORD_MIN, COORD_MAX, 10.0, "length_precision" );
79 GroupArgumentsLayout->addWidget( SpinBox_Near, 0, 1 );
81 TextLabelFar = new QLabel( tr( "Far" ), GroupArguments );
82 GroupArgumentsLayout->addWidget( TextLabelFar, 0, 2 );
84 SpinBox_Far = new SalomeApp_DoubleSpinBox( GroupArguments );
85 initSpinBox( SpinBox_Far, COORD_MIN, COORD_MAX, 10.0, "length_precision" );
86 GroupArgumentsLayout->addWidget( SpinBox_Far, 0, 3 );
88 resetButton = new QPushButton( tr( "Reset" ), GroupArguments );
89 GroupArgumentsLayout->addWidget( resetButton, 0, 4 );
91 TypeCB = new QComboBox( GroupArguments );
92 TypeCB->addItem( tr( "OFF" ) );
93 TypeCB->addItem( tr( "BACK" ) );
94 TypeCB->addItem( tr( "FRONT" ) );
95 TypeCB->addItem( tr( "SLICE" ) );
96 GroupArgumentsLayout->addWidget( TypeCB, 1, 0, 1, 5 );
98 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
99 layout->setMargin( 0 ); layout->setSpacing( 6 );
100 layout->addWidget( GroupArguments );
102 /* signals and slots connections */
103 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
104 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
106 connect( resetButton, SIGNAL( clicked() ), this, SLOT( onReset() ) ) ;
108 setHelpFileName( "none.htm" );
113 //=================================================================================
114 // function : ~ OperationGUI_ClippingDlg()
115 // purpose : Destroys the object and frees any allocated resources
116 //=================================================================================
117 OperationGUI_ClippingDlg::~ OperationGUI_ClippingDlg()
119 // no need to delete child widgets, Qt does it all for us
122 //=================================================================================
125 //=================================================================================
126 void OperationGUI_ClippingDlg::Init()
128 SUIT_ViewWindow* anActiveWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
129 if ( !anActiveWindow )
132 if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
133 SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
137 TextLabelNear->setText( tr( "Near" ) );
138 TextLabelFar->setText( tr( "Far" ) );
142 vtkRenderer* aRenderer = aVTKFrame->getRenderer();
143 if ( !aRenderer ) return;
145 vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
146 if ( anActiveCamera == NULL ) {
150 // Find the plane equation for the camera view plane
152 anActiveCamera->GetViewPlaneNormal( vn );
154 anActiveCamera->GetPosition( position );
156 vtkFloatingPointType bounds[6];
157 aRenderer->ComputeVisiblePropBounds( bounds );
160 center[0] = ( bounds[0] + bounds[1] ) / 2.0;
161 center[1] = ( bounds[2] + bounds[3] ) / 2.0;
162 center[2] = ( bounds[4] + bounds[5] ) / 2.0;
164 double width = sqrt( ( bounds[1]-bounds[0] ) * ( bounds[1]-bounds[0] ) +
165 ( bounds[3]-bounds[2] ) * ( bounds[3]-bounds[2] ) +
166 ( bounds[5]-bounds[4] ) * ( bounds[5]-bounds[4] ) );
168 double distance = sqrt( ( position[0]-center[0] ) * ( position[0]-center[0] ) +
169 ( position[1]-center[1] ) * ( position[1]-center[1] ) +
170 ( position[2]-center[2] ) * ( position[2]-center[2] ) );
172 vtkFloatingPointType range[2] = { distance - width/2.0, distance + width/2.0 };
174 SpinBox_Near->setValue( range[0] );
175 SpinBox_Far->setValue( range[1] );
179 else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
180 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
182 TextLabelNear->setText( tr( "Depth" ) );
183 TextLabelFar->setText( tr( "Thickness" ) );
185 Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
187 double depth, thickness;
188 int ztype = view3d->ZClipping( depth, thickness );
189 SpinBox_Near->setValue( depth );
190 SpinBox_Far->setValue( thickness );
191 TypeCB->setCurrentIndex( ztype );
193 //Handle(V3d_Plane) aPlane = new V3d_Plane( aOCCFrame->getViewer()->getViewer3d() ,0, 0, 1, -100);
194 //aPlane->Display(view3d);
199 //=================================================================================
200 // function : ClickOnApply()
202 //=================================================================================
203 bool OperationGUI_ClippingDlg::ClickOnApply()
205 SUIT_ViewWindow* anActiveWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
206 if ( !anActiveWindow )
209 if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
210 SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
214 vtkRenderer* aRenderer = aVTKFrame->getRenderer();
215 if ( !aRenderer ) return false;
217 vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
218 if ( anActiveCamera == NULL ) {
222 vtkFloatingPointType range[2] = { SpinBox_Near->value(), SpinBox_Far->value() };
223 if ( range[0] < 0.0 ) range[0] = 0.0;
224 anActiveCamera->SetClippingRange( range );
228 else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
229 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
231 Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
233 double depth = SpinBox_Near->value();
234 double thickness = SpinBox_Far->value();
235 int aType = TypeCB->currentIndex();
237 view3d->SetZClippingType( V3d_TypeOfZclipping( aType ) );
238 view3d->SetZClippingDepth( depth );
239 view3d->SetZClippingWidth( thickness );
245 //=================================================================================
246 // function : ClickOnOk()
248 //=================================================================================
249 void OperationGUI_ClippingDlg::ClickOnOk()
251 if ( ClickOnApply() )
255 //=================================================================================
256 // function : onActivate()
258 //=================================================================================
259 void OperationGUI_ClippingDlg::onActivate()
261 GEOMBase_Skeleton::ActivateThisDialog();
264 //=================================================================================
265 // function : enterEvent()
267 //=================================================================================
268 void OperationGUI_ClippingDlg::enterEvent( QEvent* )
270 this->setEnabled( true );
273 //=================================================================================
274 // function : onReset()
276 //=================================================================================
277 void OperationGUI_ClippingDlg::onReset()
279 SUIT_ViewWindow* anActiveWindow =
280 SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
281 if ( !anActiveWindow )
284 if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
285 SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
289 vtkRenderer* aRenderer = aVTKFrame->getRenderer();
290 if ( !aRenderer ) return;
292 vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
293 if ( anActiveCamera == NULL ) {
297 // Find the plane equation for the camera view plane
299 anActiveCamera->GetViewPlaneNormal( vn );
301 anActiveCamera->GetPosition( position );
303 vtkFloatingPointType bounds[6];
304 aRenderer->ComputeVisiblePropBounds( bounds );
307 center[0] = ( bounds[0] + bounds[1] ) / 2.0;
308 center[1] = ( bounds[2] + bounds[3] ) / 2.0;
309 center[2] = ( bounds[4] + bounds[5] ) / 2.0;
311 double width = sqrt( ( bounds[1]-bounds[0] ) * ( bounds[1]-bounds[0] ) +
312 ( bounds[3]-bounds[2] ) * ( bounds[3]-bounds[2] ) +
313 ( bounds[5]-bounds[4] ) * ( bounds[5]-bounds[4] ) );
315 double distance = sqrt( ( position[0]-center[0] ) * ( position[0]-center[0] ) +
316 ( position[1]-center[1] ) * ( position[1]-center[1] ) +
317 ( position[2]-center[2] ) * ( position[2]-center[2] ) );
319 vtkFloatingPointType range[2] = { distance - width/2.0, distance + width/2.0 };
321 SpinBox_Near->setValue( range[0] );
322 SpinBox_Far->setValue( range[1] );
326 else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
327 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
329 TextLabelNear->setText( tr( "Depth" ) );
330 TextLabelFar->setText( tr( "Thickness" ) );
332 Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
334 view3d->SetZClippingType( V3d_TypeOfZclipping( 0 ) );
336 double depth, thickness;
337 int ztype= view3d->ZClipping( depth, thickness );
338 SpinBox_Near->setValue( 0 );
339 SpinBox_Far->setValue( 1000 );
340 TypeCB->setCurrentIndex( ztype );