## @}
## @defgroup l2_measure Using measurement tools
+## @defgroup l2_field Field on Geometry
## @}
## @ingroup l1_geomBuilder_auxiliary
def RaiseIfFailed (Method_name, Operation):
if Operation.IsDone() == 0 and Operation.GetErrorCode() != "NOT_FOUND_ANY":
+ Operation.AbortOperation()
raise RuntimeError, Method_name + " : " + Operation.GetErrorCode()
+ else:
+ Operation.FinishOperation()
+ pass
## Return list of variables value from salome notebook
## @ingroup l1_geomBuilder_auxiliary
CLOSED = 1
UNCLOSED = 2
+##! Private class used to bind calls of plugin operations to geomBuilder
+class PluginOperation:
+ def __init__(self, operation, function):
+ self.operation = operation
+ self.function = function
+ pass
+
+ def __call__(self, *args):
+ res = self.function(self.operation, *args)
+ RaiseIfFailed(self.function.__name__, self.operation)
+ return res
+
# Warning: geom is a singleton
geom = None
engine = None
self.BlocksOp = None
self.GroupOp = None
self.AdvOp = None
+ self.FieldOp = None
pass
## Process object publication in the study, as follows:
pass
return _name
# ---
+ def _publish( _name, _obj ):
+ fatherObj = None
+ if isinstance( _obj, GEOM._objref_GEOM_Field ):
+ fatherObj = _obj.GetShape()
+ elif isinstance( _obj, GEOM._objref_GEOM_FieldStep ):
+ fatherObj = _obj.GetField()
+ elif not _obj.IsMainShape():
+ fatherObj = _obj.GetMainShape()
+ pass
+ if fatherObj and fatherObj.GetStudyEntry():
+ self.addToStudyInFather(fatherObj, _obj, _name)
+ else:
+ self.addToStudy(_obj, _name)
+ pass
+ return
+ # ---
if not theObj:
return # null object
if not theName and not self.myMaxNbSubShapesAllowed:
idx = 0
for obj in theObj:
if not obj: continue # bad object
- ###if obj.GetStudyEntry(): continue # already published
name = _item_name(theName, theDefaultName, idx)
- if obj.IsMainShape() or not obj.GetMainShape().GetStudyEntry():
- self.addToStudy(obj, name) # "%s_%d"%(aName, idx)
- else:
- self.addToStudyInFather(obj.GetMainShape(), obj, name) # "%s_%d"%(aName, idx)
- pass
+ _publish( name, obj )
idx = idx+1
if not theName and idx == self.myMaxNbSubShapesAllowed: break
pass
pass
else:
# single object is published
- ###if theObj.GetStudyEntry(): return # already published
name = _item_name(theName, theDefaultName)
- if theObj.IsMainShape():
- self.addToStudy(theObj, name)
- else:
- self.addToStudyInFather(theObj.GetMainShape(), theObj, name)
- pass
- pass
+ _publish( name, theObj )
pass
## @addtogroup l1_geomBuilder_auxiliary
self.MeasuOp = self.GetIMeasureOperations (self.myStudyId)
self.BlocksOp = self.GetIBlocksOperations (self.myStudyId)
self.GroupOp = self.GetIGroupOperations (self.myStudyId)
- self.AdvOp = self.GetIAdvancedOperations (self.myStudyId)
+ self.FieldOp = self.GetIFieldOperations (self.myStudyId)
+
+ # The below line is a right way to map all plugin functions to geomBuilder,
+ # but AdvancedOperations are already mapped, that is why this line is commented
+ # and presents here only as an axample
+ #self.AdvOp = self.GetPluginOperations (self.myStudyId, "AdvancedEngine")
+
+ # self.AdvOp is used by functions MakePipeTShape*, MakeDividedDisk, etc.
+ self.AdvOp = GEOM._objref_GEOM_Gen.GetPluginOperations (self, self.myStudyId, "AdvancedEngine")
+
+ # set GEOM as root in the use case tree
+ self.myUseCaseBuilder = self.myStudy.GetUseCaseBuilder()
+ self.myUseCaseBuilder.SetRootCurrent()
+ self.myUseCaseBuilder.Append(self.father)
pass
+ def GetPluginOperations(self, studyID, libraryName):
+ op = GEOM._objref_GEOM_Gen.GetPluginOperations(self, studyID, libraryName)
+ if op:
+ # bind methods of operations to self
+ methods = op.__class__.__dict__['__methods__']
+ avoid_methods = self.BasicOp.__class__.__dict__['__methods__']
+ for meth_name in methods:
+ if not meth_name in avoid_methods: # avoid basic methods
+ function = getattr(op.__class__, meth_name)
+ if callable(function):
+ #self.__dict__[meth_name] = self.__PluginOperation(op, function)
+ self.__dict__[meth_name] = PluginOperation(op, function)
+ return op
+
## Enable / disable results auto-publishing
#
# The automatic publishing is managed in the following way:
# @param theParamMin the minimal value of the parameter.
# @param theParamMax the maximum value of the parameter.
# @param theParamStep the number of steps if theNewMethod = True, else step value of the parameter.
- # @param theCurveType the type of the curve.
+ # @param theCurveType the type of the curve,
+ # one of GEOM.Polyline, GEOM.Bezier, GEOM.Interpolation.
# @param theNewMethod flag for switching to the new method if the flag is set to false a deprecated method is used which can lead to a bug.
# @param theName Object name; when specified, this parameter is used
# for result publication in the study. Otherwise, if automatic
theParamMin the minimal value of the parameter.
theParamMax the maximum value of the parameter.
theParamStep the number of steps if theNewMethod = True, else step value of the parameter.
- theCurveType the type of the curve.
+ theCurveType the type of the curve,
+ one of GEOM.Polyline, GEOM.Bezier, GEOM.Interpolation.
theNewMethod flag for switching to the new method if the flag is set to false a deprecated
method is used which can lead to a bug.
theName Object name; when specified, this parameter is used
New GEOM.GEOM_Object, containing the created compound.
"""
# Example: see GEOM_TestAll.py
+ self.ShapesOp.StartOperation()
anObj = self.ShapesOp.MakeCompound(theShapes)
RaiseIfFailed("MakeCompound", self.ShapesOp)
self._autoPublish(anObj, theName, "compound")
return ListObj
## Obtain a compound of sub-shapes of <VAR>aShape</VAR>,
- # selected by they indices in list of all sub-shapes of type <VAR>aType</VAR>.
+ # selected by their indices in list of all sub-shapes of type <VAR>aType</VAR>.
# Each index is in range [1, Nb_Sub-Shapes_Of_Given_Type]
# @param aShape Shape to get sub-shape of.
# @param ListOfInd List of sub-shapes indices.
def SubShape(self, aShape, aType, ListOfInd, theName=None):
"""
Obtain a compound of sub-shapes of aShape,
- selected by they indices in list of all sub-shapes of type aType.
+ selected by their indices in list of all sub-shapes of type aType.
Each index is in range [1, Nb_Sub-Shapes_Of_Given_Type]
Parameters:
anObj = self.HealOp.SewAllowNonManifold(theObject, theTolerance)
else:
anObj = self.HealOp.Sew(theObject, theTolerance)
+ # To avoid script failure in case of good argument shape
+ if self.HealOp.GetErrorCode() == "ShHealOper_NotError_msg":
+ return theObject
RaiseIfFailed("Sew", self.HealOp)
anObj.SetParameters(Parameters)
self._autoPublish(anObj, theName, "sewed")
# Example: see GEOM_TestMeasures.py
listSh = self.SubShapeAllIDs(theShape, theType)
Nb = len(listSh)
- t = EnumToLong(theShape.GetShapeType())
- theType = EnumToLong(theType)
- if t == theType:
- Nb = Nb + 1
- pass
return Nb
## Obtain quantity of shapes of each type in \a theShape.
if typeSh in ( "AUTO", "SHAPE" ): continue
listSh = self.SubShapeAllIDs(theShape, self.ShapeType[typeSh])
Nb = len(listSh)
- if EnumToLong(theShape.GetShapeType()) == self.ShapeType[typeSh]:
- Nb = Nb + 1
- pass
aDict[typeSh] = Nb
pass
return aDict
self._autoPublish(anObj, theName, "dividedCylinder")
return anObj
+ ## Create a surface from a cloud of points
+ # @param thelPoints list of points
+ # @return New GEOM_Object, containing the created shape.
+ #
+ # @ref tui_creation_smoothingsurface "Example"
+ def MakeSmoothingSurface(self, thelPoints):
+ anObj = self.AdvOp.MakeSmoothingSurface(thelPoints)
+ RaiseIfFailed("MakeSmoothingSurface", self.AdvOp)
+ return anObj
+
+ ## Export a shape to XAO format
+ # @param shape The shape to export
+ # @param groups The list of groups to export
+ # @param fields The list of fields to export
+ # @param author The author of the export
+ # @param fileName The name of the file to export
+ # @return boolean
+ #
+ # @ref tui_exportxao "Example"
+ def ExportXAO(self, shape, groups, fields, author, fileName):
+ res = self.InsertOp.ExportXAO(shape, groups, fields, author, fileName)
+ RaiseIfFailed("ExportXAO", self.InsertOp)
+ return res
+
+ ## Import a shape from XAO format
+ # @param shape Shape to export
+ # @param fileName The name of the file to import
+ # @return tuple (res, shape, subShapes, groups, fields)
+ # res Flag indicating if the import was successful
+ # shape The imported shape
+ # subShapes The list of imported subShapes
+ # groups The list of imported groups
+ # fields The list of imported fields
+ #
+ # @ref tui_importxao "Example"
+ def ImportXAO(self, fileName):
+ res = self.InsertOp.ImportXAO(fileName)
+ RaiseIfFailed("ImportXAO", self.InsertOp)
+ return res
+
#@@ insert new functions before this line @@ do not remove this line @@#
# end of l4_advanced
RaiseIfFailed("AddTexture", self.InsertOp)
return ID
+ ## Creates a new folder object. It is a container for any GEOM objects.
+ # @param Name name of the container
+ # @param Father parent object. If None,
+ # folder under 'Geometry' root object will be created.
+ # @return a new created folder
+ def NewFolder(self, Name, Father=None):
+ """
+ Create a new folder object. It is an auxiliary container for any GEOM objects.
+
+ Parameters:
+ Name name of the container
+ Father parent object. If None,
+ folder under 'Geometry' root object will be created.
+
+ Returns:
+ a new created folder
+ """
+ if not Father: Father = self.father
+ return self.CreateFolder(Name, Father)
+
+ ## Move object to the specified folder
+ # @param Object object to move
+ # @param Folder target folder
+ def PutToFolder(self, Object, Folder):
+ """
+ Move object to the specified folder
+
+ Parameters:
+ Object object to move
+ Folder target folder
+ """
+ self.MoveToFolder(Object, Folder)
+ pass
+
+ ## Move list of objects to the specified folder
+ # @param ListOfSO list of objects to move
+ # @param Folder target folder
+ def PutListToFolder(self, ListOfSO, Folder):
+ """
+ Move list of objects to the specified folder
+
+ Parameters:
+ ListOfSO list of objects to move
+ Folder target folder
+ """
+ self.MoveListToFolder(ListOfSO, Folder)
+ pass
+
+ ## @addtogroup l2_field
+ ## @{
+
+ ## Creates a field
+ # @param shape the shape the field lies on
+ # @param name the field name
+ # @param type type of field data: 0 - bool, 1 - int, 2 - double, 3 - string
+ # @param dimension dimension of the shape the field lies on
+ # 0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape
+ # @param componentNames names of components
+ # @return a created field
+ def CreateField(self, shape, name, type, dimension, componentNames):
+ """
+ Creates a field
+
+ Parameters:
+ shape the shape the field lies on
+ name the field name
+ type type of field data
+ dimension dimension of the shape the field lies on
+ 0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape
+ componentNames names of components
+
+ Returns:
+ a created field
+ """
+ if isinstance( type, int ):
+ if type < 0 or type > 3:
+ raise RuntimeError, "CreateField : Error: data type must be within [0-3] range"
+ type = [GEOM.FDT_Bool,GEOM.FDT_Int,GEOM.FDT_Double,GEOM.FDT_String][type]
+
+ f = self.FieldOp.CreateField( shape, name, type, dimension, componentNames)
+ RaiseIfFailed("CreateField", self.FieldOp)
+ global geom
+ geom._autoPublish( f, "", name)
+ return f
+
+ ## Removes a field from the GEOM component
+ # @param field the field to remove
+ def RemoveField(self, field):
+ "Removes a field from the GEOM component"
+ global geom
+ if isinstance( field, GEOM._objref_GEOM_Field ):
+ geom.RemoveObject( field )
+ elif isinstance( field, geomField ):
+ geom.RemoveObject( field.field )
+ else:
+ raise RuntimeError, "RemoveField() : the object is not a field"
+ return
+
+ ## Returns number of fields on a shape
+ def CountFields(self, shape):
+ "Returns number of fields on a shape"
+ nb = self.FieldOp.CountFields( shape )
+ RaiseIfFailed("CountFields", self.FieldOp)
+ return nb
+
+ ## Returns all fields on a shape
+ def GetFields(self, shape):
+ "Returns all fields on a shape"
+ ff = self.FieldOp.GetFields( shape )
+ RaiseIfFailed("GetFields", self.FieldOp)
+ return ff
+
+ ## Returns a field on a shape by its name
+ def GetField(self, shape, name):
+ "Returns a field on a shape by its name"
+ f = self.FieldOp.GetField( shape, name )
+ RaiseIfFailed("GetField", self.FieldOp)
+ return f
+
+ # end of l2_field
+ ## @}
+
+
import omniORB
# Register the new proxy for GEOM_Gen
omniORB.registerObjref(GEOM._objref_GEOM_Gen._NP_RepositoryId, geomBuilder)
+
+## Field on Geometry
+# @ingroup l2_field
+class geomField( GEOM._objref_GEOM_Field ):
+
+ def __init__(self):
+ GEOM._objref_GEOM_Field.__init__(self)
+ self.field = GEOM._objref_GEOM_Field
+ return
+
+ ## Returns the shape the field lies on
+ def getShape(self):
+ "Returns the shape the field lies on"
+ return self.field.GetShape(self)
+
+ ## Returns the field name
+ def getName(self):
+ "Returns the field name"
+ return self.field.GetName(self)
+
+ ## Returns type of field data as integer [0-3]
+ def getType(self):
+ "Returns type of field data"
+ return self.field.GetDataType(self)._v
+
+ ## Returns type of field data:
+ # one of GEOM.FDT_Bool, GEOM.FDT_Int, GEOM.FDT_Double, GEOM.FDT_String
+ def getTypeEnum(self):
+ "Returns type of field data"
+ return self.field.GetDataType(self)
+
+ ## Returns dimension of the shape the field lies on:
+ # 0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape
+ def getDimension(self):
+ """Returns dimension of the shape the field lies on:
+ 0 - VERTEX, 1 - EDGE, 2 - FACE, 3 - SOLID, -1 - whole shape"""
+ return self.field.GetDimension(self)
+
+ ## Returns names of components
+ def getComponents(self):
+ "Returns names of components"
+ return self.field.GetComponents(self)
+
+ ## Adds a time step to the field
+ # @param step the time step number futher used as the step identifier
+ # @param stamp the time step time
+ # @param values the values of the time step
+ def addStep(self, step, stamp, values):
+ "Adds a time step to the field"
+ stp = self.field.AddStep( self, step, stamp )
+ if not stp:
+ raise RuntimeError, \
+ "Field.addStep() : Error: step %s already exists in this field"%step
+ global geom
+ geom._autoPublish( stp, "", "Step %s, %s"%(step,stamp))
+ self.setValues( step, values )
+ return stp
+
+ ## Remove a time step from the field
+ def removeStep(self,step):
+ "Remove a time step from the field"
+ stepSO = None
+ try:
+ stepObj = self.field.GetStep( self, step )
+ if stepObj:
+ stepSO = geom.myStudy.FindObjectID( stepObj.GetStudyEntry() )
+ except:
+ #import traceback
+ #traceback.print_exc()
+ pass
+ self.field.RemoveStep( self, step )
+ if stepSO:
+ geom.myBuilder.RemoveObjectWithChildren( stepSO )
+ return
+
+ ## Returns number of time steps in the field
+ def countSteps(self):
+ "Returns number of time steps in the field"
+ return self.field.CountSteps(self)
+
+ ## Returns a list of time step IDs in the field
+ def getSteps(self):
+ "Returns a list of time step IDs in the field"
+ return self.field.GetSteps(self)
+
+ ## Returns a time step by its ID
+ def getStep(self,step):
+ "Returns a time step by its ID"
+ stp = self.field.GetStep(self, step)
+ if not stp:
+ raise RuntimeError, "Step %s is missing from this field"%step
+ return stp
+
+ ## Returns the time of the field step
+ def getStamp(self,step):
+ "Returns the time of the field step"
+ return self.getStep(step).GetStamp()
+
+ ## Changes the time of the field step
+ def setStamp(self, step, stamp):
+ "Changes the time of the field step"
+ return self.getStep(step).SetStamp(stamp)
+
+ ## Returns values of the field step
+ def getValues(self, step):
+ "Returns values of the field step"
+ return self.getStep(step).GetValues()
+
+ ## Changes values of the field step
+ def setValues(self, step, values):
+ "Changes values of the field step"
+ stp = self.getStep(step)
+ errBeg = "Field.setValues(values) : Error: "
+ try:
+ ok = stp.SetValues( values )
+ except Exception, e:
+ excStr = str(e)
+ if excStr.find("WrongPythonType") > 0:
+ raise RuntimeError, errBeg +\
+ "wrong type of values, %s values are expected"%str(self.getTypeEnum())[4:]
+ raise RuntimeError, errBeg + str(e)
+ if not ok:
+ nbOK = self.field.GetArraySize(self)
+ nbKO = len(values)
+ if nbOK != nbKO:
+ raise RuntimeError, errBeg + "len(values) must be %s but not %s"%(nbOK,nbKO)
+ else:
+ raise RuntimeError, errBeg + "failed"
+ return
+
+ pass # end of class geomField
+
+# Register the new proxy for GEOM_Field
+omniORB.registerObjref(GEOM._objref_GEOM_Field._NP_RepositoryId, geomField)
+
+
## Create a new geomBuilder instance.The geomBuilder class provides the Python
# interface to GEOM operations.
#