Skip to content

Commit c5ce457

Browse files
committed
precision setting of step file
1 parent 841bf45 commit c5ce457

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/compas_occ/brep/brep.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from compas.geometry import Translation
1010
from compas.geometry import Point
1111
from compas.geometry import Polyline
12+
from compas.geometry import Polygon
1213
from compas.datastructures import Mesh
1314

1415
from OCC.Extend.DataExchange import read_step_file
@@ -56,6 +57,7 @@
5657
from OCC.Core.STEPControl import STEPControl_Writer
5758
from OCC.Core.STEPControl import STEPControl_AsIs
5859
from OCC.Core.IFSelect import IFSelect_RetDone
60+
from OCC.Core.Interface import Interface_Static_SetCVal
5961
from OCC.Core.TopTools import TopTools_IndexedDataMapOfShapeListOfShape
6062
from OCC.Core.TopTools import TopTools_ListIteratorOfListOfShape
6163
from OCC.Core.TopExp import topexp_MapShapesAndUniqueAncestors
@@ -747,7 +749,7 @@ def to_json(self, filepath: str):
747749
with open(filepath, "w") as f:
748750
self.occ_shape.DumpJson(f)
749751

750-
def to_step(self, filepath: str, schema: str = "AP203", unit: str = "MM") -> None:
752+
def to_step(self, filepath: str, schema: str = "AP203", unit: str = "M") -> None:
751753
"""Write the BRep shape to a STEP file.
752754
753755
Parameters
@@ -767,7 +769,7 @@ def to_step(self, filepath: str, schema: str = "AP203", unit: str = "MM") -> Non
767769
# write_step_file(self.occ_shape, filepath)
768770
step_writer = STEPControl_Writer()
769771
# Interface_Static_SetCVal("write.step.schema", schema)
770-
# Interface_Static_SetCVal("write.step.unit", unit)
772+
Interface_Static_SetCVal("write.step.unit", unit)
771773
step_writer.Transfer(self.occ_shape, STEPControl_AsIs)
772774
status = step_writer.Write(filepath)
773775
assert status == IFSelect_RetDone, status
@@ -827,7 +829,17 @@ def to_meshes(self, u=16, v=16):
827829
meshes.append(mesh)
828830
return meshes
829831

830-
def to_viewmesh(self):
832+
def to_polygons(self):
833+
"""Convert the faces of the BRep to simple polygons without underlying geometry."""
834+
polygons = []
835+
for face in self.faces:
836+
points = []
837+
for vertex in face.loops[0].vertices:
838+
points.append(vertex.point)
839+
polygons.append(Polygon(points))
840+
return polygons
841+
842+
def to_viewmesh(self, linear_deflection=1e-3):
831843
"""Convert the BRep to a view mesh."""
832844
lines = []
833845
for edge in self.edges:
@@ -841,7 +853,7 @@ def to_viewmesh(self):
841853
lines.append(Polyline(edge.curve.locus()))
842854
elif edge.is_bspline:
843855
lines.append(Polyline(edge.curve.locus()))
844-
return self.to_tesselation(), lines
856+
return self.to_tesselation(linear_deflection=linear_deflection), lines
845857

846858
# ==============================================================================
847859
# Relationships

0 commit comments

Comments
 (0)