Salome HOME
Increment version: 9.9.0
[plugins/hybridplugin.git] / bin / createGroupsOnEntitiesFromGMFFile.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014-2021  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 """
22 to create Groups On Entities From GMFFile /tmp/tmp.mesh
23 """
24
25 import sys
26 import salome
27
28 salome.salome_init()
29 theStudy = salome.myStudy
30
31 import salome_notebook
32 notebook = salome_notebook.NoteBook(theStudy)
33 #sys.path.insert( 0, r'/somewhere')
34
35 ###
36 ### GEOM component
37 ###
38
39 import GEOM
40 from salome.geom import geomBuilder
41 import math
42 import SALOMEDS
43 import  SMESH, SALOMEDS
44
45 from salome.smesh import smeshBuilder
46
47 smesh = smeshBuilder.New(theStudy)
48
49   
50 nameFile = None
51 the_mesh = None
52
53 nameFile = r'/tmp/tmp.mesh'
54
55 if nameFile != None:
56   #do not work (the_mesh, error) = smesh.CreateMeshesFromMED(nameFile)
57   (the_mesh, error) = smesh.CreateMeshesFromGMF(nameFile)
58
59
60 #print "the_mesh", the_mesh
61
62 if the_mesh != None:
63   blue = SALOMEDS.Color(0,0,1)
64   red = SALOMEDS.Color(1,0,0)
65   green = SALOMEDS.Color(0,1,0)
66   yellow = SALOMEDS.Color(1,1,0)
67
68   for i in dir(SMESH):
69     if "Entity_" in i: print(i)
70
71   entities = [("Tetra", SMESH.Entity_Tetra, blue), 
72               ("Pyramid", SMESH.Entity_Pyramid, red), 
73               ("Prism", SMESH.Entity_Penta, yellow),
74               ("Hexa", SMESH.Entity_Hexa, green)]
75
76   for name, entity, color in entities:
77     aCriteria = []
78     aCriterion = smesh.GetCriterion(SMESH.VOLUME,SMESH.FT_EntityType,SMESH.FT_Undefined,entity)
79     aCriteria.append(aCriterion)
80     aFilter = smesh.GetFilterFromCriteria(aCriteria)
81     aFilter.SetMesh(the_mesh.GetMesh())
82     Group = the_mesh.GroupOnFilter( SMESH.VOLUME, name, aFilter )
83     Group.SetColor( color )
84   
85   if salome.sg.hasDesktop():
86     salome.sg.updateObjBrowser(True)