]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Implementation of update GEOM objects as Parameterized
authorasl <asl@opencascade.com>
Fri, 20 Nov 2009 08:11:39 +0000 (08:11 +0000)
committerasl <asl@opencascade.com>
Fri, 20 Nov 2009 08:11:39 +0000 (08:11 +0000)
src/GEOM_I/GEOM_Object_i.cc
src/GEOM_I/GEOM_Object_i.hh
src/GEOM_SWIG/geompyDC.py

index f164b4ef4bb9dc58916730914d297300ac57a73e..44ac7db00f359f71f5972b59555917bbdc14e92d 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <GEOM_Object_i.hh>
 #include <GEOM_ISubShape.hxx>
+#include <GEOM_Engine.hxx>
 #include <GEOMImpl_Types.hxx>
 
 #include "utilities.h"
@@ -35,6 +36,7 @@
 #include <TDF_Tool.hxx>
 #include <TDF_Label.hxx>
 #include <TCollection_AsciiString.hxx>
+#include <TColStd_Array1OfAsciiString.hxx>
 
 #include <BRepTools_ShapeSet.hxx>
 #include <BRepTools.hxx>
@@ -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 );
+}
index b6f16c3546410cac0d2e1917385926f8ec6e1e93..5a82dc230bf5cdbadb2c99230f21f173c22a0295 100644 (file)
@@ -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; }
 
index c8ef92793f9a967e0a405260321f5ad3903b1394..736acf416520367b5605f79a58060a954ee38dee 100644 (file)
@@ -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,