Deadlock

Transferring my work from libdxf to libdxfrw has not been easy so far. Considering the functionality of parsing the input file remaining completely same, the functions to write DXF file had to be understood.

A simple line can be written to DXF file as:
DRW_Line line;
line.basePoint.x = 10;
line.basePoint.y = 20;
line.secPoint.x = 30;
line.secPoint.y = 30;
dxfW.writeLine(&line);

The values here are passed statically. The above code is executed successfully in writeEntities() function. This function is called in write() function itself without any need to explicitly call it. However to pass the parsed attributes from an input file follows a little different approach.

DRW_Line line;
line.basePoint.x = ab->at(j).toDouble();
line.basePoint.y = ab->at(j+1).toDouble();
line.secPoint.x = ab->at(j+2).toDouble();
line.secPoint.y = ab->at(j+3).toDouble();
writer.addLine(line);

The arguments of the parsed input are passed to addLine function. Initially, I was trying to call the addLine function in writeEntities function but some arguments had to be passed to the former doing which the parsed values were over-ridden. Doing it reverse made the parsed values to pass to the writeEntities function instead of each value equal to zero in the prior case.

Now I am able to obtain the parsed values outside the function addLine which was not the situation yesterday. Still I continue to confront a segmentation fault whose roots haven’t been determined yet. So far it seems like a deadlock!

The Random Argument Input

In the previous implementation, the ordering of arguments mattered. Putting length as second argument after height as the first parameter altered the drawing which was not desired for the user.

Considering the same entity wall, creating few walls like:

wall(l=100,h=30,bx=10,by=10)
wall(h=50,l=120,bx=10,by=40)
wall(bx=20,h=100,by=100,l=60)
,

does not affect the drawing. A vector was created for storing the values of the arguments. The output file I got after splitting removing the delimiters:

wall
l
100
h
30
bx
10
by
10

and similarly for the other two walls, each line is read and the entity name and variable names are compared and pushed to a vector. After one entity is read completely, it is pushed to another vector which stores the complete data of one entity as a single entry. This data is then extracted to obtain the values of variables, passing them to function that writes to DXF file and create the final drawing.

It can be referred here: https://github.com/kamalpreetgrewal/textToDrawing.

Using libDXF library

The use of CAD applications is enormous and so has been the need for standardization. An initiative made by Autodesk back in 1982 to provide a representation of the content in the drawing resulted in the creation of DXF (Drawing Exchange Format).

libDXF is a library to read and write DXF files. The library is used to parse the content stored in DXF files to create drawings when opened in a CAD software. Reading and writing of these files via this library needs an understanding of the structure of DXF.

I worked on a task to create a DXF drawing from a simple input file given by the user. The input file looks like:

wall(l=100,h=30,bx=10,by=10)
wall(l=10,h=50,bx=0,by=0)
flange(r=20,cx=50,cy=100)

The next step I performed is splitting of this input file via the separators: "(", ")", ",", "=".

Saving everything in an output file which looks like:
wall
l
100
h
30
bx
10
by
10
for one wall and similarly for the other entities.

Further in the functions defining the creation of entities, only the numeric numbers are needed as arguments. Creating a regular expression to extract the numbers from the output file and saving the numbers in a vector, the entities are saved to a DXF file. Figure below shows a drawing I created via this procedure:

Screenshot from 2016-02-22 10:27:17

The complete work can be referred at: https://github.com/kamalpreetgrewal/textToDrawing

txt to Drawing in LibreCAD

Recently, I have been working with DXF library. My aim has been to take a text file as input from the user which has details of different elements of a building. Currently I am focusing on the wall entity. On parsing the input file, it yields a DXF file as output which can be opened up in softwares that support the DXF format.

To achieve this, I have gone through things beyond the use of DXF library itself. The correct use of regular expressions has been providing the expected results so far. Not much going into the implementation for this post, I have an input text file with details of two walls written as follows:

wall(l=100,h=30,cx=10,cy=10)
wall(l=10,h=50,cx=0,cy=0)

l depicts the length of the wall. h is height of the wall while cx and cy are coordinates of bottom left corner of the wall.

Following up the format of writing a DXF file including its header, the entities section followed up by the footer, on opening the DXF file, I achieved the drawing similar to the one below:

Screenshot from 2015-09-02 21:33:42