1 {
2 *****************************************************************************
3 * *
4 * This file is part of the ZCAD *
5 * *
6 * See the file COPYING.modifiedLGPL.txt, included in this distribution, *
7 * for details about the copyright. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
12 * *
13 *****************************************************************************
14 }
15 {
16 @author(Andrey Zubarev <zamtmn@yandex.ru>)
17 }
18 unit uzeblockdef;
19 {$INCLUDE def.inc}
20 interface
21 uses gzctnrvectortypes,uzeentity,uzeentityfactory,uzgldrawcontext,uzeobjectextender,uzedrawingdef,
22 uzeentsubordinated,uzeffdxfsupport,UGDBOpenArrayOfByte,uzbtypesbase,sysutils,uzbtypes,
23 uzbgeomtypes,uzbmemman,uzegeometry,uzestyleslayers,uzeconsts,uzeentgenericsubentry,LazLogger;
24 type
25 {REGISTEROBJECTTYPE GDBObjBlockdef}
26 {Export+}
27 PGDBObjBlockdef=^GDBObjBlockdef;
28 GDBObjBlockdef={$IFNDEF DELPHI}packed{$ENDIF} object(GDBObjGenericSubEntry)
29 Name:GDBString;(*saved_to_shd*)
30 VarFromFile:GDBString;(*saved_to_shd*)
31 Base:GDBvertex;(*saved_to_shd*)
32 Formated:GDBBoolean;
33 BlockDesc:TBlockDesc;(*'Block params'*)(*saved_to_shd*)(*oi_readonly*)
34 constructor initnul(owner:PGDBObjGenericWithSubordinated);
35 constructor init(_name:GDBString);
36 procedure FormatEntity(var drawing:TDrawingDef;var DC:TDrawContext);virtual;
FindVariablenull37 //function FindVariable(varname:GDBString):pvardesk;virtual;
38 procedure LoadFromDXF(var f: GDBOpenArrayOfByte;ptu:PExtensionData;var drawing:TDrawingDef);virtual;
ProcessFromDXFObjXDatanull39 function ProcessFromDXFObjXData(_Name,_Value:GDBString;ptu:PExtensionData;const drawing:TDrawingDef):GDBBoolean;virtual;
40 destructor done;virtual;
GetMatrixnull41 function GetMatrix:PDMatrix4D;virtual;
GetHandlenull42 function GetHandle:GDBPlatformint;virtual;
GetMainOwnernull43 function GetMainOwner:PGDBObjSubordinated;virtual;
GetTypenull44 function GetType:GDBPlatformint;virtual;
GetDXFIOFeaturesnull45 class function GetDXFIOFeatures:TDXFEntIODataManager;static;
46 end;
47 {Export-}
48 var
49 GDBObjBlockDefDXFFeatures:TDXFEntIODataManager;
50 implementation
51 //uses {iodxf,}{UUnitManager,}{uzcshared,}log;
GDBObjBlockdef.GetTypenull52 function GDBObjBlockdef.GetType:GDBPlatformint;
53 begin
54 result:=1;
55 end;
GDBObjBlockdef.GetMainOwnernull56 function GDBObjBlockdef.GetMainOwner:PGDBObjSubordinated;
57 begin
58 result:=@self;
59 end;
GDBObjBlockdef.GetHandlenull60 function GDBObjBlockdef.GetHandle:GDBPlatformint;
61 begin
62 result:=H_Root;
63 end;
GDBObjBlockdef.GetMatrixnull64 function GDBObjBlockdef.GetMatrix;
65 begin
66 result:=@OneMatrix;
67 end;
68 destructor GDBObjBlockdef.done;
69 begin
70 Name:='';
71 VarFromFile:='';
72 inherited;
73 end;
74 procedure GDBObjBlockdef.LoadFromDXF;
75 var
76 byt: GDBInteger;
77 begin
78 //initnul(@gdb.ObjRoot);
79 byt:=readmystrtoint(f);
80 while byt <> 0 do
81 begin
82 if not LoadFromDXFObjShared(f,byt,ptu,drawing) then
83 f.ReadGDBString;
84 byt:=readmystrtoint(f);
85 end;
86 GetDXFIOFeatures.RunAfterLoadFeature(@self);
87 end;
88 {function GDBObjBlockdef.FindVariable;
89 begin
90 result:=nil;//ou.FindVariable(varname);
91 end;}
92 procedure GDBObjBlockdef.FormatEntity(var drawing:TDrawingDef;var DC:TDrawContext);
93 var
94 p:pgdbobjEntity;
95 ir:itrec;
96 begin
97 p:=ObjArray.beginiterate(ir);
98 if p<>nil then
99 repeat
100 //programlog.LogOutStr('format entity '+inttostr(ir.itc),lp_OldPos);
101 p^.formatEntity(drawing,dc);
102 p^.BuildGeometry(drawing);
103 p^.FromDXFPostProcessAfterAdd;
104 p:=ObjArray.iterate(ir);
105 until p=nil;
106 Formated:=true;
107 end;
108
109 constructor GDBObjBlockdef.initnul;
110 begin
111 inherited;
112 GDBPointer(Name):=nil;
113 GDBPointer(VarFromFile):=nil;
114 Formated:=false;
115 ObjArray.initnul;
116 Base:=nulvertex;
117 GetDXFIOFeatures.AddExtendersToEntity(@self);
118 end;
119 constructor GDBObjBlockdef.init;
120 begin
121 inherited initnul(nil);
122 GDBPointer(Name):=nil;
123 GDBPointer(VarFromFile):=nil;
124 Formated:=false;
125 //ObjArray.init({$IFDEF DEBUGBUILD}'{E5C5FEFE-BF2A-48FA-8E54-D1F406DA9462}',{$ENDIF}10000);
126 Name:=_name;
127 Base:=nulvertex;
128 GetDXFIOFeatures.AddExtendersToEntity(@self);
129 end;
GDBObjBlockdef.GetDXFIOFeaturesnull130 class function GDBObjBlockdef.GetDXFIOFeatures:TDXFEntIODataManager;
131 begin
132 result:=GDBObjBlockDefDXFFeatures;
133 end;
GDBObjBlockdef.ProcessFromDXFObjXDatanull134 function GDBObjBlockdef.ProcessFromDXFObjXData;
135 var
136 features:TDXFEntIODataManager;
137 FeatureLoadProc:TDXFEntLoadFeature;
138 begin
139 result:=false;
140 features:=GetDXFIOFeatures;
141 if assigned(features) then
142 begin
143 FeatureLoadProc:=features.GetLoadFeature(_Name);
144 if assigned(FeatureLoadProc)then
145 begin
146 result:=FeatureLoadProc(_Name,_Value,ptu,drawing,@self);
147 end;
148 end;
149 if not(result) then
150 result:=inherited ProcessFromDXFObjXData(_Name,_Value,ptu,drawing);
151 end;
AllocBlockDefnull152 function AllocBlockDef:PGDBObjBlockDef;
153 begin
154 GDBGetMem({$IFDEF DEBUGBUILD}'{AllocBlockDef}',{$ENDIF}pointer(result),sizeof(GDBObjBlockdef));
155 end;
AllocAndInitBlockDefnull156 function AllocAndInitBlockDef(owner:PGDBObjGenericWithSubordinated):PGDBObjBlockDef;
157 begin
158 result:=AllocBlockDef;
159 result.initnul(owner);
160 end;
161 procedure SetLineGeomProps(PBlockdef:PGDBObjBlockDef;args:array of const);
162 var
163 counter:integer;
164 begin
165 counter:=low(args);
166 PBlockdef.Name:=CreateGDBStringFromArray(counter,args);
167 PBlockdef.Base:=CreateVertexFromArray(counter,args);
168 end;
AllocAndCreateBlockDefnull169 function AllocAndCreateBlockDef(owner:PGDBObjGenericWithSubordinated;args:array of const):PGDBObjBlockDef;
170 begin
171 result:= AllocAndInitBlockDef(owner);
172 SetLineGeomProps(result,args);
173 end;
174 initialization
175 GDBObjBlockDefDXFFeatures:=TDXFEntIODataManager.Create;
176 {RegisterDXFEntity}RegisterEntity(GDBBlockDefID,'BlockDef',@AllocBlockDef,@AllocAndInitBlockDef,@SetLineGeomProps,@AllocAndCreateBlockDef);
177 finalization
178 debugln('{I}[UnitsFinalization] Unit "',{$INCLUDE %FILE%},'" finalization');
179 GDBObjBlockDefDXFFeatures.Destroy;
180 end.
181