Salome HOME
refs #1458: disable chained panning on operations
[modules/gui.git] / src / OCCViewer / OCCViewer_CubeAxesDlg.cxx
1 // Copyright (C) 2007-2016  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     Graphic3d_GraduatedTrihedron gt;
269     // main params
270     gt.SetDrawGrid(Standard_True);       // to draw grid
271     gt.SetDrawAxes(Standard_True);       // to draw axes
272     gt.SetGridColor(Quantity_NOC_WHITE); // grid color
273     // axes params
274     for ( int i = 0; i < 3; i++ ) {
275       Graphic3d_AxisAspect& aspect = gt.ChangeAxisAspect(i);
276       aspect.SetName(anAxisData[i].Name.toLatin1().constData());
277       aspect.SetDrawName(anAxisData[i].DrawName);
278       aspect.SetDrawValues(anAxisData[i].DrawValues);
279       aspect.SetDrawTickmarks(anAxisData[i].DrawTickmarks);
280       aspect.SetNameColor(Quantity_Color(anAxisData[i].NameColor.redF(),
281                                          anAxisData[i].NameColor.greenF(),
282                                          anAxisData[i].NameColor.blueF(),
283                                          Quantity_TOC_RGB));
284       aspect.SetColor(Quantity_Color(anAxisData[i].Color.redF(),
285                                      anAxisData[i].Color.greenF(),
286                                      anAxisData[i].Color.blueF(),
287                                      Quantity_TOC_RGB));
288       aspect.SetTickmarksNumber(anAxisData[i].NbValues-1);
289       aspect.SetTickmarksLength(anAxisData[i].TickmarkLength);
290       aspect.SetValuesOffset(anAxisData[i].Offset);
291       aspect.SetNameOffset(anAxisData[i].Offset + aGap); // see above
292     }
293     // draw trihedron
294     theView->GraduatedTrihedronDisplay(gt);
295 #else
296     theView->GraduatedTrihedronDisplay(
297       anAxisData[0].Name.toLatin1().constData(),
298       anAxisData[1].Name.toLatin1().constData(),
299       anAxisData[2].Name.toLatin1().constData(),
300       anAxisData[0].DrawName,
301       anAxisData[1].DrawName,
302       anAxisData[2].DrawName,
303       anAxisData[0].DrawValues,
304       anAxisData[1].DrawValues,
305       anAxisData[2].DrawValues,
306       Standard_True, // draw grid
307       Standard_False, // draw axes
308       anAxisData[0].NbValues - 1,
309       anAxisData[1].NbValues - 1,
310       anAxisData[2].NbValues - 1,
311       anAxisData[0].Offset,
312       anAxisData[1].Offset,
313       anAxisData[2].Offset,
314       anAxisData[0].Offset + aGap, // see above
315       anAxisData[1].Offset + aGap, // see above
316       anAxisData[2].Offset + aGap, // see above
317       anAxisData[0].DrawTickmarks,
318       anAxisData[1].DrawTickmarks,
319       anAxisData[2].DrawTickmarks,
320       anAxisData[0].TickmarkLength,
321       anAxisData[1].TickmarkLength,
322       anAxisData[2].TickmarkLength,
323       Quantity_NOC_WHITE, // grid color
324       Quantity_Color( anAxisData[0].NameColor.redF(),
325                       anAxisData[0].NameColor.greenF(),
326                       anAxisData[0].NameColor.blueF(),
327                       Quantity_TOC_RGB ),
328       Quantity_Color( anAxisData[1].NameColor.redF(),
329                       anAxisData[1].NameColor.greenF(),
330                       anAxisData[1].NameColor.blueF(),
331                       Quantity_TOC_RGB ),
332       Quantity_Color( anAxisData[2].NameColor.redF(),
333                       anAxisData[2].NameColor.greenF(),
334                       anAxisData[2].NameColor.blueF(),
335                       Quantity_TOC_RGB ),
336       Quantity_Color( anAxisData[0].Color.redF(),
337                       anAxisData[0].Color.greenF(),
338                       anAxisData[0].Color.blueF(),
339                       Quantity_TOC_RGB ),
340       Quantity_Color( anAxisData[1].Color.redF(),
341                       anAxisData[1].Color.greenF(),
342                       anAxisData[1].Color.blueF(),
343                       Quantity_TOC_RGB ),
344       Quantity_Color( anAxisData[2].Color.redF(),
345                       anAxisData[2].Color.greenF(),
346                       anAxisData[2].Color.blueF(),
347                       Quantity_TOC_RGB ) );
348 #endif // OCC_VERSION_LARGE > 0x06080000
349   }
350   else
351     theView->GraduatedTrihedronErase();
352
353   theView->Redraw();
354 }