lib3mf_core/writer/
opc_writer.rs1use crate::error::Result;
2use crate::writer::xml_writer::XmlWriter;
3use std::io::Write;
4
5pub fn write_content_types<W: Write>(writer: W) -> Result<()> {
6 let mut xml = XmlWriter::new(writer);
7 xml.write_declaration()?;
8
9 xml.start_element("Types")
10 .attr(
11 "xmlns",
12 "http://schemas.openxmlformats.org/package/2006/content-types",
13 )
14 .write_start()?;
15
16 xml.start_element("Default")
18 .attr("Extension", "rels")
19 .attr(
20 "ContentType",
21 "application/vnd.openxmlformats-package.relationships+xml",
22 )
23 .write_empty()?;
24 xml.start_element("Default")
25 .attr("Extension", "model")
26 .attr(
27 "ContentType",
28 "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
29 )
30 .write_empty()?;
31 xml.start_element("Default")
32 .attr("Extension", "png")
33 .attr("ContentType", "image/png")
34 .write_empty()?;
35
36 xml.end_element("Types")?;
41 Ok(())
42}
43
44pub fn write_relationships<W: Write>(
45 writer: W,
46 model_part: &str,
47 thumbnail_part: Option<&str>,
48) -> Result<()> {
49 let mut xml = XmlWriter::new(writer);
50 xml.write_declaration()?;
51
52 xml.start_element("Relationships")
53 .attr(
54 "xmlns",
55 "http://schemas.openxmlformats.org/package/2006/relationships",
56 )
57 .write_start()?;
58
59 xml.start_element("Relationship")
60 .attr("Target", model_part)
61 .attr("Id", "rel0")
62 .attr(
63 "Type",
64 "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel",
65 )
66 .write_empty()?;
67
68 if let Some(thumb) = thumbnail_part {
69 xml.start_element("Relationship")
70 .attr("Target", thumb)
71 .attr("Id", "rel1")
72 .attr(
73 "Type",
74 "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail",
75 )
76 .write_empty()?;
77 }
78
79 xml.end_element("Relationships")?;
80 Ok(())
81}