Back to index

salome-gui  6.5.0
SVTK_CubeAxesDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  VISU VISUGUI : GUI for SMESH component
00024 //  File   : SVTK_CubeAxesDlg.cxx
00025 //  Author : Sergey LITONIN
00026 //  Module : VISU
00027 //
00028 #include "SVTK_CubeAxesDlg.h"
00029 
00030 #include "SVTK_ViewWindow.h"
00031 #include "SVTK_FontWidget.h"
00032 
00033 #include "SVTK_CubeAxesActor2D.h"
00034 
00035 #include "QtxAction.h"
00036 #include "QtxIntSpinBox.h"
00037 
00038 #include <QCheckBox>
00039 #include <QGroupBox>
00040 #include <QLineEdit>
00041 
00042 #include <vtkAxisActor2D.h>
00043 #include <vtkTextProperty.h>
00044 
00054 SVTK_AxisWidget::SVTK_AxisWidget (QWidget* theParent)
00055 : ViewerTools_AxisWidgetBase(theParent)
00056 {
00057 }
00058 
00062 SVTK_AxisWidget::~SVTK_AxisWidget()
00063 {
00064 }
00065 
00066 ViewerTools_FontWidgetBase* SVTK_AxisWidget::createFontWidget( QWidget* theParent )
00067 {
00068   SVTK_FontWidget* aFontWidget = new SVTK_FontWidget( theParent );
00069   aFontWidget->Initialize();
00070   return aFontWidget;
00071 }
00072 
00073 bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
00074 {
00075   if (theActor == 0)
00076     return false;
00077 
00078   // Name
00079 
00080   bool useName = theActor->GetTitleVisibility();
00081   QString aTitle(theActor->GetTitle());
00082 
00083   QColor aTitleColor(255, 255, 255);
00084   int aTitleFontFamily = VTK_ARIAL;
00085   bool isTitleBold = false;
00086   bool isTitleItalic = false;
00087   bool isTitleShadow = false;
00088 
00089   vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
00090   if (aTitleProp !=0)
00091   {
00092     vtkFloatingPointType c[ 3 ];
00093     aTitleProp->GetColor(c);
00094     aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
00095     aTitleFontFamily = aTitleProp->GetFontFamily();
00096     isTitleBold = aTitleProp->GetBold() ? true : false;
00097     isTitleItalic = aTitleProp->GetItalic() ? true : false;
00098     isTitleShadow = aTitleProp->GetShadow() ? true : false;
00099   }
00100 
00101   myNameGrp->setChecked(useName);
00102   myAxisName->setText(aTitle);
00103   myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
00104 
00105   // Labels
00106 
00107   bool useLabels = theActor->GetLabelVisibility();
00108   int nbLabels = theActor->GetNumberOfLabels();
00109   int anOffset = theActor->GetTickOffset();
00110 
00111   QColor aLabelsColor(255, 255, 255);
00112   int aLabelsFontFamily = VTK_ARIAL;
00113   bool isLabelsBold = false;
00114   bool isLabelsItalic = false;
00115   bool isLabelsShadow = false;
00116 
00117   vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
00118   if (aLabelsProp !=0)
00119   {
00120     vtkFloatingPointType c[ 3 ];
00121     aLabelsProp->GetColor(c);
00122     aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
00123     aLabelsFontFamily = aLabelsProp->GetFontFamily();
00124     isLabelsBold = aLabelsProp->GetBold() ? true : false;
00125     isLabelsItalic = aLabelsProp->GetItalic() ? true : false;
00126     isLabelsShadow = aLabelsProp->GetShadow() ? true : false;
00127   }
00128 
00129   myLabelsGrp->setChecked(useLabels);
00130   myLabelNumber->setValue(nbLabels);
00131   myLabelOffset->setValue(anOffset);
00132   myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
00133 
00134   // Tick marks
00135   bool useTickMarks = theActor->GetTickVisibility();
00136   int aTickLength = theActor->GetTickLength();
00137 
00138   myTicksGrp->setChecked(useTickMarks);
00139   myTickLength->setValue(aTickLength);
00140 
00141   return true;
00142 }
00143 
00144 bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
00145 {
00146    if (theActor == 0)
00147     return false;
00148 
00149   // Name
00150 
00151   theActor->SetTitleVisibility(myNameGrp->isChecked() ? 1 : 0);
00152   theActor->SetTitle(myAxisName->text().toLatin1());
00153 
00154   QColor aTitleColor(255, 255, 255);
00155   int aTitleFontFamily = VTK_ARIAL;
00156   bool isTitleBold = false;
00157   bool isTitleItalic = false;
00158   bool isTitleShadow = false;
00159 
00160   myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
00161   vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
00162   if (aTitleProp)
00163   {
00164     aTitleProp->SetColor(aTitleColor.red() / 255.,
00165                           aTitleColor.green() / 255.,
00166                           aTitleColor.blue() / 255.);
00167     aTitleProp->SetFontFamily(aTitleFontFamily);
00168 
00169     aTitleProp->SetBold(isTitleBold ? 1 : 0);
00170     aTitleProp->SetItalic(isTitleItalic ? 1 : 0);
00171     aTitleProp->SetShadow(isTitleShadow ? 1 : 0);
00172 
00173     theActor->SetTitleTextProperty(aTitleProp);
00174   }
00175 
00176   // Labels
00177 
00178   theActor->SetLabelVisibility(myLabelsGrp->isChecked() ? 1 : 0);
00179 
00180   int nbLabels = myLabelNumber->value();
00181   theActor->SetNumberOfLabels(nbLabels);
00182 
00183   int anOffset = myLabelOffset->value();
00184   theActor->SetTickOffset(anOffset);
00185 
00186   QColor aLabelsColor(255, 255, 255);
00187   int aLabelsFontFamily = VTK_ARIAL;
00188   bool isLabelsBold = false;
00189   bool isLabelsItalic = false;
00190   bool isLabelsShadow = false;
00191 
00192   myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
00193   vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
00194   if (aLabelsProp)
00195   {
00196     aLabelsProp->SetColor(aLabelsColor.red() / 255.,
00197                           aLabelsColor.green() / 255.,
00198                           aLabelsColor.blue() / 255.);
00199     aLabelsProp->SetFontFamily(aLabelsFontFamily);
00200 
00201     aLabelsProp->SetBold(isLabelsBold ? 1 : 0);
00202     aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0);
00203     aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0);
00204 
00205     aLabelsProp->Modified();
00206     theActor->SetLabelTextProperty(aLabelsProp);
00207   }
00208 
00209 
00210   // Tick marks
00211   theActor->SetTickVisibility(myTicksGrp->isChecked());
00212   int aTickLength = myTickLength->value();
00213   theActor->SetTickLength(aTickLength);
00214 
00215   return true;
00216 }
00217 
00218 /*
00219   Class       : SVTK_CubeAxesDlg
00220   Description : Dialog for specifynig cube axes properties
00221 */
00222 
00226 SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(QtxAction* theAction,
00227                                    SVTK_ViewWindow* theParent,
00228                                    const char* theName):
00229   ViewerTools_CubeAxesDlgBase(theAction,
00230                               theParent, 
00231                               theName),
00232   myMainWindow(theParent)
00233 {
00234 }
00235 
00239 SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
00240 {
00241 }
00242 
00246 ViewerTools_AxisWidgetBase* SVTK_CubeAxesDlg::createAxisWidget( QWidget* theParent )
00247 {
00248   SVTK_AxisWidget* anAxisWidget = new SVTK_AxisWidget( theParent );
00249   anAxisWidget->initialize();
00250   return anAxisWidget;
00251 }
00252 
00256 void SVTK_CubeAxesDlg::Update()
00257 {
00258   ViewerTools_CubeAxesDlgBase::Update();
00259 
00260   myActor = myMainWindow->GetCubeAxes();
00261 
00262   ((SVTK_AxisWidget*)myAxes[ 0 ])->ReadData(myActor->GetXAxisActor2D());
00263   ((SVTK_AxisWidget*)myAxes[ 1 ])->ReadData(myActor->GetYAxisActor2D());
00264   ((SVTK_AxisWidget*)myAxes[ 2 ])->ReadData(myActor->GetZAxisActor2D());
00265 
00266   myIsVisible->setChecked(myActor->GetVisibility() ? true : false);
00267 }
00268 
00272 bool SVTK_CubeAxesDlg::onApply()
00273 {
00274   bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
00275 
00276   try
00277   {
00278     QWidget *aCurrWid = this->focusWidget();
00279     aCurrWid->clearFocus();
00280     aCurrWid->setFocus();
00281 
00282     isOk = isOk && ((SVTK_AxisWidget*)myAxes[ 0 ])->Apply(myActor->GetXAxisActor2D());
00283     isOk = isOk && ((SVTK_AxisWidget*)myAxes[ 1 ])->Apply(myActor->GetYAxisActor2D());
00284     isOk = isOk && ((SVTK_AxisWidget*)myAxes[ 2 ])->Apply(myActor->GetZAxisActor2D());
00285 
00286     //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text()); // to remove?
00287     //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text()); // to remove?
00288     //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text()); // to remove?
00289 
00290     //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels()); // to remove?
00291     if (myIsVisible->isChecked())
00292       myActor->VisibilityOn();
00293     else
00294       myActor->VisibilityOff();
00295 
00296     if (isOk)
00297       myMainWindow->Repaint();
00298   }
00299   catch(...)
00300   {
00301     isOk = false;
00302   }
00303 
00304   return isOk;
00305 }