1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
23 #include "OCCViewer_CubeAxesDlg.h"
25 #include "OCCViewer_FontWidget.h"
26 #include "OCCViewer_ViewPort3d.h"
27 #include "OCCViewer_ViewWindow.h"
29 #include "QtxAction.h"
30 #include "QtxIntSpinBox.h"
32 #include <Basics_OCCTVersion.hxx>
34 #if OCC_VERSION_LARGE > 0x06080000
35 #include <Graphic3d_GraduatedTrihedron.hxx>
43 \class OCCViewer_CubeAxesDlg::AxisWidget
44 \brief Axis tab widget of the "Graduated axis" dialog box
51 OCCViewer_AxisWidget::OCCViewer_AxisWidget (QWidget* theParent)
52 : ViewerTools_AxisWidgetBase(theParent)
59 OCCViewer_AxisWidget::~OCCViewer_AxisWidget()
66 ViewerTools_FontWidgetBase* OCCViewer_AxisWidget::createFontWidget( QWidget* theParent )
68 OCCViewer_FontWidget* aFontWidget = new OCCViewer_FontWidget( theParent );
69 aFontWidget->Initialize();
76 void OCCViewer_AxisWidget::SetData( const AxisData& theAxisData )
78 myNameGrp->setChecked( theAxisData.DrawName );
79 myAxisName->setText( theAxisData.Name );
80 myNameFont->SetData( theAxisData.NameColor, 0, false, false, false );
82 myLabelsGrp->setChecked( theAxisData.DrawValues );
83 myLabelNumber->setValue( theAxisData.NbValues );
84 myLabelOffset->setValue( theAxisData.Offset );
85 myLabelsFont->SetData( theAxisData.Color, 0, false, false, false );
87 myTicksGrp->setChecked( theAxisData.DrawTickmarks );
88 myTickLength->setValue( theAxisData.TickmarkLength );
94 void OCCViewer_AxisWidget::GetData( AxisData& theAxisData )
96 theAxisData.DrawName = myNameGrp->isChecked();
97 theAxisData.Name = myAxisName->text();
100 bool aNameBold, aNameItalic, aNameShadow;
101 myNameFont->GetData( theAxisData.NameColor, aNameFamily, aNameBold, aNameItalic, aNameShadow );
103 theAxisData.DrawValues = myLabelsGrp->isChecked();
104 theAxisData.NbValues = myLabelNumber->value();
105 theAxisData.Offset = myLabelOffset->value();
108 bool aLabelBold, aLabelItalic, aLabelShadow;
109 myLabelsFont->GetData( theAxisData.Color, aLabelFamily, aLabelBold, aLabelItalic, aLabelShadow );
111 theAxisData.DrawTickmarks = myTicksGrp->isChecked();
112 theAxisData.TickmarkLength = myTickLength->value();
116 Class : OCCViewer_CubeAxesDlg
117 Description : Dialog for specifying cube axes properties
123 OCCViewer_CubeAxesDlg::OCCViewer_CubeAxesDlg(QtxAction* theAction,
124 OCCViewer_ViewWindow* theParent,
125 const char* theName):
126 ViewerTools_CubeAxesDlgBase(theAction,
129 myMainWindow(theParent)
136 OCCViewer_CubeAxesDlg::~OCCViewer_CubeAxesDlg()
143 ViewerTools_AxisWidgetBase* OCCViewer_CubeAxesDlg::createAxisWidget( QWidget* theParent )
145 OCCViewer_AxisWidget* anAxisWidget = new OCCViewer_AxisWidget( theParent );
146 anAxisWidget->initialize();
151 Update dialog fields, connect signals and slots, show dialog
153 void OCCViewer_CubeAxesDlg::initialize()
155 ViewerTools_CubeAxesDlgBase::initialize();
157 for( int i = 0; i < 3; i++ )
159 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
161 OCCViewer_AxisWidget::AxisData anAxisData;
165 anAxisData.Name = "X";
166 anAxisData.NameColor = anAxisData.Color = Qt::red;
169 anAxisData.Name = "Y";
170 anAxisData.NameColor = anAxisData.Color = Qt::green;
173 anAxisData.Name = "Z";
174 anAxisData.NameColor = anAxisData.Color = Qt::blue;
177 anAxisData.DrawName = true;
178 anAxisData.DrawValues = true;
179 anAxisData.NbValues = 3;
180 anAxisData.Offset = 2;
181 anAxisData.DrawTickmarks = true;
182 anAxisData.TickmarkLength = 5;
183 anAxisWidget->SetData( anAxisData );
189 Update dialog fields, connect signals and slots, show dialog
191 void OCCViewer_CubeAxesDlg::Update()
193 ViewerTools_CubeAxesDlgBase::Update();
197 Verify validity of entry data
199 bool OCCViewer_CubeAxesDlg::onApply()
201 bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
205 QWidget *aCurrWid = this->focusWidget();
206 aCurrWid->clearFocus();
207 aCurrWid->setFocus();
209 if( OCCViewer_ViewPort3d* aViewPort = myMainWindow->getViewPort() )
211 Handle(V3d_View) aView = aViewPort->getView();
212 if( !aView.IsNull() )
225 Get graduated trihedron parameters
227 void OCCViewer_CubeAxesDlg::GetData( bool& theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
229 theIsVisible = myIsVisible->isChecked();
230 for( int i = 0; i < 3; i++ )
231 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
232 anAxisWidget->GetData( theAxisData[i] );
236 Set graduated trihedron parameters
238 void OCCViewer_CubeAxesDlg::SetData( bool theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
240 myIsVisible->setChecked( theIsVisible );
241 for( int i = 0; i < 3; i++ )
242 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
243 anAxisWidget->SetData( theAxisData[i] );
247 Apply graduated trihedron parameters
249 void OCCViewer_CubeAxesDlg::ApplyData( const Handle(V3d_View)& theView )
251 if( theView.IsNull() )
254 if( myIsVisible->isChecked() )
256 OCCViewer_AxisWidget::AxisData anAxisData[3];
257 for( int i = 0; i < 3; i++ ) {
258 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
259 anAxisWidget->GetData( anAxisData[i] );
262 // A gap used offset of axis names' offset
263 // (this hard-coded value will be removed when the
264 // font support will be introduced in OCC-6.4)
267 #if OCC_VERSION_LARGE > 0x06080000
268 Graphic3d_GraduatedTrihedron gt;
270 gt.SetToDrawTickmarks(Standard_True); // to draw grid
271 gt.SetToDrawAxes(Standard_True); // to draw axes
272 gt.SetGridColor(Quantity_NOC_WHITE); // grid color
274 gt.ChangeXAxisAspect().SetName(anAxisData[0].Name.toLatin1().constData());
275 gt.ChangeXAxisAspect().SetToDrawName(anAxisData[0].DrawName);
276 gt.ChangeXAxisAspect().SetToDrawValues(anAxisData[0].DrawValues);
277 gt.ChangeXAxisAspect().SetToDrawTickmarks(anAxisData[0].DrawTickmarks);
278 gt.ChangeXAxisAspect().SetNameColor(Quantity_Color(anAxisData[0].NameColor.redF(),
279 anAxisData[0].NameColor.greenF(),
280 anAxisData[0].NameColor.blueF(),
282 gt.ChangeXAxisAspect().SetColor(Quantity_Color(anAxisData[0].Color.redF(),
283 anAxisData[0].Color.greenF(),
284 anAxisData[0].Color.blueF(),
286 gt.ChangeXAxisAspect().SetTickmarkNumber(anAxisData[0].NbValues-1);
287 gt.ChangeXAxisAspect().SetTickmarkLength(anAxisData[0].TickmarkLength);
288 gt.ChangeXAxisAspect().SetValuesOffset(anAxisData[0].Offset);
289 gt.ChangeXAxisAspect().SetNameOffset(anAxisData[0].Offset + aGap); // see above
291 gt.ChangeYAxisAspect().SetName(anAxisData[1].Name.toLatin1().constData());
292 gt.ChangeYAxisAspect().SetToDrawName(anAxisData[1].DrawName);
293 gt.ChangeYAxisAspect().SetToDrawValues(anAxisData[1].DrawValues);
294 gt.ChangeYAxisAspect().SetToDrawTickmarks(anAxisData[1].DrawTickmarks);
295 gt.ChangeYAxisAspect().SetNameColor(Quantity_Color(anAxisData[1].NameColor.redF(),
296 anAxisData[1].NameColor.greenF(),
297 anAxisData[1].NameColor.blueF(),
299 gt.ChangeYAxisAspect().SetColor(Quantity_Color(anAxisData[1].Color.redF(),
300 anAxisData[1].Color.greenF(),
301 anAxisData[1].Color.blueF(),
303 gt.ChangeYAxisAspect().SetTickmarkNumber(anAxisData[1].NbValues-1);
304 gt.ChangeYAxisAspect().SetTickmarkLength(anAxisData[1].TickmarkLength);
305 gt.ChangeYAxisAspect().SetValuesOffset(anAxisData[1].Offset);
306 gt.ChangeYAxisAspect().SetNameOffset(anAxisData[1].Offset + aGap); // see above
308 gt.ChangeZAxisAspect().SetName(anAxisData[2].Name.toLatin1().constData());
309 gt.ChangeZAxisAspect().SetToDrawName(anAxisData[2].DrawName);
310 gt.ChangeZAxisAspect().SetToDrawValues(anAxisData[2].DrawValues);
311 gt.ChangeZAxisAspect().SetToDrawTickmarks(anAxisData[2].DrawTickmarks);
312 gt.ChangeZAxisAspect().SetNameColor(Quantity_Color(anAxisData[2].NameColor.redF(),
313 anAxisData[2].NameColor.greenF(),
314 anAxisData[2].NameColor.blueF(),
316 gt.ChangeZAxisAspect().SetColor(Quantity_Color(anAxisData[2].Color.redF(),
317 anAxisData[2].Color.greenF(),
318 anAxisData[2].Color.blueF(),
320 gt.ChangeZAxisAspect().SetTickmarkNumber(anAxisData[2].NbValues-1);
321 gt.ChangeZAxisAspect().SetTickmarkLength(anAxisData[2].TickmarkLength);
322 gt.ChangeZAxisAspect().SetValuesOffset(anAxisData[2].Offset);
323 gt.ChangeZAxisAspect().SetNameOffset(anAxisData[2].Offset + aGap); // see above
325 theView->GraduatedTrihedronDisplay(gt);
327 theView->GraduatedTrihedronDisplay(
328 anAxisData[0].Name.toLatin1().constData(),
329 anAxisData[1].Name.toLatin1().constData(),
330 anAxisData[2].Name.toLatin1().constData(),
331 anAxisData[0].DrawName,
332 anAxisData[1].DrawName,
333 anAxisData[2].DrawName,
334 anAxisData[0].DrawValues,
335 anAxisData[1].DrawValues,
336 anAxisData[2].DrawValues,
337 Standard_True, // draw grid
338 Standard_False, // draw axes
339 anAxisData[0].NbValues - 1,
340 anAxisData[1].NbValues - 1,
341 anAxisData[2].NbValues - 1,
342 anAxisData[0].Offset,
343 anAxisData[1].Offset,
344 anAxisData[2].Offset,
345 anAxisData[0].Offset + aGap, // see above
346 anAxisData[1].Offset + aGap, // see above
347 anAxisData[2].Offset + aGap, // see above
348 anAxisData[0].DrawTickmarks,
349 anAxisData[1].DrawTickmarks,
350 anAxisData[2].DrawTickmarks,
351 anAxisData[0].TickmarkLength,
352 anAxisData[1].TickmarkLength,
353 anAxisData[2].TickmarkLength,
354 Quantity_NOC_WHITE, // grid color
355 Quantity_Color( anAxisData[0].NameColor.redF(),
356 anAxisData[0].NameColor.greenF(),
357 anAxisData[0].NameColor.blueF(),
359 Quantity_Color( anAxisData[1].NameColor.redF(),
360 anAxisData[1].NameColor.greenF(),
361 anAxisData[1].NameColor.blueF(),
363 Quantity_Color( anAxisData[2].NameColor.redF(),
364 anAxisData[2].NameColor.greenF(),
365 anAxisData[2].NameColor.blueF(),
367 Quantity_Color( anAxisData[0].Color.redF(),
368 anAxisData[0].Color.greenF(),
369 anAxisData[0].Color.blueF(),
371 Quantity_Color( anAxisData[1].Color.redF(),
372 anAxisData[1].Color.greenF(),
373 anAxisData[1].Color.blueF(),
375 Quantity_Color( anAxisData[2].Color.redF(),
376 anAxisData[2].Color.greenF(),
377 anAxisData[2].Color.blueF(),
378 Quantity_TOC_RGB ) );
379 #endif // OCC_VERSION_LARGE > 0x06080000
382 theView->GraduatedTrihedronErase();