Salome HOME
OCCT dev (6.8.0) compatibility
[modules/gui.git] / src / OCCViewer / OCCViewer_CubeAxesDlg.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "OCCViewer_CubeAxesDlg.h"
24
25 #include "OCCViewer_FontWidget.h"
26 #include "OCCViewer_ViewPort3d.h"
27 #include "OCCViewer_ViewWindow.h"
28
29 #include "QtxAction.h"
30 #include "QtxIntSpinBox.h"
31
32 #include <QCheckBox>
33 #include <QGroupBox>
34 #include <QLineEdit>
35
36 /*!
37   \class OCCViewer_CubeAxesDlg::AxisWidget
38   \brief Axis tab widget of the "Graduated axis" dialog box
39   \internal
40 */
41
42 /*!
43   Constructor
44 */
45 OCCViewer_AxisWidget::OCCViewer_AxisWidget (QWidget* theParent)
46 : ViewerTools_AxisWidgetBase(theParent)
47 {
48 }
49
50 /*!
51   Destructor
52 */
53 OCCViewer_AxisWidget::~OCCViewer_AxisWidget()
54 {
55 }
56
57 /*!
58   Create font widget
59 */
60 ViewerTools_FontWidgetBase* OCCViewer_AxisWidget::createFontWidget( QWidget* theParent )
61 {
62   OCCViewer_FontWidget* aFontWidget = new OCCViewer_FontWidget( theParent );
63   aFontWidget->Initialize();
64   return aFontWidget;
65 }
66
67 /*!
68   Set axis data
69 */
70 void OCCViewer_AxisWidget::SetData( const AxisData& theAxisData )
71 {
72   myNameGrp->setChecked( theAxisData.DrawName );
73   myAxisName->setText( theAxisData.Name );
74   myNameFont->SetData( theAxisData.NameColor, 0, false, false, false );
75
76   myLabelsGrp->setChecked( theAxisData.DrawValues );
77   myLabelNumber->setValue( theAxisData.NbValues );
78   myLabelOffset->setValue( theAxisData.Offset );
79   myLabelsFont->SetData( theAxisData.Color, 0, false, false, false );
80
81   myTicksGrp->setChecked( theAxisData.DrawTickmarks );
82   myTickLength->setValue( theAxisData.TickmarkLength );
83 }
84
85 /*!
86   Get axis data
87 */
88 void OCCViewer_AxisWidget::GetData( AxisData& theAxisData )
89 {
90   theAxisData.DrawName = myNameGrp->isChecked();
91   theAxisData.Name = myAxisName->text();
92
93   int aNameFamily;
94   bool aNameBold, aNameItalic, aNameShadow;
95   myNameFont->GetData( theAxisData.NameColor, aNameFamily, aNameBold, aNameItalic, aNameShadow );
96
97   theAxisData.DrawValues = myLabelsGrp->isChecked();
98   theAxisData.NbValues = myLabelNumber->value();
99   theAxisData.Offset = myLabelOffset->value();
100
101   int aLabelFamily;
102   bool aLabelBold, aLabelItalic, aLabelShadow;
103   myLabelsFont->GetData( theAxisData.Color, aLabelFamily, aLabelBold, aLabelItalic, aLabelShadow );
104
105   theAxisData.DrawTickmarks = myTicksGrp->isChecked();
106   theAxisData.TickmarkLength = myTickLength->value();
107 }
108
109 /*
110   Class       : OCCViewer_CubeAxesDlg
111   Description : Dialog for specifying cube axes properties
112 */
113
114 /*!
115   Constructor
116 */
117 OCCViewer_CubeAxesDlg::OCCViewer_CubeAxesDlg(QtxAction* theAction,
118                                              OCCViewer_ViewWindow* theParent,
119                                              const char* theName):
120   ViewerTools_CubeAxesDlgBase(theAction,
121                               theParent, 
122                               theName),
123   myMainWindow(theParent)
124 {
125 }
126
127 /*!
128   Destructor
129 */
130 OCCViewer_CubeAxesDlg::~OCCViewer_CubeAxesDlg()
131 {
132 }
133
134 /*!
135   Create axis widget
136 */
137 ViewerTools_AxisWidgetBase* OCCViewer_CubeAxesDlg::createAxisWidget( QWidget* theParent )
138 {
139   OCCViewer_AxisWidget* anAxisWidget = new OCCViewer_AxisWidget( theParent );
140   anAxisWidget->initialize();
141   return anAxisWidget;
142 }
143
144 /*!
145   Update dialog fields, connect signals and slots, show dialog
146 */
147 void OCCViewer_CubeAxesDlg::initialize()
148 {
149   ViewerTools_CubeAxesDlgBase::initialize();
150
151   for( int i = 0; i < 3; i++ )
152   {
153     if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
154     {
155       OCCViewer_AxisWidget::AxisData anAxisData;
156       switch( i )
157       {
158         case 0:
159           anAxisData.Name = "X";
160           anAxisData.NameColor = anAxisData.Color = Qt::red;
161           break;
162         case 1:
163           anAxisData.Name = "Y";
164           anAxisData.NameColor = anAxisData.Color = Qt::green;
165           break;
166         case 2:
167           anAxisData.Name = "Z";
168           anAxisData.NameColor = anAxisData.Color = Qt::blue;
169           break;
170       }
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 );
178     }
179   }
180 }
181
182 /*!
183   Update dialog fields, connect signals and slots, show dialog
184 */
185 void OCCViewer_CubeAxesDlg::Update()
186 {
187   ViewerTools_CubeAxesDlgBase::Update();
188 }
189
190 /*!
191   Verify validity of entry data
192 */
193 bool OCCViewer_CubeAxesDlg::onApply()
194 {
195   bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
196
197   try
198   {
199     QWidget *aCurrWid = this->focusWidget();
200     aCurrWid->clearFocus();
201     aCurrWid->setFocus();
202
203     if( OCCViewer_ViewPort3d* aViewPort = myMainWindow->getViewPort() )
204     {
205       Handle(V3d_View) aView = aViewPort->getView();
206       if( !aView.IsNull() )
207         ApplyData( aView );
208     }
209   }
210   catch(...)
211   {
212     isOk = false;
213   }
214
215   return isOk;
216 }
217
218 /*!
219   Get graduated trihedron parameters
220 */
221 void OCCViewer_CubeAxesDlg::GetData( bool& theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
222 {
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] );
227 }
228
229 /*!
230   Set graduated trihedron parameters
231 */
232 void OCCViewer_CubeAxesDlg::SetData( bool theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
233 {
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] );
238 }
239
240 /*!
241   Apply graduated trihedron parameters
242 */
243 void OCCViewer_CubeAxesDlg::ApplyData( const Handle(V3d_View)& theView )
244 {
245   if( theView.IsNull() )
246     return;
247
248   if( myIsVisible->isChecked() )
249   {
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] );
254
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)
258     int aGap = 20;
259
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(),
291                       Quantity_TOC_RGB ),
292       Quantity_Color( anAxisData[1].NameColor.redF(),
293                       anAxisData[1].NameColor.greenF(),
294                       anAxisData[1].NameColor.blueF(),
295                       Quantity_TOC_RGB ),
296       Quantity_Color( anAxisData[2].NameColor.redF(),
297                       anAxisData[2].NameColor.greenF(),
298                       anAxisData[2].NameColor.blueF(),
299                       Quantity_TOC_RGB ),
300       Quantity_Color( anAxisData[0].Color.redF(),
301                       anAxisData[0].Color.greenF(),
302                       anAxisData[0].Color.blueF(),
303                       Quantity_TOC_RGB ),
304       Quantity_Color( anAxisData[1].Color.redF(),
305                       anAxisData[1].Color.greenF(),
306                       anAxisData[1].Color.blueF(),
307                       Quantity_TOC_RGB ),
308       Quantity_Color( anAxisData[2].Color.redF(),
309                       anAxisData[2].Color.greenF(),
310                       anAxisData[2].Color.blueF(),
311                       Quantity_TOC_RGB ) );
312   }
313   else
314     theView->GraduatedTrihedronErase();
315
316   theView->Redraw();
317 }