Salome HOME
Update copyrights
[modules/smesh.git] / src / Tools / ZCracksPlug / ellipse.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2016-2019  CEA/DEN, 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
26 import sys, numpy
27 import salome
28
29 salome.salome_init()
30
31 import salome_notebook
32 notebook = salome_notebook.NoteBook()
33
34 ###
35 ### GEOM component
36 ###
37
38 import GEOM
39 from salome.geom import geomBuilder
40 import math
41 import SALOMEDS
42 from . import utilityFunctions as uF
43 from .output import message
44
45 #ellipse.generate(data_demi_grand_axe, data_centre, data_normale,data_direction, data_demi_petit_axe, data_angle, rayon_entaille,extension, outFile)
46 #if True:
47   #data_demi_grand_axe = 2.
48   #data_centre = [0., 0., 0.]
49   #data_normale = [1., 0., 0.]
50   #data_direction = [0., 1., 0.]
51   #data_demi_petit_axe = 1.
52   #data_angle=180.
53   #rayon_entaille=0.1
54   #extension=0.1
55   #outFile='/home/I60976/00_PROJETS/2015_INTEGRATION_ZCRACKS/zcracks_salome/test.med'
56
57
58 def generate(data_demi_grand_axe, data_centre, data_normale,
59              data_direction, data_demi_petit_axe, data_angle,
60              rayon_entaille, extension, outFile):
61
62   Vnormale, Vdirection, Vortho = uF.calcCoordVectors(data_normale, data_direction)
63   Vcentre = numpy.array(data_centre)
64
65   geompy = geomBuilder.New()
66
67   O = geompy.MakeVertex(0, 0, 0)
68   OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
69   OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
70   OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
71   CENTRE = geompy.MakeVertex(Vcentre[0], Vcentre[1], Vcentre[2])
72   NORMALE = geompy.MakeVectorDXDYDZ(Vnormale[0], Vnormale[1], Vnormale[2])
73   DIRECTION = geompy.MakeVectorDXDYDZ(Vdirection[0], Vdirection[1], Vdirection[2])
74   DIRECTION_op = geompy.MakeVectorDXDYDZ(-Vdirection[0], -Vdirection[1], -Vdirection[2])
75   V3 = geompy.MakeVectorDXDYDZ(Vortho[0], Vortho[1], Vortho[2])
76   V3_op = geompy.MakeVectorDXDYDZ(-Vortho[0], -Vortho[1], -Vortho[2])
77   if data_demi_grand_axe >= data_demi_petit_axe:
78     ELLIPSE = geompy.MakeEllipse(CENTRE, NORMALE, data_demi_grand_axe, data_demi_petit_axe, DIRECTION)
79   else:
80     ELLIPSE = geompy.MakeEllipse(CENTRE, NORMALE, data_demi_petit_axe, data_demi_grand_axe, V3)
81
82   if rayon_entaille<1.e-12:
83     FELLIPSE = geompy.MakeFaceWires([ELLIPSE], 1)
84     dim=2
85   else:
86     dim=3
87     VP1=Vcentre+Vdirection*(data_demi_grand_axe-rayon_entaille)+Vnormale*rayon_entaille
88     VP2=Vcentre+Vdirection*(data_demi_grand_axe)
89     VP3=Vcentre+Vdirection*(data_demi_grand_axe-rayon_entaille)-Vnormale*rayon_entaille
90     PE1=geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
91     PE2=geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
92     PE3=geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
93     ARC = geompy.MakeArc(PE1, PE2, PE3)
94     TUYAU = geompy.MakePipe(ARC, ELLIPSE)
95     subShapesList=geompy.GetFreeBoundary(TUYAU)[1]
96     entailleFace1 = geompy.MakeFaceWires([subShapesList[0]], 1)
97     entailleFace2 = geompy.MakeFaceWires([subShapesList[1]], 1)
98     FELLIPSE = geompy.MakeShell([TUYAU, entailleFace1, entailleFace2])
99
100   edgesIDs = geompy.SubShapeAllIDs(FELLIPSE, geompy.ShapeType["EDGE"])
101   edges = geompy.CreateGroup(FELLIPSE, geompy.ShapeType["EDGE"])
102   geompy.UnionIDs(edges, edgesIDs)
103   geompy.addToStudy( FELLIPSE, 'FELLIPSE' )
104   geompy.addToStudyInFather( FELLIPSE , edges, 'edges' )
105
106   hauteur=numpy.max([data_demi_grand_axe,data_demi_petit_axe])*1.1
107
108   eps=1.E-05
109   bool_boite=True
110   extrusion=numpy.max([1.,rayon_entaille])*1.1
111   if ( (data_angle>(eps)) and (data_angle<(180.-eps)) ):
112     rayon2=hauteur*numpy.tan(data_angle*numpy.pi/180./2.)
113
114     B1=geompy.MakeTranslationVectorDistance(CENTRE,DIRECTION,hauteur)
115     B2=geompy.MakeTranslationVectorDistance(B1,V3,rayon2)
116     geompy.TranslateVectorDistance(B1,V3_op,rayon2, False)
117     LB01 = geompy.MakeLineTwoPnt(CENTRE, B1)
118     LB02 = geompy.MakeLineTwoPnt(CENTRE, B2)
119     LB12 = geompy.MakeLineTwoPnt(B1, B2)
120     plan_BOITE = geompy.MakeFaceWires([LB01, LB02, LB12], True)
121
122     BOITE = geompy.MakePrismVecH2Ways(plan_BOITE, NORMALE, extrusion)
123
124     FACE_FISSURE = geompy.MakeCommonList([FELLIPSE, BOITE])
125
126   elif ( (data_angle>=(180.-eps)) and (data_angle<=(180.+eps)) ):
127     VP1=Vcentre+Vortho*hauteur
128     VP2=Vcentre-Vortho*hauteur
129     VP3=Vcentre-Vortho*hauteur+Vdirection*hauteur
130     VP4=Vcentre+Vortho*hauteur+Vdirection*hauteur
131
132     Sommet_1 = geompy.MakeVertex(VP1[0], VP1[1], VP1[2])
133     Sommet_2 = geompy.MakeVertex(VP2[0], VP2[1], VP2[2])
134     Sommet_3 = geompy.MakeVertex(VP3[0], VP3[1], VP3[2])
135     Sommet_4 = geompy.MakeVertex(VP4[0], VP4[1], VP4[2])
136
137     Ligne_1 = geompy.MakeLineTwoPnt(Sommet_1, Sommet_2)
138     Ligne_2 = geompy.MakeLineTwoPnt(Sommet_2, Sommet_3)
139     Ligne_3 = geompy.MakeLineTwoPnt(Sommet_3, Sommet_4)
140     Ligne_4 = geompy.MakeLineTwoPnt(Sommet_4, Sommet_1)
141
142     Contour_1 = geompy.MakeWire([Ligne_1, Ligne_2, Ligne_3, Ligne_4], 1e-07)
143     Face_1 = geompy.MakeFaceWires([Contour_1], 1)
144     BOITE = geompy.MakePrismVecH2Ways(Face_1, NORMALE, extrusion)
145     FACE_FISSURE = geompy.MakeCommonList([FELLIPSE, BOITE])
146
147   elif ( (data_angle>(180.+eps)) and (data_angle<(360.-eps)) ):
148     rayon2=hauteur*numpy.tan((360.-data_angle)*numpy.pi/180./2.)
149
150     B1=geompy.MakeTranslationVectorDistance(CENTRE,DIRECTION_op,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.MakeCutList(FELLIPSE, [BOITE])
161
162   elif ( (data_angle<=(eps)) or (data_angle>=(360.-eps)) ):
163     bool_boite=False
164     FACE_FISSURE = FELLIPSE
165
166   else:
167     message('E','Angle non prevu')
168
169   if bool_boite:
170     #geompy.addToStudy( BOITE, 'BOITE' )
171     newEdgesIDs = geompy.SubShapeAllIDs(FACE_FISSURE, geompy.ShapeType["EDGE"])
172     newEdges = geompy.CreateGroup(FACE_FISSURE, geompy.ShapeType["EDGE"])
173     geompy.UnionIDs(newEdges, newEdgesIDs)
174
175     [oldEdges] = geompy.RestoreGivenSubShapes(FACE_FISSURE, [FELLIPSE, edges], GEOM.FSM_GetInPlace, True, False)
176
177     toExtrude = geompy.CutListOfGroups([newEdges], [oldEdges])
178
179     if extension>1.e-12:
180       extrusion = geompy.MakePrismVecH(toExtrude, DIRECTION_op, extension)
181       try:
182         FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, True)
183       except:
184         FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, False)
185
186   #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
187
188   #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
189
190   import  SMESH, SALOMEDS
191   from salome.smesh import smeshBuilder
192   smesh = smeshBuilder.New()
193
194   A=numpy.pi/(30.)
195   minAxes=numpy.min([data_demi_grand_axe,data_demi_petit_axe])
196   maxAxes=numpy.max([data_demi_grand_axe,data_demi_petit_axe])
197   R=minAxes**2/maxAxes
198
199   if rayon_entaille>1.e-12:
200     R=numpy.min([R,rayon_entaille])
201     A=numpy.pi/(15.)
202
203   chordal, minSize = uF.calcElemSize(A, R)
204   maxSize=maxAxes/5.
205
206   Maillage=uF.meshCrack(FACE_FISSURE, minSize, maxSize, chordal, dim)
207
208   try:
209     Maillage.ExportMED(outFile)
210     smesh.SetName(Maillage.GetMesh(), 'MAILLAGE_FISSURE')
211   except:
212     print('ExportMED() failed. Invalid file name?')
213
214
215   ## Set names of Mesh objects
216
217
218   if salome.sg.hasDesktop():
219     salome.sg.updateObjBrowser()