Blog about LibreCAD, an Open Source 2D CAD program

Main menu

Post navigation

Adding DWG support

Currently I am doing some experimentation to add DWG support to LibreCAD. For this I an using the LibreDWG (I like Libre 😉 ) library from the gnu.org project.

There is only one slight issue, LibreDWG is released as GPLv3 or higher, while LibreCAD is released as GPLv2, and since I am not the original author of LibreCAD (remember, it’s QCad based, and that is released as GPLv2).

Lucky us, after mailing the original authors they are considering releasing LibreDWG as GPLv2 or higher which will bring us in good shape for supporting the frequently requested DWG support.

In the last couple of days, I have been fooling around with this and it seems like that will work quite well, however not every primitive and function is working yet and there is plenty of things todo, but what I have been adding went fairly smooth.

So far I am importing:

Layers + Layer clor

The following entities including Color, Line Width and Respected layer the entity is located on.

Line

Circle

Arc

Ellipse

The above entities are for me a proof of concept and proofs that adding full DWG support (what LibreDWG support) should be quite a bit of work, but I don’t expect any roadblocks for further implementation.

Now it’s waiting untill LibreDWG get’s released as GPLv2 or higher and I can push this to LibreCAD on github.

In the mean time, if you want to take a sneak peek at the current code, you can clone my github repo and checkout the dwgsupport branch. Please don’t distribute this version, just use it as a sneak peek until the licenses are settled.

1) dwg is a privative and pattented format, and they change it from time to time to keep control over it and sell new CAD versions.
2) Reverse engeneering is required to try to understand it and not always with sucess and with possibilities legal retaliations.
3) Because of 1), we always will be in the back of the runner, and spending energy.

I am a GNU/*nix user and like the GNU feeling of free as in freedom, cooperation, transparency.
We have a lote of free software better than its privative counterparts.
So, IMHO, we should develop a CAD just keeping a DXF for interoperability.
I like CLI and think that even some CAD tasks can be done without a GUI.
Take a look on GNU-utils, they are wonderfull pieces of software, I use than for drawing, ( to create AutoCAD text scripts ) from a console.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

If this is the case for QCad then you can relicense your software as GPL v3!

I have just discovered LibreCAD, and am thoroughly impressed it does everything I needed for extracting information from GIS DXF files – and actually manages to preserve all of the entity formatting and data the same time!

All I need now is a way of saving each layer as a separate DXF file and I have the whole job done in just a few mouse clicks.

Keep up the great work, and I look forward to the first full production version.

thanks for the kind words! I know the windows version runs a bit behind the unix/OSX version. But pretty soon (when the logo’s are added to LibreCAD) We will release OSX and WIndows again with all bug-fixes added.

i have downloaded the dwgsupport branch, but i’m missing files in the folder libredwg. may be i have not extracted correctly everything. i try to install git and follow the steps explained in the wiki.

please remember that the dwgsupport branch is very experimental and more of a proof of concept then anything else. We are waiting untill the LibreDWF guys re-release the DWG libraries under GPLv2 and higher.

ok, I’m now stepson on github, freshly created account and I got the dwbsupport branch.

first try to compile : 2 errors in src/lib/filters/rs_filterdwg.cpp :
dl_Code.h asked but missing
src/lib/filters/rs_filterdwg.cpp:500: error: ‘dxfColors’ was not declared in this scope

I try to fix this in order to make it compiling up to the end to see this. I’m so impatient (in fact no, I have time, so excited would be the best word). I would be happy if I can contribute even only a few to make this pre_alpha become a release as soon as possible !

change of THICKNESS to thickness in dwg.h and in header_variables.spec (files in libredwg/src)

there was a conflict with THICKNESS defined somewhere else…. i don’t know the further consequences of this name change. used somewhere else ? but, at last, it enabled me to go to the end of the compilation.

the compile is now done and guess what ? it works !!

I have a few dwg files. 2 opens, 1 nearly ok, 1 with a lot of missing elements.
2 more complex files make librecad do a memoryfault (probably linked to the use of ttf fonts… autocad lt2000 runned in wine fails too on these files when i try to modify some text, while on windows it works fine).

I can provide later on my files to test or test them myself when newer test versions will come out.

but, it is already a good job guys ! it is so nice to see dwg import in LibreCAD !
keep on doing this good job that will help a lot of people

Liek I mentioned, DWG supports is just in a proof of concept stage and not all entities are imported yet. Things like hatches, polylines are still missing out. I also noticed that it crashes on the latest release of DWG (2009 I believe) this is because of a bug in LibreDWG.

I will do a compile test one of these days on my Ubuntu 64 Bit and fix these compile errors. I develop on OSX so I don’t always notice the upper/lower case filename issues :s

additional info i just found by looking at the projet in qtcreator (i have not use it (it = qtcreator or its ancestor) since 2003 !) i’m going back to the pleasure of coding 😉 and discovering this nice environment

THICKNESS in dwg.h and header_variables.spec is in conflict with #define THICKNESS 39 in dl_codes.h

I don’t know if it is of help for you or for libredwg team, but I post it in case it helps one of you.

I only knew of LibreCad when I was tinkering with Ubuntu Software Centre and though I do not use CAD I am greatly impressed by the comments. Like many users if LibreCAD could read dwg files, that would be too good to be true and you have shown promise here. Keep up the excellent work.

Man oh man, this is great news (had been wondering about the use of dwg libraries for this task).

I am currently using draftsight because of ACAD familiarity but if I could get equivalent functionality in librecad (sheet view and model view, including being able to dimension and annotate in the sheet view) I think my last bit of proprietary software will be off my machine

Through work I have access to AutoCAD products so I’ve made some test files in different formats. There are different shapes and texts and so on with an image to compare so you can see what works and what doesn’t.

LibreDWG is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

Just a thought: what if I don’t need DWG support? 😉 I don’t know much about CAD but, is DWG so difficult to translate to another format (DXF?) without losing data in the process? If it isn’t, why bother with DWG? Why doesn’t LibreCAD launch LibreDWG if it needs to import some DWG? (I know this is what plug-ins do).

The main point is: is DWG so important? (remember: I don’t use CAD programs).

DWG is more difficult to translate to other formats because it’s not a open format, that means that we need to reverse engineer the format to make it work successfully. Currently LibreDWG is be able to read R13 to 2004. And yes, DWG is a important format ( and hate to say industry standard). I have had emails from our LibreCAD user base that life in countries that don’t have the $$$ to buy a version of AutoCAD. But when they get drawings in DWG format, they need to send it back to ask for a DXF version. Some day we hope to solve that problem for them.

the problem is that we are not allowed to include these tools within the LibreCAD package due to the license differences.
The Open Design alliance is unfortunately just the name, but it’s far from Open. In fact you have to pay to get in!!!

There is a free tool form Autodesk itself :
DWG Trueview (and Design review for other kind of files) which views, prints, converts all sort dwg/dxf/dgn to all sort of dwg/dxf/dgn.
So Autocad and Microstation files pose no problem at all for Librecad.

thanks for working on this! I need to check with Rallaz and see what he has been up to. I myself haven’t been to active apart from maintaining the server of LibreCAD, taking care of installing build server so I am a bit out of focus.