Imprint all the solids and construct a dictionary mapping imprinted solids to names from the input assy.
(assy: AssemblyProtocol)
| 856 | |
| 857 | |
| 858 | def imprint(assy: AssemblyProtocol) -> Tuple[Shape, Dict[Shape, Tuple[str, ...]]]: |
| 859 | """ |
| 860 | Imprint all the solids and construct a dictionary mapping imprinted solids to names from the input assy. |
| 861 | """ |
| 862 | |
| 863 | # make the id map |
| 864 | id_map = {} |
| 865 | |
| 866 | for obj, name, loc, _ in assy: |
| 867 | for s in obj.moved(loc).Solids(): |
| 868 | id_map[s] = name |
| 869 | |
| 870 | # connect topologically |
| 871 | bldr = BOPAlgo_MakeConnected() |
| 872 | bldr.SetRunParallel(True) |
| 873 | bldr.SetUseOBB(True) |
| 874 | |
| 875 | for obj in id_map: |
| 876 | bldr.AddArgument(obj.wrapped) |
| 877 | |
| 878 | bldr.Perform() |
| 879 | res = Shape(bldr.Shape()) |
| 880 | |
| 881 | # make the connected solid -> id map |
| 882 | origins: Dict[Shape, Tuple[str, ...]] = {} |
| 883 | |
| 884 | for s in res.Solids(): |
| 885 | ids = tuple(id_map[Solid(el)] for el in bldr.GetOrigins(s.wrapped)) |
| 886 | # if GetOrigins yields nothing, solid was not modified |
| 887 | origins[s] = ids if ids else (id_map[s],) |
| 888 | |
| 889 | return res, origins |