1616@author(Andrey Zubarev <zamtmn@yandex.ru>)
1717}
1818unit uzcLapeScriptsImplDrawing;
19- { $Codepage UTF8}
19+ { $Codepage UTF8}{ $Mode delphi }{ $H+ }
2020{ $INCLUDE zengineconfig.inc}
2121
2222interface
@@ -38,7 +38,8 @@ interface
3838 uzgldrawcontext,uzeentitiestypefilter,uzCtnrVectorPBaseEntity,
3939 uzeEntBase,gzctnrVectorTypes,uzcEnitiesVariablesExtender,uzcExtdrIncludingVolume,
4040 uzsbVarmanDef,UBaseTypeDescriptor,uzcregisterenitiesfeatures,
41- uzcCounter,varman,uzcdevicebaseabstract,Masks;
41+ uzcCounter,varman,uzcdevicebaseabstract,Masks,Generics.Defaults,Generics.Collections,
42+ gzctnrSTL;
4243
4344type
4445
@@ -146,6 +147,37 @@ implementation
146147 TSingles=array of Single;
147148 PSingles=^TSingles;
148149
150+ type
151+ TNames=array of string;
152+ TCounterResult=record names:Tnames;Key:string;Value :double;isInteger:boolean; end ;
153+ TCounterResults=array of TCounterResult;
154+ PCounterResults=^TCounterResults;
155+
156+ ICounterResultComparer=Generics.Defaults.IComparer<TCounterResult>;
157+ TCounterResultComparer=class (TInterfacedObject,ICounterResultComparer)
158+ function Compare (const Left,Right:TCounterResult):Integer;overload;
159+ end ;
160+
161+ TPCounter=TMyMapCounter<pointer>;
162+
163+ function TCounterResultComparer.Compare (const Left,Right:TCounterResult):Integer;overload;
164+ var
165+ l0,r0:string;
166+ begin
167+ if length(left.names)=0 then
168+ l0:=' '
169+ else
170+ l0:=left.names[0 ];
171+
172+ if length(right.names)=0 then
173+ r0:=' '
174+ else
175+ r0:=right.names[0 ];
176+ Result:=CompareStr(l0,r0);
177+ if Result=0 then
178+ Result:=CompareStr(left.Key,right.Key);
179+ end ;
180+
149181constructor ThEnts.Create;
150182begin
151183 fEnts.init(32 );
@@ -1102,6 +1134,63 @@ procedure ThCombineCounter_Create(const Params:PParamArray;const Result:Pointer)
11021134 PThingsIndex(Result)^.Index:=PThingsIndex(Result)^.Things.Size-1 ;
11031135end ;
11041136
1137+ procedure ThDictionary_Create (const Params:PParamArray;const Result:Pointer); cdecl;
1138+ var
1139+ ctx:TCurrentDrawingContext;
1140+ counter:TPCounter;
1141+ begin
1142+ ctx:=TCurrentDrawingContext(Params^[0 ]);
1143+ counter:=TPCounter.Create;
1144+ ctx.Things.PushBack(counter);
1145+ PThingsIndex(Result)^.Things:=ctx.Things;
1146+ PThingsIndex(Result)^.Index:=PThingsIndex(Result)^.Things.Size-1 ;
1147+ end ;
1148+
1149+ procedure ThDictionary_Free (const Params:PParamArray); cdecl;
1150+ var
1151+ Index:TThingsIndex;
1152+ counter:TPCounter;
1153+ begin
1154+ Index:=PThingsIndex(Params^[0 ])^;
1155+ if (Index.Things<>nil )and (Index.Index>=0 ) then begin
1156+ counter:=TPCounter(TThings(Index.Things)[Index.Index]);
1157+ counter.Free;
1158+ TThings(Index.Things).mutable[Index.Index]^:=nil ;
1159+ PThingsIndex(Params^[0 ])^.Index:=-1 ;
1160+ PThingsIndex(Params^[0 ])^.Things:=nil ;
1161+ end else
1162+ raise EScriptAV.CreateFmt(cEScriptAVmsg,[cThngNameThCombineCounter]);
1163+ end ;
1164+
1165+ procedure ThDictionary_Add (const Params:PParamArray); cdecl;
1166+ var
1167+ Index:TThingsIndex;
1168+ counter:TPCounter;
1169+ begin
1170+ Index:=PThingsIndex(Params^[0 ])^;
1171+ if (Index.Things<>nil )and (Index.Index>=0 ) then begin
1172+ counter:=TPCounter(TThings(Index.Things)[Index.Index]);
1173+ counter.CountKey(PPointer(Params^[1 ])^);
1174+ end else
1175+ raise EScriptAV.CreateFmt(cEScriptAVmsg,[cThngNameThCombineCounter]);
1176+ end ;
1177+
1178+ procedure ThDictionary_Contains (const Params:PParamArray;const Result:Pointer); cdecl;
1179+ var
1180+ Index:TThingsIndex;
1181+ counter:TPCounter;
1182+ begin
1183+ Index:=PThingsIndex(Params^[0 ])^;
1184+ if (Index.Things<>nil )and (Index.Index>=0 ) then begin
1185+ counter:=TPCounter(TThings(Index.Things)[Index.Index]);
1186+ if counter.ContainsKey(PPointer(Params^[1 ])^) then
1187+ PBoolean(Result)^:=true
1188+ else
1189+ PBoolean(Result)^:=false;
1190+ end else
1191+ raise EScriptAV.CreateFmt(cEScriptAVmsg,[cThngNameThCombineCounter]);
1192+ end ;
1193+
11051194procedure ThCombineCounter_Free (const Params:PParamArray); cdecl;
11061195var
11071196 Index:TThingsIndex;
@@ -1149,11 +1238,6 @@ procedure ThCombineCounter_SetCombineVarNames(const Params: PParamArray); cdecl;
11491238
11501239procedure ThCombineCounter_SaveTo (const Params: PParamArray); cdecl;
11511240// procedure ThCombineCounter.SaveTo(AResult:TCounterResults);
1152- type
1153- TNames=array of string;
1154- TCounterResult=record names:Tnames;Key:string;Value :double;isInteger:boolean; end ;
1155- TCounterResults=array of TCounterResult;
1156- PCounterResults=^TCounterResults;
11571241var
11581242 Index:TThingsIndex;
11591243 cc:TCombineCounter;
@@ -1171,16 +1255,18 @@ TCounterResult=record names:Tnames;Key:string;Value:double;isInteger:boolean;
11711255 for pair in cc.Container do begin
11721256 with PCounterResults(Params^[1 ])^[i] do begin
11731257 names:=pair.Value .getNames;
1258+ TArrayHelper<string>.Sort(names);
11741259 pvd:=DWGDBUnit^.FindVariable(pair.Key);
11751260 if pvd=nil then
11761261 Key:=pair.Key
11771262 else
1178- Key:=PDbBaseObject(pvd^.data.Addr.Instance)^.Name ;
1263+ Key:=PDbBaseObject(pvd^.data.Addr.Instance)^.Name + ' ; ' +PDbBaseObject(pvd^.data.Addr.Instance)^.NameShort ;
11791264 Value :=pair.Value .Value ;
11801265 isInteger:=pair.Value .isInteger;
11811266 end ;
11821267 inc(i);
11831268 end ;
1269+ TArrayHelper<TCounterResult>.Sort(PCounterResults(Params^[1 ])^,TCounterResultComparer.Create);
11841270 end else
11851271 raise EScriptAV.CreateFmt(cEScriptAVmsg,[cThngNameThCombineCounter]);
11861272end ;
@@ -1196,13 +1282,19 @@ class procedure TLapeDwg.zcReport2cplr(const ACommandContext:TZCADCommandContext
11961282 cplr.addGlobalType(' array of string' ,' TNames' );
11971283 cplr.addGlobalType(' record names:Tnames;Key:string;Value:double;isInteger:boolean; end;' ,' TCounterResult' );
11981284 cplr.addGlobalType(' array of TCounterResult' ,' TCounterResults' );
1285+ cplr.addGlobalType(' type TThingsIndex' ,' ThDictionary' );
11991286
12001287 cplr.addGlobalMethod(' function ThCombineCounter.Create: ThCombineCounter; static;' ,@ThCombineCounter_Create,ctx);
12011288 cplr.addGlobalFunc(' procedure ThCombineCounter.Free;' ,@ThCombineCounter_Free);
12021289 cplr.addGlobalFunc(' procedure ThCombineCounter.SetCombineVarNames(AVarNames:array of String);' ,@ThCombineCounter_SetCombineVarNames);
12031290 cplr.addGlobalFunc(' procedure ThCombineCounter.CombineAndCount(AEnt:PzeEntity;AVarExtdr:TVariablesExtender;AName:PVarDesk;AKey:string);' ,@ThCombineCounter_CombineAndCount);
12041291 cplr.addGlobalFunc(' procedure ThCombineCounter.SaveTo(AResult:TCounterResults);' ,@ThCombineCounter_SaveTo);
12051292
1293+ cplr.addGlobalMethod(' function ThDictionary.Create: ThDictionary; static;' ,@ThDictionary_Create,ctx);
1294+ cplr.addGlobalFunc(' procedure ThDictionary.Free;' ,@ThDictionary_Free);
1295+ cplr.addGlobalFunc(' procedure ThDictionary.Add(P:Pointer);' ,@ThDictionary_Add);
1296+ cplr.addGlobalFunc(' function ThDictionary.Contains(P:Pointer):boolean;' ,@ThDictionary_Contains);
1297+
12061298
12071299 cplr.addGlobalMethod(' function ThisReport:PzeEntity;' ,@ThisReportOwner,ctx);
12081300 cplr.addGlobalMethod(' function ThisReportVariableExtdr:TVariablesExtender;' ,@ThisReportVariableExtdr,ctx);
@@ -1293,6 +1385,24 @@ procedure TVariablesExtender_GetVarTemplate(const Params: PParamArray;const Resu
12931385 raise EScriptAV.CreateFmt(cEScriptAVNil,[cNameTVariablesExtender]);
12941386end ;
12951387
1388+ procedure TVariablesExtender_GetMainFunction (const Params: PParamArray;const Result: Pointer); cdecl;
1389+ var
1390+ varsextdr:TVariablesExtender;
1391+ pvd:pvardesk;
1392+ pent:PGDBObjEntity;
1393+ begin
1394+ varsextdr:=TVariablesExtender((Params^[0 ])^);
1395+ if varsextdr<>nil then begin
1396+ pvd:=ppointer(Params^[1 ])^;
1397+ pent:=ppointer(Params^[2 ])^;
1398+ if varsextdr.pMainFuncEntity=nil then
1399+ ppointer(Result)^:=varsextdr
1400+ else
1401+ ppointer(Result)^:=varsextdr.pMainFuncEntity^.GetExtension<TVariablesExtender>;
1402+ end else
1403+ raise EScriptAV.CreateFmt(cEScriptAVNil,[cNameTVariablesExtender]);
1404+ end ;
1405+
12961406procedure TVariablesExtender_GetVarValue_double (const Params: PParamArray;const Result: Pointer); cdecl;
12971407var
12981408 vn:string;
@@ -1391,6 +1501,8 @@ class procedure TLapeDwg.zeEntsExtenders2cplr(const ACommandContext:TZCADCommand
13911501 cplr.addGlobalFunc(' function TVariablesExtender.GetVarDesk(VarName:string;InInterfaceOnly:boolean=false):PVarDesk;' ,@TVariablesExtender_GetVarDesk);
13921502 cplr.addGlobalFunc(' function TVariablesExtender.GetValueTemplate(PVD:PVarDesk;PEnt:PzeEntity):String;' ,@TVariablesExtender_GetVarTemplate);
13931503
1504+ cplr.addGlobalFunc(' function TVariablesExtender.GetMainFunction:TVariablesExtender;' ,@TVariablesExtender_GetMainFunction);
1505+
13941506 cplr.addGlobalFunc(' function PVarDesk.GetValueAsString:String;' ,@PVarDesk_GetValueAsString);
13951507
13961508 cplr.EndImporting;
0 commit comments