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