1 // Copyright (C) 2007-2016 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 <Graphic3d_GraduatedTrihedron.hxx>
39 \class OCCViewer_CubeAxesDlg::AxisWidget
40 \brief Axis tab widget of the "Graduated axis" dialog box
47 OCCViewer_AxisWidget::OCCViewer_AxisWidget (QWidget* theParent)
48 : ViewerTools_AxisWidgetBase(theParent)
55 OCCViewer_AxisWidget::~OCCViewer_AxisWidget()
62 ViewerTools_FontWidgetBase* OCCViewer_AxisWidget::createFontWidget( QWidget* theParent )
64 OCCViewer_FontWidget* aFontWidget = new OCCViewer_FontWidget( theParent );
65 aFontWidget->Initialize();
72 void OCCViewer_AxisWidget::SetData( const AxisData& theAxisData )
74 myNameGrp->setChecked( theAxisData.DrawName );
75 myAxisName->setText( theAxisData.Name );
76 myNameFont->SetData( theAxisData.NameColor, 0, false, false, false );
78 myLabelsGrp->setChecked( theAxisData.DrawValues );
79 myLabelNumber->setValue( theAxisData.NbValues );
80 myLabelOffset->setValue( theAxisData.Offset );
81 myLabelsFont->SetData( theAxisData.Color, 0, false, false, false );
83 myTicksGrp->setChecked( theAxisData.DrawTickmarks );
84 myTickLength->setValue( theAxisData.TickmarkLength );
90 void OCCViewer_AxisWidget::GetData( AxisData& theAxisData )
92 theAxisData.DrawName = myNameGrp->isChecked();
93 theAxisData.Name = myAxisName->text();
96 bool aNameBold, aNameItalic, aNameShadow;
97 myNameFont->GetData( theAxisData.NameColor, aNameFamily, aNameBold, aNameItalic, aNameShadow );
99 theAxisData.DrawValues = myLabelsGrp->isChecked();
100 theAxisData.NbValues = myLabelNumber->value();
101 theAxisData.Offset = myLabelOffset->value();
104 bool aLabelBold, aLabelItalic, aLabelShadow;
105 myLabelsFont->GetData( theAxisData.Color, aLabelFamily, aLabelBold, aLabelItalic, aLabelShadow );
107 theAxisData.DrawTickmarks = myTicksGrp->isChecked();
108 theAxisData.TickmarkLength = myTickLength->value();
112 Class : OCCViewer_CubeAxesDlg
113 Description : Dialog for specifying cube axes properties
119 OCCViewer_CubeAxesDlg::OCCViewer_CubeAxesDlg(QtxAction* theAction,
120 OCCViewer_ViewWindow* theParent,
121 const char* theName):
122 ViewerTools_CubeAxesDlgBase(theAction,
125 myMainWindow(theParent)
132 OCCViewer_CubeAxesDlg::~OCCViewer_CubeAxesDlg()
139 ViewerTools_AxisWidgetBase* OCCViewer_CubeAxesDlg::createAxisWidget( QWidget* theParent )
141 OCCViewer_AxisWidget* anAxisWidget = new OCCViewer_AxisWidget( theParent );
142 anAxisWidget->initialize();
147 Update dialog fields, connect signals and slots, show dialog
149 void OCCViewer_CubeAxesDlg::initialize()
151 ViewerTools_CubeAxesDlgBase::initialize();
153 for( int i = 0; i < 3; i++ )
155 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
157 OCCViewer_AxisWidget::AxisData anAxisData;
161 anAxisData.Name = "X";
162 anAxisData.NameColor = anAxisData.Color = Qt::red;
165 anAxisData.Name = "Y";
166 anAxisData.NameColor = anAxisData.Color = Qt::green;
169 anAxisData.Name = "Z";
170 anAxisData.NameColor = anAxisData.Color = Qt::blue;
173 anAxisData.DrawName = true;
174 anAxisData.DrawValues = true;
175 anAxisData.NbValues = 3;
176 anAxisData.Offset = 2;
177 anAxisData.DrawTickmarks = true;
178 anAxisData.TickmarkLength = 5;
179 anAxisWidget->SetData( anAxisData );
185 Update dialog fields, connect signals and slots, show dialog
187 void OCCViewer_CubeAxesDlg::Update()
189 ViewerTools_CubeAxesDlgBase::Update();
193 Verify validity of entry data
195 bool OCCViewer_CubeAxesDlg::onApply()
197 bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
201 QWidget *aCurrWid = this->focusWidget();
202 aCurrWid->clearFocus();
203 aCurrWid->setFocus();
205 if( OCCViewer_ViewPort3d* aViewPort = myMainWindow->getViewPort() )
207 Handle(V3d_View) aView = aViewPort->getView();
208 if( !aView.IsNull() )
221 Get graduated trihedron parameters
223 void OCCViewer_CubeAxesDlg::GetData( bool& theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
225 theIsVisible = myIsVisible->isChecked();
226 for( int i = 0; i < 3; i++ )
227 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
228 anAxisWidget->GetData( theAxisData[i] );
232 Set graduated trihedron parameters
234 void OCCViewer_CubeAxesDlg::SetData( bool theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
236 myIsVisible->setChecked( theIsVisible );
237 for( int i = 0; i < 3; i++ )
238 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
239 anAxisWidget->SetData( theAxisData[i] );
243 Apply graduated trihedron parameters
245 void OCCViewer_CubeAxesDlg::ApplyData( const Handle(V3d_View)& theView )
247 if( theView.IsNull() )
250 if( myIsVisible->isChecked() )
252 OCCViewer_AxisWidget::AxisData anAxisData[3];
253 for( int i = 0; i < 3; i++ ) {
254 if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
255 anAxisWidget->GetData( anAxisData[i] );
258 // A gap used offset of axis names' offset
259 // (this hard-coded value will be removed when the
260 // font support will be introduced in OCC-6.4)
263 Graphic3d_GraduatedTrihedron gt;
265 gt.SetDrawGrid(Standard_True); // to draw grid
266 gt.SetDrawAxes(Standard_True); // to draw axes
267 gt.SetGridColor(Quantity_NOC_WHITE); // grid color
269 for ( int i = 0; i < 3; i++ ) {
270 Graphic3d_AxisAspect& aspect = gt.ChangeAxisAspect(i);
271 aspect.SetName(anAxisData[i].Name.toLatin1().constData());
272 aspect.SetDrawName(anAxisData[i].DrawName);
273 aspect.SetDrawValues(anAxisData[i].DrawValues);
274 aspect.SetDrawTickmarks(anAxisData[i].DrawTickmarks);
275 aspect.SetNameColor(Quantity_Color(anAxisData[i].NameColor.redF(),
276 anAxisData[i].NameColor.greenF(),
277 anAxisData[i].NameColor.blueF(),
279 aspect.SetColor(Quantity_Color(anAxisData[i].Color.redF(),
280 anAxisData[i].Color.greenF(),
281 anAxisData[i].Color.blueF(),
283 aspect.SetTickmarksNumber(anAxisData[i].NbValues-1);
284 aspect.SetTickmarksLength(anAxisData[i].TickmarkLength);
285 aspect.SetValuesOffset(anAxisData[i].Offset);
286 aspect.SetNameOffset(anAxisData[i].Offset + aGap); // see above
289 theView->GraduatedTrihedronDisplay(gt);
292 theView->GraduatedTrihedronErase();