1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2016-2021 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
30 import salome_notebook
31 notebook = salome_notebook.NoteBook()
38 from salome.geom import geomBuilder
41 from . import utilityFunctions as uF
42 from .output import message
45 #rectangle.generate(data_longueur,data_largeur,data_centre,data_normale,data_direction,data_angle,data_rayon,rayon_entaille,extension,outFile)
47 def generate(data_longueur,data_largeur,data_centre,
48 data_normale,data_direction,data_angle,
49 data_rayon,rayon_entaille,outFile):
53 #data_centre = [0., 0., 0.]
54 #data_normale = [1., 2., 0.]
55 #data_direction = [0., 1., 5.]
60 #epsilon=numpy.max([data_longueur,data_largeur])*1.e-8
61 Brayon = data_rayon>1e-12
62 Bentaille = rayon_entaille>1e-12
65 maxSize=numpy.min([data_longueur,data_largeur])/4.
69 R=numpy.min([data_rayon,rayon_entaille])
70 chordal, minSize = uF.calcElemSize(A, R)
72 chordal, minSize = uF.calcElemSize(A, rayon_entaille)
76 chordal, minSize = uF.calcElemSize(A, data_rayon)
78 minSize=numpy.min([data_longueur,data_largeur])/10.
82 Vnormale, Vdirection, Vortho = uF.calcCoordVectors(data_normale, data_direction)
83 Vcentre = numpy.array(data_centre)
85 geompy = geomBuilder.New()
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])
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
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])
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)
113 Contour_1 = geompy.MakeWire([Ligne_1, Ligne_2, Ligne_3, Ligne_4], 1e-07)
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)
120 RECTANGLE = geompy.MakeFaceWires([Contour_1], 1)
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])
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' )
141 hauteur=data_longueur*1.1
145 extrusion=numpy.max([1.,rayon_entaille])*1.1
147 if ( (data_angle>(eps)) and (data_angle<(180.-eps)) ):
148 rayon2=hauteur*numpy.tan(data_angle*numpy.pi/180./2.)
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)
160 FACE_FISSURE = geompy.MakeCommonList([RECTANGLE, BOITE])
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
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])
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)
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])
183 #geompy.addToStudy( RECTANGLE, 'RECTANGLE' )
184 #geompy.addToStudy( BOITE, 'BOITE' )
185 #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
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])
200 elif ( (data_angle<=(eps)) or (data_angle>=(360.-eps)) ):
202 FACE_FISSURE = RECTANGLE
205 message('E','Angle non prevu')
208 #newEdgesIDs = geompy.SubShapeAllIDs(FACE_FISSURE, geompy.ShapeType["EDGE"])
209 #newEdges = geompy.CreateGroup(FACE_FISSURE, geompy.ShapeType["EDGE"])
210 #geompy.UnionIDs(newEdges, newEdgesIDs)
212 #[oldEdges] = geompy.RestoreGivenSubShapes(FACE_FISSURE, [RECTANGLE, edges], GEOM.FSM_GetInPlace, True, False)
214 #toExtrude = geompy.CutListOfGroups([newEdges], [oldEdges])
216 #if extension>1.e-12:
217 #extrusion = geompy.MakePrismVecH(toExtrude, DIRECTION_op, extension)
219 #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, True)
221 #FACE_FISSURE = geompy.MakeFuseList([FACE_FISSURE, extrusion], False, False)
223 #geompy.addToStudy( FACE_FISSURE, 'FACE_FISSURE' )
229 import SMESH, SALOMEDS
230 from salome.smesh import smeshBuilder
231 smesh = smeshBuilder.New()
233 Maillage=uF.meshCrack(FACE_FISSURE, minSize, maxSize, chordal, dim)
236 Maillage.ExportMED(outFile)
237 smesh.SetName(Maillage.GetMesh(), 'MAILLAGE_FISSURE')
239 print('ExportMED() failed. Invalid file name?')
242 if salome.sg.hasDesktop():
243 salome.sg.updateObjBrowser()