mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-30 04:00:32 +05:00
Implementation of the "python" persistance in GEOM.
This commit is contained in:
parent
1d552bfd2c
commit
5998f517ba
@ -49,6 +49,7 @@
|
||||
#include <TColStd_MapOfTransient.hxx>
|
||||
#include <TColStd_HSequenceOfInteger.hxx>
|
||||
|
||||
|
||||
#include <Interface_DataMapIteratorOfDataMapOfIntegerTransient.hxx>
|
||||
#include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
|
||||
|
||||
@ -58,6 +59,16 @@
|
||||
#include <Standard_Failure.hxx>
|
||||
#include <Standard_ErrorHandler.hxx> // 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 : '" <<anEntry<<"'"<<endl;
|
||||
|
||||
//Find variables used for object construction
|
||||
TCollection_AsciiString aVariables;
|
||||
if(theVariableNames.IsBound(anEntry))
|
||||
aVariables = theVariableNames.Find(anEntry);
|
||||
|
||||
if(aVariables.IsEmpty()) {
|
||||
if(MYDEBUG)
|
||||
cout<<"Valiables list empty!!!"<<endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if(MYDEBUG)
|
||||
cout<<"Variables : '" <<aVariables<<"'"<<endl;
|
||||
|
||||
//Calculate number of variables, that mast be replaced
|
||||
Standard_Integer aNbReplacedParams = 1,aPos;
|
||||
TColStd_HSequenceOfInteger aPositions;
|
||||
while(aPos = aVariables.Location(aNbReplacedParams,':',1,aVariables.Length())) {
|
||||
aPositions.Append(aPos);
|
||||
aNbReplacedParams++;
|
||||
}
|
||||
|
||||
if(MYDEBUG)
|
||||
cout<<"Number of replaced variables : " <<aNbReplacedParams<<endl;
|
||||
|
||||
if(MYDEBUG)
|
||||
{
|
||||
for(Standard_Integer i = 1;i<=aPositions.Length();i++)
|
||||
cout<<"Positions ["<<i<<"] = "<<aPositions.Value(i)<<endl;
|
||||
}
|
||||
|
||||
//Calculate total number of parameter
|
||||
Standard_Integer aTotalNbParams = 1;
|
||||
while(theCommand.Location(aTotalNbParams,COMMA,1,theCommand.Length()))
|
||||
aTotalNbParams++;
|
||||
|
||||
|
||||
if(MYDEBUG)
|
||||
cout<<"Total Number of parameters : " <<aTotalNbParams<<endl;
|
||||
|
||||
//Get Variables names
|
||||
TColStd_SequenceOfAsciiString aVarSeq;
|
||||
TCollection_AsciiString aVar;
|
||||
Standard_Integer i = 1;
|
||||
while(i <= aNbReplacedParams){
|
||||
|
||||
if(i == 1)
|
||||
aVar = (aPositions.Value(i) == 1) ? TCollection_AsciiString() : aVariables.SubString(1, aPositions.Value(i)-1);
|
||||
else if(i == aNbReplacedParams) {
|
||||
Standard_Integer aLen = aVariables.Length();
|
||||
Standard_Integer aPos = aPositions.Value(i-1);
|
||||
aVar = (aPos == aLen) ? TCollection_AsciiString() : aVariables.SubString(aPos+1, aLen);
|
||||
}
|
||||
else {
|
||||
Standard_Integer aPrevPos = aPositions.Value(i-1);
|
||||
Standard_Integer aCurrentPos = aPositions.Value(i);
|
||||
aVar = (aCurrentPos - aPrevPos == 1) ? TCollection_AsciiString() : aVariables.SubString(aPrevPos+1, aCurrentPos-1);
|
||||
}
|
||||
if(MYDEBUG)
|
||||
cout<<"Variable ["<<i<<"] = '"<<aVar<<"'"<<endl;
|
||||
|
||||
//Add current varibale
|
||||
aVarSeq.Append(aVar);
|
||||
i++;
|
||||
}
|
||||
|
||||
//Replace parameters by variables
|
||||
Standard_Integer aStartPos = 0;
|
||||
Standard_Integer aEndPos = 0;
|
||||
Standard_Integer iVar = 1;
|
||||
for(Standard_Integer i=1;i <= aTotalNbParams;i++) {
|
||||
|
||||
//Replace first parameter (bettwen '(' character and first ',' character)
|
||||
if(i == 1)
|
||||
{
|
||||
aStartPos = theCommand.Location(O_BRACKET, 1, theCommand.Length()) + 1;
|
||||
aEndPos = theCommand.Location(COMMA, 1, theCommand.Length());
|
||||
}
|
||||
//Replace last parameter (bettwen ',' character and ')' character)
|
||||
else if(i == aVarSeq.Length())
|
||||
{
|
||||
aStartPos = theCommand.Location(i-1, COMMA, 1, theCommand.Length()) + 2;
|
||||
aEndPos = theCommand.Location(C_BRACKET, 1, theCommand.Length());
|
||||
}
|
||||
//Replace other parameters (bettwen two ',' characters)
|
||||
else if(i != 1 && i != aVarSeq.Length())
|
||||
{
|
||||
aStartPos = theCommand.Location(i-1, COMMA, 1, theCommand.Length()) + 2;
|
||||
aEndPos = theCommand.Location(i, COMMA, 1, theCommand.Length());
|
||||
}
|
||||
|
||||
TCollection_AsciiString aParameter = theCommand.SubString(aStartPos, aStartPos);
|
||||
|
||||
if(MYDEBUG)
|
||||
cout<<"Current parameter "<<aParameter<<endl;
|
||||
|
||||
aVar = aVarSeq.Value(iVar);
|
||||
|
||||
//If parameter is entry, skip it
|
||||
aVar.RightAdjust();
|
||||
aVar.LeftAdjust();
|
||||
if(theVariableNames.IsBound(aVar))
|
||||
continue;
|
||||
|
||||
|
||||
if(aVar.IsEmpty()) {
|
||||
iVar++;
|
||||
continue;
|
||||
}
|
||||
|
||||
aVar.InsertBefore(1,"\"");
|
||||
aVar.InsertAfter(aVar.Length(),"\"");
|
||||
|
||||
theCommand.Remove(aStartPos, aEndPos - aStartPos);
|
||||
theCommand.Insert(aStartPos,aVar);
|
||||
iVar++;
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,7 @@ class GEOM_Engine
|
||||
|
||||
Standard_EXPORT TCollection_AsciiString DumpPython(int theDocID,
|
||||
Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
|
||||
Resource_DataMapOfAsciiStringAsciiString& theVariableNames,
|
||||
bool isPublished,
|
||||
bool& aValidScript);
|
||||
|
||||
|
@ -46,7 +46,7 @@ Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
|
||||
if(CORBA::is_nil(aSO))
|
||||
return new Engines::TMPFile(0);
|
||||
|
||||
Resource_DataMapOfAsciiStringAsciiString aMap;
|
||||
Resource_DataMapOfAsciiStringAsciiString aMap, aVariableMap;
|
||||
|
||||
SALOMEDS::ChildIterator_var Itr = aStudy->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)
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user