1 // Copyright (C) 2007-2008 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.
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
22 // File : SALOME_Parameter.cxx
23 // Author : Alexandre SOLOVYOV
27 #include <SALOME_Parameter.hxx>
28 #include <SALOME_Notebook.hxx>
29 #include <Utils_SALOME_Exception.hxx>
30 #include <utilities.h>
33 SALOME_Parameter::SALOME_Parameter( SALOME_Notebook* theNotebook, const std::string& theName, double theValue )
34 : myNotebook( theNotebook ), myName( theName ), myResult( theValue ), myIsAnonimous( false ), myIsCalculable( false )
38 SALOME_Parameter::SALOME_Parameter( SALOME_Notebook* theNotebook, const std::string& theName, const std::string& theExpr )
39 : myNotebook( theNotebook ), myName( theName ), myExpr( theExpr ), myIsAnonimous( false ), myIsCalculable( true )
44 SALOME_Parameter::SALOME_Parameter( SALOME_Notebook* theNotebook, const std::string& theExpr )
45 : myNotebook( theNotebook ), myName( theExpr ), myExpr( theExpr ), myIsAnonimous( true ), myIsCalculable( true )
50 SALOME_Parameter::~SALOME_Parameter()
54 char* SALOME_Parameter::GetEntry()
56 return CORBA::string_dup( myName.c_str() );
59 char* SALOME_Parameter::GetComponent()
61 return CORBA::string_dup( PARAM_COMPONENT.c_str() );
64 CORBA::Boolean SALOME_Parameter::IsValid()
66 return myResult.isValid();
69 void SALOME_Parameter::Update()
71 //printf( "Update of %s\n", GetEntry() );
74 //1. Set parameters values
75 SALOME_StringList deps = myExpr.parser()->parameters();
76 SALOME_StringList::const_iterator it = deps.begin(), last = deps.end();
77 for( ; it!=last; it++ )
79 std::string aName = *it;
80 SALOME_Parameter* aParam = myNotebook->ParamPtr( const_cast<char*>( aName.c_str() ) );
83 //printf( "\tset %s = %lf\n", aName.c_str(), aParam->AsReal() );
84 myExpr.parser()->setParameter( aName, aParam->myResult );
88 myResult = SALOME_EvalVariant();
94 myResult = myExpr.calculate();
95 //printf( "\tresult = %lf\n", AsReal() );
99 void SALOME_Parameter::SetExpr( const char* theExpr )
102 myNotebook->AddExpr( theExpr );
106 myExpr.setExpression( theExpr );
107 myIsCalculable = true;
109 myNotebook->SetToUpdate( _this() );
113 void SALOME_Parameter::SetReal( CORBA::Double theValue )
121 myIsCalculable = false;
123 myNotebook->SetToUpdate( _this() );
127 SALOME::ParamType SALOME_Parameter::GetType()
129 switch( myResult.type() )
131 case SALOME_EvalVariant_Boolean:
132 return SALOME::TBoolean;
134 case SALOME_EvalVariant_Int:
135 case SALOME_EvalVariant_UInt:
136 return SALOME::TInteger;
138 case SALOME_EvalVariant_Double:
139 return SALOME::TReal;
141 case SALOME_EvalVariant_String:
142 return SALOME::TString;
145 return SALOME::TUnknown;
149 char* SALOME_Parameter::AsString()
151 return CORBA::string_dup( myResult.toString().c_str() );
154 CORBA::Long SALOME_Parameter::AsInteger()
157 return myResult.toInt( &ok );
160 CORBA::Double SALOME_Parameter::AsReal()
163 return myResult.toDouble( &ok );
166 CORBA::Boolean SALOME_Parameter::AsBoolean()
168 return myResult.toBool();
171 SALOME_StringList SALOME_Parameter::Dependencies() const
173 return myIsCalculable ? myExpr.parser()->parameters() : SALOME_StringList();