Salome HOME
OCCT dev compatibility
[modules/gui.git] / src / OCCViewer / OCCViewer_CubeAxesDlg.cxx
1 // Copyright (C) 2007-2015  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 #if OCC_VERSION_LARGE > 0x06080000
35 #include <Graphic3d_GraduatedTrihedron.hxx>
36 #endif
37
38 #include <QCheckBox>
39 #include <QGroupBox>
40 #include <QLineEdit>
41
42 /*!
43   \class OCCViewer_CubeAxesDlg::AxisWidget
44   \brief Axis tab widget of the "Graduated axis" dialog box
45   \internal
46 */
47
48 /*!
49   Constructor
50 */
51 OCCViewer_AxisWidget::OCCViewer_AxisWidget (QWidget* theParent)
52 : ViewerTools_AxisWidgetBase(theParent)
53 {
54 }
55
56 /*!
57   Destructor
58 */
59 OCCViewer_AxisWidget::~OCCViewer_AxisWidget()
60 {
61 }
62
63 /*!
64   Create font widget
65 */
66 ViewerTools_FontWidgetBase* OCCViewer_AxisWidget::createFontWidget( QWidget* theParent )
67 {
68   OCCViewer_FontWidget* aFontWidget = new OCCViewer_FontWidget( theParent );
69   aFontWidget->Initialize();
70   return aFontWidget;
71 }
72
73 /*!
74   Set axis data
75 */
76 void OCCViewer_AxisWidget::SetData( const AxisData& theAxisData )
77 {
78   myNameGrp->setChecked( theAxisData.DrawName );
79   myAxisName->setText( theAxisData.Name );
80   myNameFont->SetData( theAxisData.NameColor, 0, false, false, false );
81
82   myLabelsGrp->setChecked( theAxisData.DrawValues );
83   myLabelNumber->setValue( theAxisData.NbValues );
84   myLabelOffset->setValue( theAxisData.Offset );
85   myLabelsFont->SetData( theAxisData.Color, 0, false, false, false );
86
87   myTicksGrp->setChecked( theAxisData.DrawTickmarks );
88   myTickLength->setValue( theAxisData.TickmarkLength );
89 }
90
91 /*!
92   Get axis data
93 */
94 void OCCViewer_AxisWidget::GetData( AxisData& theAxisData )
95 {
96   theAxisData.DrawName = myNameGrp->isChecked();
97   theAxisData.Name = myAxisName->text();
98
99   int aNameFamily;
100   bool aNameBold, aNameItalic, aNameShadow;
101   myNameFont->GetData( theAxisData.NameColor, aNameFamily, aNameBold, aNameItalic, aNameShadow );
102
103   theAxisData.DrawValues = myLabelsGrp->isChecked();
104   theAxisData.NbValues = myLabelNumber->value();
105   theAxisData.Offset = myLabelOffset->value();
106
107   int aLabelFamily;
108   bool aLabelBold, aLabelItalic, aLabelShadow;
109   myLabelsFont->GetData( theAxisData.Color, aLabelFamily, aLabelBold, aLabelItalic, aLabelShadow );
110
111   theAxisData.DrawTickmarks = myTicksGrp->isChecked();
112   theAxisData.TickmarkLength = myTickLength->value();
113 }
114
115 /*
116   Class       : OCCViewer_CubeAxesDlg
117   Description : Dialog for specifying cube axes properties
118 */
119
120 /*!
121   Constructor
122 */
123 OCCViewer_CubeAxesDlg::OCCViewer_CubeAxesDlg(QtxAction* theAction,
124                                              OCCViewer_ViewWindow* theParent,
125                                              const char* theName):
126   ViewerTools_CubeAxesDlgBase(theAction,
127                               theParent, 
128                               theName),
129   myMainWindow(theParent)
130 {
131 }
132
133 /*!
134   Destructor
135 */
136 OCCViewer_CubeAxesDlg::~OCCViewer_CubeAxesDlg()
137 {
138 }
139
140 /*!
141   Create axis widget
142 */
143 ViewerTools_AxisWidgetBase* OCCViewer_CubeAxesDlg::createAxisWidget( QWidget* theParent )
144 {
145   OCCViewer_AxisWidget* anAxisWidget = new OCCViewer_AxisWidget( theParent );
146   anAxisWidget->initialize();
147   return anAxisWidget;
148 }
149
150 /*!
151   Update dialog fields, connect signals and slots, show dialog
152 */
153 void OCCViewer_CubeAxesDlg::initialize()
154 {
155   ViewerTools_CubeAxesDlgBase::initialize();
156
157   for( int i = 0; i < 3; i++ )
158   {
159     if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
160     {
161       OCCViewer_AxisWidget::AxisData anAxisData;
162       switch( i )
163       {
164         case 0:
165           anAxisData.Name = "X";
166           anAxisData.NameColor = anAxisData.Color = Qt::red;
167           break;
168         case 1:
169           anAxisData.Name = "Y";
170           anAxisData.NameColor = anAxisData.Color = Qt::green;
171           break;
172         case 2:
173           anAxisData.Name = "Z";
174           anAxisData.NameColor = anAxisData.Color = Qt::blue;
175           break;
176       }
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 );
184     }
185   }
186 }
187
188 /*!
189   Update dialog fields, connect signals and slots, show dialog
190 */
191 void OCCViewer_CubeAxesDlg::Update()
192 {
193   ViewerTools_CubeAxesDlgBase::Update();
194 }
195
196 /*!
197   Verify validity of entry data
198 */
199 bool OCCViewer_CubeAxesDlg::onApply()
200 {
201   bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
202
203   try
204   {
205     QWidget *aCurrWid = this->focusWidget();
206     aCurrWid->clearFocus();
207     aCurrWid->setFocus();
208
209     if( OCCViewer_ViewPort3d* aViewPort = myMainWindow->getViewPort() )
210     {
211       Handle(V3d_View) aView = aViewPort->getView();
212       if( !aView.IsNull() )
213         ApplyData( aView );
214     }
215   }
216   catch(...)
217   {
218     isOk = false;
219   }
220
221   return isOk;
222 }
223
224 /*!
225   Get graduated trihedron parameters
226 */
227 void OCCViewer_CubeAxesDlg::GetData( bool& theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
228 {
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] );
233 }
234
235 /*!
236   Set graduated trihedron parameters
237 */
238 void OCCViewer_CubeAxesDlg::SetData( bool theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
239 {
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] );
244 }
245
246 /*!
247   Apply graduated trihedron parameters
248 */
249 void OCCViewer_CubeAxesDlg::ApplyData( const Handle(V3d_View)& theView )
250 {
251   if( theView.IsNull() )
252     return;
253
254   if( myIsVisible->isChecked() )
255   {
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] );
260     }
261
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)
265     int aGap = 20;
266
267 #if OCC_VERSION_LARGE > 0x06080000
268 #ifdef OCCT_DEV_COMPAT // VSR: temporarily, to be removed later and replace below implementation
269     Graphic3d_GraduatedTrihedron gt;
270     // main params
271     gt.SetDrawGrid(Standard_True);       // to draw grid
272     gt.SetDrawAxes(Standard_True);       // to draw axes
273     gt.SetGridColor(Quantity_NOC_WHITE); // grid color
274     // axes params
275     for ( int i = 0; i < 3; i++ ) {
276       Graphic3d_AxisAspect& aspect = gt.ChangeAxisAspect(i);
277       aspect.SetName(anAxisData[i].Name.toLatin1().constData());
278       aspect.SetDrawName(anAxisData[i].DrawName);
279       aspect.SetDrawValues(anAxisData[i].DrawValues);
280       aspect.SetDrawTickmarks(anAxisData[i].DrawTickmarks);
281       aspect.SetNameColor(Quantity_Color(anAxisData[i].NameColor.redF(),
282                                          anAxisData[i].NameColor.greenF(),
283                                          anAxisData[i].NameColor.blueF(),
284                                          Quantity_TOC_RGB));
285       aspect.SetColor(Quantity_Color(anAxisData[i].Color.redF(),
286                                      anAxisData[i].Color.greenF(),
287                                      anAxisData[i].Color.blueF(),
288                                      Quantity_TOC_RGB));
289       aspect.SetTickmarksNumber(anAxisData[i].NbValues-1);
290       aspect.SetTickmarksLength(anAxisData[i].TickmarkLength);
291       aspect.SetValuesOffset(anAxisData[i].Offset);
292       aspect.SetNameOffset(anAxisData[i].Offset + aGap); // see above
293     }
294     // draw trihedron
295     theView->GraduatedTrihedronDisplay(gt);
296 #else // #ifdef OCCT_DEV_COMPAT / VSR: temporarily, to be removed later and replace below implementation
297     Graphic3d_GraduatedTrihedron gt;
298     // main params
299     gt.SetToDrawTickmarks(Standard_True);  // to draw grid
300     gt.SetToDrawAxes(Standard_True);       // to draw axes
301     gt.SetGridColor(Quantity_NOC_WHITE);   // grid color
302     // X axis aspect
303     gt.ChangeXAxisAspect().SetName(anAxisData[0].Name.toLatin1().constData());
304     gt.ChangeXAxisAspect().SetToDrawName(anAxisData[0].DrawName);
305     gt.ChangeXAxisAspect().SetToDrawValues(anAxisData[0].DrawValues);
306     gt.ChangeXAxisAspect().SetToDrawTickmarks(anAxisData[0].DrawTickmarks);
307     gt.ChangeXAxisAspect().SetNameColor(Quantity_Color(anAxisData[0].NameColor.redF(),
308                                                        anAxisData[0].NameColor.greenF(),
309                                                        anAxisData[0].NameColor.blueF(),
310                                                        Quantity_TOC_RGB));
311     gt.ChangeXAxisAspect().SetColor(Quantity_Color(anAxisData[0].Color.redF(),
312                                                    anAxisData[0].Color.greenF(),
313                                                    anAxisData[0].Color.blueF(),
314                                                    Quantity_TOC_RGB));
315     gt.ChangeXAxisAspect().SetTickmarkNumber(anAxisData[0].NbValues-1);
316     gt.ChangeXAxisAspect().SetTickmarkLength(anAxisData[0].TickmarkLength);
317     gt.ChangeXAxisAspect().SetValuesOffset(anAxisData[0].Offset);
318     gt.ChangeXAxisAspect().SetNameOffset(anAxisData[0].Offset + aGap); // see above
319     // Y axis aspect
320     gt.ChangeYAxisAspect().SetName(anAxisData[1].Name.toLatin1().constData());
321     gt.ChangeYAxisAspect().SetToDrawName(anAxisData[1].DrawName);
322     gt.ChangeYAxisAspect().SetToDrawValues(anAxisData[1].DrawValues);
323     gt.ChangeYAxisAspect().SetToDrawTickmarks(anAxisData[1].DrawTickmarks);
324     gt.ChangeYAxisAspect().SetNameColor(Quantity_Color(anAxisData[1].NameColor.redF(),
325                                                        anAxisData[1].NameColor.greenF(),
326                                                        anAxisData[1].NameColor.blueF(),
327                                                        Quantity_TOC_RGB));
328     gt.ChangeYAxisAspect().SetColor(Quantity_Color(anAxisData[1].Color.redF(),
329                                                    anAxisData[1].Color.greenF(),
330                                                    anAxisData[1].Color.blueF(),
331                                                    Quantity_TOC_RGB));
332     gt.ChangeYAxisAspect().SetTickmarkNumber(anAxisData[1].NbValues-1);
333     gt.ChangeYAxisAspect().SetTickmarkLength(anAxisData[1].TickmarkLength);
334     gt.ChangeYAxisAspect().SetValuesOffset(anAxisData[1].Offset);
335     gt.ChangeYAxisAspect().SetNameOffset(anAxisData[1].Offset + aGap); // see above
336     // Z axis aspect
337     gt.ChangeZAxisAspect().SetName(anAxisData[2].Name.toLatin1().constData());
338     gt.ChangeZAxisAspect().SetToDrawName(anAxisData[2].DrawName);
339     gt.ChangeZAxisAspect().SetToDrawValues(anAxisData[2].DrawValues);
340     gt.ChangeZAxisAspect().SetToDrawTickmarks(anAxisData[2].DrawTickmarks);
341     gt.ChangeZAxisAspect().SetNameColor(Quantity_Color(anAxisData[2].NameColor.redF(),
342                                                        anAxisData[2].NameColor.greenF(),
343                                                        anAxisData[2].NameColor.blueF(),
344                                                        Quantity_TOC_RGB));
345     gt.ChangeZAxisAspect().SetColor(Quantity_Color(anAxisData[2].Color.redF(),
346                                                    anAxisData[2].Color.greenF(),
347                                                    anAxisData[2].Color.blueF(),
348                                                    Quantity_TOC_RGB));
349     gt.ChangeZAxisAspect().SetTickmarkNumber(anAxisData[2].NbValues-1);
350     gt.ChangeZAxisAspect().SetTickmarkLength(anAxisData[2].TickmarkLength);
351     gt.ChangeZAxisAspect().SetValuesOffset(anAxisData[2].Offset);
352     gt.ChangeZAxisAspect().SetNameOffset(anAxisData[2].Offset + aGap); // see above
353     // draw trihedron
354     theView->GraduatedTrihedronDisplay(gt);
355 #endif // #ifdef OCCT_DEV_COMPAT / VSR: temporarily, to be removed later and replace below implementation
356 #else
357     theView->GraduatedTrihedronDisplay(
358       anAxisData[0].Name.toLatin1().constData(),
359       anAxisData[1].Name.toLatin1().constData(),
360       anAxisData[2].Name.toLatin1().constData(),
361       anAxisData[0].DrawName,
362       anAxisData[1].DrawName,
363       anAxisData[2].DrawName,
364       anAxisData[0].DrawValues,
365       anAxisData[1].DrawValues,
366       anAxisData[2].DrawValues,
367       Standard_True, // draw grid
368       Standard_False, // draw axes
369       anAxisData[0].NbValues - 1,
370       anAxisData[1].NbValues - 1,
371       anAxisData[2].NbValues - 1,
372       anAxisData[0].Offset,
373       anAxisData[1].Offset,
374       anAxisData[2].Offset,
375       anAxisData[0].Offset + aGap, // see above
376       anAxisData[1].Offset + aGap, // see above
377       anAxisData[2].Offset + aGap, // see above
378       anAxisData[0].DrawTickmarks,
379       anAxisData[1].DrawTickmarks,
380       anAxisData[2].DrawTickmarks,
381       anAxisData[0].TickmarkLength,
382       anAxisData[1].TickmarkLength,
383       anAxisData[2].TickmarkLength,
384       Quantity_NOC_WHITE, // grid color
385       Quantity_Color( anAxisData[0].NameColor.redF(),
386                       anAxisData[0].NameColor.greenF(),
387                       anAxisData[0].NameColor.blueF(),
388                       Quantity_TOC_RGB ),
389       Quantity_Color( anAxisData[1].NameColor.redF(),
390                       anAxisData[1].NameColor.greenF(),
391                       anAxisData[1].NameColor.blueF(),
392                       Quantity_TOC_RGB ),
393       Quantity_Color( anAxisData[2].NameColor.redF(),
394                       anAxisData[2].NameColor.greenF(),
395                       anAxisData[2].NameColor.blueF(),
396                       Quantity_TOC_RGB ),
397       Quantity_Color( anAxisData[0].Color.redF(),
398                       anAxisData[0].Color.greenF(),
399                       anAxisData[0].Color.blueF(),
400                       Quantity_TOC_RGB ),
401       Quantity_Color( anAxisData[1].Color.redF(),
402                       anAxisData[1].Color.greenF(),
403                       anAxisData[1].Color.blueF(),
404                       Quantity_TOC_RGB ),
405       Quantity_Color( anAxisData[2].Color.redF(),
406                       anAxisData[2].Color.greenF(),
407                       anAxisData[2].Color.blueF(),
408                       Quantity_TOC_RGB ) );
409 #endif // OCC_VERSION_LARGE > 0x06080000
410   }
411   else
412     theView->GraduatedTrihedronErase();
413
414   theView->Redraw();
415 }