5PACE3Dmodelsatellites / ORCASat /ORCASat_CAD /source /build_compatibility.py
MateuszBocko's picture
Initial | Project Setup
6237959 verified
Raw History Blame Contribute Delete
2.01 kB
#!/usr/bin/env python3
"""Flat AP203 alternatives. Schema is checked after the STEP writer is initialised."""
from pathlib import Path
import json, shutil
import cadquery as cq
from OCP.Interface import Interface_Static
from OCP.STEPControl import STEPControl_Controller,STEPControl_Writer,STEPControl_AsIs
import build_orcasat as b
def write_ap203(shape,path):
STEPControl_Controller.Init_s()
assert Interface_Static.SetCVal_s('write.step.schema','AP203')
writer=STEPControl_Writer()
assert Interface_Static.SetCVal_s('write.step.schema','AP203')
Interface_Static.SetIVal_s('write.surfacecurve.mode',1)
assert int(writer.Transfer(shape.wrapped,STEPControl_AsIs))==1
assert int(writer.Write(str(path)))==1
header=Path(path).read_text(errors='replace')[:3000]
assert 'CONFIG_CONTROL_DESIGN' in header, 'Expected AP203 schema was not written'
def export_all(target=None):
target=Path(target) if target else Path(__file__).resolve().parent.parent/'compatibility'
target.mkdir(exist_ok=True)
for name,view,state in [('ORCASat_Stowed_Multibody','full','stowed'),('ORCASat_Deployed_Multibody','full','deployed'),('ORCASat_Internal_Multibody','internal','stowed'),('ORCASat_Exploded_Multibody','exploded','deployed')]:
shapes=[s for p in b.PARTS if b.visible(p,state,view) for s in b.body_axes(b.moved(p,view)).Solids()]
shape=cq.Compound.makeCompound(shapes);assert shape.isValid()
write_ap203(shape,target/(name+'.step'))
print('AP203',name,len(shapes),'solids',flush=True)
write_ap203(cq.Solid.makeBox(20,20,20),target/'Test_Cube_20mm.step')
# Keep previous download names as exact copies of the updated flat exports.
shutil.copy2(target/'ORCASat_Exploded_Multibody.step',target/'ORCASat_Exploded_SW_Legacy.step')
shutil.copy2(target/'Test_Cube_20mm.step',target/'Test_Cube_20mm_SW_Legacy.step')
for old in target.glob('*_validation.json'):old.unlink()
if __name__=='__main__':
b.build();export_all()