Skip to content

Commit 0c1b370

Browse files
fsalmoirmtezzele
authored andcommitted
writer now works properly
1 parent 532611b commit 0c1b370

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

pygem/igeshandler.py

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
Utilities for reading and writing different CAD files.
33
"""
44
import numpy as np
5+
import sys
56
import pygem.filehandler as fh
67
from OCC.IGESControl import (IGESControl_Reader, IGESControl_Writer)
7-
from OCC.BRep import BRep_Tool
8+
from OCC.BRep import (BRep_Tool, BRep_Builder)
89
from OCC.BRepBuilderAPI import (BRepBuilderAPI_NurbsConvert, BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace)
910
from OCC.GeomConvert import geomconvert_SurfaceToBSplineSurface
1011
import OCC.TopoDS
@@ -94,8 +95,6 @@ def parse(self, filename):
9495

9596
n_faces += 1
9697
faces_explorer.Next()
97-
98-
print control_point_position
9998

10099
self._control_point_position = control_point_position
101100

@@ -133,6 +132,10 @@ def write(self, mesh_points, filename):
133132
n_faces = 0
134133
control_point_position = self._control_point_position
135134

135+
compound_builder = BRep_Builder()
136+
compound = OCC.TopoDS.TopoDS_Compound()
137+
compound_builder.MakeCompound(compound)
138+
136139
while faces_explorer.More():
137140

138141
# similar to the parser method
@@ -158,7 +161,7 @@ def write(self, mesh_points, filename):
158161
i += 1
159162

160163
## construct the deformed wire for the trimmed surfaces
161-
wireMaker = BRepBuilderAPI_MakeWire()
164+
wire_maker = BRepBuilderAPI_MakeWire()
162165
tol = ShapeFix_ShapeTolerance()
163166
brep = BRepBuilderAPI_MakeFace(occ_face.GetHandle(), 1e-4).Face()
164167
brep_face = BRep_Tool.Surface(brep)
@@ -172,23 +175,22 @@ def write(self, mesh_points, filename):
172175
# evaluating the new edge: same (u,v) coordinates, but different (x,y,x) ones
173176
edge_phis_coordinates_aux = BRepBuilderAPI_MakeEdge(edge_uv_coordinates[0], brep_face)
174177
edge_phis_coordinates = edge_phis_coordinates_aux.Edge()
178+
#print edge_phis_coordinates
175179
tol.SetTolerance(edge_phis_coordinates, 1e-4)
176-
wireMaker.Add(edge_phis_coordinates)
180+
wire_maker.Add(edge_phis_coordinates)
177181
edge_explorer.Next()
178182

179183
#grouping the edges in a wire
180-
wire = wireMaker.Wire()
184+
wire = wire_maker.Wire()
181185

182186
## trimming the surfaces
183-
brep_surf = BRepBuilderAPI_MakeFace(occ_face.GetHandle(), wire).Face()
184-
writer.AddShape(brep_surf)
185-
186-
#print writer
187-
187+
brep_surf = BRepBuilderAPI_MakeFace(occ_face.GetHandle(), wire).Shape()
188+
compound_builder.Add(compound, brep_surf)
188189
n_faces += 1
189-
faces_explorer.Next()
190+
faces_explorer.Next()
191+
192+
writer.AddShape(compound)
190193

191-
## write out the iges file
192194
writer.Write(self.outfile)
193195

194196

@@ -212,15 +214,42 @@ def plot(self, plot_file=None, save_fig=False):
212214
reader = IGESControl_Reader()
213215
reader.ReadFile(plot_file)
214216
reader.TransferRoots()
215-
shape = reader.Shape()
217+
shape = reader.Shape()
216218

217219
display, start_display, add_menu, add_function_to_menu = init_display()
218220
display.FitAll()
219221
display.DisplayShape(shape, update=True)
220222

223+
def export_to_BMP(event=None):
224+
display.View.Dump('./capture_bmp.bmp')
225+
226+
227+
def export_to_PNG(event=None):
228+
display.View.Dump('./capture_png.png')
229+
230+
231+
def export_to_JPEG(event=None):
232+
display.View.Dump('./capture_jpeg.jpeg')
233+
234+
235+
def export_to_TIFF(event=None):
236+
display.View.Dump('./capture_tiff.tiff')
237+
238+
239+
def exit(event=None):
240+
sys.exit()
241+
242+
add_menu('screencapture')
243+
add_function_to_menu('screencapture', export_to_BMP)
244+
add_function_to_menu('screencapture', export_to_PNG)
245+
add_function_to_menu('screencapture', export_to_JPEG)
246+
add_function_to_menu('screencapture', export_to_TIFF)
247+
add_function_to_menu('screencapture', exit)
248+
221249
# Show the plot to the screen
222250
if not save_fig:
223251
start_display()
224252
else:
225-
display.View.Dump(plot_file.split('.')[0] + '.ppm')
253+
f = display.View.View().GetObject()
254+
display.View.Dump(plot_file.split('.')[0] + '.jpg')
226255

0 commit comments

Comments
 (0)