main
John Lauer Correct front orientation and virtual marking; add reviewed candidate Fusion library and fit limitations 3a87183 9d ago
"""Build corrected nominal assembly with only the original service-generated glyph shape.
Run on the existing shared OCP host with build_model.py and review source adjacent.
"""
from pathlib import Path
import math,sys,faulthandler
faulthandler.enable()
from OCP.STEPCAFControl import STEPCAFControl_Reader
from OCP.TDF import TDF_ChildIterator,TDF_AttributeIterator
from OCP.gp import gp_Trsf,gp_Ax1,gp_Pnt,gp_Dir,gp_Vec
from OCP.BRepBuilderAPI import BRepBuilderAPI_Transform
from OCP.TDocStd import TDocStd_Document
from OCP.TCollection import TCollection_ExtendedString
from OCP.TDataStd import TDataStd_Name
from OCP.XCAFDoc import XCAFDoc_DocumentTool
p=Path(__file__).parent
markdoc=TDocStd_Document(TCollection_ExtendedString('BinXCAF'))
r=STEPCAFControl_Reader();r.SetNameMode(True)
r.ReadFile(str(p/'review/initial-upside-down-mark.step'));assert r.Transfer(markdoc)
it=TDF_ChildIterator(markdoc.Main(),True);found=[]
while it.More():
 lab=it.Value();attrs=TDF_AttributeIterator(lab);labelname=None
 while attrs.More():
  attr=attrs.Value()
  if isinstance(attr,TDataStd_Name):labelname=attr.Get().ToExtString()
  attrs.Next()
 if labelname=='Adom.LaserEtch' and not XCAFDoc_DocumentTool.ShapeTool_s(markdoc.Main()).IsReference_s(lab):
  shape=XCAFDoc_DocumentTool.ShapeTool_s(markdoc.Main()).GetShape_s(lab)
  if not shape.IsNull():found.append(shape)
 it.Next()
assert len(found)==1,len(found)
t=gp_Trsf();t.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(1,0,0)),math.pi)
t.SetTranslationPart(gp_Vec(0,0,9.015))
mark=BRepBuilderAPI_Transform(found[0],t,True).Shape()
code=(p/'build_model.py').read_text()
code=code.replace("doc=TDocStd_Document", "parts.append(('Adom.LaserEtch',mark,(.72,.73,.74)))\ndoc=TDocStd_Document")
code=code.replace("out/'ixtp15n50l2-ai-nominal.step'", "out/'ixtp15n50l2-ai-etched.step'")
exec(compile(code,str(p/'build_model.py'),'exec'))