Skip to content

Commit

Permalink
only write BLOCK_RECORD table on R13+
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo committed Nov 29, 2021
1 parent ce94d5d commit 73c0c37
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
23 changes: 21 additions & 2 deletions build/table_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,29 @@ fn generate_table_writer(fun: &mut String, element: &Element) {
"pub(crate) fn add_table_code_pairs(drawing: &Drawing, pairs: &mut Vec<CodePair>, write_handles: bool) {\n",
);
for table in &element.children {
let mut indention = "";
let mut predicates = vec![];
if !min_version(&table).is_empty() {
indention = " ";
predicates.push(format!(
"drawing.header.version >= AcadVersion::{}",
min_version(&table)
));
}
if predicates.len() != 0 {
fun.push_str(&format!(
" if {predicate} {{\n",
predicate = predicates.join(" && ")
));
}
fun.push_str(&format!(
" add_{collection}_code_pairs(pairs, drawing, write_handles);\n",
collection = attr(&table, "Collection")
" {indention}add_{collection}_code_pairs(pairs, drawing, write_handles);\n",
collection = attr(&table, "Collection"),
indention = indention
));
if predicates.len() != 0 {
fun.push_str(" }\n");
}
}

fun.push_str("}\n");
Expand Down
2 changes: 1 addition & 1 deletion spec/TableSpec.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TableItem Name="AppId" ClassName="AcDbRegAppTableRecord">
</TableItem>
</Table>
<Table Collection="block_records" TypeString="BLOCK_RECORD">
<Table Collection="block_records" TypeString="BLOCK_RECORD" MinVersion="R13">
<TableItem Name="BlockRecord" ClassName="AcDbBlockTableRecord" HasFlags="false">
<Pointer Name="layout" Code="340" MinVersion="R2000" />

Expand Down
14 changes: 14 additions & 0 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,18 @@ mod tests {
assert_eq!(1, ucss.len());
assert_eq!("primary ucs", ucss[0].name);
}

#[test]
fn block_record_table_not_written_on_r12() {
let mut drawing = Drawing::new();
drawing.header.version = AcadVersion::R12;
assert_not_contains_pairs(&drawing, vec![CodePair::new_str(0, "BLOCK_RECORD")]);
}

#[test]
fn block_record_table_is_written_on_r13() {
let mut drawing = Drawing::new();
drawing.header.version = AcadVersion::R13;
assert_contains_pairs(&drawing, vec![CodePair::new_str(0, "BLOCK_RECORD")]);
}
}

0 comments on commit 73c0c37

Please sign in to comment.