Salome HOME
Remove obsolete OCC_VERSION_LARGE defines.
[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 <Basics_OCCTVersion.hxx>
33
34 #include <QCheckBox>
35 #include <QGroupBox>
36 #include <QLineEdit>
37
38 /*!
39   \class OCCViewer_CubeAxesDlg::AxisWidget
40   \brief Axis tab widget of the "Graduated axis" dialog box
41   \internal
42 */
43
44 /*!
45   Constructor
46 */
47 OCCViewer_AxisWidget::OCCViewer_AxisWidget (QWidget* theParent)
48 : ViewerTools_AxisWidgetBase(theParent)
49 {
50 }
51
52 /*!
53   Destructor
54 */
55 OCCViewer_AxisWidget::~OCCViewer_AxisWidget()
56 {
57 }
58
59 /*!
60   Create font widget
61 */
62 ViewerTools_FontWidgetBase* OCCViewer_AxisWidget::createFontWidget( QWidget* theParent )
63 {
64   OCCViewer_FontWidget* aFontWidget = new OCCViewer_FontWidget( theParent );
65   aFontWidget->Initialize();
66   return aFontWidget;
67 }
68
69 /*!
70   Set axis data
71 */
72 void OCCViewer_AxisWidget::SetData( const AxisData& theAxisData )
73 {
74   myNameGrp->setChecked( theAxisData.DrawName );
75   myAxisName->setText( theAxisData.Name );
76   myNameFont->SetData( theAxisData.NameColor, 0, false, false, false );
77
78   myLabelsGrp->setChecked( theAxisData.DrawValues );
79   myLabelNumber->setValue( theAxisData.NbValues );
80   myLabelOffset->setValue( theAxisData.Offset );
81   myLabelsFont->SetData( theAxisData.Color, 0, false, false, false );
82
83   myTicksGrp->setChecked( theAxisData.DrawTickmarks );
84   myTickLength->setValue( theAxisData.TickmarkLength );
85 }
86
87 /*!
88   Get axis data
89 */
90 void OCCViewer_AxisWidget::GetData( AxisData& theAxisData )
91 {
92   theAxisData.DrawName = myNameGrp->isChecked();
93   theAxisData.Name = myAxisName->text();
94
95   int aNameFamily;
96   bool aNameBold, aNameItalic, aNameShadow;
97   myNameFont->GetData( theAxisData.NameColor, aNameFamily, aNameBold, aNameItalic, aNameShadow );
98
99   theAxisData.DrawValues = myLabelsGrp->isChecked();
100   theAxisData.NbValues = myLabelNumber->value();
101   theAxisData.Offset = myLabelOffset->value();
102
103   int aLabelFamily;
104   bool aLabelBold, aLabelItalic, aLabelShadow;
105   myLabelsFont->GetData( theAxisData.Color, aLabelFamily, aLabelBold, aLabelItalic, aLabelShadow );
106
107   theAxisData.DrawTickmarks = myTicksGrp->isChecked();
108   theAxisData.TickmarkLength = myTickLength->value();
109 }
110
111 /*
112   Class       : OCCViewer_CubeAxesDlg
113   Description : Dialog for specifying cube axes properties
114 */
115
116 /*!
117   Constructor
118 */
119 OCCViewer_CubeAxesDlg::OCCViewer_CubeAxesDlg(QtxAction* theAction,
120                                              OCCViewer_ViewWindow* theParent,
121                                              const char* theName):
122   ViewerTools_CubeAxesDlgBase(theAction,
123                               theParent, 
124                               theName),
125   myMainWindow(theParent)
126 {
127 }
128
129 /*!
130   Destructor
131 */
132 OCCViewer_CubeAxesDlg::~OCCViewer_CubeAxesDlg()
133 {
134 }
135
136 /*!
137   Create axis widget
138 */
139 ViewerTools_AxisWidgetBase* OCCViewer_CubeAxesDlg::createAxisWidget( QWidget* theParent )
140 {
141   OCCViewer_AxisWidget* anAxisWidget = new OCCViewer_AxisWidget( theParent );
142   anAxisWidget->initialize();
143   return anAxisWidget;
144 }
145
146 /*!
147   Update dialog fields, connect signals and slots, show dialog
148 */
149 void OCCViewer_CubeAxesDlg::initialize()
150 {
151   ViewerTools_CubeAxesDlgBase::initialize();
152
153   for( int i = 0; i < 3; i++ )
154   {
155     if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
156     {
157       OCCViewer_AxisWidget::AxisData anAxisData;
158       switch( i )
159       {
160         case 0:
161           anAxisData.Name = "X";
162           anAxisData.NameColor = anAxisData.Color = Qt::red;
163           break;
164         case 1:
165           anAxisData.Name = "Y";
166           anAxisData.NameColor = anAxisData.Color = Qt::green;
167           break;
168         case 2:
169           anAxisData.Name = "Z";
170           anAxisData.NameColor = anAxisData.Color = Qt::blue;
171           break;
172       }
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 );
180     }
181   }
182 }
183
184 /*!
185   Update dialog fields, connect signals and slots, show dialog
186 */
187 void OCCViewer_CubeAxesDlg::Update()
188 {
189   ViewerTools_CubeAxesDlgBase::Update();
190 }
191
192 /*!
193   Verify validity of entry data
194 */
195 bool OCCViewer_CubeAxesDlg::onApply()
196 {
197   bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
198
199   try
200   {
201     QWidget *aCurrWid = this->focusWidget();
202     aCurrWid->clearFocus();
203     aCurrWid->setFocus();
204
205     if( OCCViewer_ViewPort3d* aViewPort = myMainWindow->getViewPort() )
206     {
207       Handle(V3d_View) aView = aViewPort->getView();
208       if( !aView.IsNull() )
209         ApplyData( aView );
210     }
211   }
212   catch(...)
213   {
214     isOk = false;
215   }
216
217   return isOk;
218 }
219
220 /*!
221   Get graduated trihedron parameters
222 */
223 void OCCViewer_CubeAxesDlg::GetData( bool& theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
224 {
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] );
229 }
230
231 /*!
232   Set graduated trihedron parameters
233 */
234 void OCCViewer_CubeAxesDlg::SetData( bool theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
235 {
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] );
240 }
241
242 /*!
243   Apply graduated trihedron parameters
244 */
245 void OCCViewer_CubeAxesDlg::ApplyData( const Handle(V3d_View)& theView )
246 {
247   if( theView.IsNull() )
248     return;
249
250   if( myIsVisible->isChecked() )
251   {
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] );
256
257     // A gap used offset of axis names' offset
258     // (this hard-coded value will be removed when the
259     // font support will be introduced in OCC-6.4)
260     int aGap = 20;
261
262     theView->GraduatedTrihedronDisplay(
263       anAxisData[0].Name.toLatin1().constData(),
264       anAxisData[1].Name.toLatin1().constData(),
265       anAxisData[2].Name.toLatin1().constData(),
266       anAxisData[0].DrawName,
267       anAxisData[1].DrawName,
268       anAxisData[2].DrawName,
269       anAxisData[0].DrawValues,
270       anAxisData[1].DrawValues,
271       anAxisData[2].DrawValues,
272       Standard_True, // draw grid
273       Standard_False, // draw axes
274       anAxisData[0].NbValues - 1,
275       anAxisData[1].NbValues - 1,
276       anAxisData[2].NbValues - 1,
277       anAxisData[0].Offset,
278       anAxisData[1].Offset,
279       anAxisData[2].Offset,
280       anAxisData[0].Offset + aGap, // see above
281       anAxisData[1].Offset + aGap, // see above
282       anAxisData[2].Offset + aGap, // see above
283       anAxisData[0].DrawTickmarks,
284       anAxisData[1].DrawTickmarks,
285       anAxisData[2].DrawTickmarks,
286       anAxisData[0].TickmarkLength,
287       anAxisData[1].TickmarkLength,
288       anAxisData[2].TickmarkLength,
289       Quantity_NOC_WHITE, // grid color
290       Quantity_Color( anAxisData[0].NameColor.redF(),
291                       anAxisData[0].NameColor.greenF(),
292                       anAxisData[0].NameColor.blueF(),
293                       Quantity_TOC_RGB ),
294       Quantity_Color( anAxisData[1].NameColor.redF(),
295                       anAxisData[1].NameColor.greenF(),
296                       anAxisData[1].NameColor.blueF(),
297                       Quantity_TOC_RGB ),
298       Quantity_Color( anAxisData[2].NameColor.redF(),
299                       anAxisData[2].NameColor.greenF(),
300                       anAxisData[2].NameColor.blueF(),
301                       Quantity_TOC_RGB ),
302       Quantity_Color( anAxisData[0].Color.redF(),
303                       anAxisData[0].Color.greenF(),
304                       anAxisData[0].Color.blueF(),
305                       Quantity_TOC_RGB ),
306       Quantity_Color( anAxisData[1].Color.redF(),
307                       anAxisData[1].Color.greenF(),
308                       anAxisData[1].Color.blueF(),
309                       Quantity_TOC_RGB ),
310       Quantity_Color( anAxisData[2].Color.redF(),
311                       anAxisData[2].Color.greenF(),
312                       anAxisData[2].Color.blueF(),
313                       Quantity_TOC_RGB ) );
314   }
315   else
316     theView->GraduatedTrihedronErase();
317
318   theView->Redraw();
319 }