1 # -*- coding: utf-8 -*-
4 ### This file is generated automatically by SALOME v7.7.1 with dump python functionality
12 import salome_notebook
13 notebook = salome_notebook.NoteBook()
20 from salome.geom import geomBuilder
23 from . import utilityFunctions as uF
24 from .output import message
27 #rectangle.generate(data_longueur,data_largeur,data_centre,data_normale,data_direction,data_angle,data_rayon,rayon_entaille,extension,outFile)
29 def generate(data_longueur,data_largeur,data_centre,
30 data_normale,data_direction,data_angle,
31 data_rayon,rayon_entaille,outFile):
35 #data_centre = [0., 0., 0.]
36 #data_normale = [1., 2., 0.]
37 #data_direction = [0., 1., 5.]
42 #epsilon=numpy.max([data_longueur,data_largeur])*1.e-8
43 Brayon = data_rayon>1e-12
44 Bentaille = rayon_entaille>1e-12
47 maxSize=numpy.min([data_longueur,data_largeur])/4.
51 R=numpy.min([data_rayon,rayon_entaille])
52 chordal, minSize = uF.calcElemSize(A, R)
54 chordal, minSize = uF.calcElemSize(A, rayon_entaille)
58 chordal, minSize = uF.calcElemSize(A, data_rayon)
60 minSize=numpy.min([data_longueur,data_largeur])/10.
64 Vnormale, Vdirection, Vortho = uF.calcCoordVectors(data_normale, data_direction)
65 Vcentre = numpy.array(data_centre)
67 geompy = geomBuilder.New()
69 O = geompy.MakeVertex(0, 0, 0)
70 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
71 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
72 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
73 CENTRE = geompy.MakeVertex(Vcentre[0], Vcentre[1], Vcentre[2])
74 NORMALE = geompy.MakeVectorDXDYDZ(Vnormale[0], Vnormale[1], Vnormale[2])
75 DIRECTION = geompy.MakeVectorDXDYDZ(Vdirection[0], Vdirection[1], Vdirection[2])
76 DIRECTION_op = geompy.MakeVectorDXDYDZ(-Vdirection[0], -Vdirection[1], -Vdirection[2])
77 V3 = geompy.MakeVectorDXDYDZ(Vortho[0], Vortho[1], Vortho[2])
78 V3_op = geompy.MakeVectorDXDYDZ(-Vortho[0], -Vortho[1], -Vortho[2])
80 VP1=Vcentre+Vdirection*data_longueur+Vortho*data_largeur
81 VP2=Vcentre-Vdirection*data_longueur+Vortho*data_largeur
82 VP3=Vcentre-Vdirection*data_longueur-Vortho*data_largeur
83 VP4=Vcentre+Vdirection*data_longueur-Vortho*data_largeur
85 Sommet_1 = geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
86 Sommet_2 = geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
87 Sommet_3 = geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
88 Sommet_4 = geompy.MakeVertex(VP4[0], VP4[1], VP4[2])
90 Ligne_1 = geompy.MakeLineTwoPnt(Sommet_1, Sommet_2)
91 Ligne_2 = geompy.MakeLineTwoPnt(Sommet_2, Sommet_3)
92 Ligne_3 = geompy.MakeLineTwoPnt(Sommet_3, Sommet_4)
93 Ligne_4 = geompy.MakeLineTwoPnt(Sommet_4, Sommet_1)
95 Contour_1 = geompy.MakeWire([Ligne_1, Ligne_2, Ligne_3, Ligne_4], 1e-07)
97 if Brayon or Bentaille:
98 vertexOfRect=geompy.SubShapeAllIDs(Contour_1, geompy.ShapeType["VERTEX"])
99 Contour_1 = geompy.MakeFillet1D(Contour_1, data_rayon + rayon_entaille, vertexOfRect)
102 RECTANGLE = geompy.MakeFaceWires([Contour_1], 1)
104 VP1=Vcentre+Vdirection*(data_longueur-rayon_entaille)+Vnormale*rayon_entaille
105 VP2=Vcentre+Vdirection*(data_longueur)
106 VP3=Vcentre+Vdirection*(data_longueur-rayon_entaille)-Vnormale*rayon_entaille
107 PE1=geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
108 PE2=geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
109 PE3=geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
110 ARC = geompy.MakeArc(PE1, PE2, PE3)
111 TUYAU = geompy.MakePipe(ARC, Contour_1)
112 subShapesList=geompy.GetFreeBoundary(TUYAU)[1]
113 entailleFace1 = geompy.MakeFaceWires([subShapesList[0]], 1)
114 entailleFace2 = geompy.MakeFaceWires([subShapesList[1]], 1)
115 RECTANGLE = geompy.MakeShell([TUYAU, entailleFace1, entailleFace2])
117 #edgesIDs = geompy.SubShapeAllIDs(RECTANGLE, geompy.ShapeType["EDGE"])
118 #edges = geompy.CreateGroup(RECTANGLE, geompy.ShapeType["EDGE"])
119 #geompy.UnionIDs(edges, edgesIDs)
120 #geompy.addToStudy( RECTANGLE, 'RECTANGLE' )
121 #geompy.addToStudyInFather( RECTANGLE , edges, 'edges' )
123 hauteur=data_longueur*1.1
127 extrusion=numpy.max([1.,rayon_entaille])*1.1
129 if ( (data_angle>(eps)) and (data_angle<(180.-eps)) ):
130 rayon2=hauteur*numpy.tan(data_angle*numpy.pi/180./2.)
132 B1=geompy.MakeTranslationVectorDistance(CENTRE,DIRECTION,hauteur)
133 B2=geompy.MakeTranslationVectorDistance(B1,V3,rayon2)
134 geompy.TranslateVectorDistance(B1,V3_op,rayon2, False)
135 LB01 = geompy.MakeLineTwoPnt(CENTRE, B1)
136 LB02 = geompy.MakeLineTwoPnt(CENTRE, B2)
137 LB12 = geompy.MakeLineTwoPnt(B1, B2)
138 plan_BOITE = geompy.MakeFaceWires([LB01, LB02, LB12], True)
139 extrusion=numpy.max([1.,rayon_entaille])*1.1
140 BOITE = geompy.MakePrismVecH2Ways(plan_BOITE, NORMALE, extrusion)
142 FACE_FISSURE = geompy.MakeCommonList([RECTANGLE, BOITE])
144 elif ( (data_angle>=(180.-eps)) and (data_angle<=(180.+eps)) ):
145 VP1=Vcentre+Vortho*data_largeur*1.1
146 VP2=Vcentre-Vortho*data_largeur*1.1
147 VP3=Vcentre-Vortho*data_largeur*1.1+Vdirection*data_longueur*1.1
148 VP4=Vcentre+Vortho*data_largeur*1.1+Vdirection*data_longueur*1.1
150 Sommet_5 = geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
151 Sommet_6 = geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
152 Sommet_7 = geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
153 Sommet_8 = geompy.MakeVertex(VP4[0], VP4[1], VP4[2])
155 Ligne_5 = geompy.MakeLineTwoPnt(Sommet_5, Sommet_6)
156 Ligne_6 = geompy.MakeLineTwoPnt(Sommet_6, Sommet_7)
157 Ligne_7 = geompy.MakeLineTwoPnt(Sommet_7, Sommet_8)
158 Ligne_8 = geompy.MakeLineTwoPnt(Sommet_8, Sommet_5)
160 Contour_2 = geompy.MakeWire([Ligne_5, Ligne_6, Ligne_7, Ligne_8], 1e-07)
161 Face_2 = geompy.MakeFaceWires([Contour_2], 1)
162 BOITE = geompy.MakePrismVecH2Ways(Face_2, NORMALE, extrusion)
163 FACE_FISSURE = geompy.MakeCommonList([RECTANGLE, BOITE])
165 #geompy.addToStudy( RECTANGLE, 'RECTANGLE' )
166 #geompy.addToStudy( BOITE, 'BOITE' )
167 #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
169 elif ( (data_angle>(180.+eps)) and (data_angle<(360.-eps)) ):
170 rayon2=hauteur*numpy.tan((360.-data_angle)*numpy.pi/180./2.)
171 B1=geompy.MakeTranslationVectorDistance(CENTRE,DIRECTION_op,hauteur)
172 B2=geompy.MakeTranslationVectorDistance(B1,V3,rayon2)
173 geompy.TranslateVectorDistance(B1,V3_op,rayon2, False)
174 LB01 = geompy.MakeLineTwoPnt(CENTRE, B1)
175 LB02 = geompy.MakeLineTwoPnt(CENTRE, B2)
176 LB12 = geompy.MakeLineTwoPnt(B1, B2)
177 plan_BOITE = geompy.MakeFaceWires([LB01, LB02, LB12], True)
178 extrusion=numpy.max([1.,rayon_entaille])*1.1
179 BOITE = geompy.MakePrismVecH2Ways(plan_BOITE, NORMALE, extrusion)
180 FACE_FISSURE = geompy.MakeCutList(RECTANGLE, [BOITE])
182 elif ( (data_angle<=(eps)) or (data_angle>=(360.-eps)) ):
184 FACE_FISSURE = RECTANGLE
187 message('E','Angle non prevu')
190 #newEdgesIDs = geompy.SubShapeAllIDs(FACE_FISSURE, geompy.ShapeType["EDGE"])
191 #newEdges = geompy.CreateGroup(FACE_FISSURE, geompy.ShapeType["EDGE"])
192 #geompy.UnionIDs(newEdges, newEdgesIDs)
194 #[oldEdges] = geompy.RestoreGivenSubShapes(FACE_FISSURE, [RECTANGLE, edges], GEOM.FSM_GetInPlace, True, False)
196 #toExtrude = geompy.CutListOfGroups([newEdges], [oldEdges])
198 #if extension>1.e-12:
199 #extrusion = geompy.MakePrismVecH(toExtrude, DIRECTION_op, extension)
201 #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, True)
203 #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, False)
205 #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
211 import SMESH, SALOMEDS
212 from salome.smesh import smeshBuilder
213 smesh = smeshBuilder.New()
215 Maillage=uF.meshCrack(FACE_FISSURE, minSize, maxSize, chordal, dim)
218 Maillage.ExportMED(outFile)
219 smesh.SetName(Maillage.GetMesh(), 'MAILLAGE_FISSURE')
221 print('ExportMED() failed. Invalid file name?')
224 if salome.sg.hasDesktop():
225 salome.sg.updateObjBrowser()