From 403812b454c50b1fa259b0cb37bf5f6f1f0dd226 Mon Sep 17 00:00:00 2001 From: Felipe Correa da Silva Sanches Date: Thu, 11 Feb 2010 00:30:32 -0200 Subject: [PATCH] implement version dependant iterator for owned obects of a BLOCK_HEADER --- examples/testSVG.c | 10 ++++------ src/dwg.c | 30 ++++++++++++++++++++++++++++++ src/dwg.h | 7 +++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/examples/testSVG.c b/examples/testSVG.c index bfa6032..8640ffa 100644 --- a/examples/testSVG.c +++ b/examples/testSVG.c @@ -209,15 +209,13 @@ void output_BLOCK_HEADER(Dwg_Object_Ref* ref) printf( "\t\n\t\t\n", ref->absolute_ref, hdr->entry_name); - //TODO:still not quite right I think... - obj = hdr->first_entity->obj; - while(obj && obj != hdr->last_entity->obj) + obj = get_first_owned_object(ref->obj, hdr); + + while(obj) { output_object(obj); - obj = dwg_next_object(obj); + obj = get_next_owned_object(ref->obj, obj, hdr); } - //output the last one: - if (obj) output_object(obj); printf("\t\n"); } diff --git a/src/dwg.c b/src/dwg.c index 254099f..b999e7a 100644 --- a/src/dwg.c +++ b/src/dwg.c @@ -347,6 +347,36 @@ dwg_get_object(Dwg_Object* obj, Dwg_Object_Ref* ref) return -1; } +Dwg_Object* get_first_owned_object(Dwg_Object* hdr_obj, Dwg_Object_BLOCK_HEADER* hdr){ + Bit_Chain *dat = hdr_obj->parent->bit_chain; + + VERSIONS(R_13, R_2000) + { + return hdr->first_entity->obj; + } + SINCE(R_2004) + { + hdr->__iterator = 0; + return hdr->entities[0]->obj; + } +} + +Dwg_Object* get_next_owned_object(Dwg_Object* hdr_obj, Dwg_Object* current, Dwg_Object_BLOCK_HEADER* hdr){ + Bit_Chain *dat = hdr_obj->parent->bit_chain; + + VERSIONS(R_13, R_2000) + { + if (current==hdr->last_entity->obj) return 0; + return dwg_next_object(current); + } + SINCE(R_2004) + { + hdr->__iterator++; + if (hdr->__iterator == hdr->owned_object_count) return 0; + return hdr->entities[hdr->__iterator]->obj; + } +} + void dwg_free(Dwg_Data * dwg) { diff --git a/src/dwg.h b/src/dwg.h index 94413d3..ea4abc2 100644 --- a/src/dwg.h +++ b/src/dwg.h @@ -1356,6 +1356,7 @@ typedef struct _dwg_object_BLOCK_CONTROL */ typedef struct _dwg_object_BLOCK_HEADER { + int __iterator; BITCODE_TV entry_name; BITCODE_B _64_flag; BITCODE_BS xrefindex_plus1; @@ -2836,6 +2837,12 @@ dwg_next_object(Dwg_Object* obj); int dwg_get_object(Dwg_Object* obj, Dwg_Object_Ref* ref); +Dwg_Object* +get_first_owned_object(Dwg_Object* hdr_obj, Dwg_Object_BLOCK_HEADER* hdr); + +Dwg_Object* +get_next_owned_object(Dwg_Object* hdr_obj, Dwg_Object* current, Dwg_Object_BLOCK_HEADER* hdr); + void dwg_print_object(Dwg_Object *obj); -- 1.6.0.4