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.
Ries

Screenshot of LibreCAD with DWG support

55 thoughts on “Adding DWG support

  1. Great news!
    If LibreCAD adds DWG support, the program will have a important function. I hope that libreCAD can become in the future in a CAD software with own features.

    • Dear Andres,

      I hope my opinion is not misunderstood.

      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.

      forgive me if I am wrong.

      LibreCAD is a very important project for the Free Software community.

      best regards,

      julio menezes

  2. You can add support for plugins?
    So that:
    LibreCAD – GPLv2
    Plugin interface – GPLv2 or (at your option) any later option.
    DWG read plugin (whit LibreDWG) – GPLv3

    Would this be legal?

    • Rallaz,

      the people behind LibreDWG are highly likely going to release LibreDWG as GPLv2 or higher in a month.

      This was there answer to a question if they could release LibreDWG at GPLv2 or higher:
      [I cannot confirm that, but it is very likely to happen in the near future (~ one month I’d say).]

      So I think that’s enough hope to start investigating how easy it was to add the DWG import filter, and to show them our willingness to use LibreDWG, the above blogpost and screenshot the result 🙂

      Ries

    • Alexandre,

      Donations are gladly accepted 😉 patches even more!

      We are working hard to make sure that LibreCAD will be accepted in the mayor distro’s and that people are happy with the tool and I am glad you like the work we are doing.

      Ries

      • Speaking of patches….

        This patch:

        diff –git a/fparser/fparser.cc b/fparser/fparser.cc
        index 49e6ae0..e4d88b5 100644
        — a/fparser/fparser.cc
        +++ b/fparser/fparser.cc
        @@ -899,7 +899,7 @@ namespace
        byte -= n;
        if(byte > (unsigned char)(‘9’-n)) return false;
        unsigned long shifted = 1UL << byte;
        – const unsigned long mask = LiteralMask::mask;
        + const unsigned long mask = LiteralMask<Value_t, static_cast(n)>::mask;
        return (mask & shifted) != 0;
        }

        @@ -956,7 +956,7 @@ U+000B \v
        if(byte <= (unsigned char)(' '-n))
        {
        unsigned long shifted = 1UL << byte;
        – const unsigned long mask = SimpleSpaceMask::mask;
        + const unsigned long mask = SimpleSpaceMask<static_cast(n)>::mask;
        if(mask & shifted)
        { ++function; continue; } // \r, \n, \t, \v and space
        break;

        fixes the following errors with my gcc 4.6.0:

        fparser/fparser.cc: In function ‘bool {anonymous}::BeginsLiteral(unsigned int)’:
        fparser/fparser.cc:902:58: error: could not convert template argument ‘n’ to ‘unsigned int’
        fparser/fparser.cc: In function ‘void {anonymous}::SkipSpace(CharPtr&)’:
        fparser/fparser.cc:959:61: error: could not convert template argument ‘n’ to ‘unsigned int’
        fparser/fparser.cc: In function ‘bool {anonymous}::BeginsLiteral(unsigned int) [with Value_t = double]’:

        (this is with current master). Sorry for posting the patch in here, but I could not bother to
        set up a github account…

    • Vida,

      the problem is that we don’t own the copyright of LibreCAD, since it’s a fork of QCad, and QCad is released as GPLv2, we have to release it as GPLv2 aswell.

      Ries

      • GPL software commonly has this message:

        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! 🙂

        • John,

          QCad 2.0.2.0 CE was released as GPLv2 and doesn’t have anywhere “either version 2 of the License, or (at your option) any later version.”

          So we cannot change the license.

          • but it does have this:
            [9.] The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

            Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and “any later version”, you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.

            • That’s correct Gery, but when LibreCAD was forked from QCAD, the license was GPLv2, not more, no “any later version”.
              So this point doesn’t apply to the QCAD code base when LibreCAD was forked and thus we can’t re-license LibreCAD 2.x.
              There were efforts in past, asking the authors of QCAD and LibreDWG to re-license their work, but without any success.

  3. 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.

    (Version: Beta-4 on Windows 7)

    • Akysson,

      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.

      Ries

  4. it’s a long time i was waiting this.
    i’m a very light user of autocad lt 2000 that i run with wine, but with a lot of trouble.

    now with this, i can switch to librecad and it will satisfy my needs (a plan every year or 2 !)

    i try to download the source of the test version and post feedback.

    • 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.

      • 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 !

        • in fact the include is wrong :

          #include “dl_Codes.h”

          has to be changed in

          #include “dl_codes.h”

          and then it goes thru without problem.

          • new blocking point :
            In file included from src/lib/filters/rs_filterdwg.h:47,
            from src/main/main.cpp:52:
            libredwg/src/dwg.h:344: error: expected unqualified-id before numeric constant

            i check this one too…. very close to the end now 😉

          • 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

          • christophe,

            I am glad this already worked for you!

            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

            Ries

          • 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 😉

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

          • 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.

  5. 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.

  6. 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

    Lovely work

  7. 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.

    The latest version of the test files will always be linked from this text file: http://dl.dropbox.com/u/183092/LibreDWG_example_files.txt

    Drop me a line if you can think of some improvements.

    Duncan

    • Duncan,

      thanks for doing that. Currently I am still waiting if LibreDWG will get released as GPLv2 or higher, then i can pickup this project again.

  8. How is the work going, is it already relicenced?

    I think this is a very big important feature, so I would put all the effort in getting dwg support.

  9. As of today LibreDWG on LibreDWG website:
    Licensing

    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.

  10. i successfully installed libreCAD fron git with dwg support.
    i tried to open a .dwg file(building plan) but i get this answer:

    Starting /home/carlo/LibreCAD/unix/librecad…
    The program has unexpectedly finished.
    /home/carlo/LibreCAD/unix/librecad exited with code 0.
    thanks

  11. Pingback: LIBRECAD 1.0.0发布

  12. Pingback: LibreCAD 1.0, una eina completa CAD 2D | GNULinux.cat

  13. 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).

    • Hey,

      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.

  14. Pingback: LibreCAD 1.0

  15. Would be great. Right now I’m using Draftsight to convert my files from DWG to DXF. Don’t liek that workflow but is the only I have right now.

    BTW: would it be better to have LibreDWG under LGPL instead of GPL? (law-noob question I guess)

    • Samsagax,

      the problem is that we couldn’t get a conversation with GNU going so we are thinking about a other approach and that is re-write LibreCAD so we can decide on the licenses.

      So, it all will take longer then expected, we will get there though, just take slonger..

    • Mike,

      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!!!

  16. 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.

  17. I have just released a new version of LibDWG (0.5) which includes a DWG-DXF conversion tool (command-line), for versions R2000, which is the one LibreCAD works with, ok?

    Although LibDWG is GPLv3+, it should not be of a concern for the user to install it, so LibreCAD could use it via some “system ()” call.

    LibDWG originated LibreDWG, and I decided to fork it back, in order to allow things like this one I’m telling you: a graceful little tar ball.

    • Hey Filip,

      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.

  18. Pingback: LibreCAD 1.0 » Unix Srbija | Unix Srbija

  19. Hi guys,

    I suggest you to use Teigha® Viewer which brilliantly convert from all Acad DWG formats to all Acad DXF.
    It located at http://www.opendesign.com/guestfiles/teigha_viewer I compile it in Arch using AUR repo.

    LibreCad works perfect with the DXF opening so it solve the case how to open Autocad files. Also application review the created files from Autocad.

    Think this info is useful.

    Regards,
    Alex

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.