smesh/src/SMESH_SWIG/batchmode_smesh.py

318 lines
12 KiB
Python
Raw Normal View History

2003-07-10 19:41:56 +06:00
# Copyright (C) 2003 CEA/DEN, EDF R&D
#
#
#
# File : batchmode_smesh.py
# Author : Oksana TCHEBANOVA
# Module : SMESH
2003-05-19 20:07:00 +06:00
# $Header$
from batchmode_salome import *
import SMESH
#--------------------------------------------------------------------------
modulecatalog = naming_service.Resolve("/Kernel/ModulCatalog")
smesh = lcc.FindOrLoadComponent("FactoryServer", "SMESH")
myStudyBuilder = myStudy.NewBuilder()
if myStudyBuilder is None:
raise RuntimeError, " Null myStudyBuilder"
father = myStudy.FindComponent("MESH")
if father is None:
father = myStudyBuilder.NewComponent("MESH")
2004-06-18 14:34:31 +06:00
FName = myStudyBuilder.FindOrCreateAttribute(father, "AttributeName");
2003-05-19 20:07:00 +06:00
Comp = modulecatalog.GetComponent( "SMESH" )
FName.SetValue( Comp._get_componentusername() )
2004-06-18 14:34:31 +06:00
aPixmap = myStudyBuilder.FindOrCreateAttribute(father, "AttributePixMap");
2003-05-19 20:07:00 +06:00
aPixmap.SetPixMap( "ICON_OBJBROWSER_Mesh" );
myStudyBuilder.DefineComponentInstance(father,smesh)
mySComponentMesh = father._narrow(SALOMEDS.SComponent)
Tag_HypothesisRoot = 1;
Tag_AlgorithmsRoot = 2;
Tag_RefOnShape = 1;
Tag_RefOnAppliedHypothesis = 2;
Tag_RefOnAppliedAlgorithms = 3;
Tag_SubMeshOnVertex = 4;
Tag_SubMeshOnEdge = 5;
Tag_SubMeshOnFace = 6;
Tag_SubMeshOnSolid = 7;
Tag_SubMeshOnCompound = 8;
Tag = {"HypothesisRoot":1,"AlgorithmsRoot":2,"RefOnShape":1,"RefOnAppliedHypothesis":2,"RefOnAppliedAlgorithms":3,"SubMeshOnVertex":4,"SubMeshOnEdge":5,"SubMeshOnFace":6,"SubMeshOnSolid":7,"SubMeshOnCompound":8}
# -- enumeration --
ShapeTypeCompSolid = 1
ShapeTypeSolid = 2
ShapeTypeShell = 3
ShapeTypeFace = 4
ShapeTypeWire = 5
ShapeTypeEdge = 6
ShapeTypeVertex = 7
# -- enumeration ShapeType as a dictionary --
ShapeType = {"CompSolid":1, "Solid":2, "Shell":3, "Face":4, "Wire":5, "Edge":6, "Vertex":7}
#------------------------------------------------------------
def Init():
pass
#------------------------------------------------------------
def AddNewMesh(IOR):
2004-06-18 14:34:31 +06:00
# VSR: added temporarily - objects are published automatically by the engine
aSO = myStudy.FindObjectIOR( IOR )
if aSO is not None:
return aSO.GetID()
# VSR ######################################################################
2003-05-19 20:07:00 +06:00
res,HypothesisRoot = mySComponentMesh.FindSubObject ( Tag_HypothesisRoot )
if HypothesisRoot is None or res == 0:
HypothesisRoot = myStudyBuilder.NewObjectToTag(mySComponentMesh, Tag_HypothesisRoot)
2004-06-18 14:34:31 +06:00
aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
aName.SetValue("Hypotheses")
aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
2003-05-19 20:07:00 +06:00
aPixmap.SetPixMap( "mesh_tree_hypo.png" )
2004-06-18 14:34:31 +06:00
aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
2003-05-19 20:07:00 +06:00
aSelAttr.SetSelectable(0);
res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
if AlgorithmsRoot is None or res == 0:
AlgorithmsRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
2004-06-18 14:34:31 +06:00
aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
aName.SetValue("Algorithms");
aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap");
2003-05-19 20:07:00 +06:00
aPixmap.SetPixMap( "mesh_tree_algo.png" );
2004-06-18 14:34:31 +06:00
aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable");
2003-05-19 20:07:00 +06:00
aSelAttr.SetSelectable(0);
HypothesisRoot = HypothesisRoot._narrow(SALOMEDS.SObject)
newMesh = myStudyBuilder.NewObject(mySComponentMesh)
2004-06-18 14:34:31 +06:00
aPixmap = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributePixMap")
2003-05-19 20:07:00 +06:00
aPixmap.SetPixMap( "mesh_tree_mesh.png" )
2004-06-18 14:34:31 +06:00
anIOR = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributeIOR")
2003-05-19 20:07:00 +06:00
anIOR.SetValue(IOR)
return newMesh.GetID()
#------------------------------------------------------------
def AddNewHypothesis(IOR):
2004-06-18 14:34:31 +06:00
# VSR: added temporarily - objects are published automatically by the engine
aSO = myStudy.FindObjectIOR( IOR )
if aSO is not None:
return aSO.GetID()
# VSR ######################################################################
2003-05-19 20:07:00 +06:00
res, HypothesisRoot = mySComponentMesh.FindSubObject (Tag_HypothesisRoot)
if HypothesisRoot is None or res == 0:
HypothesisRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot)
2004-06-18 14:34:31 +06:00
aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName");
aName.SetValue("Hypotheses");
aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable");
2003-05-19 20:07:00 +06:00
aSelAttr.SetSelectable(0);
2004-06-18 14:34:31 +06:00
aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap");
2003-05-19 20:07:00 +06:00
aPixmap.SetPixMap( "mesh_tree_hypo.png" );
# Add New Hypothesis
newHypo = myStudyBuilder.NewObject(HypothesisRoot)
2004-06-18 14:34:31 +06:00
aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
2003-05-19 20:07:00 +06:00
H = orb.string_to_object(IOR)
aType = H.GetName();
aPixmap.SetPixMap( "mesh_tree_hypo.png_" + aType );
2004-06-18 14:34:31 +06:00
anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR");
2003-05-19 20:07:00 +06:00
anIOR.SetValue(IOR);
return newHypo.GetID();
#------------------------------------------------------------
def AddNewAlgorithms(IOR):
2004-06-18 14:34:31 +06:00
# VSR: added temporarily - objects are published automatically by the engine
aSO = myStudy.FindObjectIOR( IOR )
if aSO is not None:
return aSO.GetID()
# VSR ######################################################################
2003-05-19 20:07:00 +06:00
res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
if AlgorithmsRoot is None or res == 0:
AlgorithmsRoot = myStudyBuilde.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
2004-06-18 14:34:31 +06:00
aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
aName.SetValue("Algorithms");
aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
2003-05-19 20:07:00 +06:00
aSelAttr.SetSelectable(0);
2004-06-18 14:34:31 +06:00
aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap");
2003-05-19 20:07:00 +06:00
aPixmap.SetPixMap( "mesh_tree_algo.png" );
# Add New Algorithms
newHypo = myStudyBuilder.NewObject(AlgorithmsRoot)
2004-06-18 14:34:31 +06:00
aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap");
2003-05-19 20:07:00 +06:00
aPixmap = anAttr._narrow(SALOMEDS.AttributePixMap);
H = orb.string_to_object(IOR)
aType = H.GetName(); #QString in fact
aPixmap.SetPixMap( "mesh_tree_algo.png_" + aType );
2004-06-18 14:34:31 +06:00
anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR");
2003-05-19 20:07:00 +06:00
anIOR.SetValue(IOR);
return newHypo.GetID();
#------------------------------------------------------------
def SetShape(ShapeEntry, MeshEntry):
SO_MorSM = myStudy.FindObjectID( MeshEntry )
SO_GeomShape = myStudy.FindObjectID( ShapeEntry );
if SO_MorSM is not None and SO_GeomShape is not None :
2004-06-18 14:34:31 +06:00
# VSR: added temporarily - shape reference is published automatically by the engine
res, Ref = SO_MorSM.FindSubObject( Tag_RefOnShape );
if res == 1 :
return;
# VSR ######################################################################
2003-05-19 20:07:00 +06:00
SO = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnShape);
myStudyBuilder.Addreference (SO,SO_GeomShape);
#------------------------------------------------------------
def SetHypothesis(Mesh_Or_SubMesh_Entry, Hypothesis_Entry):
SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry );
SO_Hypothesis = myStudy.FindObjectID( Hypothesis_Entry );
if SO_MorSM is not None and SO_Hypothesis is not None :
#Find or Create Applied Hypothesis root
res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedHypothesis)
if AHR is None or res == 0:
AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis);
2004-06-18 14:34:31 +06:00
aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName");
# The same name as in SMESH_Mesh_i::AddHypothesis() ##################
aName.SetValue("Applied hypotheses");
aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable");
2003-05-19 20:07:00 +06:00
aSelAttr.SetSelectable(0);
2004-06-18 14:34:31 +06:00
aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap");
2003-05-19 20:07:00 +06:00
aPixmap.SetPixMap( "mesh_tree_hypo.png" );
2004-06-18 14:34:31 +06:00
# VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
else :
it = myStudy.NewChildIterator(AHR);
while it.More() :
res, Ref = it.Value().ReferencedObject();
if res and Ref is not None and Ref.GetID() == Hypothesis_Entry :
return;
it.Next();
# VSR ######################################################################
SO = myStudyBuilder.NewObject(AHR);
myStudyBuilder.Addreference (SO,SO_Hypothesis);
2003-05-19 20:07:00 +06:00
#------------------------------------------------------------
def SetAlgorithms(Mesh_Or_SubMesh_Entry, Algorithms_Entry):
SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
SO_Algorithms = myStudy.FindObjectID( Algorithms_Entry )
if SO_MorSM != None and SO_Algorithms != None :
#Find or Create Applied Algorithms root
res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedAlgorithms);
if AHR is None or res == 0:
AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms);
2004-06-18 14:34:31 +06:00
aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName");
# The same name as in SMESH_Mesh_i::AddHypothesis() ##################
aName.SetValue("Applied algorithms");
aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable");
2003-05-19 20:07:00 +06:00
aSelAttr.SetSelectable(0);
2004-06-18 14:34:31 +06:00
aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap");
2003-05-19 20:07:00 +06:00
aPixmap.SetPixMap( "mesh_tree_algo.png" );
2004-06-18 14:34:31 +06:00
# VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
else :
it = myStudy.NewChildIterator(AHR);
while it.More() :
res, Ref = it.Value().ReferencedObject();
if res and Ref is not None and Ref.GetID() == Algorithms_Entry :
return;
it.Next();
# VSR ######################################################################
2003-05-19 20:07:00 +06:00
SO = myStudyBuilder.NewObject(AHR);
myStudyBuilder.Addreference (SO,SO_Algorithms);
#------------------------------------------------------------
def UnSetHypothesis( Applied_Hypothesis_Entry ):
SO_Applied_Hypothesis = myStudy.FindObjectID( Applied_Hypothesis_Entry );
if SO_Applied_Hypothesis :
myStudyBuilder.RemoveObject(SO_Applied_Hypothesis);
#------------------------------------------------------------
def AddSubMesh ( SO_Mesh_Entry, SM_IOR, ST):
2004-06-18 14:34:31 +06:00
# VSR: added temporarily - objects are published automatically by the engine
aSO = myStudy.FindObjectIOR( SM_IOR )
if aSO is not None:
return aSO.GetID()
# VSR ######################################################################
2003-05-19 20:07:00 +06:00
SO_Mesh = myStudy.FindObjectID( SO_Mesh_Entry )
if ( SO_Mesh ) :
if ST == ShapeTypeCompSolid :
Tag_Shape = Tag_SubMeshOnSolid;
2004-06-18 14:34:31 +06:00
Name = "SubMeshes on Solid";
2003-05-19 20:07:00 +06:00
elif ST == ShapeTypeFace :
Tag_Shape = Tag_SubMeshOnFace;
2004-06-18 14:34:31 +06:00
Name = "SubMeshes on Face";
2003-05-19 20:07:00 +06:00
elif ST == ShapeTypeEdge :
Tag_Shape = Tag_SubMeshOnEdge;
2004-06-18 14:34:31 +06:00
Name = "SubMeshes on Edge";
2003-05-19 20:07:00 +06:00
elif ST == ShapeTypeVertex :
Tag_Shape = Tag_SubMeshOnVertex;
2004-06-18 14:34:31 +06:00
Name = "SubMeshes on Vertex";
2003-05-19 20:07:00 +06:00
else :
Tag_Shape = Tag_SubMeshOnCompound;
2004-06-18 14:34:31 +06:00
Name = "SubMeshes on Compound";
2003-05-19 20:07:00 +06:00
res, SubmeshesRoot = SO_Mesh.FindSubObject (Tag_Shape)
if SubmeshesRoot is None or res == 0:
SubmeshesRoot = myStudyBuilder.NewObjectToTag (SO_Mesh, Tag_Shape);
2004-06-18 14:34:31 +06:00
aName = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeName");
2003-05-19 20:07:00 +06:00
aName.SetValue(Name);
2004-06-18 14:34:31 +06:00
aSelAttr = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable");
2003-05-19 20:07:00 +06:00
aSelAttr.SetSelectable(0);
SO = myStudyBuilder.NewObject (SubmeshesRoot);
2004-06-18 14:34:31 +06:00
anIOR = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeIOR");
2003-05-19 20:07:00 +06:00
anIOR.SetValue(SM_IOR);
return SO.GetID();
return None;
#------------------------------------------------------------
def AddSubMeshOnShape (Mesh_Entry, GeomShape_Entry, SM_IOR, ST) :
2004-06-18 14:34:31 +06:00
# VSR: added temporarily - objects are published automatically by the engine
aSO = myStudy.FindObjectIOR( SM_IOR )
if aSO is not None:
return aSO.GetID()
# VSR ######################################################################
SO_GeomShape = myStudy.FindObjectID( GeomShape_Entry );
if SO_GeomShape != None :
SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST);
SO_SM = myStudy.FindObjectID( SM_Entry );
if SO_SM != None :
SetShape (GeomShape_Entry, SM_Entry);
return SM_Entry;
2003-05-19 20:07:00 +06:00
2004-06-18 14:34:31 +06:00
return None;
2003-05-19 20:07:00 +06:00
#------------------------------------------------------------
def SetName(Entry, Name):
SO = myStudy.FindObjectID( Entry );
if SO != None :
2004-06-18 14:34:31 +06:00
aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName");
2003-05-19 20:07:00 +06:00
aName.SetValue(Name);