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 {$MODE OBJFPC}
19 unit uzccomdraw;
20 {$INCLUDE def.inc}
21 
22 interface
23 uses
24   gzctnrvector,uzglviewareageneral,zcobjectchangeundocommand2,zcmultiobjectchangeundocommand,
25   gzctnrvectortypes,zcmultiobjectcreateundocommand,uzeentitiesmanager,uzgldrawercanvas,
26   uzcoimultiobjects,uzcenitiesvariablesextender,uzcdrawing,uzepalette,
27   uzctextenteditor,uzgldrawcontext,usimplegenerics,UGDBPoint3DArray,
28   uzeentpoint,uzeentitiestree,gmap,gvector,garrayutils,gutil,UGDBSelectedObjArray,uzeentityfactory,
29   uzedrawingsimple,uzcsysvars,uzcstrconsts,uzccomdrawdase,
30   printers,graphics,uzeentdevice,uzeentwithlocalcs,
31   LazUTF8,Clipbrd,LCLType,classes,uzeenttext,uzeentabstracttext,uzestylestexts,
32   uzccommandsabstract,uzbstrproc,
33   uzbtypesbase,uzccommandsmanager,uzccombase,
34   uzccommandsimpl,
35   uzbtypes,
36   uzcdrawings,
37   uzeutils,uzcutils,
38   sysutils,
39   varmandef,
40   uzglviewareadata,
41   uzeffdxf,
42   uzcinterface,
43   uzegeometry,
44   uzbmemman,
45   uzeconsts,
46   uzccommand_move,uzccommand_copy,
47   uzbgeomtypes,uzeentity,uzeentcircle,uzeentline,uzeentgenericsubentry,uzeentmtext,
48   uzcshared,uzeentsubordinated,uzeentblockinsert,uzeentpolyline,uzclog,gzctnrvectordata,
49   math,uzeenttable,uzctnrvectorgdbstring,
50   uzeentcurve,uzeentlwpolyline,UBaseTypeDescriptor,uzeblockdef,Varman,URecordDescriptor,TypeDescriptors,UGDBVisibleTreeArray
51   ,uzelongprocesssupport,LazLogger;
52 const
53      modelspacename:GDBSTring='**Модель**';
54 type
55 {EXPORT+}
56          TEntityProcess=(
57                        TEP_Erase(*'Erase'*),
58                        TEP_leave(*'Leave'*)
59                        );
60 
61          TBlockInsert=packed record
62                             Blocks:TEnumData;(*'Block'*)
63                             Scale:GDBvertex;(*'Scale'*)
64                             Rotation:GDBDouble;(*'Rotation'*)
65                       end;
66          TSubPolyEdit=(
67                        TSPE_Insert(*'Insert vertex'*),
68                        TSPE_Remove(*'Remove vertex'*),
69                        TSPE_Scissor(*'Cut into two parts'*)
70                        );
71          TPolyEditMode=(
72                        TPEM_Nearest(*'Paste in nearest segment'*),
73                        TPEM_Select(*'Choose a segment'*)
74                        );
75          PTMirrorParam=^TMirrorParam;
76          TMirrorParam=packed record
77                             SourceEnts:TEntityProcess;(*'Source entities'*)
78                       end;
79 
80          TPolyEdit=packed record
81                             Action:TSubPolyEdit;(*'Action'*)
82                             Mode:TPolyEditMode;(*'Mode'*)
83                             vdist:gdbdouble;(*hidden_in_objinsp*)
84                             ldist:gdbdouble;(*hidden_in_objinsp*)
85                             nearestvertex:GDBInteger;(*hidden_in_objinsp*)
86                             nearestline:GDBInteger;(*hidden_in_objinsp*)
87                             dir:gdbinteger;(*hidden_in_objinsp*)
88                             setpoint:gdbboolean;(*hidden_in_objinsp*)
89                             vvertex:gdbvertex;(*hidden_in_objinsp*)
90                             lvertex1:gdbvertex;(*hidden_in_objinsp*)
91                             lvertex2:gdbvertex;(*hidden_in_objinsp*)
92                       end;
93          TIMode=(
94                  TIM_Text(*'Text'*),
95                  TIM_MText(*'MText'*)
96                 );
97          PTTextInsertParams=^TTextInsertParams;
98          TTextInsertParams=packed record
99                             mode:TIMode;(*'Entity'*)
100                             Style:TEnumData;(*'Style'*)
101                             justify:TTextJustify;(*'Justify'*)
102                             h:GDBDouble;(*'Height'*)
103                             WidthFactor:GDBDouble;(*'Width factor'*)
104                             Oblique:GDBDouble;(*'Oblique'*)
105                             Width:GDBDouble;(*'Width'*)
106                             LineSpace:GDBDouble;(*'Line space factor'*)
107                             text:GDBAnsiString;(*'Text'*)
108                             runtexteditor:GDBBoolean;(*'Run text editor'*)
109                       end;
110          BRMode=(
111                  BRM_Block(*'Block'*),
112                  BRM_Device(*'Device'*),
113                  BRM_BD(*'Block and Device'*)
114                 );
115          PTBlockReplaceParams=^TBlockReplaceParams;
116          TBlockReplaceParams=packed record
117                             Process:BRMode;(*'Process'*)
118                             CurrentFindBlock:GDBString;(*'**CurrentFind'*)(*oi_readonly*)(*hidden_in_objinsp*)
119                             Find:TEnumData;(*'Find'*)
120                             CurrentReplaceBlock:GDBString;(*'**CurrentReplace'*)(*oi_readonly*)(*hidden_in_objinsp*)
121                             Replace:TEnumData;(*'Replace'*)
122                             SaveOrientation:GDBBoolean;(*'Save orientation'*)
123                             SaveVariables:GDBBoolean;(*'Save variables'*)
124                             SaveVariablePart:GDBBoolean;(*'Save variable part'*)
125                             SaveVariableText:GDBBoolean;(*'Save variable text'*)
126                       end;
127          PTBlockScaleParams=^TBlockScaleParams;
128          TBlockScaleParams=packed record
129                              Scale:GDBVertex;(*'New scale'*)
130                              Absolytly:GDBBoolean;(*'Absolytly'*)
131                            end;
132          PTBlockRotateParams=^TBlockRotateParams;
133          TBlockRotateParams=packed record
134                              Rotate:GDBDouble;(*'Rotation angle'*)
135                              Absolytly:GDBBoolean;(*'Absolytly'*)
136                            end;
137          {TSetVarStyle=packed record
138                             ent:TMSType;(*'Entity'*)
139                             CurrentFindBlock:GDBString;(*'**CurrentFind'*)
140                              Scale:GDBVertex;(*'New scale'*)
141                              Absolytly:GDBBoolean;(*'Absolytly'*)
142                            end;}
143          TST=(
144                  TST_YX(*'Y-X'*),
145                  TST_XY(*'X-Y'*),
146                  TST_UNSORTED(*'Unsorted'*)
147                 );
148          PTNumberingParams=^TNumberingParams;
149          TNumberingParams=packed record
150                             SortMode:TST;(*''*)
151                             InverseX:GDBBoolean;(*'Inverse X axis dir'*)
152                             InverseY:GDBBoolean;(*'Inverse Y axis dir'*)
153                             DeadDand:GDBDouble;(*'Deadband'*)
154                             StartNumber:GDBInteger;(*'Start'*)
155                             Increment:GDBInteger;(*'Increment'*)
156                             SaveStart:GDBBoolean;(*'Save start number'*)
157                             BaseName:GDBString;(*'Base name sorting devices'*)
158                             NumberVar:GDBString;(*'Number variable'*)
159                       end;
160          PTExportDevWithAxisParams=^TExportDevWithAxisParams;
161          TExportDevWithAxisParams=packed record
162                             AxisDeviceName:GDBString;(*'AxisDeviceName'*)
163                       end;
164   PTBEditParam=^TBEditParam;
165   TBEditParam=packed record
166                     CurrentEditBlock:GDBString;(*'Current block'*)(*oi_readonly*)
167                     Blocks:TEnumData;(*'Select block'*)
168               end;
169   ptpcoavector=^tpcoavector;
170   tpcoavector={-}specialize{//}
171               GZVectorData{-}<TCopyObjectDesc>{//};
172   mirror_com = {$IFNDEF DELPHI}packed{$ENDIF} object(copy_com)
CalcTransformMatrixnull173     function CalcTransformMatrix(p1,p2: GDBvertex):DMatrix4D; virtual;
AfterClicknull174     function AfterClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger; virtual;
175   end;
176 
177   rotate_com = {$IFNDEF DELPHI}packed{$ENDIF} object(move_com)
AfterClicknull178     function AfterClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger; virtual;
179     procedure CommandContinue; virtual;
180     procedure rot(a:GDBDouble; button: GDBByte);
181     procedure showprompt(mklick:integer);virtual;
182   end;
183   scale_com = {$IFNDEF DELPHI}packed{$ENDIF} object(move_com)
AfterClicknull184     function AfterClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger; virtual;
185     procedure scale(a:GDBDouble; button: GDBByte);
186     procedure showprompt(mklick:integer);virtual;
187     procedure CommandContinue; virtual;
188   end;
189   copybase_com = {$IFNDEF DELPHI}packed{$ENDIF} object(CommandRTEdObject)
190     procedure CommandStart(Operands:TCommandOperands); virtual;
BeforeClicknull191     function BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger; virtual;
192   end;
193   FloatInsert_com = {$IFNDEF DELPHI}packed{$ENDIF} object(CommandRTEdObject)
194     procedure CommandStart(Operands:TCommandOperands); virtual;
195     procedure Build(Operands:TCommandOperands); virtual;
196     procedure Command(Operands:TCommandOperands); virtual;abstract;
DoEndnull197     function DoEnd(pdata:GDBPointer):GDBBoolean;virtual;
BeforeClicknull198     function BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger; virtual;
199   end;
200   TFIWPMode=(FIWPCustomize,FIWPRun);
201   FloatInsertWithParams_com = {$IFNDEF DELPHI}packed{$ENDIF} object(FloatInsert_com)
202     CMode:TFIWPMode;
203     procedure CommandStart(Operands:TCommandOperands); virtual;
204     procedure BuildDM(Operands:TCommandOperands); virtual;
205     procedure Run(pdata:GDBPlatformint); virtual;
MouseMoveCallbacknull206     function MouseMoveCallback(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger; virtual;
207     //procedure Command(Operands:pansichar); virtual;abstract;
BeforeClicknull208     //function BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; button: GDBByte;osp:pos_record): GDBInteger; virtual;
209   end;
210   PasteClip_com = {$IFNDEF DELPHI}packed{$ENDIF} object(FloatInsert_com)
211     procedure Command(Operands:TCommandOperands); virtual;
212   end;
213 
214   TextInsert_com={$IFNDEF DELPHI}packed{$ENDIF} object(FloatInsert_com)
215                        pt:PGDBObjText;
216                        //procedure Build(Operands:pansichar); virtual;
217                        procedure CommandStart(Operands:TCommandOperands); virtual;
218                        procedure CommandEnd; virtual;
219                        procedure Command(Operands:TCommandOperands); virtual;
220                        procedure BuildPrimitives; virtual;
221                        procedure Format;virtual;
DoEndnull222                        function DoEnd(pdata:GDBPointer):GDBBoolean;virtual;
223   end;
224 
225   BlockReplace_com={$IFNDEF DELPHI}packed{$ENDIF} object(CommandRTEdObject)
226                          procedure CommandStart(Operands:TCommandOperands); virtual;
227                          procedure BuildDM(Operands:TCommandOperands); virtual;
228                          procedure Format;virtual;
229                          procedure Run(pdata:{pointer}GDBPlatformint); virtual;
230                    end;
231   BlockScale_com={$IFNDEF DELPHI}packed{$ENDIF} object(CommandRTEdObject)
232                          procedure CommandStart(Operands:TCommandOperands); virtual;
233                          procedure BuildDM(Operands:TCommandOperands); virtual;
234                          procedure Run(pdata:{pointer}GDBPlatformint); virtual;
235                    end;
236   BlockRotate_com={$IFNDEF DELPHI}packed{$ENDIF} object(CommandRTEdObject)
237                          procedure CommandStart(Operands:TCommandOperands); virtual;
238                          procedure BuildDM(Operands:TCommandOperands); virtual;
239                          procedure Run(pdata:{pointer}GDBPlatformint); virtual;
240                    end;
241   ATO_com={$IFNDEF DELPHI}packed{$ENDIF} object(CommandRTEdObject)
242                          powner:PGDBObjDevice;
243                          procedure CommandStart(Operands:TCommandOperands); virtual;
244                          procedure ShowMenu;virtual;
245                          procedure Run(pdata:GDBPlatformint); virtual;
246           end;
247   CFO_com={$IFNDEF DELPHI}packed{$ENDIF} object(ATO_com)
248                          procedure ShowMenu;virtual;
249                          procedure Run(pdata:GDBPlatformint); virtual;
250           end;
251   Number_com={$IFNDEF DELPHI}packed{$ENDIF} object(CommandRTEdObject)
252                          procedure CommandStart(Operands:TCommandOperands); virtual;
253                          procedure ShowMenu;virtual;
254                          procedure Run(pdata:GDBPlatformint); virtual;
255              end;
256   ExportDevWithAxis_com={$IFNDEF DELPHI}packed{$ENDIF} object(CommandRTEdObject)
257                          procedure CommandStart(Operands:TCommandOperands); virtual;
258                          procedure ShowMenu;virtual;
259                          procedure Run(pdata:GDBPlatformint); virtual;
260              end;
261   ITT_com = {$IFNDEF DELPHI}packed{$ENDIF} object(FloatInsert_com)
262     procedure Command(Operands:TCommandOperands); virtual;
263   end;
264 {EXPORT-}
265 taxisdesc=record
266               p1,p2:GDBVertex;
267               d0:double;
268               Name:GDBString;
269         end;
270 tdevcoord=record
271               coord:GDBVertex;
272               pdev:PGDBObjDevice;
273         end;
274 tdevname=record
275               name:GDBString;
276               pdev:PGDBObjDevice;
277         end;
278 TGDBVertexLess=class
cnull279                     class function c(a,b:tdevcoord):boolean;{inline;}
280                end;
281 TGDBNameLess=class
cnull282                     class function c(a,b:tdevname):boolean;{inline;}
283              end;
284 TGDBtaxisdescLess=class
cnull285                     class function c(a,b:taxisdesc):boolean;{inline;}
286              end;
287 taxisdescarray=specialize TVector<taxisdesc>;
288 taxisdescdsort=specialize TOrderingArrayUtils<taxisdescarray, taxisdesc, TGDBtaxisdescLess>;
289 devcoordarray=specialize TVector<tdevcoord>;
290 devnamearray=specialize TVector<tdevname>;
291 PointOnCurve3DPropArray=specialize TVector<GDBDouble>;
292 LessDouble=specialize TLess<double>;
293 PointOnCurve3DPropArraySort=specialize TOrderingArrayUtils<PointOnCurve3DPropArray, GDBDouble,LessDouble>;
294 MapPointOnCurve3DPropArray=specialize TMap<PGDBObjLine,PointOnCurve3DPropArray, LessPointer>;
295 devcoordsort=specialize TOrderingArrayUtils<devcoordarray, tdevcoord, TGDBVertexLess>;
296 devnamesort=specialize TOrderingArrayUtils<devnamearray, tdevname, TGDBNameLess>;
297 var
298    MirrorParam:TMirrorParam;
299    PEProp:TPolyEdit;
300    pworkvertex:pgdbvertex;
301    BIProp:TBlockInsert;
302    pc:pgdbobjcircle;
303    pb:PGDBObjBlockInsert;
304    PCreatedGDBLine:pgdbobjline;
305    pold:PGDBObjEntity;
306    p3dpl:pgdbobjpolyline;
307    p3dplold:PGDBObjEntity;
308    mirror:mirror_com;
309    rotate:rotate_com;
310    scale:Scale_com;
311    copybase:copybase_com;
312    PasteClip:PasteClip_com;
313 
314    InsertTestTable:ITT_com;
315 
316    pbeditcom:pCommandRTEdObjectPlugin;
317    BEditParam:TBEditParam;
318 
319    TextInsert:TextInsert_com;
320    TextInsertParams:TTextInsertParams;
321    BlockReplace:BlockReplace_com;
322    BlockReplaceParams:TBlockReplaceParams;
323    ATO:ATO_com;
324    CFO:CFO_com;
325    NumberCom:Number_com;
326    ExportDevWithAxisCom:ExportDevWithAxis_com;
327    BlockScaleParams:TBlockScaleParams;
328    BlockScale:BlockScale_com;
329    BlockRotateParams:TBlockRotateParams;
330    BlockRotate:BlockRotate_com;
331 
332    NumberingParams:TNumberingParams;
333    ExportDevWithAxisParams:TExportDevWithAxisParams;
334 
335 //procedure startup;
336 //procedure Finalize;
Line_com_CommandStartnull337 function Line_com_CommandStart(operands:TCommandOperands):TCommandResult;
338 procedure Line_com_CommandEnd(_self:pointer);
Line_com_BeforeClicknull339 function Line_com_BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record;mclick:GDBInteger): GDBInteger;
Line_com_AfterClicknull340 function Line_com_AfterClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record;mclick:GDBInteger): GDBInteger;
341 implementation
GetBlockDefNamesnull342 function GetBlockDefNames(var BDefNames:TZctnrVectorGDBString;selname:GDBString):GDBInteger;
343 var pb:PGDBObjBlockdef;
344     ir:itrec;
345     i:gdbinteger;
346     s:gdbstring;
347 begin
348      result:=-1;
349      i:=0;
350      selname:=uppercase(selname);
351      pb:=drawings.GetCurrentDWG^.BlockDefArray.beginiterate(ir);
352      if pb<>nil then
353      repeat
354            if uppercase(pb^.name)=selname then
355                                               result:=i;
356            s:=Tria_AnsiToUtf8(pb^.name);
357            BDefNames.PushBackData(s);
358            pb:=drawings.GetCurrentDWG^.BlockDefArray.iterate(ir);
359            inc(i);
360      until pb=nil;
361 end;
GetSelectedBlockNamesnull362 function GetSelectedBlockNames(var BDefNames:TZctnrVectorGDBString;selname:GDBString;mode:BRMode):GDBInteger;
363 var pb:PGDBObjBlockInsert;
364     ir:itrec;
365     i:gdbinteger;
366     poa:PGDBObjEntityTreeArray;
367 begin
368      poa:=@drawings.GetCurrentROOT^.ObjArray;
369      result:=-1;
370      i:=0;
371      selname:=uppercase(selname);
372      pb:=poa^.beginiterate(ir);
373      if pb<>nil then
374      repeat
375            if pb^.Selected then
376            case mode of
377                        BRM_Block:begin
378                                       if pb^.GetObjType=GDBBlockInsertID then
379                                       begin
380                                            BDefNames.PushBackIfNotPresent(pb^.name);
381                                            inc(i);
382                                            if result=-1 then
383                                            if uppercase(pb^.name)=selname then
384                                                                               result:=BDefNames.Count-1;
385                                       end;
386                                  end;
387                        BRM_Device:begin
388                                       if pb^.GetObjType=GDBDeviceID then
389                                       begin
390                                            BDefNames.PushBackIfNotPresent(pb^.name);
391                                            inc(i);
392                                            if result=-1 then
393                                            if uppercase(pb^.name)=selname then
394                                                                               result:=BDefNames.Count-1;
395                                       end;
396                                  end;
397                        BRM_BD:begin
398                                       if (pb^.GetObjType=GDBBlockInsertID)or
399                                          (pb^.GetObjType=GDBDeviceID)then
400                                       begin
401                                            BDefNames.PushBackIfNotPresent(pb^.name);
402                                            inc(i);
403                                            if result=-1 then
404                                            if uppercase(pb^.name)=selname then
405                                                                               result:=BDefNames.Count-1;
406                                       end;
407 
408                                  end;
409            end;
410            pb:=poa^.iterate(ir);
411      until pb=nil;
412 end;
GetStyleNamesnull413 function GetStyleNames(var BDefNames:TZctnrVectorGDBString;selname:GDBString):GDBInteger;
414 var pb:PGDBTextStyle;
415     ir:itrec;
416     i:gdbinteger;
417 begin
418      result:=-1;
419      i:=0;
420      selname:=uppercase(selname);
421      pb:=drawings.GetCurrentDWG^.TextStyleTable.beginiterate(ir);
422      if pb<>nil then
423      repeat
424            if uppercase(pb^.name)=selname then
425                                               result:=i;
426 
427            BDefNames.PushBackData(pb^.name);
428            pb:=drawings.GetCurrentDWG^.TextStyleTable.iterate(ir);
429            inc(i);
430      until pb=nil;
431 end;
432 procedure FloatInsertWithParams_com.BuildDM(Operands:TCommandOperands);
433 begin
434 
435 end;
436 procedure FloatInsertWithParams_com.CommandStart(Operands:TCommandOperands);
437 begin
438      CommandRTEdObject.CommandStart(Operands);
439      CMode:=FIWPCustomize;
440      BuildDM(Operands);
441 end;
442 procedure FloatInsertWithParams_com.Run(pdata:GDBPlatformint);
443 begin
444      cmode:=FIWPRun;
445      self.Build('');
446 end;
FloatInsertWithParams_com.MouseMoveCallbacknull447 function FloatInsertWithParams_com.MouseMoveCallback(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger;
448 begin
449      if CMode=FIWPRun then
450                           inherited MouseMoveCallback(wc,mc,button,osp);
451      result:=cmd_ok;
452 end;
453 procedure FloatInsert_com.Build(Operands:TCommandOperands);
454 begin
455      Command(operands);
456      if drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.Count-drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.Deleted<=0
457      then
458          begin
459               commandmanager.executecommandend;
460          end
461 end;
462 {BlockScale_com=object(CommandRTEdObject)
463                        procedure CommandStart(Operands:pansichar); virtual;
464                        procedure BuildDM(Operands:pansichar); virtual;
465                        procedure Run(pdata:GDBPlatformint); virtual;
466                  end;}
467 procedure BlockRotate_com.CommandStart(Operands:TCommandOperands);
468 var //pb:PGDBObjBlockdef;
469     pobj:PGDBObjBlockInsert;
470     ir:itrec;
471     {i,}counter:integer;
472 begin
473      counter:=0;
474      savemousemode := drawings.GetCurrentDWG^.wa.param.md.mode;
475      saveosmode := sysvarDWGOSMode;
476 
477   pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
478   if pobj<>nil then
479   repeat
480     if pobj^.selected then
481     if (pobj^.GetObjType=GDBDeviceID)or(pobj^.GetObjType=GDBBlockInsertID) then
482     inc(counter);
483   pobj:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
484   until pobj=nil;
485   if counter=0 then
486                       begin
487                             Prompt(rscmNoBlocksOrDevices);
488                             commandmanager.executecommandend;
489                             exit;
490                       end;
491    BuildDM(Operands);
492           inherited;
493 end;
494 procedure BlockRotate_com.BuildDM(Operands:TCommandOperands);
495 begin
496   commandmanager.DMAddMethod(rscmChange,'Change rotate selected blocks',@run);
497   commandmanager.DMShow;
498 end;
499 procedure BlockRotate_com.Run(pdata:{pointer}GDBPlatformint);
500 var pb:PGDBObjBlockInsert;
501     ir:itrec;
502     {i,}result:gdbinteger;
503     poa:PGDBObjEntityTreeArray;
504     //selname,newname:GDBString;
505 begin
506      begin
507           poa:=@drawings.GetCurrentROOT^.ObjArray;
508 
509           result:=0;
510           //i:=0;
511           pb:=poa^.beginiterate(ir);
512           if pb<>nil then
513           repeat
514                 if (pb^.Selected)and((pb^.GetObjType=GDBDeviceID)or(pb^.GetObjType=GDBBlockInsertID)) then
515                 begin
516                 case BlockRotateParams.Absolytly of
517                             true:begin
518                                       pb^.rotate:=BlockRotateParams.Rotate;
519                                  end;
520                             false:begin
521                                        pb^.rotate:=BlockRotateParams.Rotate+pb^.rotate;
522                                   end;
523                 end;
524                 inc(result);
525                 end;
526                 pb:=poa^.iterate(ir);
527           until pb=nil;
528           Prompt(sysutils.format(rscmNEntitiesProcessed,[inttostr(result)]));
529           Regen_com(EmptyCommandOperands);
530           commandmanager.executecommandend;
531      end;
532 end;
533 
534 
535 procedure BlockScale_com.CommandStart(Operands:TCommandOperands);
536 var //pb:PGDBObjBlockdef;
537     pobj:PGDBObjBlockInsert;
538     ir:itrec;
539     {i,}counter:integer;
540 begin
541      counter:=0;
542      savemousemode := drawings.GetCurrentDWG^.wa.param.md.mode;
543      saveosmode := sysvarDWGOSMode;
544 
545   pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
546   if pobj<>nil then
547   repeat
548     if pobj^.selected then
549     if (pobj^.GetObjType=GDBDeviceID)or(pobj^.GetObjType=GDBBlockInsertID) then
550     inc(counter);
551   pobj:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
552   until pobj=nil;
553   if counter=0 then
554                       begin
555                             Prompt(rscmNoBlocksOrDevices);
556                             commandmanager.executecommandend;
557                             exit;
558                       end;
559    BuildDM(Operands);
560           inherited;
561 end;
562 procedure BlockScale_com.BuildDM(Operands:TCommandOperands);
563 begin
564   commandmanager.DMAddMethod(rscmChange,'Change scale selected blocks',@run);
565   commandmanager.DMShow;
566 end;
567 
568 
569 procedure BlockScale_com.Run(pdata:{pointer}GDBPlatformint);
570 var pb:PGDBObjBlockInsert;
571     ir:itrec;
572     {i,}result:gdbinteger;
573     poa:PGDBObjEntityTreeArray;
574     //selname,newname:GDBString;
575 begin
576      begin
577           poa:=@drawings.GetCurrentROOT^.ObjArray;
578 
579           result:=0;
580           //i:=0;
581           pb:=poa^.beginiterate(ir);
582           if pb<>nil then
583           repeat
584                 if (pb^.Selected)and((pb^.GetObjType=GDBDeviceID)or(pb^.GetObjType=GDBBlockInsertID)) then
585                 begin
586                 case BlockScaleParams.Absolytly of
587                             true:begin
588                                       pb^.scale:=BlockScaleParams.Scale;
589                                  end;
590                             false:begin
591                                        pb^.scale.x:=pb^.scale.x*BlockScaleParams.Scale.x;
592                                        pb^.scale.y:=pb^.scale.y*BlockScaleParams.Scale.y;
593                                        pb^.scale.z:=pb^.scale.z*BlockScaleParams.Scale.z;
594 
595                                       end;
596                 end;
597                 inc(result);
598                 end;
599                 pb:=poa^.iterate(ir);
600           until pb=nil;
601           Prompt(sysutils.format(rscmNEntitiesProcessed,[inttostr(result)]));
602           Regen_com(EmptyCommandOperands);
603           commandmanager.executecommandend;
604      end;
605 end;
606 
607 
608 
609 procedure BlockReplace_com.CommandStart(Operands:TCommandOperands);
610 var //pb:PGDBObjBlockdef;
611     //ir:itrec;
612     i:integer;
613 begin
614      BlockReplaceParams.Replace.Enums.free;
615      i:=GetBlockDefNames(BlockReplaceParams.Replace.Enums,BlockReplaceParams.CurrentReplaceBlock);
616      if BlockReplaceParams.Replace.Enums.Count>0 then
617      begin
618           if i>0 then
619                      BlockReplaceParams.Replace.Selected:=i
620                  else
621                      if length(operands)<>0 then
622                                          begin
623                                                Prompt(rscmNoBlockDefInDWG);
624                                                commandmanager.executecommandend;
625                                                exit;
626                                          end;
627           format;
628 
629           BuildDM(Operands);
630           inherited;
631      end
632         else
633             begin
634                  Prompt(rscmInDwgBlockDefNotDeffined);
635                  commandmanager.executecommandend;
636             end;
637 end;
638 procedure BlockReplace_com.BuildDM(Operands:TCommandOperands);
639 begin
640   commandmanager.DMAddMethod(rscmReplace,'Replace blocks',@run);
641   commandmanager.DMShow;
642 end;
643 procedure BlockReplace_com.Run(pdata:GDBPlatformint);
644 var pb:PGDBObjBlockInsert;
645     ir:itrec;
646     {i,}result:gdbinteger;
647     poa:PGDBObjEntityTreeArray;
648     selname,newname:GDBString;
649     DC:TDrawContext;
650     psdesc:pselectedobjdesc;
651 procedure rb(pb:PGDBObjBlockInsert);
652 var
653     nb,tb:PGDBObjBlockInsert;
654     psubobj:PGDBObjEntity;
655     ir:itrec;
656     pnbvarext,ppbvarext:PTVariablesExtender;
657 begin
658 
659     nb := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateObj(GDBBlockInsertID));
660     PGDBObjBlockInsert(nb)^.init(drawings.GetCurrentROOT,drawings.GetCurrentDWG^.LayerTable.GetSystemLayer,0);
661     nb^.Name:=newname;
662     nb^.vp:=pb^.vp;
663     nb^.Local.p_insert:=pb^.Local.P_insert;
664     if BlockReplaceParams.SaveOrientation then begin
665       nb^.scale:=pb^.Scale;
666       nb^.rotate:=pb^.rotate;
667     end;
668     tb:=pointer(nb^.FromDXFPostProcessBeforeAdd(nil,drawings.GetCurrentDWG^));
669     if tb<>nil then begin
670                          tb^.bp:=nb^.bp;
671                          nb^.done;
672                          gdbfreemem(pointer(nb));
673                          nb:=pointer(tb);
674     end;
675     drawings.GetCurrentROOT^.AddObjectToObjArray(addr(nb));
676     PGDBObjEntity(nb)^.FromDXFPostProcessAfterAdd;
677 
678     nb^.CalcObjMatrix;
679     nb^.BuildGeometry(drawings.GetCurrentDWG^);
680     if not BlockReplaceParams.SaveVariablePart then
681       nb^.BuildVarGeometry(drawings.GetCurrentDWG^);
682 
683     if BlockReplaceParams.SaveVariables then begin
684          pnbvarext:=nb^.GetExtension(typeof(TVariablesExtender));
685          ppbvarext:=pb^.GetExtension(typeof(TVariablesExtender));
686          pnbvarext^.entityunit.free;
687          pnbvarext^.entityunit.CopyFrom(@ppbvarext^.entityunit);
688     end;
689 
690     if pb^.GetObjType=GDBDeviceID then begin
691       if BlockReplaceParams.SaveVariablePart then begin
692            PGDBObjDevice(nb)^.VarObjArray.free;
693            PGDBObjDevice(pb)^.VarObjArray.CloneEntityTo(@PGDBObjDevice(nb)^.VarObjArray,nil);
694            PGDBObjDevice(nb)^.correctobjects(pointer(PGDBObjDevice(nb)^.bp.ListPos.Owner),PGDBObjDevice(nb)^.bp.ListPos.SelfIndex);
695       end
696  else if BlockReplaceParams.SaveVariableText then begin
697            psubobj:=PGDBObjDevice(nb)^.VarObjArray.beginiterate(ir);
698            if psubobj<>nil then
699            repeat
700                  if (psubobj^.GetObjType=GDBtextID)or(psubobj^.GetObjType=GDBMTextID) then
701                    psubobj^.YouDeleted(drawings.GetCurrentDWG^);
702                  psubobj:=PGDBObjDevice(nb)^.VarObjArray.iterate(ir);
703            until psubobj=nil;
704 
705            psubobj:=PGDBObjDevice(pb)^.VarObjArray.beginiterate(ir);
706            if psubobj<>nil then
707            repeat
708                  if (psubobj^.GetObjType=GDBtextID)or(psubobj^.GetObjType=GDBMTextID) then
709                    PGDBObjDevice(nb)^.VarObjArray.AddPEntity(psubobj^.Clone(nil)^);
710                  psubobj:=PGDBObjDevice(pb)^.VarObjArray.iterate(ir);
711            until psubobj=nil;
712 
713            PGDBObjDevice(nb)^.correctobjects(pointer(PGDBObjDevice(nb)^.bp.ListPos.Owner),PGDBObjDevice(nb)^.bp.ListPos.SelfIndex);
714       end
715     end;
716 
717     nb^.Formatentity(drawings.GetCurrentDWG^,dc);
718     drawings.GetCurrentROOT^.ObjArray.ObjTree.CorrectNodeBoundingBox(nb^);
719     nb^.Visible:=0;
720     drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.Count := 0;
721     nb^.RenderFeedback(drawings.GetCurrentDWG^.pcamera^.POSCOUNT,drawings.GetCurrentDWG^.pcamera^,@drawings.GetCurrentDWG^.myGluProject2,dc);
722 
723 
724      pb^.YouDeleted(drawings.GetCurrentDWG^);
725      inc(result);
726 end;
727 
728 begin
729      if BlockReplaceParams.Find.Enums.Count=0 then
730                                                   Error(rscmCantGetBlockToReplace)
731                                               else
732      begin
733           dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
734           poa:=@drawings.GetCurrentROOT^.ObjArray;
735           result:=0;
736           //i:=0;
737           newname:=Tria_Utf8ToAnsi(GDBEnumDataDescriptorObj.GetValueAsString(@BlockReplaceParams.Replace));
738           selname:=Tria_Utf8ToAnsi(GDBEnumDataDescriptorObj.GetValueAsString(@BlockReplaceParams.Find));
739           selname:=uppercase(selname);
740           pb:=poa^.beginiterate(ir);
741           psdesc:=drawings.GetCurrentDWG^.SelObjArray.beginiterate(ir);
742           if psdesc<>nil then
743           repeat
744                 pb:=pointer(psdesc^.objaddr);
745                 if pb<>nil then
746                 if pb^.Selected then
747                 case BlockReplaceParams.Process of
748                             BRM_Block:begin
749                                            if pb^.GetObjType=GDBBlockInsertID then
750                                            if uppercase(pb^.name)=selname then
751                                            begin
752                                                 rb(pb);
753                                            end;
754                                       end;
755                             BRM_Device:begin
756                                            if pb^.GetObjType=GDBDeviceID then
757                                            if uppercase(pb^.name)=selname then
758                                            begin
759                                                 rb(pb);
760                                            end;
761                                        end;
762                             BRM_BD:begin
763                                            if (pb^.GetObjType=GDBBlockInsertID)or
764                                               (pb^.GetObjType=GDBDeviceID)then
765                                            if uppercase(pb^.name)=selname then
766                                            begin
767                                                 rb(pb);
768                                            end;
769                                    end;
770                 end;
771                 psdesc:=drawings.GetCurrentDWG^.SelObjArray.iterate(ir);
772           until psdesc=nil;
773           Prompt(sysutils.format(rscmNEntitiesProcessed,[inttostr(result)]));
774           Regen_com(EmptyCommandOperands);
775           commandmanager.executecommandend;
776      end;
777 end;
778 procedure BlockReplace_com.Format;
779 var //pb:PGDBObjBlockdef;
780     //ir:itrec;
781     i:integer;
782 begin
783      BlockReplaceParams.CurrentFindBlock:=GDBEnumDataDescriptorObj.GetValueAsString(@BlockReplaceParams.Find);
784      BlockReplaceParams.CurrentReplaceBlock:=GDBEnumDataDescriptorObj.GetValueAsString(@BlockReplaceParams.Replace);
785      BlockReplaceParams.Find.Enums.free;
786      BlockReplaceParams.Find.Selected:=GetSelectedBlockNames(BlockReplaceParams.Find.Enums,BlockReplaceParams.CurrentFindBlock,BlockReplaceParams.Process);
787      if BlockReplaceParams.Find.Selected<0 then
788                                                begin
789                                                          BlockReplaceParams.Find.Selected:=0;
790                                                          BlockReplaceParams.CurrentFindBlock:='';
791                                                end ;
792      BlockReplaceParams.CurrentFindBlock:=GDBEnumDataDescriptorObj.GetValueAsString(@BlockReplaceParams.Find);
793      BlockReplaceParams.Replace.Enums.free;
794      i:=GetBlockDefNames(BlockReplaceParams.Replace.Enums,DevicePrefix+BlockReplaceParams.CurrentFindBlock);
795      if BlockReplaceParams.Replace.Enums.Count>0 then
796      begin
797           if i>0 then
798                      BlockReplaceParams.Replace.Selected:=i
799                  else
800      end;
801 
802      if BlockReplaceParams.Find.Enums.Count=0 then
803                                                        PRecordDescriptor(commanddata.PTD)^.SetAttrib('Find',FA_READONLY,0)
804                                                    else
805                                                        PRecordDescriptor(commanddata.PTD)^.SetAttrib('Find',0,FA_READONLY);
806 end;
807 procedure CFO_com.ShowMenu;
808 begin
809   commandmanager.DMAddMethod(rscmCopy,'Copy entities to selected devices',@run);
810   commandmanager.DMShow;
811 end;
812 procedure CFO_com.Run(pdata:GDBPlatformint);
813 var
814    pobj{,pvisible}: pGDBObjDevice;
815    psubobj:PGDBObjEntity;
816    ir,ir2:itrec;
817    //tp:gdbpointer;
818    m,m2:DMatrix4D;
819    DC:TDrawContext;
820 begin
821      m:=powner^.objmatrix;
822      m2:=m;
823      matrixinvert(m);
824      dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
825      pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
826      if pobj<>nil then
827      repeat
828            if pobj^.Selected then
829            if pobj<>pointer(powner) then
830            if pobj^.GetObjType=GDBDeviceID then
831            begin
832                 psubobj:=pobj^.VarObjArray.beginiterate(ir2);
833                 if psubobj<>nil then
834                 repeat
835                       psubobj^.YouDeleted(drawings.GetCurrentDWG^);
836                       psubobj:=pobj^.VarObjArray.iterate(ir2);
837                 until psubobj=nil;
838 
839                 powner^.VarObjArray.cloneentityto(@pobj^.VarObjArray,psubobj);
840                 pobj^.correctobjects(pointer(pobj^.bp.ListPos.Owner),pobj^.bp.ListPos.SelfIndex);
841                 pobj^.FormatEntity(drawings.GetCurrentDWG^,dc);
842 
843                 //pobj^.VarObjArray.free;
844            {powner^.objmatrix:=onematrix;
845            pvisible:=pobj^.Clone(@powner^);
846                     if pvisible^.IsHaveLCS then
847                                pvisible^.Format;
848            pvisible^.transform(m);
849            powner^.objmatrix:=m2;
850            pvisible^.format;
851            pvisible.BuildGeometry;
852            powner^.VarObjArray.add(@pvisible);
853            pobj^.YouDeleted;}
854            end;
855            pobj:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
856      until pobj=nil;
857      powner^.Formatentity(drawings.GetCurrentDWG^,dc);
858      powner^.objmatrix:=m2;
859      powner:=nil;
860      Commandmanager.executecommandend;
861 end;
862 procedure ExportDevWithAxis_com.CommandStart(Operands:TCommandOperands);
863 begin
864   self.savemousemode:=drawings.GetCurrentDWG^.wa.param.md.mode;
865   if drawings.GetCurrentDWG^.SelObjArray.Count>0 then
866   begin
867        showmenu;
868        inherited CommandStart('');
869   end
870   else
871   begin
872     ZCMsgCallBackInterface.TextMessage(rscmSelEntBeforeComm,TMWOHistoryOut);
873     Commandmanager.executecommandend;
874   end;
875 end;
876 procedure ExportDevWithAxis_com.ShowMenu;
877 begin
878   commandmanager.DMAddMethod(rscmExport,'Export selected devices with axis',@run);
879   commandmanager.DMShow;
880 end;
881 procedure GetNearestAxis(axisarray:taxisdescarray;coord:gdbvertex;out nearestaxis,secondaxis:integer);
882 var
883    i:integer;
884    nearestd,{nearestd0,}secondd{,secondd0}:double;
885    tp1,tp2:gdbvertex;
886    dit,pdit:DistAndt;
887    Vertex0:GDBVertex;
888 begin
889   nearestaxis:=-1;
890   secondaxis:=-1;
891   nearestd:=Infinity;
892   secondd:=Infinity;
893   //nearestd0:=infinity;
894   //secondd0:=infinity;
895   Vertex0:=drawings.GetCurrentROOT^.vp.BoundingBox.LBN;
896   for i:=0 to axisarray.size-1 do
897   begin
898        tp1:=axisarray[i].p1;
899        tp2:=axisarray[i].p2;
900        pdit:=distance2ray(Vertex0,coord,vertexadd(coord,vertexsub(tp2,tp1)));
901        dit:=distance2ray(coord,tp1,tp2);
902        if (dit.t>=0)and(dit.t<=1)then
903        begin
904        if (dit.d<nearestd)and(axisarray[i].d0<=(pdit.d+eps)) then
905                          begin
906                               nearestaxis:=i;
907                               nearestd:=dit.d;
908                               //nearestd0:=axisarray[nearestaxis].d0;
909                               if abs(dit.d)<bigeps then
910                                                     begin
911                                                          secondaxis:=-1;
912                                                          exit;
913                                                     end;
914                          end;
915   if (dit.d<secondd)and(axisarray[i].d0>=(pdit.d-eps)) then
916                          begin
917                               secondaxis:=i;
918                               secondd:=dit.d;
919                               //secondd0:=axisarray[i].d0;
920                               if abs(dit.d)<bigeps then
921                                                     begin
922                                                          nearestaxis:=-1;
923                                                          exit;
924                                                     end;
925                          end
926        end;
927   end;
928 end;
GetAxisNamenull929 function GetAxisName(axisarray:taxisdescarray;hi,hi2:integer):gdbstring;
930 var
931    ti:integer;
932 begin
933       if hi>hi2 then
934                   begin
935                        ti:=hi2;
936                        hi2:=hi;
937                        hi:=ti;
938                   end;
939       if hi>=0 then
940                   result:=sysutils.format('%s-%s',[axisarray[hi].Name,axisarray[hi2].Name])
941  else if hi2>=0 then
942                   result:=axisarray[hi2].Name
943  else
944       result:='';
945 end;
946 
947 procedure ExportDevWithAxis_com.Run(pdata:GDBPlatformint);
948 var
949    haxis,vaxis:taxisdescarray;
950    pdev:PGDBObjDevice;
951    paxisline:PGDBObjLine;
952    ir,ir2:itrec;
953    axisdevname:GDBString;
954    ALLayer:pointer;
955    pdevvarext:PTVariablesExtender;
956    pvd,pvdv:pvardesk;
957    dv:gdbvertex;
958    axisdesc:taxisdesc;
959    psd:PSelectedObjDesc;
960    hi,hi2,vi,vi2,{ti,}i:integer;
961    hname,vname:gdbstring;
962    dit:DistAndt;
963    Vertex0:GDBVertex;
964    isAxisVerical:TGDB3StateBool;
965    isVertical:boolean;
966 begin
967   haxis:=taxisdescarray.Create;
968   vaxis:=taxisdescarray.Create;
969   axisdevname:=uppercase(ExportDevWithAxisParams.AxisDeviceName);
970   ALLayer:=drawings.GetCurrentDWG^.LayerTable.getAddres('EL_AXIS');
971   Vertex0:=drawings.GetCurrentROOT^.vp.BoundingBox.LBN;
972   ZCMsgCallBackInterface.TextMessage('Searh axis.....',TMWOHistoryOut);
973   pdev:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
974   if pdev<>nil then
975   repeat
976         if pdev^.GetObjType=GDBDeviceID then
977         if uppercase(pdev^.Name)=axisdevname then
978         begin
979              paxisline:=pdev^.VarObjArray.beginiterate(ir2);
980              if paxisline<>nil then
981              repeat
982                    if paxisline^.GetObjType=GDBLineID then
983                    if paxisline^.vp.Layer=ALLayer then
984                                                       system.break;
985              paxisline:=pdev^.VarObjArray.iterate(ir2);
986              until paxisline=nil;
987 
988              pvd:=nil;
989              pvdv:=nil;
990              pdevvarext:=pdev^.GetExtension(typeof(TVariablesExtender));
991              if pdevvarext<>nil then
992              begin
993                pvd:=pdevvarext^.entityunit.FindVariable('NMO_Name');
994                pvdv:=pdevvarext^.entityunit.FindVariable('MISC_Vertical');
995              end;
996              if pvdv<>nil then
997                               isAxisVerical:=PTGDB3StateBool(pvdv^.data.Instance)^
998                           else
999                               isAxisVerical:=T3SB_Default;
1000              if (paxisline<>nil)and(pvd<>nil) then
1001              begin
1002                   axisdesc.Name:=pgdbstring(pvd^.data.Instance)^;
1003                   axisdesc.p1:=paxisline^.CoordInWCS.lBegin;
1004                   axisdesc.p2:=paxisline^.CoordInWCS.lEnd;
1005                   dit:=distance2ray(Vertex0,axisdesc.p1,axisdesc.p2);
1006                   axisdesc.d0:=dit.d;
1007                   case isAxisVerical of
1008                              T3SB_Fale:isVertical:=false;
1009                              T3SB_True:isVertical:=true;
1010                           T3SB_Default:begin
1011                                          dv:=uzegeometry.VertexSub(paxisline^.CoordInWCS.lEnd,paxisline^.CoordInWCS.lBegin);
1012                                          isVertical:=abs(dv.x)<abs(dv.y);
1013                                        end;
1014                   end;
1015                   if isVertical then
1016                                     begin
1017                                       ZCMsgCallBackInterface.TextMessage(sysutils.format('  Found vertical axis "%s"',[pgdbstring(pvd^.data.Instance)^]),TMWOHistoryOut);
1018                                       vaxis.PushBack(axisdesc);
1019                                     end
1020                                 else
1021                                     begin
1022                                       ZCMsgCallBackInterface.TextMessage(sysutils.format('  Found horisontal axis "%s"',[pgdbstring(pvd^.data.Instance)^]),TMWOHistoryOut);
1023                                       haxis.PushBack(axisdesc);
1024                                     end
1025 
1026              end
1027         end;
1028   pdev:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
1029   until pdev=nil;
1030   if haxis.size>0 then
1031   begin
1032     ZCMsgCallBackInterface.TextMessage('Sorting horisontal axis...',TMWOHistoryOut);
1033     taxisdescdsort.Sort(haxis,haxis.size);
1034     for i:=0 to haxis.size-1 do
1035     ZCMsgCallBackInterface.TextMessage(sysutils.format('  Horisontal axis "%s", d0=%f',[haxis[i].Name,haxis[i].d0]),TMWOHistoryOut);
1036   end;
1037   if vaxis.size>0 then
1038   begin
1039     ZCMsgCallBackInterface.TextMessage('Sorting vertical axis...',TMWOHistoryOut);
1040     taxisdescdsort.Sort(vaxis,vaxis.size);
1041     for i:=0 to vaxis.size-1 do
1042     ZCMsgCallBackInterface.TextMessage(sysutils.format('  Vertical axis "%s", d0=%f',[vaxis[i].Name,vaxis[i].d0]),TMWOHistoryOut);
1043   end;
1044   psd:=drawings.GetCurrentDWG^.SelObjArray.beginiterate(ir);
1045   if psd<>nil then
1046   repeat
1047         if psd^.objaddr<>nil then
1048         begin
1049           pdev:=pointer(psd^.objaddr);
1050           if pdev^.GetObjType=GDBDeviceID then
1051           if uppercase(pdev^.Name)<>axisdevname then
1052           begin
1053              pvd:=nil;
1054              pdevvarext:=pdev^.GetExtension(typeof(TVariablesExtender));
1055              if pdevvarext<>nil then
1056              pvd:=pdevvarext^.entityunit.FindVariable('NMO_Name');
1057              if pvd<>nil then
1058              begin
1059                   GetNearestAxis(haxis,pdev^.P_insert_in_WCS,hi,hi2);
1060                   hname:=GetAxisName(haxis,hi,hi2);
1061                   GetNearestAxis(vaxis,pdev^.P_insert_in_WCS,vi,vi2);
1062                   vname:=GetAxisName(vaxis,vi,vi2);
1063                   if (hname<>'')and(vname<>'')then
1064                                           ZCMsgCallBackInterface.TextMessage(sysutils.format('%s;%s/%s',[pgdbstring(pvd^.data.Instance)^,vname,hname]),TMWOHistoryOut)
1065              else if (hname<>'')then
1066                                 ZCMsgCallBackInterface.TextMessage(sysutils.format('%s;%s',[pgdbstring(pvd^.data.Instance)^,hname]),TMWOHistoryOut)
1067              else if (vname<>'')then
1068                                 ZCMsgCallBackInterface.TextMessage(sysutils.format('%s;%s',[pgdbstring(pvd^.data.Instance)^,vname]),TMWOHistoryOut);
1069 
1070              end;
1071 
1072           end;
1073         end;
1074   psd:=drawings.GetCurrentDWG^.SelObjArray.iterate(ir);
1075   until psd=nil;
1076 end;
1077 procedure Number_com.CommandStart(Operands:TCommandOperands);
1078 begin
1079   self.savemousemode:=drawings.GetCurrentDWG^.wa.param.md.mode;
1080   if drawings.GetCurrentDWG^.SelObjArray.Count>0 then
1081   begin
1082        showmenu;
1083        inherited CommandStart('');
1084   end
1085   else
1086   begin
1087     ZCMsgCallBackInterface.TextMessage(rscmSelEntBeforeComm,TMWOHistoryOut);
1088     Commandmanager.executecommandend;
1089   end;
1090 end;
1091 procedure Number_com.ShowMenu;
1092 begin
1093   commandmanager.DMAddMethod(rscmNumber,'Number selected devices',@run);
1094   commandmanager.DMShow;
1095 end;
TGDBNameLess.cnull1096 class function TGDBNameLess.c(a,b:tdevname):boolean;
1097 begin
1098      if {a.name<b.name}AnsiNaturalCompare(a.name,b.name)>0 then
1099                           result:=false
1100                       else
1101                           result:=true;
1102 end;
TGDBtaxisdescLess.cnull1103 class function TGDBtaxisdescLess.c(a,b:taxisdesc):boolean;
1104 begin
1105      if a.d0<b.d0 then
1106                           result:=true
1107                       else
1108                           result:=false;
1109 end;
TGDBVertexLess.cnull1110 class function TGDBVertexLess.c(a,b:tdevcoord):boolean;
1111 begin
1112      //if a.coord.y<b.coord.y then
1113      if a.coord.y<b.coord.y-NumberingParams.DeadDand then
1114                     result:=true
1115                 else
1116                     if  {a.coord.y>b.coord.y}abs(a.coord.y-b.coord.y)>{eps}NumberingParams.DeadDand then
1117                                    begin
1118                                    result:=false;
1119                                    end
1120                 else
1121                     if a.coord.x<b.coord.x-NumberingParams.DeadDand then
1122                                    result:=true
1123                 else
1124                     begin
1125                     result:=false;
1126                     end;
1127 end;
1128 procedure Number_com.Run(pdata:GDBPlatformint);
1129 var
1130     psd:PSelectedObjDesc;
1131     ir:itrec;
1132     mpd:devcoordarray;
1133     pdev:PGDBObjDevice;
1134     //key:GDBVertex;
1135     index:integer;
1136     pvd:pvardesk;
1137     dcoord:tdevcoord;
1138     i,count:integer;
1139     process:boolean;
1140     DC:TDrawContext;
1141     pdevvarext:PTVariablesExtender;
1142 begin
1143      mpd:=devcoordarray.Create;
1144      psd:=drawings.GetCurrentDWG^.SelObjArray.beginiterate(ir);
1145      count:=0;
1146      dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1147      if psd<>nil then
1148      repeat
1149            if psd^.objaddr^.GetObjType=GDBDeviceID then
1150            begin
1151                 case NumberingParams.SortMode of
1152                                                 TST_YX,TST_UNSORTED:
1153                                                        begin
1154                                                        dcoord.coord:=PGDBObjDevice(psd^.objaddr)^.P_insert_in_WCS;
1155                                                        if NumberingParams.InverseX then
1156                                                                                        dcoord.coord.x:=-dcoord.coord.x;
1157                                                        if NumberingParams.InverseY then
1158                                                                                        dcoord.coord.y:=-dcoord.coord.y;
1159                                                        end;
1160                                                 TST_XY:
1161                                                        begin
1162                                                             dcoord.coord.x:=PGDBObjDevice(psd^.objaddr)^.P_insert_in_WCS.y;
1163                                                             dcoord.coord.y:=PGDBObjDevice(psd^.objaddr)^.P_insert_in_WCS.x;
1164                                                             dcoord.coord.z:=PGDBObjDevice(psd^.objaddr)^.P_insert_in_WCS.z;
1165                                                             if NumberingParams.InverseX then
1166                                                                                             dcoord.coord.y:=-dcoord.coord.y;
1167                                                             if NumberingParams.InverseY then
1168                                                                                             dcoord.coord.x:=-dcoord.coord.x;
1169                                                        end;
1170                                                end;{case}
1171                 dcoord.pdev:=pointer(psd^.objaddr);
1172                 inc(count);
1173                 mpd.PushBack(dcoord);
1174            end;
1175      psd:=drawings.GetCurrentDWG^.SelObjArray.iterate(ir);
1176      until psd=nil;
1177      if count=0 then
1178                     begin
1179                          ZCMsgCallBackInterface.TextMessage('In selection not found devices',TMWOHistoryOut);
1180                          mpd.Destroy;
1181                          Commandmanager.executecommandend;
1182                          exit;
1183                     end;
1184      index:=NumberingParams.StartNumber;
1185      if NumberingParams.SortMode<>TST_UNSORTED then
1186                                                    devcoordsort.Sort(mpd,mpd.Size);
1187      count:=0;
1188      for i:=0 to mpd.Size-1 do
1189        begin
1190             dcoord:=mpd[i];
1191             pdev:=dcoord.pdev;
1192             pdevvarext:=pdev^.GetExtension(typeof(TVariablesExtender));
1193 
1194             if NumberingParams.BaseName<>'' then
1195             begin
1196             //pvd:=PTObjectUnit(pdev^.ou.Instance)^.FindVariable('NMO_BaseName');
1197             pvd:=pdevvarext^.entityunit.FindVariable('NMO_BaseName');
1198             if pvd<>nil then
1199             begin
1200             if uppercase(pvd^.data.PTD^.GetUserValueAsString(pvd^.data.Instance))=
1201                uppercase(NumberingParams.BaseName) then
1202                                                        process:=true
1203                                                    else
1204                                                        process:=false;
1205             end
1206                else
1207                    begin
1208                         process:=true;
1209                         ZCMsgCallBackInterface.TextMessage('In device not found BaseName variable. Processed',TMWOHistoryOut);
1210                    end;
1211             end
1212                else
1213                    process:=true;
1214             if process then
1215             begin
1216             //pvd:=PTObjectUnit(pdev^.ou.Instance)^.FindVariable(NumberingParams.NumberVar);
1217             pvd:=pdevvarext^.entityunit.FindVariable(NumberingParams.NumberVar);
1218             if pvd<>nil then
1219             begin
1220                  pvd^.data.PTD^.SetValueFromString(pvd^.data.Instance,inttostr(index));
1221                  inc(index,NumberingParams.Increment);
1222                  inc(count);
1223                  pdev^.FormatEntity(drawings.GetCurrentDWG^,dc);
1224             end
1225                else
1226                ZCMsgCallBackInterface.TextMessage('In device not found numbering variable',TMWOHistoryOut);
1227             end
1228             else
1229                 ZCMsgCallBackInterface.TextMessage('Device with basename "'+pvd^.data.PTD^.GetUserValueAsString(pvd^.data.Instance)+'" filtred out',TMWOHistoryOut);
1230        end;
1231      ZCMsgCallBackInterface.TextMessage(sysutils.format(rscmNEntitiesProcessed,[inttostr(count)]),TMWOHistoryOut);
1232      if NumberingParams.SaveStart then
1233                                       NumberingParams.StartNumber:=index;
1234      mpd.Destroy;
1235      Commandmanager.executecommandend;
1236 end;
1237 
1238 
1239 
1240 
1241 procedure ATO_com.ShowMenu;
1242 begin
1243   commandmanager.DMAddMethod(rscmAdd,'Add selected ents to device',@run);
1244   commandmanager.DMShow;
1245 end;
1246 
1247 procedure ATO_com.CommandStart(Operands:TCommandOperands);
1248 var
1249    test:boolean;
1250 begin
1251   self.savemousemode:=drawings.GetCurrentDWG^.wa.param.md.mode;
1252   test:=false;
1253   if zcGetRealSelEntsCount=1 then
1254   if drawings.GetCurrentDWG^.wa.param.seldesc.LastSelectedObject<>nil then
1255   if PGDBObjEntity(drawings.GetCurrentDWG^.wa.param.seldesc.LastSelectedObject)^.GetObjType=GDBDeviceID then
1256   test:=true;
1257   if test then
1258   begin
1259        showmenu;
1260        powner:=drawings.GetCurrentDWG^.wa.param.seldesc.LastSelectedObject;
1261        inherited CommandStart('');
1262   end
1263   else
1264   begin
1265     ZCMsgCallBackInterface.TextMessage(rscmSelDevBeforeComm,TMWOHistoryOut);
1266     Commandmanager.executecommandend;
1267   end;
1268 end;
1269 procedure ATO_com.Run(pdata:GDBPlatformint);
1270 var
1271    pobj,pvisible: pGDBObjEntity;
1272    ir:itrec;
1273    //tp:gdbpointer;
1274    m,m2:DMatrix4D;
1275    DC:TDrawContext;
1276 begin
1277      m:=powner^.objmatrix;
1278      m2:=m;
1279      matrixinvert(m);
1280      dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1281      pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
1282      if pobj<>nil then
1283      repeat
1284            if pobj^.Selected then
1285            if pobj<>pointer(powner) then
1286            begin
1287            powner^.objmatrix:=onematrix;
1288            pvisible:=pobj^.Clone(@powner^);
1289                     if pvisible^.IsHaveLCS then
1290                                pvisible^.Formatentity(drawings.GetCurrentDWG^,dc);
1291            pvisible^.transform(m);
1292            //pvisible^.correctobjects(powner,{pblockdef.ObjArray.getMutableData(i)}i);
1293            powner^.objmatrix:=m2;
1294            pvisible^.formatentity(drawings.GetCurrentDWG^,dc);
1295            pvisible^.BuildGeometry(drawings.GetCurrentDWG^);
1296            powner^.VarObjArray.AddPEntity(pvisible^);
1297            pobj^.YouDeleted(drawings.GetCurrentDWG^);
1298            end;
1299            pobj:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
1300      until pobj=nil;
1301      powner^.Formatentity(drawings.GetCurrentDWG^,dc);
1302      powner^.objmatrix:=m2;
1303      powner:=nil;
1304      Commandmanager.executecommandend;
1305 end;
1306 
1307 procedure TextInsert_com.BuildPrimitives;
1308 begin
1309      if drawings.GetCurrentDWG^.TextStyleTable.GetRealCount>0 then
1310      begin
1311      drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.free;
1312      case TextInsertParams.mode of
1313            TIM_Text:
1314            begin
1315              PRecordDescriptor(TextInsert.commanddata.PTD)^.SetAttrib('Oblique',0,FA_READONLY);
1316              PRecordDescriptor(TextInsert.commanddata.PTD)^.SetAttrib('WidthFactor',0,FA_READONLY);
1317 
1318              PRecordDescriptor(TextInsert.commanddata.PTD)^.SetAttrib('Width',FA_READONLY,0);
1319              PRecordDescriptor(TextInsert.commanddata.PTD)^.SetAttrib('LineSpace',FA_READONLY,0);
1320 
1321                 pt := GDBPointer(AllocEnt(GDBTextID));
1322                 pt^.init(@drawings.GetCurrentDWG^.ConstructObjRoot,drawings.GetCurrentDWG^.GetCurrentLayer,sysvar.dwg.DWG_CLinew^,'',nulvertex,2.5,0,1,0,jstl);
1323                 zcSetEntPropFromCurrentDrawingProp(pt);
1324            end;
1325            TIM_MText:
1326            begin
1327                 PRecordDescriptor(TextInsert.commanddata.PTD)^.SetAttrib('Oblique',FA_READONLY,0);
1328                 PRecordDescriptor(TextInsert.commanddata.PTD)^.SetAttrib('WidthFactor',FA_READONLY,0);
1329 
1330                 PRecordDescriptor(TextInsert.commanddata.PTD)^.SetAttrib('Width',0,FA_READONLY);
1331                 PRecordDescriptor(TextInsert.commanddata.PTD)^.SetAttrib('LineSpace',0,FA_READONLY);
1332 
1333                 pt := GDBPointer(AllocEnt(GDBMTextID));
1334                 pgdbobjmtext(pt)^.init(@drawings.GetCurrentDWG^.ConstructObjRoot,drawings.GetCurrentDWG^.GetCurrentLayer,sysvar.dwg.DWG_CLinew^,
1335                                   '',nulvertex,2.5,0,1,0,jstl,10,1);
1336                 zcSetEntPropFromCurrentDrawingProp(pt);
1337            end;
1338 
1339      end;
1340      drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.AddPEntity(pt^);
1341      end;
1342 end;
1343 procedure TextInsert_com.CommandStart(Operands:TCommandOperands);
1344 begin
1345      inherited;
1346      if drawings.GetCurrentDWG^.TextStyleTable.GetRealCount<1 then
1347      begin
1348           ZCMsgCallBackInterface.TextMessage(rscmInDwgTxtStyleNotDeffined,TMWOShowError);
1349           commandmanager.executecommandend;
1350      end;
1351 end;
1352 procedure TextInsert_com.CommandEnd;
1353 begin
1354 
1355 end;
1356 
1357 procedure TextInsert_com.Command(Operands:TCommandOperands);
1358 var
1359    s:string;
1360    i:integer;
1361 begin
1362        if drawings.GetCurrentDWG^.TextStyleTable.GetRealCount>0 then
1363      begin
1364      if TextInsertParams.Style.Selected>=TextInsertParams.Style.Enums.Count then
1365                                                                                 begin
1366                                                                                      s:=drawings.GetCurrentDWG^.GetCurrentTextStyle^.Name;
1367                                                                                 end
1368                                                                             else
1369                                                                                 begin
1370                                                                                      s:=TextInsertParams.Style.Enums.getData(TextInsertParams.Style.Selected);
1371                                                                                 end;
1372       //TextInsertParams.Style.Enums.Clear;
1373       TextInsertParams.Style.Enums.free;
1374       i:=GetStyleNames(TextInsertParams.Style.Enums,s);
1375       if i<0 then
1376                  TextInsertParams.Style.Selected:=0;
1377       ZCMsgCallBackInterface.Do_GUIaction(nil,ZMsgID_GUIActionRedraw);
1378       BuildPrimitives;
1379      drawings.GetCurrentDWG^.wa.SetMouseMode((MGet3DPoint) or (MMoveCamera) or (MRotateCamera));
1380      format;
1381      end;
1382 end;
DoEndnull1383 function TextInsert_com.DoEnd(pdata:GDBPointer):GDBBoolean;
1384 begin
1385      result:=false;
1386      dec(self.mouseclic);
1387      zcRedrawCurrentDrawing;
1388      if TextInsertParams.runtexteditor then
1389                                            RunTextEditor(pdata,drawings.GetCurrentDWG^);
1390      //redrawoglwnd;
1391      build('');
1392 end;
1393 
1394 procedure TextInsert_com.Format;
1395 var
1396    DC:TDrawContext;
1397 begin
1398      if ((pt^.GetObjType=GDBTextID)and(TextInsertParams.mode=TIM_MText))
1399      or ((pt^.GetObjType=GDBMTextID)and(TextInsertParams.mode=TIM_Text)) then
1400                                                                         BuildPrimitives;
1401      pt^.vp.Layer:=drawings.GetCurrentDWG^.GetCurrentLayer;
1402      pt^.vp.LineWeight:=sysvar.dwg.DWG_CLinew^;
1403      //pt^.TXTStyleIndex:=drawings.GetCurrentDWG^.TextStyleTable.getMutableData(TextInsertParams.Style.Selected);
1404      pt^.TXTStyleIndex:=drawings.GetCurrentDWG^.TextStyleTable.FindStyle(pgdbstring(TextInsertParams.Style.Enums.getDataMutable(TextInsertParams.Style.Selected))^,false);
1405      pt^.textprop.size:=TextInsertParams.h;
1406      pt^.Content:='';
1407      pt^.Template:=(TextInsertParams.text);
1408 
1409      case TextInsertParams.mode of
1410      TIM_Text:
1411               begin
1412                    pt^.textprop.oblique:=TextInsertParams.Oblique;
1413                    pt^.textprop.wfactor:=TextInsertParams.WidthFactor;
1414                    byte(pt^.textprop.justify):=byte(TextInsertParams.justify);
1415               end;
1416      TIM_MText:
1417               begin
1418                    pgdbobjmtext(pt)^.width:=TextInsertParams.Width;
1419                    pgdbobjmtext(pt)^.linespace:=TextInsertParams.LineSpace;
1420 
1421                    if TextInsertParams.LineSpace<0 then
1422                                                pgdbobjmtext(pt)^.linespacef:=(-TextInsertParams.LineSpace*3/5)/TextInsertParams.h
1423                                            else
1424                                                pgdbobjmtext(pt)^.linespacef:=TextInsertParams.LineSpace;
1425 
1426                    //linespace := textprop.size * linespacef * 5 / 3;
1427 
1428                    byte(pt^.textprop.justify):=byte(TextInsertParams.justify);
1429               end;
1430 
1431      end;
1432      dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1433      pt^.FormatEntity(drawings.GetCurrentDWG^,dc);
1434 end;
1435 procedure FloatInsert_com.CommandStart(Operands:TCommandOperands);
1436 begin
1437      inherited CommandStart(Operands);
1438      build(operands);
1439 end;
FloatInsert_com.DoEndnull1440 function FloatInsert_com.DoEnd(pdata:GDBPointer):GDBBoolean;
1441 begin
1442      result:=true;
1443 end;
1444 
FloatInsert_com.BeforeClicknull1445 function FloatInsert_com.BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger;
1446 var
1447     dist:gdbvertex;
1448     dispmatr:DMatrix4D;
1449     ir:itrec;
1450     tv,pobj: pGDBObjEntity;
1451     domethod,undomethod:tmethod;
1452     dc:TDrawContext;
1453 begin
1454 
1455       //drawings.GetCurrentDWG^.ConstructObjRoot.ObjMatrix:=dispmatr;
1456       dist.x := wc.x;
1457       dist.y := wc.y;
1458       dist.z := wc.z;
1459 
1460       dispmatr:=onematrix;
1461       PGDBVertex(@dispmatr[3])^:=dist;
1462 
1463       drawings.GetCurrentDWG^.ConstructObjRoot.ObjMatrix:=dispmatr;
1464 
1465   if (button and MZW_LBUTTON)<>0 then
1466   begin
1467    pobj:=drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.beginiterate(ir);
1468    if pobj<>nil then
1469    repeat
1470           begin
1471               //if pobj^.selected then
1472               begin
1473                 tv:=drawings.CopyEnt(drawings.GetCurrentDWG,drawings.GetCurrentDWG,pobj);
1474                 if tv^.IsHaveLCS then
1475                                     PGDBObjWithLocalCS(tv)^.CalcObjMatrix;
1476                 tv^.transform(dispmatr);
1477                 tv^.build(drawings.GetCurrentDWG^);
1478                 tv^.YouChanged(drawings.GetCurrentDWG^);
1479 
1480                 SetObjCreateManipulator(domethod,undomethod);
1481                 with PushMultiObjectCreateCommand(PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack,tmethod(domethod),tmethod(undomethod),1)^ do
1482                 begin
1483                      AddObject(tv);
1484                      FreeArray:=false;
1485                      //comit;
1486                 end;
1487 
1488               end;
1489           end;
1490           pobj:=drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.iterate(ir);
1491    until pobj=nil;
1492 
1493    dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1494    drawings.GetCurrentROOT^.calcbb(dc);
1495 
1496    //CopyToClipboard;
1497 
1498    drawings.GetCurrentDWG^.ConstructObjRoot.ObjMatrix:=onematrix;
1499    //commandend;
1500    if DoEnd(tv) then commandmanager.executecommandend;
1501   end;
1502   result:=cmd_ok;
1503 end;
1504 procedure pasteclip_com.Command(Operands:TCommandOperands);
1505 var //res:longbool;
1506     //uFormat:longword;
1507 
1508 //    lpszFormatName:string[200];
1509     //hData:THANDLE;
1510     //pbuf:pchar;
1511 //    hgBuffer:HGLOBAL;
1512 
1513     s:gdbstring;
1514 
1515     zcformat:TClipboardFormat;
1516     memsubstr:TMemoryStream;
1517     size:longword;
1518 //    I:gdbinteger;
1519 begin
1520      zcformat:=RegisterClipboardFormat(ZCAD_DXF_CLIPBOARD_NAME);
1521      if clipboard.HasFormat(zcformat) then
1522      begin
1523            memsubstr:=TMemoryStream.create;
1524            clipboard.GetFormat(zcformat,memsubstr);
1525            setlength(s,{memsubstr.GetSize}memsubstr.Seek(0,soFromEnd));
1526            size:=memsubstr.Seek(0,soFromEnd);
1527            memsubstr.Seek(0,soFromBeginning);
1528            memsubstr.ReadBuffer(s[1],{memsubstr.GetSize}size);
1529            memsubstr.Seek(0,0);
1530            //s:=memsubstr.ReadAnsiString;
1531            memsubstr.free;
1532                          if fileexists(utf8tosys(s)) then
1533               begin
1534                     addfromdxf(s,@drawings.GetCurrentDWG^.ConstructObjRoot,{tloload}TLOMerge,drawings.GetCurrentDWG^);
1535                     {ReloadLayer;
1536                     drawings.GetCurrentROOT^.calcbb;
1537                     drawings.GetCurrentROOT^.format;
1538                     drawings.GetCurrentROOT^.format;
1539                     updatevisible;
1540                     redrawoglwnd;}
1541               end;
1542            drawings.GetCurrentDWG^.wa.SetMouseMode((MGet3DPoint) or (MMoveCamera) or (MRotateCamera));
1543            ZCMsgCallBackInterface.TextMessage(rscmNewBasePoint,TMWOHistoryOut);
1544      end
1545        else
1546          ZCMsgCallBackInterface.TextMessage(rsClipboardIsEmpty,TMWOHistoryOut);
1547 end;
1548 procedure copybase_com.CommandStart(Operands:TCommandOperands);
1549 var //i: GDBInteger;
1550   {tv,}pobj: pGDBObjEntity;
1551       ir:itrec;
1552       counter:integer;
1553       //tcd:TCopyObjectDesc;
1554 begin
1555   inherited;
1556 
1557   counter:=0;
1558 
1559   pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
1560   if pobj<>nil then
1561   repeat
1562     if pobj^.selected then
1563     inc(counter);
1564   pobj:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
1565   until pobj=nil;
1566 
1567 
1568   if counter>0 then
1569   begin
1570   drawings.GetCurrentDWG^.wa.SetMouseMode((MGet3DPoint) or (MMoveCamera) or (MRotateCamera));
1571   ZCMsgCallBackInterface.TextMessage(rscmBasePoint,TMWOHistoryOut);
1572   end
1573   else
1574   begin
1575     ZCMsgCallBackInterface.TextMessage(rscmSelEntBeforeComm,TMWOHistoryOut);
1576     Commandmanager.executecommandend;
1577   end;
1578 end;
copybase_com.BeforeClicknull1579 function copybase_com.BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger;
1580 var
1581     dist:gdbvertex;
1582     dispmatr:DMatrix4D;
1583     ir:itrec;
1584     //pcd:PTCopyObjectDesc;
1585 
1586     //pbuf:pchar;
1587     //hgBuffer:HGLOBAL;
1588 
1589     //s,suni:gdbstring;
1590     //I:gdbinteger;
1591       tv,pobj: pGDBObjEntity;
1592       DC:TDrawContext;
1593       NeedReCreateClipboardDWG:boolean;
1594 begin
1595 
1596       //drawings.GetCurrentDWG^.ConstructObjRoot.ObjMatrix:=dispmatr;
1597   NeedReCreateClipboardDWG:=true;
1598   if (button and MZW_LBUTTON)<>0 then
1599   begin
1600       ClipboardDWG^.pObjRoot^.ObjArray.free;
1601       dist.x := -wc.x;
1602       dist.y := -wc.y;
1603       dist.z := -wc.z;
1604 
1605       dispmatr:=onematrix;
1606       PGDBVertex(@dispmatr[3])^:=dist;
1607 
1608    dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1609    pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
1610    if pobj<>nil then
1611    repeat
1612           begin
1613               if pobj^.selected then
1614               begin
1615                 if NeedReCreateClipboardDWG then
1616                                                  begin
1617                                                       ReCreateClipboardDWG;
1618                                                       NeedReCreateClipboardDWG:=false;
1619                                                  end;
1620                 tv:=drawings.CopyEnt(drawings.GetCurrentDWG,ClipboardDWG,pobj);
1621                 if tv^.IsHaveLCS then
1622                                     PGDBObjWithLocalCS(tv)^.CalcObjMatrix;
1623                 tv^.transform(dispmatr);
1624                 tv^.FormatEntity(ClipboardDWG^,dc);
1625               end;
1626           end;
1627           pobj:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
1628    until pobj=nil;
1629 
1630    CopyToClipboard;
1631 
1632    drawings.GetCurrentDWG^.ConstructObjRoot.ObjMatrix:=onematrix;
1633    commandend;
1634    commandmanager.executecommandend;
1635   end;
1636   result:=cmd_ok;
1637 end;
Insert_com_CommandStartnull1638 function Insert_com_CommandStart(operands:TCommandOperands):GDBInteger;
1639 var pb:PGDBObjBlockdef;
1640     //ir:itrec;
1641     i:integer;
1642 begin
1643      if operands<>'' then
1644      begin
1645           pb:=drawings.GetCurrentDWG^.BlockDefArray.getblockdef(operands);
1646           if pb=nil then
1647                         begin
1648                              drawings.AddBlockFromDBIfNeed(drawings.GetCurrentDWG,operands);
1649                              (*pb:=BlockBaseDWG^.BlockDefArray.getblockdef(operands);
1650                              if pb<>nil then
1651                              begin
1652                                   drawings.CopyBlock(BlockBaseDWG,drawings.GetCurrentDWG,pb);
1653                                   //pb^.CloneToGDB({@drawings.GetCurrentDWG^.BlockDefArray});
1654                              end;*)
1655                         end;
1656      end;
1657 
1658 
1659 
1660      BIProp.Blocks.Enums.free;
1661      i:=GetBlockDefNames(BIProp.Blocks.Enums,operands);
1662      if BIProp.Blocks.Enums.Count>0 then
1663      begin
1664           if i>=0 then
1665                      BIProp.Blocks.Selected:=i
1666                  else
1667                      if length(operands)<>0 then
1668                                          begin
1669                                                ZCMsgCallBackInterface.TextMessage('Insert:'+sysutils.format(rscmNoBlockDefInDWG,[operands]),TMWOHistoryOut);
1670                                                commandmanager.executecommandend;
1671                                                exit;
1672                                          end;
1673           ZCMsgCallBackInterface.Do_PrepareObject(nil,drawings.GetUnitsFormat,SysUnit^.TypeName2PTD('TBlockInsert'),@BIProp,drawings.GetCurrentDWG);
1674           drawings.GetCurrentDWG^.wa.SetMouseMode((MGet3DPoint) or (MMoveCamera) or (MRotateCamera));
1675           ZCMsgCallBackInterface.TextMessage(rscmInsertPoint,TMWOHistoryOut);
1676      end
1677         else
1678             begin
1679                  ZCMsgCallBackInterface.TextMessage('Insert:'+rscmInDwgBlockDefNotDeffined,TMWOHistoryOut);
1680                  commandmanager.executecommandend;
1681             end;
1682   result:=cmd_ok;
1683 end;
Insert_com_BeforeClicknull1684 function Insert_com_BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record;mclick:GDBInteger): GDBInteger;
1685 var tb:PGDBObjSubordinated;
1686     domethod,undomethod:tmethod;
1687     DC:TDrawContext;
1688 begin
1689   result:=mclick;
1690   dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1691   if (button and MZW_LBUTTON)<>0 then
1692   begin
1693     if pb<>nil then begin
1694                          //pb^.done;
1695                          //gdbfreemem(pointer(pb));
1696                          pb:=nil;
1697                          drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.free;
1698                          //drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.Count := 0;
1699                     end;
1700     pb := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateObj(GDBBlockInsertID{,drawings.GetCurrentROOT}));
1701     //PGDBObjBlockInsert(pb)^.initnul;//(@drawings.GetCurrentDWG^.ObjRoot,drawings.LayerTable.GetSystemLayer,0);
1702     PGDBObjBlockInsert(pb)^.init(drawings.GetCurrentROOT,drawings.GetCurrentDWG^.GetCurrentLayer,0);
1703     pb^.Name:=PGDBObjBlockdef(drawings.GetCurrentDWG^.BlockDefArray.getDataMutable(BIProp.Blocks.Selected))^.Name;//'DEVICE_NOC';
1704     zcSetEntPropFromCurrentDrawingProp(pb);
1705     //pb^.vp.ID:=GDBBlockInsertID;
1706     pb^.Local.p_insert:=wc;
1707     pb^.scale:=BIProp.Scale;
1708     pb^.CalcObjMatrix;
1709     //pb^.rotate:=BIProp.Rotation;
1710     pb^.setrot(BIProp.Rotation);
1711     //pb^.
1712     //GDBObjCircleInit(pc,drawings.LayerTable.GetCurrentLayer, sysvar.dwg.DWG_CLinew^, wc, 0);
1713     //pc^.lod:=4;
1714     tb:=pb^.FromDXFPostProcessBeforeAdd(nil,drawings.GetCurrentDWG^);
1715     if tb<>nil then begin
1716                          tb^.bp:=pb^.bp;
1717                          pb^.done;
1718                          gdbfreemem(pointer(pb));
1719                          pb:=pointer(tb);
1720     end;
1721 
1722     SetObjCreateManipulator(domethod,undomethod);
1723     with PushMultiObjectCreateCommand(PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack,tmethod(domethod),tmethod(undomethod),1)^ do
1724     begin
1725          AddObject(pb);
1726          comit;
1727     end;
1728 
1729     //drawings.GetCurrentROOT^.AddObjectToObjArray{ObjArray.add}(addr(pb));
1730     PGDBObjEntity(pb)^.FromDXFPostProcessAfterAdd;
1731     pb^.CalcObjMatrix;
1732     pb^.BuildGeometry(drawings.GetCurrentDWG^);
1733     pb^.BuildVarGeometry(drawings.GetCurrentDWG^);
1734     pb^.FormatEntity(drawings.GetCurrentDWG^,dc);
1735     drawings.GetCurrentROOT^.ObjArray.ObjTree.CorrectNodeBoundingBox(pb^);
1736     pb^.Visible:=0;
1737     drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.Count := 0;
1738     pb^.RenderFeedback(drawings.GetCurrentDWG^.pcamera^.POSCOUNT,drawings.GetCurrentDWG^.pcamera^,@drawings.GetCurrentDWG^.myGluProject2,dc);
1739     pb:=nil;
1740     //commandmanager.executecommandend;
1741     //result:=1;
1742     zcRedrawCurrentDrawing;
1743 
1744     result:=0;
1745   end
1746   else
1747   begin
1748     if pb<>nil then begin
1749                          //pb^.done;
1750                          //gdbfreemem(pointer(pb));
1751                          pb:=nil;
1752                          drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.free;
1753                          //drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.Count := 0;
1754                     end;
1755     pointer(pb) :=AllocEnt(GDBBlockInsertID);
1756     //pointer(pb) :=drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateObj(GDBBlockInsertID,drawings.GetCurrentROOT);
1757     //pb := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.CreateObj(GDBBlockInsertID,@drawings.GetCurrentDWG^.ObjRoot));
1758     //PGDBObjBlockInsert(pb)^.initnul;//(@drawings.GetCurrentDWG^.ObjRoot,drawings.LayerTable.GetSystemLayer,0);
1759     PGDBObjBlockInsert(pb)^.init(drawings.GetCurrentROOT,drawings.GetCurrentDWG^.GetCurrentLayer,0);
1760     pb^.Name:=PGDBObjBlockdef(drawings.GetCurrentDWG^.BlockDefArray.getDataMutable(BIProp.Blocks.Selected))^.Name;//'NOC';//'TESTBLOCK';
1761     zcSetEntPropFromCurrentDrawingProp(pb);
1762     //pb^.vp.ID:=GDBBlockInsertID;
1763     pb^.Local.p_insert:=wc;
1764 
1765     pb^.Local.p_insert:=wc;
1766     pb^.scale:=BIProp.Scale;
1767     pb^.CalcObjMatrix;
1768     //pb^.rotate:=BIProp.Rotation;
1769     pb^.setrot(BIProp.Rotation);
1770 
1771     tb:=pb^.FromDXFPostProcessBeforeAdd(nil,drawings.GetCurrentDWG^);
1772     if tb<>nil then begin
1773                          tb^.bp:=pb^.bp;
1774                          //drawings.GetCurrentDWG^.ConstructObjRoot.deliteminarray(pb^.bp.PSelfInOwnerArray);
1775                          pb^.done;
1776                          gdbfreemem(pointer(pb));
1777                          pb:=pointer(tb);
1778     end;
1779     drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.AddPEntity(pb^);
1780     //PGDBObjEntity(pb)^.FromDXFPostProcessAfterAdd;
1781     pb^.CalcObjMatrix;
1782     pb^.BuildGeometry(drawings.GetCurrentDWG^);
1783     pb^.BuildVarGeometry(drawings.GetCurrentDWG^);
1784     pb^.FormatEntity(drawings.GetCurrentDWG^,dc);
1785     //drawings.GetCurrentDWG^.ConstructObjRoot.Count := 0;
1786     //pb^.RenderFeedback;
1787   end;
1788 end;
1789 procedure Insert_com_CommandEnd(_self:pointer);
1790 begin
1791      if pb<>nil then
1792                     begin
1793                          //pb^.done;
1794                          //gdbfreemem(pointer(pb));
1795                          pb:=nil;
1796                     end;
1797 end;
Erase_comnull1798 function Erase_com(operands:TCommandOperands):TCommandResult;
1799 var pv:pGDBObjEntity;
1800     ir:itrec;
1801     count:integer;
1802     domethod,undomethod:tmethod;
1803 begin
1804   if (drawings.GetCurrentROOT^.ObjArray.count = 0)or(drawings.GetCurrentDWG^.wa.param.seldesc.Selectedobjcount=0) then exit;
1805   count:=0;
1806   pv:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
1807   if pv<>nil then
1808   repeat
1809     if pv^.Selected then
1810                         begin
1811                              //pv^.YouDeleted;
1812                              inc(count);
1813                         end
1814                     else
1815                         pv^.DelSelectedSubitem(drawings.GetCurrentDWG^);
1816 
1817   pv:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
1818   until pv=nil;
1819   if count>0 then
1820   begin
1821   SetObjCreateManipulator(undomethod,domethod);
1822   with PushMultiObjectCreateCommand(PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack,tmethod(domethod),tmethod(undomethod),count)^ do
1823   begin
1824     pv:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
1825     if pv<>nil then
1826     repeat
1827       if pv^.Selected then
1828                           begin
1829                                AddObject(pv);
1830                                pv^.Selected:=false;
1831                           end;
1832     pv:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
1833     until pv=nil;
1834        //AddObject(pc);
1835        FreeArray:=false;
1836        comit;
1837        //UnDo;
1838   end;
1839   end;
1840   drawings.GetCurrentDWG^.wa.param.seldesc.Selectedobjcount:=0;
1841   drawings.GetCurrentDWG^.wa.param.seldesc.OnMouseObject:=nil;
1842   drawings.GetCurrentDWG^.wa.param.seldesc.LastSelectedObject:=nil;
1843   drawings.GetCurrentDWG^.wa.param.lastonmouseobject:=nil;
1844   ZCMsgCallBackInterface.Do_GUIaction(nil,ZMsgID_GUIReturnToDefaultObject);
1845   clearcp;
1846   zcRedrawCurrentDrawing;
1847   result:=cmd_ok;
1848 end;
CutClip_comnull1849 function CutClip_com(operands:TCommandOperands):TCommandResult;
1850 begin
1851    copyclip_com(EmptyCommandOperands);
1852    Erase_com(EmptyCommandOperands);
1853    result:=cmd_ok;
1854 end;
InverseSelected_comnull1855 function InverseSelected_com(operands:TCommandOperands):TCommandResult;
1856 var pv:pGDBObjEntity;
1857     ir:itrec;
1858     count:integer;
1859     //domethod,undomethod:tmethod;
1860 begin
1861   //if (drawings.GetCurrentROOT^.ObjArray.count = 0)or(drawings.GetCurrentDWG^.OGLwindow1.param.seldesc.Selectedobjcount=0) then exit;
1862   count:=0;
1863   pv:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
1864   if pv<>nil then
1865   repeat
1866     if pv^.Selected then
1867                         begin
1868                              pv^.deselect(drawings.GetCurrentDWG^.wa.param.SelDesc.Selectedobjcount,@drawings.CurrentDWG^.DeSelector);
1869                              inc(count);
1870                         end
1871                     else
1872                         begin
1873                           pv^.select(drawings.GetCurrentDWG^.wa.param.SelDesc.Selectedobjcount,@drawings.CurrentDWG^.selector);
1874                           inc(count);
1875                         end;
1876 
1877   pv:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
1878   until pv=nil;
1879   drawings.GetCurrentDWG^.wa.param.seldesc.Selectedobjcount:=count;
1880   drawings.GetCurrentDWG^.wa.param.seldesc.OnMouseObject:=nil;
1881   drawings.GetCurrentDWG^.wa.param.seldesc.LastSelectedObject:=nil;
1882   drawings.GetCurrentDWG^.wa.param.lastonmouseobject:=nil;
1883   //{objinsp.GDBobjinsp.}ReturnToDefault;
1884   //clearcp;
1885   zcRedrawCurrentDrawing;
1886   result:=cmd_ok;
1887 end;
1888 
1889 {var i, newend, objdel: GDBInteger;
1890 begin
1891   if drawings.ObjRoot.ObjArray.count = 0 then exit;
1892   newend := 0;
1893   objdel := 0;
1894   for i := 0 to drawings.ObjRoot.ObjArray.count - 1 do
1895   begin
1896     if newend <> i then PGDBObjEntityArray(drawings.ObjRoot.ObjArray.PArray)[newend] := PGDBObjEntityArray(drawings.ObjRoot.ObjArray.PArray)[i];
1897     if PGDBObjEntityArray(drawings.ObjRoot.ObjArray.PArray)[i].selected = false then inc(newend)
1898     else inc(objdel);
1899   end;
1900   drawings.ObjRoot.ObjArray.count := drawings.ObjRoot.ObjArray.count - objdel;
1901   clearcp;
1902   redrawoglwnd;
1903 end;}
Circle_com_CommandStartnull1904 function Circle_com_CommandStart(operands:TCommandOperands):TCommandResult;
1905 begin
1906   drawings.GetCurrentDWG^.wa.SetMouseMode((MGet3DPoint) or (MMoveCamera) or (MRotateCamera));
1907   ZCMsgCallBackInterface.TextMessage(rscmCenterPointCircle,TMWOHistoryOut);
1908   result:=cmd_ok;
1909 end;
1910 
1911 procedure Circle_com_CommandEnd(_self:pointer);
1912 begin
1913 end;
1914 
Circle_com_BeforeClicknull1915 function Circle_com_BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record;mclick:GDBInteger): GDBInteger;
1916 var
1917   dc:TDrawContext;
1918 begin
1919   if (button and MZW_LBUTTON)<>0 then
1920   begin
1921     dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1922     ZCMsgCallBackInterface.TextMessage(rscmPointOnCircle,TMWOHistoryOut);
1923 
1924     pc := PGDBObjCircle(ENTF_CreateCircle(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[wc.x,wc.y,wc.z,0]));
1925     zcSetEntPropFromCurrentDrawingProp(pc);
1926     //pc := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateInitObj(GDBCircleID,drawings.GetCurrentROOT));
1927     //GDBObjSetCircleProp(pc,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer,sysvar.dwg.DWG_CLType^,sysvar.dwg.DWG_CColor^, sysvar.dwg.DWG_CLinew^, wc, 0);
1928 
1929     dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1930     pc^.Formatentity(drawings.GetCurrentDWG^,dc);
1931     pc^.RenderFeedback(drawings.GetCurrentDWG^.pcamera^.POSCOUNT,drawings.GetCurrentDWG^.pcamera^,@drawings.GetCurrentDWG^.myGluProject2,dc);
1932   end;
1933   result:=0;
1934 end;
1935 
Circle_com_AfterClicknull1936 function Circle_com_AfterClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record;mclick:GDBInteger): GDBInteger;
1937 var
1938     domethod,undomethod:tmethod;
1939     dc:TDrawContext;
1940 begin
1941   result:=mclick;
1942   dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1943   zcSetEntPropFromCurrentDrawingProp(pc);
1944   pc^.Radius := Vertexlength(pc^.local.P_insert, wc);
1945   pc^.Formatentity(drawings.GetCurrentDWG^,dc);
1946   pc^.RenderFeedback(drawings.GetCurrentDWG^.pcamera^.POSCOUNT,drawings.GetCurrentDWG^.pcamera^,@drawings.GetCurrentDWG^.myGluProject2,dc);
1947   if (button and MZW_LBUTTON)<>0 then
1948   begin
1949 
1950          SetObjCreateManipulator(domethod,undomethod);
1951          with PushMultiObjectCreateCommand(PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack,tmethod(domethod),tmethod(undomethod),1)^ do
1952          begin
1953               AddObject(pc);
1954               comit;
1955          end;
1956 
1957     drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.Count := 0;
1958     commandmanager.executecommandend;
1959   end;
1960 end;
1961 
1962 
1963 
1964 
1965 
1966 
Line_com_CommandStartnull1967 function Line_com_CommandStart(operands:TCommandOperands):TCommandResult;
1968 begin
1969   pold:=nil;
1970   drawings.GetCurrentDWG^.wa.SetMouseMode((MGet3DPoint) or (MMoveCamera) or (MRotateCamera));
1971   ZCMsgCallBackInterface.TextMessage(rscmFirstPoint,TMWOHistoryOut);
1972   result:=cmd_ok;
1973 end;
1974 
1975 procedure Line_com_CommandEnd(_self:pointer);
1976 begin
1977 end;
1978 
Line_com_BeforeClicknull1979 function Line_com_BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record;mclick:GDBInteger): GDBInteger;
1980 var
1981     dc:TDrawContext;
1982 begin
1983   result:=0;
1984   if (button and MZW_LBUTTON)<>0 then
1985   begin
1986     dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
1987     PCreatedGDBLine := PGDBObjLine(ENTF_CreateLine(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[wc.x,wc.y,wc.z,wc.x,wc.y,wc.z]));
1988     zcSetEntPropFromCurrentDrawingProp(PCreatedGDBLine);
1989     PCreatedGDBLine^.FormatEntity(drawings.GetCurrentDWG^,dc);
1990   end
1991 end;
1992 
Line_com_AfterClicknull1993 function Line_com_AfterClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record;mclick:GDBInteger): GDBInteger;
1994 var po:PGDBObjSubordinated;
1995     domethod,undomethod:tmethod;
1996     dc:TDrawContext;
1997 begin
1998   result:=mclick;
1999   {PCreatedGDBLine^.vp.Layer :=drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer;
2000   PCreatedGDBLine^.vp.lineweight := sysvar.dwg.DWG_CLinew^;}
2001   zcSetEntPropFromCurrentDrawingProp(PCreatedGDBLine);
2002   PCreatedGDBLine^.CoordInOCS.lEnd:= wc;
2003   dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
2004   PCreatedGDBLine^.FormatEntity(drawings.GetCurrentDWG^,dc);
2005   po:=nil;
2006   if osp<>nil then
2007   begin
2008        if (PGDBObjEntity(osp^.PGDBObject)<>nil)and(osp^.PGDBObject<>pold)
2009        then
2010        begin
2011             PGDBObjEntity(osp^.PGDBObject)^.formatentity(drawings.GetCurrentDWG^,dc);
2012             //PGDBObjEntity(osp^.PGDBObject)^.ObjToGDBString('Found: ','');
2013             ZCMsgCallBackInterface.TextMessage(PGDBObjline(osp^.PGDBObject)^.ObjToGDBString('Found: ',''),TMWOHistoryOut);
2014             po:=PGDBObjEntity(osp^.PGDBObject)^.getowner;
2015             pold:=osp^.PGDBObject;
2016        end
2017   end else pold:=nil;
2018   //pl^.RenderFeedback;
2019   if (button and MZW_LBUTTON)<>0 then
2020   begin
2021     PCreatedGDBLine^.RenderFeedback(drawings.GetCurrentDWG^.pcamera^.POSCOUNT,drawings.GetCurrentDWG^.pcamera^,@drawings.GetCurrentDWG^.myGluProject2,dc);
2022     if po<>nil then
2023     begin
2024     PCreatedGDBLine^.bp.ListPos.Owner:=po;
2025     //drawings.ObjRoot.ObjArray.add(addr(pl));
2026     PGDBObjGenericSubEntry(po)^.ObjArray.AddPEntity(PCreatedGDBLine^);
2027     end
2028     else
2029     begin
2030     PCreatedGDBLine^.bp.ListPos.Owner:=drawings.GetCurrentROOT;
2031     //drawings.ObjRoot.ObjArray.add(addr(pl));
2032     SetObjCreateManipulator(domethod,undomethod);
2033     with PushMultiObjectCreateCommand(PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack,tmethod(domethod),tmethod(undomethod),1)^ do
2034     begin
2035          AddObject(PCreatedGDBLine);
2036          comit;
2037     end;
2038     //drawings.GetCurrentROOT^.AddObjectToObjArray{ObjArray.add}(addr(PCreatedGDBLine));
2039     end;
2040     drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.Count := 0;
2041     result:=1;
2042     //Line_com_BeforeClick(wc,mc,button,osp);
2043     zcRedrawCurrentDrawing;
2044     //commandend;
2045     //commandmanager.executecommandend;
2046   end;
2047 end;
2048 
Mirror_com.CalcTransformMatrixnull2049 function Mirror_com.CalcTransformMatrix(p1,p2: GDBvertex):DMatrix4D;
2050 var
2051     dist,p3:gdbvertex;
2052     d:GDBDouble;
2053     plane:DVector4D;
2054 begin
2055         dist:=uzegeometry.VertexSub(p2,p1);
2056         d:=uzegeometry.oneVertexlength(dist);
2057         p3:=uzegeometry.VertexMulOnSc(ZWCS,d);
2058         p3:=uzegeometry.VertexAdd(p3,t3dp);
2059 
2060         plane:=PlaneFrom3Pont(p1,p2,p3);
2061         normalizeplane(plane);
2062         result:=CreateReflectionMatrix(plane);
2063 end;
Mirror_com.AfterClicknull2064 function Mirror_com.AfterClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger;
2065 var
2066     dispmatr:DMatrix4D;
2067 begin
2068 
2069   dispmatr:=CalcTransformMatrix(t3dp,wc);
2070   drawings.GetCurrentDWG^.ConstructObjRoot.ObjMatrix:=dispmatr;
2071 
2072    if (button and MZW_LBUTTON)<>0 then
2073    begin
2074       case MirrorParam.SourceEnts of
2075                            TEP_Erase:move(dispmatr,self.CommandName);
2076                            TEP_Leave:copy(dispmatr,self.CommandName);
2077       end;
2078       //redrawoglwnd;
2079       commandmanager.executecommandend;
2080    end;
2081    result:=cmd_ok;
2082 end;
2083 procedure rotate_com.CommandContinue;
2084 var v1:vardesk;
2085     td:gdbdouble;
2086 begin
2087    if (commandmanager.GetValueHeap{-vs})>0 then
2088    begin
2089    v1:=commandmanager.PopValue;
2090    td:=Pgdbdouble(v1.data.Instance)^*pi/180;
2091    rot(td,MZW_LBUTTON);
2092    end;
2093 end;
2094 procedure rotate_com.showprompt(mklick:integer);
2095 begin
2096      case mklick of
2097      0:inherited;
2098      1:ZCMsgCallBackInterface.TextMessage(rscmPickOrEnterAngle,TMWOHistoryOut);
2099      end;
2100 end;
2101 procedure rotate_com.rot(a:GDBDouble; button: GDBByte);
2102 var
2103     dispmatr,im,rotmatr:DMatrix4D;
2104     ir:itrec;
2105     pcd:PTCopyObjectDesc;
2106     //v1,v2:GDBVertex2d;
2107     m:tmethod;
2108     dc:TDrawContext;
2109 begin
2110   dispmatr:=uzegeometry.CreateTranslationMatrix(createvertex(-t3dp.x,-t3dp.y,-t3dp.z));
2111   rotmatr:=uzegeometry.CreateRotationMatrixZ(sin(a),cos(a));
2112   rotmatr:=uzegeometry.MatrixMultiply(dispmatr,rotmatr);
2113   dispmatr:=uzegeometry.CreateTranslationMatrix(createvertex(t3dp.x,t3dp.y,t3dp.z));
2114   dispmatr:=uzegeometry.MatrixMultiply(rotmatr,dispmatr);
2115   dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
2116 
2117 if (button and MZW_LBUTTON)=0 then
2118                  begin
2119                       //drawings.GetCurrentDWG^.ConstructObjRoot.ObjMatrix:=dispmatr;
2120                       drawings.GetCurrentDWG^.ConstructObjRoot.ObjMatrix:=dispmatr;
2121                        {pcd:=pcoa^.beginiterate(ir);
2122                        if pcd<>nil then
2123                        repeat
2124                             pcd.clone^.TransformAt(pcd.obj,@dispmatr);
2125                             pcd.clone^.format;
2126                             pcd:=pcoa^.iterate(ir);
2127                        until pcd=nil;}
2128                  end
2129             else
2130                 begin
2131                   im:=dispmatr;
2132                   uzegeometry.MatrixInvert(im);
2133                   PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack.PushStartMarker('Rotate');
2134                   with PushCreateTGMultiObjectChangeCommand(PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack,dispmatr,im,pcoa^.Count)^ do
2135                   begin
2136                    pcd:=pcoa^.beginiterate(ir);
2137                   if pcd<>nil then
2138                   repeat
2139                       m:=TMethod(@pcd^.sourceEnt^.Transform);
2140                       {m.Data:=pcd.obj;
2141                       m.Code:=pointer(pcd.obj^.Transform);}
2142                       AddMethod(m);
2143 
2144                       dec(pcd^.sourceEnt^.vp.LastCameraPos);
2145                       //pcd.obj^.Format;
2146 
2147                       pcd:=pcoa^.iterate(ir);
2148                   until pcd=nil;
2149                   comit;
2150                   end;
2151                   PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack.PushEndMarker;
2152                 end;
2153 if (button and MZW_LBUTTON)<>0 then
2154 begin
2155 drawings.GetCurrentROOT^.FormatAfterEdit(drawings.GetCurrentDWG^,dc);
2156 drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.free;
2157 commandend;
2158 commandmanager.executecommandend;
2159 end;
2160 
2161 end;
2162 
rotate_com.AfterClicknull2163 function rotate_com.AfterClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger;
2164 var
2165     //dispmatr,im,rotmatr:DMatrix4D;
2166     //ir:itrec;
2167     //pcd:PTCopyObjectDesc;
2168     a:double;
2169     v1,v2:GDBVertex2d;
2170     //m:tmethod;
2171 begin
2172       v2.x:=wc.x;
2173       v2.y:=wc.y;
2174       v1.x:=t3dp.x;
2175       v1.y:=t3dp.y;
2176       a:=uzegeometry.Vertexangle(v1,v2);
2177 
2178       rot(a,button);
2179 
2180       //dispmatr:=onematrix;
2181       result:=cmd_ok;
2182 end;
2183 procedure scale_com.CommandContinue;
2184 var v1:vardesk;
2185     td:gdbdouble;
2186 begin
2187    if (commandmanager.GetValueHeap{-vs})>0 then
2188    begin
2189    v1:=commandmanager.PopValue;
2190    td:=Pgdbdouble(v1.data.Instance)^;
2191    scale(td,MZW_LBUTTON);
2192    end;
2193 end;
2194 
2195 procedure scale_com.showprompt(mklick:integer);
2196 begin
2197      case mklick of
2198      0:inherited;
2199      1:ZCMsgCallBackInterface.TextMessage(rscmPickOrEnterScale,TMWOHistoryOut);
2200      end;
2201 end;
2202 procedure scale_com.scale(a:GDBDouble; button: GDBByte);
2203 var
2204     dispmatr,im,rotmatr:DMatrix4D;
2205     ir:itrec;
2206     pcd:PTCopyObjectDesc;
2207     //v:GDBVertex;
2208     m:tmethod;
2209     dc:TDrawContext;
2210 begin
2211 if a<eps then a:=1;
2212 
2213 dispmatr:=uzegeometry.CreateTranslationMatrix(createvertex(-t3dp.x,-t3dp.y,-t3dp.z));
2214 
2215 rotmatr:=onematrix;
2216 rotmatr[0][0]:=a;
2217 rotmatr[1][1]:=a;
2218 rotmatr[2][2]:=a;
2219 
2220 rotmatr:=uzegeometry.MatrixMultiply(dispmatr,rotmatr);
2221 dispmatr:=uzegeometry.CreateTranslationMatrix(createvertex(t3dp.x,t3dp.y,t3dp.z));
2222 dispmatr:=uzegeometry.MatrixMultiply(rotmatr,dispmatr);
2223 dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
2224 {pcd:=pcoa^.beginiterate(ir);
2225 if pcd<>nil then
2226 repeat
2227   pcd.clone^.TransformAt(pcd.obj,@dispmatr);
2228   pcd.clone^.format;
2229   if button = 1 then
2230                     begin
2231                     pcd.clone^.rtsave(pcd.obj);
2232                     pcd.obj^.Format;
2233                     end;
2234 
2235   pcd:=pcoa^.iterate(ir);
2236 until pcd=nil;}
2237 if (button and MZW_LBUTTON)=0 then
2238                   begin
2239                         drawings.GetCurrentDWG^.ConstructObjRoot.ObjMatrix:=dispmatr;
2240                         {pcd:=pcoa^.beginiterate(ir);
2241                         if pcd<>nil then
2242                         repeat
2243                              pcd.clone^.TransformAt(pcd.obj,@dispmatr);
2244                              pcd.clone^.format;
2245                              pcd:=pcoa^.iterate(ir);
2246                         until pcd=nil;}
2247                   end
2248              else
2249                  begin
2250                    im:=dispmatr;
2251                    uzegeometry.MatrixInvert(im);
2252                    PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack.PushStartMarker('Scale');
2253                    with PushCreateTGMultiObjectChangeCommand(PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack,dispmatr,im,pcoa^.Count)^ do
2254                    begin
2255                     pcd:=pcoa^.beginiterate(ir);
2256                    if pcd<>nil then
2257                    repeat
2258                        m:=TMEthod(@pcd^.sourceEnt^.Transform);
2259                        {m.Data:=pcd.obj;
2260                        m.Code:=pointer(pcd.obj^.Transform);}
2261                        AddMethod(m);
2262 
2263                        dec(pcd^.sourceEnt^.vp.LastCameraPos);
2264                        //pcd.obj^.Format;
2265 
2266                        pcd:=pcoa^.iterate(ir);
2267                    until pcd=nil;
2268                    comit;
2269                    end;
2270                    PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack.PushEndMarker;
2271                  end;
2272 
2273 if (button and MZW_LBUTTON)<>0 then
2274 begin
2275 drawings.GetCurrentROOT^.FormatAfterEdit(drawings.GetCurrentDWG^,dc);
2276 drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.free;
2277 commandend;
2278 commandmanager.executecommandend;
2279 end;
2280 end;
2281 
scale_com.AfterClicknull2282 function scale_com.AfterClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record): GDBInteger;
2283 var
2284     //dispmatr,im,rotmatr:DMatrix4D;
2285     //ir:itrec;
2286     //pcd:PTCopyObjectDesc;
2287     a:double;
2288     //v:GDBVertex;
2289     //m:tmethod;
2290 begin
2291       //v:=uzegeometry.VertexSub(t3dp,wc);
2292       a:=uzegeometry.Vertexlength(t3dp,wc);
2293       scale(a,button);
2294       result:=cmd_ok;
2295 end;
2296 
_3DPolyEd_com_CommandStartnull2297 function _3DPolyEd_com_CommandStart(operands:TCommandOperands):TCommandResult;
2298 var
2299    pobj:pgdbobjentity;
2300    ir:itrec;
2301 begin
2302   p3dpl:=nil;
2303   pc:=nil;
2304   PCreatedGDBLine:=nil;
2305   pworkvertex:=nil;
2306   PEProp.setpoint:=false;
2307   pobj:=drawings.GetCurrentROOT^.ObjArray.beginiterate(ir);
2308    if pobj<>nil then
2309    repeat
2310           begin
2311               if pobj^.selected
2312               and (
2313                    (pobj^.GetObjType=GDBPolylineID)
2314                  or(pobj^.GetObjType=GDBCableID)
2315                    )
2316               then
2317                   begin
2318                        p3dpl:=pointer(pobj);
2319                        system.Break;
2320                   end;
2321           end;
2322           pobj:=drawings.GetCurrentROOT^.ObjArray.iterate(ir);
2323    until pobj=nil;
2324    if p3dpl=nil then
2325                    begin
2326                         ZCMsgCallBackInterface.TextMessage(rscmPolyNotSel,TMWOHistoryOut);
2327                         commandmanager.executecommandend;
2328                    end
2329                else
2330                    begin
2331                         ZCMsgCallBackInterface.Do_PrepareObject(nil,drawings.GetUnitsFormat,SysUnit^.TypeName2PTD('TPolyEdit'),@PEProp,drawings.GetCurrentDWG);
2332                         drawings.GetCurrentDWG^.wa.SetMouseMode((MGet3DPoint) or (MMoveCamera) or (MRotateCamera));
2333                         drawings.GetCurrentDWG^.SelObjArray.Free;
2334                    end;
2335   result:=cmd_ok;
2336 end;
2337 
2338 
_3DPolyEd_com_BeforeClicknull2339 function _3DPolyEd_com_BeforeClick(wc: GDBvertex; mc: GDBvertex2DI; var button: GDBByte;osp:pos_record;mclick:GDBInteger): GDBInteger;
2340 var
2341     ptv,ptvprev:pgdbvertex;
2342     ir:itrec;
2343     v,l:gdbdouble;
2344     domethod,undomethod:tmethod;
2345     polydata:tpolydata;
2346     _tv:gdbvertex;
2347     p3dpl2:pgdbobjpolyline;
2348     i:integer;
2349     dc:TDrawContext;
2350 begin
2351   if (button and MZW_LBUTTON)<>0 then
2352                     button:=button;
2353   if PEProp.Action=TSPE_Remove then
2354                                    PEProp.setpoint:=false;
2355 
2356   if (pc<>nil)or(PCreatedGDBLine<>nil) then
2357                  begin
2358                       drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.free;
2359                       pc:=nil;
2360                       PCreatedGDBLine:=nil;
2361                  end;
2362   dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
2363   result:={mclick}0;
2364   if not PEProp.setpoint then
2365   begin
2366   PEProp.nearestvertex:=-1;
2367   PEProp.dir:=0;
2368   PEProp.nearestline:=-1;
2369   PEProp.vdist:=+Infinity;
2370   PEProp.ldist:=+Infinity;
2371   ptvprev:=nil;
2372   ptv:=p3dpl^.vertexarrayinwcs.beginiterate(ir);
2373   if ptv<>nil then
2374   repeat
2375         v:=SqrVertexlength(wc,ptv^);
2376         if v<PEProp.vdist then
2377                        begin
2378                             PEProp.vdist:=v;
2379                             PEProp.nearestvertex:=ir.itc;
2380                             PEProp.vvertex:=ptv^;
2381                        end;
2382         if ptvprev<>nil then
2383                             begin
2384                                  l:=sqr(distance2piece(wc,ptvprev^,ptv^));
2385                                  if l<PEProp.ldist then
2386                                                 begin
2387                                                      PEProp.ldist:=l;
2388                                                      PEProp.nearestline:=ir.itc;
2389                                                      PEProp.lvertex1:=ptvprev^;
2390                                                      PEProp.lvertex2:=ptv^;
2391                                                 end;
2392                             end;
2393         ptvprev:=ptv;
2394         ptv:=p3dpl^.vertexarrayinwcs.iterate(ir);
2395   until ptv=nil;
2396   end;
2397   if (PEProp.Action=TSPE_Remove) then
2398   begin
2399   if PEProp.nearestvertex>-1 then
2400                           begin
2401 
2402                           pc := PGDBObjCircle(ENTF_CreateCircle(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[PEProp.vvertex.x,PEProp.vvertex.y,PEProp.vvertex.z,10*drawings.GetCurrentDWG^.pcamera^.prop.zoom]));
2403                           zcSetEntPropFromCurrentDrawingProp(pc);
2404                           //pc := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateInitObj(GDBCircleID,drawings.GetCurrentROOT));
2405                           //GDBObjSetCircleProp(pc,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer,sysvar.dwg.DWG_CLType^,sysvar.dwg.DWG_CColor^,sysvar.dwg.DWG_CLinew^, PEProp.vvertex,10*drawings.GetCurrentDWG^.pcamera^.prop.zoom);
2406 
2407                           pc^.Formatentity(drawings.GetCurrentDWG^,dc);
2408                           end;
2409   end;
2410   if (PEProp.Action=TSPE_Insert) then
2411                                      begin
2412                                           if abs(PEProp.vdist-PEProp.ldist)>sqreps then
2413                                           begin
2414                                                PCreatedGDBLine := PGDBObjLine(ENTF_CreateLine(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[PEProp.lvertex1.x,PEProp.lvertex1.y,PEProp.lvertex1.z,wc.x,wc.y,wc.z]));
2415                                                zcSetEntPropFromCurrentDrawingProp(PCreatedGDBLine);
2416                                                //PCreatedGDBLine := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateInitObj(GDBLineID,drawings.GetCurrentROOT));
2417                                                //GDBObjSetLineProp(PCreatedGDBLine,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer,sysvar.dwg.DWG_CLType^,sysvar.dwg.DWG_CColor^, sysvar.dwg.DWG_CLinew^, PEProp.lvertex1, wc);
2418 
2419                                                PCreatedGDBLine^.Formatentity(drawings.GetCurrentDWG^,dc);
2420 
2421                                                PCreatedGDBLine := PGDBObjLine(ENTF_CreateLine(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[PEProp.lvertex2.x,PEProp.lvertex2.y,PEProp.lvertex2.z,wc.x,wc.y,wc.z]));
2422                                                zcSetEntPropFromCurrentDrawingProp(PCreatedGDBLine);
2423                                                //PCreatedGDBLine := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateInitObj(GDBLineID,drawings.GetCurrentROOT));
2424                                                //GDBObjSetLineProp(PCreatedGDBLine,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer,sysvar.dwg.DWG_CLType^,sysvar.dwg.DWG_CColor^,sysvar.dwg.DWG_CLinew^, PEProp.lvertex2, wc);
2425 
2426                                                PCreatedGDBLine^.Formatentity(drawings.GetCurrentDWG^,dc);
2427                                                PEProp.dir:=-1;
2428                                           end
2429                                      else
2430                                          begin
2431                                               if PEProp.nearestvertex=0 then
2432                                               begin
2433                                                    PCreatedGDBLine := PGDBObjLine(ENTF_CreateLine(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[PEProp.lvertex1.x,PEProp.lvertex1.y,PEProp.lvertex1.z,wc.x,wc.y,wc.z]));
2434                                                    zcSetEntPropFromCurrentDrawingProp(PCreatedGDBLine);
2435 
2436                                                    //PCreatedGDBLine := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateInitObj(GDBLineID,drawings.GetCurrentROOT));
2437                                                    //GDBObjSetLineProp(PCreatedGDBLine,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer,sysvar.dwg.DWG_CLType^,sysvar.dwg.DWG_CColor^, sysvar.dwg.DWG_CLinew^, PEProp.lvertex1, wc);
2438                                                    PCreatedGDBLine^.Formatentity(drawings.GetCurrentDWG^,dc);
2439                                                    PEProp.nearestline:=PEProp.nearestvertex;
2440                                                    PEProp.dir:=-1;
2441                                               end
2442                                               else if PEProp.nearestvertex=p3dpl^.vertexarrayinwcs.Count-1 then
2443                                               begin
2444                                                    PCreatedGDBLine := PGDBObjLine(ENTF_CreateLine(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[PEProp.lvertex2.x,PEProp.lvertex2.y,PEProp.lvertex2.z,wc.x,wc.y,wc.z]));
2445                                                    zcSetEntPropFromCurrentDrawingProp(PCreatedGDBLine);
2446                                                    //PCreatedGDBLine := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateInitObj(GDBLineID,drawings.GetCurrentROOT));
2447                                                    //GDBObjSetLineProp(PCreatedGDBLine,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer,sysvar.dwg.DWG_CLType^,sysvar.dwg.DWG_CColor^, sysvar.dwg.DWG_CLinew^, PEProp.lvertex2, wc);
2448                                                    PCreatedGDBLine^.Formatentity(drawings.GetCurrentDWG^,dc);
2449                                                    PEProp.nearestline:=PEProp.nearestvertex;
2450                                                    PEProp.dir:=1;
2451                                               end
2452 
2453                                          end;
2454                                      end;
2455   if (PEProp.Action=TSPE_Scissor) then
2456   begin
2457   if PEProp.vdist>PEProp.ldist+bigeps then
2458                                    begin
2459                                         _tv:=NearestPointOnSegment(wc,PEProp.lvertex1,PEProp.lvertex2);
2460                                         pc := PGDBObjCircle(ENTF_CreateCircle(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[_tv.x,_tv.y,_tv.z,10*drawings.GetCurrentDWG^.pcamera^.prop.zoom]));
2461                                         zcSetEntPropFromCurrentDrawingProp(pc);
2462                                         //pc := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateInitObj(GDBCircleID,drawings.GetCurrentROOT));
2463                                         //GDBObjSetCircleProp(pc,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer,sysvar.dwg.DWG_CLType^,sysvar.dwg.DWG_CColor^, sysvar.dwg.DWG_CLinew^, _tv, 10*drawings.GetCurrentDWG^.pcamera^.prop.zoom);
2464                                         pc^.Formatentity(drawings.GetCurrentDWG^,dc);
2465 
2466                                         PCreatedGDBLine := PGDBObjLine(ENTF_CreateLine(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[_tv.x,_tv.y,_tv.z,wc.x,wc.y,wc.z]));
2467                                         zcSetEntPropFromCurrentDrawingProp(PCreatedGDBLine);
2468                                         //PCreatedGDBLine := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateInitObj(GDBLineID,drawings.GetCurrentROOT));
2469                                         //GDBObjSetLineProp(PCreatedGDBLine,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer,sysvar.dwg.DWG_CLType^,sysvar.dwg.DWG_CColor^, sysvar.dwg.DWG_CLinew^, _tv, wc);
2470 
2471                                         //PCreatedGDBLine := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateObj(GDBLineID,drawings.GetCurrentROOT));
2472                                         //GDBObjLineInit(drawings.GetCurrentROOT,PCreatedGDBLine,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer, sysvar.dwg.DWG_CLinew^, _tv, wc);
2473                                         PCreatedGDBLine^.Formatentity(drawings.GetCurrentDWG^,dc);
2474                                    end
2475                                else
2476                                begin
2477                                    pc := PGDBObjCircle(ENTF_CreateCircle(@drawings.GetCurrentDWG^.ConstructObjRoot,@drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray,[PEProp.vvertex.x,PEProp.vvertex.y,PEProp.vvertex.z,40*drawings.GetCurrentDWG^.pcamera^.prop.zoom]));
2478                                    zcSetEntPropFromCurrentDrawingProp(pc);
2479                                    //pc := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateInitObj(GDBCircleID,drawings.GetCurrentROOT));
2480                                    //GDBObjSetCircleProp(pc,drawings.GetCurrentDWG^.LayerTable.GetCurrentLayer,sysvar.dwg.DWG_CLType^,sysvar.dwg.DWG_CColor^, sysvar.dwg.DWG_CLinew^, PEProp.vvertex, 40*drawings.GetCurrentDWG^.pcamera^.prop.zoom);
2481                                    pc^.Formatentity(drawings.GetCurrentDWG^,dc);
2482                                end
2483 
2484   end;
2485   if (button and MZW_LBUTTON)<>0 then
2486   begin
2487        if (PEProp.Action=TSPE_Remove)and(PEProp.nearestvertex<>-1) then
2488                                         begin
2489                                              if p3dpl^.vertexarrayinocs.Count>2 then
2490                                              begin
2491                                                   polydata.index:=PEProp.nearestvertex;
2492                                                   if PEProp.nearestvertex=p3dpl^.vertexarrayinocs.GetCount then
2493                                                                                 polydata.index:=polydata.index+1;
2494                                                   {polydata.nearestvertex:=PEProp.nearestvertex;
2495                                                   polydata.nearestline:=polydata.nearestvertex;
2496                                                   polydata.dir:=PEProp.dir;
2497                                                   polydata.dir:=-1;
2498                                                   if PEProp.nearestvertex=0 then
2499                                                                                 polydata.dir:=-1;
2500                                                   if PEProp.nearestvertex=p3dpl^.vertexarrayinocs.GetCount then
2501                                                                                 polydata.dir:=1;}
2502                                                   polydata.wc:=PEProp.vvertex;
2503                                                   domethod:=tmethod(@p3dpl^.DeleteVertex);
2504                                                   {tmethod(domethod).Code:=pointer(p3dpl.DeleteVertex);
2505                                                   tmethod(domethod).Data:=p3dpl;}
2506                                                   undomethod:=tmethod(@p3dpl^.InsertVertex);
2507                                                   {tmethod(undomethod).Code:=pointer(p3dpl.InsertVertex);
2508                                                   tmethod(undomethod).Data:=p3dpl;}
2509                                                   with PushCreateTGObjectChangeCommand2(PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack,polydata,tmethod(domethod),tmethod(undomethod))^ do
2510                                                   begin
2511                                                        comit;
2512                                                   end;
2513 
2514 
2515 
2516 
2517                                                   //p3dpl^.vertexarrayinocs.DeleteElement(PEProp.nearestvertex);
2518                                                   p3dpl^.YouChanged(drawings.GetCurrentDWG^);
2519                                                   drawings.GetCurrentROOT^.FormatAfterEdit(drawings.GetCurrentDWG^,dc);
2520                                                   //p3dpl^.Format;
2521                                                   zcRedrawCurrentDrawing;
2522                                              end
2523                                              else
2524                                                  ZCMsgCallBackInterface.TextMessage(rscm2VNotRemove,TMWOHistoryOut);
2525                                         end;
2526        if (PEProp.Action=TSPE_Insert)and(PEProp.nearestline<>-1)and(PEProp.dir<>0) then
2527                                         begin
2528                                              if (PEProp.setpoint)or(PEProp.Mode=TPEM_Nearest) then
2529                                                                     begin
2530                                                                          polydata.{nearestvertex}index:=PEProp.nearestline;
2531                                                                          if PEProp.dir=1 then
2532                                                                                       inc(polydata.{nearestvertex}index);
2533                                                                          //polydata.nearestline:=PEProp.nearestline;
2534                                                                          //polydata.dir:=PEProp.dir;
2535                                                                          polydata.wc:=wc;
2536                                                                          domethod:=tmethod(@p3dpl^.InsertVertex);
2537                                                                          {tmethod(domethod).Code:=pointer(p3dpl.InsertVertex);
2538                                                                          tmethod(domethod).Data:=p3dpl;}
2539                                                                          undomethod:=tmethod(@p3dpl^.DeleteVertex);
2540                                                                          {tmethod(undomethod).Code:=pointer(p3dpl.DeleteVertex);
2541                                                                          tmethod(undomethod).Data:=p3dpl;}
2542                                                                          with PushCreateTGObjectChangeCommand2(PTZCADDrawing(drawings.GetCurrentDWG)^.UndoStack,polydata,tmethod(domethod),tmethod(undomethod))^ do
2543                                                                          begin
2544                                                                               comit;
2545                                                                          end;
2546 
2547                                                                          //p3dpl^.vertexarrayinocs.InsertElement(PEProp.nearestline,PEProp.dir,@wc);
2548                                                                          p3dpl^.YouChanged(drawings.GetCurrentDWG^);
2549                                                                          drawings.GetCurrentROOT^.FormatAfterEdit(drawings.GetCurrentDWG^,dc);
2550                                                                          //p3dpl^.Format;
2551                                                                          zcRedrawCurrentDrawing;
2552                                                                          PEProp.setpoint:=false;
2553                                                                     end
2554                                                                 else
2555                                                                     begin
2556                                                                          PEProp.setpoint:=true;
2557                                                                     end;
2558 
2559 
2560                                         end;
2561 
2562        if (PEProp.Action=TSPE_Scissor) then
2563        begin
2564        if PEProp.vdist>PEProp.ldist+bigeps then
2565                                         begin
2566                                         p3dpl2 := pointer(p3dpl^.Clone(p3dpl^.bp.ListPos.Owner));
2567                                         drawings.GetCurrentROOT^.AddObjectToObjArray(@p3dpl2);
2568                                         _tv:=NearestPointOnSegment(wc,PEProp.lvertex1,PEProp.lvertex2);
2569                                         for i:=0 to p3dpl^.VertexArrayInOCS.count-1 do
2570                                           begin
2571                                                if i<PEProp.nearestline then
2572                                                                              p3dpl2^.VertexArrayInOCS.DeleteElement(0);
2573                                                if i>PEProp.nearestline-1 then
2574                                                                              p3dpl^.VertexArrayInOCS.DeleteElement(PEProp.nearestline{+1});
2575 
2576                                           end;
2577                                         (*if p3dpl2^.VertexArrayInOCS.Count>1 then
2578                                                                                p3dpl2^.VertexArrayInOCS.InsertElement({0}1,{1,}_tv)
2579                                                                            else*)
2580                                                                                p3dpl2^.VertexArrayInOCS.InsertElement(0,{-1,}_tv);
2581                                         p3dpl^.VertexArrayInOCS.InsertElement(p3dpl^.VertexArrayInOCS.Count,{1,}_tv);
2582                                         p3dpl2^.Formatentity(drawings.GetCurrentDWG^,dc);
2583                                         p3dpl^.Formatentity(drawings.GetCurrentDWG^,dc);
2584                                         drawings.GetCurrentROOT^.ObjArray.ObjTree.CorrectNodeBoundingBox(p3dpl2^);
2585                                         end
2586                                     else
2587                                     begin
2588                                          if (PEProp.nearestvertex=0)or(PEProp.nearestvertex=p3dpl^.VertexArrayInOCS.Count-1) then
2589                                          begin
2590                                               ZCMsgCallBackInterface.TextMessage(rscmNotCutHere,TMWOShowError);
2591                                               exit;
2592                                          end;
2593                                          p3dpl2 := pointer(p3dpl^.Clone(p3dpl^.bp.ListPos.Owner));
2594                                          drawings.GetCurrentROOT^.AddObjectToObjArray(@p3dpl2);
2595 
2596                                          for i:=0 to p3dpl^.VertexArrayInOCS.count-1 do
2597                                            begin
2598                                                 if i<PEProp.nearestvertex then
2599                                                                               p3dpl2^.VertexArrayInOCS.DeleteElement(0);
2600                                                 if i>PEProp.nearestvertex then
2601                                                                               p3dpl^.VertexArrayInOCS.DeleteElement(PEProp.nearestvertex+1);
2602 
2603                                            end;
2604                                          p3dpl2^.Formatentity(drawings.GetCurrentDWG^,dc);
2605                                          p3dpl^.Formatentity(drawings.GetCurrentDWG^,dc);
2606                                          drawings.GetCurrentROOT^.ObjArray.ObjTree.CorrectNodeBoundingBox(p3dpl2^);
2607                                     end
2608 
2609        end;
2610       zcRedrawCurrentDrawing;
2611       //drawings.GetCurrentDWG^.OGLwindow1.draw;
2612 
2613   end
2614 end;
2615 
2616 {function _3DPolyEd_com_AfterClick(wc: GDBvertex; mc: GDBvertex2DI; button: GDBByte;osp:pos_record;mclick:GDBInteger): GDBInteger;
2617 var po:PGDBObjSubordinated;
2618 begin
2619   exit;
2620   result:=mclick;
2621   p3dpl^.vp.Layer :=drawings.LayerTable.GetCurrentLayer;
2622   p3dpl^.vp.lineweight := sysvar.dwg.DWG_CLinew^;
2623   //p3dpl^.CoordInOCS.lEnd:= wc;
2624   p3dpl^.Format;
2625   if button = 1 then
2626   begin
2627     p3dpl^.AddVertex(wc);
2628     p3dpl^.RenderFeedback;
2629     drawings.GetCurrentDWG^.ConstructObjRoot.Count := 0;
2630     result:=1;
2631     redrawoglwnd;
2632   end;
2633 end;}
Insert2_comnull2634 function Insert2_com(operands:TCommandOperands):TCommandResult;
2635 var
2636     s:gdbstring;
2637 begin
2638      if commandmanager.ContextCommandParams<>nil then
2639      begin
2640      if PGDBString(commandmanager.ContextCommandParams)^<>'' then
2641      begin
2642           s:=PGDBString(commandmanager.ContextCommandParams)^;
2643           commandmanager.executecommandend;
2644           s:='Insert('+s+')';
2645           commandmanager.executecommand(s,drawings.GetCurrentDWG,drawings.GetCurrentOGLWParam);
2646           result:=ZCMD_OK_NOEND;
2647      end;
2648      end
2649         else
2650             ZCMsgCallBackInterface.TextMessage(rscmCommandOnlyCTXMenu,TMWOHistoryOut);
2651 end;
2652 procedure ITT_com.Command(Operands:TCommandOperands);
2653 var //pv:pGDBObjEntity;
2654     pt:PGDBObjTable;
2655     //pleader:PGDBObjElLeader;
2656     //ir:itrec;
2657     //psl:PTZctnrVectorGDBString;
2658     //i,j:integer;
2659     //s:gdbstring;
2660     dc:TDrawContext;
2661 begin
2662   drawings.GetCurrentDWG^.wa.SetMouseMode((MGet3DPoint) or (MMoveCamera) or (MRotateCamera));
2663 
2664   GDBGetMem({$IFDEF DEBUGBUILD}'{743A21EB-4741-42A4-8CB2-D4E4A1E2EAF8}',{$ENDIF}pointer(pt),sizeof(GDBObjTable));
2665   pt^.initnul;
2666   pt^.bp.ListPos.Owner:=@drawings.CurrentDWG^.ConstructObjRoot;
2667   drawings.CurrentDWG^.ConstructObjRoot.ObjArray.AddPEntity(pt^);
2668 
2669   pt^.ptablestyle:=drawings.GetCurrentDWG^.TableStyleTable.getAddres('ShRaspr');
2670   pt^.tbl.free;
2671   dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
2672 
2673 
2674   {for j := 1 to 10 do
2675   begin
2676   psl:=pointer(pt^.tbl.CreateObject);
2677   psl^.init(16);
2678     for i := 1 to 16 do
2679       begin
2680            s:=inttostr(i);
2681            psl^.AddByPointer(@s);
2682       end;
2683   end;}
2684 
2685   pt^.Build(drawings.GetCurrentDWG^);
2686   pt^.FormatEntity(drawings.GetCurrentDWG^,dc);
2687 
2688   //drawings.GetCurrentROOT^.getoutbound;
2689   //redrawoglwnd;
2690 end;
2691 procedure bedit_format(_self:pointer);
2692 var
2693    nname:gdbstring;
2694 begin
2695      nname:=(BEditParam.Blocks.Enums.getData(BEditParam.Blocks.Selected));
2696      if nname<>BEditParam.CurrentEditBlock then
2697      begin
2698           BEditParam.CurrentEditBlock:=nname;
2699           if nname<>modelspacename then
2700                                       drawings.GetCurrentDWG^.pObjRoot:=drawings.GetCurrentDWG^.BlockDefArray.getblockdef(Tria_Utf8ToAnsi(nname))
2701                                   else
2702                                       drawings.GetCurrentDWG^.pObjRoot:=@drawings.GetCurrentDWG^.mainObjRoot;
2703           ZCMsgCallBackInterface.Do_GUIaction(nil,ZMsgID_GUIActionRedraw);
2704           //if assigned(UpdateVisibleProc) then UpdateVisibleProc(ZMsgID_GUIActionRedraw);
2705           zcRedrawCurrentDrawing;
2706      end;
2707 end;
bedit_comnull2708 function bedit_com(operands:TCommandOperands):TCommandResult;
2709 var
2710    i:integer;
2711    sd:TSelEntsDesk;
2712    tn:gdbstring;
2713 begin
2714      tn:=operands;
2715      sd:=zcGetSelEntsDeskInCurrentRoot;
2716      if (sd.PFirstSelectedEnt<>nil)and(sd.SelectedEntsCount=1) then
2717      begin
2718     if (sd.PFirstSelectedEnt^.GetObjType=GDBBlockInsertID) then
2719     begin
2720          tn:=PGDBObjBlockInsert(sd.PFirstSelectedEnt)^.name;
2721     end
2722 else if (sd.PFirstSelectedEnt^.GetObjType=GDBDeviceID) then
2723     begin
2724          tn:=DevicePrefix+PGDBObjBlockInsert(sd.PFirstSelectedEnt)^.name;
2725     end;
2726      end;
2727 
2728      BEditParam.Blocks.Enums.free;
2729      i:=GetBlockDefNames(BEditParam.Blocks.Enums,tn);
2730      BEditParam.Blocks.Enums.PushBackData(modelspacename);
2731      if BEditParam.CurrentEditBlock=modelspacename then
2732        begin
2733             BEditParam.Blocks.Selected:=BEditParam.Blocks.Enums.Count-1;
2734        end;
2735      if (tn='')and(drawings.GetCurrentDWG^.pObjRoot<>@drawings.GetCurrentDWG^.mainObjRoot) then
2736                                                                                    begin
2737                                                                                         tn:=modelspacename;
2738                                                                                         BEditParam.Blocks.Selected:=BEditParam.Blocks.Enums.Count-1;
2739                                                                                    end;
2740      if BEditParam.Blocks.Enums.Count>0 then
2741      begin
2742           //BEditParam.Blocks.Enums.add(@modelspacename);
2743           if i>0 then
2744                      BEditParam.Blocks.Selected:=i
2745                  else
2746                      if length(operands)<>0 then
2747                                          begin
2748                                                ZCMsgCallBackInterface.TextMessage('BEdit:'+format(rscmNoBlockDefInDWG,[operands]),TMWOHistoryOut);
2749                                                commandmanager.executecommandend;
2750                                                exit;
2751                                          end;
2752           ZCMsgCallBackInterface.Do_PrepareObject(nil,drawings.GetUnitsFormat,SysUnit^.TypeName2PTD('CommandRTEdObject'),pbeditcom,drawings.GetCurrentDWG);
2753           drawings.GetCurrentDWG^.SelObjArray.Free;
2754           drawings.GetCurrentROOT^.ObjArray.DeSelect(drawings.GetCurrentDWG^.wa.param.SelDesc.Selectedobjcount,@drawings.GetCurrentDWG^.deselector);
2755           result:=cmd_ok;
2756           zcRedrawCurrentDrawing;
2757           if tn<>'' then
2758                         bedit_format(nil);
2759      end
2760         else
2761             begin
2762                  ZCMsgCallBackInterface.TextMessage('BEdit:'+rscmInDwgBlockDefNotDeffined,TMWOHistoryOut);
2763                  commandmanager.executecommandend;
2764             end;
2765 
2766 
2767 
2768   exit;
2769   ZCMsgCallBackInterface.Do_PrepareObject(nil,drawings.GetUnitsFormat,SysUnit^.TypeName2PTD('CommandRTEdObject'),pbeditcom,drawings.GetCurrentDWG);
2770   drawings.GetCurrentDWG^.SelObjArray.Free;
2771   drawings.GetCurrentROOT^.ObjArray.DeSelect(drawings.GetCurrentDWG^.wa.param.SelDesc.Selectedobjcount,@drawings.GetCurrentDWG^.deselector);
2772   result:=cmd_ok;
2773   zcRedrawCurrentDrawing;
2774 end;
PlaceAllBlocks_comnull2775 function PlaceAllBlocks_com(operands:TCommandOperands):TCommandResult;
2776 var pb:PGDBObjBlockdef;
2777     ir:itrec;
2778     xcoord:GDBDouble;
2779     BLinsert,tb:PGDBObjBlockInsert;
2780     dc:TDrawContext;
2781 begin
2782      pb:=drawings.GetCurrentDWG^.BlockDefArray.beginiterate(ir);
2783      xcoord:=0;
2784      if pb<>nil then
2785      repeat
2786            ZCMsgCallBackInterface.TextMessage(pb^.name,TMWOHistoryOut);
2787 
2788 
2789     BLINSERT := GDBPointer(drawings.GetCurrentDWG^.ConstructObjRoot.ObjArray.CreateObj(GDBBlockInsertID{,drawings.GetCurrentROOT}));
2790     PGDBObjBlockInsert(BLINSERT)^.initnul;//(@drawings.GetCurrentDWG^.ObjRoot,drawings.LayerTable.GetSystemLayer,0);
2791     PGDBObjBlockInsert(BLINSERT)^.init(drawings.GetCurrentROOT,drawings.GetCurrentDWG^.GetCurrentLayer,0);
2792     BLinsert^.Name:=pb^.name;
2793     BLINSERT^.Local.p_insert.x:=xcoord;
2794     tb:=pointer(BLINSERT^.FromDXFPostProcessBeforeAdd(nil,drawings.GetCurrentDWG^));
2795     if tb<>nil then begin
2796                          tb^.bp:=BLINSERT^.bp;
2797                          BLINSERT^.done;
2798                          gdbfreemem(pointer(BLINSERT));
2799                          BLINSERT:=pointer(tb);
2800     end;
2801     drawings.GetCurrentROOT^.AddObjectToObjArray{ObjArray.add}(addr(BLINSERT));
2802     PGDBObjEntity(BLINSERT)^.FromDXFPostProcessAfterAdd;
2803     BLINSERT^.CalcObjMatrix;
2804     BLINSERT^.BuildGeometry(drawings.GetCurrentDWG^);
2805     BLINSERT^.BuildVarGeometry(drawings.GetCurrentDWG^);
2806     dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
2807     BLINSERT^.FormatEntity(drawings.GetCurrentDWG^,dc);
2808     BLINSERT^.Visible:=0;
2809     BLINSERT^.RenderFeedback(drawings.GetCurrentDWG^.pcamera^.POSCOUNT,drawings.GetCurrentDWG^.pcamera^,@drawings.GetCurrentDWG^.myGluProject2,dc);
2810     //BLINSERT:=nil;
2811     //commandmanager.executecommandend;
2812 
2813            pb:=drawings.GetCurrentDWG^.BlockDefArray.iterate(ir);
2814            xcoord:=xcoord+20;
2815      until pb=nil;
2816 
2817     zcRedrawCurrentDrawing;
2818 
2819     result:=cmd_ok;
2820 
2821 end;
BlocksList_comnull2822 function BlocksList_com(operands:TCommandOperands):TCommandResult;
2823 var pb:PGDBObjBlockdef;
2824     ir:itrec;
2825 begin
2826      pb:=drawings.GetCurrentDWG^.BlockDefArray.beginiterate(ir);
2827      if pb<>nil then
2828      repeat
2829            ZCMsgCallBackInterface.TextMessage(format('Found block "%s", contains %d entities',[Tria_AnsiToUtf8(pb^.name),pb^.ObjArray.Count]),TMWOHistoryOut);
2830 
2831 
2832            pb:=drawings.GetCurrentDWG^.BlockDefArray.iterate(ir);
2833      until pb=nil;
2834 
2835     result:=cmd_ok;
2836 
2837 end;
2838 
2839 procedure PlacePoint(const point:GDBVertex);inline;
2840 var
2841     PCreatedGDBPoint:PGDBobjPoint;
2842     dc:TDrawContext;
2843 begin
2844     PCreatedGDBPoint := GDBPointer(drawings.GetCurrentDWG^.mainObjRoot.ObjArray.CreateInitObj(GDBPointID,drawings.GetCurrentROOT));
2845     PCreatedGDBPoint^.P_insertInOCS:=point;
2846     PCreatedGDBPoint^.vp.layer:=drawings.GetCurrentDWG^.GetCurrentLayer;
2847     dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
2848     PCreatedGDBPoint^.FormatEntity(drawings.GetCurrentDWG^,dc);
2849 end;
2850 
2851 procedure CheckIntersection(pl1,pl2:PGDBObjLine;var linelinetests,intersectcount:integer;pparray:PGDBPoint3dArray;LinesMap:MapPointOnCurve3DPropArray;var lineiterator:MapPointOnCurve3DPropArray.TIterator);
2852 var
2853     IP:Intercept3DProp;
2854     lineiterator2:MapPointOnCurve3DPropArray.TIterator;
2855 begin
2856       inc(linelinetests);
2857       IP:=pl2^.IsIntersect_Line(pl1^.CoordInWCS.lBegin,pl1^.CoordInWCS.lEnd);
2858       if ip.isintercept then
2859       begin
2860            inc(intersectcount);
2861            pparray^.PushBackData(ip.interceptcoord);
2862            if lineiterator=nil then
2863                                    begin
2864                                         lineiterator:=LinesMap.InsertAndGetIterator(pl1,PointOnCurve3DPropArray.Create);
2865                                    end;
2866            lineiterator.value.PushBack(IP.t1);
2867 
2868            lineiterator2:=LinesMap.Find(pl2);
2869            if lineiterator2=nil then
2870                                    begin
2871                                         lineiterator2:=LinesMap.InsertAndGetIterator(pl2,PointOnCurve3DPropArray.Create);
2872                                    end;
2873            lineiterator2.value.PushBack(IP.t2);
2874       end;
2875 end;
2876 procedure FindLineIntersectionsInNode(pl:PGDBObjLine;PNode:PTEntTreeNode;var lineAABBtests,linelinetests,intersectcount:integer;pparray:PGDBPoint3dArray;LinesMap:MapPointOnCurve3DPropArray;var lineiterator:MapPointOnCurve3DPropArray.TIterator);
2877 var
2878     ir1:itrec;
2879     pl1:PGDBObjLine;
2880 begin
2881      inc(lineAABBtests);
2882      if boundingintersect(pl^.vp.BoundingBox,PNode^.BoundingBox) then
2883      begin
2884            pl1:=PNode^.nulbeginiterate(ir1);
2885            if pl1<>nil then
2886            repeat
2887                  CheckIntersection(pl,pl1,linelinetests,intersectcount,pparray,LinesMap,lineiterator);
2888 
2889                  pl1:=PNode^.nuliterate(ir1);
2890            until pl1=nil;
2891 
2892            if PNode^.pplusnode<>nil then
2893                                         FindLineIntersectionsInNode(pl,PTEntTreeNode(PNode^.pplusnode),lineAABBtests,linelinetests,intersectcount,pparray,LinesMap,lineiterator);
2894            if PNode^.pminusnode<>nil then
2895                                         FindLineIntersectionsInNode(pl,PTEntTreeNode(PNode^.pminusnode),lineAABBtests,linelinetests,intersectcount,pparray,LinesMap,lineiterator);
2896 
2897      end;
2898 end;
2899 
2900 procedure FindAllIntersectionsInNode(PNode:PTEntTreeNode;var lineAABBtests,linelinetests,intersectcount:integer;pparray:PGDBPoint3dArray;LinesMap:MapPointOnCurve3DPropArray);
2901 var
2902     ir1,ir2:itrec;
2903     pl1,pl2:PGDBObjLine;
2904     lineiterator:MapPointOnCurve3DPropArray.TIterator;
2905 begin
2906      pl1:=PNode^.nulbeginiterate(ir1);
2907      if pl1<>nil then
2908      repeat
2909            lineiterator:=LinesMap.Find(pl1);
2910            ir2:=ir1;
2911            pl2:=PNode^.nuliterate(ir2);
2912            if pl2<>nil then
2913            repeat
2914                  CheckIntersection(pl1,pl2,linelinetests,intersectcount,pparray,LinesMap,lineiterator);
2915 
2916                  pl2:=PNode^.nuliterate(ir2);
2917            until pl2=nil;
2918 
2919            if PNode^.pplusnode<>nil then
2920                                         FindLineIntersectionsInNode(pl1,PTEntTreeNode(PNode^.pplusnode),lineAABBtests,linelinetests,intersectcount,pparray,LinesMap,lineiterator);
2921            if PNode^.pminusnode<>nil then
2922                                         FindLineIntersectionsInNode(pl1,PTEntTreeNode(PNode^.pminusnode),lineAABBtests,linelinetests,intersectcount,pparray,LinesMap,lineiterator);
2923 
2924            pl1:=PNode^.nuliterate(ir1);
2925      until pl1=nil;
2926      //else
2927          begin
2928                if PNode^.pplusnode<>nil then
2929                                             FindAllIntersectionsInNode(PTEntTreeNode(PNode^.pplusnode),lineAABBtests,linelinetests,intersectcount,pparray,LinesMap);
2930                if PNode^.pminusnode<>nil then
2931                                             FindAllIntersectionsInNode(PTEntTreeNode(PNode^.pminusnode),lineAABBtests,linelinetests,intersectcount,pparray,LinesMap);
2932          end;
2933 end;
2934 procedure PlaceLines(LinesMap:MapPointOnCurve3DPropArray;var lm,lcr:integer);inline;
2935 var
2936     //PCreatedGDBPoint:PGDBobjPoint;
2937     lineiterator:MapPointOnCurve3DPropArray.TIterator;
2938     pl,PCreatedGDBLine:PGDBObjLine;
2939     LC:GDBLineProp;
2940     arr:PointOnCurve3DPropArray;
2941     point,point2:gdbvertex;
2942     i:integer;
2943     dc:TDrawContext;
2944 begin
2945       lineiterator:=LinesMap.Min;
2946       dc:=drawings.GetCurrentDWG^.CreateDrawingRC;
2947       if lineiterator<>nil then
2948       repeat
2949             arr:=lineiterator.Value;
2950             if arr.Size>0 then
2951             begin
2952                  pl:=lineiterator.key;
2953                  PointOnCurve3DPropArraySort.Sort(arr,arr.size);
2954                  lc:=pl^.CoordInOCS;
2955                  point:=uzegeometry.Vertexmorph(lc.lBegin,lc.lEnd,arr[0]);
2956                  pl^.CoordInOCS.lend:=point;
2957                  pl^.FormatEntity(drawings.GetCurrentDWG^,dc);
2958                  inc(lm);
2959                  for i:=1 to arr.size-1 do
2960                  begin
2961                       point2:=uzegeometry.Vertexmorph(lc.lBegin,lc.lEnd,arr[i]);
2962 
2963                       begin
2964                           PCreatedGDBLine := GDBPointer(drawings.GetCurrentDWG^.mainObjRoot.ObjArray.CreateInitObj(GDBLineID,drawings.GetCurrentROOT));
2965                           PCreatedGDBLine^.vp:=pl^.vp;
2966                           PCreatedGDBLine^.CoordInOCS.lbegin:=point;
2967                           PCreatedGDBLine^.CoordInOCS.lend:=point2;
2968                           PCreatedGDBLine^.FormatEntity(drawings.GetCurrentDWG^,dc);
2969                           inc(lcr);
2970                       end;
2971 
2972                       point:=point2;
2973                  end;
2974 
2975                  PCreatedGDBLine := GDBPointer(drawings.GetCurrentDWG^.mainObjRoot.ObjArray.CreateInitObj(GDBLineID,drawings.GetCurrentROOT));
2976                  PCreatedGDBLine^.vp:=pl^.vp;
2977                  PCreatedGDBLine^.CoordInOCS.lbegin:=point;
2978                  PCreatedGDBLine^.CoordInOCS.lend:=lc.lEnd;
2979                  PCreatedGDBLine^.FormatEntity(drawings.GetCurrentDWG^,dc);
2980                  inc(lcr);
2981 
2982 
2983             end;
2984       until not lineiterator.next;
2985      //for i:=0 to LinesMap.
2986     {PCreatedGDBPoint := GDBPointer(drawings.GetCurrentDWG^.mainObjRoot.ObjArray.CreateInitObj(GDBPointID,drawings.GetCurrentROOT));
2987     PCreatedGDBPoint^.P_insertInOCS:=point;
2988     PCreatedGDBPoint^.FormatEntity(drawings.GetCurrentDWG^);}
2989 end;
FindAllIntersections_comnull2990 function FindAllIntersections_com(operands:TCommandOperands):TCommandResult;
2991 var
2992     lineAABBtests,linelinetests,intersectcount,lm,lc:integer;
2993     parray:GDBPoint3dArray;
2994     pv:PGDBVertex;
2995     ir:itrec;
2996     LinesMap:MapPointOnCurve3DPropArray;
2997     lph:TLPSHandle;
2998     //PointOnCurve3DPropArray=specialize TVector<PointOnCurve3DProp>;
2999     //MapPointOnCurve3DPropArray=specialize TMap<PGDBObjLine,PointOnCurve3DPropArray, lessppi>;
3000 begin
3001      intersectcount:=0;
3002      linelinetests:=0;
3003      lineAABBtests:=0;
3004      lm:=0;
3005      lc:=0;
3006      parray.init({$IFDEF DEBUGBUILD}'{527C1C8F-E832-43F9-B8C4-2733AD9EAF67}',{$ENDIF}10000);
3007      LinesMap:=MapPointOnCurve3DPropArray.Create;
3008      lph:=lps.StartLongProcess(10,'Search intersections and storing data',nil);
3009      FindAllIntersectionsInNode(@drawings.GetCurrentDWG^.pObjRoot^.ObjArray.ObjTree,lineAABBtests,linelinetests,intersectcount,@parray,LinesMap);
3010      lps.EndLongProcess(lph);
3011 
3012      lph:=lps.StartLongProcess(10,'Placing points',nil);
3013        pv:=parray.beginiterate(ir);
3014        if pv<>nil then
3015        repeat
3016              PlacePoint(pv^);
3017              pv:=parray.iterate(ir);
3018        until pv=nil;
3019      lps.EndLongProcess(lph);
3020 
3021      lph:=lps.StartLongProcess(10,'Cutting lines',nil);
3022       PlaceLines(LinesMap,lm,lc);
3023      lps.EndLongProcess(lph);
3024      ZCMsgCallBackInterface.TextMessage('Lines modified: '+inttostr(lm),TMWOHistoryOut);
3025      ZCMsgCallBackInterface.TextMessage('Lines created: '+inttostr(lc),TMWOHistoryOut);
3026 
3027 
3028 
3029      lph:=lps.StartLongProcess(10,'Freeing memory',nil);
3030      parray.done;
3031      LinesMap.Free;
3032      lps.EndLongProcess(lph);
3033      ZCMsgCallBackInterface.TextMessage('Line-AABB tests count: '+inttostr(lineAABBtests),TMWOHistoryOut);
3034      ZCMsgCallBackInterface.TextMessage('Line-Line tests count: '+inttostr(linelinetests),TMWOHistoryOut);
3035      ZCMsgCallBackInterface.TextMessage('Intersections count: '+inttostr(intersectcount),TMWOHistoryOut);
3036      result:=cmd_ok;
3037 end;
3038 
3039 procedure startup;
3040 begin
3041   BIProp.Blocks.Enums.init(100);
3042   BIProp.Scale:=uzegeometry.OneVertex;
3043   BIProp.Rotation:=0;
3044   PEProp.Action:=TSPE_Insert;
3045 
3046   CreateCommandRTEdObjectPlugin(@Circle_com_CommandStart,@Circle_com_CommandEnd,nil,nil,@Circle_com_BeforeClick,@Circle_com_AfterClick,nil,nil,'Circle2',0,0);
3047   CreateCommandRTEdObjectPlugin(@Line_com_CommandStart,@Line_com_CommandEnd,nil,nil,@Line_com_BeforeClick,@Line_com_AfterClick,nil,nil,'Line',0,0);
3048   CreateCommandRTEdObjectPlugin(@_3DPolyEd_com_CommandStart,nil,nil,nil,@_3DPolyEd_com_BeforeClick,@_3DPolyEd_com_BeforeClick,nil,nil,'PolyEd',0,0);
3049   CreateCommandRTEdObjectPlugin(@Insert_com_CommandStart,@Insert_com_CommandEnd,nil,nil,@Insert_com_BeforeClick,@Insert_com_BeforeClick,nil,nil,'Insert',0,0);
3050 
3051   copy.init('Copy',0,0);
3052   mirror.init('Mirror',0,0);
3053   mirror.SetCommandParam(@MirrorParam,'PTMirrorParam');
3054   move.init('Move',0,0);
3055   rotate.init('Rotate',0,0);
3056   rotate.NotUseCommandLine:=false;
3057   scale.init('Scale',0,0);
3058   scale.NotUseCommandLine:=false;
3059   copybase.init('CopyBase',CADWG or CASelEnts,0);
3060   PasteClip.init('PasteClip',0,0);
3061 
3062   TextInsert.init('Text',0,0);
3063   TextInsertParams.Style.Enums.init(10);
3064   TextInsertParams.Style.Selected:=0;
3065   TextInsertParams.h:=2.5;
3066   TextInsertParams.Oblique:=0;
3067   TextInsertParams.WidthFactor:=1;
3068   TextInsertParams.justify:=uzbtypes.jstl;
3069   TextInsertParams.text:='text';
3070   TextInsertParams.runtexteditor:=false;
3071   TextInsertParams.Width:=100;
3072   TextInsertParams.LineSpace:=1;
3073   TextInsert.SetCommandParam(@TextInsertParams,'PTTextInsertParams');
3074 
3075   BlockReplace.init('BlockReplace',0,0);
3076   BlockReplaceParams.Find.Enums.init(10);
3077   BlockReplaceParams.Replace.Enums.init(10);
3078   BlockReplaceParams.Process:=BRM_Device;
3079   BlockReplaceParams.SaveVariables:=true;
3080   BlockReplaceParams.SaveVariablePart:=true;
3081   BlockReplaceParams.SaveOrientation:=true;
3082   BlockReplace.SetCommandParam(@BlockReplaceParams,'PTBlockReplaceParams');
3083 
3084 
3085   CreateCommandFastObjectPlugin(@Erase_com,'Erase',CADWG,0);
3086   CreateCommandFastObjectPlugin(@CutClip_com,'CutClip',CADWG or CASelEnts,0);
3087   CreateCommandFastObjectPlugin(@Insert2_com,'Insert2',CADWG,0);
3088   CreateCommandFastObjectPlugin(@PlaceAllBlocks_com,'PlaceAllBlocks',CADWG,0);
3089   CreateCommandFastObjectPlugin(@BlocksList_com,'BlocksList',CADWG,0);
3090   CreateCommandFastObjectPlugin(@InverseSelected_com,'InverseSelected',CADWG or CASelEnts,0);
3091   //CreateCommandFastObjectPlugin(@bedit_com,'BEdit');
3092   pbeditcom:=CreateCommandRTEdObjectPlugin(@bedit_com,nil,nil,@bedit_format,nil,nil,nil,nil,'BEdit',0,0);
3093   BEditParam.Blocks.Enums.init(100);
3094   BEditParam.CurrentEditBlock:=modelspacename;
3095   pbeditcom^.SetCommandParam(@BEditParam,'PTBEditParam');
3096 
3097   ATO.init('AddToOwner',CADWG,0);
3098   CFO.init('CopyFromOwner',CADWG,0);
3099 
3100   NumberingParams.BaseName:='??';
3101   NumberingParams.Increment:=1;
3102   NumberingParams.StartNumber:=1;
3103   NumberingParams.SaveStart:=false;
3104   NumberingParams.DeadDand:=10;
3105   NumberingParams.NumberVar:='NMO_Suffix';
3106   NumberingParams.InverseX:=false;
3107   NumberingParams.InverseY:=true;
3108   NumberingParams.SortMode:=TST_YX;
3109   NumberCom.init('NumDevices',CADWG,0);
3110   NumberCom.SetCommandParam(@NumberingParams,'PTNumberingParams');
3111 
3112   ExportDevWithAxisParams.AxisDeviceName:='SPDS_AXIS';
3113   ExportDevWithAxisCom.init('ExportDevWithAxis',CADWG,0);
3114   ExportDevWithAxisCom.SetCommandParam(@ExportDevWithAxisParams,'PTExportDevWithAxisParams');
3115 
3116   BlockScale.init('BlockScale',0,0);
3117   BlockScale.CEndActionAttr:=0;
3118   BlockScaleParams.Scale:=uzegeometry.CreateVertex(1,1,1);
3119   BlockScaleParams.Absolytly:=true;
3120   BlockScale.SetCommandParam(@BlockScaleParams,'PTBlockScaleParams');
3121 
3122   BlockRotate.init('BlockRotate',0,0);
3123   BlockRotate.CEndActionAttr:=0;
3124   BlockRotateParams.Rotate:=0;
3125   BlockRotateParams.Absolytly:=true;
3126   BlockRotate.SetCommandParam(@BlockRotateParams,'PTBlockRotateParams');
3127 
3128 
3129   InsertTestTable.init('InsertTestTable',0,0);
3130   //CreateCommandFastObjectPlugin(@InsertTestTable_com,'InsertTestTable',0,0);
3131 
3132   CreateCommandFastObjectPlugin(@FindAllIntersections_com,'FindAllIntersections',CADWG,0);
3133 end;
3134 procedure Finalize;
3135 begin
3136   BIProp.Blocks.Enums.done;
3137   BEditParam.Blocks.Enums.done;
3138   TextInsertParams.Style.Enums.done;
3139 end;
3140 initialization
3141   startup;
3142 finalization
3143   debugln('{I}[UnitsFinalization] Unit "',{$INCLUDE %FILE%},'" finalization');
3144   finalize;
3145 end.
3146