1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU VISUGUI : GUI for SMESH component
24 // File : SVTK_CubeAxesDlg.cxx
25 // Author : Sergey LITONIN
28 #include "SVTK_CubeAxesDlg.h"
30 #include "SVTK_ViewWindow.h"
31 #include "SVTK_FontWidget.h"
33 #include "SVTK_CubeAxesActor2D.h"
35 #include "QtxAction.h"
36 #include "QtxIntSpinBox.h"
42 #include <vtkAxisActor2D.h>
43 #include <vtkTextProperty.h>
46 \class SVTK_CubeAxesDlg::AxisWidget
47 \brief Axis tab widget of the "Graduated axis" dialog box
54 SVTK_AxisWidget::SVTK_AxisWidget (QWidget* theParent)
55 : ViewerTools_AxisWidgetBase(theParent)
62 SVTK_AxisWidget::~SVTK_AxisWidget()
66 ViewerTools_FontWidgetBase* SVTK_AxisWidget::createFontWidget( QWidget* theParent )
68 SVTK_FontWidget* aFontWidget = new SVTK_FontWidget( theParent );
69 aFontWidget->Initialize();
73 bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
80 bool useName = theActor->GetTitleVisibility();
81 QString aTitle(theActor->GetTitle());
83 QColor aTitleColor(255, 255, 255);
84 int aTitleFontFamily = VTK_ARIAL;
85 bool isTitleBold = false;
86 bool isTitleItalic = false;
87 bool isTitleShadow = false;
89 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
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;
101 myNameGrp->setChecked(useName);
102 myAxisName->setText(aTitle);
103 myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
107 bool useLabels = theActor->GetLabelVisibility();
108 int nbLabels = theActor->GetNumberOfLabels();
109 int anOffset = theActor->GetTickOffset();
111 QColor aLabelsColor(255, 255, 255);
112 int aLabelsFontFamily = VTK_ARIAL;
113 bool isLabelsBold = false;
114 bool isLabelsItalic = false;
115 bool isLabelsShadow = false;
117 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
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;
129 myLabelsGrp->setChecked(useLabels);
130 myLabelNumber->setValue(nbLabels);
131 myLabelOffset->setValue(anOffset);
132 myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
135 bool useTickMarks = theActor->GetTickVisibility();
136 int aTickLength = theActor->GetTickLength();
138 myTicksGrp->setChecked(useTickMarks);
139 myTickLength->setValue(aTickLength);
144 bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
151 theActor->SetTitleVisibility(myNameGrp->isChecked() ? 1 : 0);
152 theActor->SetTitle(myAxisName->text().toLatin1());
154 QColor aTitleColor(255, 255, 255);
155 int aTitleFontFamily = VTK_ARIAL;
156 bool isTitleBold = false;
157 bool isTitleItalic = false;
158 bool isTitleShadow = false;
160 myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
161 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
164 aTitleProp->SetColor(aTitleColor.red() / 255.,
165 aTitleColor.green() / 255.,
166 aTitleColor.blue() / 255.);
167 aTitleProp->SetFontFamily(aTitleFontFamily);
169 aTitleProp->SetBold(isTitleBold ? 1 : 0);
170 aTitleProp->SetItalic(isTitleItalic ? 1 : 0);
171 aTitleProp->SetShadow(isTitleShadow ? 1 : 0);
173 theActor->SetTitleTextProperty(aTitleProp);
178 theActor->SetLabelVisibility(myLabelsGrp->isChecked() ? 1 : 0);
180 int nbLabels = myLabelNumber->value();
181 theActor->SetNumberOfLabels(nbLabels);
183 int anOffset = myLabelOffset->value();
184 theActor->SetTickOffset(anOffset);
186 QColor aLabelsColor(255, 255, 255);
187 int aLabelsFontFamily = VTK_ARIAL;
188 bool isLabelsBold = false;
189 bool isLabelsItalic = false;
190 bool isLabelsShadow = false;
192 myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
193 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
196 aLabelsProp->SetColor(aLabelsColor.red() / 255.,
197 aLabelsColor.green() / 255.,
198 aLabelsColor.blue() / 255.);
199 aLabelsProp->SetFontFamily(aLabelsFontFamily);
201 aLabelsProp->SetBold(isLabelsBold ? 1 : 0);
202 aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0);
203 aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0);
205 aLabelsProp->Modified();
206 theActor->SetLabelTextProperty(aLabelsProp);
211 theActor->SetTickVisibility(myTicksGrp->isChecked());
212 int aTickLength = myTickLength->value();
213 theActor->SetTickLength(aTickLength);
219 Class : SVTK_CubeAxesDlg
220 Description : Dialog for specifynig cube axes properties
226 SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(QtxAction* theAction,
227 SVTK_ViewWindow* theParent,
228 const char* theName):
229 ViewerTools_CubeAxesDlgBase(theAction,
232 myMainWindow(theParent)
239 SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
246 ViewerTools_AxisWidgetBase* SVTK_CubeAxesDlg::createAxisWidget( QWidget* theParent )
248 SVTK_AxisWidget* anAxisWidget = new SVTK_AxisWidget( theParent );
249 anAxisWidget->initialize();
254 Update dialog fields, connect signals and slots, show dialog
256 void SVTK_CubeAxesDlg::Update()
258 ViewerTools_CubeAxesDlgBase::Update();
260 myActor = myMainWindow->GetCubeAxes();
262 ((SVTK_AxisWidget*)myAxes[ 0 ])->ReadData(myActor->GetXAxisActor2D());
263 ((SVTK_AxisWidget*)myAxes[ 1 ])->ReadData(myActor->GetYAxisActor2D());
264 ((SVTK_AxisWidget*)myAxes[ 2 ])->ReadData(myActor->GetZAxisActor2D());
266 myIsVisible->setChecked(myActor->GetVisibility() ? true : false);
270 Verify validity of entry data
272 bool SVTK_CubeAxesDlg::onApply()
274 bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
278 QWidget *aCurrWid = this->focusWidget();
279 aCurrWid->clearFocus();
280 aCurrWid->setFocus();
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());
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?
290 //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels()); // to remove?
291 if (myIsVisible->isChecked())
292 myActor->VisibilityOn();
294 myActor->VisibilityOff();
297 myMainWindow->Repaint();