You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
251 lines
6.4 KiB
C++
251 lines
6.4 KiB
C++
//////////////////////////////////////////////////////////////////////////////
|
|
//文件: 格式转换类
|
|
//主要功能:
|
|
// 转换AutoCAD的DXF明码格式
|
|
//
|
|
//程序编写: 2007-5-09
|
|
//
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
#pragma once
|
|
#include ".\otherformat.h"
|
|
#include "afxcoll.h"
|
|
|
|
namespace NFormatReader
|
|
{
|
|
|
|
#define DXF_READ_BREAK -1
|
|
#define DXF_READ_ERROR 0
|
|
#define DXF_READ_OK 1
|
|
#define DXF_READ_ELEMENT 2 //读取元素段
|
|
|
|
class CDxfFile :
|
|
public COtherFormat
|
|
{
|
|
public:
|
|
CDxfFile(void);
|
|
virtual ~CDxfFile(void);
|
|
|
|
int Read(LPCTSTR lpszPathName);
|
|
int Read(CFile& fr);
|
|
|
|
protected:
|
|
int ReadSection(CFile& fr);
|
|
|
|
//生成元素
|
|
void CreatePline(void);
|
|
|
|
//段信息
|
|
int ReadSectionEntities(CFile& fr);
|
|
int ReadSectionHeader(CFile& fr);
|
|
int ReadSectionClasses(CFile& fr);
|
|
int ReadSectionBlocks(CFile& fr);
|
|
int ReadSectionTables(CFile& fr);
|
|
int ReadSectionObjects(CFile& fr);
|
|
bool IsSectionEnd(CString &cmd);
|
|
|
|
//块信息
|
|
int ReadBlock(CFile& fr);
|
|
int EndBlock(CFile& fr);
|
|
//Table
|
|
int ReadTable(CFile& fr);
|
|
int EndTable(CFile& fr);
|
|
|
|
//元素信息
|
|
int ReadEntitieArc(CFile& fr);
|
|
int ReadEntitieCircle(CFile& fr);
|
|
int ReadEntitieLine(CFile& fr);
|
|
int ReadEntitiePline(CFile& fr);
|
|
int ReadEntitieText(CFile& fr);
|
|
int ReadEntitie3DFace(CFile& fr);
|
|
int ReadEntitiePoint(CFile& fr);
|
|
int ReadEntitieSolid(CFile& fr);
|
|
int ReadEntitieEllipse(CFile& fr);
|
|
int ReadEntitieSpline(CFile& fr);
|
|
int ReadEntitieLWPolyline(CFile& fr);
|
|
int ReadEntitieImage(CFile& fr);
|
|
int ReadEntitieMline(CFile& fr);
|
|
int ReadEntitieLeader(CFile& fr);
|
|
int ReadEntitieTrace(CFile& fr);
|
|
int ReadEntitieInsert(CFile& fr);
|
|
int ReadEntitieAttdef(CFile& fr);
|
|
int ReadEntitieAttrib(CFile& fr);
|
|
int ReadEntitieMText(CFile& fr);
|
|
int ReadEntitieHatch(CFile& fr);
|
|
|
|
//int _ReadEntitieHatch_MSegment(CFile& fr); //多线段
|
|
//int _ReadEntitieHatch_Line(CFile& fr); //直线
|
|
//int _ReadEntitieHatch_Arc(CFile& fr); //弧
|
|
//int _ReadEntitieHatch_EllipseArc(CFile& fr);//椭圆弧
|
|
//int _ReadEntitieHatch_Spline(CFile& fr); //样条曲线
|
|
|
|
int ReadEntitieDimension(CFile& fr);
|
|
int ReadEntitieImageDef(CFile& fr);
|
|
int ReadEntitieViewPort(CFile& fr);
|
|
int ReadEntitieRay(CFile& fr);
|
|
int ReadEntitieXLine(CFile& fr);
|
|
int ReadEntitieShape(CFile& fr);
|
|
int ReadEntitieVertex(CFile& fr); //读取曲线顶点
|
|
|
|
int ReadGeneralCode(CFile& fr); //适用于所有图形对象的组码
|
|
int ReadEntitieState();
|
|
int _ReadEntities(CFile& fr); //读取0段之后的
|
|
int ReadEntities(CFile& fr); //读取0段之后的
|
|
|
|
int SkipLine(CFile& fr); //跳过非0代码行
|
|
|
|
void InitCurrentElement(void);
|
|
virtual POSITION AddElement(void* pElement, int type);
|
|
|
|
protected:
|
|
virtual void* GetXY(void);
|
|
|
|
CString GetFontName(CString faceName);
|
|
void SetFontName(void* pCText_Value, char* pFaceName);
|
|
|
|
CPtrList m_listBlockXY; //块堆栈
|
|
BOOL IsBlockXY(void);
|
|
|
|
class CBlockMarkClone
|
|
{
|
|
public:
|
|
void* m_pXy;
|
|
void* m_pMarkXy;
|
|
CString m_strMarkName;
|
|
};
|
|
CList<CBlockMarkClone, CBlockMarkClone> m_listMarkClone;
|
|
|
|
class CHeader
|
|
{
|
|
public:
|
|
CHeader(void);
|
|
CString m_strVer; //版本号
|
|
CPoint3D PUCSORG; //当前图纸空间 UCS 原点
|
|
CPoint3D PUCSXDIR; //当前图纸空间 UCS X 轴
|
|
CPoint3D PUCSYDIR; //当前图纸空间 UCS Y 轴
|
|
};
|
|
CHeader header;
|
|
|
|
class CReadCode
|
|
{
|
|
public:
|
|
CReadCode(void);
|
|
int Compare(LPCTSTR lpszString);
|
|
|
|
int code;
|
|
CString cmd;
|
|
};
|
|
CReadCode m_rc;
|
|
int ReadCode(CFile& fr);
|
|
|
|
//Pline
|
|
class CPolylinePar
|
|
{
|
|
public:
|
|
CPolylinePar() {Init();};
|
|
void Init()
|
|
{
|
|
m_pointList.RemoveAll();
|
|
m_dStartWidth=0;
|
|
m_dEndWidth=0;
|
|
m_nSegmentType=0;
|
|
m_nSmoothType=0;
|
|
m_strEleType=_T("");
|
|
};
|
|
|
|
CPointList m_pointList;
|
|
double m_dStartWidth;
|
|
double m_dEndWidth;
|
|
int m_nSegmentType;
|
|
int m_nSmoothType;
|
|
CString m_strEleType;
|
|
};
|
|
CPolylinePar m_polylinePar;
|
|
|
|
struct _CURRENT_ELE{
|
|
DWORD m_dwID; //当前元素的句柄ID号
|
|
COLORREF m_colCurrent; //当前元素的颜色
|
|
BOOL m_bCurentView; //当前元素的可视状态
|
|
CString m_strLineType; // Used LineType's Name
|
|
};
|
|
_CURRENT_ELE m_curElement;
|
|
|
|
typedef struct tag_LAYER
|
|
{
|
|
char Name[512]; // Layer Name
|
|
UINT StandardFlags; // Standard flags
|
|
int Color; // Layer Color
|
|
char LineType[512]; // Line Type
|
|
} DXFLAYER, *PDXFLAYER;
|
|
|
|
CList<DXFLAYER, DXFLAYER> m_listLayer; //保存读取的层信息,为了后面设置元素的颜色、线型等参数
|
|
int FindLayer(CString strLayerName, DXFLAYER& ds);
|
|
|
|
typedef struct tag_LTYPE
|
|
{
|
|
char Name[512]; // Line Type Name
|
|
int StandardFlags; // Standard flags
|
|
char DescriptiveText[512]; // Descriptive Text
|
|
int ElementsNumber; // Line Elements Number
|
|
double TotalPatternLength; // Total Pattern Length
|
|
double Elements[30]; // Line Elements
|
|
} DXFLTYPE, *PDXFLTYPE;
|
|
|
|
typedef struct tag_STYLE
|
|
{
|
|
char Name[512]; // Style Name
|
|
char PrimaryFontFilename[512]; // Primary Font Filename
|
|
int StandardFlags; // Standard flag values -> 4=Vertical text
|
|
int TextGenerationFlags; // Text generation flags -> 2=Text is backward 4=Text is upside down
|
|
double FixedTextHeight; // Fixed text height
|
|
double WidthFactor; // Width Factor
|
|
double Height; // Height
|
|
double ObliqueAngle; // Oblique angle
|
|
} DXFSTYLE, *PDXFSTYLE;
|
|
|
|
typedef struct tag_DIMSTYLE
|
|
{
|
|
char Name[512]; // DimStyle Name
|
|
int StandardFlags; // Standard flag values
|
|
int DIMCLRD; // Dimension line & Arrow heads color
|
|
double DIMDLE; // Dimension line size after Extensionline
|
|
int DIMCLRE; // Extension line color
|
|
double DIMEXE; // Extension line size after Dimline
|
|
double DIMEXO; // Offset from origin
|
|
char DIMBLK1[512]; // 1st Arrow head
|
|
char DIMBLK2[512]; // 2nd Arrow head
|
|
double DIMASZ; // Arrow size
|
|
char DIMTXSTY[512]; // Text style
|
|
DWORD DIMTXSTYObjhandle; // Text style Object Handle
|
|
int DIMCLRT; // Text color
|
|
double DIMTXT; // Text height
|
|
int DIMTAD; // Vertical Text Placement
|
|
double DIMGAP; // Offset from dimension line
|
|
} DXFDIMSTYLE, *PDXFDIMSTYLE;
|
|
|
|
//Tables
|
|
int ReadTableVIEW(CFile &fr);
|
|
int ReadTableUCS(CFile &fr);
|
|
int ReadTableBLOCK_RECORD(CFile &fr);
|
|
int ReadTableAPPID(CFile &fr);
|
|
int ReadTableVPORT(CFile &fr);
|
|
int ReadTableSTYLE(CFile &fr);
|
|
int ReadTableDIMSTYLE(CFile &fr);
|
|
int ReadTableLAYER(CFile &fr);
|
|
int ReadTableLTYPE(CFile &fr);
|
|
|
|
typedef struct tag_DXFENTDIMENSION {
|
|
CPoint3D DefPoint3;
|
|
CPoint3D DefPoint4;
|
|
double DimRotationAngle;
|
|
CPoint3D DimLineDefPoint;
|
|
char BlockName[16];
|
|
char DimStyleName[512];
|
|
char DimText[1024];
|
|
} DXFENTDIMENSION, *PDXFENTDIMENSION;
|
|
};
|
|
|
|
};
|