From: asl Date: Fri, 20 Nov 2009 08:11:39 +0000 (+0000) Subject: Implementation of update GEOM objects as Parameterized X-Git-Tag: PHASE_17_Part1_V1~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f5bc551fbdede825f5dc74d3407cda951a612ebe;p=modules%2Fgeom.git Implementation of update GEOM objects as Parameterized --- diff --git a/src/GEOM_I/GEOM_Object_i.cc b/src/GEOM_I/GEOM_Object_i.cc index f164b4ef4..44ac7db00 100644 --- a/src/GEOM_I/GEOM_Object_i.cc +++ b/src/GEOM_I/GEOM_Object_i.cc @@ -23,6 +23,7 @@ #include #include +#include #include #include "utilities.h" @@ -35,6 +36,7 @@ #include #include #include +#include #include #include @@ -427,13 +429,81 @@ bool GEOM_Object_i::IsShape() return !_impl->GetValue().IsNull() && _impl->GetType() != GEOM_MARKER; } -void GEOM_Object_i::SetParameters(const char* theParameters) +void GEOM_Object_i::SetParameters( SALOME::Notebook_ptr theNotebook, const GEOM::string_array& theParameters ) { - _impl->SetParameters((char*)theParameters); + printf( "set parameters\n" ); + int n = theParameters.length(); + if ( n <= 0 ) + return; + + theNotebook->ClearDependencies( _this() ); + + Handle( GEOM_Function ) aFunc = _impl->GetLastFunction(); + TColStd_Array1OfAsciiString aParams( 1, n ); + char* aStr; + for( int i = 0; i < n; i++ ) + { + aStr = CORBA::string_dup( theParameters[i] ); + printf( "\tparam = %s\n", aStr ); + SALOME::Parameter_ptr aParam = theNotebook->Param( aStr ); + TCollection_AsciiString anAsciiName; + if( !CORBA::is_nil( aParam ) ) + { + printf( "add dep\n" ); + theNotebook->AddDependency( _this(), aParam ); + anAsciiName = aStr; + } + aFunc->SetParam( i+1, anAsciiName ); + } +} + +char* GEOM_Object_i::GetComponent() +{ + return CORBA::string_dup( "GEOM" ); } -char* GEOM_Object_i::GetParameters() +CORBA::Boolean GEOM_Object_i::IsValid() { - return CORBA::string_dup(_impl->GetParameters().ToCString()); + return true; } +void GEOM_Object_i::Update( SALOME::Notebook_ptr theNotebook ) +{ + printf( "GEOM_Object_i::Update:\n" ); + Handle( GEOM_Function ) aFunc = _impl->GetLastFunction(); + + //1. Update parameter values + int n = aFunc->GetArgsCount(); + printf( "args count = %i\n", n ); + for( int i = 1; i <= n; i++ ) + { + TCollection_AsciiString aParamName = aFunc->GetParam( i ); + printf( "arg = %s\n", aParamName.ToCString() ); + SALOME::Parameter_ptr aParam = theNotebook->Param( aParamName.ToCString() ); + if( CORBA::is_nil( aParam ) ) + continue; + + switch( aParam->GetType() ) + { + case SALOME::TInteger: + aFunc->SetInteger( i, aParam->AsInteger() ); + break; + + case SALOME::TReal: + printf( "real: %i-th = %lf\n", i, aParam->AsReal() ); + aFunc->SetReal( i, aParam->AsReal() ); + break; + + case SALOME::TString: + aFunc->SetString( i, aParam->AsString() ); + break; + + default: + return; + } + } + + //2. Recompute object + GEOM_Solver aSolver( GEOM_Engine::GetEngine() ); + aSolver.ComputeFunction( aFunc ); +} diff --git a/src/GEOM_I/GEOM_Object_i.hh b/src/GEOM_I/GEOM_Object_i.hh index b6f16c354..5a82dc230 100644 --- a/src/GEOM_I/GEOM_Object_i.hh +++ b/src/GEOM_I/GEOM_Object_i.hh @@ -92,9 +92,13 @@ class GEOM_I_EXPORT GEOM_Object_i : public virtual POA_GEOM::GEOM_Object, public virtual bool IsShape(); - virtual void SetParameters(const char* theParameters); + virtual void SetParameters( SALOME::Notebook_ptr theNotebook, const GEOM::string_array& theParameters ); - virtual char* GetParameters(); + virtual char* GetComponent(); + + virtual CORBA::Boolean IsValid(); + + virtual void Update( SALOME::Notebook_ptr theNotebook ); Handle(GEOM_Object) GetImpl() { return _impl; } diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index c8ef92793..736acf416 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -77,8 +77,8 @@ import salome salome.salome_init() -from salome import * +from salome import * from salome_notebook import * import GEOM @@ -98,24 +98,24 @@ def RaiseIfFailed (Method_name, Operation): ## @ingroup l1_geompy_auxiliary def ParseParameters(*parameters): Result = [] - StringResult = "" + Params = [] for parameter in parameters: - if isinstance(parameter,str): - if notebook.isVariable(parameter): - Result.append(notebook.get(parameter)) - else: - raise RuntimeError, "Variable with name '" + parameter + "' doesn't exist!!!" + if isinstance(parameter, str): + Result.append(notebook.get(parameter)) + Params.append(parameter) else: Result.append(parameter) + Params.append("") pass - StringResult = StringResult + str(parameter) - StringResult = StringResult + ":" - pass - StringResult = StringResult[:len(StringResult)-1] - Result.append(StringResult) + Result.append( Params ) return Result + +def SetParameters( obj, params ): + obj.SetParameters( notebook.getNotebook(), params ) + + ## Return list of variables value from salome notebook ## @ingroup l1_geompy_auxiliary def ParseList(list): @@ -409,7 +409,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @return New GEOM_Object, containing the created point. # # @ref tui_creation_point "Example" - def MakeVertex(self,theX, theY, theZ): + def MakeVertex(self, theX, theY, theZ): # Example: see GEOM_TestAll.py theX,theY,theZ,Parameters = ParseParameters(theX, theY, theZ) anObj = self.BasicOp.MakePointXYZ(theX, theY, theZ) @@ -969,12 +969,15 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @return New GEOM_Object, containing the created box. # # @ref tui_creation_box "Example" - def MakeBoxDXDYDZ(self,theDX, theDY, theDZ): + def MakeBoxDXDYDZ(self, theDX, theDY, theDZ): # Example: see GEOM_TestAll.py theDX,theDY,theDZ,Parameters = ParseParameters(theDX, theDY, theDZ) + print theDX + print theDY + print theDZ anObj = self.PrimOp.MakeBoxDXDYDZ(theDX, theDY, theDZ) RaiseIfFailed("MakeBoxDXDYDZ", self.PrimOp) - anObj.SetParameters(Parameters) + SetParameters( anObj, Parameters ) return anObj ## Create a box with two specified opposite vertices,