Back to index

salome-gui  6.5.0
OCCViewer_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 #include "OCCViewer_CubeAxesDlg.h"
00024 
00025 #include "OCCViewer_FontWidget.h"
00026 #include "OCCViewer_ViewPort3d.h"
00027 #include "OCCViewer_ViewWindow.h"
00028 
00029 #include "QtxAction.h"
00030 #include "QtxIntSpinBox.h"
00031 
00032 #include <Basics_OCCTVersion.hxx>
00033 
00034 #include <QCheckBox>
00035 #include <QGroupBox>
00036 #include <QLineEdit>
00037 
00047 OCCViewer_AxisWidget::OCCViewer_AxisWidget (QWidget* theParent)
00048 : ViewerTools_AxisWidgetBase(theParent)
00049 {
00050 }
00051 
00055 OCCViewer_AxisWidget::~OCCViewer_AxisWidget()
00056 {
00057 }
00058 
00062 ViewerTools_FontWidgetBase* OCCViewer_AxisWidget::createFontWidget( QWidget* theParent )
00063 {
00064   OCCViewer_FontWidget* aFontWidget = new OCCViewer_FontWidget( theParent );
00065   aFontWidget->Initialize();
00066   return aFontWidget;
00067 }
00068 
00072 void OCCViewer_AxisWidget::SetData( const AxisData& theAxisData )
00073 {
00074   myNameGrp->setChecked( theAxisData.DrawName );
00075   myAxisName->setText( theAxisData.Name );
00076   myNameFont->SetData( theAxisData.NameColor, 0, false, false, false );
00077 
00078   myLabelsGrp->setChecked( theAxisData.DrawValues );
00079   myLabelNumber->setValue( theAxisData.NbValues );
00080   myLabelOffset->setValue( theAxisData.Offset );
00081   myLabelsFont->SetData( theAxisData.Color, 0, false, false, false );
00082 
00083   myTicksGrp->setChecked( theAxisData.DrawTickmarks );
00084   myTickLength->setValue( theAxisData.TickmarkLength );
00085 }
00086 
00090 void OCCViewer_AxisWidget::GetData( AxisData& theAxisData )
00091 {
00092   theAxisData.DrawName = myNameGrp->isChecked();
00093   theAxisData.Name = myAxisName->text();
00094 
00095   int aNameFamily;
00096   bool aNameBold, aNameItalic, aNameShadow;
00097   myNameFont->GetData( theAxisData.NameColor, aNameFamily, aNameBold, aNameItalic, aNameShadow );
00098 
00099   theAxisData.DrawValues = myLabelsGrp->isChecked();
00100   theAxisData.NbValues = myLabelNumber->value();
00101   theAxisData.Offset = myLabelOffset->value();
00102 
00103   int aLabelFamily;
00104   bool aLabelBold, aLabelItalic, aLabelShadow;
00105   myLabelsFont->GetData( theAxisData.Color, aLabelFamily, aLabelBold, aLabelItalic, aLabelShadow );
00106 
00107   theAxisData.DrawTickmarks = myTicksGrp->isChecked();
00108   theAxisData.TickmarkLength = myTickLength->value();
00109 }
00110 
00111 /*
00112   Class       : OCCViewer_CubeAxesDlg
00113   Description : Dialog for specifying cube axes properties
00114 */
00115 
00119 OCCViewer_CubeAxesDlg::OCCViewer_CubeAxesDlg(QtxAction* theAction,
00120                                              OCCViewer_ViewWindow* theParent,
00121                                              const char* theName):
00122   ViewerTools_CubeAxesDlgBase(theAction,
00123                               theParent, 
00124                               theName),
00125   myMainWindow(theParent)
00126 {
00127 }
00128 
00132 OCCViewer_CubeAxesDlg::~OCCViewer_CubeAxesDlg()
00133 {
00134 }
00135 
00139 ViewerTools_AxisWidgetBase* OCCViewer_CubeAxesDlg::createAxisWidget( QWidget* theParent )
00140 {
00141   OCCViewer_AxisWidget* anAxisWidget = new OCCViewer_AxisWidget( theParent );
00142   anAxisWidget->initialize();
00143   return anAxisWidget;
00144 }
00145 
00149 void OCCViewer_CubeAxesDlg::initialize()
00150 {
00151   ViewerTools_CubeAxesDlgBase::initialize();
00152 
00153   for( int i = 0; i < 3; i++ )
00154   {
00155     if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
00156     {
00157       OCCViewer_AxisWidget::AxisData anAxisData;
00158       switch( i )
00159       {
00160         case 0:
00161           anAxisData.Name = "X";
00162           anAxisData.NameColor = anAxisData.Color = Qt::red;
00163           break;
00164         case 1:
00165           anAxisData.Name = "Y";
00166           anAxisData.NameColor = anAxisData.Color = Qt::green;
00167           break;
00168         case 2:
00169           anAxisData.Name = "Z";
00170           anAxisData.NameColor = anAxisData.Color = Qt::blue;
00171           break;
00172       }
00173       anAxisData.DrawName       = true;
00174       anAxisData.DrawValues     = true;
00175       anAxisData.NbValues       = 3;
00176       anAxisData.Offset         = 2;
00177       anAxisData.DrawTickmarks  = true;
00178       anAxisData.TickmarkLength = 5;
00179       anAxisWidget->SetData( anAxisData );
00180     }
00181   }
00182 }
00183 
00187 void OCCViewer_CubeAxesDlg::Update()
00188 {
00189   ViewerTools_CubeAxesDlgBase::Update();
00190 }
00191 
00195 bool OCCViewer_CubeAxesDlg::onApply()
00196 {
00197   bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
00198 
00199   try
00200   {
00201     QWidget *aCurrWid = this->focusWidget();
00202     aCurrWid->clearFocus();
00203     aCurrWid->setFocus();
00204 
00205     if( OCCViewer_ViewPort3d* aViewPort = myMainWindow->getViewPort() )
00206     {
00207       Handle(V3d_View) aView = aViewPort->getView();
00208       if( !aView.IsNull() )
00209         ApplyData( aView );
00210     }
00211   }
00212   catch(...)
00213   {
00214     isOk = false;
00215   }
00216 
00217   return isOk;
00218 }
00219 
00223 void OCCViewer_CubeAxesDlg::GetData( bool& theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
00224 {
00225   theIsVisible = myIsVisible->isChecked();
00226   for( int i = 0; i < 3; i++ )
00227     if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
00228       anAxisWidget->GetData( theAxisData[i] );
00229 }
00230 
00234 void OCCViewer_CubeAxesDlg::SetData( bool theIsVisible, OCCViewer_AxisWidget::AxisData theAxisData[3] )
00235 {
00236   myIsVisible->setChecked( theIsVisible );
00237   for( int i = 0; i < 3; i++ )
00238     if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
00239       anAxisWidget->SetData( theAxisData[i] );
00240 }
00241 
00245 void OCCViewer_CubeAxesDlg::ApplyData( const Handle(V3d_View)& theView )
00246 {
00247 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
00248   if( theView.IsNull() )
00249     return;
00250 
00251   if( myIsVisible->isChecked() )
00252   {
00253     OCCViewer_AxisWidget::AxisData anAxisData[3];
00254     for( int i = 0; i < 3; i++ )
00255       if( OCCViewer_AxisWidget* anAxisWidget = dynamic_cast<OCCViewer_AxisWidget*>( myAxes[ i ] ) )
00256         anAxisWidget->GetData( anAxisData[i] );
00257 
00258     // A gap used offset of axis names' offset
00259     // (this hard-coded value will be removed when the
00260     // font support will be introduced in OCC-6.4)
00261     int aGap = 20;
00262 
00263     theView->GraduatedTrihedronDisplay(
00264       anAxisData[0].Name.toLatin1().constData(),
00265       anAxisData[1].Name.toLatin1().constData(),
00266       anAxisData[2].Name.toLatin1().constData(),
00267       anAxisData[0].DrawName,
00268       anAxisData[1].DrawName,
00269       anAxisData[2].DrawName,
00270       anAxisData[0].DrawValues,
00271       anAxisData[1].DrawValues,
00272       anAxisData[2].DrawValues,
00273       Standard_True, // draw grid
00274       Standard_False, // draw axes
00275       anAxisData[0].NbValues - 1,
00276       anAxisData[1].NbValues - 1,
00277       anAxisData[2].NbValues - 1,
00278       anAxisData[0].Offset,
00279       anAxisData[1].Offset,
00280       anAxisData[2].Offset,
00281       anAxisData[0].Offset + aGap, // see above
00282       anAxisData[1].Offset + aGap, // see above
00283       anAxisData[2].Offset + aGap, // see above
00284       anAxisData[0].DrawTickmarks,
00285       anAxisData[1].DrawTickmarks,
00286       anAxisData[2].DrawTickmarks,
00287       anAxisData[0].TickmarkLength,
00288       anAxisData[1].TickmarkLength,
00289       anAxisData[2].TickmarkLength,
00290       Quantity_NOC_WHITE, // grid color
00291       Quantity_Color( anAxisData[0].NameColor.redF(),
00292                       anAxisData[0].NameColor.greenF(),
00293                       anAxisData[0].NameColor.blueF(),
00294                       Quantity_TOC_RGB ),
00295       Quantity_Color( anAxisData[1].NameColor.redF(),
00296                       anAxisData[1].NameColor.greenF(),
00297                       anAxisData[1].NameColor.blueF(),
00298                       Quantity_TOC_RGB ),
00299       Quantity_Color( anAxisData[2].NameColor.redF(),
00300                       anAxisData[2].NameColor.greenF(),
00301                       anAxisData[2].NameColor.blueF(),
00302                       Quantity_TOC_RGB ),
00303       Quantity_Color( anAxisData[0].Color.redF(),
00304                       anAxisData[0].Color.greenF(),
00305                       anAxisData[0].Color.blueF(),
00306                       Quantity_TOC_RGB ),
00307       Quantity_Color( anAxisData[1].Color.redF(),
00308                       anAxisData[1].Color.greenF(),
00309                       anAxisData[1].Color.blueF(),
00310                       Quantity_TOC_RGB ),
00311       Quantity_Color( anAxisData[2].Color.redF(),
00312                       anAxisData[2].Color.greenF(),
00313                       anAxisData[2].Color.blueF(),
00314                       Quantity_TOC_RGB ) );
00315   }
00316   else
00317     theView->GraduatedTrihedronErase();
00318 
00319   theView->Redraw();
00320 #endif
00321 }