libredwg
[Top][All Lists]
Advanced

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

Re: [libredwg] Sample functions


From: Till Heuschmann
Subject: Re: [libredwg] Sample functions
Date: Thu, 13 Jun 2013 23:54:46 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6

Hi Gagan,

before designing the API you should be familar with some basic .dwg concepts:

1) Every entity in the drawing belongs to a block
2) A drawing at least contains the blocks "*Model_Space" and "*Paper_Space"
3) The "*Paper_Space" block contains entities that are needed to print the drawing (frames...) 4) The "*Model_Space" block contains the entities that make up the graphical drawing 5) A .dwg file is structured as a database, it contains tables for blocks, layers, linetypes...
...

I think that the upcoming API of LibreDWG should follow these concepts.

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.

Imagine this example whith the new API:
- No struct climbing like "obj->tio.object->tio"
- No access to internal members like "dwg->object[0]"


Am 13.06.2013 20:20, schrieb gagan:
I have made a function for high level line entity access, Can we have
functions like this for all entities.

Function:-

Dwg_Entity_LINE **
extract_lines(Dwg_Data *dwg)
{
   int i,x=0;
   Dwg_Entity_LINE ** lines = (Dwg_Entity_LINE **) malloc(
   count_data(dwg, "LINE") * (sizeof (Dwg_Entity_LINE*) + 2));
   for (i = 0; i < dwg->num_objects; i++)
     {
       Dwg_Entity_LINE *line;
         if(DWG_TYPE_LINE==dwg->object[i].type)
         {
           lines[x] = dwg->object[i].tio.entity->tio.LINE;
           x++;
         }
     }
   return lines;
}

Usage :-

Dwg_Entity_LINE **all_lines;
   all_lines = extract_lines(&dwg);
     for (i = 0; i < count_data(&dwg,"LINE") ; i++)
       {
         printf("%f \n",all_lines[i]->start.x);
       }

I have created a count_data function that counts different types of
entities according to input to the function
Please check it here [0]. Function was large so I showed here.

example usage is like :-
count_data(&dwg,"LINE")
count_data(&dwg,"ARC")
count_data(&dwg,"LAYER")
count_data(&dwg,"LAYER_CONTROL")
count_data(&dwg,"BLOCK_CONTROL")

[0] http://202.164.53.122/~gagan/sample.txt





reply via email to

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