📄 ezdxfimport.pas
字号:
End;
End;
End;
{$ENDIF}
If Not FExplodeBlocks and FImportBlocks then
begin
Found:= False;
For I := 0 To FImportLayerList.Count - 1 Do
Begin
alayer := Dxf_layer( FImportLayerList.Objects[I] );
If (AnsiCompareText( alayer.layer_name, 'Block_' ) <> 0) Or
(alayer.entities.count = 0) Then
Continue;
{ Create a dummy layer for importing}
for J:= 0 to alayer.entities.count-1 do
begin
blk:= Block_(DXF_Entity( alayer.entities[J] ));
If blk.entities.count = 0 Then
continue;
Index := Ez_Symbols.IndexOfName( blk.name );
If Index >= 0 then
continue;
TempImport:= TEzDxfImport.Create(Nil);
try
TempImport.FDrawBox:= Self.FDrawBox;
TempImport.UseTrueType:= Self.UseTrueType;
Layer := TempImport.FCad.CreateLayer( 'Dummy', ltMemory );
TempImport.FCad.CurrentLayerName:= Layer.Name;
TempImport.FExplodeBlocks:= True;
For K := 0 To blk.entities.count - 1 Do
Begin
ent := Dxf_entity( blk.entities[K] );
ent.AddToGIS( TempImport, Nil );
Found:= True;
End;
Symbol := TEzSymbol.Create(Ez_Symbols);
try
Symbol.Name := blk.name;
Layer.First;
while not Layer.Eof do
begin
NativeEnt:= Layer.RecLoadEntity;
Symbol.Add(NativeEnt);
Layer.Next;
end;
Symbol.UpdateExtension;
Ez_Symbols.Add(Symbol);
except
Symbol.Free;
TempImport.FDrawBox:= Nil;
raise;
end;
Finally
TempImport.FDrawBox:= Nil;
TempImport.Free;
End;
end;
End;
If Found then
Ez_Symbols.SaveToFile(Ez_Symbols.FileName);
End;
{ count the entities to import }
FTotalEntities := 0;
For I := 0 To FImportLayerList.Count - 1 Do
Begin
alayer := Dxf_layer( FImportLayerList.Objects[I] );
If AnsiCompareText( alayer.layer_name, 'Block_' ) = 0 Then
Continue;
Inc( FTotalEntities, alayer.entities.count );
End;
FTotalProcessed := 0;
FMsg := fullname;
For I := 0 To FImportLayerList.Count - 1 Do
Begin
alayer := Dxf_layer( FImportLayerList.Objects[I] );
If (AnsiCompareText( alayer.layer_name, 'Block_' ) = 0) or
(alayer.entities.count=0) Then
Continue;
Layer := FCad.CreateLayer( alayer.layer_name, ltMemory );
FTargetNames.Add( Layer.Name );
FCad.CurrentLayerName:= Layer.Name;
alayer.AddToGIS( Self, Nil );
If Not alayer.FContinueProcessing Then Break;
End;
FCad.MapInfo.Extension := Rect2D( FDxf_Emin.x, FDxf_Emin.y, FDxf_Emax.x, FDxf_Emax.y );
If FCad.Layers.Count > 0 Then
Begin
Extent := FCad.MapInfo.Extension;
For I := 0 To FCad.Layers.Count - 1 Do
Begin
MaxBound( Extent.Emax, FCad.Layers[I].LayerInfo.Extension.Emax );
MinBound( Extent.Emin, FCad.Layers[I].LayerInfo.Extension.Emin );
End;
FCad.MapInfo.Extension := Extent;
End;
{ free ram memory from the source layers }
FreeAndNil( FDxf_Main );
Finally
Screen.Cursor:= crDefault;
End;
End;
{ important: this function mus be called after calling ReadDxf method }
Function TEzDxfImport.Execute: Boolean;
var
temps: string;
FileWithoutExt: string;
I, J, Index: Integer;
LIndex: Integer;
Layer: TEzBaseLayer;
wasActive: Boolean;
FieldList : TStringList;
SrcLayer: TEzBaseLayer;
TheRecno: Integer;
PrevLayerCount: integer;
DestCoordSystem: TEzCoordSystem;
DestCoordsUnits: TEzCoordsUnits;
TmpEntity: TEzEntity;
//DataIndex: Integer;
ImportCnt: integer;
CurrCnt: integer;
CanContinue: boolean;
Begin
Assert( FDrawBox <> Nil );
Assert( FDrawBox.Gis <> Nil );
Assert( FConverter <> Nil );
PrevLayerCount := FDrawBox.GIS.Layers.Count;
FileWithoutExt := ChangeFileExt( FFileName, '' );
If PrevLayerCount > 0 Then
begin
With FDrawBox.GIS, FConverter Do
Begin
FConverter.DestinCoordSystem := MapInfo.CoordSystem;
FConverter.DestinProjector.Params.Assign( ProjectionParams );
End;
end;
If FConfirmProjectionSystem And
Not FConverter.EditProjections( PrevLayerCount = 0 ) Then Exit;
Application.ProcessMessages;
DestCoordSystem := FConverter.DestinCoordSystem;
DestCoordsUnits := FConverter.DestinationUnits;
If PrevLayerCount = 0 Then
With FDrawBox.GIS Do
Begin
MapInfo.CoordSystem := FConverter.DestinCoordSystem;
MapInfo.CoordsUnits := DestCoordsUnits;
ProjectionParams.Assign( FConverter.DestinProjector.Params );
Modified := True;
End;
{ count the elements to import }
ImportCnt:= 0;
For LIndex:= 0 to FCad.Layers.Count-1 do
begin
SrcLayer:= FCad.Layers[LIndex];
If Not SrcLayer.LayerInfo.Visible then Continue;
Inc( ImportCnt, SrcLayer.RecordCount );
end;
CurrCnt:= 0;
CanContinue:= True;
If FGenerateMultiLayers then
begin
//DataIndex:= -1;
For LIndex:= 0 to FCad.Layers.Count-1 do
begin
SrcLayer:= FCad.Layers[LIndex];
If Not SrcLayer.LayerInfo.Visible then Continue;
temps := ezsystem.GetValidLayerName( FTargetNames[LIndex] );
Index := DrawBox.GIS.Layers.IndexOfName( temps );
If Index >= 0 Then
Begin
// replace existing layer
With DrawBox.GIS Do
Begin
Layer := Layers[Index];
wasActive := AnsiCompareText( MapInfo.CurrentLayer, Layer.Name ) = 0;
Layers.Delete( Layer.Name, True );
If wasActive And ( Layers.Count > 0 ) Then
MapInfo.CurrentLayer := Layers[0].Name;
If Layers.Count = 0 Then
With MapInfo Do
Begin
Extension := INVALID_EXTENSION;
CurrentLayer := '';
End;
//Layer.LayerInfo.CoordsUnits := MapInfo.CoordsUnits;
End
End;
FieldList := TStringList.Create;
Try
FieldList.Add( 'UID;N;12;0' );
{FieldList.Add( 'ELE_TYPE;N;2;0' );
FieldList.Add( 'ELE_STR;C;20;0' );
FieldList.Add( 'DIMENSION;N;1;0' ); }
FieldList.Add( 'Z;N;20;4' );
Layer := DrawBox.GIS.Layers.CreateNewEx(
ExtractFilePath( DrawBox.GIS.FileName ) + temps, DestCoordSystem,
DestCoordsUnits, FieldList );
Finally
FieldList.Free;
End;
If Layer = Nil Then
Begin
MessageToUser( SCannotCreateNewLayer, SMsgError, MB_ICONERROR );
Exit;
End;
Layer.ForceOpened;
Layer.StartBatchInsert;
try
SrcLayer.First;
While Not SrcLayer.Eof do
begin
Inc(CurrCnt);
FOnFileProgress( Self, FFilename, Round( ( ( CurrCnt + 1 ) / ImportCnt ) * 100 ), CurrCnt, 0, CanContinue );
If Not CanContinue Then Break;
TmpEntity:= SrcLayer.RecLoadEntity;
try
{ convert from source coordinate system }
TmpEntity.BeginUpdate;
For J := 0 To TmpEntity.Points.Count - 1 Do
TmpEntity.Points[J] := FConverter.Convert( TmpEntity.Points[J] );
TmpEntity.EndUpdate;
TheRecno:= Layer.AddEntity( TmpEntity );
If Layer.DBTable <> Nil Then
Begin
//Inc( DataIndex );
Layer.DBTable.Recno:= TheRecno;
Layer.DBTable.Edit;
//Layer.DBTable.IntegerPut( 'ELE_TYPE', FCol0[DataIndex] );
//Layer.DBTable.StringPut( 'ELE_STR', FCol1[DataIndex] );
//Layer.DBTable.IntegerPut( 'DIMENSION', FCol2[DataIndex] );
Layer.DBTable.FloatPut( 'Z', 0 );
Layer.DBTable.Post;
End;
finally
TmpEntity.Free;
end;
SrcLayer.Next;
end;
finally
Layer.FinishBatchInsert;
end;
Layer.Modified := True;
end;
end else
begin
{ Exists a layer with that name already ? }
temps := ezsystem.GetValidlayerName( ExtractFileName( FileWithoutExt ) );
Index := DrawBox.GIS.Layers.IndexOfName( temps );
If Index >= 0 Then
Begin
If MessageDlg( Format( SLayerAlreadyExists, [temps] ), mtConfirmation, [mbYes, mbNo], 0 ) = mrYes Then
// replace existing layer
With DrawBox.GIS Do
Begin
Layer := Layers[Index];
wasActive := AnsiCompareText( MapInfo.CurrentLayer, Layer.Name ) = 0;
Layers.Delete( Layer.Name, True );
If wasActive And ( Layers.Count > 0 ) Then
MapInfo.CurrentLayer := Layers[0].Name;
If Layers.Count = 0 Then
With MapInfo Do
Begin
Extension := INVALID_EXTENSION;
CurrentLayer := '';
End;
//Layer.LayerInfo.CoordsUnits := MapInfo.CoordsUnits;
End
Else
Exit;
End;
FieldList := TStringList.Create;
Try
FieldList.Add( 'UID;N;12;0' );
{FieldList.Add( 'ELE_TYPE;N;2;0' );
FieldList.Add( 'ELE_STR;C;20;0' );
FieldList.Add( 'DIMENSION;N;1;0' ); }
FieldList.Add( 'Z;N;20;4' );
Layer := DrawBox.GIS.Layers.CreateNewEx( ExtractFilePath( DrawBox.GIS.FileName ) +
temps, DestCoordSystem, DestCoordsUnits, FieldList );
Finally
FieldList.Free;
End;
If Layer = Nil Then
Begin
MessageToUser( SCannotCreateNewLayer, SMsgError, MB_ICONERROR );
Exit;
End;
//DataIndex:= -1;
Layer.ForceOpened;
Layer.StartBatchInsert;
try
For LIndex:= 0 to FCad.Layers.Count-1 do
begin
SrcLayer:= FCad.Layers[LIndex];
If Not SrcLayer.LayerInfo.Visible then Continue;
SrcLayer.First;
While Not SrcLayer.Eof do
begin
Inc(CurrCnt);
FOnFileProgress( Self, FFilename, Round( ( ( CurrCnt + 1 ) / ImportCnt ) * 100 ), CurrCnt, 0, CanContinue );
If Not CanContinue Then Break;
TmpEntity:= SrcLayer.RecLoadEntity;
try
{ convert from source coordinate system }
TmpEntity.BeginUpdate;
For J := 0 To TmpEntity.Points.Count - 1 Do
TmpEntity.Points[J] := FConverter.Convert( TmpEntity.Points[J] );
TmpEntity.EndUpdate;
TheRecno:= Layer.AddEntity( TmpEntity );
If Layer.DBTable <> Nil Then
Begin
//Inc( DataIndex );
Layer.DBTable.Recno:= TheRecno;
Layer.DBTable.Edit;
//Layer.DBTable.IntegerPut( 'ELE_TYPE', FCol0[DataIndex] );
//Layer.DBTable.StringPut( 'ELE_STR', FCol1[DataIndex] );
//Layer.DBTable.IntegerPut( 'DIMENSION', FCol2[DataIndex] );
Layer.DBTable.FloatPut( 'Z', 0 );
Layer.DBTable.Post;
End;
finally
TmpEntity.Free;
end;
SrcLayer.Next;
end;
end;
finally
Layer.FinishBatchInsert;
end;
Layer.Modified := True;
End;
{ sort by name }
If FGenerateMultiLayers then
DrawBox.GIS.Layers.Sort;
DrawBox.GIS.QuickUpdateExtension;
If PrevLayerCount = 0 Then
With DrawBox.GIS Do
For I := 0 To DrawBoxList.Count - 1 Do
DrawBoxList[I].ZoomToExtension;
End;
Function TEzDxfImport.ImportFiles( FileList: TStrings ): Boolean;
Var
I: Integer;
TmpFilename: String;
TmpBool: Boolean;
Begin
TmpBool := FConfirmProjectionSystem;
TmpFilename := FFileName;
Try
For I := 0 To FileList.Count - 1 Do
Begin
FFileName := FileList[I];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -