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 
19 unit uzglviewareageneral;
20 {$INCLUDE def.inc}
21 interface
22 uses
23      gzctnrvectortypes,uzbgeomtypes,LCLProc,uzbmemman,uzemathutils,uzepalette,
24      uzeentsubordinated,uzegeometry,uzbtypesbase,uzbtypes,UGDBSelectedObjArray,
25      uzglviewareadata,uzgldrawcontext,uzeentity,uzedrawingabstract,UGDBPoint3DArray,uzeentitiestree,
26      uzeconsts,uzestrconsts,UGDBTracePropArray,math,sysutils,uzedrawingdef,uzbstrproc,
27      ExtCtrls,Controls,Classes,{$IFDEF DELPHI}Types,{$ENDIF}{$IFNDEF DELPHI}LCLType,{$ENDIF}Forms,
28      UGDBOpenArrayOfPV,uzeentgenericsubentry,uzecamera,UGDBVisibleOpenArray,uzgldrawerabstract,
29      uzgldrawergeneral,uzglviewareaabstract,uzeentitiesprop;
30 const
31   ontracdist=10;
32   ontracignoredist=25;
33 
34 resourcestring
35   rswonlyparalel='Works only for parallel projection!';
36   rswonlytop='Works only for top view!';
37 
38 type
39     TOnActivateProc=Procedure;
40     TCameraChangedNotify=procedure of object;
41     TGeneralViewArea=class(TAbstractViewArea)
42                            public
43                            WorkArea:TCADControl;
44                            InsidePaintMessage:integer;
45 
getviewcontrolnull46                            function getviewcontrol:TCADControl;override;
47 
48 
49                            procedure calcgrid;override;
50                            procedure Clear0Ontrackpoint;override;
51                            procedure ClearOntrackpoint;override;
52                            procedure SetMouseMode(smode:GDBByte);override;
53                            procedure reprojectaxis;override;
54                            procedure Project0Axis;override;
55                            procedure create0axis;override;
56                            procedure ZoomToVolume(Volume:TBoundingBox);override;
57                            procedure ZoomAll;override;
58                            procedure ZoomSel;override;
59                            procedure RotTo(x0,y0,z0:GDBVertex);override;
60                            procedure PanScreen(oldX,oldY,X,Y:Integer);override;
61                            procedure RestoreMouse;override;
62                            procedure myKeyPress(var Key: Word; Shift: TShiftState);override;
ProjectPointnull63                            function ProjectPoint(pntx,pnty,pntz:gdbdouble;var wcsLBN,wcsRTF,dcsLBN,dcsRTF: GDBVertex):gdbvertex;override;
64                            procedure mouseunproject(X, Y: integer);override;
65                            procedure addaxistootrack(var posr:os_record;const axis:GDBVertex);virtual;
66                            procedure projectaxis;override;
67                            procedure CalcOptimalMatrix;override;
68                            procedure SetOGLMatrix;virtual;
69                            procedure CalcMouseFrustum;override;
70                            procedure ProcOTrackTimer(Sender:TObject);override;
71                            procedure KillOTrackTimer(Sender: TObject);override;
72                            procedure SetOTrackTimer(Sender: TObject);override;
73                            procedure KillOHintTimer(Sender: TObject);override;
74                            procedure SetOHintTimer(Sender: TObject);override;
75                            procedure getosnappoint(radius: GDBFloat);override;
76                            procedure getonmouseobject(pva: PGDBObjEntityOpenArray;InSubEntry:GDBBoolean);virtual;
77                            procedure findonmobj(pva: PGDBObjEntityOpenArray; var i: GDBInteger;InSubEntry:GDBBoolean);virtual;
78                            procedure findonmobjTree(var Node:TEntTreeNode; var i: GDBInteger;InSubEntry:GDBBoolean);virtual;
79                            procedure getonmouseobjectbytree(var Node:TEntTreeNode;InSubEntry:GDBBoolean);override;
80                            procedure processmousenode(Node:TEntTreeNode;var i:integer;InSubEntry:GDBBoolean);virtual;
81                            procedure AddOntrackpoint;override;
82                            procedure CorrectMouseAfterOS;override;
CreateRCnull83                            function CreateRC(_maxdetail:GDBBoolean=false):TDrawContext;override;
84                            //procedure sendcoordtocommand(coord:GDBVertex;key: GDBByte);virtual;
85                            //procedure sendmousecoordwop(key: GDBByte);override;
86                            //procedure sendmousecoord(key: GDBByte);override;
87                            procedure asynczoomsel(Data: PtrInt);override;
88                            procedure asynczoomall(Data: PtrInt);override;
89                            procedure asyncupdatemouse(Data: PtrInt);override;
90                            procedure set3dmouse;override;
91                            procedure SetCameraPosZoom(_pos:gdbvertex;_zoom:gdbdouble;finalcalk:gdbboolean);override;
92                            procedure DISP_ZoomFactor(x: double{; MousePos: TPoint});
93                            procedure showmousecursor;override;
94                            procedure hidemousecursor;override;
95                            Procedure Paint; override;
treerendernull96                            function treerender(var Node:TEntTreeNode;StartTime:TDateTime;var DC:TDrawContext):GDBBoolean; override;
97                            procedure render(const Root:GDBObjGenericSubEntry;var DC:TDrawContext); override;
98                            procedure finishdraw(var RC:TDrawContext); override;
99                            procedure draw;override;
100                            procedure DrawOrInvalidate;override;
101                            procedure showcursor(var DC:TDrawContext);override;
102                            procedure DrawCSAxis(var DC:TDrawContext);
103                            procedure SwapBuffers(var DC:TDrawContext);override;
104                            procedure DrawGrid(var DC:TDrawContext);override;
105                            procedure LightOn(var DC:TDrawContext);override;
106                            procedure LightOff(var DC:TDrawContext);override;
107                            procedure GDBActivate;override;
108 
109 
110                            procedure showsnap(var DC:TDrawContext); virtual;
111 
112 
113                            {onЧетоТам обработчики событй рабочей области}
114                            procedure WaMouseUp(Sender:TObject;Button: TMouseButton; Shift:TShiftState;X, Y: Integer);
115                            procedure WaMouseDown(Sender:TObject;Button: TMouseButton; Shift: TShiftState;X, Y: Integer);
116                            procedure WaMouseMove(sender:tobject;Shift: TShiftState; X, Y: Integer);override;
117                            procedure WaMouseWheel(Sender:TObject;Shift: TShiftState; WheelDelta: Integer;MousePos: TPoint;var handled:boolean);
118                            procedure WaMouseEnter(Sender:TObject);
119                            procedure WaMouseLeave(Sender:TObject);
120                            procedure WaResize(sender:tobject);override;
121                            procedure mypaint(sender:tobject);
122 
123                            procedure idle(Sender: TObject; var Done: Boolean);override;
124 
125                            constructor Create(TheOwner: TComponent); override;
126                            destructor Destroy; override;
CreateWorkAreanull127                            function CreateWorkArea(TheOwner: TComponent):TCADControl; virtual;abstract;
128                            procedure CreateDrawer; virtual;abstract;
129                            procedure SetupWorkArea; virtual;abstract;
130                            procedure doCameraChanged; override;
startpaintnull131                            function startpaint:boolean;override;
132                            procedure endpaint;override;
NeedDrawInsidePaintEventnull133                            function NeedDrawInsidePaintEvent:boolean; virtual;abstract;
134                            procedure ZoomIn;override;
135                            procedure ZoomOut;override;
136                       end;
MouseButton2ZKeynull137 function MouseButton2ZKey(Shift: TShiftState):GDBByte;
138 procedure RemoveCursorIfNeed(acontrol:TControl;RemoveCursor:boolean);
139 var
140    sysvarDISPOSSize:double=10;
141    sysvarDISPCursorSize:integer=10;
142    SysVarDISPCrosshairSize:double=0.05;
143    sysvarDISPBackGroundColor:TRGB=(r:0;g:0;b:0;a:255);
144    sysvarRDMaxRenderTime:integer=0;
145    sysvarDISPZoomFactor:double=1.624;
146    sysvarDISPSystmGeometryDraw:boolean=false;
147    sysvarDISPSystmGeometryColor:TGDBPaletteColor=1;
148    sysvarDISPHotGripColor:TGDBPaletteColor=2;
149    sysvarDISPSelGripColor:TGDBPaletteColor=3;
150    sysvarDISPUnSelGripColor:TGDBPaletteColor=4;
151    sysvarDWGOSMode:TGDBOSMode=0;
152    sysvarDWGOSModeControl:Boolean=True;
153    sysvarDISPGripSize:GDBInteger=5;
154    sysvarDISPColorAxis:boolean=true;
155    sysvarDISPDrawZAxis:boolean=true;
156    sysvarDrawInsidePaintMessage:TGDB3StateBool=T3SB_Default;
157    sysvarDWGPolarMode:GDBBoolean=false;
158    SysVarRDLineSmooth:GDBBoolean=false;
159    sysvarRDUseStencil:GDBBoolean=false;
160    sysvarRDLastRenderTime:integer=0;
161    sysvarRDLastUpdateTime:integer=0;
162    SysVarRDImageDegradationEnabled:boolean=false;
163    SysVarRDImageDegradationPrefferedRenderTime:integer=0;
164    SysVarRDImageDegradationCurrentDegradationFactor:GDBDouble=0;
165    SysVarRDImageDegradationMaxDegradationFactor:GDBDouble=0;
166    SysVarRDRemoveSystemCursorFromWorkArea:GDBBoolean=true;
167    sysvarDSGNSelNew:GDBBoolean=false;
168    sysvarDWGEditInSubEntry:gdbboolean=false;
169    sysvarDSGNOTrackTimerInterval:GDBInteger=500;
170    sysvarRDLastCalcVisible:GDBInteger=0;
171    sysvarRDLight:boolean=false;
172 
173    OnActivateProc:TOnActivateProc=nil;
174    ForeGroundColorIndex:GDBInteger;
175 
176    sysvarDISPLWDisplayScale:GDBInteger=10;
177    sysvarDISPDefaultLW:TGDBLineWeight=LnWt025;
178 
179 implementation
180 procedure RemoveCursorIfNeed(acontrol:TControl;RemoveCursor:boolean);
181 begin
182      if RemoveCursor then
183                          acontrol.cursor:=crNone
184                      else
185                          acontrol.cursor:=crDefault;
186 end;
187 procedure TGeneralViewArea.mypaint;
188 begin
189      //param.firstdraw:=true;
190      inc(InsidePaintMessage);
191      draw;
192      dec(InsidePaintMessage);
193      inherited;
194 end;
195 procedure TGeneralViewArea.idle(Sender: TObject; var Done: Boolean);
196 begin
197      //paint;
198 end;
199 procedure TGeneralViewArea.ZoomIn;
200 begin
201      getviewcontrol.DoMouseWheel([],1,point(0,0));
202 end;
203 procedure TGeneralViewArea.ZoomOut;
204 begin
205      getviewcontrol.DoMouseWheel([],-1,point(0,0));
206 end;
207 procedure TGeneralViewArea.GDBActivate;
208 begin
209     pdwg.SetCurrentDWG;
210     param.firstdraw:=true;
211     GDBActivateGLContext;
212     getviewcontrol.invalidate;
213     if assigned(OnActivateProc) then OnActivateProc;
214 end;
215 procedure drawfrustustum(frustum:ClipArray;var DC:TDrawContext);
216 var
217 tv1,tv2,tv3,tv4{,sv1,sv2,sv3,sv4,d1PProjPoint{,d2,d3,d4}:gdbvertex;
218 Tempplane:DVector4D;
219 
220 begin
221   Tempplane:=frustum[5];
222   tempplane[3]:=(tempplane[3]-frustum[4][3])/2;
223   begin
224   tv1:=PointOf3PlaneIntersect(frustum[0],frustum[3],Tempplane);
225   tv2:=PointOf3PlaneIntersect(frustum[1],frustum[3],Tempplane);
226   tv3:=PointOf3PlaneIntersect(frustum[1],frustum[2],Tempplane);
227   tv4:=PointOf3PlaneIntersect(frustum[0],frustum[2],Tempplane);
228 
229   dc.drawer.DrawLine3DInModelSpace(tv1,tv2,dc.DrawingContext.matrixs);
230   dc.drawer.DrawLine3DInModelSpace(tv2,tv3,dc.DrawingContext.matrixs);
231   dc.drawer.DrawLine3DInModelSpace(tv3,tv4,dc.DrawingContext.matrixs);
232   dc.drawer.DrawLine3DInModelSpace(tv4,tv1,dc.DrawingContext.matrixs);
233   end;
234 end;
235 procedure TGeneralViewArea.showcursor(var DC:TDrawContext);
236 var
237   i, j: GDBInteger;
238   pt:ptraceprop;
239   mvertex,dvertex,tv1,tv2,sv1,d1:gdbvertex;
240   Tempplane,plx,ply,plz:DVector4D;
241   a: GDBInteger;
242   i2d,i2dresult:intercept2dprop;
243   _NotUseLCS:boolean;
244 begin
245   if param.scrollmode then
246                           exit;
247   CalcOptimalMatrix;
248   dc.drawer.startrender(TRM_ModelSpace,dc.DrawingContext.matrixs);
249   if PDWG.GetSelObjArray.Count<>0 then
250                                       begin
251                                         PDWG.GetSelObjArray.drawpoint(dc,sysvarDISPGripSize,palette[sysvarDISPSelGripColor].RGB,palette[sysvarDISPUnSelGripColor].RGB);
252                                         if param.gluetocp then
253                                         begin
254                                           dc.drawer.SetColor(palette[sysvarDISPHotGripColor].rgb);
255                                           dc.drawer.SetPointSize(sysvarDISPGripSize);
256                                           dc.drawer.DrawPoint3DInModelSpace(param.md.mouse3dcoord,dc.DrawingContext.matrixs);
257                                           dc.drawer.SetPointSize(1);
258                                         end;
259                                       end;
260   dc.drawer.SetColor(palette[ForeGroundColorIndex].RGB);
261   dc.drawer.SetDrawMode(TDM_Normal);
262   if param.ShowDebugFrustum then
263                           drawfrustustum(param.debugfrustum,dc);
264   Tempplane:=param.mousefrustumLCS[5];
265   tempplane[3]:=(tempplane[3]-param.mousefrustumLCS[4][3])/2;
266   {курсор фрустума выделения}
267   if param.md.mousein then
268   if (param.md.mode and MGetSelectObject) <> 0 then
269   begin
270   _NotUseLCS:=NotUseLCS;
271   NotUseLCS:=true;
272   drawfrustustum(param.mousefrustumLCS,dc);
273   NotUseLCS:=_NotUseLCS;
274   end;
275   {оси курсора}
276   _NotUseLCS:=NotUseLCS;
277   NotUseLCS:=true;
278   if param.md.mousein then
279   if ((param.md.mode)and(MGet3DPoint or MGet3DPointWoOP or MGetControlpoint))<> 0 then
280   begin
281   sv1:=param.md.mouseray.lbegin;
282   sv1:=vertexadd(sv1,PDWG.Getpcamera^.CamCSOffset);
283 
284   PointOfLinePlaneIntersect(VertexAdd(param.md.mouseray.lbegin,PDWG.Getpcamera^.CamCSOffset),param.md.mouseray.dir,tempplane,mvertex);
285   plx:=PlaneFrom3Pont(sv1,vertexadd(param.md.mouse3dcoord,PDWG.Getpcamera^.CamCSOffset),
286                       vertexadd(VertexAdd(param.md.mouse3dcoord,xWCS{VertexMulOnSc(xWCS,oneVertexlength(wa.param.md.mouse3dcoord))}),PDWG.Getpcamera^.CamCSOffset));
287   //if assigned(sysvar.DISP.DISP_ColorAxis)then
288   if sysvarDISPColorAxis then dc.drawer.SetColor(255, 0, 0,255);
289   tv1:=PointOf3PlaneIntersect(PDWG.Getpcamera.frustumLCS[0],plx,Tempplane);
290   tv2:=PointOf3PlaneIntersect(PDWG.Getpcamera.frustumLCS[1],plx,Tempplane);
291   dvertex:=uzegeometry.VertexSub(tv2,tv1);
292   dvertex:=uzegeometry.VertexMulOnSc(dvertex,SysVarDISPCrosshairSize);
293   tv1:=VertexSub(mvertex,dvertex);
294   tv2:=VertexAdd(mvertex,dvertex);
295   dc.drawer.DrawLine3DInModelSpace(tv1,tv2,dc.DrawingContext.matrixs);
296 
297   ply:=PlaneFrom3Pont(sv1,vertexadd(param.md.mouse3dcoord,PDWG.Getpcamera^.CamCSOffset),
298                       vertexadd(VertexAdd(param.md.mouse3dcoord,yWCS{VertexMulOnSc(xWCS,oneVertexlength(wa.param.md.mouse3dcoord))}),PDWG.Getpcamera^.CamCSOffset));
299   //if assigned(sysvar.DISP.DISP_ColorAxis)then
300   if sysvarDISPColorAxis then dc.drawer.SetColor(0, 255, 0,255);
301   tv1:=PointOf3PlaneIntersect(PDWG.Getpcamera.frustumLCS[2],ply,Tempplane);
302   tv2:=PointOf3PlaneIntersect(PDWG.Getpcamera.frustumLCS[3],ply,Tempplane);
303   dvertex:=uzegeometry.VertexSub(tv2,tv1);
304   dvertex:=uzegeometry.VertexMulOnSc(dvertex,SysVarDISPCrosshairSize*{gdb.GetCurrentDWG.OGLwindow1.}getviewcontrol.ClientWidth/{gdb.GetCurrentDWG.OGLwindow1.}getviewcontrol.ClientHeight);
305   tv1:=VertexSub(mvertex,dvertex);
306   tv2:=VertexAdd(mvertex,dvertex);
307   dc.drawer.DrawLine3DInModelSpace(tv1,tv2,dc.DrawingContext.matrixs);
308 
309   //if assigned(sysvar.DISP.DISP_DrawZAxis)then
310   if sysvarDISPDrawZAxis then
311   begin
312   plz:=PlaneFrom3Pont(sv1,vertexadd(param.md.mouse3dcoord,PDWG.Getpcamera^.CamCSOffset),
313                       vertexadd(VertexAdd(param.md.mouse3dcoord,zWCS{VertexMulOnSc(xWCS,oneVertexlength(wa.param.md.mouse3dcoord))}),PDWG.Getpcamera^.CamCSOffset));
314   //if assigned(sysvar.DISP.DISP_ColorAxis)then
315   if sysvarDISPColorAxis then dc.drawer.SetColor(0, 0, 255,255);
316   tv1:=PointOf3PlaneIntersect(PDWG.Getpcamera.frustumLCS[0],plz,Tempplane);
317   tv2:=PointOf3PlaneIntersect(PDWG.Getpcamera.frustumLCS[1],plz,Tempplane);
318   dvertex:=uzegeometry.VertexSub(tv2,tv1);
319   dvertex:=uzegeometry.VertexMulOnSc(dvertex,SysVarDISPCrosshairSize);
320   tv1:=VertexSub(mvertex,dvertex);
321   tv2:=VertexAdd(mvertex,dvertex);
322   dc.drawer.DrawLine3DInModelSpace(tv1,tv2,dc.DrawingContext.matrixs);
323   end;
324   end;
325   dc.drawer.SetColor(palette[ForeGroundColorIndex].RGB);
326   //dc.drawer.SetColor(255, 255, 255,255);
327   d1:=uzegeometry.VertexAdd(param.md.mouseray.lbegin,param.md.mouseray.lend);
328   d1:=uzegeometry.VertexMulOnSc(d1,0.5);
329 
330 
331   dc.drawer.startrender(TRM_DisplaySpace,dc.DrawingContext.matrixs);
332   //dc.drawer.SetDisplayCSmode(getviewcontrol.clientwidth, getviewcontrol.clientheight);
333   {oglsm.myglMatrixMode(GL_PROJECTION);
334   oglsm.myglLoadIdentity;
335   oglsm.myglOrtho(0.0, getviewcontrol.clientwidth, getviewcontrol.clientheight, 0.0, -1.0, 1.0);
336   oglsm.myglMatrixMode(GL_MODELVIEW);
337   oglsm.myglLoadIdentity;
338   oglsm.myglscalef(1, -1, 1);
339   oglsm.myglpushmatrix;
340   oglsm.mygltranslated(0, -getviewcontrol.clientheight, 0);}
341 
342   if assigned(OnWaShowCursor)then
343                                  OnWaShowCursor(self,dc);
344   (*oglsm.myglpopmatrix;
345   dc.drawer.SetColor(0, 100, 100,255);
346   oglsm.myglpushmatrix;
347   oglsm.mygltranslated(param.CSIcon.csx.x + 2, -getviewcontrol.clientheight + param.CSIcon.csx.y - 10, 0);
348   //textwrite('X');
349   oglsm.myglpopmatrix;
350   oglsm.myglpushmatrix;
351   oglsm.mygltranslated(param.CSIcon.csy.x + 2, -getviewcontrol.clientheight + param.CSIcon.csy.y - 10, 0);
352   //textwrite('Y');
353   oglsm.myglpopmatrix;
354   oglsm.myglpushmatrix;
355   oglsm.mygltranslated(param.CSIcon.csz.x + 2, -getviewcontrol.clientheight + param.CSIcon.csz.y - 10, 0);
356   //textwrite('Z');
357   oglsm.myglpopmatrix;
358   oglsm.myglLoadIdentity;
359   *)
360   //glColor3ub(255, 255, 255);
361   dc.drawer.startrender(TRM_WindowSpace,dc.DrawingContext.matrixs);
362   dc.drawer.SetColor(palette[ForeGroundColorIndex].RGB);
363   //oglsm.glColor3ubv(foreground);
364 
365   if param.seldesc.MouseFrameON then
366   begin
367     dc.drawer.SetDrawMode(TDM_Normal);
368     if param.seldesc.MouseFrameInverse then
369       dc.drawer.SetPenStyle(TPS_Dash);
370     dc.drawer.DrawLine2DInDCS(param.seldesc.Frame1.x,param.seldesc.Frame1.y,
371                               param.seldesc.Frame2.x,param.seldesc.Frame1.y);
372     dc.drawer.DrawLine2DInDCS(param.seldesc.Frame2.x,param.seldesc.Frame1.y,
373                               param.seldesc.Frame2.x,param.seldesc.Frame2.y);
374     dc.drawer.DrawLine2DInDCS(param.seldesc.Frame2.x,param.seldesc.Frame2.y,
375                               param.seldesc.Frame1.x,param.seldesc.Frame2.y);
376     dc.drawer.DrawLine2DInDCS(param.seldesc.Frame1.x,param.seldesc.Frame2.y,
377                               param.seldesc.Frame1.x,param.seldesc.Frame1.y);
378 
379     dc.drawer.DrawLine2DInDCS(param.seldesc.Frame1.x,param.seldesc.Frame1.y,
380                               param.seldesc.Frame2.x,param.seldesc.Frame2.y);
381     dc.drawer.DrawLine2DInDCS(param.seldesc.Frame1.x,param.seldesc.Frame2.y,
382                               param.seldesc.Frame2.x,param.seldesc.Frame1.y);
383 
384     if param.seldesc.MouseFrameInverse then
385       dc.drawer.SetPenStyle(TPS_Solid);
386     if param.seldesc.MouseFrameInverse then
387     begin
388       dc.drawer.SetDrawMode(TDM_XOR);
389       dc.drawer.SetPenStyle(TPS_Dash);
390     end;
391     if param.seldesc.MouseFrameInverse then
392       dc.drawer.SetColor(0,40,0,10)
393     else
394       dc.drawer.SetColor(0,0,40,10);
395     dc.drawer.SetDrawMode(TDM_XOR);
396     dc.drawer.DrawQuad2DInDCS(param.seldesc.Frame1.x,param.seldesc.Frame1.y,param.seldesc.Frame2.x,param.seldesc.Frame2.y);
397     if param.seldesc.MouseFrameInverse then
398       dc.drawer.SetPenStyle(TPS_Solid);
399   end;
400 
401 
402   if PDWG<>nil then
403 
404   if tocommandmcliccount=0 then a:=1
405                            else a:=0;
406   //if sysvar.DWG.DWG_PolarMode<>nil then
407   if sysvarDWGPolarMode then
408   if param.ontrackarray.total <> 0 then
409   begin
410     dc.drawer.SetDrawMode(TDM_XOR);
411     {oglsm.myglLogicOp(GL_XOR);}
412     for i := a to param.ontrackarray.total - 1 do
413     begin
414      dc.drawer.SetColor(255,255, 0,255);
415       dc.drawer.DrawLine2DInDCS(param.ontrackarray.otrackarray[i].dispcoord.x,
416                  getviewcontrol.clientheight - param.ontrackarray.otrackarray[i].dispcoord.y + marksize,param.ontrackarray.otrackarray[i].dispcoord.x,
417                  getviewcontrol.clientheight - param.ontrackarray.otrackarray[i].dispcoord.y - marksize);
418      dc.drawer.DrawLine2DInDCS(param.ontrackarray.otrackarray[i].dispcoord.x + marksize,
419                  getviewcontrol.clientheight - param.ontrackarray.otrackarray[i].dispcoord.y,param.ontrackarray.otrackarray[i].dispcoord.x - marksize,
420                  getviewcontrol.clientheight - param.ontrackarray.otrackarray[i].dispcoord.y);
421 
422       dc.drawer.SetPenStyle(TPS_Dot);
423       {oglsm.myglLineStipple(1, $3333);
424       oglsm.myglEnable(GL_LINE_STIPPLE);}
425       //oglsm.myglbegin(GL_LINES);
426       dc.drawer.SetColor(80,80, 80,255);
427       if param.ontrackarray.otrackarray[i].arraydispaxis.Count <> 0 then
428       begin;
429       pt:=param.ontrackarray.otrackarray[i].arraydispaxis.GetParrayAsPointer;
430       for j := 0 to param.ontrackarray.otrackarray[i].arraydispaxis.count - 1 do
431         begin
432           if pt.trace then
433           begin
434             //|---2---|
435             //|       |
436             //1       3
437             //|       |
438             //|---4---|
439             {1}
440             i2dresult:=intercept2dmy(CreateVertex2D(0,0),CreateVertex2D(0,getviewcontrol.clientheight),PGDBVertex2D(@param.ontrackarray.otrackarray[i].dispcoord)^,PGDBVertex2D(@pt.dispraycoord)^);
441             {2}
442             i2d:=intercept2dmy(CreateVertex2D(0,getviewcontrol.clientheight),CreateVertex2D(getviewcontrol.clientwidth,getviewcontrol.clientheight),PGDBVertex2D(@param.ontrackarray.otrackarray[i].dispcoord)^,PGDBVertex2D(@pt.dispraycoord)^);
443             if not i2dresult.isintercept then
444                                              i2dresult:=i2d;
445             if i2d.isintercept then
446             if i2d.t2>0 then
447             if (i2d.t2>i2dresult.t2)or(i2dresult.t2<0) then
448                                             i2dresult:=i2d;
449             {3}
450             i2d:=intercept2dmy(CreateVertex2D(getviewcontrol.clientwidth,getviewcontrol.clientheight),CreateVertex2D(getviewcontrol.clientwidth,0),PGDBVertex2D(@param.ontrackarray.otrackarray[i].dispcoord)^,PGDBVertex2D(@pt.dispraycoord)^);
451             if not i2dresult.isintercept then
452                                              i2dresult:=i2d;
453             if i2d.isintercept then
454             if i2d.t2>0 then
455             if (i2d.t2>i2dresult.t2)or(i2dresult.t2<0) then
456                                             i2dresult:=i2d;
457             {4}
458             i2d:=intercept2dmy(CreateVertex2D(getviewcontrol.clientwidth,0),CreateVertex2D(0,0),PGDBVertex2D(@param.ontrackarray.otrackarray[i].dispcoord)^,PGDBVertex2D(@pt.dispraycoord)^);
459             if not i2dresult.isintercept then
460                                              i2dresult:=i2d;
461             if i2d.isintercept then
462             if i2d.t2>0 then
463             if (i2d.t2>i2dresult.t2)or(i2dresult.t2<0) then
464                                             i2dresult:=i2d;
465 
466             //uzegeometry.
467             dc.drawer.DrawLine2DInDCS(param.ontrackarray.otrackarray[i].dispcoord.x, getviewcontrol.clientheight - param.ontrackarray.otrackarray[i].dispcoord.y,i2dresult.interceptcoord.x, getviewcontrol.clientheight - i2dresult.interceptcoord.y);
468             //glvertex2d(pt.dispraycoord.x, clientheight - pt.dispraycoord.y);
469           end;
470           inc(pt);
471         end;
472       end;
473       //oglsm.myglend;
474       //oglsm.mytotalglend;
475       //isOpenGLError;
476       dc.drawer.SetPenStyle(TPS_Solid);
477       //oglsm.myglDisable(GL_LINE_STIPPLE);
478     end;
479   end;
480 
481   showsnap(DC);
482 
483  //{$ENDREGION}
484  NotUseLCS:=_NotUseLCS;
485   //oglsm.myglMatrixMode(GL_PROJECTION);
486   //glLoadIdentity;
487   //gdb.GetCurrentDWG.pcamera^.projMatrix:=onematrix;
488   if PDWG<>nil then
489   begin
490 {    if wa.param.projtype = Projparalel then
491   begin
492     gdb.GetCurrentDWG.pcamera^.projMatrix:=ortho(-clientwidth * wa.param.zoom / 2, clientwidth * wa.param.zoom / 2,
493             -clientheight * wa.param.zoom / 2, clientheight * wa.param.zoom / 2,
494              gdb.GetCurrentDWG.pcamera^.zmin, gdb.GetCurrentDWG.pcamera^.zmax,@onematrix);
495   end;
496   if wa.param.projtype = Projperspective then
497     gdb.GetCurrentDWG.pcamera^.projMatrix:=Perspective(gdb.GetCurrentDWG.pcamera^.fovy, Width / Height, gdb.GetCurrentDWG.pcamera^.zmin, gdb.GetCurrentDWG.pcamera^.zmax,@onematrix);
498     glLoadMatrixD(@gdb.GetCurrentDWG.pcamera^.projMatrix);
499    glulookat(-gdb.GetCurrentDWG.pcamera^.point.x, -gdb.GetCurrentDWG.pcamera^.point.y, -gdb.GetCurrentDWG.pcamera^.point.z,
500              -gdb.GetCurrentDWG.pcamera^.point.x + gdb.GetCurrentDWG.pcamera^.look.x,
501              -gdb.GetCurrentDWG.pcamera^.point.y + gdb.GetCurrentDWG.pcamera^.look.y,
502              -gdb.GetCurrentDWG.pcamera^.point.z + gdb.GetCurrentDWG.pcamera^.look.z,
503               gdb.GetCurrentDWG.pcamera^.ydir.x, gdb.GetCurrentDWG.pcamera^.ydir.y, gdb.GetCurrentDWG.pcamera^.ydir.z);
504   gltranslated(0, 0, -500);
505   oglsm.myglMatrixMode(GL_MODELVIEW);
506   glLoadIdentity;
507   oglsm.myglDisable(GL_LIGHTING);
508 }
509   dc.drawer.ClearStatesMachine;
510   dc.drawer.SetDrawMode(TDM_Normal);
511 end;
512 end;
513 procedure TGeneralViewArea.DrawCSAxis(var DC:TDrawContext);
514 var
515   td,td2,td22:gdbdouble;
516 begin
517   dc.drawer.SetDrawMode(TDM_Normal);
518   CalcOptimalMatrix;
519   if param.CSIcon.axislen<>0 then {переделать}
520   begin
521   td:=param.CSIcon.axislen;
522   td2:=td/5;
523   td22:=td2/3;
524 
525   dc.drawer.SetColor(255, 0, 0,255);
526   dc.drawer.DrawLine3DInModelSpace(param.CSIcon.CSIconCoord,param.CSIcon.CSIconX,dc.DrawingContext.matrixs);
527   dc.drawer.DrawLine3DInModelSpace(param.CSIcon.CSIconX,createvertex(param.CSIcon.CSIconCoord.x + td-td2, param.CSIcon.CSIconCoord.y-td22 , param.CSIcon.CSIconCoord.z),dc.DrawingContext.matrixs);
528   dc.drawer.DrawLine3DInModelSpace(param.CSIcon.CSIconX,createvertex(param.CSIcon.CSIconCoord.x + td-td2, param.CSIcon.CSIconCoord.y+td22 , param.CSIcon.CSIconCoord.z),dc.DrawingContext.matrixs);
529 
530   dc.drawer.SetColor(0, 255, 0,255);
531   dc.drawer.DrawLine3DInModelSpace(param.CSIcon.CSIconCoord,param.CSIcon.CSIconY,dc.DrawingContext.matrixs);
532   dc.drawer.DrawLine3DInModelSpace(param.CSIcon.CSIconY,createvertex(param.CSIcon.CSIconCoord.x-td22, param.CSIcon.CSIconCoord.y + td-td2, param.CSIcon.CSIconCoord.z),dc.DrawingContext.matrixs);
533   dc.drawer.DrawLine3DInModelSpace(param.CSIcon.CSIconY,createvertex(param.CSIcon.CSIconCoord.x+td22, param.CSIcon.CSIconCoord.y + td-td2, param.CSIcon.CSIconCoord.z),dc.DrawingContext.matrixs);
534 
535   dc.drawer.SetColor(0, 0, 255,255);
536   dc.drawer.DrawLine3DInModelSpace(param.CSIcon.CSIconCoord,param.CSIcon.CSIconZ,dc.DrawingContext.matrixs);
537 
538   if IsVectorNul(vectordot(pdwg.GetPcamera.prop.look,ZWCS)) then
539   begin
540       dc.drawer.SetColor(255, 255, 255,255);
541       dc.drawer.DrawLine3DInModelSpace(createvertex(param.CSIcon.CSIconCoord.x + td2, param.CSIcon.CSIconCoord.y , param.CSIcon.CSIconCoord.z),createvertex(param.CSIcon.CSIconCoord.x + td2, param.CSIcon.CSIconCoord.y+ td2 , param.CSIcon.CSIconCoord.z),dc.DrawingContext.matrixs);
542       dc.drawer.DrawLine3DInModelSpace(createvertex(param.CSIcon.CSIconCoord.x + td2, param.CSIcon.CSIconCoord.y+ td2 , param.CSIcon.CSIconCoord.z),createvertex(param.CSIcon.CSIconCoord.x, param.CSIcon.CSIconCoord.y+ td2 , param.CSIcon.CSIconCoord.z),dc.DrawingContext.matrixs);
543   end;
544   end;
545   dc.drawer.ClearStatesMachine;
546   dc.drawer.SetDrawMode(TDM_Normal);
547 end;
548 procedure TGeneralViewArea.DrawGrid(var DC:TDrawContext);
549 begin
550 end;
551 procedure TGeneralViewArea.LightOn(var DC:TDrawContext);
552 begin
553 end;
554 procedure TGeneralViewArea.LightOff(var DC:TDrawContext);
555 begin
556 end;
557 procedure TGeneralViewArea.SwapBuffers(var DC:TDrawContext);
558 begin
559      drawer.SwapBuffers;
560 end;
treerendernull561 function TGeneralViewArea.treerender;
562 var
563    currtime:TDateTime;
564    Hour,Minute,Second,MilliSecond:word;
565    q1,q2:gdbboolean;
566    //currd:PTDrawing;
567 begin //currd:=gdb.GetCurrentDWG;
568     if (sysvarRDMaxRenderTime<>0) then
569     begin
570      currtime:=now;
571      decodetime(currtime-StartTime,Hour,Minute,Second,MilliSecond);
572      if (sysvarRDMaxRenderTime<>0) then
573      if (sysvarRDMaxRenderTime-MilliSecond)<0 then
574                             begin
575                                   result:=true;
576                                   exit;
577                             end;
578      end;
579      q1:=false;
580      q2:=false;
581 
582   if Node.NodeData.infrustum={gdb.GetCurrentDWG}PDWG.Getpcamera.POSCOUNT then
583   begin
584        if (Node.NodeData.FulDraw=TDTFulDraw)or(Node.nul.count=0) then
585        begin
586        if assigned(node.pminusnode)then
587                                        if node.NodeData.minusdrawpos<>PDWG.Getpcamera.DRAWCOUNT then
588                                        begin
589                                        if not treerender(PTEntTreeNode(node.pminusnode)^,StartTime,dc) then
590                                            node.NodeData.minusdrawpos:=PDWG.Getpcamera.DRAWCOUNT
591                                                                                      else
592                                                                                          q1:=true;
593                                        end;
594        if assigned(node.pplusnode)then
595                                       if node.NodeData.plusdrawpos<>PDWG.Getpcamera.DRAWCOUNT then
596                                       begin
597                                        if not treerender(PTEntTreeNode(node.pplusnode)^,StartTime,dc) then
598                                            node.NodeData.plusdrawpos:=PDWG.Getpcamera.DRAWCOUNT
599                                                                                     else
600                                                                                         q2:=true;
601                                       end;
602        end;
603        if node.NodeData.nuldrawpos<>PDWG.Getpcamera.DRAWCOUNT then
604        begin
605         TEntTreeNode(Node).DrawWithAttribExternalArray(dc);
606         //GDBObjEntityOpenArray(Node.nul).DrawWithattrib(dc{gdb.GetCurrentDWG.pcamera.POSCOUNT,subrender});
607         node.NodeData.nuldrawpos:=PDWG.Getpcamera.DRAWCOUNT;
608        end;
609   end;
610   result:=(q1) or (q2);
611   //Node.drawpos:=gdb.GetCurrentDWG.pcamera.DRAWCOUNT;
612 
613   //root.DrawWithattrib(gdb.GetCurrentDWG.pcamera.POSCOUNT);
614 end;
615 procedure TGeneralViewArea.render;
616 begin
617   if dc.subrender = 0 then
618   begin
619     PDWG.Getpcamera^.obj_zmax:=-nan;
620     PDWG.Getpcamera^.obj_zmin:=-1000000;
621     PDWG.Getpcamera^.totalobj:=0;
622     PDWG.Getpcamera^.infrustum:=0;
623     //gdb.pcamera.getfrustum;
624     //pva^.calcvisible;
625 //    if not wa.param.scrollmode then
626 //                                PVA.renderfeedbac;
627     //if not wa.param.scrollmode then 56RenderOsnapstart(pva);
628     CalcOptimalMatrix;
629     //Clearcparray;
630   end;
631   //if wa.param.subrender=0 then
632   //pva^.DeSelect;
633   //if pva^.Count>0 then
634   //                       pva^.Count:=pva^.Count;
635   root.{ObjArray.}DrawWithattrib({gdb.GetCurrentDWG.pcamera.POSCOUNT,0}dc);
636 end;
637 procedure TGeneralViewArea.finishdraw;
638   var
639     LPTime:Tdatetime;
640 begin
641      //inc(sysvar.debug.int1);
642      CalcOptimalMatrix;
643      drawer.RestoreBuffers;
644      LPTime:=now();
645      PDWG.Getpcamera.DRAWNOTEND:=treerender(PDWG.GetCurrentROOT^.ObjArray.ObjTree,lptime,rc);
646      drawer.SaveBuffers;
647      showcursor(rc);
648      SwapBuffers(rc);
649 end;
650 procedure TGeneralViewArea.DrawOrInvalidate;
651 var
652    insidepaint:boolean;
653 begin
654      //if sysvar.RD.RD_DrawInsidePaintMessage<>nil then
655      begin
656           case sysvarDrawInsidePaintMessage of
657               T3SB_Fale:insidepaint:=false;
658               T3SB_True:insidepaint:=true;
659               T3SB_Default:insidepaint:=NeedDrawInsidePaintEvent;
660           end;
661      end;
662      if insidepaint then
663                         getviewcontrol.Invalidate
664                     else
665                         draw;
666 end;
667 
668 procedure TGeneralViewArea.draw;
669 var
670   scrollmode:GDBBOOlean;
671   LPTime:Tdatetime;
672   DC:TDrawContext;
673   dt:integer;
674   tick:cardinal;
675   needredraw,needredrawbydrawer:boolean;
676   const msec=1;
677 begin
678   if not assigned(pdwg) then exit;
679   if (getviewcontrol.clientwidth=0)or(getviewcontrol.clientheight=0) then exit;
680   LPTime:=now;
681   needredraw:=param.firstdraw{ or true};
682   if VerboseLog^ then
683   debugln('{T}TOGLWnd.draw');
684   //programlog.logoutstr('TOGLWnd.draw',0,LM_Trace);
685   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.draw',lp_IncPos);{$ENDIF}
686 
687   //-----------------------------------MakeCurrent;{не забыть что обычный контекст не делает себя текущим сам!}
688 
689   if (sysvarDISPBackGroundColor.r<ClCanalMin)and(sysvarDISPBackGroundColor.g<ClCanalMin)
690   and(sysvarDISPBackGroundColor.b<ClCanalMin) then
691     ForeGroundColorIndex:=ClWhite
692   else
693     ForeGroundColorIndex:=ClBlack;
694   {foreground.r:=not(sysvarDISPBackGroundColor.r);
695   foreground.g:=not(sysvarDISPBackGroundColor.g);
696   foreground.b:=not(sysvarDISPBackGroundColor.b);}
697   dc:=CreateRC;
698   needredrawbydrawer:=startpaint;
699   needredraw:=needredrawbydrawer or needredraw;
700   //if assigned(SysVar.RD.RD_LineSmooth)then
701                                           dc.drawer.SetLineSmooth(SysVarRDLineSmooth);
702   dc.drawer.SetZTest(true);
703   if PDWG<>nil then
704   begin
705   {else if sysvar.RD.RD_Restore_Mode^=WND_Texture then}
706   begin
707   if needredraw then
708   begin
709     inc(PDWG.Getpcamera^.DRAWCOUNT);
710     dc.drawer.ClearStatesMachine;
711 
712     dc.drawer.SetClearColor(sysvarDISPBackGroundColor.r,sysvarDISPBackGroundColor.g,sysvarDISPBackGroundColor.b,sysvarDISPBackGroundColor.a);
713     dc.drawer.ClearScreen(true);
714 
715     CalcOptimalMatrix;
716     //if sysvar.RD.RD_UseStencil<>nil then
717     if sysvarRDUseStencil then
718     begin
719          dc.drawer.SetFillStencilMode;
720          dc.drawer.startrender(TRM_ModelSpace,dc.DrawingContext.matrixs);
721          PDWG.GetSelObjArray.drawobject(dc);
722          dc.drawer.SetDrawWithStencilMode;
723     end
724        else
725            dc.drawer.DisableStencil;
726     //   else
727     //       dc.drawer.DisableStencil;
728     dc.drawer.SetLineWidth(1);
729     dc.drawer.SetPointSize(1);
730     dc.drawer.SetPointSmooth(false);
731 
732     DrawGrid(dc);
733 
734     LightOn(dc);
735 
736     if (sysvarDISPSystmGeometryDraw) then
737                                                begin
738                                                dc.drawer.setcolor(palette[dc.SystmGeometryColor+2].RGB);
739                                                PDWG.GetCurrentROOT^.ObjArray.ObjTree.DrawVolume(dc);
740                                                end;
741     begin
742     dc.drawer.startrender(TRM_ModelSpace,dc.DrawingContext.matrixs);
743     PDWG.Getpcamera.DRAWNOTEND:=treerender(PDWG.GetCurrentROOT^.ObjArray.ObjTree,lptime,dc);
744     dc.drawer.endrender;
745     end;
746     PDWG.GetCurrentROOT.DrawBB(dc);
747 
748     DrawCSAxis(dc);
749 
750     dc.drawer.ClearStatesMachine;
751 
752 
753     drawer.SaveBuffers;
754 
755     dc.drawer.SetZTest(false);
756     inc(dc.subrender);
757     if assigned(dc.DrawingContext.DrawHeplGeometryProc) then
758                                                dc.DrawingContext.DrawHeplGeometryProc;
759 
760     scrollmode:=param.scrollmode;
761     param.scrollmode:=true;
762     render(PDWG.GetConstructObjRoot^,dc);
763 
764 
765     param.scrollmode:=scrollmode;
766     PDWG.GetConstructObjRoot.DrawBB(dc);
767 
768 
769     PDWG.GetSelObjArray.remappoints(PDWG.GetPcamera.POSCOUNT,param.scrollmode,PDWG.GetPcamera^,PDWG^.myGluProject2,dc);
770     dc.drawer.DisableStencil;
771     dc.MaxDetail:=true;
772     PDWG.GetSelObjArray.drawobj(dc);
773     dec(dc.subrender);
774     LightOff(dc);
775     showcursor(dc);
776   end
777   else
778   begin
779     LightOff(dc);
780     drawer.RestoreBuffers;
781     CalcOptimalMatrix;
782     inc(dc.subrender);
783     dc.drawer.startrender(TRM_ModelSpace,dc.DrawingContext.matrixs);
784     if PDWG.GetConstructObjRoot.ObjArray.Count>0 then
785                                                     PDWG.GetConstructObjRoot.ObjArray.Count:=PDWG.GetConstructObjRoot.ObjArray.Count;
786     if assigned(dc.DrawingContext.DrawHeplGeometryProc) then
787                                                dc.DrawingContext.DrawHeplGeometryProc;
788     scrollmode:=param.scrollmode;
789     param.scrollmode:=true;
790     render(PDWG.GetConstructObjRoot^,dc);
791     param.scrollmode:=scrollmode;
792     PDWG.GetConstructObjRoot.DrawBB(dc);
793 
794     dc.drawer.DisableStencil;
795     dc.MaxDetail:=true;
796     PDWG.GetSelObjArray.drawobj(dc);
797     dc.drawer.SetLineWidth(1);
798     dc.drawer.SetPointSize(1);
799     showcursor(dc);
800     dc.drawer.startrender(TRM_WindowSpace,dc.DrawingContext.matrixs);
801 
802     dec(dc.subrender);
803   end;
804   end
805   end
806      else begin
807                dc.drawer.SetClearColor(150,150,150,255);
808                dc.drawer.ClearScreen(false);
809           end;
810 
811 
812 
813   //------------------------------------------------------------------MySwapBuffers(OGLContext);//SwapBuffers(DC);
814 
815   //oglsm.mytotalglend;
816   dc.drawer.ClearStatesMachine;
817   dc.drawer.PostRenderDraw;
818   SwapBuffers(dc);
819   endpaint;
820 
821   lptime:=now()-LPTime;
822   tick:=round(lptime*10e7);
823   if needredraw then
824                     begin
825                          //if assigned(sysvarRDLastRenderTime)then
826                          sysvarRDLastRenderTime:=tick*msec
827                     end
828                 else
829                     begin
830                          //if assigned(sysvarRDLastUpdateTime)then
831                          sysvarRDLastUpdateTime:=tick*msec;
832                     end;
833   {$IFDEF PERFOMANCELOG}
834                        //if needredraw then
835                        //                       log.programlog.LogOutStrFast('Draw time='+inttostr(sysvarRDLastRenderTime),0)
836                        //                   else
837                        //                       log.programlog.LogOutStrFast('ReDraw time='+inttostr(sysvarRDLastUpdateTime),0);
838   {$ENDIF}
839   if needredraw then
840   //if assigned(SysVarRDImageDegradationEnabled)then
841   if SysVarRDImageDegradationEnabled then
842   begin
843   dt:=sysvarRDLastRenderTime-SysVarRDImageDegradationPrefferedRenderTime;
844   if dt<0 then
845                                          SysVarRDImageDegradationCurrentDegradationFactor:=SysVarRDImageDegradationCurrentDegradationFactor+{0.5}dt/5
846                                      else
847                                          SysVarRDImageDegradationCurrentDegradationFactor:=SysVarRDImageDegradationCurrentDegradationFactor+{0.5}dt/10;
848   if SysVarRDImageDegradationCurrentDegradationFactor>SysVarRDImageDegradationMaxDegradationFactor then
849                                                  SysVarRDImageDegradationCurrentDegradationFactor:=SysVarRDImageDegradationMaxDegradationFactor;
850   if SysVarRDImageDegradationCurrentDegradationFactor<0 then
851                                                  SysVarRDImageDegradationCurrentDegradationFactor:=0;
852   end;
853   param.firstdraw := false;
854   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.draw---{end}',lp_DecPos);{$ENDIF}
855 end;
856 procedure TGeneralViewArea.showsnap(var DC:TDrawContext);
857 begin
858   if param.ospoint.ostype <> os_none then
859   begin
860     dc.drawer.SetColor(255,255, 0,255);
861     dc.drawer.SetLineWidth(2);
862     dc.drawer.TranslateCoord2D(param.ospoint.dispcoord.x, getviewcontrol.clientheight - param.ospoint.dispcoord.y);
863     dc.drawer.ScaleCoord2D(sysvarDISPOSSize,sysvarDISPOSSize);
864       if (param.ospoint.ostype = os_begin)or(param.ospoint.ostype = os_end) then
865       begin
866            dc.drawer.DrawClosedPolyLine2DInDCS([-1,  1,
867                                                  1,  1,
868                                                  1, -1,
869                                                 -1, -1]);
870       end
871       else
872       if (param.ospoint.ostype = os_midle) then
873       begin
874            dc.drawer.DrawClosedPolyLine2DInDCS([ 0,              -1,
875                                                  0.8660254037844, 0.5,
876                                                 -0.8660254037844, 0.5]);
877       end
878       else
879       if (param.ospoint.ostype = os_1_4)or(param.ospoint.ostype = os_3_4) then
880       begin
881            dc.drawer.DrawLine2DInDCS(-0.5,  1,-0.5, -1);
882            dc.drawer.DrawLine2DInDCS(-0.2, -1, 0.15, 1);
883            dc.drawer.DrawLine2DInDCS( 0.5, -1, 0.15, 1);
884       end
885       else
886       if (param.ospoint.ostype = os_center)then
887                                                begin
888                                                  dc.drawer.DrawClosedPolyLine2DInDCS([-1,     0,
889                                                                                       -0.707, 0.707,
890                                                                                        0,     1,
891                                                                                        0.707, 0.707,
892                                                                                        1,     0,
893                                                                                        0.707,-0.707,
894                                                                                        0,    -1,
895                                                                                       -0.707,-0.707
896                                                                                        ]);
897                                                end
898       else
899       if (param.ospoint.ostype = os_q0)or(param.ospoint.ostype = os_q1)
900        or(param.ospoint.ostype = os_q2)or(param.ospoint.ostype = os_q3) then
901       begin
902            dc.drawer.DrawClosedPolyLine2DInDCS([-1,  0,
903                                                  0,  1,
904                                                  1,  0,
905                                                  0, -1,
906                                                 -1,  0]);
907       end
908       else
909       if (param.ospoint.ostype = os_1_3)or(param.ospoint.ostype = os_2_3) then
910       begin
911                                       dc.drawer.DrawLine2DInDCS(-0.5, 1,-0.5, -1);
912                                       dc.drawer.DrawLine2DInDCS(0, 1,0, -1);
913                                       dc.drawer.DrawLine2DInDCS(0.5, 1,0.5, -1);
914       end
915       else
916       if (param.ospoint.ostype = os_point) then
917       begin
918            dc.drawer.DrawLine2DInDCS(-1, 1,1, -1);
919            dc.drawer.DrawLine2DInDCS(-1, -1,1, 1);
920       end
921       else
922       if (param.ospoint.ostype = os_intersection) then
923       begin
924            dc.drawer.DrawLine2DInDCS(-1, 1,1, -1);
925            dc.drawer.DrawLine2DInDCS(-1, -1,1, 1);
926       end
927       else
928       if (param.ospoint.ostype = os_apparentintersection) then
929       begin
930            dc.drawer.DrawLine2DInDCS(-1, 1,1, -1);
931            dc.drawer.DrawLine2DInDCS(-1, -1,1, 1);
932            dc.drawer.DrawClosedPolyLine2DInDCS([-1,  1,
933                                                  1,  1,
934                                                  1, -1,
935                                                 -1, -1]);
936       end
937       else
938       if (param.ospoint.ostype = os_textinsert) then
939       begin
940            dc.drawer.DrawLine2DInDCS(-1, 0, 1, 0);
941            dc.drawer.DrawLine2DInDCS( 0, 1, 0,-1);
942       end
943       else
944       if (param.ospoint.ostype = os_perpendicular) then
945       begin
946            dc.drawer.DrawLine2DInDCS(-1,-1,-1, 1);
947            dc.drawer.DrawLine2DInDCS(-1, 1, 1, 1);
948            dc.drawer.DrawLine2DInDCS(-1, 0, 0, 0);
949            dc.drawer.DrawLine2DInDCS( 0, 0, 0, 1);
950       end
951       else
952       if (param.ospoint.ostype = os_trace) then
953       begin
954            dc.drawer.DrawLine2DInDCS(-1, -0.5,1, -0.5);
955            dc.drawer.DrawLine2DInDCS(-1,  0.5,1,  0.5);
956       end
957       else if (param.ospoint.ostype = os_nearest) then
958       begin
959            dc.drawer.DrawClosedPolyLine2DInDCS([-1, 1,
960                                                  1, 1,
961                                                 -1,-1,
962                                                  1,-1]);
963       end;
964     dc.drawer.SetLineWidth(1);
965   end;
966 end;
967 
968 Procedure TGeneralViewArea.Paint;
969 begin
970      WorkArea.Repaint;
971 end;
972 procedure TGeneralViewArea.showmousecursor;
973 begin
974      if assigned(WorkArea) then
975      WorkArea.Cursor:=crDefault;
976 end;
977 procedure TGeneralViewArea.hidemousecursor;
978 begin
979      if assigned(WorkArea) then
980      RemoveCursorIfNeed(WorkArea,sysvarRDRemoveSystemCursorFromWorkArea);
981 end;
982 procedure TGeneralViewArea.RestoreMouse;
983 var
984   fv1: GDBVertex;
985   DC:TDrawContext;
986 begin
987   CalcOptimalMatrix;
988   mouseunproject(param.md.mouse.x, getviewcontrol.clientheight-param.md.mouse.y);
989   reprojectaxis;
990   if param.seldesc.MouseFrameON then
991   begin
992     pdwg^.myGluProject2(param.seldesc.Frame13d,
993                fv1);
994     param.seldesc.Frame1.x := round(fv1.x);
995     param.seldesc.Frame1.y := getviewcontrol.clientheight - round(fv1.y);
996     if param.seldesc.Frame1.x < 0 then param.seldesc.Frame1.x := 0
997     else if param.seldesc.Frame1.x > (getviewcontrol.clientwidth - 1) then param.seldesc.Frame1.x := getviewcontrol.clientwidth - 1;
998     if param.seldesc.Frame1.y < 0 then param.seldesc.Frame1.y := 1
999     else if param.seldesc.Frame1.y > (getviewcontrol.clientheight - 1) then param.seldesc.Frame1.y := getviewcontrol.clientheight - 1;
1000   end;
1001 
1002   //param.zoommode := true;
1003   //param.scrollmode:=true;
1004   pdwg.GetCurrentROOT.CalcVisibleByTree(pdwg.getpcamera^.frustum,pdwg.getpcamera.POSCOUNT,pdwg.getpcamera.VISCOUNT,pdwg.GetCurrentROOT.ObjArray.ObjTree,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1005   //gdb.GetCurrentROOT.calcvisible(gdb.GetCurrentDWG.pcamera^.frustum,gdb.GetCurrentDWG.pcamera.POSCOUNT,gdb.GetCurrentDWG.pcamera.VISCOUNT);
1006   pdwg.GetCurrentROOT.calcvisible(pdwg.getpcamera^.frustum,pdwg.getpcamera.POSCOUNT,pdwg.getpcamera.VISCOUNT,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1007   DC:=self.CreateRC;
1008   pdwg.GetSelObjArray.RenderFeedBack(pdwg^.GetPcamera^.POSCOUNT,pdwg^.GetPcamera^,pdwg^.myGluProject2,dc);
1009 
1010   calcmousefrustum;
1011 
1012   {if param.lastonmouseobject<>nil then
1013                                       begin
1014                                            PGDBObjEntity(param.lastonmouseobject)^.RenderFeedBack(pdwg.GetPcamera^.POSCOUNT,pdwg^.GetPcamera^, pdwg^.myGluProject2,dc);
1015                                       end;}
1016 
1017   Set3dmouse;
1018   calcgrid;
1019 
1020   {paint;}
1021 
1022   WaMouseMove(self,[],param.md.mouse.x,param.md.mouse.y);
1023 
1024 end;
1025 
1026 procedure TGeneralViewArea.RotTo(x0,y0,z0:GDBVertex);
1027 const
1028      steps=10;
1029 var
1030   fv1: GDBVertex;
1031   i:integer;
1032   pucommand:pointer;
1033   q1,q2,q:GDBQuaternion;
1034   pcam:PGDBBaseCamera;
1035 
1036   mat1,mat2,mat : DMatrix4D;
1037 begin
1038   pcam:=PDWG.Getpcamera;
1039   mat1:=CreateMatrixFromBasis(pcam.prop.xdir,pcam.prop.ydir,pcam.prop.look);
1040   mat2:=CreateMatrixFromBasis(x0,y0,z0);
1041 
1042   q1:=QuaternionFromMatrix(mat1);
1043   q2:=QuaternionFromMatrix(mat2);
1044   pucommand:=PDWG^.StoreOldCamerapPos;
1045   for i:=1 to steps do
1046   begin
1047   q:=QuaternionSlerp(q1,q2,i/steps);
1048   mat:=QuaternionToMatrix(q);
1049   CreateBasisFromMatrix(mat,pcam.prop.xdir,pcam.prop.ydir,pcam.prop.look);
1050 
1051   //wa.PDWG.Getpcamera^.prop.point:=vertexadd(camerapos,uzegeometry.VertexMulOnSc(target,i/steps));
1052   //wa.PDWG.Getpcamera^.prop.zoom:=wa.PDWG.Getpcamera^.prop.zoom+tzoom{*i}/steps;
1053   param.firstdraw := true;
1054   PDWG.Getpcamera^.NextPosition;
1055   //RestoreMouse;
1056   {}CalcOptimalMatrix;
1057   mouseunproject(param.md.mouse.x,param.md.mouse.y);
1058   reprojectaxis;
1059   PDWG.GetCurrentROOT.CalcVisibleByTree(PDWG.Getpcamera^.frustum,PDWG.Getpcamera.POSCOUNT,PDWG.Getpcamera.VISCOUNT,PDWG.GetCurrentRoot.ObjArray.ObjTree,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1060   PDWG.GetConstructObjRoot.calcvisible(PDWG.Getpcamera^.frustum,PDWG.Getpcamera.POSCOUNT,PDWG.Getpcamera.VISCOUNT,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1061   WaMouseMove(nil,[],param.md.mouse.x,param.md.mouse.y);
1062   if i=steps then
1063     begin
1064   if param.seldesc.MouseFrameON then
1065   begin
1066     pdwg.myGluProject2(param.seldesc.Frame13d,
1067                fv1);
1068     param.seldesc.Frame1.x := round(fv1.x);
1069     param.seldesc.Frame1.y := getviewcontrol.clientheight - round(fv1.y);
1070     if param.seldesc.Frame1.x < 0 then param.seldesc.Frame1.x := 0
1071     else if param.seldesc.Frame1.x > (getviewcontrol.clientwidth - 1) then param.seldesc.Frame1.x := getviewcontrol.clientwidth - 1;
1072     if param.seldesc.Frame1.y < 0 then param.seldesc.Frame1.y := 1
1073     else if param.seldesc.Frame1.y > (getviewcontrol.clientheight - 1) then param.seldesc.Frame1.y := getviewcontrol.clientheight - 1;
1074   end;
1075   end;{}
1076   //----ComitFromObj;
1077 
1078   if sysvarRDLastRenderTime<30 then
1079                                         sleep(30-sysvarRDLastRenderTime);
1080   end;
1081   pcam.prop.xdir:=x0;
1082   pcam.prop.ydir:=y0;
1083   pcam.prop.look:=z0;
1084   PDWG^.StoreNewCamerapPos(pucommand);
1085   calcgrid;
1086 
1087   draw;
1088 
1089 end;
1090 procedure TGeneralViewArea.ZoomSel;
1091 var
1092    psa:PGDBSelectedObjArray;
1093    dc:TDrawContext;
1094 begin
1095      psa:=PDWG^.GetSelObjArray;
1096      if psa<>nil then
1097      begin
1098           if psa^.Count=0 then
1099                               begin
1100                                    DebugLn('{WH}'+'ZoomSel: Ничего не выбрано?');
1101                                    //historyout('ZoomSel: Ничего не выбрано?');
1102                                    exit;
1103                               end;
1104           dc:=pdwg^.CreateDrawingRC;
1105           zoomtovolume(psa^.getonlyoutbound(dc));
1106      end;
1107 
1108 end;
1109 procedure TGeneralViewArea.ZoomAll;
1110 var
1111   proot:PGDBObjGenericSubEntry;
1112 begin
1113   proot:=pdwg.GetCurrentROOT;
1114   if proot<>nil then
1115                     zoomtovolume(proot.vp.BoundingBox);
1116 end;
1117 
1118 procedure TGeneralViewArea.ZoomToVolume(Volume:TBoundingBox);
1119   const
1120        steps=10;
1121   var
1122     tpz,tzoom: GDBDouble;
1123     {fv1,tp,}wcsLBN,wcsRTF,dcsLBN,dcsRTF: GDBVertex;
1124     camerapos,target:GDBVertex;
1125     i:integer;
1126     pucommand:pointer;
1127   begin
1128     if param.projtype = PROJPerspective then
1129                                             begin
1130                                                  //historyout('Zoom: Works only for parallel projection!');
1131                                                  DebugLn('{WH}Zoom:'+rswonlyparalel);
1132                                             end;
1133     //historyout('Zoom: Works only for top view!');
1134     DebugLn('{WH}Zoom:'+rswonlytop);
1135 
1136 
1137 
1138     CalcOptimalMatrix;
1139 
1140     dcsLBN:=InfinityVertex;
1141     dcsRTF:=MinusInfinityVertex;
1142     wcsLBN:=InfinityVertex;
1143     wcsRTF:=MinusInfinityVertex;
1144     {tp:=}ProjectPoint(Volume.LBN.x,Volume.LBN.y,Volume.LBN.Z,wcsLBN,wcsRTF,dcsLBN,dcsRTF);
1145     {tp:=}ProjectPoint(Volume.RTF.x,Volume.LBN.y,Volume.LBN.Z,wcsLBN,wcsRTF,dcsLBN,dcsRTF);
1146     {tp:=}ProjectPoint(Volume.RTF.x,Volume.RTF.y,Volume.LBN.Z,wcsLBN,wcsRTF,dcsLBN,dcsRTF);
1147     {tp:=}ProjectPoint(Volume.LBN.x,Volume.RTF.y,Volume.LBN.Z,wcsLBN,wcsRTF,dcsLBN,dcsRTF);
1148     {tp:=}ProjectPoint(Volume.LBN.x,Volume.LBN.y,Volume.RTF.Z,wcsLBN,wcsRTF,dcsLBN,dcsRTF);
1149     {tp:=}ProjectPoint(Volume.RTF.x,Volume.LBN.y,Volume.RTF.Z,wcsLBN,wcsRTF,dcsLBN,dcsRTF);
1150     {tp:=}ProjectPoint(Volume.RTF.x,Volume.RTF.y,Volume.RTF.Z,wcsLBN,wcsRTF,dcsLBN,dcsRTF);
1151     {tp:=}ProjectPoint(Volume.LBN.x,Volume.RTF.y,Volume.RTF.Z,wcsLBN,wcsRTF,dcsLBN,dcsRTF);
1152 
1153     dcsLBN.z:=0;
1154     dcsRTF.z:=0;
1155     pdwg.myGluUnProject(dcsLBN,wcsLBN);
1156     pdwg.myGluUnProject(dcsRTF,wcsRTF);
1157 
1158        if wcsRTF.x<wcsLBN.x then
1159                                 begin
1160                                      tpz:=wcsLBN.x;
1161                                      wcsLBN.x:=wcsRTF.x;
1162                                      wcsRTF.x:=tpz;
1163                                 end;
1164        if wcsRTF.y<wcsLBN.y then
1165                                 begin
1166                                 tpz:=wcsLBN.y;
1167                                 wcsLBN.y:=wcsRTF.y;
1168                                 wcsRTF.y:=tpz;
1169                                 end;
1170        if wcsRTF.z<wcsLBN.z then
1171                                 begin
1172                                 tpz:=wcsLBN.z;
1173                                 wcsLBN.z:=wcsRTF.z;
1174                                 wcsRTF.z:=tpz;
1175                                 end;
1176     if (abs(wcsRTF.x-wcsLBN.x)<eps)and(abs(wcsRTF.y-wcsLBN.y)<eps) then
1177                                                                       begin
1178                                                                            //historyout('ZoomToVolume: Пустой чертеж?');
1179                                                                            DebugLn('{WH}'+'ZoomToVolume: Пустой чертеж?');
1180                                                                            exit;
1181                                                                       end;
1182     target:=createvertex(-(wcsLBN.x+(wcsRTF.x-wcsLBN.x)/2),-(wcsLBN.y+(wcsRTF.y-wcsLBN.y)/2),-(wcsLBN.z+(wcsRTF.z-wcsLBN.z)/2));
1183     camerapos:=pdwg.Getpcamera^.prop.point;
1184     target:=vertexsub(target,camerapos);
1185 
1186     tzoom:=abs((wcsRTF.x-wcsLBN.x){*wa.pdwg.GetPcamera.prop.xdir.x}/getviewcontrol.clientwidth);
1187     tpz:=abs((wcsRTF.y-wcsLBN.y){*wa.pdwg.GetPcamera.prop.ydir.y}/getviewcontrol.clientheight);
1188 
1189     //-------with gdb.GetCurrentDWG.UndoStack.PushCreateTGChangeCommand(gdb.GetCurrentDWG.pcamera^.prop)^ do
1190     pucommand:=PDWG^.StoreOldCamerapPos;
1191     begin
1192 
1193     if tpz>tzoom then tzoom:=tpz;
1194 
1195     tzoom:=tzoom-PDWG.Getpcamera^.prop.zoom;
1196 
1197     for i:=1 to steps do
1198     begin
1199     SetCameraPosZoom(vertexadd(camerapos,uzegeometry.VertexMulOnSc(target,i/steps)),PDWG.Getpcamera^.prop.zoom+tzoom{*i}/steps,i=steps);
1200     //if assigned(sysvar.RD.RD_LastRenderTime)then
1201     if sysvarRDLastRenderTime<30 then
1202                                           sleep(30-sysvarRDLastRenderTime);
1203     end;
1204     PDWG^.StoreNewCamerapPos(pucommand);
1205     calcgrid;
1206 
1207     draw;
1208     doCameraChanged;
1209     end;
1210   end;
1211 procedure TGeneralViewArea.DISP_ZoomFactor;
1212 var
1213   glx1, gly1: GDBDouble;
1214   pucommand:pointer;
1215 //  fv1: GDBVertex;
1216 begin
1217   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.DISP_ZoomFactor',lp_incPos);{$ENDIF}
1218   //gdb.GetCurrentDWG.UndoStack.PushChangeCommand(@gdb.GetCurrentDWG.pcamera^.prop,sizeof(GDBCameraBaseProp));
1219   //with gdb.GetCurrentDWG.UndoStack.PushCreateTGChangeCommand(gdb.GetCurrentDWG.pcamera^.prop)^ do
1220   pucommand:=PDWG^.StoreOldCamerapPos;
1221   begin
1222         CalcOptimalMatrix;
1223         if not param.md.mousein then
1224                                     mouseunproject(getviewcontrol.clientwidth div 2, getviewcontrol.clientheight div 2);
1225         glx1 := param.md.mouseray.lbegin.x;
1226         gly1 := param.md.mouseray.lbegin.y;
1227         if param.projtype = ProjParalel then
1228           PDWG.Getpcamera^.prop.zoom := PDWG.Getpcamera^.prop.zoom * x
1229         else
1230         begin
1231           PDWG.Getpcamera^.prop.point.x := PDWG.Getpcamera^.prop.point.x + (PDWG.Getpcamera^.prop.look.x *
1232           (PDWG.Getpcamera^.zmax - PDWG.Getpcamera^.zmin) * sign(x - 1) / 10);
1233           PDWG.Getpcamera^.prop.point.y := PDWG.Getpcamera^.prop.point.y + (PDWG.Getpcamera^.prop.look.y *
1234           (PDWG.Getpcamera^.zmax - PDWG.Getpcamera^.zmin) * sign(x - 1) / 10);
1235           PDWG.Getpcamera^.prop.point.z := PDWG.Getpcamera^.prop.point.z + (PDWG.Getpcamera^.prop.look.z *
1236           (PDWG.Getpcamera^.zmax - PDWG.Getpcamera^.zmin) * sign(x - 1) / 10);
1237         end;
1238 
1239         CalcOptimalMatrix;
1240         if param.md.mousein then
1241                                 mouseunproject(param.md.mouse.x, getviewcontrol.clientheight-param.md.mouse.y)
1242                             else
1243                                 mouseunproject(getviewcontrol.clientwidth div 2, getviewcontrol.clientheight div 2);
1244         if param.projtype = ProjParalel then
1245         begin
1246         PDWG.Getpcamera^.prop.point.x := PDWG.Getpcamera^.prop.point.x - (glx1 - param.md.mouseray.lbegin.x);
1247         PDWG.Getpcamera^.prop.point.y := PDWG.Getpcamera^.prop.point.y - (gly1 - param.md.mouseray.lbegin.y);
1248         end;
1249         PDWG^.StoreNewCamerapPos(pucommand);
1250         //ComitFromObj;
1251   end;
1252   doCameraChanged;
1253   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.DISP_ZoomFactor----{end}',lp_decPos);{$ENDIF}
1254 end;
1255 
1256 procedure TGeneralViewArea.SetCameraPosZoom(_pos:gdbvertex;_zoom:gdbdouble;finalcalk:gdbboolean);
1257 var
1258   fv1: GDBVertex;
1259 begin
1260     PDWG.Getpcamera^.prop.point:=_pos;
1261     PDWG.Getpcamera^.prop.zoom:=_zoom;
1262     param.firstdraw := true;
1263     PDWG.Getpcamera^.NextPosition;
1264 
1265     CalcOptimalMatrix;
1266     mouseunproject(param.md.mouse.x,param.md.mouse.y);
1267     reprojectaxis;
1268     PDWG.GetCurrentROOT.CalcVisibleByTree(PDWG.Getpcamera^.frustum,PDWG.Getpcamera.POSCOUNT,PDWG.Getpcamera.VISCOUNT,PDWG.GetCurrentRoot.ObjArray.ObjTree,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1269     PDWG.GetConstructObjRoot.calcvisible(PDWG.Getpcamera^.frustum,PDWG.Getpcamera.POSCOUNT,PDWG.Getpcamera.VISCOUNT,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1270 
1271   if finalcalk then
1272     begin
1273   if param.seldesc.MouseFrameON then
1274   begin
1275     pdwg.myGluProject2(param.seldesc.Frame13d,
1276                fv1);
1277     param.seldesc.Frame1.x := round(fv1.x);
1278     param.seldesc.Frame1.y := getviewcontrol.clientheight - round(fv1.y);
1279     if param.seldesc.Frame1.x < 0 then param.seldesc.Frame1.x := 0
1280     else if param.seldesc.Frame1.x > (getviewcontrol.clientwidth - 1) then param.seldesc.Frame1.x := getviewcontrol.clientwidth - 1;
1281     if param.seldesc.Frame1.y < 0 then param.seldesc.Frame1.y := 1
1282     else if param.seldesc.Frame1.y > (getviewcontrol.clientheight - 1) then param.seldesc.Frame1.y := getviewcontrol.clientheight - 1;
1283   end;
1284   end;
1285   WaMouseMove(nil,[],param.md.mouse.x,param.md.mouse.y);
1286 end;
1287 
1288 procedure TGeneralViewArea.Set3dmouse;
1289 begin
1290     if (param.ospoint.ostype <> os_none)or(currentmousemovesnaptogrid)
1291     then
1292     begin
1293          param.md.mouse3dcoord:=param.ospoint.worldcoord;
1294     end
1295     else
1296     begin
1297         if param.md.mouseonworkplan
1298         then
1299             begin
1300                  param.md.mouse3dcoord:=param.md.mouseonworkplanecoord;
1301             end
1302         else
1303             begin
1304                  param.md.mouse3dcoord:=param.md.mouseray.lbegin;
1305             end;
1306        end;
1307 end;
1308 
1309 procedure TGeneralViewArea.doCameraChanged;
1310 begin
1311      if assigned(onCameraChanged) then onCameraChanged;
1312 end;
TGeneralViewArea.startpaintnull1313 function TGeneralViewArea.startpaint;
1314 begin
1315      result:=drawer.startpaint(InsidePaintMessage>0,getviewcontrol.clientwidth,getviewcontrol.clientheight);
1316 end;
1317 procedure TGeneralViewArea.endpaint;
1318 begin
1319      drawer.endpaint(InsidePaintMessage>0);
1320 end;
1321 procedure TGeneralViewArea.WaMouseEnter;
1322 begin
1323      param.md.mousein:=true;
1324      //DrawOrInvalidate
1325 end;
1326 procedure TGeneralViewArea.WaMouseLeave;
1327 begin
1328      param.md.mousein:=false;
1329      DrawOrInvalidate;
1330 end;
1331 procedure TGeneralViewArea.WaResize(sender:tobject);
1332 var
1333    rect:trect;
1334 begin
1335      rect:=getviewcontrol.ClientRect;
1336      drawer.WorkAreaResize(rect);
1337      getviewcontrol.invalidate;
1338      param.height := rect.bottom;
1339      param.width := rect.right;
1340 end;
1341 procedure TGeneralViewArea.WaMouseWheel(Sender:TObject;Shift: TShiftState; WheelDelta: Integer;MousePos: TPoint;var handled:boolean);
1342 //procedure TOGLWnd.Pre_MouseWheel;
1343 var
1344 //  mpoint: tpoint;
1345   smallwheel:gdbdouble;
1346 //    glx1, gly1: GDBDouble;
1347   //fv1: GDBVertex;
1348 
1349 //  msg : TMsg;
1350 
1351 begin
1352   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.DoMouseWheel',lp_incPos);{$ENDIF}
1353   smallwheel:=1+(sysvarDISPZoomFactor-1)/10;
1354   //mpoint := point(mousepos.x - clientorigin.X, mousepos.y - clientorigin.y);
1355   if {mousein(mpoint)}true then
1356   begin
1357     //mpoint := point({mpoint.x - left}0, {mpoint.y - top}0);
1358     if wheeldelta < 0 then
1359     begin
1360       if (ssShift in Shift) then
1361         DISP_ZoomFactor({1.01}smallwheel)
1362       else
1363       begin
1364         ClearOntrackpoint;
1365         Create0axis;
1366         DISP_ZoomFactor(sysvarDISPZoomFactor);
1367       end;
1368       //handled := true;
1369     end
1370     else
1371     begin
1372       if (ssShift in Shift) then
1373         DISP_ZoomFactor({0.990099009901}1/smallwheel)
1374       else
1375       begin
1376         ClearOntrackpoint;
1377         DISP_ZoomFactor(1 / sysvarDISPZoomFactor);
1378       end;
1379       //handled := true;
1380     end;
1381   end;
1382   //pre_mousemove(0,param.md.mouse.x,param.md.mouse.y,r);
1383       //param.firstdraw := true;
1384       //CalcOptimalMatrix;
1385       //gdb.GetCurrentDWG.ObjRoot.calcvisible;
1386       //gdb.GetCurrentDWG.ConstructObjRoot.calcvisible;
1387       //reprojectaxis;
1388       //draw;
1389       pdwg.getpcamera^.NextPosition;
1390       param.firstdraw:=true;
1391   restoremouse;
1392   paint;
1393 
1394   {if (PeekMessage(msg,handle,WM_MOUSEWHEEL,0,PM_NOREMOVE)) then
1395                                                                            param.scrollmode:=true
1396                                                                        else
1397                                                                            begin
1398                                                                            param.scrollmode:=false;
1399                                                                            paint;
1400                                                                            end;}
1401 
1402   inherited;
1403   handled:=true;
1404   WaMouseMove(self,[],param.md.mouse.x,param.md.mouse.y);
1405   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.DoMouseWheel----{end}',lp_decPos);{$ENDIF}
1406 end;
1407 
1408 procedure TGeneralViewArea.WaMouseMove(sender:tobject;Shift: TShiftState; X, Y: Integer);
1409 var
1410   //glmcoord1: gdbpiece;
1411   ux,uy:GDBDouble;
1412   //htext,htext2:gdbstring;
1413   key: GDBByte;
1414   //f:TzeUnitsFormat;
1415 begin
1416   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.Pre_MouseMove',lp_IncPos);{$ENDIF}
1417   if assigned(mainmousemove)then
1418                                 mainmousemove;
1419   KillOHintTimer(self);
1420   SetOHintTimer(self);
1421   currentmousemovesnaptogrid:=false;
1422   key:=0;
1423   if (ssShift in Shift) then
1424                             key := key or MZW_SHIFT;
1425   if (ssCtrl in Shift) then
1426                                     key := key or MZW_CONTROL;
1427   if pdwg=nil then
1428                             begin
1429                                    param.md.mouse.y := y;
1430                                    param.md.mouse.x := x;
1431                                    param.md.glmouse.y := getviewcontrol.clientheight-y;
1432                                    param.md.glmouse.x := x;
1433                                    exit;
1434                             end;
1435   //glmcoord1:= param.md.mouseraywithoutos;
1436   //if param.ospoint.ostype<>os_none then
1437   //                                   glmcoord1.lend := param.ospoint.worldcoord;  //пан при привязке ездит меньше
1438 
1439   if ((param.md.mode) and ((MRotateCamera) or (MMoveCamera)) <> 0) then
1440     if ((ssCtrl in shift) and ((ssMiddle in shift))) and ((param.md.mode) and (MRotateCamera) <> 0) then
1441     begin
1442       uy :=(x - param.md.mouse.x) / 1000;
1443       ux :=- (y - param.md.mouse.y) / 1000;
1444       pdwg.RotateCameraInLocalCSXY(ux,uy);
1445       {with gdb.GetCurrentDWG.UndoStack.CreateTGChangeCommand(gdb.GetCurrentDWG.pcamera^.prop)^ do
1446       begin
1447       gdb.GetCurrentDWG.pcamera.RotateInLocalCSXY(ux,uy);
1448       ComitFromObj;
1449       end;}
1450       param.firstdraw := true;
1451       pdwg.GetPcamera^.NextPosition;
1452       CalcOptimalMatrix;
1453       calcgrid;
1454       //-------------------CalcOptimalMatrix;
1455 
1456       pdwg.GetCurrentROOT.CalcVisibleByTree(pdwg.Getpcamera^.frustum,pdwg.Getpcamera.POSCOUNT,pdwg.Getpcamera.VISCOUNT,pdwg.GetCurrentROOT.ObjArray.ObjTree,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1457       //gdb.GetCurrentROOT.calcalcvisible(gdb.GetCurrentDWG.pcamera^.frustum,gdb.GetCurrentDWG.pcamera.POSCOUNT);
1458       pdwg.GetConstructObjRoot.calcvisible(pdwg.Getpcamera^.frustum,pdwg.Getpcamera.POSCOUNT,pdwg.Getpcamera.VISCOUNT,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1459       doCameraChanged;
1460     end
1461     else
1462       if ssMiddle in shift then     {MK_Control}
1463 begin
1464       PanScreen(param.md.mouse.x,param.md.mouse.y,X,Y{,glmcoord1});
1465       doCameraChanged;
1466 end;
1467 
1468   param.md.mouse.y := y;
1469   param.md.mouse.x := x;
1470   param.md.glmouse.y := getviewcontrol.clientheight-y;
1471   param.md.glmouse.x := x;
1472 
1473   param.md.mouseglue := param.md.mouse;
1474   param.gluetocp := false;
1475 
1476   if (param.md.mode and MGetControlpoint) <> 0 then
1477   begin
1478     param.nearesttcontrolpoint:=pdwg.GetSelObjArray.getnearesttomouse(param.md.mouse.x,param.height-param.md.mouse.y);
1479     if (param.nearesttcontrolpoint.pcontrolpoint = nil) or (param.nearesttcontrolpoint.disttomouse > 2 * sysvarDISPCursorSize) then
1480     begin
1481       param.md.mouseglue := param.md.mouse;
1482       param.gluetocp := false;
1483     end
1484     else begin
1485       param.gluetocp := true;
1486       param.md.mouseglue := param.nearesttcontrolpoint.pcontrolpoint^.dispcoord;
1487       param.md.mouseglue.y:=getviewcontrol.clientheight-param.md.mouseglue.y;
1488     end;
1489   end
1490   else param.md.mouseglue := param.md.mouse;
1491 
1492   //wa.param.md.mouse:=wa.param.md.mouseglue;
1493   param.md.glmouse.x := param.md.mouseglue.x;
1494   param.md.glmouse.y := getviewcontrol.clientheight-param.md.mouseglue.y;
1495 
1496   CalcOptimalMatrix;
1497   mouseunproject(param.md.glmouse.X, param.md.glmouse.Y);
1498   CalcMouseFrustum;
1499 
1500 
1501 
1502 
1503   //gdb.GetCurrentDWG.pcamera^.getfrustum();   tyui
1504   //param.mousefrustum:=gdb.GetCurrentDWG.pcamera^.frustum;
1505 
1506 {  for I := 0 to 5 do
1507     //if param.mousefrustum[0][i]<0 then
1508                                       begin
1509                                            param.mousefrustum[i][0]:=-param.mousefrustum[i][0];
1510                                            param.mousefrustum[i][1]:=-param.mousefrustum[i][1];
1511                                            param.mousefrustum[i][2]:=-param.mousefrustum[i][2];
1512                                            param.mousefrustum[i][3]:=-param.mousefrustum[i][3];
1513 
1514                                            param.mousefrustum[i][0]:=param.mousefrustum[i][0]*0.5;
1515                                            param.mousefrustum[i][1]:=param.mousefrustum[i][1]*0.5;
1516                                            param.mousefrustum[i][2]:=param.mousefrustum[i][2]*0.5;
1517                                            param.mousefrustum[i][3]:=param.mousefrustum[i][3]*0.99;
1518                                       end;
1519 
1520  }
1521   {param.mousefrustum[0][3]:=-param.mousefrustum[0][3];
1522   param.mousefrustum[0][0]:=-param.mousefrustum[0][0];
1523 
1524   param.mousefrustum[1][3]:=-param.mousefrustum[1][3];
1525   param.mousefrustum[1][0]:=-param.mousefrustum[1][0];}
1526 
1527   {param.mousefrustum[1][3]:=-param.mousefrustum[1][3];
1528   param.mousefrustum[1][0]:=-param.mousefrustum[1][0];}
1529 
1530   {
1531   param.mousefrustum[1][3]:=-param.mousefrustum[1][3];
1532   param.mousefrustum[2][3]:=-param.mousefrustum[2][3];
1533   param.mousefrustum[3][3]:=-param.mousefrustum[3][3];}
1534 
1535 
1536 
1537 
1538 
1539 
1540 
1541 
1542   if (param.md.mode and MGetSelectObject) <> 0 then
1543                                                      getonmouseobjectbytree(PDWG.GetCurrentROOT.ObjArray.ObjTree,sysvarDWGEditInSubEntry);
1544   if (param.md.mode and MGet3DPointWoOP) <> 0 then param.ospoint.ostype := os_none;
1545   if (param.md.mode and MGet3DPoint) <> 0 then
1546   begin
1547 
1548       if (param.md.mode and MGetSelectObject) = 0 then
1549                                                       getonmouseobjectbytree(pdwg.GetCurrentROOT.ObjArray.ObjTree,sysvarDWGEditInSubEntry);
1550       getosnappoint({@gdb.GetCurrentROOT.ObjArray,} 0);
1551       //create0axis;-------------------------------
1552     if sysvarDWGOSMode <> 0 then
1553     begin
1554       if otracktimer = 1 then
1555       begin
1556         otracktimer := 0;
1557         projectaxis;
1558         project0axis;//-------------------------------
1559         AddOntrackpoint;
1560       end;
1561       if (param.ospoint.ostype <> os_none)and(param.ospoint.ostype <> os_snap)and(param.ospoint.ostype <> os_nearest)and(param.ospoint.ostype<>os_perpendicular) then
1562       begin
1563         SetOTrackTimer(@self);
1564         copyospoint(param.oldospoint,param.ospoint);
1565       end
1566       else KillOTrackTimer(@self)
1567     end
1568     else param.ospoint.ostype := os_none;
1569 
1570   end
1571   else param.ospoint.ostype := os_none;
1572 
1573 
1574 
1575 
1576   reprojectaxis;
1577 
1578   if assigned(OnWaMouseMove) then
1579                                  OnWaMouseMove(self,shift,x,y);
1580     {if pcommandrunning <> nil then
1581     begin
1582       if param.ospoint.ostype <> os_none then pcommandrunning^.MouseMoveCallback(param.ospoint.worldcoord, param.md.mouse, 0)
1583       else begin
1584         if param.mouseonworkplan then
1585           pcommandrunning^.MouseMoveCallback(param.mouseonworkplanecoord,param.md.mouse, 0)
1586         else pcommandrunning^.MouseMoveCallback(param.glmcoord[0], param.md.mouse, 0);
1587       end;
1588     end;}
1589      //glGetDoublev(GL_MODELVIEW_MATRIX,@modelMatrix);
1590   //mouseunproject(param.md.mouse.x, param.md.mouse.y);
1591   //reprojectaxis;
1592 
1593 
1594   (* убрано в FrameEdit_com_AfterClick
1595   if param.seldesc.MouseFrameON then
1596   begin
1597     pdwg^.myGluProject2(param.seldesc.Frame13d,
1598                glmcoord1.lbegin);
1599     param.seldesc.Frame1.x := round(glmcoord1.lbegin.x);
1600     param.seldesc.Frame1.y := getviewcontrol.clientheight - round(glmcoord1.lbegin.y);
1601     if param.seldesc.Frame1.x < 0 then param.seldesc.Frame1.x := 0
1602     else if param.seldesc.Frame1.x > (getviewcontrol.clientwidth - 1) then param.seldesc.Frame1.x := getviewcontrol.clientwidth - 1;
1603     if param.seldesc.Frame1.y < 0 then param.seldesc.Frame1.y := 1
1604     else if param.seldesc.Frame1.y > (getviewcontrol.clientheight - 1) then param.seldesc.Frame1.y := getviewcontrol.clientheight - 1;
1605   end;*)
1606 
1607 
1608      //GDBobjinsp23.reread;
1609   //CalcOptimalMatrix;
1610   CalcOptimalMatrix;
1611   pdwg.GetConstructObjRoot.calcvisible(pdwg.Getpcamera^.frustum,pdwg.Getpcamera.POSCOUNT,pdwg.Getpcamera.VISCOUNT,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1612 
1613   //gdb.GetCurrentDWG.ConstructObjRoot.calcvisible(gdb.GetCurrentDWG.OGLwindow1.wa.param.mousefrustum);
1614 
1615   pdwg.GetSelObjArray.calcvisible(pdwg.Getpcamera^.frustum,pdwg.Getpcamera.POSCOUNT,pdwg.Getpcamera.VISCOUNT,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
1616   Set3dmouse;
1617   CorrectMouseAfterOS;
1618   draworinvalidate;
1619 end;
1620 procedure TGeneralViewArea.asynczoomsel(Data: PtrInt);
1621 begin
1622      ZoomSel();
1623 end;
1624 procedure TGeneralViewArea.asynczoomall(Data: PtrInt);
1625 begin
1626      ZoomAll();
1627 end;
1628 procedure TGeneralViewArea.asyncupdatemouse(Data: PtrInt);
1629 begin
1630      WaMouseMove(nil,[],param.md.mouse.x,param.md.mouse.y);
1631 end;
1632 destructor TGeneralViewArea.Destroy;
1633 begin
1634   Drawer.delmyscrbuf;
1635   PolarAxis.done;
1636   param.done;
1637   freeandnil(drawer);
1638   freeandnil(OTTimer);
1639   freeandnil(OHTimer);
1640   inherited;
1641 end;
1642 
1643 constructor TGeneralViewArea.Create(TheOwner: TComponent);
1644 var
1645   i:integer;
1646   v:gdbvertex;
1647 begin
1648      inherited;
1649      InsidePaintMessage:=0;
1650      drawer:=nil;
1651 
1652      WorkArea:=CreateWorkArea(TheOwner);
1653      CreateDrawer;
1654      SetupWorkArea;
1655 
1656      OTTimer:=TTimer.create(self);
1657      OHTimer:=TTimer.create(self);
1658 
1659      PDWG:=nil;
1660 
1661      param.init;
1662      SetMouseMode((MGetControlpoint) or (MGetSelectObject) or (MMoveCamera) or (MRotateCamera) or (MGetSelectionFrame));
1663 
1664      PolarAxis.init({$IFDEF DEBUGBUILD}'{5AD9927A-0312-4844-8C2D-9498647CCECB}',{$ENDIF}10);
1665 
1666      for i := 0 to 4 - 1 do
1667      begin
1668        v.x:=cos(pi * i / 4);
1669        v.y:=sin(pi * i / 4);
1670        v.z:=0;
1671        PolarAxis.PushBackData(v);
1672      end;
1673 
1674      tocommandmcliccount:=0;
1675 
1676      if PDWG<>nil then
1677      begin
1678      PDWG.Getpcamera^.obj_zmax:=-1;
1679      PDWG.Getpcamera^.obj_zmin:=100000;
1680      end;
1681 
1682 
1683      //OpenGLWindow.wa:=self;
1684      onCameraChanged:=nil;
1685      ShowCXMenu:=nil;
1686      MainMouseMove:=nil;
1687      MainMouseDown:=nil;
1688      MainMouseUp:=nil;
1689 
1690      WorkArea.onmouseup:=WaMouseUp;
1691      WorkArea.onmousedown:=WaMouseDown;
1692      WorkArea.onmousemove:=WaMouseMove;
1693      WorkArea.onmousewheel:=WaMouseWheel;
1694      WorkArea.onmouseenter:=WaMouseEnter;
1695      WorkArea.onmouseleave:=WaMouseLeave;
1696      WorkArea.onresize:=WaResize;
1697 end;
MouseButton2ZKeynull1698 function MouseButton2ZKey(Shift: TShiftState):GDBByte;
1699 begin
1700   result := 0;
1701   if (ssLeft in shift) then
1702                            result := result or MZW_LBUTTON;
1703   if (ssShift in shift) then result := result or MZW_SHIFT;
1704   if (ssCtrl in shift) then result := result or MZW_CONTROL;
1705 end;
TGeneralViewArea.getviewcontrolnull1706 function TGeneralViewArea.getviewcontrol:TCADControl;
1707 begin
1708      result:=WorkArea;
1709 end;
1710 procedure TGeneralViewArea.WaMouseDown(Sender:TObject;Button: TMouseButton; Shift: TShiftState;X, Y: Integer);
1711 var //key: GDBByte;
1712     NeedRedraw:boolean;
1713     //menu:TmyPopupMenu;
1714     //FreeClick:boolean;
1715 begin
1716   //FreeClick:=true;
1717   if assigned(MainmouseDown)then
1718   if mainmousedown(self) then
1719                        exit;
1720   //if (cxmenumgr.ismenupopup)or(ActivePopupMenu<>nil) then
1721   //                                                       exit;
1722   //ActivePopupMenu:=ActivePopupMenu;
1723   NeedRedraw:=false;
1724   if assigned(OnWaMouseDown) then
1725   if OnWaMouseDown(self,Button,Shift,X, Y,param.SelDesc.OnMouseObject,needredraw) then
1726   begin
1727     if needredraw then
1728                     begin
1729                     param.firstdraw:=true;
1730                     DrawOrInvalidate;
1731                     end;
1732     exit;
1733   end;
1734   if ssRight in shift then
1735                            begin
1736                                 if assigned(ShowCXMenu)then
1737                                                            ShowCXMenu;
1738                                 exit;
1739                            end;
1740   begin
1741   //r.handled:=true;
1742   if pdwg=nil then exit;
1743   //key := MouseButton2ZKey(shift);
1744   if (ssMiddle in shift) then
1745   begin
1746     WorkArea.cursor := crHandPoint;
1747     param.scrollmode:=true;
1748     param.lastonmouseobject := nil;
1749   end;
1750   param.md.mouse.x := x;
1751   param.md.mouse.y := y;
1752 
1753   end;
1754   inherited;
1755   if needredraw then
1756                     begin
1757                     param.firstdraw:=true;
1758                     DrawOrInvalidate;
1759                     end;
1760 end;
1761 
1762 procedure TGeneralViewArea.WaMouseUp(Sender:TObject;Button: TMouseButton; Shift:TShiftState;X, Y: Integer);
1763 begin
1764   inherited;
1765   if button = mbMiddle then
1766   begin
1767     RemoveCursorIfNeed(WorkArea,sysvarRDRemoveSystemCursorFromWorkArea);
1768     param.scrollmode:=false;
1769     param.firstdraw:=true;
1770     WorkArea.invalidate;
1771   end;
1772   if assigned(MainMouseUp) then
1773                                MainMouseUp;
1774 end;
CreateRCnull1775 function TGeneralViewArea.CreateRC(_maxdetail:GDBBoolean=false):TDrawContext;
1776 begin
1777   if PDWG<>nil then
1778                    PDWG^.FillDrawingPartRC(result);
1779 
1780   if sysvarDISPLWDisplayScale<2 then sysvarDISPLWDisplayScale:=2;
1781   if sysvarDISPLWDisplayScale>20 then sysvarDISPLWDisplayScale:=20;
1782   result.LWDisplayScale:=sysvarDISPLWDisplayScale;
1783   result.DefaultLW:=sysvarDISPDefaultLW;
1784 
1785   result.Subrender:=0;
1786   result.Selected:=false;
1787   result.MaxDetail:=_maxdetail;
1788 
1789   {if sysvar.dwg.DWG_DrawMode<>nil then
1790                                       result.DrawMode:=sysvar.dwg.DWG_DrawMode^
1791                                   else
1792                                       result.DrawMode:=true;}
1793   result.OwnerLineWeight:=-3;
1794   result.OwnerColor:=ClWhite;
1795   {if assigned(sysvar.RD.RD_MaxWidth)then
1796                                         result.MaxWidth:=sysvar.RD.RD_MaxWidth^
1797                                     else}
1798   result.MaxWidth:=20;
1799   result.ScrollMode:=param.scrollmode;
1800   result.drawer:=drawer;
1801   result.SystmGeometryDraw:=sysvarDISPSystmGeometryDraw;
1802   result.SystmGeometryColor:=sysvarDISPSystmGeometryColor;
1803   result.DrawingContext.GlobalLTScale:=1;
1804   result.DrawingContext.ForeGroundColorIndex:=ForeGroundColorIndex;
1805 end;
1806 procedure TGeneralViewArea.CorrectMouseAfterOS;
1807 var d,tv1,tv2:GDBVertex;
1808     b1,b2:GDBBoolean;
1809 begin
1810      param.md.mouseraywithoutos:=param.md.mouseray;
1811      if (param.ospoint.ostype <> os_none)or(currentmousemovesnaptogrid) then
1812      begin
1813 
1814      if param.projtype = ProjParalel then
1815      begin
1816           d:=pdwg.getpcamera^.prop.look;
1817           b1:=PointOfLinePlaneIntersect(param.ospoint.worldcoord,d,pdwg.getpcamera^.frustum[4],tv1);
1818           b2:=PointOfLinePlaneIntersect(param.ospoint.worldcoord,d,pdwg.getpcamera^.frustum[5],tv2);
1819           if (b1 and b2) then
1820                              begin
1821                                   param.md.mouseray.lbegin:=tv1;
1822                                   param.md.mouseray.lend:=tv2;
1823                                   param.md.mouseray.dir:=vertexsub(tv2,tv1);
1824                              end;
1825      end
1826      else
1827      begin
1828          d:=VertexSub(param.ospoint.worldcoord,pdwg.getpcamera^.prop.point);
1829          //d:=gdb.GetCurrentDWG.pcamera^.prop.look;
1830          b1:=PointOfLinePlaneIntersect(param.ospoint.worldcoord,d,pdwg.getpcamera^.frustum[4],tv1);
1831          b2:=PointOfLinePlaneIntersect(param.ospoint.worldcoord,d,pdwg.getpcamera^.frustum[5],tv2);
1832          if (b1 and b2) then
1833                             begin
1834                                  param.md.mouseray.lbegin:=tv1;
1835                                  param.md.mouseray.lend:=tv2;
1836                                  param.md.mouseray.dir:=vertexsub(tv2,tv1);
1837                             end;
1838          pdwg^.myGluUnProject(createvertex(param.ospoint.dispcoord.x, param.ospoint.dispcoord.y, 0),param.md.mouseray.lbegin);
1839          pdwg^.myGluUnProject(createvertex(param.ospoint.dispcoord.x, param.ospoint.dispcoord.y, 1),param.md.mouseray.lend);
1840      end;
1841      end;
1842 end;
1843 procedure TGeneralViewArea.AddOntrackpoint;
1844 begin
1845   if not sysvarDWGPolarMode then exit;
1846   copyospoint(param.ontrackarray.otrackarray[param.ontrackarray.current],param.ospoint);
1847   param.ontrackarray.otrackarray[param.ontrackarray.current].arrayworldaxis.clear;
1848   param.ontrackarray.otrackarray[param.ontrackarray.current].arraydispaxis.clear;
1849   param.ospoint.arrayworldaxis.copyto(param.ontrackarray.otrackarray[param.ontrackarray.current].arrayworldaxis);
1850   param.ospoint.arraydispaxis.copyto(param.ontrackarray.otrackarray[param.ontrackarray.current].arraydispaxis);
1851 
1852 
1853   inc(param.ontrackarray.current);
1854   if param.ontrackarray.current = maxtrackpoint then
1855   begin
1856     param.ontrackarray.current := 1;
1857   end;
1858   if param.ontrackarray.total < maxtrackpoint then
1859   begin
1860     inc(param.ontrackarray.total);
1861   end;
1862 end;
1863 
1864 procedure TGeneralViewArea.processmousenode(Node:TEntTreeNode;var i:integer;InSubEntry:GDBBoolean);
1865 //var
1866   //pp:PGDBObjEntity;
1867   //ir:itrec;
1868   //inr:TINRect;
1869 begin
1870      if CalcAABBInFrustum (Node.BoundingBox,param.mousefrustum)<>IREmpty then
1871      begin
1872           findonmobjtree(node, i,InSubEntry);
1873           if assigned(node.pminusnode) then
1874                                            processmousenode(PTEntTreeNode(node.pminusnode)^,i,InSubEntry);
1875           if assigned(node.pplusnode) then
1876                                            processmousenode(PTEntTreeNode(node.pplusnode)^,i,InSubEntry);
1877      end;
1878 end;
1879 
1880 procedure TGeneralViewArea.getonmouseobjectbytree(var Node:TEntTreeNode;InSubEntry:GDBBoolean);
1881 var
1882   i: GDBInteger;
1883   pp:PGDBObjEntity;
1884   ir:itrec;
1885   //inr:TINRect;
1886   DC:TDrawContext;
1887 begin
1888   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.getonmouseobjectbytree',lp_IncPos);{$ENDIF}
1889   i := 0;
1890   PDWG.GetOnMouseObj.clear;
1891   param.SelDesc.OnMouseObject := nil;
1892 
1893 
1894   processmousenode(Node,i,InSubEntry);
1895   if param.processObjConstruct then
1896                                    findonmobj(@PDWG.GetConstructObjRoot.ObjArray,i,InSubEntry);
1897 
1898   pp:=PDWG.GetOnMouseObj.beginiterate(ir);
1899   if pp<>nil then
1900                  begin
1901                       param.lastonmouseobject:=pp;
1902                       dc:=CreateRC;
1903                       repeat
1904                             if pp^.vp.LastCameraPos<>PDWG.Getpcamera^.POSCOUNT then
1905                             pp^.RenderFeedback(PDWG.Getpcamera^.POSCOUNT,PDWG.Getpcamera^,PDWG.myGluProject2,dc);
1906 
1907 
1908                             pp:=PDWG.GetOnMouseObj.iterate(ir);
1909                       until pp=nil;
1910                  end;
1911 
1912   {gdb.GetCurrentDWG.OnMouseObj.clear;
1913   param.SelDesc.OnMouseObject := nil;
1914   param.lastonmouseobject:=nil;}
1915 
1916   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.getonmouseobjectbytree------{end}',lp_DecPos);{$ENDIF}
1917 end;
1918 
1919 procedure TGeneralViewArea.findonmobj(pva: PGDBObjEntityOpenArray; var i: GDBInteger;InSubEntry:GDBBoolean);
1920 var
1921   pp:PGDBObjEntity;
1922   ir:itrec;
1923   _total,_visible,_isonmouse:integer;
1924 begin
1925   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.findonmobj',lp_IncPos);{$ENDIF}
1926   if not param.scrollmode then
1927   begin
1928   _total:=0;
1929   _visible:=0;
1930   _isonmouse:=0;
1931   pp:=pva^.beginiterate(ir);
1932   if pp<>nil then
1933   repeat
1934        inc(_total);
1935        if pp^.visible=PDWG.Getpcamera.VISCOUNT then
1936        begin
1937        inc(_visible);
1938        if pp^.isonmouse(PDWG.GetOnMouseObj^,param.mousefrustum,InSubEntry)
1939        then
1940            begin
1941                 inc(_isonmouse);
1942                 pp:=pp.ReturnLastOnMouse(InSubEntry);
1943                 param.SelDesc.OnMouseObject:=pp;
1944                 PDWG.GetOnMouseObj.PushBackData(pp);
1945            end;
1946 
1947        end;
1948   pp:=pva^.iterate(ir);
1949   until pp=nil;
1950   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('Total:='+inttostr(_total)+'; Visible:='+inttostr(_visible)+'; IsOnMouse:='+inttostr(_isonmouse),0);{$ENDIF}
1951   end
1952   else ;//{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('wa.param.scrollmode=true. exit',0);{$ENDIF}
1953   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.findonmobj-----{end}',lp_DecPos);{$ENDIF}
1954 end;
1955 procedure TGeneralViewArea.findonmobjTree(var Node:TEntTreeNode; var i: GDBInteger;InSubEntry:GDBBoolean);
1956 var
1957   pp:PGDBObjEntity;
1958   ir:itrec;
1959   _total,_visible,_isonmouse:integer;
1960 begin
1961   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.findonmobj',lp_IncPos);{$ENDIF}
1962   if not param.scrollmode then
1963   begin
1964   _total:=0;
1965   _visible:=0;
1966   _isonmouse:=0;
1967   pp:=Node.nulbeginiterate(ir);
1968   if pp<>nil then
1969   repeat
1970        inc(_total);
1971        if pp^.visible=PDWG.Getpcamera.VISCOUNT then
1972        begin
1973        inc(_visible);
1974        if pp^.isonmouse(PDWG.GetOnMouseObj^,param.mousefrustum,InSubEntry)
1975        then
1976            begin
1977                 inc(_isonmouse);
1978                 pp:=pp.ReturnLastOnMouse(InSubEntry);
1979                 param.SelDesc.OnMouseObject:=pp;
1980                 PDWG.GetOnMouseObj.PushBackData(pp);
1981            end;
1982 
1983        end;
1984   pp:=Node.nuliterate(ir);
1985   until pp=nil;
1986   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('Total:='+inttostr(_total)+'; Visible:='+inttostr(_visible)+'; IsOnMouse:='+inttostr(_isonmouse),0);{$ENDIF}
1987   end
1988   else ;//{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('wa.param.scrollmode=true. exit',0);{$ENDIF}
1989   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.findonmobj-----{end}',lp_DecPos);{$ENDIF}
1990 end;
1991 procedure TGeneralViewArea.getonmouseobject;
1992 var
1993   i: GDBInteger;
1994   pp:PGDBObjEntity;
1995   ir:itrec;
1996   DC:TDrawContext;
1997 begin
1998   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.getonmouseobject',lp_IncPos);{$ENDIF}
1999   i := 0;
2000   PDWG.GetOnMouseObj.clear;
2001   param.SelDesc.OnMouseObject := nil;
2002   findonmobj(pva, i,InSubEntry);
2003   pp:=PDWG.GetOnMouseObj.beginiterate(ir);
2004   if pp<>nil then
2005                  begin
2006                      param.lastonmouseobject:=pp;
2007                      dc:=CreateRC;
2008                       repeat
2009                             if pp^.vp.LastCameraPos<>PDWG.Getpcamera^.POSCOUNT then
2010                             pp^.RenderFeedback(PDWG.Getpcamera^.POSCOUNT,PDWG.Getpcamera^,PDWG.myGluProject2,dc);
2011 
2012 
2013                             pp:=PDWG.GetOnMouseObj.iterate(ir);
2014                       until pp=nil;
2015                  end;
2016 
2017   {gdb.GetCurrentDWG.OnMouseObj.clear;
2018   wa.param.SelDesc.OnMouseObject := nil;
2019   wa.param.lastonmouseobject:=nil;}
2020 
2021   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.getonmouseobject------{end}',lp_DecPos);{$ENDIF}
2022 end;
GetFoctOSnapModenull2023 function GetFoctOSnapMode(pv:PGDBObjSubordinated):TOSnapModeControl;
2024 var
2025   owner:PGDBObjSubordinated;
2026 begin
2027   if pv.OSnapModeControl<>AsOwner then
2028     exit(pv.OSnapModeControl)
2029   else begin
2030     owner:=pointer(pv.bp.ListPos.Owner);
2031     if assigned(owner)then
2032       result:=getFoctOSnapMode(owner)
2033     else
2034       result:=on;
2035   end
2036 end;
2037 procedure TGeneralViewArea.getosnappoint({pva: PGDBObjEntityOpenArray; }radius: GDBFloat);
2038 var
2039   pv,pv2:PGDBObjEntity;
2040   osp:os_record;
2041   dx,dy:GDBDouble;
2042 //  oldit:itrec;
2043       ir,ir2:itrec;
2044   pdata:GDBPointer;
2045   DefaultRadius,DefaultTextRadius:GDBDouble;
2046 begin
2047   DefaultRadius:=sysvarDISPCursorSize*sysvarDISPCursorSize+1;
2048   DefaultTextRadius:=(5*5)*DefaultRadius;
2049   param.ospoint.radius:=DefaultRadius;
2050   param.ospoint.ostype:=os_none;
2051       if param.md.mouseonworkplan
2052       then
2053           begin
2054                param.ospoint.worldcoord:=param.md.mouseonworkplanecoord;
2055                //if SysVar.DWG.DWG_SnapGrid<>nil then
2056                if PDWG^.SnapGrid then
2057                begin
2058                     param.ospoint.worldcoord:=correcttogrid(param.ospoint.worldcoord,PDWG^.Snap);
2059                     //param.ospoint.worldcoord.x:=round((param.md.mouseonworkplanecoord.x-SysVar.DWG.DWG_OriginGrid.x)/SysVar.DWG.DWG_StepGrid.x)*SysVar.DWG.DWG_StepGrid.x+SysVar.DWG.DWG_OriginGrid.x;
2060                     //param.ospoint.worldcoord.y:=round((param.md.mouseonworkplanecoord.y-SysVar.DWG.DWG_OriginGrid.y)/SysVar.DWG.DWG_StepGrid.y)*SysVar.DWG.DWG_StepGrid.y+SysVar.DWG.DWG_OriginGrid.y;
2061                     param.ospoint.ostype:=os_snap;
2062                     currentmousemovesnaptogrid:=true;
2063                end;
2064           end
2065       else
2066           begin
2067                param.ospoint.worldcoord:=param.md.mouseray.lbegin;
2068           end;
2069 
2070   param.ospoint.PGDBObject:=nil;
2071   if (param.scrollmode)or(PDWG.GetOnMouseObj.Count=0)then exit;
2072   if PDWG.GetOnMouseObj.Count>0 then
2073      begin
2074      pv:=PDWG.GetOnMouseObj.beginiterate(ir);
2075      if pv<>nil then
2076      repeat
2077      if (not sysvarDWGOSModeControl) or (GetFoctOSnapMode(pv)=on) then
2078      begin
2079        pv.startsnap(osp,pdata);
2080        while pv.getsnap(osp,pdata,param,pdwg.myGluProject2,sysvarDWGOSMode) do
2081        begin
2082             if osp.ostype<>os_none then
2083             begin
2084             dx:=osp.dispcoord.x-param.md.glmouse.x;
2085             dy:=osp.dispcoord.y-param.md.glmouse.y;
2086             osp.radius:=dx*dx+dy*dy;
2087             if osp.ostype<>os_nearest
2088             then
2089             begin
2090                  if param.ospoint.ostype=os_nearest then
2091                  begin
2092                       if (osp.radius<DefaultRadius) then copyospoint(param.ospoint,osp);
2093                  end
2094                  else
2095                  if (osp.radius<=param.ospoint.radius)or(osp.ostype=os_textinsert) then
2096                                                                                        begin
2097                                                                                             if (osp.radius<param.ospoint.radius) then
2098                                                                                                                                      begin
2099                                                                                                                                      if osp.ostype<param.ospoint.ostype then
2100                                                                                                                                           copyospoint(param.ospoint,osp)
2101 
2102                                                                                                                                      end
2103                                                                                        else
2104                                                                                            if ((osp.ostype<>os_perpendicular)and(osp.ostype<>os_textinsert))or((osp.ostype=os_textinsert)and (osp.radius<=DefaultTextRadius)) then
2105                                                                                                                                      copyospoint(param.ospoint,osp)
2106                                                                                        end;
2107             end
2108             else
2109             begin
2110                  if (osp.radius<DefaultRadius)and(param.ospoint.ostype=os_none) then copyospoint(param.ospoint,osp)
2111                  else if param.ospoint.ostype=os_nearest then
2112                                                             if (osp.radius<param.ospoint.radius) then
2113                                                                                                    copyospoint(param.ospoint,osp);
2114             end;
2115             end;
2116        end;
2117        pv.endsnap(osp,pdata);
2118      end;
2119      pv:=PDWG.GetOnMouseObj.iterate(ir);
2120      until pv=nil;
2121      end;
2122   if ((sysvarDWGOSMode and osm_apparentintersection)<>0)or((sysvarDWGOSMode and osm_intersection)<>0)then
2123   begin
2124   if (PDWG.GetOnMouseObj.Count>1)and(PDWG.GetOnMouseObj.Count<10) then
2125   begin
2126   pv:=PDWG.GetOnMouseObj.beginiterate(ir);
2127   repeat
2128   if pv<>nil then
2129   begin
2130   pv2:=PDWG.GetOnMouseObj.beginiterate(ir2);
2131   if pv2<>nil then
2132   repeat
2133   if pv<>pv2 then
2134   if (not sysvarDWGOSModeControl) or ((GetFoctOSnapMode(pv)=on)and(GetFoctOSnapMode(pv2)=on)) then
2135   begin
2136        pv.startsnap(osp,pdata);
2137        while pv.getintersect(osp,pv2,param,PDWG.myGluProject2,sysvarDWGOSMode) do
2138        begin
2139             if osp.ostype<>os_none then
2140             begin
2141             dx:=osp.dispcoord.x-param.md.glmouse.x;
2142             dy:=osp.dispcoord.y-param.md.glmouse.y;
2143             osp.radius:=dx*dx+dy*dy;
2144             if (osp.radius<=param.ospoint.radius) then
2145             begin
2146                  if param.ospoint.ostype=os_nearest then
2147                  begin
2148                       if (osp.radius<DefaultRadius) then copyospoint(param.ospoint,osp);
2149                  end
2150                  else
2151                  //if (osp.radius<param.ospoint.radius) then copyospoint(param.ospoint,osp);
2152                  if param.ospoint.ostype=os_none        then copyospoint(param.ospoint,osp);
2153 
2154             end
2155             end;
2156        end;
2157        pv.endsnap(osp,pdata);
2158   end;
2159   pv2:=PDWG.GetOnMouseObj.iterate(ir2);
2160   until pv2=nil;
2161   end;
2162   pv:=PDWG.GetOnMouseObj.iterate(ir);
2163   until pv=nil;
2164   end;
2165   end;
2166 end;
2167 
2168 procedure TGeneralViewArea.ProcOTrackTimer(Sender:TObject);
2169 begin
2170   //timeKillEvent(uEventID);
2171   otracktimer := 1;
2172   OTTimer.Interval:=0;
2173   OTTimer.Enabled:=false;
2174 end;
2175 procedure TGeneralViewArea.KillOTrackTimer(Sender: TObject);
2176 begin
2177   if param.otracktimerwork = 0 then exit;
2178   dec(param.otracktimerwork);
2179   OTTimer.Interval:=0;
2180   OTTimer.Enabled:=false;
2181   //timeKillEvent(uEventID);
2182 end;
2183 procedure TGeneralViewArea.SetOTrackTimer(Sender: TObject);
2184 var
2185    interval:integer;
2186 begin
2187   if param.otracktimerwork = 1 then exit;
2188   inc(param.otracktimerwork);
2189   if param.otracktimerwork > 0 then
2190                                    begin
2191                                         //if assigned(sysvar.DSGN.DSGN_OTrackTimerInterval) then
2192                                         begin
2193                                              if sysvarDSGNOTrackTimerInterval>0 then
2194                                                                                    interval:=sysvarDSGNOTrackTimerInterval
2195                                                                                 else
2196                                                                                    interval:=0;
2197                                         end;
2198                                         OTTimer.Interval:=interval;
2199                                         OTTimer.OnTimer:=ProcOTrackTimer;
2200                                         OTTimer.Enabled:=true;
2201 
2202                                    end;
2203 end;
2204 procedure TGeneralViewArea.KillOHintTimer(Sender: TObject);
2205 begin
2206   OHTimer.Interval:=0;
2207   OHTimer.Enabled:=false;
2208 end;
2209 
2210 procedure TGeneralViewArea.SetOHintTimer(Sender: TObject);
2211 begin
2212     if assigned(OnGetEntsDesc)then
2213                                   getviewcontrol.Hint:=OnGetEntsDesc(PDWG^.GetOnMouseObj)
2214                               else
2215                                   getviewcontrol.Hint:='';
2216     getviewcontrol.ShowHint:=true;
2217     if getviewcontrol.hint<>'' then
2218     Application.ActivateHint(getviewcontrol.ClientToScreen(Point(param.md.mouse.x,param.md.mouse.y)))
2219     else
2220         application.CancelHint;
2221 
2222                                    begin
2223                                         //uEventID := timeSetEvent(500, 250, @ProcTime, 0, 1)
2224                                         OHTimer.Interval:=500;
2225                                         //wa.OHTimer.OnTimer:=ProcOHintTimer;
2226                                         OHTimer.Enabled:=true;
2227 
2228                                    end;
2229 end;
2230 procedure TGeneralViewArea.CalcMouseFrustum;
2231 var
2232   tm: DMatrix4D;
2233   td:gdbdouble;
2234 begin
2235   td:=sysvarDISPCursorSize*2;
2236   param.mousefrustum   :=CalcDisplaySubFrustum(param.md.glmouse.x,param.md.glmouse.y,td,td,PDWG.Getpcamera.modelMatrix,PDWG.Getpcamera.projMatrix,PDWG.Getpcamera.viewport);
2237   param.mousefrustumLCS:=CalcDisplaySubFrustum(param.md.glmouse.x,param.md.glmouse.y,td,td,PDWG.Getpcamera.modelMatrixLCS,PDWG.Getpcamera.projMatrixLCS,PDWG.Getpcamera.viewport);
2238   exit;
2239   {
2240   tm:=lookat(param.md.mouseray.lbegin,
2241              gdb.GetCurrentDWG.pcamera^.xdir,
2242              gdb.GetCurrentDWG.pcamera^.ydir,
2243              normalizevertex(param.md.mouseray.dir),@onematrix);
2244   if param.projtype = ProjParalel then
2245                                       begin
2246 
2247                                       param.mouseclipmatrix:=ortho(-sysvar.DISP.DISP_CursorSize^*param.zoom*2,sysvar.DISP.DISP_CursorSize^*param.zoom*2,
2248                                                                    -sysvar.DISP.DISP_CursorSize^*param.zoom*2,sysvar.DISP.DISP_CursorSize^*param.zoom*2,
2249                                                                    gdb.GetCurrentDWG.pcamera^.zmin, gdb.GetCurrentDWG.pcamera^.zmax,@onematrix);
2250                                       param.mouseclipmatrix:=MatrixMultiply(tm,param.mouseclipmatrix);
2251                                       param.mousefrustum:=calcfrustum(@param.mouseclipmatrix);
2252                                       end;
2253 
2254 }
2255   //--oglsm.myglMatrixMode(GL_Projection);
2256   //--oglsm.myglpushmatrix;
2257   //--oglsm.myglLoadIdentity;
2258   tm:=myPickMatrix(param.md.glmouse.x, param.md.glmouse.y, sysvarDISPCursorSize * 2, sysvarDISPCursorSize * 2, PDWG.Getpcamera^.viewport);
2259   //--oglsm.mygluPickMatrix(param.md.glmouse.x, param.md.glmouse.y, sysvar.DISP.DISP_CursorSize^ * 2, sysvar.DISP.DISP_CursorSize^ * 2, (@PDWG.Getpcamera^.viewport));
2260   //--oglsm.myglGetDoublev(GL_PROJECTION_MATRIX, @tm);
2261   param.mouseclipmatrix := MatrixMultiply(PDWG.Getpcamera^.projMatrix, tm);
2262   param.mouseclipmatrix := MatrixMultiply(PDWG.Getpcamera^.modelMatrix, param.mouseclipmatrix);
2263   param.mousefrustum := calcfrustum(@param.mouseclipmatrix);
2264   //--oglsm.myglpopmatrix;
2265   //--oglsm.myglMatrixMode(GL_MODELVIEW);
2266 end;
2267 
ProjectPoint2null2268 function ProjectPoint2(pntx,pnty,pntz:gdbdouble; var m:DMatrix4D; var ccsLBN,ccsRTF:GDBVertex):gdbvertex;
2269 begin
2270      result.x:=pntx;
2271      result.y:=pnty;
2272      result.z:=pntz;
2273      result:=uzegeometry.VectorTransform3D(result,m);
2274 
2275      if result.x<ccsLBN.x then
2276                               begin
2277                                    ccsLBN.x:=result.x;
2278                               end;
2279                           //else
2280      if result.y<ccsLBN.y then
2281                               begin
2282                                    ccsLBN.y:=result.y;
2283                               end;
2284                           //else
2285      if result.z<ccsLBN.z then
2286                               begin
2287                                    ccsLBN.z:=result.z;
2288                               end;
2289                           //else
2290      if result.x>ccsRTF.x then
2291                               begin
2292                                    ccsRTF.x:=result.x;
2293                               end;
2294                           //else
2295      if result.y>ccsRTF.y then
2296                               begin
2297                                    ccsRTF.y:=result.y;
2298                               end ;
2299                           //else
2300      if result.z>ccsRTF.z then
2301                               begin
2302                                    ccsRTF.z:=result.z;
2303                               end;
2304 end;
2305 
2306 procedure TGeneralViewArea.CalcOptimalMatrix;
2307 var ccsLBN,ccsRTF:GDBVertex;
2308     tm:DMatrix4D;
2309     LBN:GDBvertex;
2310     RTF:GDBvertex;
2311     tbb,tbb2:TBoundingBox;
2312     //wa.pdwg:PTDrawing;
2313     proot:PGDBObjGenericSubEntry;
2314     pcamera:PGDBObjCamera;
2315     td:GDBDouble;
2316     dc:TDrawContext;
2317 begin
2318   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.CalcOptimalMatrix',lp_IncPos);{$ENDIF}
2319   {Если нет примитивов выходим}
2320   //pdwg:=gdb.GetCurrentDWG;
2321   //self.MakeCurrent;
2322   if pdwg=nil then exit;
2323   proot:=PDWG.GetCurrentROOT;
2324   pcamera:=pdwg.getpcamera;
2325 
2326   if (assigned(pdwg))and(assigned(proot))and(assigned(pcamera))then
2327   begin
2328   dc:=CreateRC;
2329   Pcamera^.modelMatrix:=lookat(Pcamera^.prop.point,
2330                                                Pcamera^.prop.xdir,
2331                                                Pcamera^.prop.ydir,
2332                                                Pcamera^.prop.look,@onematrix);
2333   //glGetDoublev(GL_MODELVIEW_MATRIX, @pdwg.pcamera^.modelMatrix);
2334 
2335   {pdwg.pcamera^.modelMatrix[0][0]:=pdwg.pcamera^.modelMatrix[0][0]/1e5;
2336   pdwg.pcamera^.modelMatrix[1][1]:=pdwg.pcamera^.modelMatrix[1][1]/1e5;
2337   pdwg.pcamera^.modelMatrix[2][2]:=pdwg.pcamera^.modelMatrix[2][2]/1e5;
2338 
2339   pdwg.pcamera^.modelMatrix[3][0]:=pdwg.pcamera^.modelMatrix[3][0]/1e5;
2340   pdwg.pcamera^.modelMatrix[3][1]:=pdwg.pcamera^.modelMatrix[3][1]/1e5;
2341   pdwg.pcamera^.modelMatrix[3][2]:=pdwg.pcamera^.modelMatrix[3][2]/1e5;
2342 
2343   pdwg.pcamera^.modelMatrix[3][3]:=pdwg.pcamera^.modelMatrix[3][3]*1e5;}
2344 
2345   ccsLBN:=InfinityVertex;
2346   ccsRTF:=MinusInfinityVertex;
2347   {ProjectPoint2(proot.vp.BoundingBox.LBN.x,proot.vp.BoundingBox.LBN.y,proot.vp.BoundingBox.LBN.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2348   ProjectPoint2(proot.vp.BoundingBox.RTF.x,proot.vp.BoundingBox.LBN.y,proot.vp.BoundingBox.LBN.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2349   ProjectPoint2(proot.vp.BoundingBox.RTF.x,proot.vp.BoundingBox.RTF.y,proot.vp.BoundingBox.LBN.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2350   ProjectPoint2(proot.vp.BoundingBox.LBN.x,proot.vp.BoundingBox.RTF.y,proot.vp.BoundingBox.LBN.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2351   ProjectPoint2(proot.vp.BoundingBox.LBN.x,proot.vp.BoundingBox.LBN.y,proot.vp.BoundingBox.RTF.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2352   ProjectPoint2(proot.vp.BoundingBox.RTF.x,proot.vp.BoundingBox.LBN.y,proot.vp.BoundingBox.RTF.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2353   ProjectPoint2(proot.vp.BoundingBox.RTF.x,proot.vp.BoundingBox.RTF.y,proot.vp.BoundingBox.RTF.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2354   ProjectPoint2(proot.vp.BoundingBox.LBN.x,proot.vp.BoundingBox.RTF.y,proot.vp.BoundingBox.RTF.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2355   }
2356   {ProjectPoint2(proot.VisibleOBJBoundingBox.LBN.x,proot.VisibleOBJBoundingBox.LBN.y,proot.VisibleOBJBoundingBox.LBN.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2357   ProjectPoint2(proot.VisibleOBJBoundingBox.RTF.x,proot.VisibleOBJBoundingBox.LBN.y,proot.VisibleOBJBoundingBox.LBN.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2358   ProjectPoint2(proot.VisibleOBJBoundingBox.RTF.x,proot.VisibleOBJBoundingBox.RTF.y,proot.VisibleOBJBoundingBox.LBN.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2359   ProjectPoint2(proot.VisibleOBJBoundingBox.LBN.x,proot.VisibleOBJBoundingBox.RTF.y,proot.VisibleOBJBoundingBox.LBN.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2360   ProjectPoint2(proot.VisibleOBJBoundingBox.LBN.x,proot.VisibleOBJBoundingBox.LBN.y,proot.VisibleOBJBoundingBox.RTF.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2361   ProjectPoint2(proot.VisibleOBJBoundingBox.RTF.x,proot.VisibleOBJBoundingBox.LBN.y,proot.VisibleOBJBoundingBox.RTF.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2362   ProjectPoint2(proot.VisibleOBJBoundingBox.RTF.x,proot.VisibleOBJBoundingBox.RTF.y,proot.VisibleOBJBoundingBox.RTF.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);
2363   ProjectPoint2(proot.VisibleOBJBoundingBox.LBN.x,proot.VisibleOBJBoundingBox.RTF.y,proot.VisibleOBJBoundingBox.RTF.Z,pdwg.pcamera^.modelMatrix,ccsLBN,ccsRTF);}
2364 
2365   tbb:=proot.vp.BoundingBox;
2366 
2367   if IsBBNul(tbb) then
2368   begin
2369        {tbb.LBN:=uzegeometry.VertexAdd(pdwg.tpcamera^.prop.point,MinusOneVertex);
2370        tbb.RTF:=uzegeometry.VertexAdd(pdwg.tpcamera^.prop.point,OneVertex);}
2371        concatBBandPoint(tbb,param.CSIcon.CSIconCoord);
2372        concatBBandPoint(tbb,param.CSIcon.CSIconX);
2373        concatBBandPoint(tbb,param.CSIcon.CSIconY);
2374        concatBBandPoint(tbb,param.CSIcon.CSIconZ);
2375   end;
2376 
2377   if pdwg.GetConstructObjRoot.ObjArray.Count>0 then
2378                        begin
2379   pdwg.GetConstructObjRoot.calcbb(dc);
2380   tbb2:=pdwg.GetConstructObjRoot.vp.BoundingBox;
2381   ConcatBB(tbb,tbb2);
2382   end;
2383   {if param.CSIcon.AxisLen>eps then
2384   begin
2385   concatBBandPoint(tbb,param.CSIcon.CSIconCoord);
2386   concatBBandPoint(tbb,param.CSIcon.CSIconX);
2387   concatBBandPoint(tbb,param.CSIcon.CSIconY);
2388   concatBBandPoint(tbb,param.CSIcon.CSIconZ);
2389   end;}
2390 
2391 
2392   if IsBBNul(tbb) then
2393   begin
2394        tbb.LBN:=uzegeometry.VertexAdd(pcamera^.prop.point,MinusOneVertex);
2395        tbb.RTF:=uzegeometry.VertexAdd(pcamera^.prop.point,OneVertex);
2396   end;
2397 
2398   //if param.CSIcon.AxisLen>eps then
2399   begin
2400   //concatBBandPoint(tbb,param.CSIcon.CSIconCoord);
2401   //concatBBandPoint(tbb,param.CSIcon.CSIconX);
2402   //concatBBandPoint(tbb,param.CSIcon.CSIconY);
2403   //concatBBandPoint(tbb,param.CSIcon.CSIconZ);
2404   end;
2405 
2406   LBN:=tbb.LBN;
2407   RTF:=tbb.RTF;
2408 
2409   ProjectPoint2(LBN.x,LBN.y,LBN.Z,pcamera^.modelMatrix,ccsLBN,ccsRTF);
2410   ProjectPoint2(RTF.x,LBN.y,LBN.Z,pcamera^.modelMatrix,ccsLBN,ccsRTF);
2411   ProjectPoint2(RTF.x,RTF.y,LBN.Z,pcamera^.modelMatrix,ccsLBN,ccsRTF);
2412   ProjectPoint2(LBN.x,RTF.y,LBN.Z,pcamera^.modelMatrix,ccsLBN,ccsRTF);
2413   ProjectPoint2(LBN.x,LBN.y,RTF.Z,pcamera^.modelMatrix,ccsLBN,ccsRTF);
2414   ProjectPoint2(RTF.x,LBN.y,RTF.Z,pcamera^.modelMatrix,ccsLBN,ccsRTF);
2415   ProjectPoint2(RTF.x,RTF.y,RTF.Z,pcamera^.modelMatrix,ccsLBN,ccsRTF);
2416   ProjectPoint2(LBN.x,RTF.y,RTF.Z,pcamera^.modelMatrix,ccsLBN,ccsRTF);
2417 
2418   ccsLBN.z:=-ccsLBN.z;
2419   ccsRTF.z:=-ccsRTF.z;
2420   td:=(ccsRTF.z-ccsLBN.z)/20;
2421   td:=min(td,-ccsLBN.z/100);
2422   ccsLBN.z:=ccsLBN.z-td;
2423   ccsRTF.z:=ccsRTF.z+td;
2424   if (ccsLBN.z-ccsRTF.z)<sqreps then
2425                                  begin
2426                                       ccsLBN.z:=ccsLBN.z+1;
2427                                       ccsRTF.z:=ccsRTF.z-1;
2428                                  end;
2429   pcamera^.obj_zmAx:=ccsLBN.z;
2430   pcamera^.obj_zmin:=ccsRTF.z;
2431   pcamera^.zmax:=pcamera^.obj_zmAx;
2432   pcamera^.zmin:=pcamera^.obj_zmin;
2433 
2434 
2435   {if pdwg.pcamera^.zmax>10000 then
2436                                                 pdwg.pcamera^.zmax:=100000;
2437   if pdwg.pcamera^.zmin<10000 then
2438                                                   pdwg.pcamera^.zmin:=-10000;}
2439 
2440 
2441   if param.projtype = PROJPerspective then
2442   begin
2443        if pcamera^.zmin<pcamera^.zmax/10000 then
2444                                                   pcamera^.zmin:=pcamera^.zmax/10000;
2445        if pcamera^.zmin<10 then
2446                                                   pcamera^.zmin:=10;
2447        if pcamera^.zmax<pcamera^.zmin then
2448                                                   pcamera^.zmax:=1000;
2449   end;
2450 
2451 
2452 
2453   if param.projtype = ProjParalel then
2454                                       begin
2455                                       pcamera^.projMatrix:=ortho(-getviewcontrol.clientwidth*pcamera^.prop.zoom/2,getviewcontrol.clientwidth*pcamera^.prop.zoom/2,
2456                                                                                  -getviewcontrol.clientheight*pcamera^.prop.zoom/2,getviewcontrol.clientheight*pcamera^.prop.zoom/2,
2457                                                                                  pcamera^.zmin, pcamera^.zmax,@onematrix);
2458                                       end
2459                                   else
2460                                       BEGIN
2461                                            pcamera^.projMatrix:=Perspective(pcamera^.fovy, getviewcontrol.Width / getviewcontrol.Height, pcamera^.zmin, pcamera^.zmax,@onematrix);
2462   //glGetDoublev(GL_PROJECTION_MATRIX, @pdwg.pcamera^.projMatrix);
2463                                       end;
2464 
2465 
2466   ///pdwg.pcamera.getfrustum(@pdwg.pcamera^.modelMatrix,   @pdwg.pcamera^.projMatrix,   pdwg.pcamera^.clip,   pdwg.pcamera^.frustum);
2467 
2468 
2469 
2470   pcamera^.CamCSOffset:=NulVertex;
2471   pcamera^.CamCSOffset.z:=(pcamera^.zmax+pcamera^.zmin)/2;
2472   pcamera^.CamCSOffset.z:=(pcamera^.zmin);
2473 
2474 
2475   tm:=pcamera^.modelMatrix;
2476   //MatrixInvert(tm);
2477   pcamera^.CamCSOffset:=uzegeometry.VectorTransform3D(pcamera^.CamCSOffset,tm);
2478   pcamera^.CamCSOffset:=pcamera^.prop.point;
2479 
2480   {получение центра виевфрустума}
2481   tm:=uzegeometry.CreateTranslationMatrix({minusvertex(pdwg.pcamera^.CamCSOffset)}nulvertex);
2482 
2483   //pdwg.pcamera^.modelMatrixLCS:=tm;
2484   pcamera^.modelMatrixLCS:=lookat({vertexsub(pdwg.pcamera^.prop.point,pdwg.pcamera^.CamCSOffset)}nulvertex,
2485                                                pcamera^.prop.xdir,
2486                                                pcamera^.prop.ydir,
2487                                                pcamera^.prop.look,{@tm}@onematrix);
2488   pcamera^.modelMatrixLCS:=uzegeometry.MatrixMultiply(tm,pcamera^.modelMatrixLCS);
2489   ccsLBN:=InfinityVertex;
2490   ccsRTF:=MinusInfinityVertex;
2491   tbb:=proot.VisibleOBJBoundingBox;
2492   //pdwg.ConstructObjRoot.calcbb;
2493   tbb2:=pdwg.getConstructObjRoot.vp.BoundingBox;
2494   ConcatBB(tbb,tbb2);
2495 
2496   //proot.VisibleOBJBoundingBox:=tbb;
2497 
2498   if not IsBBNul(tbb) then
2499   begin
2500         LBN:=tbb.LBN;
2501         LBN:=vertexadd(LBN,pcamera^.CamCSOffset);
2502         RTF:=tbb.RTF;
2503         RTF:=vertexadd(RTF,pcamera^.CamCSOffset);
2504   end
2505   else
2506   begin
2507        LBN:=uzegeometry.VertexMulOnSc(OneVertex,50);
2508        //LBN:=vertexadd(LBN,pdwg.pcamera^.CamCSOffset);
2509        RTF:=uzegeometry.VertexMulOnSc(OneVertex,100);
2510        //RTF:=vertexadd(RTF,pdwg.pcamera^.CamCSOffset);
2511   end;
2512   ProjectPoint2(LBN.x,LBN.y,LBN.Z,pcamera^.modelMatrixLCS,ccsLBN,ccsRTF);
2513   ProjectPoint2(RTF.x,LBN.y,LBN.Z,pcamera^.modelMatrixLCS,ccsLBN,ccsRTF);
2514   ProjectPoint2(RTF.x,RTF.y,LBN.Z,pcamera^.modelMatrixLCS,ccsLBN,ccsRTF);
2515   ProjectPoint2(LBN.x,RTF.y,LBN.Z,pcamera^.modelMatrixLCS,ccsLBN,ccsRTF);
2516   ProjectPoint2(LBN.x,LBN.y,RTF.Z,pcamera^.modelMatrixLCS,ccsLBN,ccsRTF);
2517   ProjectPoint2(RTF.x,LBN.y,RTF.Z,pcamera^.modelMatrixLCS,ccsLBN,ccsRTF);
2518   ProjectPoint2(RTF.x,RTF.y,RTF.Z,pcamera^.modelMatrixLCS,ccsLBN,ccsRTF);
2519   ProjectPoint2(LBN.x,RTF.y,RTF.Z,pcamera^.modelMatrixLCS,ccsLBN,ccsRTF);
2520   ccsLBN.z:=-ccsLBN.z;
2521   ccsRTF.z:=-ccsRTF.z;
2522   td:=(ccsRTF.z-ccsLBN.z)/20;
2523   ccsLBN.z:=ccsLBN.z-td;
2524   ccsRTF.z:=ccsRTF.z+td;
2525   if (ccsLBN.z-ccsRTF.z)<sqreps then
2526                                  begin
2527                                       if abs(ccsLBN.z)>eps then
2528                                       begin
2529                                       ccsLBN.z:=ccsLBN.z/10;
2530                                       ccsRTF.z:=ccsRTF.z*10;
2531                                       end
2532                                       else
2533                                       begin
2534                                       ccsLBN.z:=+1;
2535                                       ccsRTF.z:=-1;
2536                                       end
2537                                  end;
2538   pcamera^.obj_zmAx:=ccsLBN.z;
2539   pcamera^.obj_zmin:=ccsRTF.z;
2540   pcamera^.zmaxLCS:=pcamera^.obj_zmAx;
2541   pcamera^.zminLCS:=pcamera^.obj_zmin;
2542 
2543 
2544   if param.projtype = PROJPerspective then
2545   begin
2546        if pcamera^.zminLCS<pcamera^.zmaxLCS/10000 then
2547                                                   pcamera^.zminLCS:=pcamera^.zmaxLCS/10000;
2548        if pcamera^.zminLCS<10 then
2549                                                   pcamera^.zminLCS:=10;
2550        if pcamera^.zmaxLCS<pcamera^.zminLCS then
2551                                                   pcamera^.zmaxLCS:=1000;
2552   end;
2553 
2554   pcamera^.zminLCS:=pcamera^.zminLCS;//-pdwg.pcamera^.CamCSOffset.z;
2555   pcamera^.zmaxLCS:=pcamera^.zmaxLCS;//+pdwg.pcamera^.CamCSOffset.z;
2556 
2557   //glLoadIdentity;
2558   //pdwg.pcamera^.projMatrix:=onematrix;
2559   if param.projtype = ProjParalel then
2560                                       begin
2561                                       pcamera^.projMatrixLCS:=ortho(-getviewcontrol.clientwidth*pcamera^.prop.zoom/2,getviewcontrol.clientwidth*pcamera^.prop.zoom/2,
2562                                                                                  -getviewcontrol.clientheight*pcamera^.prop.zoom/2,getviewcontrol.clientheight*pcamera^.prop.zoom/2,
2563                                                                                  pcamera^.zminLCS, pcamera^.zmaxLCS,@onematrix);
2564                                       end
2565                                   else
2566                                       BEGIN
2567                                            pcamera^.projMatrixLCS:=Perspective(pcamera^.fovy, getviewcontrol.Width / getviewcontrol.Height, pcamera^.zminLCS, pcamera^.zmaxLCS,@onematrix);
2568   //glGetDoublev(GL_PROJECTION_MATRIX, @pdwg.pcamera^.projMatrix);
2569                                       end;
2570   if param.projtype = ProjParalel then
2571                                       begin
2572                                            if uzegeometry.oneVertexlength(pcamera^.CamCSOffset)>1000000 then
2573                                            begin
2574                                                 CurrentCamCSOffset:=pcamera^.CamCSOffset;
2575                                                 CurrentCamCSOffsetS:=VertexD2S(CurrentCamCSOffset);
2576                                                 notuseLCS:=pcamera^.notuseLCS;
2577                                            end
2578                                            else notuseLCS:=true;
2579                                       end
2580                                   else
2581                                       begin
2582                                            notuseLCS:=true;
2583                                       end;
2584   if notuseLCS then
2585   begin
2586         pcamera^.projMatrixLCS:=pcamera^.projMatrix;
2587         pcamera^.modelMatrixLCS:=pcamera^.modelMatrix;
2588         pcamera^.frustumLCS:=pcamera^.frustum;
2589         pcamera^.CamCSOffset:=NulVertex;
2590         CurrentCamCSOffset:=nulvertex;
2591   end;
2592 
2593 
2594   if {pdwg.pcamera^.notuseLCS}notuseLCS then
2595   begin
2596         pcamera^.projMatrixLCS:=pcamera^.projMatrix;
2597         pcamera^.modelMatrixLCS:=pcamera^.modelMatrix;
2598         pcamera^.frustumLCS:=pcamera^.frustum;
2599         pcamera^.CamCSOffset:=NulVertex;
2600         CurrentCamCSOffset:=nulvertex;
2601   end;
2602   SetOGLMatrix;
2603   end;
2604     //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.CalcOptimalMatrix----{end}',lp_DecPos);{$ENDIF}
2605   //gdb.GetCurrentDWG.pcamera.getfrustum(@gdb.GetCurrentDWG.pcamera^.modelMatrixLCS,@gdb.GetCurrentDWG.pcamera^.projMatrixLCS,gdb.GetCurrentDWG.pcamera^.clipLCS,gdb.GetCurrentDWG.pcamera^.frustumLCS);
2606 end;
2607 procedure TGeneralViewArea.SetOGLMatrix;
2608 var
2609     pcam:PGDBObjCamera;
2610 begin
2611   //{$IFDEF PERFOMANCELOG}log.programlog.LogOutStrFast('TOGLWnd.SetOGLMatrix',0);{$ENDIF}
2612   pcam:=pdwg.GetPcamera;
2613   pcam^.viewport[0]:=0;
2614   pcam^.viewport[1]:=0;
2615   pcam^.viewport[2]:=getviewcontrol.clientWidth;
2616   pcam^.viewport[3]:=getviewcontrol.clientHeight;
2617   drawer.SetOGLMatrix(pcam^,getviewcontrol.clientWidth, getviewcontrol.clientHeight);
2618 
2619   {oglsm.myglMatrixMode(GL_MODELVIEW);
2620   oglsm.myglLoadMatrixD(@pcam^.modelMatrixLCS);
2621 
2622   oglsm.myglMatrixMode(GL_PROJECTION);
2623   oglsm.myglLoadMatrixD(@pcam^.projMatrixLCS);
2624 
2625   oglsm.myglMatrixMode(GL_MODELVIEW);}
2626 
2627 
2628   pcam^.getfrustum(@pcam^.modelMatrix,   @pcam^.projMatrix,   pcam^.clip,   pdwg.GetPcamera^.frustum);
2629   pcam^.getfrustum(@pcam^.modelMatrixLCS,@pcam^.projMatrixLCS,pcam^.clipLCS,pdwg.GetPcamera^.frustumLCS);
2630 
2631 end;
2632 procedure TGeneralViewArea.PanScreen(oldX,oldY,X,Y:Integer);
2633 var
2634   glmcoord1: gdbpiece;
2635   tv2:gdbvertex4d;
2636   ax:gdbvertex;
2637   //ux,uy:GDBDouble;
2638   //htext,htext2:gdbstring;
2639   //key: GDBByte;
2640   lptime:ttime;
2641 begin
2642   mouseunproject(oldX, getviewcontrol.clientheight-oldY);
2643   glmcoord1:= param.md.mouseraywithoutos;
2644   mouseunproject(X, getviewcontrol.clientheight-Y);
2645   tv2.x:=(x - {param.md.mouse.x}oldX);
2646   tv2.y:=(y - {param.md.mouse.y}oldY);
2647   if (abs(tv2.x)>eps)or(abs(tv2.y)>eps) then
2648   begin
2649        ax.x:=-(param.md.mouseray.lend.x - glmcoord1.lend.x);
2650        ax.y:=(param.md.mouseray.lend.y - glmcoord1.lend.y);
2651        ax.z:=0;
2652        pdwg.MoveCameraInLocalCSXY(tv2.x,tv2.y,ax);
2653        {with gdb.GetCurrentDWG.UndoStack.PushCreateTGChangeCommand(gdb.GetCurrentDWG.pcamera^.prop)^ do
2654        begin
2655        gdb.GetCurrentDWG.pcamera.moveInLocalCSXY(tv2.x,tv2.y,ax);
2656        ComitFromObj;
2657        end;}
2658        param.firstdraw := true;
2659        pdwg.Getpcamera^.NextPosition;
2660        CalcOptimalMatrix;
2661        calcgrid;
2662        //gdb.GetCurrentDWG.Changed:=true;
2663        //-------------CalcOptimalMatrix;
2664        lptime:=now();
2665        pdwg.GetCurrentROOT.CalcVisibleByTree(pdwg.Getpcamera^.frustum,pdwg.Getpcamera.POSCOUNT,pdwg.Getpcamera.VISCOUNT,pdwg.GetCurrentROOT.ObjArray.ObjTree,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
2666        lptime:=now()-LPTime;
2667        sysvarRDLastCalcVisible:=round(lptime*10e7);
2668        //gdb.GetCurrentROOT.calcvisible(gdb.GetCurrentDWG.pcamera^.frustum,gdb.GetCurrentDWG.pcamera.POSCOUNT);
2669        pdwg.GetConstructObjRoot.calcvisible(pdwg.Getpcamera^.frustum,pdwg.Getpcamera.POSCOUNT,pdwg.Getpcamera.VISCOUNT,pdwg.getpcamera.totalobj,pdwg.getpcamera.infrustum,pdwg.myGluProject2,pdwg.getpcamera.prop.zoom,SysVarRDImageDegradationCurrentDegradationFactor);
2670   end;
2671 
2672 end;
2673 
2674 procedure TGeneralViewArea.projectaxis;
2675 var
2676   i: GDBInteger;
2677   temp: gdbvertex;
2678   pv:pgdbvertex;
2679   tp:traceprop;
2680 
2681   Objects:GDBObjOpenArrayOfPV;
2682   pobj:pGDBObjEntity;
2683   ir:itrec;
2684 begin
2685   PDWG.myGluProject2(param.ospoint.worldcoord,
2686              param.ospoint.dispcoord);
2687   if not sysvarDWGPolarMode then exit;
2688   //param.ospoint.arrayworldaxis.init({$IFDEF DEBUGBUILD}'{8BE71BAA-507B-4D6B-BE2C-63693022090C}',{$ENDIF}4);
2689   param.ospoint.arrayworldaxis.clear;
2690   pv:=polaraxis.GetParrayAsPointer;
2691   for i:=0 to polaraxis.Count-1 do
2692   begin
2693        param.ospoint.arrayworldaxis.PushBackData(pv^);
2694        inc(pv);
2695   end;
2696   //if param.ospoint.PGDBObject<>nil then
2697   begin
2698   objects.init({$IFDEF DEBUGBUILD}'{8BE71BAA-507B-4D6B-BE2C-63693022090C}',{$ENDIF}100);
2699   if PDWG.GetCurrentROOT.FindObjectsInPoint(param.ospoint.worldcoord,Objects) then
2700   begin
2701                        pobj:=objects.beginiterate(ir);
2702                        if pobj<>nil then
2703                        repeat
2704                              pgdbobjentity(pobj)^.AddOnTrackAxis(param.ospoint,addaxistootrack);
2705                              pobj:=objects.iterate(ir);
2706                        until pobj=nil;
2707   end;
2708   {if param.ospoint.PGDBObject<>nil then
2709   begin
2710        pgdbobjentity(param.ospoint.PGDBObject)^.AddOnTrackAxis(@param.ospoint);   fghfgh
2711   end;}
2712   objects.Clear;
2713   objects.Done;
2714   if param.processObjConstruct then
2715   begin
2716   objects.init({$IFDEF DEBUGBUILD}'{8BE71BAA-507B-4D6B-BE2C-63693022090C}',{$ENDIF}100);
2717   if PDWG.GetConstructObjRoot.FindObjectsInPointSlow(param.ospoint.worldcoord,Objects) then
2718   begin
2719                        pobj:=objects.beginiterate(ir);
2720                        if pobj<>nil then
2721                        repeat
2722                              pgdbobjentity(pobj)^.AddOnTrackAxis(param.ospoint,addaxistootrack);
2723                              pobj:=objects.iterate(ir);
2724                        until pobj=nil;
2725   end;
2726   objects.Clear;
2727   objects.Done;
2728   end;
2729   end;
2730   project0axis;
2731   {GDBGetMem(param.ospoint.arrayworldaxis, sizeof(GDBWord) + param.ppolaraxis^.count * sizeof(gdbvertex));
2732   Move(param.ppolaraxis^, param.ospoint.arrayworldaxis^, sizeof(GDBWord) + param.ppolaraxis^.count * sizeof(gdbvertex));}
2733   PDWG.myGluProject2(param.ospoint.worldcoord,
2734              param.ospoint.dispcoord);
2735   //param.ospoint.arraydispaxis.init({$IFDEF DEBUGBUILD}'{722A886F-5616-4E8F-B94D-3A1C3D7ADBD4}',{$ENDIF}param.ospoint.arrayworldaxis.count);
2736   param.ospoint.arraydispaxis.clear;
2737   //GDBGetMem(param.ospoint.arraydispaxis, sizeof(GDBWord) + param.ospoint.arrayworldaxis.count * sizeof(traceprop));
2738   //param.ospoint.arraydispaxis.count := param.ospoint.arrayworldaxis.count;
2739   pv:=param.ospoint.arrayworldaxis.GetParrayAsPointer;
2740   for i := 0 to param.ospoint.arrayworldaxis.count - 1 do
2741   begin
2742     PDWG.myGluProject2(createvertex(param.ospoint.worldcoord.x + pv.x, param.ospoint.worldcoord.y + pv.y, param.ospoint.worldcoord.z + pv.z),
2743                                      temp);
2744     tp.dir.x:=temp.x - param.ospoint.dispcoord.x;
2745     tp.dir.y:=(temp.y - param.ospoint.dispcoord.y);
2746     tp.dir.z:=temp.z - param.ospoint.dispcoord.z;
2747     param.ospoint.arraydispaxis.PushBackData(tp);
2748     {param.ospoint.arraydispaxis.arr[i].dir.x := temp.x - param.ospoint.dispcoord.x;
2749     param.ospoint.arraydispaxis.arr[i].dir.y := -(temp.y - param.ospoint.dispcoord.y);
2750     param.ospoint.arraydispaxis.arr[i].dir.z := temp.z - param.ospoint.dispcoord.z;}
2751     inc(pv);
2752   end
2753 end;
2754 
2755 procedure TGeneralViewArea.addaxistootrack(var posr:os_record;const axis:GDBVertex);
2756 begin
2757      posr.arrayworldaxis.PushBackData(axis);
2758 
2759      if @posr<>@param.ontrackarray.otrackarray[0] then
2760      if (sysvarDWGOSMode and osm_paralel)<>0 then
2761      begin
2762           param.ontrackarray.otrackarray[0].arrayworldaxis.PushBackData(axis);
2763      end;
2764 end;
2765 
2766 procedure TGeneralViewArea.create0axis;
2767 var
2768   i: GDBInteger;
2769   pv:pgdbvertex;
2770   Objects:GDBObjOpenArrayOfPV;
2771   pobj:pGDBObjEntity;
2772   ir:itrec;
2773 begin
2774   PDWG.myGluProject2(param.ospoint.worldcoord,
2775              param.ospoint.dispcoord);
2776   //if not assigned(sysvar.dwg.DWG_PolarMode) then exit;
2777   if not sysvarDWGPolarMode then exit;
2778   //param.ontrackarray.otrackarray[0].arrayworldaxis.init({$IFDEF DEBUGBUILD}'{8BE71BAA-507B-4D6B-BE2C-63693022090C}',{$ENDIF}4);
2779   param.ontrackarray.otrackarray[0].arrayworldaxis.clear;
2780   pv:=polaraxis.GetParrayAsPointer;
2781   for i:=0 to polaraxis.Count-1 do
2782   begin
2783        param.ontrackarray.otrackarray[0].arrayworldaxis.PushBackData(pv^);
2784        inc(pv);
2785   end;
2786 
2787   if tocommandmcliccount>0 then
2788   begin
2789   objects.init({$IFDEF DEBUGBUILD}'{8BE71BAA-507B-4D6B-BE2C-63693022090C}',{$ENDIF}100);
2790   if PDWG.GetCurrentROOT.FindObjectsInPoint(param.ontrackarray.otrackarray[0].worldcoord,Objects) then
2791   begin
2792                        pobj:=objects.beginiterate(ir);
2793                        if pobj<>nil then
2794                        repeat
2795                              pgdbobjentity(pobj)^.AddOnTrackAxis(param.ontrackarray.otrackarray[0],addaxistootrack);
2796                              pobj:=objects.iterate(ir);
2797                        until pobj=nil;
2798   end;
2799   objects.Clear;
2800   objects.Done;
2801                        if param.processObjConstruct then
2802                        begin
2803   objects.init({$IFDEF DEBUGBUILD}'{8BE71BAA-507B-4D6B-BE2C-63693022090C}',{$ENDIF}100);
2804   if PDWG.GetConstructObjRoot.FindObjectsInPointSlow(param.ontrackarray.otrackarray[0].worldcoord,Objects) then
2805   begin
2806                        pobj:=objects.beginiterate(ir);
2807                        if pobj<>nil then
2808                        repeat
2809                              pgdbobjentity(pobj)^.AddOnTrackAxis(param.ontrackarray.otrackarray[0],addaxistootrack);
2810                              pobj:=objects.iterate(ir);
2811                        until pobj=nil;
2812   end;
2813   objects.Clear;
2814   objects.Done;
2815   end;
2816   end;
2817 
2818 
2819   Project0Axis;
2820 end;
2821 
2822 procedure TGeneralViewArea.Project0Axis;
2823 var
2824   tp: traceprop;
2825   temp: gdbvertex;
2826   pv: pgdbvertex;
2827   i: GDBInteger;
2828 begin
2829   {GDBGetMem(param.ospoint.arrayworldaxis, sizeof(GDBWord) + param.ppolaraxis
2830     ^.count * sizeof(gdbvertex));
2831   Move(param.ppolaraxis^, param.ospoint.arrayworldaxis^, sizeof(GDBWord) +
2832     param.ppolaraxis^.count * sizeof(gdbvertex)); }
2833   {gdb.GetCurrentDWG^}pdwg.myGluProject2(param.ontrackarray.otrackarray[0
2834     ].worldcoord,
2835              param.ontrackarray.otrackarray[0].dispcoord);
2836   //param.ontrackarray.otrackarray[0].arraydispaxis.init({$IFDEF DEBUGBUILD}'{722A886F-5616-4E8F-B94D-3A1C3D7ADBD4}', {$ENDIF}    param.ontrackarray.otrackarray[0].arrayworldaxis.count);
2837   param.ontrackarray.otrackarray[0].arraydispaxis.clear;
2838   //GDBGetMem(param.ospoint.arraydispaxis, sizeof(GDBWord) +param.ospoint.arrayworldaxis.count * sizeof(traceprop));
2839   //param.ospoint.arraydispaxis.count := param.ospoint.arrayworldaxis.count;
2840   pv:=param.ontrackarray.otrackarray[0].arrayworldaxis.GetParrayAsPointer;
2841   for i := 0 to param.ontrackarray.otrackarray[0].arrayworldaxis.count - 1 do
2842   begin
2843     {gdb.GetCurrentDWG^}pdwg.myGluProject2(createvertex(param.ontrackarray.otrackarray
2844       [0].worldcoord.x + pv.x, param.ontrackarray.otrackarray[0].worldcoord.y +
2845       pv.y, param.ontrackarray.otrackarray[0].worldcoord.z + pv.z)
2846                                     , temp);
2847     tp.dir.x:=temp.x - param.ontrackarray.otrackarray[0].dispcoord.x;
2848     tp.dir.y:=(temp.y - param.ontrackarray.otrackarray[0].dispcoord.y);
2849     tp.dir.z:=temp.z - param.ontrackarray.otrackarray[0].dispcoord.z;
2850     param.ontrackarray.otrackarray[0].arraydispaxis.PushBackData(tp);
2851     {param.ospoint.arraydispaxis.arr[i].dir.x := temp.x -
2852       param.ospoint.dispcoord.x;
2853     param.ospoint.arraydispaxis.arr[i].dir.y := -(temp.y -
2854       param.ospoint.dispcoord.y);
2855     param.ospoint.arraydispaxis.arr[i].dir.z := temp.z -
2856       param.ospoint.dispcoord.z; }
2857     inc(pv);
2858   end
2859 end;
2860 
2861 procedure TGeneralViewArea.reprojectaxis;
2862 var
2863   i, j, a: GDBInteger;
2864   temp: gdbvertex;
2865   pv:pgdbvertex;
2866   pt,pt2:ptraceprop;
2867   ir,ir2:itrec;
2868   ip:intercept3dprop;
2869   lastontracdist,currentontracdist,tx,ty,tz:gdbdouble;
2870   test:gdbboolean;
2871   pobj:pgdbobjentity;
2872 //  dispraylen:double;
2873 begin
2874   if param.ontrackarray.total = 0 then exit;
2875   param.polarlinetrace := 0;
2876 
2877     if tocommandmcliccount=0 then
2878                                  a:=1
2879                              else
2880                                  a:=0;
2881     for j := a to param.ontrackarray.total - 1 do
2882     begin
2883       PDWG.myGluProject2(param.ontrackarray.otrackarray[j].worldcoord,
2884                  param.ontrackarray.otrackarray[j].dispcoord);
2885     end;
2886     //if not assigned(sysvar.dwg.DWG_PolarMode) then exit;
2887     if not sysvarDWGPolarMode then exit;
2888   for j := a to param.ontrackarray.total - 1 do
2889   begin
2890     {gdb.GetCurrentDWG^.myGluProject2(param.ontrackarray.otrackarray[j].worldcoord,
2891                param.ontrackarray.otrackarray[j].dispcoord);}
2892     param.ontrackarray.otrackarray[j].dispcoord.z:=0;
2893     param.ontrackarray.otrackarray[j].dmousecoord.x :=
2894     param.md.glmouse.x - param.ontrackarray.otrackarray[j].dispcoord.x;
2895     param.ontrackarray.otrackarray[j].dmousecoord.y :=
2896     //-(clientheight - param.md.glmouse.y - param.ontrackarray.otrackarray[j].dispcoord.y);
2897     param.md.glmouse.y -  param.ontrackarray.otrackarray[j].dispcoord.y;
2898     param.ontrackarray.otrackarray[j].dmousecoord.z := 0;
2899      //caption:=floattostr(ontrackarray.otrackarray[j].dmousecoord.x)+';'+floattostr(ontrackarray.otrackarray[j].dmousecoord.y);
2900      //caption:='' ;
2901     param.ontrackarray.otrackarray[j].dmousecoord.z := 0;
2902     lastontracdist:=infinity;
2903     pt2:=nil;
2904     if param.ontrackarray.otrackarray[j].arrayworldaxis.Count <> 0 then
2905     begin
2906       pv:=param.ontrackarray.otrackarray[j].arrayworldaxis.GetParrayAsPointer;
2907       pt:=param.ontrackarray.otrackarray[j].arraydispaxis.GetParrayAsPointer;
2908       for i := 0 to param.ontrackarray.otrackarray[j].arrayworldaxis.count - 1 do
2909       begin
2910         PDWG.myGluProject2(createvertex(param.ontrackarray.otrackarray[j].worldcoord.x + pv.x,
2911                    param.ontrackarray.otrackarray[j].worldcoord.y + pv.y,
2912                    param.ontrackarray.otrackarray[j].worldcoord.z + pv.z),
2913                    temp);
2914         pt.dir.x := temp.x - param.ontrackarray.otrackarray[j].dispcoord.x;
2915         pt.dir.y := (temp.y - param.ontrackarray.otrackarray[j].dispcoord.y);
2916         pt.dir.z := temp.z - param.ontrackarray.otrackarray[j].dispcoord.z;
2917 
2918         pt.trace:=false;
2919 
2920         if (pt.dir.x*pt.dir.x+pt.dir.y*pt.dir.y)>sqreps then
2921 
2922         begin
2923         pt.tmouse :=
2924           (pt.dir.x *
2925           param.ontrackarray.otrackarray[j].dmousecoord.x +
2926           pt.dir.y *
2927           param.ontrackarray.otrackarray[j].dmousecoord.y)
2928           / (sqr(pt.dir.x) + sqr(pt.dir.y));
2929         //dispraylen:=
2930 
2931         tx:=pt.tmouse * pv.x;
2932         ty:=pt.tmouse * pv.y;
2933         tz:=pt.tmouse * pv.z;
2934 
2935         pt.dispraycoord.x := param.ontrackarray.otrackarray[j].dispcoord.x + pt.tmouse * pt.dir.x;
2936         pt.dispraycoord.y := param.ontrackarray.otrackarray[j].dispcoord.y + pt.tmouse * pt.dir.y;
2937         pt.dispraycoord.z:=0;
2938         pt.worldraycoord.x := param.ontrackarray.otrackarray[j].worldcoord.x + {pt.tmouse * pv.x}tx;
2939         pt.worldraycoord.y := param.ontrackarray.otrackarray[j].worldcoord.y + {pt.tmouse * pv.y}ty;
2940         pt.worldraycoord.z := param.ontrackarray.otrackarray[j].worldcoord.z + {pt.tmouse * pv.z}tz;
2941           //temp.x:=ontrackarray.otrackarray[j].dmousecoord.x-ontrackarray.otrackarray[j].arraydispaxis.arr[i].dispraycoord.x;
2942           //temp.y:=ontrackarray.otrackarray[j].dmousecoord.y-ontrackarray.otrackarray[j].arraydispaxis.arr[i].dispraycoord.y;
2943         temp.x := param.md.glmouse.x - pt.dispraycoord.x;
2944         temp.y := param.md.glmouse.y - pt.dispraycoord.y {clientheight - param.md.glmouse.y - pt.dispraycoord.y};
2945 
2946 
2947 
2948 
2949         pt.dmouse := round(sqrt(temp.x * temp.x + temp.y * temp.y));
2950         pt.trace:=false;
2951         if pt.dmouse < ontracdist then
2952         begin
2953         //currentontracdist:=pt.dmouse;
2954         if (pt.dmouse<lastontracdist) then
2955         if (param.ospoint.ostype=os_blockinsert)or(param.ospoint.ostype=os_insert)or(param.ospoint.ostype=os_textinsert)or(param.ospoint.ostype=os_none)or(param.ospoint.ostype={os_intersection}os_trace) then
2956         begin
2957         if uzegeometry.vertexlen2df(param.ontrackarray.otrackarray[j].dispcoord.x,
2958                                  param.ontrackarray.otrackarray[j].dispcoord.y,
2959                                  param.md.glmouse.x,
2960                                  param.md.glmouse.y)>ontracignoredist then
2961 
2962         begin
2963           if param.polarlinetrace=0 then
2964                                         test:=true
2965                                     else
2966                                         test:=false;
2967           if not(test) then
2968                            begin
2969                                 if not uzegeometry.vertexeq(pt.worldraycoord,param.ospoint.worldcoord)
2970                                 then test:=true;
2971                            end;
2972           if test then
2973 
2974           begin
2975           lastontracdist:=pt.dmouse;
2976           if pt2<>nil then
2977                           pt2.trace:=false;
2978           pt2:=pt;
2979           pt.trace:=true;
2980           param.ospoint.worldcoord := pt.worldraycoord;
2981           param.ospoint.dispcoord := pt.dispraycoord;
2982           param.ospoint.ostype := {os_polar}{os_midle}{os_intersection}os_trace;
2983           param.pointnum := j;
2984           param.axisnum := i;
2985           //param.ospoint.tmouse:=pt.dmouse;
2986           inc(param.polarlinetrace);
2987 
2988           param.ontrackarray.otrackarray[j].tmouse:=sqrt(tx*tx+ty*ty+tz*tz);
2989           end;
2990         end;
2991         end;
2992         end;
2993         end;
2994         inc(pt);
2995         inc(pv);
2996       end;
2997    end;
2998   end;
2999 
3000   lastontracdist:=infinity;
3001   if param.polarlinetrace>0 then
3002   for i := a to param.ontrackarray.total - 1 do
3003   begin
3004        pt:=param.ontrackarray.otrackarray[i].arraydispaxis.beginiterate(ir2);
3005        if pt<>nil then
3006        begin
3007        repeat
3008             if pt^.trace then
3009             begin
3010             pobj:=PDWG.GetOnMouseObj.beginiterate(ir);
3011             if pobj<>nil then
3012             repeat
3013                   if (not sysvarDWGOSModeControl) or(GetFoctOSnapMode(pobj)=on) then
3014                   begin
3015                   ip:=pobj.IsIntersect_Line(param.ontrackarray.otrackarray[i].worldcoord,pt.worldraycoord);
3016 
3017                   if ip.isintercept then
3018                   begin
3019                    PDWG.myGluProject2(ip.interceptcoord,temp);
3020                   currentontracdist:=vertexlen2df(temp.x, temp.y,param.md.glmouse.x,param.md.glmouse.y);
3021                   if currentontracdist<lastontracdist then
3022                   //if currentontracdist<sysvar.DISP.DISP_CursorSize^*sysvar.DISP.DISP_CursorSize^+1 then
3023                   begin
3024                   param.ospoint.worldcoord := ip.interceptcoord;
3025                   param.ospoint.dispcoord := temp;
3026                   param.ospoint.ostype := {os_polar}os_apparentintersection;
3027                   lastontracdist:=currentontracdist;
3028                   end;
3029                   end;
3030                   end;
3031 
3032 
3033 
3034                   pobj:=PDWG.GetOnMouseObj.iterate(ir);
3035             until pobj=nil;
3036             end;
3037             pt:=param.ontrackarray.otrackarray[i].arraydispaxis.iterate(ir2);
3038       until pt=nil;
3039        end;
3040   end;
3041 
3042 
3043 
3044   if param.polarlinetrace<2 then exit;
3045     //lastontracdist:=infinity;
3046 
3047   for i := a to param.ontrackarray.total - 1 do
3048   for j := i+1 to param.ontrackarray.total - 1 do
3049   begin
3050        pt:=param.ontrackarray.otrackarray[i].arraydispaxis.beginiterate(ir);
3051        if pt<>nil then
3052        repeat
3053                      lastontracdist:=infinity;
3054                      pt2:=param.ontrackarray.otrackarray[j].arraydispaxis.beginiterate(ir2);
3055                      if pt2<>nil then
3056                      repeat
3057                            if (pt.trace)and(pt2.trace) then
3058                            if SqrOneVertexlength(vectordot(pt.dir,pt2.dir))>sqreps then
3059                            begin
3060                            ip:=ip;
3061                            ip.isintercept:=false;
3062                            ip:=intercept3dmy2(param.ontrackarray.otrackarray[i].worldcoord,pt.worldraycoord,param.ontrackarray.otrackarray[j].worldcoord,pt2.worldraycoord);
3063                            //ip:=intercept3dmy(createvertex(0,0,0),createvertex(0,2,0),createvertex(-1,1,0),createvertex(1,1,0));
3064                                     begin
3065                                       if ip.isintercept then
3066                                       begin
3067                                       PDWG.myGluProject2(ip.interceptcoord,
3068                                                                        temp);
3069 
3070                                       currentontracdist:=vertexlen2df(temp.x, temp.y,param.md.glmouse.x,param.md.glmouse.y);
3071                                       if currentontracdist<lastontracdist then
3072                                       if currentontracdist<sysvarDISPCursorSize*sysvarDISPCursorSize+1 then
3073                                       begin
3074                                       param.ospoint.worldcoord := ip.interceptcoord;
3075                                       param.ospoint.dispcoord := temp;
3076                                       param.ospoint.ostype := {os_polar}os_apparentintersection;
3077                                       lastontracdist:=currentontracdist;
3078                                       end;
3079                                       end;
3080                                       //param.pointnum := j;
3081                                       //param.axisnum := i;
3082                                       //inc(param.polarlinetrace);
3083                                     end;
3084 
3085                            end;
3086 
3087                            pt2:=param.ontrackarray.otrackarray[j].arraydispaxis.iterate(ir2);
3088                      until pt2=nil;
3089 
3090 
3091 
3092              pt:=param.ontrackarray.otrackarray[i].arraydispaxis.iterate(ir);
3093        until pt=nil;
3094 
3095   end;
3096 end;
3097 procedure TGeneralViewArea.myKeyPress(var Key: Word; Shift: TShiftState);
3098 {$IFDEF DELPHI}
3099 const
3100      VK_V=$56;
3101 {$ENDIF}
3102 begin
3103   if assigned(OnWaKeyPress) then
3104                                 OnWaKeyPress(self,Key,Shift);
3105   if key=0 then
3106                exit;
3107  {else if (Key = VK_A) and (shift=[ssCtrl]) then
3108       begin
3109         commandmanager.ExecuteCommand('SelectAll');
3110         Key:=00;
3111       end}
3112  {else if (Key = VK_Z) and (shift=[ssCtrl]) then
3113       begin
3114         commandmanager.ExecuteCommand('Undo');
3115         Key:=00;
3116       end}
3117   {else if (Key = VK_Z) and (shift=[ssCtrl,ssShift]) then
3118       begin
3119         commandmanager.ExecuteCommand('Redo');
3120         Key:=00;
3121       end}
3122  {else if (Key = VK_DELETE) then
3123       begin
3124         commandmanager.ExecuteCommand('Erase');
3125         Key:=00;
3126       end}
3127  (*else if (Key=VK_TAB)and(shift=[ssctrl,ssShift]) then
3128                           begin
3129                                //if assigned(MainFormN.PageControl)then
3130                                //   if MainFormN.PageControl.PageCount>1 then
3131                                   begin
3132                                        commandmanager.executecommandsilent('PrevDrawing');
3133                                        key:=00;
3134                                   end;
3135                           end
3136  else if (Key=VK_TAB)and(shift=[ssctrl]) then
3137                           begin
3138                                //if assigned(MainFormN.PageControl)then
3139                                //   if MainFormN.PageControl.PageCount>1 then
3140                                   begin
3141                                        commandmanager.executecommandsilent('NextDrawing');
3142                                        key:=00;
3143                                   end;
3144                           end*)
3145 end;
3146 
ProjectPointnull3147 function TGeneralViewArea.ProjectPoint(pntx,pnty,pntz:gdbdouble;var wcsLBN,wcsRTF,dcsLBN,dcsRTF: GDBVertex):gdbvertex;
3148 begin
3149      PDWG.myGluProject2(CreateVertex(pntx,pnty,pntz),
3150      result);
3151 
3152 
3153      if result.x<dcsLBN.x then
3154                               begin
3155                                    dcsLBN.x:=result.x;
3156                                    wcsLBN.x:=pntx;
3157                               end;
3158      if result.y<dcsLBN.y then
3159                               begin
3160                                    dcsLBN.y:=result.y;
3161                                    wcsLBN.y:=pnty;
3162                               end;
3163      if result.z<dcsLBN.z then
3164                               begin
3165                                    dcsLBN.z:=result.z;
3166                                    wcsLBN.z:=pntz;
3167                               end;
3168      if result.x>dcsRTF.x then
3169                               begin
3170                                    dcsRTF.x:=result.x;
3171                                    wcsRTF.x:=pntx;
3172                               end;
3173      if result.y>dcsRTF.y then
3174                               begin
3175                                    dcsRTF.y:=result.y;
3176                                    wcsRTF.y:=pnty;
3177                               end;
3178      if result.z>dcsRTF.z then
3179                               begin
3180                                    dcsRTF.z:=result.z;
3181                                    wcsRTF.z:=pntz;
3182                               end;
3183 end;
3184 procedure TGeneralViewArea.mouseunproject(X, Y: integer);
3185 var ca, cv: extended; ds:GDBString;
3186 begin
3187   if pdwg=NIL then exit;
3188 
3189   pdwg^.myGluUnProject(createvertex(x, y, 0),param.md.mouseray.lbegin);
3190   pdwg^.myGluUnProject(createvertex(x, y, 1),param.md.mouseray.lend);
3191 
3192   param.md.mouseray.dir:=vertexsub(param.md.mouseray.lend,param.md.mouseray.lbegin);
3193   cv:=param.md.workplane[0]*param.md.mouseray.dir.x +
3194       param.md.workplane[1]*param.md.mouseray.dir.y +
3195       param.md.workplane[2]*param.md.mouseray.dir.z;
3196   ca:=-param.md.workplane[3] - param.md.workplane[0]*param.md.mouseray.lbegin.x -
3197        param.md.workplane[1]*param.md.mouseray.lbegin.y -
3198        param.md.workplane[2]*param.md.mouseray.lbegin.z;
3199   if cv = 0 then param.md.mouseonworkplan := false
3200   else begin
3201     param.md.mouseonworkplan := true;
3202     ca := ca / cv;
3203     param.md.mouseonworkplanecoord.x := param.md.mouseray.lbegin.x + param.md.mouseray.dir.x * ca;
3204     param.md.mouseonworkplanecoord.y := param.md.mouseray.lbegin.y + param.md.mouseray.dir.y * ca;
3205     param.md.mouseonworkplanecoord.z := param.md.mouseray.lbegin.z + param.md.mouseray.dir.z * ca;
3206 
3207     ca:=param.md.workplane[0] * param.md.mouseonworkplanecoord.x +
3208         param.md.workplane[1] * param.md.mouseonworkplanecoord.y +
3209         param.md.workplane[2] * param.md.mouseonworkplanecoord.z+param.md.workplane[3];
3210 
3211     if ca<>0 then
3212     begin
3213          param.md.mouseonworkplanecoord.x:=param.md.mouseonworkplanecoord.x-param.md.workplane[0]*ca;
3214          param.md.mouseonworkplanecoord.y:=param.md.mouseonworkplanecoord.y-param.md.workplane[1]*ca;
3215          param.md.mouseonworkplanecoord.z:=param.md.mouseonworkplanecoord.z-param.md.workplane[2]*ca;
3216     end;
3217     ca:=param.md.workplane[0] * param.md.mouseonworkplanecoord.x +
3218         param.md.workplane[1] * param.md.mouseonworkplanecoord.y +
3219         param.md.workplane[2] * param.md.mouseonworkplanecoord.z + param.md.workplane[3];
3220     str(ca,ds);
3221   end;
3222 end;
3223 procedure TGeneralViewArea.SetMouseMode(smode:GDBByte);
3224 begin
3225      param.md.mode := smode;
3226 end;
3227 procedure TGeneralViewArea.ClearOntrackpoint;
3228 begin
3229   param.ontrackarray.current := 1;
3230   param.ontrackarray.total := 1;
3231 end;
3232 procedure TGeneralViewArea.Clear0Ontrackpoint;
3233 begin
3234   param.ontrackarray.current := 1;
3235   param.ontrackarray.total := 1;
3236   tocommandmcliccount:=0;
3237 end;
3238 procedure TGeneralViewArea.calcgrid;
3239 var
3240     tempv,cav: gdbvertex;
3241     l,u,r,b,maxh,maxv,ph,pv:GDBDouble;
3242 begin
3243      if pdwg=NIL then exit;
3244      tempv.x:=0;
3245      tempv.y:=0;
3246      tempv.z:=0;
3247      pdwg^.myGluUnProject(tempv,cav);
3248      param.BLPoint.x:=cav.x;
3249      param.BLPoint.y:=cav.y;
3250 
3251      tempv.x:=getviewcontrol.clientwidth/2;
3252      tempv.y:=getviewcontrol.clientheight/2;
3253      tempv.z:=0;
3254      pdwg^.myGluUnProject(tempv,cav);
3255      param.CPoint.x:=cav.x;
3256      param.CPoint.y:=cav.y;
3257 
3258      tempv.x:=getviewcontrol.clientwidth;
3259      tempv.y:=getviewcontrol.clientheight;
3260      tempv.z:=0;
3261      pdwg^.myGluUnProject(tempv,cav);
3262      param.TRPoint.x:=cav.x;
3263      param.TRPoint.y:=cav.y;
3264 
3265      tempv.x:=0;
3266      tempv.y:=getviewcontrol.clientheight;
3267      tempv.z:=0;
3268      pdwg^.myGluUnProject(tempv,cav);
3269      param.ViewHeight:=cav.y-param.BLPoint.y;
3270 
3271 
3272      pdwg^.myGluProject2(NulVertex,param.CSIcon.CSIconCoord);
3273 
3274      if (param.CSIcon.CSIconCoord.x>0)and(param.CSIcon.CSIconCoord.y>0)and(param.CSIcon.CSIconCoord.x<getviewcontrol.clientwidth)and(param.CSIcon.CSIconCoord.y<getviewcontrol.clientheight)
3275      then
3276      begin
3277           pdwg^.myGluProject2(x_Y_zVertex,
3278                                   cav);
3279           cav.x:=param.CSIcon.CSIconCoord.x-cav.x;
3280           cav.y:=param.CSIcon.CSIconCoord.y-cav.y;
3281           param.CSIcon.axislen:=sqrt(cav.x*cav.x+cav.y*cav.y);
3282           param.CSIcon.CSIconCoord.x:=0;
3283           param.CSIcon.CSIconCoord.y:=0;
3284           param.CSIcon.CSIconCoord.z:=0;
3285      end
3286      else
3287      begin
3288      pdwg^.myGluUnProject(createvertex(40, 40, 0.1),
3289                                  param.CSIcon.CSIconCoord);
3290           pdwg^.myGluProject2(CreateVertex(param.CSIcon.CSIconCoord.x,param.CSIcon.CSIconCoord.y+1,param.CSIcon.CSIconCoord.z),
3291 
3292                      cav);
3293           cav.x:=40-cav.x;
3294           cav.y:=40-cav.y;
3295           param.CSIcon.axislen:=sqrt(cav.x*cav.x+cav.y*cav.y);
3296 
3297      end;
3298      if param.CSIcon.axislen>eps then
3299                                      param.CSIcon.axislen:=100/param.CSIcon.axislen;
3300      param.CSIcon.CSIconX:=param.CSIcon.CSIconCoord;
3301      param.CSIcon.CSIconX.x:=param.CSIcon.CSIconX.x+param.CSIcon.axislen;
3302      param.CSIcon.CSIconY:=param.CSIcon.CSIconCoord;
3303      param.CSIcon.CSIconY.y:=param.CSIcon.CSIconY.y+param.CSIcon.axislen;
3304      param.CSIcon.CSIconZ:=param.CSIcon.CSIconCoord;
3305      param.CSIcon.CSIconZ.z:=param.CSIcon.CSIconZ.z+param.CSIcon.axislen;
3306 
3307 
3308      pdwg^.myGluProject2(CreateVertex(param.CSIcon.CSIconCoord.x + sizeaxis * pdwg.getpcamera^.prop.zoom, param.CSIcon.CSIconCoord.y, param.CSIcon.CSIconCoord.z),
3309                 CAV);
3310      param.CSIcon.csx.x := round(cav.x);
3311      param.CSIcon.csx.y := round(cav.y);
3312      pdwg^.myGluProject2(CreateVertex(param.CSIcon.CSIconCoord.x, param.CSIcon.CSIconCoord.y + sizeaxis * pdwg.getpcamera^.prop.zoom, param.CSIcon.CSIconCoord.z),
3313                 CAV);
3314      param.CSIcon.csy.x := round(cav.x);
3315      param.CSIcon.csy.y := round(cav.y);
3316      pdwg^.myGluProject2(CreateVertex(param.CSIcon.CSIconCoord.x, param.CSIcon.CSIconCoord.y, param.CSIcon.CSIconCoord.z + sizeaxis * pdwg.getpcamera^.prop.zoom),
3317                 CAV);
3318      param.CSIcon.csz.x := round(cav.x);
3319      param.CSIcon.csz.y := round(cav.y);
3320 
3321      param.md.WPPointLU:=PointOf3PlaneIntersect(pdwg.getpcamera.frustum[0],pdwg.getpcamera.frustum[3],param.md.workplane);
3322      param.md.WPPointUR:=PointOf3PlaneIntersect(pdwg.getpcamera.frustum[3],pdwg.getpcamera.frustum[1],param.md.workplane);
3323      param.md.WPPointRB:=PointOf3PlaneIntersect(pdwg.getpcamera.frustum[1],pdwg.getpcamera.frustum[2],param.md.workplane);
3324      param.md.WPPointBL:=PointOf3PlaneIntersect(pdwg.getpcamera.frustum[2],pdwg.getpcamera.frustum[0],param.md.workplane);
3325      l:=Vertexlength(param.md.WPPointLU,param.md.WPPointBL);
3326      r:=Vertexlength(param.md.WPPointUR,param.md.WPPointRB);
3327      u:=Vertexlength(param.md.WPPointLU,param.md.WPPointUR);
3328      b:=Vertexlength(param.md.WPPointRB,param.md.WPPointBL);
3329      if r>l then
3330                 maxh:=r
3331             else
3332                 maxh:=l;
3333      if b>u then
3334                 maxv:=b
3335             else
3336                 maxv:=u;
3337      //if sysvar.DWG.DWG_GridSpacing<>nil then
3338      begin
3339      ph:=(maxh/pdwg^.GridSpacing.y)+1;
3340      pv:=(maxv/pdwg^.GridSpacing.x)+1;
3341      param.md.WPPointUR.z:=1;
3342      if (4*ph>getviewcontrol.clientwidth)or(4*pv>getviewcontrol.clientheight)then
3343                                                    begin
3344                                                         //if sysvar.DWG.DWG_DrawGrid<>nil then
3345                                                         if pdwg^.DrawGrid then
3346                                                                                         DebugLn('{WH}'+rsGridTooDensity);
3347                                                         param.md.WPPointUR.z:=-1;
3348                                                    end;
3349      param.md.WPPointLU:=vertexmulonsc(vertexsub(param.md.WPPointLU,param.md.WPPointBL),1/pv);
3350      param.md.WPPointRB:=vertexmulonsc(vertexsub(param.md.WPPointRB,param.md.WPPointBL),1/ph);
3351 
3352      param.md.WPPointBL.x:=round((param.md.WPPointBL.x-pdwg^.Snap.Base.x)/pdwg^.GridSpacing.x)*pdwg^.GridSpacing.x+pdwg^.GridSpacing.x+pdwg^.Snap.Base.x;
3353      param.md.WPPointBL.y:=round((param.md.WPPointBL.y-pdwg^.Snap.Base.y)/pdwg^.GridSpacing.y)*pdwg^.GridSpacing.y-pdwg^.GridSpacing.y+pdwg^.Snap.Base.y;
3354 
3355      param.md.WPPointBL.z:=(-param.md.workplane[3]-param.md.workplane[0]*param.md.WPPointBL.x-param.md.workplane[1]*param.md.WPPointBL.y)/param.md.workplane[2];
3356 
3357      param.md.WPPointUR.x:=pv;
3358      param.md.WPPointUR.y:=ph;
3359      end;
3360 end;
3361 
3362 begin
3363 end.
3364