From 5998f517ba7b421bbfbcec30ac822e0a1ee8b324 Mon Sep 17 00:00:00 2001 From: rnv Date: Fri, 7 Nov 2008 15:51:55 +0000 Subject: [PATCH] Implementation of the "python" persistance in GEOM. --- src/GEOM/GEOM_Engine.cxx | 162 +++++++++++++++++++++++++++++++++- src/GEOM/GEOM_Engine.hxx | 1 + src/GEOM_I/GEOM_DumpPython.cc | 14 ++- src/GEOM_SWIG/geompyDC.py | 27 ++++++ 4 files changed, 201 insertions(+), 3 deletions(-) diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index 5693abceb..ba4976e00 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -49,6 +49,7 @@ #include #include + #include #include @@ -58,6 +59,16 @@ #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC +#define COMMA ',' +#define O_BRACKET '(' +#define C_BRACKET ')' + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + static GEOM_Engine* TheEngine = NULL; static TCollection_AsciiString BuildIDFromObject(Handle(GEOM_Object)& theObject) @@ -84,10 +95,17 @@ static Standard_Integer ExtractDocID(TCollection_AsciiString& theID) void ProcessFunction(Handle(GEOM_Function)& theFunction, TCollection_AsciiString& theScript, + Resource_DataMapOfAsciiStringAsciiString& theVariableNames, TColStd_MapOfTransient& theProcessed); +void ReplaceVariables(TCollection_AsciiString& theCommand, + Resource_DataMapOfAsciiStringAsciiString& theVariableNames); + + + Handle(TColStd_HSequenceOfInteger) FindEntries(TCollection_AsciiString& theString); + //============================================================================= /*! * GetEngine @@ -421,6 +439,7 @@ void GEOM_Engine::Close(int theDocID) //============================================================================= TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID, Resource_DataMapOfAsciiStringAsciiString& theObjectNames, + Resource_DataMapOfAsciiStringAsciiString& theVariableNames, bool isPublished, bool& aValidScript) { @@ -450,7 +469,7 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID, MESSAGE ( "Null function !!!!" ); continue; } - ProcessFunction(aFunction, aScript, aMap); + ProcessFunction(aFunction, aScript,theVariableNames,aMap); } } @@ -675,6 +694,7 @@ Handle(TColStd_HSequenceOfAsciiString) GEOM_Engine::GetAllDumpNames() const //=========================================================================== void ProcessFunction(Handle(GEOM_Function)& theFunction, TCollection_AsciiString& theScript, + Resource_DataMapOfAsciiStringAsciiString& theVariableNames, TColStd_MapOfTransient& theProcessed) { if(theFunction.IsNull() || theProcessed.Contains(theFunction)) return; @@ -698,8 +718,11 @@ void ProcessFunction(Handle(GEOM_Function)& theFunction, //Check if its internal function which doesn't requires dumping if(aDescr == "None") return; + //Replace parameter by notebook variables + ReplaceVariables(aDescr,theVariableNames); theScript += "\n\t"; theScript += aDescr; + theProcessed.Add(theFunction); return; @@ -741,3 +764,140 @@ Handle(TColStd_HSequenceOfInteger) FindEntries(TCollection_AsciiString& theStrin return aSeq; } + +//============================================================================= +/*! + * ReplaceVariables: Replace parameters of the function by variales from + * Notebook if need + */ +//============================================================================= +void ReplaceVariables(TCollection_AsciiString& theCommand, + Resource_DataMapOfAsciiStringAsciiString& theVariableNames) +{ + //Get Entry of the result object + TCollection_AsciiString anEntry = theCommand.Token("=",1); + + //Remove white spaces + anEntry.RightAdjust(); + anEntry.LeftAdjust(); + if(MYDEBUG) + cout<<"Result entry : '" <NewChildIterator(aSO); for(Itr->InitEx(true); Itr->More(); Itr->Next()) { @@ -59,6 +59,16 @@ Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy, CORBA::String_var aName = aValue->GetName(); CORBA::String_var anEntry = GO->GetEntry(); aMap.Bind( (char*)anEntry.in(), (char*)aName.in() ); + + //Find attribute with list of used notebook variables + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributeString_var anAttrStr; + TCollection_AsciiString aParameters; + if(aValue->FindAttribute(anAttr,"AttributeString")){ + anAttrStr = SALOMEDS::AttributeString::_narrow(anAttr); + aParameters = TCollection_AsciiString(anAttrStr->Value()); + } + aVariableMap.Bind((char*)anEntry.in(),aParameters); } } } @@ -66,7 +76,7 @@ Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy, TCollection_AsciiString aScript = "### This file is generated by SALOME automatically by dump python functionality\n" "### of GEOM component\n\n"; - aScript += _impl->DumpPython(aStudy->StudyId(), aMap, isPublished, isValidScript); + aScript += _impl->DumpPython(aStudy->StudyId(), aMap, aVariableMap, isPublished, isValidScript); if (isPublished) { diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index d3477a9a3..2a883e425 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -80,6 +80,8 @@ import salome salome.salome_init() from salome import * +from salome_notebook import * + import GEOM import math @@ -92,6 +94,29 @@ ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE" def RaiseIfFailed (Method_name, Operation): if Operation.IsDone() == 0 and Operation.GetErrorCode() != "NOT_FOUND_ANY": raise RuntimeError, Method_name + " : " + Operation.GetErrorCode() + +## Return list of variables value from salome notebook +## @ingroup l1_geompy_auxiliary +def ParseParameters(*parameters): + Result = [] + StringResult = "" + for parameter in parameters: + if isinstance(parameter,str): + if notebook.isVariable(parameter): + Result.append(notebook.get(parameter)) + pass + pass + else: + Result.append(parameter) + pass + + StringResult = StringResult + str(parameter) + StringResult = StringResult + ":" + pass + StringResult = StringResult[:len(StringResult)-1] + Result.append(StringResult) + return Result + ## Kinds of shape enumeration # @ingroup l1_geompy_auxiliary @@ -684,6 +709,8 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @ref tui_creation_box "Example" def MakeBoxDXDYDZ(self,theDX, theDY, theDZ): # Example: see GEOM_TestAll.py + theDX,theDY,theDZ,Parameters = ParseParameters(theDX, theDY, theDZ) + self.PrimOp.SetParameters(Parameters) anObj = self.PrimOp.MakeBoxDXDYDZ(theDX, theDY, theDZ) RaiseIfFailed("MakeBoxDXDYDZ", self.PrimOp) return anObj -- 2.39.2