From 00f8636774cd363ab376526a60cf786c29ea5510 Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 31 Oct 2008 13:36:35 +0000 Subject: [PATCH] Dump Python Extension --- src/SalomeApp/Makefile.am | 12 +- src/SalomeApp/SalomeApp_DataObject.cxx | 8 +- src/SalomeApp/SalomeApp_DoubleSpinBox.cxx | 193 ++++++++++++++++++++++ src/SalomeApp/SalomeApp_DoubleSpinBox.h | 57 +++++++ src/SalomeApp/SalomeApp_IntSpinBox.cxx | 175 ++++++++++++++++++++ src/SalomeApp/SalomeApp_IntSpinBox.h | 56 +++++++ 6 files changed, 497 insertions(+), 4 deletions(-) create mode 100644 src/SalomeApp/SalomeApp_DoubleSpinBox.cxx create mode 100644 src/SalomeApp/SalomeApp_DoubleSpinBox.h create mode 100644 src/SalomeApp/SalomeApp_IntSpinBox.cxx create mode 100644 src/SalomeApp/SalomeApp_IntSpinBox.h diff --git a/src/SalomeApp/Makefile.am b/src/SalomeApp/Makefile.am index 1efa60f51..dd2af858f 100755 --- a/src/SalomeApp/Makefile.am +++ b/src/SalomeApp/Makefile.am @@ -50,7 +50,9 @@ salomeinclude_HEADERS = \ SalomeApp_CheckFileDlg.h \ SalomeApp_VisualState.h \ SalomeApp_ExitDlg.h \ - SalomeApp_NoteBookDlg.h + SalomeApp_NoteBookDlg.h \ + SalomeApp_DoubleSpinBox.h \ + SalomeApp_IntSpinBox.h dist_libSalomeApp_la_SOURCES = \ SalomeApp_Module.cxx \ @@ -71,7 +73,9 @@ dist_libSalomeApp_la_SOURCES = \ SalomeApp_CheckFileDlg.cxx \ SalomeApp_VisualState.cxx \ SalomeApp_ExitDlg.cxx \ - SalomeApp_NoteBookDlg.cxx + SalomeApp_NoteBookDlg.cxx \ + SalomeApp_DoubleSpinBox.cxx \ + SalomeApp_IntSpinBox.cxx MOC_FILES = \ SalomeApp_Application_moc.cxx \ @@ -83,7 +87,9 @@ MOC_FILES = \ SalomeApp_ListView_moc.cxx \ SalomeApp_CheckFileDlg_moc.cxx \ SalomeApp_ExitDlg_moc.cxx \ - SalomeApp_NoteBookDlg_moc.cxx + SalomeApp_NoteBookDlg_moc.cxx \ + SalomeApp_DoubleSpinBox_moc.cxx \ + SalomeApp_IntSpinBox_moc.cxx nodist_libSalomeApp_la_SOURCES = $(MOC_FILES) diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index 4ba451631..c78e28520 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -441,7 +441,13 @@ QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const QString val; _PTR(GenericAttribute) attr; - if ( obj->FindAttribute( attr, "AttributeInteger" ) ) + if ( obj->FindAttribute( attr, "AttributeString" ) ) + { + _PTR(AttributeString) strAttr = attr; + std::string str = strAttr->Value(); + val = QString( str.c_str() ); + } + else if ( obj->FindAttribute( attr, "AttributeInteger" ) ) { _PTR(AttributeInteger) intAttr = attr; if ( intAttr ) diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx new file mode 100644 index 000000000..6d5360156 --- /dev/null +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx @@ -0,0 +1,193 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: SalomeApp_DoubleSpinBox.cxx +// Author: Oleg UVAROV + +#include "SalomeApp_DoubleSpinBox.h" +#include "SalomeApp_Application.h" +#include "SalomeApp_Study.h" + +#include + +#include "SALOMEDSClient_ClientFactory.hxx" +#include CORBA_SERVER_HEADER(SALOMEDS) + +/*! + \class SalomeApp_DoubleSpinBox +*/ + +/*! + \brief Constructor. + + Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value, + a step value of 1.0 and a precision of 2 decimal places. + The value is initially set to 0.00. + + \param parent parent object +*/ +SalomeApp_DoubleSpinBox::SalomeApp_DoubleSpinBox( QWidget* parent ) +: QtxDoubleSpinBox( parent ) +{ +} + +/*! + \brief Constructor. + + Constructs a spin box with specified minimum, maximum and step value. + The precision is set to 2 decimal places. + The value is initially set to the minimum value. + + \param min spin box minimum possible value + \param max spin box maximum possible value + \param step spin box increment/decrement value + \param parent parent object +*/ +SalomeApp_DoubleSpinBox::SalomeApp_DoubleSpinBox( double min, double max, double step, QWidget* parent ) +: QtxDoubleSpinBox( min, max, step, parent ) +{ +} + +/*! + \brief Constructor. + + Constructs a spin box with specified minimum, maximum and step value. + The precision is set to 2 decimal places. + The value is initially set to the minimum value. + + \param min spin box minimum possible value + \param max spin box maximum possible value + \param step spin box increment/decrement value + \param parent parent object +*/ +SalomeApp_DoubleSpinBox::SalomeApp_DoubleSpinBox( double min, double max, double step, int prec, int dec, QWidget* parent ) +: QtxDoubleSpinBox( min, max, step, prec, dec, parent ) +{ +} + +/*! + \brief Destructor. +*/ +SalomeApp_DoubleSpinBox::~SalomeApp_DoubleSpinBox() +{ +} + +/*! + \brief Interpret text entered by the user as a value. + \param text text entered by the user + \return mapped value + \sa textFromValue() +*/ +double SalomeApp_DoubleSpinBox::valueFromText( const QString& text ) const +{ + QString str = text; + + double value = 0; + if( findVariable( str, value ) ) + str = QString::number( value ); + + int pos = 0; + if( QtxDoubleSpinBox::validate( str, pos ) == QValidator::Acceptable ) + value = QtxDoubleSpinBox::valueFromText( str ); + else + value = defaultValue(); + + return value; +} + +/*! + \brief This function is used by the spin box whenever it needs to display + the given value. + + \param val spin box value + \return text representation of the value + \sa valueFromText() +*/ +QString SalomeApp_DoubleSpinBox::textFromValue( double val ) const +{ + return QtxDoubleSpinBox::textFromValue( val ); +} + +/*! + \brief This function is used to determine whether input is valid. + \param str currently entered value + \param pos cursor position in the string + \return validating operation result +*/ +QValidator::State SalomeApp_DoubleSpinBox::validate( QString& str, int& pos ) const +{ + return QValidator::Acceptable; +} + +/*! + \brief This function is used to determine whether input is valid. + \return validating operation result +*/ +bool SalomeApp_DoubleSpinBox::isValid() const +{ + QString str = text(); + + double value = 0; + if( findVariable( str, value ) ) + str = QString::number( value ); + + int pos = 0; + return QtxDoubleSpinBox::validate( str, pos ) == QValidator::Acceptable; +} + +/*! + \brief This function return a default acceptable value (commonly, 0.0). + \return default acceptable value +*/ +double SalomeApp_DoubleSpinBox::defaultValue() const +{ + if( minimum() > 0 || maximum() < 0 ) + return minimum(); + + return 0.0; +} + +/*! + \brief This function is used to determine whether input is a variable name and to get its value. + \return true if the input is a variable name +*/ +bool SalomeApp_DoubleSpinBox::findVariable( const QString& name, double& value ) const +{ + if( SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ) ) + { + if( SalomeApp_Study* study = dynamic_cast( app->activeStudy() ) ) + { + _PTR(Study) studyDS = study->studyDS(); + std::vector aVariableNames = studyDS->GetVariableNames(); + for( unsigned int i = 0, n = aVariableNames.size(); i < n; i++ ) + { + std::string aName = aVariableNames[ i ]; + if( studyDS->IsReal( aName ) || studyDS->IsInteger( aName ) ) + { + double aValue = studyDS->GetReal( aName ); + if( aName == name.toStdString() ) + { + value = aValue; + return true; + } + } + } + } + } + return false; +} diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.h b/src/SalomeApp/SalomeApp_DoubleSpinBox.h new file mode 100644 index 000000000..254370631 --- /dev/null +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.h @@ -0,0 +1,57 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: SalomeApp_DoubleSpinBox.h +// Author: Oleg UVAROV + +#ifndef SALOMEAPP_DOUBLESPINBOX_H +#define SALOMEAPP_DOUBLESPINBOX_H + +#include "SalomeApp.h" + +#include + +#include + +class SALOMEAPP_EXPORT SalomeApp_DoubleSpinBox : public QtxDoubleSpinBox +{ + Q_OBJECT + +public: + SalomeApp_DoubleSpinBox( QWidget* = 0 ); + SalomeApp_DoubleSpinBox( double, double, double = 1, QWidget* = 0 ); + SalomeApp_DoubleSpinBox( double, double, double, int, int, QWidget* = 0 ); + virtual ~SalomeApp_DoubleSpinBox(); + + virtual double valueFromText( const QString& ) const; + virtual QString textFromValue( double ) const; + + virtual QValidator::State validate( QString&, int& ) const; + + bool isValid() const; + +protected: + double defaultValue() const; + bool findVariable( const QString&, double& ) const; + +private slots: + +private: +}; + +#endif diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.cxx b/src/SalomeApp/SalomeApp_IntSpinBox.cxx new file mode 100644 index 000000000..f9614ef45 --- /dev/null +++ b/src/SalomeApp/SalomeApp_IntSpinBox.cxx @@ -0,0 +1,175 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: SalomeApp_IntSpinBox.cxx +// Author: Oleg UVAROV + +#include "SalomeApp_IntSpinBox.h" +#include "SalomeApp_Application.h" +#include "SalomeApp_Study.h" + +#include + +#include "SALOMEDSClient_ClientFactory.hxx" +#include CORBA_SERVER_HEADER(SALOMEDS) + +/*! + \class SalomeApp_IntSpinBox +*/ + +/*! + \brief Constructor. + + Constructs a spin box with 0 as minimum value and 99 as maximum value, + a step value of 1. The value is initially set to 0. + + \param parent parent object +*/ +SalomeApp_IntSpinBox::SalomeApp_IntSpinBox( QWidget* parent ) +: QtxIntSpinBox( parent ) +{ +} + +/*! + \brief Constructor. + + Constructs a spin box with specified minimum, maximum and step value. + The value is initially set to the minimum value. + + \param min spin box minimum possible value + \param max spin box maximum possible value + \param step spin box increment/decrement value + \param parent parent object +*/ +SalomeApp_IntSpinBox::SalomeApp_IntSpinBox( int min, int max, int step, QWidget* parent ) +: QtxIntSpinBox( min, max, step, parent ) +{ +} + +/*! + \brief Destructor. +*/ +SalomeApp_IntSpinBox::~SalomeApp_IntSpinBox() +{ +} + +/*! + \brief Interpret text entered by the user as a value. + \param text text entered by the user + \return mapped value + \sa textFromValue() +*/ +int SalomeApp_IntSpinBox::valueFromText( const QString& text ) const +{ + QString str = text; + + int value = 0; + if( findVariable( str, value ) ) + str = QString::number( value ); + + int pos = 0; + if( QtxIntSpinBox::validate( str, pos ) == QValidator::Acceptable ) + value = QtxIntSpinBox::valueFromText( str ); + else + value = defaultValue(); + + return value; +} + +/*! + \brief This function is used by the spin box whenever it needs to display + the given value. + + \param val spin box value + \return text representation of the value + \sa valueFromText() +*/ +QString SalomeApp_IntSpinBox::textFromValue( int val ) const +{ + return QtxIntSpinBox::textFromValue( val ); +} + +/*! + \brief This function is used to determine whether input is valid. + \param str currently entered value + \param pos cursor position in the string + \return validating operation result +*/ +QValidator::State SalomeApp_IntSpinBox::validate( QString& str, int& pos ) const +{ + return QValidator::Acceptable; +} + +/*! + \brief This function is used to determine whether input is valid. + \return validating operation result +*/ +bool SalomeApp_IntSpinBox::isValid() const +{ + QString str = text(); + + int value = 0; + if( findVariable( str, value ) ) + str = QString::number( value ); + + int pos = 0; + return QtxIntSpinBox::validate( str, pos ) == QValidator::Acceptable; +} + +/*! + \brief This function return a default acceptable value (commonly, 0). + \return default acceptable value +*/ +int SalomeApp_IntSpinBox::defaultValue() const +{ + if( minimum() > 0 || maximum() < 0 ) + return minimum(); + + return 0; +} + +/*! + \brief This function is used to determine whether input is a variable name and to get its value. + \return true if the input is a variable name +*/ +bool SalomeApp_IntSpinBox::findVariable( const QString& name, int& value ) const +{ + if( SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ) ) + { + if( SalomeApp_Study* study = dynamic_cast( app->activeStudy() ) ) + { + _PTR(Study) studyDS = study->studyDS(); + std::vector aVariableNames = studyDS->GetVariableNames(); + for( unsigned int i = 0, n = aVariableNames.size(); i < n; i++ ) + { + std::string aName = aVariableNames[ i ]; + if( studyDS->IsInteger( aName ) ) + { + int aValue = studyDS->GetInteger( aName ); + + if( aName == name.toStdString() ) + { + value = aValue; + return true; + } + } + } + } + } + return false; +} diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.h b/src/SalomeApp/SalomeApp_IntSpinBox.h new file mode 100644 index 000000000..5c88a6e69 --- /dev/null +++ b/src/SalomeApp/SalomeApp_IntSpinBox.h @@ -0,0 +1,56 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: SalomeApp_IntSpinBox.h +// Author: Oleg UVAROV + +#ifndef SALOMEAPP_INTSPINBOX_H +#define SALOMEAPP_INTSPINBOX_H + +#include "SalomeApp.h" + +#include + +#include + +class SALOMEAPP_EXPORT SalomeApp_IntSpinBox : public QtxIntSpinBox +{ + Q_OBJECT + +public: + SalomeApp_IntSpinBox( QWidget* = 0 ); + SalomeApp_IntSpinBox( int, int, int = 1, QWidget* = 0 ); + virtual ~SalomeApp_IntSpinBox(); + + virtual int valueFromText( const QString& ) const; + virtual QString textFromValue( int ) const; + + virtual QValidator::State validate( QString&, int& ) const; + + bool isValid() const; + +protected: + int defaultValue() const; + bool findVariable( const QString&, int& ) const; + +private slots: + +private: +}; + +#endif -- 2.39.2