📄 ezentities.pas
字号:
End
Else
Begin
Idx1 := V.Parts[n];
Idx2 := V.Parts[n + 1] - 1;
End;
Box := FExtension;
APenStyle:= PenStyle;
If APenStyle.Scale <= 0 Then
Scale := 1
Else
Scale := APenStyle.Scale;
APenStyle.Width:= 0;
SymbolWidth := ( Box.Emax.X - Box.Emin.X ) * Scale;
TmpV := TEzVector.Create( 2 );
Try
Repeat
For I := Idx1 To Idx2 - 1 Do
Begin
TmpPt1 := TransformPoint2d( V[I], Matrix );
TmpPt2 := TransformPoint2d( V[I + 1], Matrix );
SegmDist := Dist2d( TmpPt1, TmpPt2 );
SegmAngle := Angle2d( TmpPt1, TmpPt2 );
N := trunc( SegmDist / SymbolWidth );
If N = 0 Then
Begin
// not enough space for drawing the line type
TmpV[0] := TmpPt1;
TmpV[1] := TmpPt2;
TmpV.DrawOpened( Canvas, Clip, TmpV.Extension, Grapher, APenStyle,
IDENTITY_MATRIX2D, DrawMode );
End
Else
Begin
ResidualDist := ( SegmDist - SymbolWidth * N ) / 2;
p1 := TmpPt1;
p2 := Point2d( p1.X + SegmDist, p1.Y );
AcumX := 0;
If ResidualDist > 0 Then
Begin
// draw the start segment
TmpV[0] := p1;
TmpV[1] := Point2d( p1.X + ResidualDist, p1.y );
M1 := Rotate2d( SegmAngle, p1 );
TmpV.DrawOpened( Canvas,
Clip,
TmpV.Extension,
Grapher,
APenStyle,
M1,
DrawMode );
// draw the finish segment
TmpV[0] := Point2d( p2.X - ResidualDist, p1.y );
TmpV[1] := p2;
TmpV.DrawOpened( Canvas, Clip, TmpV.Extension, Grapher, APenStyle,
M1, DrawMode );
AcumX := AcumX + ResidualDist;
End;
For J := 0 To FEntities.Count - 1 Do
Begin
Entity := TEzEntity( FEntities[J] );
If Entity Is TEzFittedVectorText Then
TEzFittedVectorText( Entity ).FontColor := APenStyle.Color
Else If Entity Is TEzJustifVectorText Then
TEzJustifVectorText( Entity ).FontColor := APenStyle.Color
Else If Entity Is TEzOpenedEntity Then
TEzOpenedEntity( Entity ).Pentool.FPenStyle := APenStyle
Else If Entity Is TEzPointEntity Then
Begin
TEzPointEntity( Entity ).Color := APenStyle.Color;
TEzPointEntity( Entity ).PointShape := psPoint;
End;
End;
While N > 0 Do
Begin
{ move the centroid of the symbol to (0,0) then translate to center
of next segment }
TmpPt1 := TransformPoint2d( Point2d( p1.X + AcumX + SymbolWidth / 2, p1.Y ),
Rotate2d( SegmAngle, p1 ) );
M1 := Translate2d( -FCentroid.X + TmpPt1.X, -FCentroid.Y + TmpPt1.Y );
M2 := Scale2d( Scale, Scale, FCentroid );
M := MultiplyMatrix2d( M1, M2 );
If SegmAngle <> 0 Then
M := MultiplyMatrix2d( M, Rotate2d( SegmAngle, FCentroid ) );
Self.Draw( Grapher, Canvas, Clip, M, DrawMode );
AcumX := AcumX + SymbolWidth;
Dec( N );
End;
End;
End;
If V.Parts.Count < 2 Then
Break;
Inc( n );
If n >= V.Parts.Count Then
Break;
Idx1 := V.Parts[n];
If n < V.Parts.Count - 1 Then
Idx2 := V.Parts[n + 1] - 1
Else
Idx2 := V.Count - 1;
Until False;
Finally
TmpV.Free;
End;
End;
procedure TEzSymbol.SetName(const Value: String);
begin
FName := StringReplace(Value,#32,'',[rfReplaceAll]);
end;
{TEzSymbols - class implementation}
type
{ The header for the symbol file }
TEzSymbolsHeader = Packed Record
HeaderID: smallint;
VersionNumber: SmallInt;
RecordCount: Integer;
Reserved: Array[0..99] Of byte;
End;
Constructor TEzSymbols.Create;
Begin
Inherited Create;
FList := TList.Create;
FFileName := 'SYMBOLS.EZS';
AtLeastOne;
End;
Destructor TEzSymbols.Destroy;
Begin
Clear;
FList.Free;
Inherited Destroy;
End;
Procedure TEzSymbols.ExChange( Index1, Index2: Integer );
begin
if (Index1<0) or (Index1>FList.Count-1) or (Index2<0) or
(Index2>FList.Count-1) then
begin
Exit;
end;
FList.Exchange( Index1, Index2 );
end;
Procedure TEzSymbols.Up( Index : Integer );
begin
If ( Index <= 0 ) Or ( Index > FList.Count - 1 ) Then
begin
Exit;
end;
Exchange( Index, Index - 1 );
end;
procedure TEzSymbols.Down( Index : Integer );
begin
If ( Index < 0 ) Or ( Index >= FList.Count - 1 ) Then Exit;
Exchange( Index, Index + 1 );
end;
Procedure TEzSymbols.BringToTop( Index: Integer );
Var
I: Integer;
Temp: Pointer;
Begin
If ( Index < 0 ) Or ( Index >= FList.Count - 1 ) Then
begin
Exit;
end;
Temp := FList[Index];
For I := Index To Count - 2 Do
begin
FList[I] := FList[I + 1];
end;
FList[Count - 1] := Temp;
end;
Procedure TEzSymbols.SendToBack( Index: Integer );
Var
I: Integer;
Temp: Pointer;
Begin
If ( Index < 0 ) Or ( Index >= Count - 1 ) Then
begin
Exit;
end;
Temp := FList[Index];
For I := Index Downto 1 Do
begin
FList[I] := FList[I - 1];
end;
FList[0] := Temp;
end;
Procedure TEzSymbols.Assign( Symbols: TEzSymbols );
Var
I: Integer;
S: TEzSymbol;
Begin
Clear;
FFileName := Symbols.FileName;
FIsLineType := Symbols.IsLineType;
For I := 0 To Symbols.Count - 1 Do
Begin
S := TEzSymbol.Create( Self );
S.Assign( Symbols[I] );
Add( S );
End;
End;
Procedure TEzSymbols.SetIsLineType( Value: Boolean );
Begin
If Value Then
Begin
ChangeFileExt( FFileName, '.EZL' );
FFileName := 'LINETYPES.EZL';
End
Else
Begin
ChangeFileExt( FFileName, '.EZS' );
FFileName := 'SYMBOLS.EZS';
End;
FIsLineType := Value;
Clear;
AtLeastOne;
End;
Procedure TEzSymbols.AtLeastOne;
Var
S: TEzSymbol;
E: TEzEntity;
Begin
If FList.Count > 0 Then
exit;
{ ensure at least one entity }
S := TEzSymbol.Create( Self );
If Not FIsLineType Then
Begin
E := TEzRectangle.CreateEntity( Point2D( 0, 0 ), Point2D( 10, 10 ) );
TEzRectangle( E ).PenTool.Style := 1;
TEzRectangle( E ).PenTool.Color := clBlack;
End
Else
Begin
E := TEzPolyLine.CreateEntity( [Point2D( 0, 0 ), Point2D( 10, 0 )] );
TEzPolyLine( E ).PenTool.Style := 1;
End;
S.Add( E );
Add( S );
End;
Procedure TEzSymbols.Clear;
Var
I: Integer;
Begin
For I := 0 To FList.Count - 1 Do
TEzSymbol( FList[I] ).Free;
FList.Clear;
End;
Function TEzSymbols.Count: Integer;
Begin
Result := FList.Count;
End;
Procedure TEzSymbols.LoadFromStream( Stream: TStream );
Var
I: Integer;
SymbolsHeader: TEzSymbolsHeader;
Begin
Clear;
With Stream Do
Begin
Read( SymbolsHeader, SizeOf( TEzSymbolsHeader ) );
If SymbolsHeader.HeaderID <> SYMBOL_ID Then
EzGisError( SInvalidSymbolFile );
If SymbolsHeader.VersionNumber <> SYMBOL_VERSIONNUMBER Then
EzGisError( SInvalidSymbolVersion );
For I := 0 To SymbolsHeader.RecordCount - 1 Do
FList.Add( TEzSymbol.CreateFromStream( Self, Stream ) );
End;
AtLeastOne;
If Assigned( FOnChange ) Then
FOnChange( Self );
End;
Procedure TEzSymbols.SaveToStream( Stream: TStream );
Var
I: Integer;
SymbolsHeader: TEzSymbolsHeader;
Begin
With Stream Do
Begin
With SymbolsHeader Do
Begin
HeaderID := SYMBOL_ID;
VersionNumber := SYMBOL_VERSIONNUMBER;
RecordCount := FList.Count;
End;
Write( SymbolsHeader, SizeOf( TEzSymbolsHeader ) );
For I := 0 To FList.Count - 1 Do
TEzSymbol( FList[I] ).SaveToStream( Stream );
End;
End;
Function TEzSymbols.Add( Item: TEzSymbol ): Integer;
Begin
Item.FSymbols := Self;
Result := FList.Add( Item );
If Item.Name = '' Then
Begin
If FIsLineType Then
Item.Name := Format( SLinetypeCaption, [Result] )
Else
Item.Name := Format( SSymbolCaption, [Result] );
End;
End;
Procedure TEzSymbols.Delete( Index: Integer );
Begin
If ( Index < 0 ) Or ( Index > FList.Count - 1 ) Then
EzGisError( SSymbolOutOfBound );
TEzSymbol( FList[Index] ).Free;
FList.Delete( Index );
End;
Function TEzSymbols.Get( Index: Integer ): TEzSymbol;
Begin
If ( Index < 0 ) Or ( Index > FList.Count - 1 ) Then
EzGisError
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -