Salome HOME
updated copyright message
[modules/gui.git] / src / SVTK / SVTK_CubeAxesDlg.cxx
1 // Copyright (C) 2007-2023  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 //  VISU VISUGUI : GUI for SMESH component
24 //  File   : SVTK_CubeAxesDlg.cxx
25 //  Author : Sergey LITONIN
26 //  Module : VISU
27 //
28 #include "SVTK_CubeAxesDlg.h"
29
30 #include "SVTK_ViewWindow.h"
31 #include "SVTK_FontWidget.h"
32
33 #include "SVTK_CubeAxesActor2D.h"
34
35 #include "QtxAction.h"
36 #include "QtxIntSpinBox.h"
37
38 #include <QCheckBox>
39 #include <QGroupBox>
40 #include <QLineEdit>
41
42 #include <vtkAxisActor2D.h>
43 #include <vtkTextProperty.h>
44
45 /*!
46   \class SVTK_CubeAxesDlg::AxisWidget
47   \brief Axis tab widget of the "Graduated axis" dialog box
48   \internal
49 */
50
51 /*!
52   Constructor
53 */
54 SVTK_AxisWidget::SVTK_AxisWidget (QWidget* theParent)
55 : ViewerTools_AxisWidgetBase(theParent)
56 {
57 }
58
59 /*!
60   Destructor
61 */
62 SVTK_AxisWidget::~SVTK_AxisWidget()
63 {
64 }
65
66 ViewerTools_FontWidgetBase* SVTK_AxisWidget::createFontWidget( QWidget* theParent )
67 {
68   SVTK_FontWidget* aFontWidget = new SVTK_FontWidget( theParent );
69   aFontWidget->Initialize();
70   return aFontWidget;
71 }
72
73 bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
74 {
75   if (theActor == 0)
76     return false;
77
78   // Name
79
80   bool useName = theActor->GetTitleVisibility();
81   QString aTitle(theActor->GetTitle());
82
83   QColor aTitleColor(255, 255, 255);
84   int aTitleFontFamily = VTK_ARIAL;
85   bool isTitleBold = false;
86   bool isTitleItalic = false;
87   bool isTitleShadow = false;
88
89   vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
90   if (aTitleProp !=0)
91   {
92     double c[ 3 ];
93     aTitleProp->GetColor(c);
94     aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
95     aTitleFontFamily = aTitleProp->GetFontFamily();
96     isTitleBold = aTitleProp->GetBold() ? true : false;
97     isTitleItalic = aTitleProp->GetItalic() ? true : false;
98     isTitleShadow = aTitleProp->GetShadow() ? true : false;
99   }
100
101   myNameGrp->setChecked(useName);
102   myAxisName->setText(aTitle);
103   myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
104
105   // Labels
106
107   bool useLabels = theActor->GetLabelVisibility();
108   int nbLabels = theActor->GetNumberOfLabels();
109   int anOffset = theActor->GetTickOffset();
110
111   QColor aLabelsColor(255, 255, 255);
112   int aLabelsFontFamily = VTK_ARIAL;
113   bool isLabelsBold = false;
114   bool isLabelsItalic = false;
115   bool isLabelsShadow = false;
116
117   vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
118   if (aLabelsProp !=0)
119   {
120     double c[ 3 ];
121     aLabelsProp->GetColor(c);
122     aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
123     aLabelsFontFamily = aLabelsProp->GetFontFamily();
124     isLabelsBold = aLabelsProp->GetBold() ? true : false;
125     isLabelsItalic = aLabelsProp->GetItalic() ? true : false;
126     isLabelsShadow = aLabelsProp->GetShadow() ? true : false;
127   }
128
129   myLabelsGrp->setChecked(useLabels);
130   myLabelNumber->setValue(nbLabels);
131   myLabelOffset->setValue(anOffset);
132   myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
133
134   // Tick marks
135   bool useTickMarks = theActor->GetTickVisibility();
136   int aTickLength = theActor->GetTickLength();
137
138   myTicksGrp->setChecked(useTickMarks);
139   myTickLength->setValue(aTickLength);
140
141   return true;
142 }
143
144 bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
145 {
146    if (theActor == 0)
147     return false;
148
149   // Name
150
151   theActor->SetTitleVisibility(myNameGrp->isChecked() ? 1 : 0);
152   theActor->SetTitle(myAxisName->text().toUtf8());
153
154   QColor aTitleColor(255, 255, 255);
155   int aTitleFontFamily = VTK_ARIAL;
156   bool isTitleBold = false;
157   bool isTitleItalic = false;
158   bool isTitleShadow = false;
159
160   myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
161   vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
162   if (aTitleProp)
163   {
164     aTitleProp->SetColor(aTitleColor.red() / 255.,
165                           aTitleColor.green() / 255.,
166                           aTitleColor.blue() / 255.);
167     aTitleProp->SetFontFamily(aTitleFontFamily);
168
169     aTitleProp->SetBold(isTitleBold ? 1 : 0);
170     aTitleProp->SetItalic(isTitleItalic ? 1 : 0);
171     aTitleProp->SetShadow(isTitleShadow ? 1 : 0);
172
173     theActor->SetTitleTextProperty(aTitleProp);
174   }
175
176   // Labels
177
178   theActor->SetLabelVisibility(myLabelsGrp->isChecked() ? 1 : 0);
179
180   int nbLabels = myLabelNumber->value();
181   theActor->SetNumberOfLabels(nbLabels);
182
183   int anOffset = myLabelOffset->value();
184   theActor->SetTickOffset(anOffset);
185
186   QColor aLabelsColor(255, 255, 255);
187   int aLabelsFontFamily = VTK_ARIAL;
188   bool isLabelsBold = false;
189   bool isLabelsItalic = false;
190   bool isLabelsShadow = false;
191
192   myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
193   vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
194   if (aLabelsProp)
195   {
196     aLabelsProp->SetColor(aLabelsColor.red() / 255.,
197                           aLabelsColor.green() / 255.,
198                           aLabelsColor.blue() / 255.);
199     aLabelsProp->SetFontFamily(aLabelsFontFamily);
200
201     aLabelsProp->SetBold(isLabelsBold ? 1 : 0);
202     aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0);
203     aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0);
204
205     aLabelsProp->Modified();
206     theActor->SetLabelTextProperty(aLabelsProp);
207   }
208
209
210   // Tick marks
211   theActor->SetTickVisibility(myTicksGrp->isChecked());
212   int aTickLength = myTickLength->value();
213   theActor->SetTickLength(aTickLength);
214
215   return true;
216 }
217
218 /*
219   Class       : SVTK_CubeAxesDlg
220   Description : Dialog for specifynig cube axes properties
221 */
222
223 /*!
224   Constructor
225 */
226 SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(QtxAction* theAction,
227                                    SVTK_ViewWindow* theParent,
228                                    const char* theName):
229   ViewerTools_CubeAxesDlgBase(theAction,
230                               theParent, 
231                               theName),
232   myMainWindow(theParent)
233 {
234 }
235
236 /*!
237   Destructor
238 */
239 SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
240 {
241 }
242
243 /*!
244   Create axis widget
245 */
246 ViewerTools_AxisWidgetBase* SVTK_CubeAxesDlg::createAxisWidget( QWidget* theParent )
247 {
248   SVTK_AxisWidget* anAxisWidget = new SVTK_AxisWidget( theParent );
249   anAxisWidget->initialize();
250   return anAxisWidget;
251 }
252
253 /*!
254   Update dialog fields, connect signals and slots, show dialog
255 */
256 void SVTK_CubeAxesDlg::Update()
257 {
258   ViewerTools_CubeAxesDlgBase::Update();
259
260   myActor = myMainWindow->GetCubeAxes();
261
262   ((SVTK_AxisWidget*)myAxes[ 0 ])->ReadData(myActor->GetXAxisActor2D());
263   ((SVTK_AxisWidget*)myAxes[ 1 ])->ReadData(myActor->GetYAxisActor2D());
264   ((SVTK_AxisWidget*)myAxes[ 2 ])->ReadData(myActor->GetZAxisActor2D());
265
266   myIsVisible->setChecked(myActor->GetVisibility() ? true : false);
267 }
268
269 /*!
270   Verify validity of entry data
271 */
272 bool SVTK_CubeAxesDlg::onApply()
273 {
274   bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
275
276   try
277   {
278     QWidget *aCurrWid = this->focusWidget();
279     aCurrWid->clearFocus();
280     aCurrWid->setFocus();
281
282     isOk = isOk && ((SVTK_AxisWidget*)myAxes[ 0 ])->Apply(myActor->GetXAxisActor2D());
283     isOk = isOk && ((SVTK_AxisWidget*)myAxes[ 1 ])->Apply(myActor->GetYAxisActor2D());
284     isOk = isOk && ((SVTK_AxisWidget*)myAxes[ 2 ])->Apply(myActor->GetZAxisActor2D());
285
286     //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text()); // to remove?
287     //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text()); // to remove?
288     //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text()); // to remove?
289
290     //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels()); // to remove?
291     if (myIsVisible->isChecked())
292       myActor->VisibilityOn();
293     else
294       myActor->VisibilityOff();
295
296     if (isOk)
297       myMainWindow->Repaint();
298   }
299   catch(...)
300   {
301     isOk = false;
302   }
303
304   return isOk;
305 }