libredwg
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libredwg] Fwd: Sample functions


From: gagan
Subject: [libredwg] Fwd: Sample functions
Date: Wed, 19 Jun 2013 10:34:09 +0530

---------- Forwarded message ----------
From: Till Heuschmann <address@hidden>
Date: Mon, Jun 17, 2013 at 2:53 AM
Subject: Re: [libredwg] Sample functions
To: gagan <address@hidden>
Cc: Till Heuschmann <address@hidden>


Hi Gaganjyot,

yes I think the object extraction should be done block wise.
The most interesting block would be the "*model_space" block since it
contains all the entities that one would transfer to other CAD systems
(writing a converter).

What about a function like:
Dwg_Object* dwg_get_model_space(Dwg_Data *dwg)

The returned Dwg_Object can then be casted to a
Dwg_Object_BLOCK_HEADER with this function:

// pseudocode not tested
// Similar functions for each object possible
Dwg_Object_BLOCK_HEADER* dwg_object_to_block_header(Dwg_Object *obj)
{
   Dwg_Object_BLOCK_HEADER *_obj;
   if (obj != 0 && obj->type == DWG_TYPE_BLOCK_HEADER)
      {
_obj = obj->tio.object->tio.BLOCK_HEADER;
      }
   return _obj;
}


And to access the entities of the block:
int dwg_block_get_entity_count(Dwg_Object_BLOCK_HEADER *block,
Dwg_Object_Type type)

Functions to get the entities of a block (or generalized a "parent")
are already there in dwg.c:
get_first_owned_object() and get_next_owned_object()
You can use this functions as a start and design more flexible variations:

// pseudocode to retrive the first element of a block that matches o
specific type
dwg_Object* get_first_owned_object_by_type(Dwg_Object *hdr_obj,
Dwg_Object_Typ type)
{
   Dwg_Object_BLOCK_HEADER *hdr = dwg_object_to_block_header(hdr_obj);


   if (hdr != 0)
      {
         unsigned int version = hdr_obj->parent->header.version;

         // get owned objects like in get_first_owned_object(),
compare if type matches and return

      }
   return 0;
}

Using these sort of functions (...get_first / ...get_next) the user of
your API would be able to iterate over all entities.

When you compare the definition of the functions
get_first_owned_object() and get_first_owned_object_by_type() you will
recognize that the parameter "hdr" is missing in
get_first_owned_object_by_type(). Since it is just used to get the
version information and can be retrived through the "hdr_obj"
parameter it had to go.

I hope that I've not confused you to much.

Regards
Till

Am 16.06.2013 um 18:17 schrieb gagan:

On 6/14/13, Till Heuschmann <address@hidden> wrote:

Iterating over the dwg->object[] array and counting/collecting entities

ignores the block relation and leads to parentless data.

The testSVG example that comes with libredwg does it in a better way:


function output_SVG()

The first element in the dwg->object[] is always the block control

(other name for block table). Using this object all blocks can be

accessed and with the special model space block all entities of the

drawing can be found.


Hi till,
Thanks for correcting me. I studied the testSVG program, So now should
I count number according to blocks ? Moreover should extracting
entities be based on blocks ? Should I count model_space and
*paper_space in blocks also ?

--
Thanks
Gaganjyot




-- 
Thanks
Gaganjyot



reply via email to

[Prev in Thread] Current Thread [Next in Thread]