1 // Copyright (C) 2007-2014 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"
37 \class OCCViewer_CubeAxesDlg::AxisWidget
38 \brief Axis tab widget of the "Graduated axis" dialog box
45 OCCViewer_AxisWidget::OCCViewer_AxisWidget (QWidget* theParent)
46 : ViewerTools_AxisWidgetBase(theParent)
53 OCCViewer_AxisWidget::~OCCViewer_AxisWidget()
60 ViewerTools_FontWidgetBase* OCCViewer_AxisWidget::createFontWidget( QWidget* theParent )
62 OCCViewer_FontWidget* aFontWidget = new OCCViewer_FontWidget( theParent );
63 aFontWidget->Initialize();
70 void OCCViewer_AxisWidget::SetData( const AxisData& theAxisData )
72 myNameGrp->setChecked( theAxisData.DrawName );
73 myAxisName->setText( theAxisData.Name );
74 myNameFont->SetData( theAxisData.NameColor, 0, false, false, false );
76 myLabelsGrp->setChecked( theAxisData.DrawValues );
77 myLabelNumber->setValue( theAxisData.NbValues );
78 myLabelOffset->setValue( theAxisData.Offset );
79 myLabelsFont->SetData( theAxisData.Color, 0, false, false, false );
81 myTicksGrp->setChecked( theAxisData.DrawTickmarks );
82 myTickLength->setValue( theAxisData.TickmarkLength );
88 void OCCViewer_AxisWidget::GetData( AxisData& theAxisData )
90 theAxisData.DrawName = myNameGrp->isChecked();
91 theAxisData.Name = myAxisName->text();
94 bool aNameBold, aNameItalic, aNameShadow;
95 myNameFont->GetData( theAxisData.NameColor, aNameFamily, aNameBold, aNameItalic, aNameShadow );
97 theAxisData.DrawValues = myLabelsGrp->isChecked();
98 theAxisData.NbValues = myLabelNumber->value();
99 theAxisData.Offset = myLabelOffset->value();
102 bool aLabelBold, aLabelItalic, aLabelShadow;
103 myLabelsFont->GetData( theAxisData.Color, aLabelFamily, aLabelBold, aLabelItalic, aLabelShadow );
105 theAxisData.DrawTickmarks = myTicksGrp->isChecked();
106 theAxisData.TickmarkLength = myTickLength->value();
110 Class : OCCViewer_CubeAxesDlg
111 Description : Dialog for specifying cube axes properties
117 OCCViewer_CubeAxesDlg::OCCViewer_CubeAxesDlg(QtxAction* theAction,
118 OCCViewer_ViewWindow* theParent,
119 const char* theName):
120 ViewerTools_CubeAxesDlgBase(theAction,
123 myMainWindow(theParent)
130 OCCViewer_CubeAxesDlg::~OCCViewer_CubeAxesDlg()
137 ViewerTools_AxisWidgetBase* OCCViewer_CubeAxesDlg::createAxisWidget( QWidget* theParent )
139 OCCViewer_AxisWidget* anAxisWidget = new OCCViewer_AxisWidget( theParent );
140 anAxisWidget->initialize();
145 Update dialog fields, connect signals and slots, show dialog
147 void OCCViewer_CubeAxesDlg::initialize()
149 ViewerTools_CubeAxesDlgBase::initialize();
151 for( int i = 0; i < 3; i++ )
153 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
155 OCCViewer_AxisWidget::AxisData anAxisData;
159 anAxisData.Name = "X";
160 anAxisData.NameColor = anAxisData.Color = Qt::red;
163 anAxisData.Name = "Y";
164 anAxisData.NameColor = anAxisData.Color = Qt::green;
167 anAxisData.Name = "Z";
168 anAxisData.NameColor = anAxisData.Color = Qt::blue;
171 anAxisData.DrawName = true;
172 anAxisData.DrawValues = true;
173 anAxisData.NbValues = 3;
174 anAxisData.Offset = 2;
175 anAxisData.DrawTickmarks = true;
176 anAxisData.TickmarkLength = 5;
177 anAxisWidget->SetData( anAxisData );
183 Update dialog fields, connect signals and slots, show dialog
185 void OCCViewer_CubeAxesDlg::Update()
187 ViewerTools_CubeAxesDlgBase::Update();
191 Verify validity of entry data
193 bool OCCViewer_CubeAxesDlg::onApply()
195 bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
199 QWidget *aCurrWid = this->focusWidget();
200 aCurrWid->clearFocus();
201 aCurrWid->setFocus();
203 if( OCCViewer_ViewPort3d* aViewPort = myMainWindow->getViewPort() )
205 Handle(V3d_View) aView = aViewPort->getView();
206 if( !aView.IsNull() )
219 Get graduated trihedron parameters
221 void OCCViewer_CubeAxesDlg::GetData( bool& theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
223 theIsVisible = myIsVisible->isChecked();
224 for( int i = 0; i < 3; i++ )
225 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
226 anAxisWidget->GetData( theAxisData[i] );
230 Set graduated trihedron parameters
232 void OCCViewer_CubeAxesDlg::SetData( bool theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
234 myIsVisible->setChecked( theIsVisible );
235 for( int i = 0; i < 3; i++ )
236 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
237 anAxisWidget->SetData( theAxisData[i] );
241 Apply graduated trihedron parameters
243 void OCCViewer_CubeAxesDlg::ApplyData( const Handle(V3d_View)& theView )
245 if( theView.IsNull() )
248 if( myIsVisible->isChecked() )
250 OCCViewer_AxisWidget::AxisData anAxisData[3];
251 for( int i = 0; i < 3; i++ )
252 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
253 anAxisWidget->GetData( anAxisData[i] );
255 // A gap used offset of axis names' offset
256 // (this hard-coded value will be removed when the
257 // font support will be introduced in OCC-6.4)
260 theView->GraduatedTrihedronDisplay(
261 anAxisData[0].Name.toLatin1().constData(),
262 anAxisData[1].Name.toLatin1().constData(),
263 anAxisData[2].Name.toLatin1().constData(),
264 anAxisData[0].DrawName,
265 anAxisData[1].DrawName,
266 anAxisData[2].DrawName,
267 anAxisData[0].DrawValues,
268 anAxisData[1].DrawValues,
269 anAxisData[2].DrawValues,
270 Standard_True, // draw grid
271 Standard_False, // draw axes
272 anAxisData[0].NbValues - 1,
273 anAxisData[1].NbValues - 1,
274 anAxisData[2].NbValues - 1,
275 anAxisData[0].Offset,
276 anAxisData[1].Offset,
277 anAxisData[2].Offset,
278 anAxisData[0].Offset + aGap, // see above
279 anAxisData[1].Offset + aGap, // see above
280 anAxisData[2].Offset + aGap, // see above
281 anAxisData[0].DrawTickmarks,
282 anAxisData[1].DrawTickmarks,
283 anAxisData[2].DrawTickmarks,
284 anAxisData[0].TickmarkLength,
285 anAxisData[1].TickmarkLength,
286 anAxisData[2].TickmarkLength,
287 Quantity_NOC_WHITE, // grid color
288 Quantity_Color( anAxisData[0].NameColor.redF(),
289 anAxisData[0].NameColor.greenF(),
290 anAxisData[0].NameColor.blueF(),
292 Quantity_Color( anAxisData[1].NameColor.redF(),
293 anAxisData[1].NameColor.greenF(),
294 anAxisData[1].NameColor.blueF(),
296 Quantity_Color( anAxisData[2].NameColor.redF(),
297 anAxisData[2].NameColor.greenF(),
298 anAxisData[2].NameColor.blueF(),
300 Quantity_Color( anAxisData[0].Color.redF(),
301 anAxisData[0].Color.greenF(),
302 anAxisData[0].Color.blueF(),
304 Quantity_Color( anAxisData[1].Color.redF(),
305 anAxisData[1].Color.greenF(),
306 anAxisData[1].Color.blueF(),
308 Quantity_Color( anAxisData[2].Color.redF(),
309 anAxisData[2].Color.greenF(),
310 anAxisData[2].Color.blueF(),
311 Quantity_TOC_RGB ) );
314 theView->GraduatedTrihedronErase();