You've already forked lazarus-ccr
fpvectorial: Adds pen and brush information to all objects and other small improvements
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1561 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -515,6 +515,7 @@ var
|
||||
// LINE
|
||||
LineStartX, LineStartY, LineStartZ: Double;
|
||||
LineEndX, LineEndY, LineEndZ: Double;
|
||||
LLineColor: TvColor;
|
||||
begin
|
||||
// Initial values
|
||||
LineStartX := 0;
|
||||
@@ -523,6 +524,7 @@ begin
|
||||
LineEndX := 0;
|
||||
LineEndY := 0;
|
||||
LineEndZ := 0;
|
||||
LLineColor := clvBlack;
|
||||
|
||||
for i := 0 to ATokens.Count - 1 do
|
||||
begin
|
||||
@@ -530,7 +532,7 @@ begin
|
||||
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
|
||||
if CurToken.GroupCode in [10, 20, 30, 11, 21, 31, 62] then
|
||||
begin
|
||||
CurToken.FloatValue := StrToFloat(Trim(CurToken.StrValue), FPointSeparator);
|
||||
end;
|
||||
@@ -542,6 +544,7 @@ begin
|
||||
11: LineEndX := CurToken.FloatValue;
|
||||
21: LineEndY := CurToken.FloatValue;
|
||||
31: LineEndZ := CurToken.FloatValue;
|
||||
62: LLineColor := DXFColorIndexToVColor(Trunc(CurToken.FloatValue));
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -556,7 +559,7 @@ begin
|
||||
// WriteLn(Format('Adding Line from %f,%f to %f,%f', [LineStartX, LineStartY, LineEndX, LineEndY]));
|
||||
{$endif}
|
||||
AData.StartPath(LineStartX, LineStartY);
|
||||
AData.AddLineToPath(LineEndX, LineEndY);
|
||||
AData.AddLineToPath(LineEndX, LineEndY, LLineColor);
|
||||
AData.EndPath();
|
||||
end;
|
||||
|
||||
@@ -580,6 +583,7 @@ var
|
||||
CurToken: TDXFToken;
|
||||
i: Integer;
|
||||
CenterX, CenterY, CenterZ, Radius, StartAngle, EndAngle: Double;
|
||||
LColor: TvColor;
|
||||
begin
|
||||
CenterX := 0.0;
|
||||
CenterY := 0.0;
|
||||
@@ -587,6 +591,7 @@ begin
|
||||
Radius := 0.0;
|
||||
StartAngle := 0.0;
|
||||
EndAngle := 0.0;
|
||||
LColor := clvBlack;
|
||||
|
||||
for i := 0 to ATokens.Count - 1 do
|
||||
begin
|
||||
@@ -594,7 +599,7 @@ begin
|
||||
CurToken := TDXFToken(ATokens.Items[i]);
|
||||
|
||||
// Avoid an exception by previously checking if the conversion can be made
|
||||
if CurToken.GroupCode in [10, 20, 30, 40, 50, 51] then
|
||||
if CurToken.GroupCode in [10, 20, 30, 40, 50, 51, 62] then
|
||||
begin
|
||||
CurToken.FloatValue := StrToFloat(Trim(CurToken.StrValue), FPointSeparator);
|
||||
end;
|
||||
@@ -606,6 +611,7 @@ begin
|
||||
40: Radius := CurToken.FloatValue;
|
||||
50: StartAngle := CurToken.FloatValue;
|
||||
51: EndAngle := CurToken.FloatValue;
|
||||
62: LColor := DXFColorIndexToVColor(Trunc(CurToken.FloatValue));
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -621,7 +627,7 @@ begin
|
||||
WriteLn(Format('Adding Arc Center=%f,%f Radius=%f StartAngle=%f EndAngle=%f',
|
||||
[CenterX, CenterY, Radius, StartAngle, EndAngle]));
|
||||
{$endif}
|
||||
AData.AddCircularArc(CenterX, CenterY, CenterZ, Radius, StartAngle, EndAngle);
|
||||
AData.AddCircularArc(CenterX, CenterY, CenterZ, Radius, StartAngle, EndAngle, LColor);
|
||||
end;
|
||||
|
||||
{
|
||||
@@ -1102,11 +1108,7 @@ begin
|
||||
case CurToken.GroupCode of
|
||||
10: Polyline[curPoint].X := CurToken.FloatValue - DOC_OFFSET.X;
|
||||
20: Polyline[curPoint].Y := CurToken.FloatValue - DOC_OFFSET.Y;
|
||||
62:
|
||||
begin
|
||||
if (CurToken.FloatValue >= 0) and (CurToken.FloatValue <= 15) then
|
||||
Polyline[curPoint].Color := DXFColorIndexToVColor(Trunc(CurToken.FloatValue));
|
||||
end;
|
||||
62: Polyline[curPoint].Color := DXFColorIndexToVColor(Trunc(CurToken.FloatValue));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@@ -1230,7 +1232,7 @@ end;
|
||||
function TvDXFVectorialReader.DXFColorIndexToVColor(AColorIndex: Integer
|
||||
): TvColor;
|
||||
begin
|
||||
if (AColorIndex <= 0) and (AColorIndex <= 15) then
|
||||
if (AColorIndex >= 0) and (AColorIndex <= 15) then
|
||||
Result := AUTOCAD_COLOR_PALETTE[AColorIndex]
|
||||
else
|
||||
raise Exception.Create(Format('[TvDXFVectorialReader.DXFColorIndexToFPVColor] Invalid DXF Color Index: %d', [AColorIndex]));
|
||||
|
@@ -18,7 +18,8 @@ unit fpvectorial;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Math;
|
||||
Classes, SysUtils, Math,
|
||||
fpcanvas;
|
||||
|
||||
type
|
||||
TvVectorialFormat = (
|
||||
@@ -74,6 +75,8 @@ type
|
||||
// Fields for linking the list
|
||||
Previous: TPathSegment;
|
||||
Next: TPathSegment;
|
||||
// Data fields
|
||||
Color: TvColor;
|
||||
end;
|
||||
|
||||
{@@
|
||||
@@ -86,7 +89,6 @@ type
|
||||
T2DSegment = class(TPathSegment)
|
||||
public
|
||||
X, Y: Double;
|
||||
Color: TvColor;
|
||||
end;
|
||||
|
||||
{@@
|
||||
@@ -138,12 +140,20 @@ type
|
||||
FontSize: integer;
|
||||
FontName: utf8string;
|
||||
Value: utf8string;
|
||||
Color: TvColor;
|
||||
end;
|
||||
|
||||
{@@
|
||||
}
|
||||
TvEntity = class
|
||||
public
|
||||
// Pen
|
||||
PenColor: TvColor;
|
||||
PenStyle: TFPPenStyle;
|
||||
PenWidth: Integer;
|
||||
// Brush
|
||||
BrushStyle: TFPBrushStyle;
|
||||
BrushColor: TvColor;
|
||||
end;
|
||||
|
||||
{@@
|
||||
@@ -245,7 +255,7 @@ type
|
||||
procedure AddText(AX, AY, AZ: Double; FontName: string; FontSize: integer; AText: utf8string); overload;
|
||||
procedure AddText(AX, AY, AZ: Double; AStr: utf8string); overload;
|
||||
procedure AddCircle(ACenterX, ACenterY, ACenterZ, ARadius: Double);
|
||||
procedure AddCircularArc(ACenterX, ACenterY, ACenterZ, ARadius, AStartAngle, AEndAngle: Double);
|
||||
procedure AddCircularArc(ACenterX, ACenterY, ACenterZ, ARadius, AStartAngle, AEndAngle: Double; AColor: TvColor);
|
||||
procedure AddEllipse(CenterX, CenterY, CenterZ, MajorHalfAxis, MinorHalfAxis, Angle: Double);
|
||||
// Dimensions
|
||||
procedure AddAlignedDimension(BaseLeft, BaseRight, DimLeft, DimRight: T3DPoint);
|
||||
@@ -538,6 +548,7 @@ begin
|
||||
segment.SegmentType := st2DLine;
|
||||
segment.X := AX;
|
||||
segment.Y := AY;
|
||||
segment.Color := clvBlack;
|
||||
|
||||
AppendSegmentToTmpPath(segment);
|
||||
end;
|
||||
@@ -659,7 +670,7 @@ begin
|
||||
end;
|
||||
|
||||
procedure TvVectorialDocument.AddCircularArc(ACenterX, ACenterY, ACenterZ,
|
||||
ARadius, AStartAngle, AEndAngle: Double);
|
||||
ARadius, AStartAngle, AEndAngle: Double; AColor: TvColor);
|
||||
var
|
||||
lCircularArc: TvCircularArc;
|
||||
begin
|
||||
@@ -670,6 +681,7 @@ begin
|
||||
lCircularArc.Radius := ARadius;
|
||||
lCircularArc.StartAngle := AStartAngle;
|
||||
lCircularArc.EndAngle := AEndAngle;
|
||||
lCircularArc.PenColor := AColor;
|
||||
FEntities.Add(lCircularArc);
|
||||
end;
|
||||
|
||||
|
@@ -17,11 +17,16 @@ uses
|
||||
fpvectorial;
|
||||
|
||||
procedure DrawFPVectorialToCanvas(ASource: TvVectorialDocument;
|
||||
{$ifdef USE_LCL_CANVAS}
|
||||
ADest: TCanvas;
|
||||
{$else}
|
||||
ADest: TFPCustomCanvas;
|
||||
{$endif}
|
||||
{$ifdef USE_LCL_CANVAS}ADest: TCanvas;{$else}ADest: TFPCustomCanvas;{$endif}
|
||||
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
|
||||
procedure DrawFPVPathsToCanvas(ASource: TvVectorialDocument;
|
||||
{$ifdef USE_LCL_CANVAS}ADest: TCanvas;{$else}ADest: TFPCustomCanvas;{$endif}
|
||||
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
|
||||
procedure DrawFPVEntitiesToCanvas(ASource: TvVectorialDocument;
|
||||
{$ifdef USE_LCL_CANVAS}ADest: TCanvas;{$else}ADest: TFPCustomCanvas;{$endif}
|
||||
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
|
||||
procedure DrawFPVTextToCanvas(ASource: TvVectorialDocument;
|
||||
{$ifdef USE_LCL_CANVAS}ADest: TCanvas;{$else}ADest: TFPCustomCanvas;{$endif}
|
||||
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
|
||||
|
||||
implementation
|
||||
@@ -112,11 +117,24 @@ end;
|
||||
}
|
||||
{$define FPVECTORIAL_TOCANVAS_DEBUG}
|
||||
procedure DrawFPVectorialToCanvas(ASource: TvVectorialDocument;
|
||||
{$ifdef USE_LCL_CANVAS}
|
||||
ADest: TCanvas;
|
||||
{$else}
|
||||
ADest: TFPCustomCanvas;
|
||||
{$ifdef USE_LCL_CANVAS}ADest: TCanvas;{$else}ADest: TFPCustomCanvas;{$endif}
|
||||
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
|
||||
begin
|
||||
{$ifdef FPVECTORIAL_TOCANVAS_DEBUG}
|
||||
WriteLn(':>DrawFPVectorialToCanvas');
|
||||
{$endif}
|
||||
|
||||
DrawFPVPathsToCanvas(ASource, ADest, ADestX, ADestY, AMulX, AMulY);
|
||||
DrawFPVEntitiesToCanvas(ASource, ADest, ADestX, ADestY, AMulX, AMulY);
|
||||
DrawFPVTextToCanvas(ASource, ADest, ADestX, ADestY, AMulX, AMulY);
|
||||
|
||||
{$ifdef FPVECTORIALDEBUG}
|
||||
WriteLn(':<DrawFPVectorialToCanvas');
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
procedure DrawFPVPathsToCanvas(ASource: TvVectorialDocument;
|
||||
{$ifdef USE_LCL_CANVAS}ADest: TCanvas;{$else}ADest: TFPCustomCanvas;{$endif}
|
||||
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
|
||||
|
||||
function CoordToCanvasX(ACoord: Double): Integer;
|
||||
@@ -139,26 +157,7 @@ var
|
||||
CurX, CurY: Integer; // Not modified by ADestX, etc
|
||||
CurveLength: Integer;
|
||||
t: Double;
|
||||
// For text
|
||||
CurText: TvText;
|
||||
// For entities
|
||||
CurEntity: TvEntity;
|
||||
CurCircle: TvCircle;
|
||||
CurEllipse: TvEllipse;
|
||||
//
|
||||
CurArc: TvCircularArc;
|
||||
FinalStartAngle, FinalEndAngle, tmpAngle: double;
|
||||
BoundsLeft, BoundsTop, BoundsRight, BoundsBottom,
|
||||
IntStartAngle, IntAngleLength, IntTmp: Integer;
|
||||
//
|
||||
CurDim: TvAlignedDimension;
|
||||
Points: array of TPoint;
|
||||
UpperDim, LowerDim: T3DPoint;
|
||||
begin
|
||||
{$ifdef FPVECTORIAL_TOCANVAS_DEBUG}
|
||||
WriteLn(':>DrawFPVectorialToCanvas');
|
||||
{$endif}
|
||||
|
||||
PosX := 0;
|
||||
PosY := 0;
|
||||
ADest.Brush.Style := bsClear;
|
||||
@@ -222,6 +221,39 @@ begin
|
||||
WriteLn('');
|
||||
{$endif}
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure DrawFPVEntitiesToCanvas(ASource: TvVectorialDocument;
|
||||
{$ifdef USE_LCL_CANVAS}ADest: TCanvas;{$else}ADest: TFPCustomCanvas;{$endif}
|
||||
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
|
||||
|
||||
function CoordToCanvasX(ACoord: Double): Integer;
|
||||
begin
|
||||
Result := Round(ADestX + AmulX * ACoord);
|
||||
end;
|
||||
|
||||
function CoordToCanvasY(ACoord: Double): Integer;
|
||||
begin
|
||||
Result := Round(ADestY + AmulY * ACoord);
|
||||
end;
|
||||
|
||||
var
|
||||
i: Integer;
|
||||
// For entities
|
||||
CurEntity: TvEntity;
|
||||
CurCircle: TvCircle;
|
||||
CurEllipse: TvEllipse;
|
||||
//
|
||||
CurArc: TvCircularArc;
|
||||
FinalStartAngle, FinalEndAngle: double;
|
||||
BoundsLeft, BoundsTop, BoundsRight, BoundsBottom,
|
||||
IntStartAngle, IntAngleLength, IntTmp: Integer;
|
||||
//
|
||||
CurDim: TvAlignedDimension;
|
||||
Points: array of TPoint;
|
||||
UpperDim, LowerDim: T3DPoint;
|
||||
begin
|
||||
ADest.Brush.Style := bsClear;
|
||||
|
||||
// Draws all entities
|
||||
for i := 0 to ASource.GetEntityCount - 1 do
|
||||
@@ -289,10 +321,12 @@ begin
|
||||
WriteLn(Format('Drawing Arc Center=%f,%f Radius=%f StartAngle=%f AngleLength=%f',
|
||||
[CurArc.CenterX, CurArc.CenterY, CurArc.Radius, IntStartAngle/16, IntAngleLength/16]));
|
||||
{$endif}
|
||||
ADest.Pen.Color := {$ifdef USE_LCL_CANVAS}VColorToTColor(CurArc.PenColor);{$else}VColorToFPColor(CurArc.PenColor);{$endif}
|
||||
ADest.Arc(
|
||||
BoundsLeft, BoundsTop, BoundsRight, BoundsBottom,
|
||||
IntStartAngle, IntAngleLength
|
||||
);
|
||||
ADest.Pen.Color := clBlack;
|
||||
// Debug info
|
||||
// {$define FPVECTORIALDEBUG}
|
||||
// {$ifdef FPVECTORIALDEBUG}
|
||||
@@ -397,7 +431,29 @@ begin
|
||||
ADest.TextOut(CoordToCanvasX(CurDim.BaseLeft.X), CoordToCanvasY(CurDim.BaseLeft.Y), 'BL');}
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure DrawFPVTextToCanvas(ASource: TvVectorialDocument;
|
||||
{$ifdef USE_LCL_CANVAS}ADest: TCanvas;{$else}ADest: TFPCustomCanvas;{$endif}
|
||||
ADestX: Integer = 0; ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0);
|
||||
|
||||
function CoordToCanvasX(ACoord: Double): Integer;
|
||||
begin
|
||||
Result := Round(ADestX + AmulX * ACoord);
|
||||
end;
|
||||
|
||||
function CoordToCanvasY(ACoord: Double): Integer;
|
||||
begin
|
||||
Result := Round(ADestY + AmulY * ACoord);
|
||||
end;
|
||||
|
||||
var
|
||||
i: Integer;
|
||||
// For text
|
||||
CurText: TvText;
|
||||
//
|
||||
LowerDim: T3DPoint;
|
||||
begin
|
||||
// Draws all text
|
||||
for i := 0 to ASource.GetTextCount - 1 do
|
||||
begin
|
||||
@@ -413,10 +469,6 @@ begin
|
||||
LowerDim.Y := CurText.Y + CurText.FontSize;
|
||||
ADest.TextOut(CoordToCanvasX(CurText.X), CoordToCanvasY(LowerDim.Y), CurText.Value);
|
||||
end;
|
||||
|
||||
{$ifdef FPVECTORIALDEBUG}
|
||||
WriteLn(':<DrawFPVectorialToCanvas');
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Reference in New Issue
Block a user