1 # -*- coding: utf-8 -*-
4 ### This file is generated automatically by SALOME v7.7.1 with dump python functionality
11 theStudy = salome.myStudy
13 import salome_notebook
14 notebook = salome_notebook.NoteBook(theStudy)
21 from salome.geom import geomBuilder
24 import utilityFunctions as uF
25 from output import message
28 #rectangle.generate(data_longueur,data_largeur,data_centre,data_normale,data_direction,data_angle,data_rayon,rayon_entaille,extension,outFile)
30 def generate(data_longueur,data_largeur,data_centre,
31 data_normale,data_direction,data_angle,
32 data_rayon,rayon_entaille,outFile):
36 #data_centre = [0., 0., 0.]
37 #data_normale = [1., 2., 0.]
38 #data_direction = [0., 1., 5.]
43 #epsilon=numpy.max([data_longueur,data_largeur])*1.e-8
44 Brayon = data_rayon>1e-12
45 Bentaille = rayon_entaille>1e-12
48 maxSize=numpy.min([data_longueur,data_largeur])/4.
52 R=numpy.min([data_rayon,rayon_entaille])
53 chordal, minSize = uF.calcElemSize(A, R)
55 chordal, minSize = uF.calcElemSize(A, rayon_entaille)
59 chordal, minSize = uF.calcElemSize(A, data_rayon)
61 minSize=numpy.min([data_longueur,data_largeur])/10.
65 Vnormale, Vdirection, Vortho = uF.calcCoordVectors(data_normale, data_direction)
66 Vcentre = numpy.array(data_centre)
68 geompy = geomBuilder.New(theStudy)
70 O = geompy.MakeVertex(0, 0, 0)
71 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
72 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
73 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
74 CENTRE = geompy.MakeVertex(Vcentre[0], Vcentre[1], Vcentre[2])
75 NORMALE = geompy.MakeVectorDXDYDZ(Vnormale[0], Vnormale[1], Vnormale[2])
76 DIRECTION = geompy.MakeVectorDXDYDZ(Vdirection[0], Vdirection[1], Vdirection[2])
77 DIRECTION_op = geompy.MakeVectorDXDYDZ(-Vdirection[0], -Vdirection[1], -Vdirection[2])
78 V3 = geompy.MakeVectorDXDYDZ(Vortho[0], Vortho[1], Vortho[2])
79 V3_op = geompy.MakeVectorDXDYDZ(-Vortho[0], -Vortho[1], -Vortho[2])
81 VP1=Vcentre+Vdirection*data_longueur+Vortho*data_largeur
82 VP2=Vcentre-Vdirection*data_longueur+Vortho*data_largeur
83 VP3=Vcentre-Vdirection*data_longueur-Vortho*data_largeur
84 VP4=Vcentre+Vdirection*data_longueur-Vortho*data_largeur
86 Sommet_1 = geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
87 Sommet_2 = geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
88 Sommet_3 = geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
89 Sommet_4 = geompy.MakeVertex(VP4[0], VP4[1], VP4[2])
91 Ligne_1 = geompy.MakeLineTwoPnt(Sommet_1, Sommet_2)
92 Ligne_2 = geompy.MakeLineTwoPnt(Sommet_2, Sommet_3)
93 Ligne_3 = geompy.MakeLineTwoPnt(Sommet_3, Sommet_4)
94 Ligne_4 = geompy.MakeLineTwoPnt(Sommet_4, Sommet_1)
96 Contour_1 = geompy.MakeWire([Ligne_1, Ligne_2, Ligne_3, Ligne_4], 1e-07)
98 if Brayon or Bentaille:
99 vertexOfRect=geompy.SubShapeAllIDs(Contour_1, geompy.ShapeType["VERTEX"])
100 Contour_1 = geompy.MakeFillet1D(Contour_1, data_rayon + rayon_entaille, vertexOfRect)
103 RECTANGLE = geompy.MakeFaceWires([Contour_1], 1)
105 VP1=Vcentre+Vdirection*(data_longueur-rayon_entaille)+Vnormale*rayon_entaille
106 VP2=Vcentre+Vdirection*(data_longueur)
107 VP3=Vcentre+Vdirection*(data_longueur-rayon_entaille)-Vnormale*rayon_entaille
108 PE1=geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
109 PE2=geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
110 PE3=geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
111 ARC = geompy.MakeArc(PE1, PE2, PE3)
112 TUYAU = geompy.MakePipe(ARC, Contour_1)
113 subShapesList=geompy.GetFreeBoundary(TUYAU)[1]
114 entailleFace1 = geompy.MakeFaceWires([subShapesList[0]], 1)
115 entailleFace2 = geompy.MakeFaceWires([subShapesList[1]], 1)
116 RECTANGLE = geompy.MakeShell([TUYAU, entailleFace1, entailleFace2])
118 #edgesIDs = geompy.SubShapeAllIDs(RECTANGLE, geompy.ShapeType["EDGE"])
119 #edges = geompy.CreateGroup(RECTANGLE, geompy.ShapeType["EDGE"])
120 #geompy.UnionIDs(edges, edgesIDs)
121 #geompy.addToStudy( RECTANGLE, 'RECTANGLE' )
122 #geompy.addToStudyInFather( RECTANGLE , edges, 'edges' )
124 hauteur=data_longueur*1.1
128 extrusion=numpy.max([1.,rayon_entaille])*1.1
130 if ( (data_angle>(eps)) and (data_angle<(180.-eps)) ):
131 rayon2=hauteur*numpy.tan(data_angle*numpy.pi/180./2.)
133 B1=geompy.MakeTranslationVectorDistance(CENTRE,DIRECTION,hauteur)
134 B2=geompy.MakeTranslationVectorDistance(B1,V3,rayon2)
135 geompy.TranslateVectorDistance(B1,V3_op,rayon2, False)
136 LB01 = geompy.MakeLineTwoPnt(CENTRE, B1)
137 LB02 = geompy.MakeLineTwoPnt(CENTRE, B2)
138 LB12 = geompy.MakeLineTwoPnt(B1, B2)
139 plan_BOITE = geompy.MakeFaceWires([LB01, LB02, LB12], True)
140 extrusion=numpy.max([1.,rayon_entaille])*1.1
141 BOITE = geompy.MakePrismVecH2Ways(plan_BOITE, NORMALE, extrusion)
143 FACE_FISSURE = geompy.MakeCommonList([RECTANGLE, BOITE])
145 elif ( (data_angle>=(180.-eps)) and (data_angle<=(180.+eps)) ):
146 VP1=Vcentre+Vortho*data_largeur*1.1
147 VP2=Vcentre-Vortho*data_largeur*1.1
148 VP3=Vcentre-Vortho*data_largeur*1.1+Vdirection*data_longueur*1.1
149 VP4=Vcentre+Vortho*data_largeur*1.1+Vdirection*data_longueur*1.1
151 Sommet_5 = geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
152 Sommet_6 = geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
153 Sommet_7 = geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
154 Sommet_8 = geompy.MakeVertex(VP4[0], VP4[1], VP4[2])
156 Ligne_5 = geompy.MakeLineTwoPnt(Sommet_5, Sommet_6)
157 Ligne_6 = geompy.MakeLineTwoPnt(Sommet_6, Sommet_7)
158 Ligne_7 = geompy.MakeLineTwoPnt(Sommet_7, Sommet_8)
159 Ligne_8 = geompy.MakeLineTwoPnt(Sommet_8, Sommet_5)
161 Contour_2 = geompy.MakeWire([Ligne_5, Ligne_6, Ligne_7, Ligne_8], 1e-07)
162 Face_2 = geompy.MakeFaceWires([Contour_2], 1)
163 BOITE = geompy.MakePrismVecH2Ways(Face_2, NORMALE, extrusion)
164 FACE_FISSURE = geompy.MakeCommonList([RECTANGLE, BOITE])
166 #geompy.addToStudy( RECTANGLE, 'RECTANGLE' )
167 #geompy.addToStudy( BOITE, 'BOITE' )
168 #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
170 elif ( (data_angle>(180.+eps)) and (data_angle<(360.-eps)) ):
171 rayon2=hauteur*numpy.tan((360.-data_angle)*numpy.pi/180./2.)
172 B1=geompy.MakeTranslationVectorDistance(CENTRE,DIRECTION_op,hauteur)
173 B2=geompy.MakeTranslationVectorDistance(B1,V3,rayon2)
174 geompy.TranslateVectorDistance(B1,V3_op,rayon2, False)
175 LB01 = geompy.MakeLineTwoPnt(CENTRE, B1)
176 LB02 = geompy.MakeLineTwoPnt(CENTRE, B2)
177 LB12 = geompy.MakeLineTwoPnt(B1, B2)
178 plan_BOITE = geompy.MakeFaceWires([LB01, LB02, LB12], True)
179 extrusion=numpy.max([1.,rayon_entaille])*1.1
180 BOITE = geompy.MakePrismVecH2Ways(plan_BOITE, NORMALE, extrusion)
181 FACE_FISSURE = geompy.MakeCutList(RECTANGLE, [BOITE])
183 elif ( (data_angle<=(eps)) or (data_angle>=(360.-eps)) ):
185 FACE_FISSURE = RECTANGLE
188 message('E','Angle non prevu')
191 #newEdgesIDs = geompy.SubShapeAllIDs(FACE_FISSURE, geompy.ShapeType["EDGE"])
192 #newEdges = geompy.CreateGroup(FACE_FISSURE, geompy.ShapeType["EDGE"])
193 #geompy.UnionIDs(newEdges, newEdgesIDs)
195 #[oldEdges] = geompy.RestoreGivenSubShapes(FACE_FISSURE, [RECTANGLE, edges], GEOM.FSM_GetInPlace, True, False)
197 #toExtrude = geompy.CutListOfGroups([newEdges], [oldEdges])
199 #if extension>1.e-12:
200 #extrusion = geompy.MakePrismVecH(toExtrude, DIRECTION_op, extension)
202 #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, True)
204 #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, False)
206 #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
212 import SMESH, SALOMEDS
213 from salome.smesh import smeshBuilder
214 smesh = smeshBuilder.New(theStudy)
216 Maillage=uF.meshCrack(FACE_FISSURE, minSize, maxSize, chordal, dim)
219 Maillage.ExportMED( outFile, 0, SMESH.MED_V2_2, 1, None ,1)
220 smesh.SetName(Maillage.GetMesh(), 'MAILLAGE_FISSURE')
222 print 'ExportToMEDX() failed. Invalid file name?'
225 if salome.sg.hasDesktop():
226 salome.sg.updateObjBrowser(1)