Salome HOME
Merge remote branch 'origin/V8_5_asterstudy'
[modules/smesh.git] / src / Tools / ZCracksPlug / rectangle.py
1 # -*- coding: utf-8 -*-
2
3 ###
4 ### This file is generated automatically by SALOME v7.7.1 with dump python functionality
5 ###
6
7 import sys, numpy
8 import salome
9
10 salome.salome_init()
11
12 import salome_notebook
13 notebook = salome_notebook.NoteBook()
14
15 ###
16 ### GEOM component
17 ###
18
19 import GEOM
20 from salome.geom import geomBuilder
21 import math
22 import SALOMEDS
23 from . import utilityFunctions as uF
24 from .output import message
25
26 #import GEOM_Gen.ild
27 #rectangle.generate(data_longueur,data_largeur,data_centre,data_normale,data_direction,data_angle,data_rayon,rayon_entaille,extension,outFile)
28
29 def generate(data_longueur,data_largeur,data_centre,
30              data_normale,data_direction,data_angle,
31              data_rayon,rayon_entaille,outFile):
32
33 #data_longueur = 2.
34 #data_largeur = 1.
35 #data_centre = [0., 0., 0.]
36 #data_normale = [1., 2., 0.]
37 #data_direction = [0., 1., 5.]
38 #rayon_entaille=0.1
39 #data_angle=180.
40 #data_rayon=0.1
41 #extension=0.1
42   #epsilon=numpy.max([data_longueur,data_largeur])*1.e-8
43   Brayon = data_rayon>1e-12
44   Bentaille = rayon_entaille>1e-12
45
46   A=numpy.pi/(15.)
47   maxSize=numpy.min([data_longueur,data_largeur])/4.
48   if Bentaille:
49     dim=3
50     if Brayon:
51       R=numpy.min([data_rayon,rayon_entaille])
52       chordal, minSize = uF.calcElemSize(A, R)
53     else:
54       chordal, minSize = uF.calcElemSize(A, rayon_entaille)
55   else:
56     dim=2
57     if Brayon:
58       chordal, minSize = uF.calcElemSize(A, data_rayon)
59     else:
60       minSize=numpy.min([data_longueur,data_largeur])/10.
61       maxSize=minSize
62       chordal=1.
63
64   Vnormale, Vdirection, Vortho = uF.calcCoordVectors(data_normale, data_direction)
65   Vcentre = numpy.array(data_centre)
66
67   geompy = geomBuilder.New()
68
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])
79
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
84
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])
89
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)
94   
95   Contour_1 = geompy.MakeWire([Ligne_1, Ligne_2, Ligne_3, Ligne_4], 1e-07)
96
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)
100
101   if not Bentaille:
102     RECTANGLE = geompy.MakeFaceWires([Contour_1], 1)
103   else:
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])
116
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' )
122
123   hauteur=data_longueur*1.1
124
125   eps=1.E-05
126   bool_boite=True
127   extrusion=numpy.max([1.,rayon_entaille])*1.1
128
129   if ( (data_angle>(eps)) and (data_angle<(180.-eps)) ):
130     rayon2=hauteur*numpy.tan(data_angle*numpy.pi/180./2.)
131
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)
141
142     FACE_FISSURE = geompy.MakeCommonList([RECTANGLE, BOITE])
143
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
149
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])
154
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)
159
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])
164
165     #geompy.addToStudy( RECTANGLE, 'RECTANGLE' )
166     #geompy.addToStudy( BOITE, 'BOITE' )
167     #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
168
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])
181
182   elif ( (data_angle<=(eps)) or (data_angle>=(360.-eps)) ):
183     bool_boite=False
184     FACE_FISSURE = RECTANGLE
185
186   else:
187     message('E','Angle non prevu')
188
189   #if bool_boite:
190     #newEdgesIDs = geompy.SubShapeAllIDs(FACE_FISSURE, geompy.ShapeType["EDGE"])
191     #newEdges = geompy.CreateGroup(FACE_FISSURE, geompy.ShapeType["EDGE"])
192     #geompy.UnionIDs(newEdges, newEdgesIDs)
193
194     #[oldEdges] = geompy.RestoreGivenSubShapes(FACE_FISSURE, [RECTANGLE, edges], GEOM.FSM_GetInPlace, True, False)
195
196     #toExtrude = geompy.CutListOfGroups([newEdges], [oldEdges])
197
198     #if extension>1.e-12:
199       #extrusion = geompy.MakePrismVecH(toExtrude, DIRECTION_op, extension)
200       #try:
201         #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, True)
202       #except:
203         #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, False)
204
205   #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
206
207   #
208   # SMESH component
209   #
210
211   import  SMESH, SALOMEDS
212   from salome.smesh import smeshBuilder
213   smesh = smeshBuilder.New()
214
215   Maillage=uF.meshCrack(FACE_FISSURE, minSize, maxSize, chordal, dim)
216
217   try:
218     Maillage.ExportMED(outFile)
219     smesh.SetName(Maillage.GetMesh(), 'MAILLAGE_FISSURE')
220   except:
221     print('ExportMED() failed. Invalid file name?')
222
223
224   if salome.sg.hasDesktop():
225     salome.sg.updateObjBrowser()