Reestablishes drawing the cube example

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1459 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2011-01-25 14:43:07 +00:00
parent d67eefba96
commit 907f0fe3e0
2 changed files with 48 additions and 43 deletions

View File

@ -70,13 +70,13 @@ type
LineEndX, LineEndY, LineEndZ: Double; LineEndX, LineEndY, LineEndZ: Double;
function SeparateString(AString: string; ASeparator: Char): T10Strings; function SeparateString(AString: string; ASeparator: Char): T10Strings;
procedure ReadENTITIES(ATokens: TDXFTokens; AData: TvVectorialDocument); procedure ReadENTITIES(ATokens: TDXFTokens; AData: TvVectorialDocument);
function ReadENTITIES_LINE(AStrings: TStrings; var AIndex: Integer; AData: TvVectorialDocument): Boolean; function ReadENTITIES_LINE(ATokens: TDXFTokens; AData: TvVectorialDocument): Boolean;
function GetCoordinate(AStr: shortstring): Integer; function GetCoordinate(AStr: shortstring): Integer;
function GetCoordinateValue(AStr: shortstring): Double; function GetCoordinateValue(AStr: shortstring): Double;
public public
{ General reading methods } { General reading methods }
Tokenizer: TDXFTokenizer; Tokenizer: TDXFTokenizer;
constructor Create; constructor Create; override;
Destructor Destroy; override; Destructor Destroy; override;
procedure ReadFromStrings(AStrings: TStrings; AData: TvVectorialDocument); override; procedure ReadFromStrings(AStrings: TStrings; AData: TvVectorialDocument); override;
end; end;
@ -131,7 +131,7 @@ var
i: Integer; i: Integer;
StrSectionGroupCode, StrSectionName: string; StrSectionGroupCode, StrSectionName: string;
IntSectionGroupCode: Integer; IntSectionGroupCode: Integer;
CurTokenBase, NextTokenBase, ENTITIESTokenBase: TDXFTokens; CurTokenBase, NextTokenBase, SectionTokenBase: TDXFTokens;
NewToken: TDXFToken; NewToken: TDXFToken;
ParserState: Integer; ParserState: Integer;
begin begin
@ -164,6 +164,10 @@ begin
ParserState := 1; ParserState := 1;
NextTokenBase := NewToken.Childs; NextTokenBase := NewToken.Childs;
end end
else if (StrSectionName = 'EOF') then
begin
Exit;
end
else else
begin begin
raise Exception.Create(Format( raise Exception.Create(Format(
@ -181,15 +185,12 @@ begin
(StrSectionName = 'THUMBNAILIMAGE') then (StrSectionName = 'THUMBNAILIMAGE') then
begin begin
ParserState := 2; ParserState := 2;
SectionTokenBase := CurTokenBase;
end end
else if (StrSectionName = 'ENTITIES') then else if (StrSectionName = 'ENTITIES') then
begin begin
ParserState := 3; ParserState := 3;
ENTITIESTokenBase := CurTokenBase; SectionTokenBase := CurTokenBase;
end
else if (StrSectionName = 'EOF') then
begin
Exit;
end end
else else
begin begin
@ -203,6 +204,7 @@ begin
if StrSectionName = 'ENDSEC' then if StrSectionName = 'ENDSEC' then
begin begin
ParserState := 0; ParserState := 0;
CurTokenBase := SectionTokenBase;
NextTokenBase := Tokens; NextTokenBase := Tokens;
end; end;
end end
@ -211,9 +213,15 @@ begin
begin begin
if IsENTITIES_Subsection(StrSectionName) then if IsENTITIES_Subsection(StrSectionName) then
begin begin
CurTokenBase := ENTITIESTokenBase; CurTokenBase := SectionTokenBase;
NextTokenBase := NewToken.Childs; NextTokenBase := NewToken.Childs;
end end
else if StrSectionName = 'ENDSEC' then
begin
ParserState := 0;
CurTokenBase := SectionTokenBase;
NextTokenBase := Tokens;
end;
end; end;
CurTokenBase.Add(NewToken); CurTokenBase.Add(NewToken);
@ -319,16 +327,15 @@ begin
LineEndZ := 0; LineEndZ := 0;
// Read the data of the line // Read the data of the line
// Inc(AIndex, 2); ReadENTITIES_LINE(CurToken.Childs, AData);
// while not ReadENTITIES_LINE(AStrings, AIndex, AData) do ;
// And now write it // And now write it
{$ifdef FPVECTORIALDEBUG} {$ifdef FPVECTORIALDEBUG}
WriteLn(Format('Adding Line from %f,%f to %f,%f', [LineStartX, LineStartY, LineEndX, LineEndY])); WriteLn(Format('Adding Line from %f,%f to %f,%f', [LineStartX, LineStartY, LineEndX, LineEndY]));
{$endif} {$endif}
// AData.StartPath(LineStartX, LineStartY); AData.StartPath(LineStartX, LineStartY);
// AData.AddLineToPath(LineEndX, LineEndY); AData.AddLineToPath(LineEndX, LineEndY);
// AData.EndPath(); AData.EndPath();
end end
else if CurToken.StrValue = 'TEXT' then else if CurToken.StrValue = 'TEXT' then
begin begin
@ -337,40 +344,26 @@ begin
end; end;
end; end;
function TvDXFVectorialReader.ReadENTITIES_LINE(AStrings: TStrings; function TvDXFVectorialReader.ReadENTITIES_LINE(ATokens: TDXFTokens; AData: TvVectorialDocument): Boolean;
var AIndex: Integer; AData: TvVectorialDocument): Boolean;
var var
StrSectionNum, StrSectionValue: string; CurToken: TDXFToken;
IntSectionNum: Integer; i: Integer;
FloatSectionValue: double;
begin begin
Result := False; for i := 0 to ATokens.Count - 1 do
{ // Now read and process the item name
StrSectionNum := AStrings.Strings[AIndex];
StrSectionValue := AStrings.Strings[AIndex+1];
if IsENTITIES_Subsection(StrSectionValue) or
(StrSectionValue = 'ENDSEC') then
begin begin
Exit(True); // Now read and process the item name
end CurToken := TDXFToken(ATokens.Items[i]);
else CurToken.FloatValue := StrToFloat(Trim(CurToken.StrValue));
begin
Inc(AIndex, 2);
IntSectionNum := StrToInt(Trim(StrSectionNum)); case CurToken.GroupCode of
FloatSectionValue := StrToFloat(Trim(StrSectionValue)); 10: LineStartX := CurToken.FloatValue;
20: LineStartY := CurToken.FloatValue;
case IntSectionNum of 30: LineStartZ := CurToken.FloatValue;
10: LineStartX := FloatSectionValue; 11: LineEndX := CurToken.FloatValue;
20: LineStartY := FloatSectionValue; 21: LineEndY := CurToken.FloatValue;
30: LineStartZ := FloatSectionValue; 31: LineEndZ := CurToken.FloatValue;
11: LineEndX := FloatSectionValue;
21: LineEndY := FloatSectionValue;
31: LineEndZ := FloatSectionValue;
end; end;
end;} end;
end; end;
function TvDXFVectorialReader.GetCoordinate(AStr: shortstring): Integer; function TvDXFVectorialReader.GetCoordinate(AStr: shortstring): Integer;

View File

@ -186,6 +186,7 @@ type
TvCustomVectorialReader = class TvCustomVectorialReader = class
public public
{ General reading methods } { General reading methods }
constructor Create; virtual;
procedure ReadFromFile(AFileName: string; AData: TvVectorialDocument); virtual; procedure ReadFromFile(AFileName: string; AData: TvVectorialDocument); virtual;
procedure ReadFromStream(AStream: TStream; AData: TvVectorialDocument); virtual; procedure ReadFromStream(AStream: TStream; AData: TvVectorialDocument); virtual;
procedure ReadFromStrings(AStrings: TStrings; AData: TvVectorialDocument); virtual; procedure ReadFromStrings(AStrings: TStrings; AData: TvVectorialDocument); virtual;
@ -202,6 +203,7 @@ type
TvCustomVectorialWriter = class TvCustomVectorialWriter = class
public public
{ General writing methods } { General writing methods }
constructor Create; virtual;
procedure WriteToFile(AFileName: string; AData: TvVectorialDocument); virtual; procedure WriteToFile(AFileName: string; AData: TvVectorialDocument); virtual;
procedure WriteToStream(AStream: TStream; AData: TvVectorialDocument); virtual; procedure WriteToStream(AStream: TStream; AData: TvVectorialDocument); virtual;
procedure WriteToStrings(AStrings: TStrings; AData: TvVectorialDocument); virtual; procedure WriteToStrings(AStrings: TStrings; AData: TvVectorialDocument); virtual;
@ -758,6 +760,11 @@ end;
{ TvCustomVectorialReader } { TvCustomVectorialReader }
constructor TvCustomVectorialReader.Create;
begin
inherited Create;
end;
procedure TvCustomVectorialReader.ReadFromFile(AFileName: string; AData: TvVectorialDocument); procedure TvCustomVectorialReader.ReadFromFile(AFileName: string; AData: TvVectorialDocument);
var var
FileStream: TFileStream; FileStream: TFileStream;
@ -806,6 +813,11 @@ end;
{ TsCustomSpreadWriter } { TsCustomSpreadWriter }
constructor TvCustomVectorialWriter.Create;
begin
inherited Create;
end;
{@@ {@@
Default file writting method. Default file writting method.