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

            Read DXF File

            Posted on 2011-12-17 18:38 eryar 閱讀(5159) 評論(3)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            設計類圖如下所示:


            定義代碼為:
            File: Entity.h
             1 
             2 #ifndef _ENTITY_H_
             3 #define _ENTITY_H_
             4 
             5 #include <iostream>
             6 #include <list>
             7 #include <fstream>
             8 #include <string>
             9 using namespace std;
            10 
            11 class CEntity
            12 {
            13 public:
            14     CEntity(void);
            15     ~CEntity(void);
            16 
            17     // 顯示數據
            18     virtual void Show(void= 0;
            19 
            20 private:
            21 
            22 };
            23 
            24 #endif // _ENTITY_H_

            File : Entity.cpp
             1 #include "Entity.h"
             2 
             3 CEntity::CEntity(void)
             4 {
             5 }
             6 
             7 CEntity::~CEntity(void)
             8 {
             9 }
            10 
            File : Line.h
             1 
             2 #ifndef _LINE_H_
             3 #define _LINE_H_
             4 
             5 #include "Entity.h"
             6 
             7 class CLine : public CEntity
             8 {
             9 public:
            10     CLine(void);
            11     ~CLine(void);
            12 
            13     // 顯示數據
            14     void Show(void);
            15 
            16     // 設值
            17     void SetX1(double x);
            18     void SetY1(double y);
            19     void SetZ1(double z);
            20     void SetX2(double x);
            21     void SetY2(double y);
            22     void SetZ2(double z);
            23 
            24 private:
            25     // 直線起點x: 10
            26     double    m_x1;
            27     // 直線起點y: 20
            28     double    m_y1;
            29     // 直線起點z: 30
            30     double    m_z1;
            31     // 直線終點x: 11
            32     double    m_x2;
            33     // 直線終點y: 21
            34     double    m_y2;
            35     // 直線終點z: 31
            36     double    m_z2;
            37 
            38 };
            39 
            40 #endif // _LINE_H_
            File: Line.cpp
             1 #include "Line.h"
             2 
             3 CLine::CLine(void)
             4 {
             5     m_x1 = m_x2 = m_y1 = m_y2 = m_z1 = m_z2 = 0;
             6 }
             7 
             8 CLine::~CLine(void)
             9 {
            10 }
            11 
            12 void CLine::Show( void )
            13 {
            14     cout<<"-----------------LINE------------------"<<endl;
            15     cout<<"Start : ("<<m_x1<<","<<m_y1<<","<<m_z1<<")"<<endl;
            16     cout<<"End   : ("<<m_x2<<","<<m_y2<<","<<m_z2<<")"<<endl;
            17     cout<<"======================================="<<endl;
            18 }
            19 
            20 void CLine::SetX1( double x )
            21 {
            22     m_x1    = x;
            23 }
            24 
            25 void CLine::SetY1( double y )
            26 {
            27     m_y1    = y;
            28 }
            29 
            30 void CLine::SetZ1( double z )
            31 {
            32     m_z1    = z;
            33 }
            34 
            35 void CLine::SetX2( double x )
            36 {
            37     m_x2    = x;
            38 }
            39 
            40 void CLine::SetY2( double y )
            41 {
            42     m_y2    = y;
            43 }
            44 
            45 void CLine::SetZ2( double z )
            46 {
            47     m_z2    = z;
            48 }
            File : Circle.h
             1 
             2 #ifndef _CIRCLE_H_
             3 #define _CIRCLE_H_
             4 
             5 #include "Entity.h"
             6 
             7 class CCircle : public CEntity
             8 {
             9 public:
            10     CCircle(void);
            11     ~CCircle(void);
            12 
            13     // 顯示數據
            14     void Show(void);
            15 
            16     // 設值
            17     void SetX(double x);
            18     void SetY(double y);
            19     void SetZ(double z);
            20     void SetRadius(double r);
            21 
            22 private:
            23     // 圓心坐標x: 10
            24     double    m_x;
            25     // 圓心坐標x: 20
            26     double    m_y;
            27     // 圓心坐標x: 30
            28     double    m_z;
            29     // 半徑R: 40
            30     double    m_Radius;
            31 };
            32 
            33 #endif // _CIRCLE_H_
            File : Circle.cpp
             1 #include "Circle.h"
             2 
             3 CCircle::CCircle(void)
             4 {
             5     m_x    = m_y = m_z = m_Radius = 0;
             6 }
             7 
             8 CCircle::~CCircle(void)
             9 {
            10 }
            11 
            12 void CCircle::Show( void )
            13 {
            14     cout<<"----------------CIRCLE-----------------"<<endl;
            15     cout<<"Center : ("<<m_x<<","<<m_y<<","<<m_z<<")"<<endl;
            16     cout<<"Radius : "<<m_Radius<<endl;
            17     cout<<"======================================="<<endl;
            18 }
            19 
            20 void CCircle::SetX( double x )
            21 {
            22     m_x    = x;
            23 }
            24 
            25 void CCircle::SetY( double y )
            26 {
            27     m_y    = y;
            28 }
            29 
            30 void CCircle::SetZ( double z )
            31 {
            32     m_z    = z;
            33 }
            34 
            35 void CCircle::SetRadius( double r )
            36 {
            37     m_Radius    = r;
            38 }
            File. : Arc.h
             1 
             2 #ifndef _ARC_H_
             3 #define _ARC_H_
             4 
             5 #include "Entity.h"
             6 
             7 class CArc : public CEntity
             8 {
             9 public:
            10     CArc(void);
            11     ~CArc(void);
            12 
            13     // 顯示數據
            14     void Show(void);
            15 
            16     // 設值
            17     void SetStartAngle(double s);
            18     void SetEndAngle(double e);
            19 
            20 private:
            21     // 起點角度: 50
            22     double    m_StartAngle;
            23     // 端點角度: 51
            24     double    m_EndAngle;
            25 };
            26 
            27 #endif // _ARC_H_
            File : Arc.cpp
             1 #include "Arc.h"
             2 
             3 CArc::CArc(void)
             4 {
             5     m_StartAngle = 0;
             6     m_EndAngle     = 0;
             7 }
             8 
             9 CArc::~CArc(void)
            10 {
            11 }
            12 
            13 void CArc::Show( void )
            14 {
            15     cout<<"-----------------ARC-------------------"<<endl;
            16     cout<<"Start : "<<m_StartAngle<<endl;
            17     cout<<"End   : "<<m_EndAngle<<endl;
            18     cout<<"======================================="<<endl;
            19 }
            20 
            21 void CArc::SetStartAngle( double s )
            22 {
            23     m_StartAngle    = s;
            24 }
            25 
            26 void CArc::SetEndAngle( double e )
            27 {
            28     m_EndAngle    = e;
            29 }
            Put it all together :
            File : main.cpp
              1 
              2 #include "Arc.h"
              3 #include "Line.h"
              4 #include "Circle.h"
              5 
              6 
              7 int main(int argc, char* argv[])
              8 {
              9     char            szFileName[_MAX_FNAME];
             10     int                iGroupCode = 0;
             11     string            strGroupValue;
             12     string            strBuffer;
             13     list<CEntity*>    EntitiesList;
             14 
             15     cout<<"Input a DXF file name :";
             16     cin>>szFileName;
             17 
             18     CLine*        pLine    = NULL;
             19     CCircle*    pCircle    = NULL;
             20     CArc*        pArc    = NULL;
             21 
             22     ifstream    iDxfFile(szFileName);
             23 
             24     if (!iDxfFile.is_open())
             25     {
             26         cout<<"Open DXF file "<<szFileName<<" failed!"<<endl;
             27         return -1;
             28     }
             29 
             30     while ( !iDxfFile.eof())
             31     {
             32         getline(iDxfFile, strBuffer);
             33         iGroupCode    = atoi(strBuffer.c_str());
             34         getline(iDxfFile, strGroupValue);
             35 
             36         // Just Read Entities Section.
             37         if (iGroupCode == 2 && strGroupValue.compare("ENTITIES"== 0)
             38         {
             39             getline(iDxfFile, strBuffer);
             40             getline(iDxfFile, strGroupValue);
             41             iGroupCode    = atoi(strBuffer.c_str());
             42 
             43             while (strGroupValue.compare("ENDSEC"!= 0)
             44             {
             45                 // Read Line Data
             46                 if (iGroupCode == 0 && strGroupValue.compare("LINE"== 0)
             47                 {
             48                     pLine    = new CLine;
             49                     getline(iDxfFile, strBuffer);
             50                     getline(iDxfFile, strGroupValue);
             51                     iGroupCode = atoi(strBuffer.c_str());
             52 
             53                     while (iGroupCode)
             54                     {
             55                         // 
             56                         getline(iDxfFile, strBuffer);
             57                         getline(iDxfFile, strGroupValue);
             58                         iGroupCode = atoi(strBuffer.c_str());
             59                         switch(iGroupCode)
             60                         {
             61                         case 10: pLine->SetX1(atof(strGroupValue.c_str())); break;
             62                         case 20: pLine->SetY1(atof(strGroupValue.c_str())); break;
             63                         case 30: pLine->SetZ1(atof(strGroupValue.c_str())); break;
             64                         case 11: pLine->SetX2(atof(strGroupValue.c_str())); break;
             65                         case 21: pLine->SetY2(atof(strGroupValue.c_str())); break;
             66                         case 31: pLine->SetZ2(atof(strGroupValue.c_str())); break;
             67                         }
             68                     }
             69 
             70                     EntitiesList.push_front(pLine);
             71                 }
             72 
             73                 // Read Circle Data
             74                 else if (iGroupCode == 0 && strGroupValue.compare("CIRCLE"== 0)
             75                 {
             76                     pCircle    = new CCircle;
             77                     getline(iDxfFile, strBuffer);
             78                     getline(iDxfFile, strGroupValue);
             79                     iGroupCode = atoi(strBuffer.c_str());
             80 
             81                     while (iGroupCode)
             82                     {
             83                         // 
             84                         getline(iDxfFile, strBuffer);
             85                         getline(iDxfFile, strGroupValue);
             86                         iGroupCode = atoi(strBuffer.c_str());
             87                         switch(iGroupCode)
             88                         {
             89                         case 10: pCircle->SetX(atof(strGroupValue.c_str()));        break;
             90                         case 20: pCircle->SetY(atof(strGroupValue.c_str()));        break;
             91                         case 30: pCircle->SetZ(atof(strGroupValue.c_str()));        break;
             92                         case 40: pCircle->SetRadius(atof(strGroupValue.c_str()));    break;
             93                         }
             94                     }
             95 
             96                     EntitiesList.push_front(pCircle);
             97                 }
             98 
             99                 // Read Arc Data
            100                 else if (iGroupCode == 0 && strGroupValue.compare("ARC"== 0)
            101                 {
            102                     pArc    = new CArc;
            103                     getline(iDxfFile, strBuffer);
            104                     getline(iDxfFile, strGroupValue);
            105                     iGroupCode = atoi(strBuffer.c_str());
            106 
            107                     while (iGroupCode)
            108                     {
            109                         // 
            110                         getline(iDxfFile, strBuffer);
            111                         getline(iDxfFile, strGroupValue);
            112                         iGroupCode = atoi(strBuffer.c_str());
            113                         switch(iGroupCode)
            114                         {
            115                         case 50: pArc->SetStartAngle(atof(strGroupValue.c_str()));    break;
            116                         case 51: pArc->SetEndAngle(atof(strGroupValue.c_str()));    break;
            117                         }
            118                     }
            119 
            120                     EntitiesList.push_front(pArc);
            121                 }
            122 
            123                 // Other entities
            124                 else
            125                 {
            126                     // Move to next two lines
            127                     getline(iDxfFile, strBuffer);
            128                     getline(iDxfFile, strGroupValue);
            129                     /*iGroupCode = atoi(strBuffer.c_str());*/
            130                 }
            131             }
            132         }
            133 
            134     }
            135 
            136     // Output Entities
            137     for (list<CEntity*>::iterator iter = EntitiesList.begin(); 
            138         iter != EntitiesList.end(); 
            139         iter++)
            140     {
            141         (*iter)->Show();
            142     }
            143 
            144     return 0;
            145 }

            Feedback

            # re: Read DXF File  回復  更多評論   

            2013-03-26 16:33 by 王婷
            很厲害啊,牛掰哥哥,廣大單身MM可瘋狂追之...

            # re: Read DXF File[未登錄]  回復  更多評論   

            2014-08-14 09:34 by 張輝
            哥們,看了你很多文章,很佩服你!!

            # re: Read DXF File  回復  更多評論   

            2014-08-14 10:36 by eryar
            過獎了,
            我也是在學習中……

            @張輝
            久久亚洲精品无码观看不卡| 一级做a爰片久久毛片毛片| 青青热久久综合网伊人| 久久久91人妻无码精品蜜桃HD| 无码人妻久久一区二区三区| 99久久精品国产一区二区蜜芽| 久久91精品国产91| 99精品久久久久久久婷婷| 怡红院日本一道日本久久 | 国产成人综合久久久久久| 伊人久久大香线蕉AV一区二区| 日产精品久久久一区二区| 久久99精品久久久久久秒播| 天天爽天天狠久久久综合麻豆| 国内精品欧美久久精品| 91精品国产色综合久久| 亚洲国产另类久久久精品黑人| 激情五月综合综合久久69| 99久久99这里只有免费的精品| 国产69精品久久久久观看软件| 99热热久久这里只有精品68| 99久久99久久| 97久久超碰成人精品网站| 亚洲国产精品无码久久| 久久这里只有精品首页| 欧美精品丝袜久久久中文字幕 | 人人狠狠综合久久亚洲| 999久久久免费国产精品播放| 成人妇女免费播放久久久| 天堂久久天堂AV色综合| 日韩欧美亚洲综合久久| 一本一道久久a久久精品综合| 久久国产成人亚洲精品影院| 99热成人精品免费久久| 99久久精品免费| 久久久精品久久久久久 | 亚洲国产视频久久| 中文字幕无码久久精品青草| 亚洲午夜无码久久久久小说| 久久精品极品盛宴观看| 一本一本久久a久久精品综合麻豆|