• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            OpenCASCADE DataExchange DWG

            Posted on 2014-10-15 23:02 eryar 閱讀(6393) 評論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            OpenCASCADE DataExchange DWG

            eryar@163.com

            Abstract. DWG is a file format created in the 70’s for the emerging CAD applications. Currently it is the native file format of AutoCAD, a proprietary CAD program developed by Autodesk. Libredwg is a free C library to read and write DWG files. This program is part of GNU project, released under the aegis of GNU. The paper focus on the usage of Libredwg, and use the Libredwg to read a DWG file and output the entities of the DWG to Tcl script for OpenCASCADE Draw Test Harness visualization.

            Key Words. OpenCASCADE, DWG, Libredwg, DataExchange, Windows

            1. Introduction

            DWG是CAD軟件AutoCAD及基于AutoCAD的軟件保存設計數據所用的一種專有文件格式,始于1970年代的一套Interact CAD軟件。之后Autodesk公司于1982年取得版權開始使用這種文件格式。Autodesk公司擁有、開發并且更新DWG文件格式,通常每隔幾年DWG就會隨著在AutoCAD中添加新的特性而對DWG格式進行更新。

            DWG格式及它的ASCII格式變體DXF格式,已經成為CAD制圖數據交換中的事實文件標準,據估計全世界有超過十億個DWG文件。有幾家公司正在對DWG文件格式進行逆向工程以試圖為其它的設計軟件提供讀寫DWG文件的能力。Autodesk公司也提供了一套需要授權的DWG讀寫技術開發包“RealDWG”。

            新版的AutoCAD可以打開舊版的DWG文件,AutoCAD2007可以打開2.0版本的DWG文件并且可以保存為R14版本。另外Autodesk公司提供一個免費的DWG查看工個“DWG TrueView”用于查看所有版本的DWG文件。另外Autodesk公司是vendor lock-in策略的強力支持者,盡力保護DWG文件格式并且禁止開發支持DWG格式的開放源代碼庫。

            2006年11月12日,Autodesk公司對Open Design Alliance-一款支持DWG格式的自由庫OpenDWG提出了訴訟。

            ASCII格式的DXF文件的文檔Autodesk提供了,但是二進制的DWG格式并沒有提供相關文檔,由上可見對DWG文件的讀寫處理是非常困難的。本文主要介紹如何使用Libredwg庫來對讀取DWG中的幾何數據,并將幾何數據生成為可以在OpenCASCADE中顯示的Tcl腳本,以驗證讀取數據的正確性。

            2.Modify Libredwg for Visual Studio

            Libredwg是一個Free的讀寫DWG文件的C庫,這個程序是GNU項目的一部分,授權方式是GNU GPL3。

            Libredwg是Libdwg的一個分支,其目的是創建OpenDWG庫的一個替代庫。也是高優先級的Free軟件項目:

            http://www.fsf.org/campaigns/priority-projects/priority-projects/highpriorityprojects#ReplaceOpenDWG ,更多信息可訪問http://www.gnu.org/software/libredwg 。

            從網上下載的Libredwg源程序是在Linux下編譯的,并沒有配置在Windows下編譯方法。為了使用Libredwg可以在Windows上的Visual Studio中編譯通過,對Libredwg做了一些修改,最終編譯成功。在Visual Studio 2008上成功編譯的工程可以文后的鏈接中下載。

            下面給出使用Libredwg讀取DWG文件中直線、圓及文字的例子程序:

             

            /*
             * load_dwg.c: load a DWG, get lines, text and circles
             * written by Felipe Castro
             * modified by Felipe Corrêa da Silva Sances
             * modified by Thien-Thi Nguyen
             
            */

            #include 
            <dwg.h>
            #include 
            "suffix.c"

            void add_line(double x1, double y1, double x2, double y2)
            {
              
            // Make something with that
            }

            void add_circle(double x, double y, double R)
            {
              
            // Make something with that
            }

            void add_text(double x, double y, char *txt)
            {
              
            // Make something with that
            }

            int load_dwg(char *filename)
            {
              unsigned 
            int i;
              
            int success;
              Dwg_Data dwg;

              dwg.num_objects 
            = 0;
              success 
            = dwg_read_file(filename, &dwg);
              
            for (i = 0; i < dwg.num_objects; i++)
                {
                  Dwg_Entity_LINE 
            *line;
                  Dwg_Entity_CIRCLE 
            *circle;
                  Dwg_Entity_TEXT 
            *text;

                  
            switch (dwg.object[i].type)
                    {
                  
            case DWG_TYPE_LINE:
                    line 
            = dwg.object[i].tio.entity->tio.LINE;
                    add_line(line
            ->start.x, line->end.x, line->start.y, line->end.y);
                    
            break;
                  
            case DWG_TYPE_CIRCLE:
                    circle 
            = dwg.object[i].tio.entity->tio.CIRCLE;
                    add_circle(circle
            ->center.x, circle->center.y, circle->radius);
                    
            break;
                  
            case DWG_TYPE_TEXT:
                    text 
            = dwg.object[i].tio.entity->tio.TEXT;
                    add_text(text
            ->insertion_pt.x, text->insertion_pt.y, text->text_value);
                    
            break;
                    }
                }
              dwg_free(
            &dwg);
              
            return success;
            }

            int main (int argc, char *argv[])
            {
              REQUIRE_INPUT_FILE_ARG (argc);
              load_dwg (argv[
            1]);
              
            return 0;
            }

            因為Libredwg用的C編程風格,沒有定義導出定義宏,所以決定將Libredwg編譯成靜態庫libredwg.lib,然后使用其頭文件及這個靜態庫的方式來在程序中使用Libredwg庫。

            經過測試,若DWG中只有簡單的線和圓等簡單實體,Libredwg還是可以正確讀取出。但是若用rewrite的例子來測試寫DWG的功能,簡單的實例如一個圓的數據都會寫出到DWG失敗,看樣子寫的功能還沒有完全實現好。

            3.DWG to OCC

            基于上面的例子程序,結合Libredwg的讀取功能,將DWG中的幾何數據導出成Tcl腳本,這樣就可以方便在OpenCASCADE的Draw Test Harness中來測試結果了。下面給出具體的程序實例及如何在Draw Test Harness中來使用生成的Tcl腳本。

             

            /*
            *    Copyright (c) 2014 eryar All Rights Reserved.
            *
            *        File    : Main.cpp
            *        Author  : eryar@163.com
            *        Date    : 2014-10-15 20:46
            *        Version : 1.0v
            *
            *    Description : Use libredwg to read data from DWG and
            *                  output them to Tcl script for Draw.
            *
            *      Key words : OpenCASCADE, libredwg, Draw Test Harness
            */

            #include 
            "dwg.h"

            #include 
            <fstream>
            #include 
            <iostream>

            #pragma comment(lib, 
            "../Debug/libredwg.lib")

            // Output the entities to Tcl for OpenCASCADE Draw.
            static std::ofstream theTclExporter("d:/dwg2occ.tcl");


            void OutputLine(int id, const Dwg_Entity_LINE* theLine)
            {
                
            // Draw Tcl command: vline name xa ya za xb yb zb
                theTclExporter << "vline line" << id << " " 
                    
            << theLine->start.x << " " << theLine->start.y << " " << theLine->start.z << " " 
                    
            << theLine->end.x << " " << theLine->end.y << " " << theLine->end.z << std::endl;
            }

            void OutputCircle(int id, const Dwg_Entity_CIRCLE* theCircle)
            {
                
            // Draw Tcl command: circle name x y [z [dx dy dz]] [ux uy [uz]] radius
                
            // 1. make a curve
                theTclExporter << "circle circle" << id << " "
                    
            << theCircle->center.x << " " << theCircle->center.y << " " << theCircle->center.z << " " 
                    
            << "0 0 1 " << theCircle->radius << std::endl;

                
            // 2. make edge from the circle
                theTclExporter << "mkedge e" << id << " "
                    
            << "circle" << id << std::endl;

                
            // 3. display the circle edge
                theTclExporter << "vdisplay e" << id << std::endl;
            }

            void OutputText(int id, const Dwg_Entity_TEXT* theText)
            {
                
            // vdrawtext : vdrawtext  : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]
                theTclExporter << "vdrawtext " << theText->text_value << " "
                    
            << theText->insertion_pt.x << " " << theText->insertion_pt.y << " 0" 
                    
            << " 255 255 000 " 
                    
            << theText->horiz_alignment << " " << theText->vert_alignment << " " 
                    
            << theText->height << " 1 Times-Roman"<< std::endl;
            }

            int LoadDwg(char* theDwgFile)
            {
                
            int aResult = 0;

                Dwg_Data aDwgData;

                aResult 
            = dwg_read_file(theDwgFile, &aDwgData);

                
            for (unsigned int i = 0; i < aDwgData.num_objects; ++i)
                {
                    
            switch (aDwgData.object[i].type)
                    {
                    
            case DWG_TYPE_LINE:
                        OutputLine(i, aDwgData.
            object[i].tio.entity->tio.LINE);
                        
            break;

                    
            case DWG_TYPE_CIRCLE:
                        OutputCircle(i, aDwgData.
            object[i].tio.entity->tio.CIRCLE);
                        
            break;

                    
            case DWG_TYPE_TEXT:
                        OutputText(i, aDwgData.
            object[i].tio.entity->tio.TEXT);
                        
            break;
                    }
                }

                
            return aResult;
            }

            int main(int argc, char* argv[])
            {
                theTclExporter.flags(std::ios::
            fixed);

                theTclExporter 
            << "pload ALL" << std::endl;
                theTclExporter 
            << "vinit" << std::endl;
                theTclExporter 
            << "vtrihedron tr" << std::endl;

                
            if (argc < 1)
                {
                    std::cout 
            << "please input the dwg file name!" << std::endl;
                }
                
            else
                {
                    LoadDwg(argv[
            1]);
                }

                theTclExporter 
            << "vdisplayall" << std::endl;
                theTclExporter 
            << "vfit" << std::endl;
                theTclExporter 
            << "vhelp" << std::endl;

                
            return 0;
            }

            將生成的dwg2occ.tcl在OpenCASCADE的Draw Test Harness中顯示如下所示:

            wps_clip_image-17275

            Figure 3.1 Import the Tcl script in the Draw Test Hanress of OpenCASCADE

            wps_clip_image-24182

            Figure 3.2 Enitites in the DWG file

            wps_clip_image-5022

            Figure 3.3 Entities in the Draw Test Harness of OpenCASCADE

            通過對比發現,直線和圓已經正確讀出,但是文字沒有讀出來。看來Libredwg的可靠性還有待提高啊。

            4.Conclusion

            通過使用Libredwg來讀取DWG格式中幾何數據,并將其轉換成OpenCASCADE的Draw Test Harness中能執行的Tcl腳本,以方便測試libredwg讀取數據的正確性。

            通過簡單測試發現,libredwg能讀取直線和圓,但是文字內容沒有正確讀出,看來libredwg的可靠性還有待提高,但是發現這個開源庫的更新很緩慢。

            5. References

            1. DWG Wiki: http://en.wikipedia.org/wiki/.dwg

            2. Libredwg: http://www.gnu.org/software/libredwg

            3. OpenCASCADE Test Harness User’s Guide 6.7.1

             

            Libredwg for Visual Studio: OpenCASCADE DataExchange DWG

            亚洲中文字幕伊人久久无码| 久久99精品久久久久久齐齐| 久久国产亚洲精品| 久久中文字幕人妻熟av女| 亚洲国产欧美国产综合久久| 国产成人精品久久二区二区| 精品久久久久久国产免费了| 久久精品桃花综合| 1000部精品久久久久久久久| 中文字幕久久亚洲一区| 99精品久久精品一区二区| 亚洲欧美日韩久久精品| 精品蜜臀久久久久99网站| 久久夜色精品国产www| 97精品伊人久久大香线蕉app| 人妻中文久久久久| 国产精品久久久久久福利69堂| 久久天天婷婷五月俺也去| 久久综合中文字幕| 精品国产VA久久久久久久冰 | 久久99精品国产99久久6男男| 亚洲色欲久久久久综合网| 91精品婷婷国产综合久久| 亚洲AV无一区二区三区久久| 伊人色综合久久天天网| 91久久福利国产成人精品| 99麻豆久久久国产精品免费| 性高湖久久久久久久久| 一本久道久久综合狠狠躁AV| 成人午夜精品久久久久久久小说| 蜜桃麻豆www久久| 热99re久久国超精品首页| 久久国产精品一区二区| 久久精品无码专区免费东京热| 久久婷婷人人澡人人爽人人爱| 久久只有这精品99| 久久人妻AV中文字幕| 亚洲AV日韩AV永久无码久久| 中文无码久久精品| AAA级久久久精品无码片| 久久国产精品久久|