1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2016-2019 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 ### This file is generated automatically by SALOME v7.7.1 with dump python functionality
31 import salome_notebook
32 notebook = salome_notebook.NoteBook()
39 from salome.geom import geomBuilder
42 from . import utilityFunctions as uF
43 from .output import message
45 #ellipse.generate(data_demi_grand_axe, data_centre, data_normale,data_direction, data_demi_petit_axe, data_angle, rayon_entaille,extension, outFile)
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.
55 #outFile='/home/I60976/00_PROJETS/2015_INTEGRATION_ZCRACKS/zcracks_salome/test.med'
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):
62 Vnormale, Vdirection, Vortho = uF.calcCoordVectors(data_normale, data_direction)
63 Vcentre = numpy.array(data_centre)
65 geompy = geomBuilder.New()
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)
80 ELLIPSE = geompy.MakeEllipse(CENTRE, NORMALE, data_demi_petit_axe, data_demi_grand_axe, V3)
82 if rayon_entaille<1.e-12:
83 FELLIPSE = geompy.MakeFaceWires([ELLIPSE], 1)
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])
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' )
106 hauteur=numpy.max([data_demi_grand_axe,data_demi_petit_axe])*1.1
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.)
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)
122 BOITE = geompy.MakePrismVecH2Ways(plan_BOITE, NORMALE, extrusion)
124 FACE_FISSURE = geompy.MakeCommonList([FELLIPSE, BOITE])
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
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])
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)
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])
147 elif ( (data_angle>(180.+eps)) and (data_angle<(360.-eps)) ):
148 rayon2=hauteur*numpy.tan((360.-data_angle)*numpy.pi/180./2.)
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)
160 FACE_FISSURE = geompy.MakeCutList(FELLIPSE, [BOITE])
162 elif ( (data_angle<=(eps)) or (data_angle>=(360.-eps)) ):
164 FACE_FISSURE = FELLIPSE
167 message('E','Angle non prevu')
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)
175 [oldEdges] = geompy.RestoreGivenSubShapes(FACE_FISSURE, [FELLIPSE, edges], GEOM.FSM_GetInPlace, True, False)
177 toExtrude = geompy.CutListOfGroups([newEdges], [oldEdges])
180 extrusion = geompy.MakePrismVecH(toExtrude, DIRECTION_op, extension)
182 FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, True)
184 FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, False)
186 #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
188 #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
190 import SMESH, SALOMEDS
191 from salome.smesh import smeshBuilder
192 smesh = smeshBuilder.New()
195 minAxes=numpy.min([data_demi_grand_axe,data_demi_petit_axe])
196 maxAxes=numpy.max([data_demi_grand_axe,data_demi_petit_axe])
199 if rayon_entaille>1.e-12:
200 R=numpy.min([R,rayon_entaille])
203 chordal, minSize = uF.calcElemSize(A, R)
206 Maillage=uF.meshCrack(FACE_FISSURE, minSize, maxSize, chordal, dim)
209 Maillage.ExportMED(outFile)
210 smesh.SetName(Maillage.GetMesh(), 'MAILLAGE_FISSURE')
212 print('ExportMED() failed. Invalid file name?')
215 ## Set names of Mesh objects
218 if salome.sg.hasDesktop():
219 salome.sg.updateObjBrowser()