From 51aa36d50e6ee95c4c52fc9747b789e47d9dc710 Mon Sep 17 00:00:00 2001 From: asl Date: Sat, 21 Nov 2009 12:14:19 +0000 Subject: [PATCH] GUI wrapper for Notebook --- src/SalomeApp/Makefile.am | 6 +- src/SalomeApp/SalomeApp_Notebook.cxx | 162 +++++++++++++++++++++++++++ src/SalomeApp/SalomeApp_Notebook.h | 66 +++++++++++ 3 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 src/SalomeApp/SalomeApp_Notebook.cxx create mode 100644 src/SalomeApp/SalomeApp_Notebook.h diff --git a/src/SalomeApp/Makefile.am b/src/SalomeApp/Makefile.am index 614de706b..026d6a05c 100755 --- a/src/SalomeApp/Makefile.am +++ b/src/SalomeApp/Makefile.am @@ -54,7 +54,8 @@ salomeinclude_HEADERS = \ SalomeApp_ExitDlg.h \ SalomeApp_NoteBookDlg.h \ SalomeApp_DoubleSpinBox.h \ - SalomeApp_IntSpinBox.h + SalomeApp_IntSpinBox.h \ + SalomeApp_Notebook.h dist_libSalomeApp_la_SOURCES = \ SalomeApp_Module.cxx \ @@ -76,7 +77,8 @@ dist_libSalomeApp_la_SOURCES = \ SalomeApp_ExitDlg.cxx \ SalomeApp_NoteBookDlg.cxx \ SalomeApp_DoubleSpinBox.cxx \ - SalomeApp_IntSpinBox.cxx + SalomeApp_IntSpinBox.cxx \ + SalomeApp_Notebook.cxx MOC_FILES = \ SalomeApp_Application_moc.cxx \ diff --git a/src/SalomeApp/SalomeApp_Notebook.cxx b/src/SalomeApp/SalomeApp_Notebook.cxx new file mode 100644 index 000000000..44c73237c --- /dev/null +++ b/src/SalomeApp/SalomeApp_Notebook.cxx @@ -0,0 +1,162 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_Notebook.cxx +// Created: 11/21/2009 10:08:37 AM +// Author: Alexandre SOLOVYOV +// + +#include "SalomeApp_Notebook.h" +#include "SalomeApp_Study.h" +#include "SalomeApp_DoubleSpinBox.h" +#include "SalomeApp_IntSpinBox.h" +#include +#include +#include + +SalomeApp_Notebook::SalomeApp_Notebook( SalomeApp_Study* theStudy ) +{ + SALOME::Notebook_var aRes; + SALOMEDS_Study* aStudy = dynamic_cast( theStudy->studyDS().operator->() ); + if( aStudy ) + aRes = aStudy->GetStudy()->GetNotebook(); + myNotebook = aRes._retn(); +} + +SalomeApp_Notebook::~SalomeApp_Notebook() +{ +} + +void SalomeApp_Notebook::set( const QString& theName, const QVariant& theValue ) +{ + const char* aName = theName.toLatin1().constData(); + SALOME::Parameter_ptr aParam = myNotebook->GetParameter( aName ); + bool isNew = CORBA::is_nil( aParam ); + + switch( theValue.type() ) + { + case QVariant::Int: + case QVariant::UInt: + if( isNew ) + myNotebook->AddInteger( aName, theValue.toInt() ); + else + aParam->SetInteger( theValue.toInt() ); + break; + + case QVariant::Double: + if( isNew ) + myNotebook->AddReal( aName, theValue.toDouble() ); + else + aParam->SetReal( theValue.toDouble() ); + break; + + case QVariant::Bool: + if( isNew ) + myNotebook->AddBoolean( aName, theValue.toBool() ); + else + aParam->SetBoolean( theValue.toBool() ); + break; + + case QVariant::String: + { + const char* aData = theValue.toString().toLatin1().constData(); + if( isNew ) + myNotebook->AddNamedExpression( aName, aData ); + else + aParam->SetExpression( aData ); + break; + } + } +} + +QVariant SalomeApp_Notebook::get( const QString& theName ) const +{ + QVariant aRes; + SALOME::Parameter_ptr aParam = myNotebook->GetParameter( theName.toLatin1().constData() ); + if( !CORBA::is_nil( aParam ) ) + switch( aParam->GetType() ) + { + case SALOME::TBoolean: + aRes = aParam->AsBoolean(); + break; + case SALOME::TInteger: + aRes = (int)aParam->AsInteger(); + break; + case SALOME::TReal: + aRes = aParam->AsReal(); + break; + case SALOME::TString: + aRes = aParam->AsString(); + break; + } + return aRes; +} + +void SalomeApp_Notebook::update() +{ + myNotebook->Update(); +} + +QStringList SalomeApp_Notebook::convert( SALOME::StringArray* theList ) const +{ + QStringList aRes; + + int n = theList->length(); + for( int i = 0; i < n; i++ ) + aRes.append( CORBA::string_dup( theList->operator[]( i ) ) ); + + return aRes; +} + +QStringList SalomeApp_Notebook::parameters() const +{ + return convert( myNotebook->Parameters() ); +} + +QStringList SalomeApp_Notebook::absentParameters() const +{ + return convert( myNotebook->AbsentParameters() ); +} + +void SalomeApp_Notebook::setParameters( SALOME::ParameterizedObject_ptr theObject, int theCount, QAbstractSpinBox* theFirstSpin, ... ) +{ + SALOME::StringArray aParams; + aParams.length( theCount ); + QAbstractSpinBox** aSpin = &theFirstSpin; + for( int i=0; i( *aSpin ); + if( aDbl ) + { + continue; + } + + SalomeApp_IntSpinBox* anInt = dynamic_cast( *aSpin ); + if( anInt ) + { + continue; + } + + aParams[i] = CORBA::string_dup( "" ); + } + + theObject->SetParameters( myNotebook, aParams ); +} diff --git a/src/SalomeApp/SalomeApp_Notebook.h b/src/SalomeApp/SalomeApp_Notebook.h new file mode 100644 index 000000000..d5951280f --- /dev/null +++ b/src/SalomeApp/SalomeApp_Notebook.h @@ -0,0 +1,66 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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_Notebook.h +// Created: 11/21/2009 10:05:25 AM +// Author: Alexandre SOLOVYOV +// +#ifndef SALOMEAPP_NOTEBOOK_H +#define SALOMEAPP_NOTEBOOK_H + +#include "SalomeApp.h" +#include CORBA_CLIENT_HEADER( SALOME_Notebook ) + +class SalomeApp_Study; +class QString; +class QVariant; +class QStringList; +class QAbstractSpinBox; + +/*! + \class SalomeApp_Notebook + \brief Wrapper of notebook functionality for the GUI +*/ + +class SALOMEAPP_EXPORT SalomeApp_Notebook +{ +public: + SalomeApp_Notebook( SalomeApp_Study* theStudy ); + virtual ~SalomeApp_Notebook(); + + void set( const QString& theName, const QVariant& theValue ); + QVariant get( const QString& theName ) const; + + void update(); + + QStringList parameters() const; + QStringList absentParameters() const; + + void setParameters( SALOME::ParameterizedObject_ptr theObject, int theCount, QAbstractSpinBox* theFirstSpin, ... ); + +protected: + QStringList convert( SALOME::StringArray* theArray ) const; + +private: + SALOME::Notebook_ptr myNotebook; +}; + +#endif -- 2.39.2