Salome HOME
Update of CheckDone
[modules/smesh.git] / src / Tools / ZCracksPlug / rectangle.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2016-2022  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 ### This file is generated automatically by SALOME v7.7.1 with dump python functionality
23 ###
24
25 import sys, numpy
26 import salome
27
28 salome.salome_init()
29
30 import salome_notebook
31 notebook = salome_notebook.NoteBook()
32
33 ###
34 ### GEOM component
35 ###
36
37 import GEOM
38 from salome.geom import geomBuilder
39 import math
40 import SALOMEDS
41 from . import utilityFunctions as uF
42 from .output import message
43
44 #import GEOM_Gen.ild
45 #rectangle.generate(data_longueur,data_largeur,data_centre,data_normale,data_direction,data_angle,data_rayon,rayon_entaille,extension,outFile)
46
47 def generate(data_longueur,data_largeur,data_centre,
48              data_normale,data_direction,data_angle,
49              data_rayon,rayon_entaille,outFile):
50
51 #data_longueur = 2.
52 #data_largeur = 1.
53 #data_centre = [0., 0., 0.]
54 #data_normale = [1., 2., 0.]
55 #data_direction = [0., 1., 5.]
56 #rayon_entaille=0.1
57 #data_angle=180.
58 #data_rayon=0.1
59 #extension=0.1
60   #epsilon=numpy.max([data_longueur,data_largeur])*1.e-8
61   Brayon = data_rayon>1e-12
62   Bentaille = rayon_entaille>1e-12
63
64   A=numpy.pi/(15.)
65   maxSize=numpy.min([data_longueur,data_largeur])/4.
66   if Bentaille:
67     dim=3
68     if Brayon:
69       R=numpy.min([data_rayon,rayon_entaille])
70       chordal, minSize = uF.calcElemSize(A, R)
71     else:
72       chordal, minSize = uF.calcElemSize(A, rayon_entaille)
73   else:
74     dim=2
75     if Brayon:
76       chordal, minSize = uF.calcElemSize(A, data_rayon)
77     else:
78       minSize=numpy.min([data_longueur,data_largeur])/10.
79       maxSize=minSize
80       chordal=1.
81
82   Vnormale, Vdirection, Vortho = uF.calcCoordVectors(data_normale, data_direction)
83   Vcentre = numpy.array(data_centre)
84
85   geompy = geomBuilder.New()
86
87   O = geompy.MakeVertex(0, 0, 0)
88   OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
89   OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
90   OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
91   CENTRE = geompy.MakeVertex(Vcentre[0], Vcentre[1], Vcentre[2])
92   NORMALE = geompy.MakeVectorDXDYDZ(Vnormale[0], Vnormale[1], Vnormale[2])
93   DIRECTION = geompy.MakeVectorDXDYDZ(Vdirection[0], Vdirection[1], Vdirection[2])
94   DIRECTION_op = geompy.MakeVectorDXDYDZ(-Vdirection[0], -Vdirection[1], -Vdirection[2])
95   V3 = geompy.MakeVectorDXDYDZ(Vortho[0], Vortho[1], Vortho[2])
96   V3_op = geompy.MakeVectorDXDYDZ(-Vortho[0], -Vortho[1], -Vortho[2])
97
98   VP1=Vcentre+Vdirection*data_longueur+Vortho*data_largeur
99   VP2=Vcentre-Vdirection*data_longueur+Vortho*data_largeur
100   VP3=Vcentre-Vdirection*data_longueur-Vortho*data_largeur
101   VP4=Vcentre+Vdirection*data_longueur-Vortho*data_largeur
102
103   Sommet_1 = geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
104   Sommet_2 = geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
105   Sommet_3 = geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
106   Sommet_4 = geompy.MakeVertex(VP4[0], VP4[1], VP4[2])
107
108   Ligne_1 = geompy.MakeLineTwoPnt(Sommet_1, Sommet_2)
109   Ligne_2 = geompy.MakeLineTwoPnt(Sommet_2, Sommet_3)
110   Ligne_3 = geompy.MakeLineTwoPnt(Sommet_3, Sommet_4)
111   Ligne_4 = geompy.MakeLineTwoPnt(Sommet_4, Sommet_1)
112   
113   Contour_1 = geompy.MakeWire([Ligne_1, Ligne_2, Ligne_3, Ligne_4], 1e-07)
114
115   if Brayon or Bentaille:
116     vertexOfRect=geompy.SubShapeAllIDs(Contour_1, geompy.ShapeType["VERTEX"])
117     Contour_1 = geompy.MakeFillet1D(Contour_1, data_rayon + rayon_entaille, vertexOfRect)
118
119   if not Bentaille:
120     RECTANGLE = geompy.MakeFaceWires([Contour_1], 1)
121   else:
122     VP1=Vcentre+Vdirection*(data_longueur-rayon_entaille)+Vnormale*rayon_entaille
123     VP2=Vcentre+Vdirection*(data_longueur)
124     VP3=Vcentre+Vdirection*(data_longueur-rayon_entaille)-Vnormale*rayon_entaille
125     PE1=geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
126     PE2=geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
127     PE3=geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
128     ARC = geompy.MakeArc(PE1, PE2, PE3)
129     TUYAU = geompy.MakePipe(ARC, Contour_1)
130     subShapesList=geompy.GetFreeBoundary(TUYAU)[1]
131     entailleFace1 = geompy.MakeFaceWires([subShapesList[0]], 1)
132     entailleFace2 = geompy.MakeFaceWires([subShapesList[1]], 1)
133     RECTANGLE = geompy.MakeShell([TUYAU, entailleFace1, entailleFace2])
134
135   #edgesIDs = geompy.SubShapeAllIDs(RECTANGLE, geompy.ShapeType["EDGE"])
136   #edges = geompy.CreateGroup(RECTANGLE, geompy.ShapeType["EDGE"])
137   #geompy.UnionIDs(edges, edgesIDs)
138   #geompy.addToStudy( RECTANGLE, 'RECTANGLE' )
139   #geompy.addToStudyInFather( RECTANGLE , edges, 'edges' )
140
141   hauteur=data_longueur*1.1
142
143   eps=1.E-05
144   bool_boite=True
145   extrusion=numpy.max([1.,rayon_entaille])*1.1
146
147   if ( (data_angle>(eps)) and (data_angle<(180.-eps)) ):
148     rayon2=hauteur*numpy.tan(data_angle*numpy.pi/180./2.)
149
150     B1=geompy.MakeTranslationVectorDistance(CENTRE,DIRECTION,hauteur)
151     B2=geompy.MakeTranslationVectorDistance(B1,V3,rayon2)
152     geompy.TranslateVectorDistance(B1,V3_op,rayon2, False)
153     LB01 = geompy.MakeLineTwoPnt(CENTRE, B1)
154     LB02 = geompy.MakeLineTwoPnt(CENTRE, B2)
155     LB12 = geompy.MakeLineTwoPnt(B1, B2)
156     plan_BOITE = geompy.MakeFaceWires([LB01, LB02, LB12], True)
157     extrusion=numpy.max([1.,rayon_entaille])*1.1
158     BOITE = geompy.MakePrismVecH2Ways(plan_BOITE, NORMALE, extrusion)
159
160     FACE_FISSURE = geompy.MakeCommonList([RECTANGLE, BOITE])
161
162   elif ( (data_angle>=(180.-eps)) and (data_angle<=(180.+eps)) ):
163     VP1=Vcentre+Vortho*data_largeur*1.1
164     VP2=Vcentre-Vortho*data_largeur*1.1
165     VP3=Vcentre-Vortho*data_largeur*1.1+Vdirection*data_longueur*1.1
166     VP4=Vcentre+Vortho*data_largeur*1.1+Vdirection*data_longueur*1.1
167
168     Sommet_5 = geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
169     Sommet_6 = geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
170     Sommet_7 = geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
171     Sommet_8 = geompy.MakeVertex(VP4[0], VP4[1], VP4[2])
172
173     Ligne_5 = geompy.MakeLineTwoPnt(Sommet_5, Sommet_6)
174     Ligne_6 = geompy.MakeLineTwoPnt(Sommet_6, Sommet_7)
175     Ligne_7 = geompy.MakeLineTwoPnt(Sommet_7, Sommet_8)
176     Ligne_8 = geompy.MakeLineTwoPnt(Sommet_8, Sommet_5)
177
178     Contour_2 = geompy.MakeWire([Ligne_5, Ligne_6, Ligne_7, Ligne_8], 1e-07)
179     Face_2 = geompy.MakeFaceWires([Contour_2], 1)
180     BOITE = geompy.MakePrismVecH2Ways(Face_2, NORMALE, extrusion)
181     FACE_FISSURE = geompy.MakeCommonList([RECTANGLE, BOITE])
182
183     #geompy.addToStudy( RECTANGLE, 'RECTANGLE' )
184     #geompy.addToStudy( BOITE, 'BOITE' )
185     #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
186
187   elif ( (data_angle>(180.+eps)) and (data_angle<(360.-eps)) ):
188     rayon2=hauteur*numpy.tan((360.-data_angle)*numpy.pi/180./2.)
189     B1=geompy.MakeTranslationVectorDistance(CENTRE,DIRECTION_op,hauteur)
190     B2=geompy.MakeTranslationVectorDistance(B1,V3,rayon2)
191     geompy.TranslateVectorDistance(B1,V3_op,rayon2, False)
192     LB01 = geompy.MakeLineTwoPnt(CENTRE, B1)
193     LB02 = geompy.MakeLineTwoPnt(CENTRE, B2)
194     LB12 = geompy.MakeLineTwoPnt(B1, B2)
195     plan_BOITE = geompy.MakeFaceWires([LB01, LB02, LB12], True)
196     extrusion=numpy.max([1.,rayon_entaille])*1.1
197     BOITE = geompy.MakePrismVecH2Ways(plan_BOITE, NORMALE, extrusion)
198     FACE_FISSURE = geompy.MakeCutList(RECTANGLE, [BOITE])
199
200   elif ( (data_angle<=(eps)) or (data_angle>=(360.-eps)) ):
201     bool_boite=False
202     FACE_FISSURE = RECTANGLE
203
204   else:
205     message('E','Angle non prevu')
206
207   #if bool_boite:
208     #newEdgesIDs = geompy.SubShapeAllIDs(FACE_FISSURE, geompy.ShapeType["EDGE"])
209     #newEdges = geompy.CreateGroup(FACE_FISSURE, geompy.ShapeType["EDGE"])
210     #geompy.UnionIDs(newEdges, newEdgesIDs)
211
212     #[oldEdges] = geompy.RestoreGivenSubShapes(FACE_FISSURE, [RECTANGLE, edges], GEOM.FSM_GetInPlace, True, False)
213
214     #toExtrude = geompy.CutListOfGroups([newEdges], [oldEdges])
215
216     #if extension>1.e-12:
217       #extrusion = geompy.MakePrismVecH(toExtrude, DIRECTION_op, extension)
218       #try:
219         #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, True)
220       #except:
221         #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, False)
222
223   #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
224
225   #
226   # SMESH component
227   #
228
229   import  SMESH, SALOMEDS
230   from salome.smesh import smeshBuilder
231   smesh = smeshBuilder.New()
232
233   Maillage=uF.meshCrack(FACE_FISSURE, minSize, maxSize, chordal, dim)
234
235   try:
236     Maillage.ExportMED(outFile)
237     smesh.SetName(Maillage.GetMesh(), 'MAILLAGE_FISSURE')
238   except:
239     print('ExportMED() failed. Invalid file name?')
240
241
242   if salome.sg.hasDesktop():
243     salome.sg.updateObjBrowser()