feat: 完善一级关系参数化建模与参数导出
This commit is contained in:
@@ -4,6 +4,8 @@ import re
|
||||
from pathlib import Path
|
||||
|
||||
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Transform
|
||||
from OCC.Core.BRep import BRep_Builder
|
||||
from OCC.Core.BRepTools import breptools
|
||||
from OCC.Core.IFSelect import IFSelect_RetDone
|
||||
from OCC.Core.Interface import Interface_Static
|
||||
from OCC.Core.STEPCAFControl import STEPCAFControl_Reader
|
||||
@@ -126,6 +128,24 @@ def _write_step(shape: TopoDS_Shape, filename: Path) -> None:
|
||||
raise IOError(f"Could not write STEP file: {filename}")
|
||||
|
||||
|
||||
def _load_brep_shape(filename: str | Path) -> TopoDS_Shape:
|
||||
path = Path(filename)
|
||||
shape = TopoDS_Shape()
|
||||
builder = BRep_Builder()
|
||||
if not breptools.Read(shape, str(path), builder) or shape.IsNull():
|
||||
raise IOError(f"Could not read BREP file: {path}")
|
||||
return shape
|
||||
|
||||
|
||||
def _write_brep(shape: TopoDS_Shape, filename: str | Path) -> None:
|
||||
if shape.IsNull():
|
||||
raise ValueError("Cannot export a null shape.")
|
||||
path = Path(filename)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not breptools.Write(shape, str(path)):
|
||||
raise IOError(f"Could not write BREP file: {path}")
|
||||
|
||||
|
||||
def _prepare_shape_for_step_export(shape: TopoDS_Shape) -> TopoDS_Shape:
|
||||
if shape.IsNull():
|
||||
return shape
|
||||
|
||||
Reference in New Issue
Block a user