全部给你不太合适,给你部分吧,不过也差不多了,没给的都很简单。
类:
TGeoDXFFile = Class(TGeoFile)
private
bReadPolyLine : boolean
//用标记 开始读 POLYLINE,用在 GetObjXYS, Read_2DPoint 里
bFindSEQEND : boolean
//在 GetObjXYS 开始读 POLYLINE 后,用于标记是否读到 SEQEND 组
iPolyLine70Group : integer
// 用在读DXF 文件的 POLYLINE 时, 该组值默认为0,如果为 1,则为封闭多边形
nSequence : longword;
function Read_2DPoint(var dX:do
uble;var dY:do
uble;intXGroup: integer =10): boolean;
function Read_GroupValue(intGroup: integer;var strLine: string): boolean;
function NextGroupCode(var intGroup: integer;var strLine: string): Boolean;
function Skip_upto_Section(strSectName:string) : boolean;
public
DXFFile : TextFile;
// WriteFile : TextFile;
//检测读取的文件用,最后要删除 ,存在 E:/Temp/Write.txt
constructor Create(FileName: string;
OpenMode: FileState);override;
destructor Destroy;override;
procedure OpenFile;
override;
procedure CloseFile;
override;
function EOF: boolean;
override;
procedure GetFileHeader(var nData: integer;
var LayerType : integer;
var Rect: TGeoRect);
override;
procedure PutFileHeader(nData: integer;
LayerType : integer;
Rect: TGeoRect);
override;
procedure GetObjHeader(var ObjHeader: TGeoObjHeader);
override;
procedure GetObjXYS(ObjHeader : TGeoObjHeader;PtList : TList;ObjPen : TGeoPen;ObjBrush : TGeoBrush;ObjFont : TGeoFont);
override;
procedure PutObjHeader(var ObjHeader: TGeoObjHeader;ObjPen : TGeoPen;ObjBrush : TGeoBrush;ObjFont : TGeoFont;Data : Pointer);
override;
procedure PutObjXYS(ObjHeader : TGeoObjHeader;PtList : TList;ObjPen : TGeoPen;ObjBrush : TGeoBrush;ObjFont : TGeoFont;Data : Pointer);
override;
procedure PutFinalSomeThing;override;
procedure BuildColumnList(Table : TTable);override;
procedure CreatePropertyFile(Table : TTable;OutFileName : string;ObjCount : integer);override;
end;
function TGeoDXFFile.Read_2DPoint(var dX:do
uble;var dY:do
uble;intXGroup: integer =10): boolean;
var intGroup : integer;
strLine : string;
bFindX : boolean;
begin
Result := False;
bFindX := False;
bFindSEQEND := False;
iPolyLine70Group := 0;
while bFindX = Falsedo
begin
if (NextGroupCode(intGroup,strLine)) then
begin
//在 GetObjXYS 开始读 POLYLINE 后,用于检查是否读到 SEQEND 组
//如果读到,跳出,返回 FALSE
if ((bReadPolyLine = True) and (strLine = 'SEQEND')) then
begin
bFindSEQEND := True;
exit;
end;
// 用在读DXF 文件的 POLYLINE 时, 该组值默认为0,如果为 1,则为封闭多边形
if ((bReadPolyLine = True) and (intGroup = 70)) then
iPolyLine70Group := StrtoInt(strLine);
//if strLine = '$DIMAPOST' then
showmessage ('$DIMPAOSE');
if intGroup = intXGroup then
begin
//if strLine = '$DIMAPOST' then
showmessage ('$DIMPAOSE');
dX := StrtoFloat(strLine);
bFindX := True;
end;
end
else
//取不到 10 组,到了文件末尾
break;
end;
if NextGroupCode(intGroup,strLine) then
begin
dY := StrtoFloat(strLine);
Read_2DPoint := True;
end;
end;
function TGeoDXFFile.Read_GroupValue(intGroup: integer;var strLine: string): boolean;
var iGroup : integer;
begin
Result := False;
while NextGroupCode(iGroup,strLine)do
begin
if iGroup = intGroup then
begin
//找到组 intGroup 的值
Result := True;
break;
end;
end;
end;
function TGeoDXFFile.NextGroupCode(var intGroup: integer;var strLine: string): Boolean;
var strBuf : string;
begin
Result := FALSE;
if System.Eof(DXFFile) then
begin
Exit;
end;
Readln(DXFFile,strBuf);
//监测读取的组值用,最后需要删除
// AssignFile(WriteFile,'E:/Temp/Write.txt');
// Append(WriteFile);
// Writeln(WriteFile,strBuf);
intGroup := StrtoInt(trim(strBuf));
if Trim(strBuf) = '' then
exit;
Readln(DXFFile,strBuf);
//监测读取的组值用,最后需要删除
// Writeln(WriteFile,strBuf);
// system.CloseFile(WriteFile);
strLine := Trim(strBuf);
// if Trim(strBuf) = '' then
exit;
//组值可以为空
Result := TRUE;
end;
// 跳到文件的某个节 HEADER , TABLES , BLCOKS , ENTITIES
// 或跳到某个制定位置
// LastModified 2002/05/15
function TGeoDXFFile.Skip_upto_Section(strSectName:string) : boolean;
var bFileEnd : boolean;
intGroup : integer;
strLine : string;
begin
//跳到文件第一行
reset(DXFFile);
bFileEnd := False;
while bFileEnd = Falsedo
begin
if System.Eof(DXFFile) then
begin
Exit;
end;
if NextGroupCode(intGroup,strLine) then
begin
if UpperCase(strLine) = UpperCase(strSectName) then
begin
Result := True;
break;
end;
end
else
//取不到值,到了文件末尾 或 文件错误
break;
end;
end;