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.SetDrawGrid(Standard_True); // to draw grid
271 gt.SetDrawAxes(Standard_True); // to draw axes
272 gt.SetGridColor(Quantity_NOC_WHITE); // grid color
274 for ( int i = 0; i < 3; i++ ) {
275 Graphic3d_AxisAspect& aspect = gt.ChangeAxisAspect(i);
276 aspect.SetName(anAxisData[i].Name.toLatin1().constData());
277 aspect.SetDrawName(anAxisData[i].DrawName);
278 aspect.SetDrawValues(anAxisData[i].DrawValues);
279 aspect.SetDrawTickmarks(anAxisData[i].DrawTickmarks);
280 aspect.SetNameColor(Quantity_Color(anAxisData[i].NameColor.redF(),
281 anAxisData[i].NameColor.greenF(),
282 anAxisData[i].NameColor.blueF(),
284 aspect.SetColor(Quantity_Color(anAxisData[i].Color.redF(),
285 anAxisData[i].Color.greenF(),
286 anAxisData[i].Color.blueF(),
288 aspect.SetTickmarksNumber(anAxisData[i].NbValues-1);
289 aspect.SetTickmarksLength(anAxisData[i].TickmarkLength);
290 aspect.SetValuesOffset(anAxisData[i].Offset);
291 aspect.SetNameOffset(anAxisData[i].Offset + aGap); // see above
294 theView->GraduatedTrihedronDisplay(gt);
296 theView->GraduatedTrihedronDisplay(
297 anAxisData[0].Name.toLatin1().constData(),
298 anAxisData[1].Name.toLatin1().constData(),
299 anAxisData[2].Name.toLatin1().constData(),
300 anAxisData[0].DrawName,
301 anAxisData[1].DrawName,
302 anAxisData[2].DrawName,
303 anAxisData[0].DrawValues,
304 anAxisData[1].DrawValues,
305 anAxisData[2].DrawValues,
306 Standard_True, // draw grid
307 Standard_False, // draw axes
308 anAxisData[0].NbValues - 1,
309 anAxisData[1].NbValues - 1,
310 anAxisData[2].NbValues - 1,
311 anAxisData[0].Offset,
312 anAxisData[1].Offset,
313 anAxisData[2].Offset,
314 anAxisData[0].Offset + aGap, // see above
315 anAxisData[1].Offset + aGap, // see above
316 anAxisData[2].Offset + aGap, // see above
317 anAxisData[0].DrawTickmarks,
318 anAxisData[1].DrawTickmarks,
319 anAxisData[2].DrawTickmarks,
320 anAxisData[0].TickmarkLength,
321 anAxisData[1].TickmarkLength,
322 anAxisData[2].TickmarkLength,
323 Quantity_NOC_WHITE, // grid color
324 Quantity_Color( anAxisData[0].NameColor.redF(),
325 anAxisData[0].NameColor.greenF(),
326 anAxisData[0].NameColor.blueF(),
328 Quantity_Color( anAxisData[1].NameColor.redF(),
329 anAxisData[1].NameColor.greenF(),
330 anAxisData[1].NameColor.blueF(),
332 Quantity_Color( anAxisData[2].NameColor.redF(),
333 anAxisData[2].NameColor.greenF(),
334 anAxisData[2].NameColor.blueF(),
336 Quantity_Color( anAxisData[0].Color.redF(),
337 anAxisData[0].Color.greenF(),
338 anAxisData[0].Color.blueF(),
340 Quantity_Color( anAxisData[1].Color.redF(),
341 anAxisData[1].Color.greenF(),
342 anAxisData[1].Color.blueF(),
344 Quantity_Color( anAxisData[2].Color.redF(),
345 anAxisData[2].Color.greenF(),
346 anAxisData[2].Color.blueF(),
347 Quantity_TOC_RGB ) );
348 #endif // OCC_VERSION_LARGE > 0x06080000
351 theView->GraduatedTrihedronErase();