📄 ezmifimport.pas
字号:
If AnsiCompareText( gslMIF[0], 'Angle' ) = 0 Then
Begin
val(gslMIF[1],DefFont.Angle,code);
continue;
End;
If AnsiCompareText( gslMIF[0], 'Spacing' ) = 0 Then
continue;
If AnsiCompareText( gslMIF[0], 'justify' ) = 0 Then
continue;
If AnsiCompareText( gslMIF[0], 'Label' ) = 0 Then
continue;
break;
End;
End;
{------------------------------------------------------------------------------
ReadPointObject
------------------------------------------------------------------------------}
Function TEzMifImport.ReadPointObject: TEzEntity;
Var
P1: TEzPoint;
idx,code: integer;
Begin
Try
val(gslMIF[1],P1.x,code);
val(gslMIF[2],P1.y,code);
Result := TEzPlace.CreateEntity( p1 );
FetchMIFdata( True );
ReadSymbolobject;
TEzPlace( Result ).Symboltool.Index := DefSymbol.Index;
With DrawBox Do
TEzPlace( Result ).Symboltool.Height := grapher.getrealsize( Ez_Preferences.DefSymbolStyle.height );
TEzPlace( Result ).Symboltool.Rotangle := DefSymbol.Rotangle;
If Not HaveBound Then
Begin
For idx := 0 To Result.Points.Count - 1 Do
Compareboundary( Result.Points[idx].x, Result.Points[idx].y );
End;
Except
Result := Nil;
End;
End;
{------------------------------------------------------------------------------
ReadRegionObject
------------------------------------------------------------------------------}
Function TEzMifImport.ReadRegionObject: TEzEntity;
Var
ipt, idx, iParts, code,Prvipoints, iPoints: integer;
AX, AY: double;
panPoint2D: PEzPoint;
MifPoints: TList;
TmpPt: TEzPoint;
TmpLoc: Longint;
Begin
Try
val(gslMIF[1],iParts,code); { get number of parts to region }
FetchMIFdata( True );
val(gslMIF[0],iPoints,code); { get number of points in this region }
// Get Combined Region Color
If iparts > 1 Then
Begin
Tmploc := giMIFLinePos;
For ipt := 1 To iparts Do
Begin
{ get number of points in this multiple region }
If ipt > 1 Then
val(gslMIF[0],iPoints,code);
inc( giMIFLinePOS, ipoints );
FetchMIFdata( True );
ReadPenObject;
ReadBrushObject;
If AnsiCompareText( gslMIF[0], 'Center' ) = 0 Then
FetchMIFdata( True );
End;
giMIFLinePos := Tmploc - 1;
FetchMIFdata( True );
val(gslMIF[0],iPoints,code);
End;
// Combined multiple Region process
MifPoints := TList.Create;
Result:= TEzPolygon.Create( ipoints );
// for multy polygon
prvipoints := 0;
For ipt := 1 To iparts Do
Begin
{ get number of points in this multiple region }
If ipt > 1 Then
val(gslMIF[0],ipoints,code);
For idx := 1 To iPoints Do
Begin
FetchMIFdata( True );
//if ipoints <= MAX_POINTS then
Begin
val(gslMIF[0],ax,code);
val(gslMIF[1],ay,code);
// max/Min Check
If ( AX < MINCOORD ) Or ( AX > MAXCOORD ) Or
( AY < MINCOORD ) Or ( AY > MAXCOORD ) Then
Continue;
New( panPoint2D );
panPoint2D^.x := AX;
panPoint2D^.y := AY;
MifPoints.Add( panPoint2D );
End;
End;
{ read attributes }
FetchMIFdata( True );
If ( iparts = 1 ) Or ( ipt = iparts ) Then
Begin
ReadPenObject;
ReadBrushObject;
If AnsiCompareText( gslMIF[0], 'Center' ) = 0 Then
FetchMIFdata( True );
With TEzClosedEntity( Result ) Do
Begin
Pentool.FPenstyle := Defpen;
Brushtool.FBrushstyle := DefBrush;
End;
End;
Result.BeginUpdate;
try
For idx := 0 To MifPoints.Count - 1 Do
Begin
TmpPt := PEzPoint( MifPoints[idx] )^;
Result.Points.Add( TmpPt );
End;
finally
Result.EndUpdate;
end;
If iparts > 1 Then
Begin
Result.Points.Parts.Add( Prvipoints );
PrvIpoints := PrvIpoints + ipoints;
End;
//clear previous points data
For idx := 0 To MifPoints.Count - 1 Do
Dispose( PEzPoint( MifPoints[idx] ) );
MifPoints.Clear;
End; // for iparts
If HaveBound = false Then
For idx := 0 To Result.Points.Count - 1 Do
Compareboundary( Result.Points[idx].x, Result.Points[idx].y );
MifPoints.Clear;
MifPoints.Free;
Entityno := iparts;
Except
Result := Nil;
End;
End;
{------------------------------------------------------------------------------
ReadPLineObject
------------------------------------------------------------------------------}
Function TEzMifImport.ReadPLineObject: TEzEntity;
Var
ipt, idx, iParts, iPoints, code,prvipoints: integer;
AX, AY: double;
panPoint2D: PEzPoint;
MifPoints: TList;
Smoothed: boolean;
TmpPt: TEzPoint;
PenStyle: TEzPenStyle;
Begin
Result:= Nil;
Try
iParts := 1;
iPoints := 0;
{case of Mapinfo Mif data version}
Case giMIFVersion Of
300, 410, 450, 550: If gslMIF.Count > 1 Then
Begin
Case gslMIF.Count Of
2:
val(gslMIF[1],iPoints,code); { get number of points in this region }
3:
Begin
val(gslMIF[2],iparts,code);
FetchMIFdata( True );
val(gslMIF[0],iPoints,code);
End;
End;
End
Else
Begin
FetchMIFdata( True );
val(gslMIF[0],iPoints,code);
End;
1:
val(gslMIF[1],iPoints,code);
Else
val(gslMIF[1],iParts,code);
FetchMIFdata( True );
val( gslMIF[0], iPoints, code );
End;
// Combined multiple pline process
MifPoints := TList.Create;
//Result := TEzPolyLine.Create(nil,ipoints);
prvipoints := 0;
For ipt := 1 To iparts Do
Begin
{ get number of points in this multiple region }
If ipt > 1 Then
val(gslMIF[0],iPoints,code);
For idx := 1 To iPoints Do
Begin
FetchMIFdata( True );
//if ipoints <= MAX_POINTS then
Begin
val(gslMIF[0],ax,code);
val(gslMIF[1],ay,code);
// max/Min Check
If ( abs( AX ) < 1E-10 ) Or ( abs( AX ) > 1E+10 ) Or
( abs( AY ) < 1E-10 ) Or ( abs( AY ) > 1E+10 ) Then
exit;
New( panPoint2D );
panPoint2D^.x := AX;
panPoint2D^.y := AY;
MifPoints.Add( panPoint2D );
End;
End;
{ read attributes }
Smoothed := false;
FetchMIFdata( True );
If ( iparts = 1 ) Or ( ipt = iparts ) Then
Begin
ReadPenObject;
If AnsiCompareText( gslMIF[0], 'Smooth' ) = 0 Then
Begin
Smoothed := true;
FetchMIFData( True );
End;
PenStyle.Color := defpen.Color;
PenStyle.Style := defpen.Style;
PenStyle.Scale := defpen.Scale;
End;
// end else FetchMIFdata( True );
{ error }
If Smoothed Then
Result := TEzSpline.Create( iPoints )
Else
Result := TEzPolyLine.Create( ipoints );
TEzOpenedEntity( Result ).Pentool.FPenStyle := PenStyle;
Result.BeginUpdate;
try
For idx := 0 To MifPoints.Count - 1 Do
Begin
TmpPt := PEzPoint( MifPoints[idx] )^;
Result.Points.Add( TmpPt );
End;
finally
Result.EndUpdate;
end;
If iparts > 1 Then
Begin
Result.Points.Parts.Add( Prvipoints );
PrvIpoints := PrvIpoints + ipoints;
End;
For idx := 0 To MifPoints.Count - 1 Do
Dispose( PEzPoint( MifPoints[idx] ) );
MifPoints.Clear;
End; //end for multiple objects
If HaveBound = false Then
For idx := 0 To Result.Points.Count - 1 Do
Compareboundary( Result.Points[idx].x, Result.Points[idx].y );
For idx := 0 To MifPoints.Count - 1 Do
Dispose( PEzPoint( MifPoints[idx] ) );
MifPoints.Clear;
MifPoints.Free;
Entityno := iparts;
Except
Result := nil;
End;
End;
{------------------------------------------------------------------------------
ReadLineObject
------------------------------------------------------------------------------}
Function TEzMifImport.ReadLineObject: TEzEntity;
Var
p1, p2: TEzPoint;
idx,code: integer;
Begin
Try
val(gslMIF[1],p1.x,code);
val(gslMIF[2],p1.y,code);
val(gslMIF[3],p2.x,code);
val(gslMIF[4],p2.y,code);
Result := TEzPolyLine.CreateEntity( [p1, p2] );
FetchMIFdata( True );
ReadPenObject;
TEzOpenedEntity( Result ).Pentool.FPenstyle := defpen;
If HaveBound = false Then
For idx := 0 To Result.Points.Count - 1 Do
Compareboundary( Result.Points[idx].x, Result.Points[idx].y );
Except
Result := Nil
End;
End;
{------------------------------------------------------------------------------
ReadTextObject
------------------------------------------------------------------------------}
Function TEzMifImport.ReadTextObject: TEzEntity;
Var
sText: String;
p1, p2, p3: TEzPoint;
code,idx: integer;
Begin
Try
FetchMIFdata( True );
sText := gslMIF[0];
For idx := 1 To gslMIF.Count - 1 Do
sText := sText + ' ' + gslMIF[idx];
//sText := ReplaceStr(ReplaceStr(Trim(sText), '"', ''), '\n', ' ');
sText := StringReplace( StringReplace( Trim( sText ), '"', '', [rfReplaceAll] ), '\n', #13 + #10, [rfReplaceAll] );
FetchMIFdata( True );
val(gslMIF[0],p1.x,code);
val(gslMIF[1],p1.y,code);
val(gslMIF[2],p2.x,code);
val(gslMIF[3],p2.y,code);
p3.x := p1.x;
p3.y := p2.y;
FetchMIFdata( True );
ReadFontObject;
Result := TEzFittedVectorText.CreateEntity( p3, stext, abs( p2.y - p1.y ), -1, deffont.Angle );
//ttext2d( Result ).Font2d := deffont ;
TEzFittedVectorText( Result ).FontColor := deffont.color;
If HaveBound = false Then
For idx := 0 To Result.Points.Count - 1 Do
Compareboundary( Result.Points[idx].x, Result.Points[idx].y );
Except
Result := nil
End;
End;
{------------------------------------------------------------------------------
ReadArcObject
------------------------------------------------------------------------------}
Function TEzMifImport.ReadArcObject: TEzEntity;
Var
p1, p2, FirstPt, SecondPt, ThirdPt: TEzPoint;
code,idx: integer;
SA, Ea, tmpangle: double;
RX, RY, CX, CY, WorkAngle: double;
Begin
Try
val(gslMIF[1],p1.x,code); // lower left X
val(gslMIF[2],p1.y,code); // lower left Y
val(gslMIF[3],p2.x,code); // topright X
val(gslMIF[4],p2.y,code); // topright Y
RX := Abs( P2.X - P1.X ) / 2.0; // ellipse radius X
RY := Abs( P2.Y - P1.Y ) / 2.0; // ellipse radius Y
CX := ( P2.X + P1.X ) / 2.0; // ellipse Center X
CY := ( P2.Y + P1.Y ) / 2.0; // ellipse center Y
val(gslMIF[5],Sa,code); // Start Angle
val(gslMIF[6],Ea,code); // End Angle
Sa := DegToRad( Sa ); // start angle in radians
Ea := DegToRad( Ea ); // end angle in radians
// calculate first point of start for arc
WorkAngle := Sa;
FirstPt := Point2D( CX + RX * Cos( WorkAngle ), CY + RY * Sin( WorkAngle ) );
// calc second point (at middle)
If ea > sa Then
Begin
WorkAngle := ( sa + ea ) / 2;
End
Else
Begin
tmpangle := ea;
While tmpangle < sa Do
tmpangle := tmpangle + 2 * Pi;
WorkAngle := ( tmpangle - sa ) / 2 + sa;
End;
SecondPt := Point2D( CX + RX * Cos( WorkAngle ), CY + RY * Sin( WorkAngle ) );
// calc third point
WorkAngle := ea;
ThirdPt := Point2D( CX + RX * Cos( WorkAngle ), CY + RY * Sin( WorkAngle ) );
// now build the arc that will pass for this three points
Result := TEzArc.CreateEntity( FirstPt, SecondPt, ThirdPt );
FetchMIFdata( True );
ReadPenObject;
TEzArc( Result ).Pentool.FPenstyle := defpen;
If HaveBound = false Then
For idx := 0 To Result.Points.Count - 1 Do
Compareboundary( Result.Points[idx].x, Result.Points[idx].y );
Except
Result := nil
End;
End;
{------------------------------------------------------------------------------
ReadEllipseObject
------------------------------------------------------------------------------}
Function TEzMifImport.ReadEllipseObject: TEzEntity;
Var
p1, p2: TEzPoint;
code,idx: integer;
Begin
Try
val(gslMIF[1],p1.x,code);
val(gslMIF[2],p1.y,code);
val(gslMIF[3],p2.x,code);
val(gslMIF[4],p2.y,code);
Result := TEzEllipse.CreateEntity( p1, p2 );
FetchMIFdata( True );
ReadPenObject;
ReadBrushObject;
With TEzClosedEntity( Result ) Do
Begin
Pentool.FPenstyle := defpen;
Brushtool.FBrushstyle := defbrush;
End;
If HaveBound = false Then
For idx := 0 To Result.Points.Count - 1 Do
Compareboundary( Result.Points[idx].x, Result.Points[idx].y );
Except
Result := Nil
End;
End;
{------------------------------------------------------------------------------
ReadRectangleObject
------------------------------------------------------------------------------}
Function TEzMifImport.ReadRectangleObject: TEzEntity;
Var
p1, p2: TEzPoint;
code,idx: integer;
Begin
Try
val(gslMIF[1],p1.x,code);
val(gslMIF[2],p1.y,code);
val(gslMIF[3],p2.x,code);
val(gslMIF[4],p2.y,code);
Result := TEzRectangle.CreateEntity( p1, p2 );
FetchMIFdata( True );
ReadPenObject;
ReadBrushObject;
With TEzRectangle( Result ) Do
Begin
Pentool.FPenstyle := defpen;
Brushtool.FBrushstyle := defbrush;
End;
If HaveBound = false Then
For idx := 0 To Result.Points.Count - 1 Do
Compareboundary( Result.Points[idx].x, Result.Points[idx].y );
Except
Result := nil
End;
End;
// Count number of Data in MIF
Function TEzMifImport.MIFDataCount: Longint;
Var
sTmp, sTmp1, sTmp2: String;
Fetch: longint;
i: Longint;
Function splitSpace( Const ss: String; Var s1, s2: String ): boolean;
Var
i: integer;
Begin
If AnsiPos( ' ', ss ) = 0 Then
Begin
s1 := ss;
s2 := ss;
result := false;
exit;
End;
i := AnsiPos( ' ', ss );
s1 := copy( ss, 1, i - 1 );
s2 := copy( ss, i + 1, length( ss ) - i );
result := true;
End;
Begin
Result := 0;
Fetch := 0;
If gMIFlines.Count = 0 Then
exit;
// Skip Header
While AnsiCompareText( trim( gMIFLines[fetch] ), 'Data' ) <> 0 Do
inc( Fetch );
// Scanning Entities
For i := Fetch To gMIFlines.Count - 1 Do
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -