-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfpdxfwritebridge.pas
3288 lines (2866 loc) · 104 KB
/
fpdxfwritebridge.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit FPDxfWriteBridge;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, GeometryUtilsBridge{, Dialogs};
type
TDXFColor = (
DXFByBlock = 0,
DXFRed = 1,
DXFYellow = 2,
DXFGreen = 3,
DXFCyan = 4,
DXFBlue = 5,
DXFMagenta = 6,
DXFWhite = 7,
DXFGray = 8,
DXFBrown = 15,
DXFltRed = 23,
DXFltGreen = 121,
DXFltCyan = 131,
DXFltBlue = 163,
DXFltMagenta = 221,
DXFBlack = 250,
DXFltGray = 252,
DXFLyLayer = 256);
TDxfTextStyleCode = (
PRIMARY_FILE_NAME = 3,
FIXED_HEIGHT = 40,
WIDTH_FACTOR = 41,
LAST_HEIGHT_USED = 42,
TEXT_ANGLE = 50,
STANDARD_FLAG = 70,
GENERATION_FLAGS = 71);
{TDxfTextStyle}
TDxfTextStyle = class
public
TextStyleName: string;
FixedHeight: real;
WidthFactor: real;
GenerationFlags: integer;
LastHeightUsed: real;
PrimaryFileName: string;
TextAngle: real;
DxfCode: TDxfTextStyleCode;
function ToDXF: string;
constructor Create(textStyle: string; fontFileName: string; fontHeight: real);
destructor Destroy; Override;
end;
TDxfLineTypeCode = (
ASCII_LINE_PATTERN = 3,
SUM_DASH_ELEMENT_LENGTH = 40,
DASH_ELEMENT_LENGTH = 49,
ALIGNMENT = 72,
DASH_ELEMENT_COUNT = 73);
{TDxfLineType}
TDxfLineType = class
LineTypeName: String;
AsciiLinePatern: string; // '__ __ __ __') ; '__' {Plus}; ' ' {minus}
Alignment: integer; //"A"
DashElementCount: integer; // Number of linetype elements, ex up: 2
SUMDashElementLength: real; //Sum Abs DASH_ELEMENT_LENGTH: Abs(DashElementLength:=v[0])+ Abs(DashElementLength:=v[1]);
DashElementLength: real; //repeat patern: DashElementLength:=v[0]; DashElementLength:=v[1]; etc..
VectorDashElementLength: array of real; //alternate numbers: "+" or "-" where: '__' :plus ' ':minus
DxfCode: TDxfLineTypeCode;
function ToDXF: string;
constructor Create(typeName: string; VectDashLen: array of Real; linePattern: string);
destructor Destroy; override;
end;
TDxfDimStyleCode = (
ARROW_SIZE = 41,
OFFSET_EXTENSION_LINE_FROM_ORIGIN = 42,
EXTENSION_LINE_SIZE_PASSING = 44, // Extension line size after Dimension line
LINE_SIZE_PASSING = 46, // Dimension line size after Extension line
DIMSTANDARD_FLAGS = 70, //default: 0
POSITION_TEXT_INSIDE_EXTENSION_LINES = 73, //position of dimension text inside the extension lines
VERTICAL_TEXT_LOCATION = 77, // Vertical Text Placement
TEXT_HEIGHT = 140, //Text height
OFFSET_FROM_DIMENSION_LINE_TO_TEXT = 147, // Offset from dimension line to text
LINE_AND_ARROW_HEAD_COLOR = 176, // Dimension line & Arrow heads color
EXTENSION_LINE_COLOR = 177, // Extension line color
TEXT_COLOR = 178);
{TDxfDimStyle}
TDxfDimStyle = class
public
DimStyleName: string; // DimStyle Name
DimStandardFlags: integer; //0
{DIMCLRD} LineAndArrowHeadColor: integer;
{DIMDLE} LineSizePassing: real; // Dimension line size after Extensionline
{DIMCLRE} ExtensionLineColor: integer; // Extension line color
{DIMEXE} ExtensionLinePassing: real; // Extension line size after Dimension line
{DIMEXO} OffsetExtensionLineFromOrigin: real; // Offset from origin
{DIMASZ} ArrowSize: real;
ArrowWidth: real;
{DIMCLRT} TextColor: integer;
{DIMTXT} TextHeight: real;
{DIMTAD} VerticalTextLocation: integer;
{DIMTIH} PositionTextInsideExtensionLines: integer;
{DIMGAP} OffsetFromDimensionLineToText:real; // Gap/offset from dimension line to text
DxfCode: TDxfDimStyleCode;
function ToDXF: string;
constructor Create(styleName: string; arrwSize, ArrwWidth: real; color: integer;
txtHeight: real);
Destructor Destroy; override;
end;
TDxfLayerCode = (
LINE_TYPE = 6,
COLOR = 62);
TDxfLayer = record
LayerName: string;
LineType: string; //CONTINUOUS.. or Dashed.. or Hidden ... etc
Color: integer;
DxfCode: TDxfLayerCode;
end;
PDxfLayer = ^TDxfLayer;
TDxfCommonCode = (
TEXT1 = 1,
TEXT2 = 3, {only for MTEXT}
STYLE_NAME = 7, {Text style}
X1 = 10,
X2 = 11,
X3 = 12,
X4 = 13,
Y1 = 20,
Y2 = 21,
Y3 = 22,
Y4 = 23,
Z1 = 30,
Z2 = 31,
Z3 = 32,
Z4 = 33,
THICKNESS = 39,
SIZE = 40, {Radius, Height, ...}
ANGLE1 = 50, {start angle, rotation, inclination, ...}
ANGLE2 = 51, {end angle}
FOLLOW_FLAG = 66, {only PolyLine}
OPENED_CLOSED_FLAG = 70, {PolyLine and LWPolyLine}
COUNT_VERTICE = 90); {only LWPolyLine}
TDxfCommonData = class
public
X1, Y1, Z1: real;
Thickness: real;
DxfLayer: TDxfLayer;
DxfCommonCode: TDxfCommonCode;
constructor Create;
destructor Destroy; override;
end;
{TDxfPoint}
TDxfPoint = class(TDxfCommonData)
public
function ToDXF: string;
constructor Create(layerName: string; x, y: real);
destructor Destroy; override;
end;
{TDxfCircle}
TDxfCircle = class(TDxfCommonData)
public
Radius: real;
function ToDXF: string;
constructor Create(layerName: string; x, y, r: real);
destructor Destroy; override;
end;
{TDxfArc}
TDxfArc = class(TDxfCommonData)
public
Radius: real;
StartAngle: real;
EndAngle: real;
function ToDXF: string;
constructor Create(layerName: string; x, y, r, startAng, endAng: real);
destructor Destroy; override;
end;
TDxfDataText = class(TDxfCommonData)
public
Text1: string;
TextStyleName: string;
Height: real;
RotationAngle: real;
constructor Create;
Destructor Destroy; override;
end;
{TDxfText}
TDxfText = class(TDxfDataText)
public
function ToDXF: string;
constructor Create(layerName: string; angle, H, x, y: real; txt: string);
destructor Destroy; override;
end;
{TDxfMText}
TDxfMText = class(TDxfDataText)
public
Text2: string;
function ToDXF: string;
constructor Create(layerName: string; angle, H, x, y: real; txt: string);
destructor Destroy; override;
end;
{TDxfLine}
TDxfLine = class(TDxfCommonData)
public
X2: real;
Y2: real;
Z2: real;
function ToDXF: string;
constructor Create(layerName: string; px1, py1, px2, py2: real);
destructor Destroy; override;
end;
TDxfDataPolyLine = class(TDxfCommonData)
private
CountVertice: integer;
public
OpenedClosedFlag: integer;
Vertice: array of TRealPoint;
constructor Create;
destructor Destroy; override;
end;
{TDxfPolyLine}
TDxfPolyLine = class(TDxfDataPolyLine)
public
FollowFlag: integer; //set to 1!
function ToDXF: string;
constructor Create(layerName: string; V: array of TRealPoint; closed: boolean);
destructor Destroy; override;
end;
{TDxfLWPolyLine}
TDxfLWPolyLine = class(TDxfDataPolyLine)
function ToDXF: string;
constructor Create(layerName: string; V: array of TRealPoint; closed: boolean);
destructor Destroy; override;
end;
{TDxfSolidArrowHead}
TDxfSolidArrowHead = class(TDxfCommonData)
public
X2, Y2, Z2: real;
X3, Y3, Z3: real;
X4, Y4, Z4: real;
function ToDXF: string;
constructor Create(layerName: string; V: array of TRealPoint);
destructor Destroy; override;
end;
TDxfGenericDimensionCode = (
BLOCK_NAME = 2,
DIM_STYLE_NAME = 3, //dimension style name,
ORIGIN_X = 10, //X definition to specify the point of dimension line.
MIDDLE_TEXT_X = 11, //X middle point to specify the point of dimension text
DEF_POINT1_X = 13, //X of The point used to specify the first extension line.
DEF_POINT2_X = 14, //X of The point used to specify the second extension line.
DEF_POINT3_X = 15, //X of The point used to specify the second extension line.
ORIGIN_Y = 20,
MIDDLE_TEXT_Y = 21,
DEF_POINT1_Y = 23,
DEF_POINT2_Y = 24,
DEF_POINT3_Y = 25,
ORIGIN_Z = 30,
MIDDLE_TEXT_Z = 31,
DEF_POINT1_Z = 33,
DEF_POINT2_Z = 34,
DEF_POINT3_Z = 35,
LEADER_LENGTH = 40,
MEASUREMENT = 42, //actual dimension measurement
ANGLE = 50,
DIMTYPE = 70); //0 = rotated, horizontal, or vertical;1 = aligned ...
TDxfCommonDimensionData = class
protected
DimStyleName: string; //dimension style name,
OriginX: real; //X of definition point used to specify the dimension line.
MiddleTextX: real; //X of middle point used to specify the dimension text location
OriginY: real;
MiddleTextY: real;
OriginZ: real;
MiddleTextZ: real;
Measurement: real;
DimType: integer;
public
constructor Create;
Destructor Destroy; Override;
end;
{TDxfRadialDimension}
TDxfRadialDimension = class(TDxfCommonDimensionData)
private
FlagControl: integer;
Arrow1, Arrow2: TDxfSolidArrowHead;
DimText: TDxfText;
DimLine: TDxfLine;
public
BlockName: string;
DefPoint3X: real;
DefPoint3Y: real;
DefPoint3Z: real;
LeaderLength: real;
RAngle: real;
DxfCode: TDxfGenericDimensionCode;
DxfLayer: TDxfLayer;
function ToDXF: string;
procedure CreateBlock(layerName, anounymousBlockName, typeName: string; objDimStyle: TDxfDimStyle;
cx, cy, r, angle: real);
procedure CreateEntity(layerName, anounymousBlockName, typeName, styleName: string;
cx, cy, r, angle: real);
constructor Create(layerName, anounymousBlockName, typeName, styleName: string;
cx, cy, r, angle: real);
constructor Create(layerName, anounymousBlockName, typeName: string; objDimStyle: TDxfDimStyle;
cx, cy, r, angle: real);
destructor Destroy; override;
end;
{TDxfAngular3PDimension}
TDxfAngular3PDimension = class(TDxfCommonDimensionData)
private
FlagControl: integer;
DimText: TDxfText;
Arrow1, Arrow2: TDxfSolidArrowHead;
ExtLine1: TDxfLine;
ExtLine2: TDxfLine;
DimArc: TDxfArc;
public
BlockName: string;
Angle: real;
DefPoint1X: real;
DefPoint1Y: real;
DefPoint1Z: real;
DefPoint2X: real;
DefPoint2Y: real;
DefPoint2Z: real;
DefPoint3X: real;
DefPoint3Y: real;
DefPoint3Z: real;
DxfCode: TDxfGenericDimensionCode;
DxfLayer: TDxfLayer;
function ToDXF: string;
procedure CreateBlock(layerName, anounymousBlockName, typeName: string;
objDimStyle: TDxfDimStyle; offset: real; cx, cy, r, startAngle, endAngle: real);
procedure CreateEntity(layerName, anounymousBlockName, styleName: string; offset: real;
cx, cy, r, startAngle, endAngle: real);
constructor Create(layerName, anounymousBlockName, styleName: string; offset: real;
cx, cy, r, startAngle, endAngle: real);
constructor Create(layerName, anounymousBlockName, typeName: string;
objDimStyle: TDxfDimStyle; offset: real; cx, cy, r, startAngle, endAngle: real);
destructor Destroy; override;
end;
{TDxfLinearDimension}
TDxfLinearDimension = class(TDxfCommonDimensionData)
private
FlagControl: integer;
DimText: TDxfText;
Arrow1, Arrow2: TDxfSolidArrowHead;
DimLine: TDxfLine;
ExtLine1: TDxfLine;
ExtLine2: TDxfLine;
public
BlockName: string;
DefPoint1X: real; //13
DefPoint2X: real; //14
DefPoint1Y: real; //23
DefPoint2Y: real; //24
DefPoint1Z: real; //33
DefPoint2Z: real; //34
Angle: real; //50
DxfCode: TDxfGenericDimensionCode;
DxfLayer: TDxfLayer;
function ToDXF: string;
procedure CreateBlock(layerName, anounymousBlockName, typeName: string; objDimStyle: TDxfDimStyle;
offset, x1, y1, x2, y2: real);
procedure CreateEntity(layerName, anounymousBlockName, typeName, styleName: string;
offset, x1, y1, x2, y2: real);
constructor Create(layerName, anounymousBlockName, typeName, styleName: string;
offset, x1, y1, x2, y2: real);
constructor Create(layerName, anounymousBlockName, typeName: string; objDimStyle: TDxfDimStyle;
offset, x1, y1, x2, y2: real);
destructor Destroy; override;
end;
TProduceEntity = procedure(out entityDXF: string) of object;
TProduceBlock = procedure(out blockDXF: string) of object;
{TFPDxfWriteBridge}
TFPDxfWriteBridge = class(TComponent)
private
DimBlockList: TList;
FOnProduceEntity: TProduceEntity;
FOnProduceBlock: TProduceBlock;
function RadialOrDiameterDimension(layerName, anounymousBlockName, typeName, styleName: string;
cx, cy, r, angle: real): string;
function LinearOrAlignedDimension(layerName, anounymousBlockName, typeName, styleName: string;
offset, x1, y1, x2, y2: real): string;
function AngularOrArc3PDimension(layerName, anounymousBlockName, typeName, styleName: string;
offset: real; cx, cy, r, startAngle, endAngle: real): string;
public
RestrictedLayer: string;
ToDxf: TStringList;
LayerList: TList;
LineTypeList: TList;
TextStyleList: TList;
DimStyleList: TList;
procedure Produce(selectLayer: string);
procedure DoProduceDXFEntity(out entityDXF: string);
procedure DoProduceDXFBlock(out blockDXF: string);
procedure AddLayer(LayerName, lineType: string; color: integer);
procedure DeleteLayerByIndex(index: integer);
//'CENTER',[1.25,-0.25, 0.25, -0.25],'____ _ ____ _ '
procedure AddLineType(lineTypeName: string; V: array of real; linePattern: string);
procedure AddTextStyle(fontName: string; fontFileName: string; fontHeight: real);
procedure AddDimStyle(styleName: string; arrwSize, arrwWidth: real; color: integer;
txtHeight: real);
procedure DxfBegin;
procedure BeginTables;
procedure BeginTable(tabName: string; count: integer);
procedure AddTableLType(tabName: string; V: array of real; graphicsPattern: string);
procedure AddTableTextStyle(fontName, fontFileName: string; fontHeight: real);
procedure AddTableLayer(tabName, lineType: string; color: integer);
procedure AddTableLayer(tabName, lineType: string; color: TDXFColor);
procedure AddTableLayer(tabName, lineType: string; color: string);
procedure AddTableDimStyle(dimStyleName: string; arrwSize, arrwWidth: real;
color: integer; txtHeight:real);
//procedure AddTableUCS(tabName: string);
procedure EndTable;
procedure EndTables;
procedure BeginBlocks;
function BeginBlock(layerName, blockName: string; X,Y: real): string;
procedure AddBlock(dxfBlock: string);
function EndBlock: string;
procedure EndBlocks;
procedure BeginEntities;
procedure AddEntity(dxfEntity: string);
procedure AddEntity(objEntity: TObject);
procedure EndEntities;
function InsertBlock(blockName: string; x,y: real): string;
procedure DxfEnd;
function Circle(layerName: string; x, y, radius: real): string;
function Arc(layerName: string; x, y, radius, startAngle, endAngle: real): string;
function Point(layerName: string; x, y: real): string;
function Text(layerName: string; angle, height, x, y: real; txt: string): string;
function MText(layerName: string; angle, height, x, y: real; txt: string): string;
function SolidArrowHead(layerName: string; V: array of TRealPoint): string;
function Line(layerName: string; x1, y1, x2, y2: real): string;
function LWPolyLine(layerName: string; V: array of TRealPoint; closed: boolean): string;
function PolyLine(layerName: string; V: array of TRealPoint; closed: boolean): string;
function LinearAlignedDimension(layerName, anounymousBlockName, styleName: string;
offset, x1, y1, x2, y2: real): string;
function LinearHorizontalDimension(layerName, anounymousBlockName, styleName: string;
offset, x1, y1, x2, y2: real): string;
function LinearVerticalDimension(layerName, anounymousBlockName, styleName: string;
offset, x1, y1, x2, y2: real): string;
function RadialDimension(layerName, anounymousBlockName, styleName: string;
cx, cy, r, angle: real): string;
function DiameterDimension(layerName, anounymousBlockName, styleName: string;
cx, cy, r, angle: real): string;
function Angular3PDimension(layerName, anounymousBlockName, styleName: string; offset: real;
cx, cy, r, startAngle, endAngle: real): string;
function Arc3PDimension(layerName, anounymousBlockName, styleName: string; offset: real;
cx, cy, r, startAngle, endAngle: real): string;
function Dimension(AnounymousDimensionanounymousBlockName: string): string;
function LinearAlignedDimension(layerName, styleName: string;
offset, x1, y1, x2, y2: real): string;
function LinearHorizontalDimension(layerName, styleName: string;
offset, x1, y1, x2, y2: real): string;
function LinearVerticalDimension(layerName, styleName: string;
offset, x1, y1, x2, y2: real): string;
function RadialDimension(layerName, styleName: string;
cx, cy, r, angle: real): string;
function DiameterDimension(layerName, styleName: string;
cx, cy, r, angle: real): string;
function Angular3PDimension(layerName, styleName: string; offset: real;
cx, cy, r, startAngle, endAngle: real): string;
function Arc3PDimension(layerName, styleName: string; offset: real;
cx, cy, r, startAngle, endAngle: real): string;
procedure SaveToFile(path: string);
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnProduceEntity: TProduceEntity read FOnProduceEntity write FOnProduceEntity;
property OnProduceBlock: TProduceBlock read FOnProduceBlock write FOnProduceBlock;
end;
(*TODO:
{TDxfBridge}
TDxfBridge = class
public
Write: TFPDxfWriteBridge;
Read: TDxfReadBridge; //TODO:
constructor Create;
destructor Destroy; override;
end;
*)
function ReplaceChar(query: string; oldchar, newchar: char):string;
implementation
function ReplaceChar(query: string; oldchar, newchar: char):string;
begin
if query <> '' then
begin
while Pos(oldchar,query) > 0 do query[pos(oldchar,query)]:= newchar;
Result:= query;
end;
end;
constructor TDxfCommonData.Create;
begin
//
end;
destructor TDxfCommonData.Destroy;
begin
//
inherited Destroy;
end;
constructor TDxfDataText.Create;
begin
//
end;
destructor TDxfDataText.Destroy;
begin
//
inherited Destroy;
end;
constructor TDxfDataPolyLine.Create;
begin
//
end;
destructor TDxfDataPolyLine.Destroy;
begin
//
inherited Destroy;
end;
constructor TDxfCommonDimensionData.Create;
begin
//
end;
destructor TDxfCommonDimensionData.Destroy;
begin
//
inherited Destroy;
end;
{TDxfDimStyle}
function TDxfDimStyle.ToDXF: string;
var
dxfList: TStringList;
begin
dxfList:= TStringList.Create;
dxfList.Add('0');
dxfList.Add('DIMSTYLE');
dxfList.Add('100');
dxfList.Add('AcDbSymbolTableRecord');
dxfList.Add('100');
dxfList.Add('AcDbDimStyleTableRecord');
dxfList.Add('2');
dxfList.Add(DimStyleName);
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.DIMSTANDARD_FLAGS))); //DxfCode
dxfList.Add(intToStr(DimStandardFlags));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.VERTICAL_TEXT_LOCATION))); //DxfCode
dxfList.Add(intToStr(VerticalTextLocation));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.LINE_AND_ARROW_HEAD_COLOR)));
dxfList.Add(intToStr(LineAndArrowHeadColor));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.EXTENSION_LINE_COLOR)));
dxfList.Add(intToStr(ExtensionLineColor));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.TEXT_COLOR)));
dxfList.Add(intToStr(TextColor));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.ARROW_SIZE)));
dxfList.Add(ReplaceChar(FloatToStrF(ArrowSize, ffFixed,0,2) , ',', '.'));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.LINE_SIZE_PASSING)));
dxfList.Add(ReplaceChar(FloatToStrF(LineSizePassing, ffFixed,0,2),',','.'));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.EXTENSION_LINE_SIZE_PASSING)));
dxfList.Add(ReplaceChar(FloatToStrF(ExtensionLinePassing, ffFixed,0,2),',','.'));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.OFFSET_EXTENSION_LINE_FROM_ORIGIN)));
dxfList.Add(ReplaceChar(FloatToStrF(OffsetExtensionLineFromOrigin, ffFixed,0,2),',','.'));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.OFFSET_FROM_DIMENSION_LINE_TO_TEXT)));
dxfList.Add(ReplaceChar(FloatToStrF(OffsetFromDimensionLineToText, ffFixed,0,2),',','.'));
dxfList.Add(intToStr(Ord(TDxfDimStyleCode.TEXT_HEIGHT)));
dxfList.Add(ReplaceChar(FloatToStrF(TextHeight, ffFixed,0,2),',','.'));
//autocad need!
dxfList.Add('3');
dxfList.Add('');
dxfList.Add('4');
dxfList.Add('');
dxfList.Add('5');
dxfList.Add('');
dxfList.Add('6');
dxfList.Add('');
dxfList.Add('7');
dxfList.Add('');
dxfList.Add('40'); //DIMSCALE
dxfList.Add('1.0');
dxfList.Add('43'); //DIMDLI
dxfList.Add('0.38'); {metric} {0.38 = imperial}
dxfList.Add('45'); //DIMRND
dxfList.Add('0.0');
dxfList.Add('47'); //DIMTP
dxfList.Add('0.0');
dxfList.Add('48'); //DIMTM
dxfList.Add('0.0');
dxfList.Add('141'); //DIMCEN
dxfList.Add('0.09');
dxfList.Add('142'); //DIMTSZ
dxfList.Add('0.0');
dxfList.Add('143'); //DIMALTF
dxfList.Add('25.39999');
dxfList.Add('144'); //DIMLFAC
dxfList.Add('1.0');
dxfList.Add('145'); //DIMTVP
dxfList.Add('0.0');
dxfList.Add('146'); //DIMTFAC
dxfList.Add('1.0');
dxfList.Add('71');
dxfList.Add('0');
dxfList.Add('72');
dxfList.Add('0');
dxfList.Add('73');
dxfList.Add('1');
dxfList.Add('74');
dxfList.Add('1');
dxfList.Add('75');
dxfList.Add('0');
dxfList.Add('76');
dxfList.Add('0');
dxfList.Add('78');
dxfList.Add('0');
dxfList.Add('170');
dxfList.Add('0');
dxfList.Add('171');
dxfList.Add('2');
dxfList.Add('172');
dxfList.Add('0');
dxfList.Add('173');
dxfList.Add('0');
dxfList.Add('174');
dxfList.Add('0');
dxfList.Add('175');
dxfList.Add('0');
Result:= Trim(dxfList.Text);
dxfList.Free;
end;
//AddDimStyle('CUSTOM', 0.1800{arrwSize}, 0.0625{arrwWidth} , 2{color}, 0.1800 {0.25});
constructor TDxfDimStyle.Create(styleName: string; arrwSize, arrwWidth: real; color: integer;
txtHeight: real);
begin
DimStandardFlags:= 0;
if (styleName = '') or (Pos(styleName,'GENERIC') > 0 ) then
begin
DimStyleName:= 'GENERIC';
{DIMCLRD} LineAndArrowHeadColor:= 256;
{DIMDLE} LineSizePassing:= 0.0; //0:for arrow; OR <>0: for tickes/strok...line size after Extensionline
{DIMCLRE} ExtensionLineColor:= 256;
{DIMEXE} ExtensionLinePassing:= 0.1800; {or 1.2500 metric} // Extension line size after Dimension line
{DIMEXO} OffsetExtensionLineFromOrigin:= 0.0625; //distance from extension line from baseline/shape
{DIMASZ} ArrowSize:= 0.1800;
ArrowWidth:= 0.0625;
{DIMCLRT} TextColor:= 256;
{DIMTXT} TextHeight:= 0.1800; {imperial 2.5 = metric}
{DIMTIH} PositionTextInsideExtensionLines:= 1; {1= force horizontal 0=metric}
{DIMTAD} VerticalTextLocation:= 0; {imperial} {1=metric} //Place text above the dimension line
{DIMGAP} OffsetFromDimensionLineToText:= 0.0900;{0.6250 = metric} {imperial=0.0900}; //Gape from dimension line to text
end
else
begin
DimStyleName:= styleName;
{DIMCLRD} LineAndArrowHeadColor:= color;
{DIMDLE} LineSizePassing:= 0.0;
{DIMCLRE} ExtensionLineColor:= color;
{DIMEXE} ExtensionLinePassing:= 0.1800;
{DIMEXO} OffsetExtensionLineFromOrigin:= 0.0625;
{DIMASZ} ArrowSize:= arrwSize;
ArrowWidth:= arrwWidth;
{DIMCLRT} TextColor:= color;
{DIMTXT} TextHeight:= txtHeight;
{DIMTIH} PositionTextInsideExtensionLines:= 1; {1= force horizontal}
{DIMTAD} VerticalTextLocation:= 0;
{DIMGAP} OffsetFromDimensionLineToText:= 0.0900; {0.6250 or 0.0900};
end;
end;
Destructor TDxfDimStyle.Destroy;
begin
//
inherited Destroy;
end;
{TDxfLinearDimension}
function TDxfLinearDimension.ToDXF: string;
var
dxfList: TStringList;
begin
dxfList:= TStringList.Create;
if FlagControl = 1 then //Create Block
begin
dxfList.Add(DimLine.ToDXF);
dxfList.Add(Arrow1.ToDXF);
dxfList.Add(Arrow2.ToDXF);
dxfList.Add(ExtLine1.ToDXF);
dxfList.Add(ExtLine2.ToDXF);
dxfList.Add(DimText.ToDXF);
Result:= TrimRight(dxfList.Text);
end
else //Create Entity
begin
dxfList.Add('0');
dxfList.Add('DIMENSION');
dxfList.Add('100');
dxfList.Add('AcDbEntity');
dxfList.Add('8');
dxfList.Add(DxfLayer.LayerName);
dxfList.Add('100');
dxfList.Add('AcDbDimension');
dxfList.Add('2');
dxfList.Add(BlockName);
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.ORIGIN_X)));
dxfList.Add(ReplaceChar(FloatToStrF(OriginX, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.ORIGIN_Y)));
dxfList.Add(ReplaceChar(FloatToStrF(OriginY, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.ORIGIN_Z)));
dxfList.Add(ReplaceChar(FloatToStrF(OriginZ, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.MIDDLE_TEXT_X)));
dxfList.Add(ReplaceChar(FloatToStrF(MiddleTextX, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.MIDDLE_TEXT_Y)));
dxfList.Add(ReplaceChar(FloatToStrF(MiddleTextY, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.MIDDLE_TEXT_Z)));
dxfList.Add(ReplaceChar(FloatToStrF(MiddleTextZ, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.DIMTYPE)));
dxfList.Add(intToStr(DimType));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.DIM_STYLE_NAME)));
dxfList.Add(DimSTyleName);
dxfList.Add('100');
dxfList.Add('AcDbAlignedDimension');
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.DEF_POINT1_X)));
dxfList.Add(ReplaceChar(FloatToStrF(DefPoint1X, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.DEF_POINT1_Y)));
dxfList.Add(ReplaceChar(FloatToStrF(DefPoint1Y, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.DEF_POINT1_Z)));
dxfList.Add(ReplaceChar(FloatToStrF(DefPoint1Z, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.DEF_POINT2_X)));
dxfList.Add(ReplaceChar(FloatToStrF(DefPoint2X, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.DEF_POINT2_Y)));
dxfList.Add(ReplaceChar(FloatToStrF(DefPoint2Y, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.DEF_POINT2_Z)));
dxfList.Add(ReplaceChar(FloatToStrF(DefPoint2Z, ffFixed,0,2), ',','.'));
dxfList.Add(intToStr(Ord(TDxfGenericDimensionCode.ANGLE)));
dxfList.Add(ReplaceChar(FloatToStrF(Angle, ffFixed,0,2), ',','.'));
if DimType = 0 then
begin
dxfList.Add('100');
dxfList.Add('AcDbRotatedDimension');
end;
Result:= Trim(dxfList.Text);
end;
dxfList.Free;
end;
procedure TDxfLinearDimension.CreateBlock(layerName, anounymousBlockName, typeName: string; objDimStyle: TDxfDimStyle;
offset, x1, y1, x2, y2: real);
var
{DIMEXE,} DIMEXO, DIMASZ{, DIMDLE}: real;
px,py, px1,py1, px2,py2, angleDegree: real;
orthoX1,orthoY1,orthoX2,orthoY2: real;
distP1P2, dLineX1, dLineY1, dLineX2, dLineY2 : real;
x, y: real;
begin
FlagControl:= 1;
BlockName:= anounymousBlockName;
if objDimStyle <> nil then
begin
//DIMEXE:= objDimStyle.ExtensionLinePassing; {0.1}
DIMEXO:= objDimStyle.OffsetExtensionLineFromOrigin; {0.1}
DIMASZ:= objDimStyle.ArrowSize; {0.2}
//DIMDLE:= 0.0; DimStyle.DimesionLineSizePassing; {0.0}
end
else
begin
//DIMEXE:= 0.1800; {1.25}
DIMEXO:= 0.0625; {metric = 0.625}
DIMASZ:= 0.1800; {2.5}
//DIMDLE:= 0.0;
end;
x:=x1;
y:=y1;
if typeName = 'H' then y:=y2;
if typeName = 'V' then x:=x2;
distP1P2:= sqrt(sqr(x2-x) + sqr(y2-y));
GetLineParallel(offset, x, y, x2, y2, dLineX1,dLineY1,dLineX2,dLineY2);
DimLine:= TDxfLine.Create(layerName,dLineX1,dLineY1,dLineX2,dLineY2);
GetLineOrthogonal(-DIMASZ{offset}, objDimStyle.ArrowWidth {r}, dLineX1,dLineY1,dLineX2,dLineY2,
orthoX1,orthoY1,orthoX2,orthoY2, px, py, 1);
Arrow1:= TDxfSolidArrowHead.Create(layerName,[ToRealPoint(orthoX1,orthoY1),ToRealPoint(orthoX2,orthoY2),
ToRealPoint(dLineX1,dLineY1),ToRealPoint(dLineX1,dLineY1)]);
GetLineOrthogonal(-DIMASZ{offset}, objDimStyle.ArrowWidth {r}, dLineX1,dLineY1,dLineX2,dLineY2,
orthoX1,orthoY1,orthoX2,orthoY2, px, py, 2);
Arrow2:= TDxfSolidArrowHead.Create(layerName,[ToRealPoint(orthoX1,orthoY1),ToRealPoint(orthoX2,orthoY2),
ToRealPoint(dLineX2,dLineY2),ToRealPoint(dLineX2,dLineY2)]);
GetLineTranslated(dimexo,x, y, dLineX1,dLineY1, px1, py1, px2, py2);
ExtLine1:= TDxfLine.Create(layerName, px1, py1, px2, py2);
GetLineTranslated(dimexo,x2, y2, dLineX2,dLineY2, px1, py1, px2, py2);
ExtLine2:= TDxfLine.Create(layerName, px1, py1, px2, py2);
Angle:= GetAngleOfLine(dLineX1,dLineY1,dLineX2,dLineY2);
angleDegree:= ToDegrees(angle);
DimText:= TDxfText.Create(layerName, angleDegree, objDimStyle.TextHeight, (dLineX1+dLineX2)/2,(dLineY1+dLineY2)/2,
ReplaceChar(FloatToStrF(distP1P2,ffFixed,0,2),',','.'));
end;
procedure TDxfLinearDimension.CreateEntity(layerName, anounymousBlockName, typeName, styleName: string;
offset, x1, y1, x2, y2: real);
var
ang, angleDegree: real;
distP1P2, dLineX1, dLineY1, dLineX2, dLineY2 : real;
x,y: real;
begin
FlagControl:=2;
BlockName:= anounymousBlockName;
if layerName = '' then DxfLayer.LayerName:='0'
else DxfLayer.LayerName:= layerName; //'0';default autocad layer!
DxfLayer.Color:= 256; //0 : BYBLOCK.
DxfLayer.LineType:= 'BYLAYER';
if styleName <> '' then
DimSTyleName:= styleName
else DimSTyleName:= 'GENERIC';
x:=x1;
y:=y1;
if typeName = 'A' then
begin
ang:=GetAngleOfLine(x, y, x2, y2);
DimType:= 33; //1=aligned or 33!;
end;
if typeName = 'H' then
begin
y:=y2;
DimType:= 32; //0= Linear horizontal or 32!
ang:=0;
end;
if typeName = 'V' then
begin
x:=x2;
DimType:= 32; //0= Linear vertical;
ang:= PI/2;
end;
distP1P2:= sqrt(sqr(x2-x)+sqr(y2-y));
Measurement:= distP1P2;
GetLineParallel(offset, x, y, x2, y2, dLineX1,dLineY1,dLineX2,dLineY2);
angleDegree:= ToDegrees(ang);
Angle:= angleDegree; //50 angle of rotated, horizontal, or vertical Aligned dimensions
MiddleTextX:=(dLineX1+dLineX2)/2;
MiddleTextY:=(dLineY1+dLineY2)/2;
MiddleTextZ:=0.0;
DefPoint1X:= x; //13,
DefPoint2X:= x2; //14,
DefPoint1Y:= y; //23,
DefPoint2Y:= y2; //24,
DefPoint1Z:= 0.0; //33,
DefPoint2Z:= 0.0; //34,
OriginX:= dLineX1;
OriginY:= dLineY1;
OriginZ:= 0.0;
end;
//create Entity
constructor TDxfLinearDimension.Create(layerName, anounymousBlockName, typeName, styleName: string;
offset, x1, y1, x2, y2: real);
begin
CreateEntity(layerName, anounymousBlockName, typeName, styleName, offset, x1, y1, x2, y2);
end;
//create Block
constructor TDxfLinearDimension.Create(layerName, anounymousBlockName, typeName: string; objDimStyle: TDxfDimStyle;
offset, x1, y1, x2, y2: real);
begin
CreateBlock(layerName, anounymousBlockName, typeName, objDimStyle, offset, x1, y1, x2, y2);
end;
destructor TDxfLinearDimension.Destroy;
begin
DimText.Free;
Arrow1.Free;
Arrow2.Free;
DimLine.Free;
ExtLine1.Free;
ExtLine2.Free;
inherited Destroy;
end;
{TDxfRadialDimension}
function TDxfRadialDimension.ToDXF: string;
var
dxfList: TStringList;
begin
dxfList:= TStringList.Create;
if flagControl = 1 then //Create Block
begin
dxfList.Add(DimLine.ToDXF);
dxfList.Add(Arrow1.ToDXF);
dxfList.Add(Arrow2.ToDXF);
dxfList.Add(DimText.ToDXF);
Result:= TrimRight(dxfList.Text);
end
else //Create Entity
begin
dxfList.Add('0');
dxfList.Add('DIMENSION');
dxfList.Add('100');
dxfList.Add('AcDbEntity');
dxfList.Add('8');