diff --git a/applications/fpvviewer/fpvectorialsrc/dxfvectorialreader.pas b/applications/fpvviewer/fpvectorialsrc/dxfvectorialreader.pas index 32153aedf..a4bc9dbc2 100644 --- a/applications/fpvviewer/fpvectorialsrc/dxfvectorialreader.pas +++ b/applications/fpvviewer/fpvectorialsrc/dxfvectorialreader.pas @@ -77,6 +77,7 @@ type procedure ReadENTITIES_LINE(ATokens: TDXFTokens; AData: TvVectorialDocument); procedure ReadENTITIES_ARC(ATokens: TDXFTokens; AData: TvVectorialDocument); procedure ReadENTITIES_CIRCLE(ATokens: TDXFTokens; AData: TvVectorialDocument); + procedure ReadENTITIES_DIMENSION(ATokens: TDXFTokens; AData: TvVectorialDocument); procedure ReadENTITIES_ELLIPSE(ATokens: TDXFTokens; AData: TvVectorialDocument); procedure ReadENTITIES_TEXT(ATokens: TDXFTokens; AData: TvVectorialDocument); function GetCoordinateValue(AStr: shortstring): Double; @@ -344,6 +345,16 @@ begin CurToken := TDXFToken(ATokens.Items[i+1]); ANGDIR := StrToInt(CurToken.StrValue); Inc(i); + end + // This indicates the size of the document + else if CurToken.StrValue = '$LIMMAX' then + begin + {$Warning Actually verify if the values are present in this order} + CurToken := TDXFToken(ATokens.Items[i+1]); // If Group 10 + aData.Width := StrToFloat(CurToken.StrValue); + CurToken := TDXFToken(ATokens.Items[i+2]); // If Group 20 + aData.Height := StrToFloat(CurToken.StrValue); + Inc(i, 2); end; Inc(i); @@ -360,6 +371,7 @@ begin CurToken := TDXFToken(ATokens.Items[i]); if CurToken.StrValue = 'ARC' then ReadENTITIES_ARC(CurToken.Childs, AData) else if CurToken.StrValue = 'CIRCLE' then ReadENTITIES_CIRCLE(CurToken.Childs, AData) + else if CurToken.StrValue = 'DIMENSION' then ReadENTITIES_DIMENSION(CurToken.Childs, AData) else if CurToken.StrValue = 'ELLIPSE' then ReadENTITIES_ELLIPSE(CurToken.Childs, AData) else if CurToken.StrValue = 'LINE' then ReadENTITIES_LINE(CurToken.Childs, AData) else if CurToken.StrValue = 'TEXT' then @@ -514,6 +526,99 @@ begin CircleCenterZ, CircleRadius); end; +{ +Group codes Description +100 Subclass marker (AcDbDimension) +2 Name of the block that contains the entities that make up the dimension picture +10 Definition point (in WCS) DXF: X value; APP: 3D point +20, 30 DXF: Y and Z values of definition point (in WCS) +11 Middle point of dimension text (in OCS) DXF: X value; APP: 3D point +21, 31 DXF: Y and Z values of middle point of dimension text (in OCS) +70 Dimension type. + Values 0-6 are integer values that represent the dimension type. + Values 32, 64, and 128 are bit values, which are added to the integer values + (value 32 is always set in R13 and later releases). + 0 = Rotated, horizontal, or vertical; 1 = Aligned; + 2 = Angular; 3 = Diameter; 4 = Radius; + 5 = Angular 3 point; 6 = Ordinate; + 32 = Indicates that the block reference (group code 2) is referenced by this dimension only. + 64 = Ordinate type. This is a bit value (bit 7) used only with integer value 6. + If set, ordinate is X-type; if not set, ordinate is Y-type. + 128 = This is a bit value (bit 8) added to the other group 70 values + if the dimension text has been positioned at a user-defined location + rather than at the default location. +71 Attachment point: + 1 = Top left; 2 = Top center; 3 = Top right; + 4 = Middle left; 5 = Middle center; 6 = Middle right; + 7 = Bottom left; 8 = Bottom center; 9 = Bottom right +72 Dimension text line spacing style (optional): + 1(or missing) = At least (taller characters will override) + 2 = Exact (taller characters will not override) +41 Dimension text line spacing factor (optional): + Percentage of default (3-on-5) line spacing to be applied. Valid values range from 0.25 to 4.00. +42 Actual measurement (optional; read-only value) +1 Dimension text explicitly entered by the user. Optional; default is the measurement. + If null or "<>", the dimension measurement is drawn as the text, + if " " (one blank space), the text is suppressed. Anything else is drawn as the text. +53 The optional group code 53 is the rotation angle of the dimension + text away from its default orientation (the direction of the dimension line) (optional). +51 All dimension types have an optional 51 group code, which indicates the + horizontal direction for the dimension entity. The dimension entity determines + the orientation of dimension text and lines for horizontal, vertical, and + rotated linear dimensions. + This group value is the negative of the angle between the OCS X axis + and the UCS X axis. It is always in the XY plane of the OCS. +210 Extrusion direction (optional; default = 0, 0, 1) DXF: X value; APP: 3D vector +220, 230 DXF: Y and Z values of extrusion direction (optional) +3 Dimension style name +} +procedure TvDXFVectorialReader.ReadENTITIES_DIMENSION(ATokens: TDXFTokens; + AData: TvVectorialDocument); +{var + CurToken: TDXFToken; + i: Integer; + // LINE + LineStartX, LineStartY, LineStartZ: Double; + LineEndX, LineEndY, LineEndZ: Double;} +begin +{ // Initial values + LineStartX := 0; + LineStartY := 0; + LineStartZ := 0; + LineEndX := 0; + LineEndY := 0; + LineEndZ := 0; + + for i := 0 to ATokens.Count - 1 do + begin + // Now read and process the item name + CurToken := TDXFToken(ATokens.Items[i]); + + // Avoid an exception by previously checking if the conversion can be made + if CurToken.GroupCode in [10, 20, 30, 11, 21, 31] then + begin + CurToken.FloatValue := StrToFloat(Trim(CurToken.StrValue), FPointSeparator); + end; + + case CurToken.GroupCode of + 10: LineStartX := CurToken.FloatValue; + 20: LineStartY := CurToken.FloatValue; + 30: LineStartZ := CurToken.FloatValue; + 11: LineEndX := CurToken.FloatValue; + 21: LineEndY := CurToken.FloatValue; + 31: LineEndZ := CurToken.FloatValue; + end; + end; + + // And now write it + {$ifdef FPVECTORIALDEBUG} +// WriteLn(Format('Adding Line from %f,%f to %f,%f', [LineStartX, LineStartY, LineEndX, LineEndY])); + {$endif} + AData.StartPath(LineStartX, LineStartY); + AData.AddLineToPath(LineEndX, LineEndY); + AData.EndPath();} +end; + { 100 Subclass marker (AcDbEllipse) 10 Center point (in WCS) DXF: X value; APP: 3D point diff --git a/applications/fpvviewer/fpvv_mainform.lfm b/applications/fpvviewer/fpvv_mainform.lfm index 08d4a61ec..6d501e4f1 100644 --- a/applications/fpvviewer/fpvv_mainform.lfm +++ b/applications/fpvviewer/fpvv_mainform.lfm @@ -6,6 +6,8 @@ object frmFPVViewer: TfrmFPVViewer Caption = 'Free Pascal Vectorial Viewer' ClientHeight = 473 ClientWidth = 375 + OnCreate = FormCreate + OnDestroy = FormDestroy LCLVersion = '0.9.31' object editFileName: TFileNameEdit Left = 8 @@ -82,13 +84,13 @@ object frmFPVViewer: TfrmFPVViewer Caption = 'Start Pos Y:' ParentColor = False end - object Button1: TButton + object btnViewDXFTokens: TButton Left = 112 Height = 25 Top = 41 Width = 128 Caption = 'View DXF Tokens' - OnClick = Button1Click + OnClick = btnViewDXFTokensClick TabOrder = 5 end object notebook: TNotebook @@ -104,23 +106,7 @@ object frmFPVViewer: TfrmFPVViewer Anchors = [akTop, akLeft, akRight, akBottom] TabOrder = 6 TabStop = True - object Page1: TPage - ClientWidth = 375 - ClientHeight = 345 - object imageView: TImage - AnchorSideRight.Control = Page1 - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Page1 - AnchorSideBottom.Side = asrBottom - Left = 8 - Height = 332 - Top = 8 - Width = 362 - Anchors = [akTop, akLeft, akRight, akBottom] - AutoSize = True - BorderSpacing.Right = 5 - BorderSpacing.Bottom = 5 - end + object pageViewer: TPage end object Page2: TPage ClientWidth = 21504 diff --git a/applications/fpvviewer/fpvv_mainform.pas b/applications/fpvviewer/fpvv_mainform.pas index 8282ca46e..c359d90d8 100644 --- a/applications/fpvviewer/fpvv_mainform.pas +++ b/applications/fpvviewer/fpvv_mainform.pas @@ -6,7 +6,8 @@ interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, EditBtn, - StdCtrls, Spin, ExtCtrls, ComCtrls; + StdCtrls, Spin, ExtCtrls, ComCtrls, + fpvv_drawer; type @@ -14,13 +15,12 @@ type TfrmFPVViewer = class(TForm) btnVisualize: TButton; - Button1: TButton; + btnViewDXFTokens: TButton; editFileName: TFileNameEdit; - imageView: TImage; Label2: TLabel; Label3: TLabel; notebook: TNotebook; - Page1: TPage; + pageViewer: TPage; Page2: TPage; spinStartX: TSpinEdit; spinStartY: TSpinEdit; @@ -28,12 +28,15 @@ type Label1: TLabel; DXFTreeView: TTreeView; procedure btnVisualizeClick(Sender: TObject); - procedure Button1Click(Sender: TObject); + procedure btnViewDXFTokensClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); private { private declarations } public { public declarations } - end; + Drawer: TFPVVDrawer; + end; var frmFPVViewer: TfrmFPVViewer; @@ -62,21 +65,24 @@ begin Vec := TvVectorialDocument.Create; try Vec.ReadFromFile(editFileName.FileName, vfDXF); - imageView.Canvas.Brush.Color := clWhite; - imageView.Canvas.FillRect(0, 0, imageView.Width, imageView.Height); + Drawer.Drawing.Width := Round(Vec.Width); + Drawer.Drawing.Height := Round(Vec.Height); + Drawer.Drawing.Canvas.Brush.Color := clWhite; + Drawer.Drawing.Canvas.FillRect(0, 0, Drawer.Drawing.Width, Drawer.Drawing.Height); DrawFPVectorialToCanvas( Vec, - imageView.Canvas, + Drawer.Drawing.Canvas, spinStartX.Value, - spinStartY.Value + imageView.Height, + spinStartY.Value + Drawer.Drawing.Height, spinScale.Value, -1 * spinScale.Value); + Drawer.Invalidate; finally Vec.Free; end; end; -procedure TfrmFPVViewer.Button1Click(Sender: TObject); +procedure TfrmFPVViewer.btnViewDXFTokensClick(Sender: TObject); var Reader: TvDXFVectorialReader; Vec: TvVectorialDocument; @@ -97,5 +103,19 @@ begin end; end; +procedure TfrmFPVViewer.FormCreate(Sender: TObject); +begin + Drawer := TFPVVDrawer.Create(Self); + Drawer.Parent := pageViewer; + Drawer.Top := 5; + Drawer.Left := 5; + Drawer.AnchorClient(5); +end; + +procedure TfrmFPVViewer.FormDestroy(Sender: TObject); +begin + Drawer.Free; +end; + end. diff --git a/applications/fpvviewer/fpvviewer.lpi b/applications/fpvviewer/fpvviewer.lpi index 7ffae7696..47c402a72 100644 --- a/applications/fpvviewer/fpvviewer.lpi +++ b/applications/fpvviewer/fpvviewer.lpi @@ -33,7 +33,7 @@ - + @@ -51,6 +51,11 @@ + + + + + diff --git a/applications/fpvviewer/fpvviewer.lpr b/applications/fpvviewer/fpvviewer.lpr index d75de4970..eb44a52c9 100644 --- a/applications/fpvviewer/fpvviewer.lpr +++ b/applications/fpvviewer/fpvviewer.lpr @@ -7,7 +7,7 @@ uses cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset - Forms, fpvv_mainform, dxftokentotree + Forms, fpvv_mainform, dxftokentotree, fpvv_drawer { you can add units after this }; {$R *.res}