• <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级毛片| 久久精品国产亚洲精品| 精品无码久久久久国产| 久久久久久亚洲Av无码精品专口| 一本久久知道综合久久| 亚洲色欲久久久综合网| 嫩草伊人久久精品少妇AV| 久久人人爽人人爽人人片av高请 | 精品一区二区久久久久久久网站| 色综合久久久久久久久五月| 国产成人精品三上悠亚久久| 久久青青草原精品国产| 国产精品视频久久久| 青青青国产成人久久111网站| 88久久精品无码一区二区毛片 | 国产综合久久久久久鬼色| 91精品国产乱码久久久久久| 久久er国产精品免费观看2| 国产精自产拍久久久久久蜜| 久久久噜噜噜久久| 亚洲国产精品18久久久久久| 狠狠色丁香久久婷婷综合五月| 色综合合久久天天综合绕视看| 色综合久久久久综合99| 97久久婷婷五月综合色d啪蜜芽| 精品久久久久久成人AV| 久久强奷乱码老熟女网站| 亚洲愉拍99热成人精品热久久| 久久99国产精品久久久| 亚洲国产精品嫩草影院久久| 久久久久无码精品国产| 久久久久婷婷| 久久精品免费一区二区三区| 国产69精品久久久久观看软件 | 日韩美女18网站久久精品| 色妞色综合久久夜夜| 久久影院久久香蕉国产线看观看| 中文字幕乱码人妻无码久久|