📄 ezpreview.pas
字号:
End;
Procedure TEzGISList.SetItem( Index: Integer; Value: TEzGISItem );
Begin
Inherited SetItem( Index, Value );
End;
{ ********* TEzPreviewBox ************ }
Constructor TEzPreviewBox.Create( AOwner: TComponent );
Begin
Inherited Create( AOwner );
FGISList := TEzGISList.Create( Self );
FPaperPen := TPen.Create;
FPaperPen.Style := psSolid;
FPaperPen.Color := clBlack;
FPaperBrush := TBrush.Create;
FPaperBrush.Style := bsSolid;
FPaperBrush.Color := clWhite;
FShadowPen := TPen.Create;
FShadowPen.Style := psSolid;
FShadowPen.Color := clBlack;
FShadowBrush := TBrush.Create;
FShadowBrush.Style := bsSolid;
FShadowBrush.Color := clBlack;
FShowShadow := True;
CreatePaperShapes;
FShowPrinterMargins := True;
FOrientation := Printer.Orientation;
PaperSize := psPrinter; { force calculation of printer dimensions and margins }
GIS := TEzCAD.Create( Nil );
CreateNewEditor;
End;
Destructor TEzPreviewBox.Destroy;
Begin
FPaperPen.Free;
FPaperBrush.Free;
FShadowPen.Free;
FShadowBrush.Free;
DestroyShapes;
FGISList.Free;
Gis.Free;
Inherited Destroy;
End;
Procedure TEzPreviewBox.Loaded;
begin
inherited Loaded;
SetPaperShapeAttributes;
end;
function TEzPreviewBox.GetAbout: TEzAbout;
begin
Result:= SEz_GisVersion;
end;
procedure TEzPreviewBox.SetAbout(const Value: TEzAbout);
begin
end;
{$IFDEF BCB}
Function TEzPreviewBox.GetGISList: TEzGISList;
Begin
Result:=FGISList;
End;
Function TEzPreviewBox.GetPaperSize: TEzPaperSize;
Begin
Result:=FPaperSize;
End;
Function TEzPreviewBox.GetOrientation: TPrinterOrientation;
Begin
Result:=FOrientation;
End;
Function TEzPreviewBox.GetShowPrinterMargins: Boolean;
Begin
Result:= FShowPrinterMargins;
End;
Procedure TEzPreviewBox.SetShowPrinterMargins(Value: Boolean);
Begin
FShowPrinterMargins:=Value;
End;
Function TEzPreviewBox.GetPaperUnits: TEzScaleUnits;
Begin
Result:=FPaperUnits;
End;
Procedure TEzPreviewBox.SetPaperUnits(Value: TEzScaleUnits);
Begin
FPaperUnits:=Value;
End;
Function TEzPreviewBox.GetPrintMode: TEzPrintMode;
Begin
Result:=FPrintMode;
End;
Procedure TEzPreviewBox.SetPrintMode(Value: TEzPrintMode);
Begin
FPrintMode:=Value;
End;
Function TEzPreviewBox.GetPaperPen: TPen;
Begin
Result:=FPaperPen;
End;
Function TEzPreviewBox.GetPaperBrush: TBrush;
Begin
Result:=FPaperBrush;
End;
Function TEzPreviewBox.GetShadowPen: TPen;
Begin
Result:=FShadowPen;
End;
Function TEzPreviewBox.GetShadowBrush: TBrush;
Begin
Result:=FShadowBrush;
End;
Function TEzPreviewBox.GetShowShadow: Boolean;
Begin
Result:=FShowShadow;
End;
function TEzPreviewBox.GetMarginBottomShp: TEzPolyLine;
begin
Result := FMarginBottomShp;
end;
function TEzPreviewBox.GetMarginLeftShp: TEzPolyLine;
begin
Result := FMarginLeftShp;
end;
function TEzPreviewBox.GetMarginRightShp: TEzPolyLine;
begin
Result := FMarginRightShp;
end;
function TEzPreviewBox.GetMarginTopShp: TEzPolyLine;
begin
Result := FMarginTopShp;
end;
function TEzPreviewBox.GetPaperShp: TEzRectangle;
begin
Result := FPaperShp;
end;
function TEzPreviewBox.GetShadowShp: TEzRectangle;
begin
Result := FShadowShp;
end;
{$ENDIF}
Procedure TEzPreviewBox.CreateNewEditor;
Var
I: Integer;
Begin
ConfigurePaperShapes;
GIS.Close;
GIS.Layers.CreateNewCosmethic( 'A0' );
GIS.Open;
GIS.CurrentLayerName := 'A0';
For I := 0 To Gis.DrawBoxList.Count - 1 Do
Gis.DrawBoxList[I].Grapher.Clear;
Selection.Clear;
Grapher.Clear;
End;
Procedure TEzPreviewBox.PopulateFrom( Symbol: TEzSymbol );
Var
Layer: TEzBaseLayer;
I: Integer;
Begin
{ delete all records }
Layer := GIS.Layers[0];
Layer.First;
While Not Layer.Eof Do
Begin
Layer.DeleteEntity( Layer.Recno );
Layer.Next;
End;
//Layer.Pack;
For I := 0 To Symbol.Count - 1 Do
Layer.AddEntity( Symbol.Entities[I] );
End;
Procedure TEzPreviewBox.PopulateTo( Symbol: TEzSymbol );
Var
Layer: TEzBaseLayer;
Entity: TEzEntity;
Begin
{ delete all records }
Symbol.Clear;
Layer := GIS.Layers[0];
Layer.First;
While Not Layer.Eof Do
Begin
If Not Layer.RecIsDeleted Then
Begin
Entity := Layer.RecLoadEntity;
Symbol.Add( Entity );
End;
Layer.Next;
End;
End;
Procedure TEzPreviewBox.DestroyShapes;
Begin
If Assigned( FPaperShp ) Then
FPaperShp.Free;
If Assigned( FShadowShp ) Then
FShadowShp.Free;
If Assigned( FMarginLeftShp ) Then
FMarginLeftShp.Free;
If Assigned( FMarginRightShp ) Then
FMarginRightShp.Free;
If Assigned( FMarginTopShp ) Then
FMarginTopShp.Free;
If Assigned( FMarginBottomShp ) Then
FMarginBottomShp.Free;
End;
Procedure TEzPreviewBox.CreatePaperShapes;
Var
p: TEzPoint;
Begin
DestroyShapes;
p := Point2d( 0, 0 );
FPaperShp := TEzRectangle.CreateEntity( p, p );
FShadowShp := TEzRectangle.CreateEntity( p, p );
FMarginLeftShp := TEzPolyLine.CreateEntity( [p, p] );
FMarginRightShp := TEzPolyLine.CreateEntity( [p, p] );
FMarginTopShp := TEzPolyLine.CreateEntity( [p, p] );
FMarginBottomShp := TEzPolyLine.CreateEntity( [p, p] );
SetPaperShapeAttributes;
End;
Procedure TEzPreviewBox.SetPaperShapeAttributes;
Begin
With FPaperShp.Pentool Do
Begin
Style := 1;
Color := FPaperPen.Color;
Width := 0;
End;
With FPaperShp.Brushtool Do
Begin
Pattern := 1;
Color := FPaperBrush.Color;
BackColor:= clBlack;
End;
With FShadowShp.Pentool Do
Begin
Style := 1;
Color := FShadowPen.Color;
Width := 0;
End;
With FShadowShp.Brushtool Do
Begin
Pattern := 1;
Color := FShadowBrush.Color;
BackColor:= clBlack;
End;
With FMarginLeftShp.Pentool Do
Begin
Style := 1;
Color := clSilver;
Width := 0;
End;
FMarginRightShp.Pentool.Assign( FMarginLeftShp.Pentool );
FMarginTopShp.Pentool.Assign( FMarginLeftShp.Pentool );
FMarginBottomShp.Pentool.Assign( FMarginLeftShp.Pentool );
End;
Procedure TEzPreviewBox.UpdateViewport( WCRect: TEzRect );
Var
TheCanvas: TCanvas;
VisualWindow: TEzRect;
Begin
//If Not Showing then Exit;
VisualWindow := Grapher.CurrentParams.VisualWindow;
WCRect := VisualWindow;
Inherited UpdateViewport( WCRect );
If FShowShadow And IsRectVisible( FShadowShp.FBox, VisualWindow ) Then
Begin
FShadowShp.Draw( Grapher, ScreenBitmap.Canvas, VisualWindow, dmNormal );
End;
If IsRectVisible( FPaperShp.FBox, VisualWindow ) Then
FPaperShp.Draw( Grapher, ScreenBitmap.Canvas, VisualWindow, dmNormal );
If FShowPrinterMargins Then
Begin
If IsRectVisible( FMarginLeftShp.FBox, VisualWindow ) Then
FMarginLeftShp.Draw( Grapher, ScreenBitmap.Canvas, VisualWindow, dmNormal );
If IsRectVisible( FMarginRightShp.FBox, VisualWindow ) Then
FMarginRightShp.Draw( Grapher, ScreenBitmap.Canvas, VisualWindow, dmNormal );
If IsRectVisible( FMarginTopShp.FBox, VisualWindow ) Then
FMarginTopShp.Draw( Grapher, ScreenBitmap.Canvas, VisualWindow, dmNormal );
If IsRectVisible( FMarginBottomShp.FBox, VisualWindow ) Then
FMarginBottomShp.Draw( Grapher, ScreenBitmap.Canvas, VisualWindow, dmNormal );
End;
{ now draw the entities as usual }
TheCanvas := Canvas;
If odCanvas In OutputDevices Then
TheCanvas := Canvas
Else If odBitmap In OutputDevices Then
TheCanvas := ScreenBitmap.Canvas;
With TEzPainterObject.Create(Nil) Do
Try
DrawEntities( WCRect, GIS, TheCanvas, Grapher, Selection, IsAerial,
False, pmAll, Self.ScreenBitmap );
Finally
Free;
End;
End;
Procedure TEzPreviewBox.SetShowShadow( Value: Boolean );
Begin
FShowShadow := Value;
Repaint;
End;
Procedure TEzPreviewBox.Print;
Var
PrnGrapher: TEzGrapher;
//PaperUnits: TEzScaleUnits;
//PageW, PageH: Double;
Begin
If Printer.Printing Then
Raise Exception.Create( SPrinterIsBusy );
{ this will raise an exception immediately if printer is not ready }
Printer.BeginDoc;
PrnGrapher := TEzGrapher.Create( 1, adPrinter );
{ first, we need to calculate how many pixels are in the current printer
for the predefined pagewidth and pageheight }
//PageW := Dpi2Units(PaperUnits, PrnGrapher.PrinterDpiX, Printer.PageWidth );
//PageH := Dpi2Units(PaperUnits, PrnGrapher.PrinterDpiY, Printer.PageHeight );
PrnGrapher.SetViewport( 0, 0, Printer.PageWidth-1, Printer.PageHeight-1 );
PrnGrapher.SetWindow( MarginLeft, ( PaperWidth - MarginRight ),
-MarginTop, -( PaperHeight - MarginBottom ) );
With TEzPainterObject.Create(Nil) Do
Try
DrawEntities( Rect2D( 0, -PaperHeight, PaperWidth, 0 ),
GIS,
Printer.Canvas,
PrnGrapher,
Selection,
False,
False,
pmAll,
Self.ScreenBitmap );
Finally
Free;
PrnGrapher.Free;
Printer.EndDoc;
End;
End;
Procedure TEzPreviewBox.ZoomToPaper;
Var
TmpMarginX, TmpMarginY: Double;
MaxExtents: TEzRect;
Begin
Resync;
MaxExtents := Rect2D( 0, -PaperHeight, PaperWidth, 0 );
If Not EqualRect2D( MaxExtents, Grapher.OriginalParams.VisualWindow ) Then
Begin
With MaxExtents Do
Begin
TmpMarginX := ( Emax.X - Emin.X ) / 40;
TmpMarginY := ( Emax.Y - Emin.Y ) / 40;
Grapher.SetWindow( Emin.X - TmpMarginX,
Emax.X + TmpMarginX ,
Emin.Y - TmpMarginY,
Emax.Y + TmpMarginY );
End;
End;
Grapher.Zoom( 1 );
Repaint;
End;
Function TEzPreviewBox.GetPrintablePageWidth: Double;
Begin
result := PaperWidth - MarginLeft - MarginRight;
End;
Function TEzPreviewBox.GetPrintablePageHeight: Double;
Begin
result := PaperHeight - MarginTop - MarginBottom;
End;
Procedure TEzPreviewBox.ConfigurePaperShapes;
Var
Delta: Double;
p: TEzPoint;
Begin
{ paper }
FPaperShp.Points[0] := Point2D( 0, 0 );
FPaperShp.Points[1] := Point2D( PaperWidth, -PaperHeight );
{ shadow }
FShadowShp.Points.Assign( FPaperShp.Points );
Delta := PaperWidth * 0.015;
p := FShadowShp.Points[0];
FShadowShp.Points[0] := Point2D( p.X + Delta, p.Y - Delta );
p := FShadowShp.Points[1];
FShadowShp.Points[1] := Point2D( p.X + Delta, p.Y - Delta );
{ left margin }
FMarginLeftShp.Points[0] := Point2D( MarginLeft, -MarginTop );
FMarginLeftShp.Points[1] := Point2D( MarginLeft, -( PaperHeight - MarginBottom ) );
{ right margin }
FMarginRightShp.Points[0] := Point2D( PaperWidth - MarginRight, -MarginTop );
FMarginRightShp.Points[1] := Point2D( PaperWidth - MarginRight, -( PaperHeight - MarginBottom ) );
{ margin top }
FMarginTopShp.Points[0] := Point2D( MarginLeft, -MarginTop );
FMarginTopShp.Points[1] := Point2D( PaperWidth - MarginRight, -MarginTop );
{ margin bottom }
FMarginBottomShp.Points[0] := Point2D( MarginLeft, -( PaperHeight - MarginBottom ) );
FMarginBottomShp.Points[1] := Point2D( PaperWidth - MarginRight, -( PaperHeight - MarginBottom ) );
End;
Function TEzPreviewBox.GetMarginLeft: Double;
Begin
result := Inches2Units( FPaperUnits, FPrinterMarginLeft );
End;
Function TEzPreviewBox.GetMarginTop: Double;
Begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -