1 // Created on: 1992-04-06
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Updated by GG Tue Oct 22 16:22:10 1996
22 // reason : Try to compress the pixel image
23 // in PseudoColor 8 planes format
24 // see : SaveView(filename)
26 #include <Draw_Viewer.hxx>
29 #include <gp_Pnt2d.hxx>
30 #include <Draw_Window.hxx>
31 #include <Draw_Display.hxx>
36 #define MotionNotify 6
37 static const Standard_Real DRAWINFINITE = 1e50;
38 Standard_EXPORT Standard_Boolean Draw_Bounds = Standard_True;
39 extern Standard_Boolean Draw_Batch;
40 const Standard_Integer MAXSEGMENT = 1000;
41 Segment segm[MAXSEGMENT];
43 static Draw_View* curview = NULL;
44 static Standard_Integer curviewId = 0;
45 static char blank[2] = "";
46 static Standard_Real xmin,xmax,ymin,ymax;
47 static Standard_Boolean found = Standard_False;
48 static Standard_Integer xpick, ypick, precpick;
49 static gp_Pnt lastPickP1;
50 static gp_Pnt lastPickP2;
51 static Standard_Real lastPickParam;
52 static Draw_Color highlightcol;
53 static Draw_Color currentcolor;
54 static Standard_Boolean highlight = Standard_False;
55 static Standard_Integer ps_vx, ps_vy;
56 static Standard_Real ps_kx, ps_ky;
57 static Standard_Integer ps_px, ps_py;
58 static ostream* ps_stream;
59 static Standard_Integer ps_width[MAXCOLOR];
60 static Standard_Real ps_gray[MAXCOLOR];
62 enum DrawingMode {DRAW, PICK, POSTSCRIPT};
63 static DrawingMode CurrentMode = DRAW;
65 /* local window class */
67 //=======================================================================
69 //=======================================================================
71 class Draw_View : public Draw_Window {
73 Draw_View(Standard_Integer i,
80 #if defined(_WIN32) || defined(__WIN32__)
81 Draw_View(Standard_Integer i,
88 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
89 Draw_View(Standard_Integer i,
98 Draw_View(Standard_Integer i,
104 Standard_Boolean Init(const char* typ);
105 ~Draw_View() {Destroy();}
107 void ResetFrame() { Framex0=Framey0=Framex1=Framey1=0; }
109 void GetFrame(Standard_Integer& x0,Standard_Integer& y0,
110 Standard_Integer& x1,Standard_Integer& y1) {
111 if(Framex0==Framex1) {
112 viewer->GetFrame(id,x0,y0,x1,y1);
113 Framex0=x0; Framex1=x1; Framey0=y0; Framey1=y1;
116 x0=Framex0; x1=Framex1;
117 y0=Framey0; y1=Framey1;
124 Standard_Integer FlagPers;
125 Standard_Integer Flag2d;
126 Standard_Real FocalDist;
131 Standard_Integer lastX;
132 Standard_Integer lastY;
133 Standard_Integer Framex0,Framey0,Framex1,Framey1;
136 //=======================================================================
137 //function : Draw_View
139 //=======================================================================
140 Draw_View::Draw_View(Standard_Integer i, Draw_Viewer* v,
144 Standard_Integer H) :
145 Draw_Window("Win", X, Y, W, H), id(i), viewer(v)
147 Framex0=Framey0=Framex1=Framey1=0;
150 #if defined(_WIN32) || defined(__WIN32__)
151 //=======================================================================
152 //function : Draw_View
154 //=======================================================================
155 Draw_View::Draw_View(Standard_Integer i, Draw_Viewer* v,
161 Draw_Window("Win", X, Y, W, H, win), id(i), viewer(v)
163 Framex0=Framey0=Framex1=Framey1=0;
165 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
166 Draw_View::Draw_View(Standard_Integer i, Draw_Viewer* v,
171 NSWindow* theWindow) :
172 Draw_Window(theWindow, "Win", X, Y, W, H), id(i), viewer(v)
174 Framex0=Framey0=Framex1=Framey1=0;
178 //=======================================================================
179 //function : Draw_View
181 //=======================================================================
182 #if defined(_WIN32) || defined (__WIN32__) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
183 Draw_View::Draw_View(Standard_Integer i, Draw_Viewer* v, const char* w)
185 Draw_View::Draw_View(Standard_Integer i, Draw_Viewer* v, const char* w) :
186 Draw_Window(w), id(i), viewer(v)
192 //=======================================================================
195 //=======================================================================
197 Standard_Boolean Draw_View::Init (const char* typ)
201 Framex0=Framey0=Framex1=Framey1=0;
204 Flag2d = !strcmp("-2D-",typ);
208 if (!strcmp("+X+Y",typ) || Flag2d)
212 else if (!strcmp("-Y+X",typ))
214 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,0,1)),M_PI/2);
216 else if (!strcmp("-X-Y",typ))
218 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,0,1)),M_PI);
220 else if (!strcmp("+Y-X",typ))
222 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,0,1)),-M_PI/2);
224 else if (!strcmp("+Y+X",typ))
226 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,0,1)),-M_PI/2);
227 T.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),M_PI);
230 else if (!strcmp("-X+Y",typ))
232 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),M_PI);
234 else if (!strcmp("-Y-X",typ))
236 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,0,1)),-M_PI/2);
237 T.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI);
240 else if (!strcmp("+X-Y",typ))
242 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI);
244 else if (!strcmp("+X+Z",typ))
246 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),-M_PI/2);
248 else if (!strcmp("-Z+X",typ))
250 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),-M_PI/2);
251 T.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),-M_PI/2);
254 else if (!strcmp("-X-Z",typ))
256 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),-M_PI/2);
257 T.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),-M_PI);
260 else if (!strcmp("+Z-X",typ))
262 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),-M_PI/2);
263 T.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),M_PI/2);
266 else if (!strcmp("+Z+X",typ))
268 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI/2);
269 T.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),M_PI/2);
272 else if (!strcmp("-X+Z",typ))
274 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI/2);
275 T.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),M_PI);
278 else if (!strcmp("-Z-X",typ))
280 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI/2);
281 T.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),-M_PI/2);
284 else if (!strcmp("+X-Z",typ))
286 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI/2);
288 else if (!strcmp("+Y+Z",typ))
290 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),-M_PI/2);
291 T.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),-M_PI/2);
294 else if (!strcmp("-Z+Y",typ))
296 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),-M_PI/2);
298 else if (!strcmp("-Y-Z",typ))
300 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),-M_PI/2);
301 T.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI/2);
304 else if (!strcmp("+Z-Y",typ))
306 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),-M_PI/2);
307 T.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI);
310 else if (!strcmp("+Z+Y",typ))
312 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),M_PI/2);
314 else if (!strcmp("-Y+Z",typ))
316 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),M_PI/2);
317 T.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),-M_PI/2);
320 else if (!strcmp("-Z-Y",typ))
322 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),M_PI/2);
323 T.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI);
326 else if (!strcmp("+Y-Z",typ))
328 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(0,1,0)),M_PI/2);
329 T.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),M_PI/2);
332 else if (!strcmp("AXON",typ))
334 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),-M_PI/4);
335 T.SetRotation(gp_Ax1(Pvise,gp_Dir(0,0,1)),-M_PI/4);
338 else if (!strcmp("PERS",typ))
341 Matrix.SetRotation(gp_Ax1(Pvise,gp_Dir(1,0,0)),-M_PI/4);
342 T.SetRotation(gp_Ax1(Pvise,gp_Dir(0,0,1)),-M_PI/4);
346 return Standard_False;
349 return Standard_True;
352 //=======================================================================
355 //=======================================================================
357 void Draw_View::WExpose()
359 Framex0=Framey0=Framex1=Framey1=0;
360 viewer->RepaintView(id);
363 //=======================================================================
366 //=======================================================================
368 Draw_Viewer::Draw_Viewer()
370 if (Draw_Batch) return;
372 for ( i = 0; i < MAXVIEW; i++) myViews[i] = NULL;
373 for (i = 0; i < MAXCOLOR; i++) {
379 //=======================================================================
380 //function : DefineColor
382 //=======================================================================
384 Standard_Boolean Draw_Viewer::DefineColor (const Standard_Integer i, const char* colname)
386 if (Draw_Batch) return 1;
387 return Draw_Window::DefineColor(i,colname);
391 //=======================================================================
392 //function : MakeView
394 //=======================================================================
396 void Draw_Viewer::MakeView(const Standard_Integer id,
398 const Standard_Integer X, const Standard_Integer Y,
399 const Standard_Integer W, const Standard_Integer H)
401 if (Draw_Batch) return;
405 myViews[id] = new Draw_View(id,this,X , Y, W, H);
408 myViews[id]->dX = W / 2;
409 myViews[id]->dY = - H / 2;
411 if (!myViews[id]->Init(typ))
419 //=======================================================================
420 //function : MakeView
422 //=======================================================================
424 void Draw_Viewer::MakeView(const Standard_Integer id,
426 const Standard_Integer X, const Standard_Integer Y,
427 const Standard_Integer W, const Standard_Integer H,
428 HWND win, Standard_Boolean useBuffer)
430 if (Draw_Batch) return;
434 myViews[id] = new Draw_View(id, this, X, Y, W, H, win);
435 myViews[id]->SetUseBuffer(useBuffer);
438 myViews[id]->dX = W / 2;
439 myViews[id]->dY = - H / 2;
441 if (!myViews[id]->Init(typ))
448 //=======================================================================
449 //function : MakeView
451 //=======================================================================
453 void Draw_Viewer::MakeView (const Standard_Integer id,
457 if (Draw_Batch) return;
461 myViews[id] = new Draw_View(id,this,window);
464 myViews[id]->dX = myViews[id]->WidthWin() / 2;
465 myViews[id]->dY = - myViews[id]->HeightWin() / 2;
467 if (!myViews[id]->Init(typ))
475 //=======================================================================
476 //function : SetTitle
478 //=======================================================================
480 void Draw_Viewer::SetTitle (const Standard_Integer id, const char* name)
482 if (Draw_Batch) return;
483 if(myViews[id]) myViews[id]->SetTitle((char*)name);
486 //=======================================================================
487 //function : ResetView
488 //purpose : reset view zoom and axes
489 //=======================================================================
491 void Draw_Viewer::ResetView(const Standard_Integer id)
493 if (Draw_Batch) return;
495 myViews[id]->Init(myViews[id]->type);
500 //=======================================================================
503 //=======================================================================
505 void Draw_Viewer::SetZoom (const Standard_Integer id, const Standard_Real z)
507 if (Draw_Batch) return;
509 Standard_Real zz = z / myViews[id]->Zoom;
510 myViews[id]->Zoom = z;
511 Standard_Integer X,Y,W,H;
512 GetPosSize(id,X,Y,W,H);
514 myViews[id]->dX = (Standard_Integer )( w / 2 - zz * (w/2 - myViews[id]->dX));
516 myViews[id]->dY = (Standard_Integer )( - h / 2 + zz * (h/2 + myViews[id]->dY));
520 //=======================================================================
521 //function : RotateView
523 //=======================================================================
525 void Draw_Viewer::RotateView (const Standard_Integer id,
527 const Standard_Real A)
529 if (Draw_Batch) return;
531 gp_Trsf T = myViews[id]->Matrix;
535 gp_Dir DD(D.X(),D.Y(),0);
538 RotateView(id,PP,DD,A);
542 //=======================================================================
543 //function : RotateView
545 //=======================================================================
547 void Draw_Viewer::RotateView (const Standard_Integer id,
550 const Standard_Real A)
552 if (Draw_Batch) return;
555 T.SetRotation(gp_Ax1(P,D),A);
556 myViews[id]->Matrix.Multiply(T);
561 //=======================================================================
562 //function : SetFocal
564 //=======================================================================
566 void Draw_Viewer::SetFocal (const Standard_Integer id, const Standard_Real F)
568 if (Draw_Batch) return;
570 myViews[id]->FocalDist = F;
573 //=======================================================================
576 //=======================================================================
578 char* Draw_Viewer::GetType (const Standard_Integer id) const
580 if (Draw_Batch) return blank;
582 return myViews[id]->type;
587 //=======================================================================
590 //=======================================================================
592 Standard_Real Draw_Viewer::Zoom (const Standard_Integer id) const
594 if (Draw_Batch) return Standard_False;
596 return myViews[id]->Zoom;
601 //=======================================================================
604 //=======================================================================
606 Standard_Real Draw_Viewer::Focal (const Standard_Integer id) const
608 if (Draw_Batch) return 1.;
610 return myViews[id]->FocalDist;
615 //=======================================================================
618 //=======================================================================
620 void Draw_Viewer::GetTrsf (const Standard_Integer id,gp_Trsf& T) const
622 if (Draw_Batch) return;
624 T = myViews[id]->Matrix;
627 //=======================================================================
630 //=======================================================================
632 Standard_Boolean Draw_Viewer::Is3D (const Standard_Integer id) const
634 if (Draw_Batch) return Standard_False;
636 return !myViews[id]->Flag2d;
638 return Standard_False;
641 //=======================================================================
644 //=======================================================================
646 void Draw_Viewer::SetTrsf (const Standard_Integer id,gp_Trsf& T)
648 if (Draw_Batch) return;
650 myViews[id]->Matrix = T;
653 //=======================================================================
654 //function : GetPosSize
656 //=======================================================================
658 void Draw_Viewer::GetPosSize(const Standard_Integer id,
659 Standard_Integer& X, Standard_Integer& Y,
660 Standard_Integer& W, Standard_Integer& H)
662 if (Draw_Batch) return;
663 if (myViews[id] != NULL) {
664 myViews[id]->GetPosition(X, Y);
665 W = myViews[id]->WidthWin();
666 H = myViews[id]->HeightWin();
670 //=======================================================================
671 //function : GetFrame
673 //=======================================================================
675 void Draw_Viewer::GetFrame(const Standard_Integer id,
676 Standard_Integer& xminf, Standard_Integer& yminf,
677 Standard_Integer& xmaxf, Standard_Integer& ymaxf)
679 if (Draw_Batch) return;
681 Standard_Integer X,Y,H,W;
682 GetPosSize(id,X,Y,W,H);
683 xminf = - myViews[id]->dX;
684 xmaxf = W - myViews[id]->dX;
685 yminf = - myViews[id]->dY - H;
686 ymaxf = - myViews[id]->dY;
690 //=======================================================================
693 //=======================================================================
695 void Draw_Viewer::FitView(const Standard_Integer id, const Standard_Integer frame)
697 if (Draw_Batch) return;
700 // is this the only view in its category
701 Standard_Integer is2d = myViews[id]->Flag2d;
702 Standard_Integer i,nbviews = 0;
703 for (i = 1; i < MAXVIEW; i++) {
705 if (myViews[i]->Flag2d == is2d) nbviews++;
708 Standard_Boolean only = (nbviews == 1);
710 Standard_Integer X,Y,H,W;
711 GetPosSize(id,X,Y,W,H);
712 // compute the min max
713 Standard_Integer n = myDrawables.Length();
716 curview = myViews[id];
717 Standard_Real umin,umax,vmin,vmax;
718 Standard_Real u1,u2,v1,v2;
719 umin = vmin = DRAWINFINITE;
720 umax = vmax = -DRAWINFINITE;
722 for (i = 1; i <= n; i++) {
723 Standard_Boolean d3d = myDrawables(i)->Is3D();
724 if ((d3d && !is2d) || (!d3d && is2d)) {
725 // if this is not the only view recompute...
727 DrawOnView(id,myDrawables(i));
728 myDrawables(i)->Bounds(u1,u2,v1,v2);
729 if (u1 < umin) umin = u1;
730 if (u2 > umax) umax = u2;
731 if (v1 < vmin) vmin = v1;
732 if (v2 > vmax) vmax = v2;
736 umin = umin / curview->Zoom;
737 vmin = vmin / curview->Zoom;
738 umax = umax / curview->Zoom;
739 vmax = vmax / curview->Zoom;
740 if ((umax - umin) < 1.e-6) {
741 if ((vmax - vmin) < 1.e-6)
744 z = ((Standard_Real)(H - 2*frame)) / (vmax - vmin);
747 z = ((Standard_Real)(W - 2*frame)) /((Standard_Real) (umax - umin));
748 if ((vmax - vmin) > 1.e-6) {
749 Standard_Real z2 = ((Standard_Real)(H - 2*frame)) /(vmax - vmin);
754 curview->dX = (Standard_Integer )( W / 2 - ((umin+umax) / 2) * z);
755 curview->dY = (Standard_Integer )( - H / 2 - ((vmin+vmax) / 2) * z);
759 //=======================================================================
762 //=======================================================================
764 void Draw_Viewer::PanView(const Standard_Integer id,
765 const Standard_Integer DX, const Standard_Integer DY)
767 if (Draw_Batch) return;
769 myViews[id]->dX += DX;
770 myViews[id]->dY += DY;
775 //=======================================================================
778 //=======================================================================
780 void Draw_Viewer::SetPan(const Standard_Integer id,
781 const Standard_Integer DX, const Standard_Integer DY)
783 if (Draw_Batch) return;
785 myViews[id]->dX = DX;
786 myViews[id]->dY = DY;
790 //=======================================================================
793 //=======================================================================
795 void Draw_Viewer::GetPan(const Standard_Integer id,
796 Standard_Integer& DX, Standard_Integer& DY)
798 if (Draw_Batch) return;
800 DX = myViews[id]->dX;
801 DY = myViews[id]->dY;
805 //=======================================================================
808 //=======================================================================
810 Standard_Boolean Draw_Viewer::HasView(const Standard_Integer id) const
812 if (Draw_Batch) return Standard_False;
813 if ((id < 0) || id >= MAXVIEW) return Standard_False;
814 return myViews[id] != NULL;
817 //=======================================================================
818 //function : DisplayView
820 //=======================================================================
822 void Draw_Viewer::DisplayView (const Standard_Integer id) const
824 if (Draw_Batch) return;
825 if (myViews[id]) myViews[id]->DisplayWindow();
828 //=======================================================================
829 //function : HideView
831 //=======================================================================
833 void Draw_Viewer::HideView (const Standard_Integer id) const
835 if (Draw_Batch) return;
841 //=======================================================================
842 //function : ClearView
844 //=======================================================================
846 void Draw_Viewer::ClearView(const Standard_Integer id) const
848 if (Draw_Batch) return;
849 if (myViews[id]) myViews[id]->Clear();
852 //=======================================================================
853 //function : RemoveView
855 //=======================================================================
857 void Draw_Viewer::RemoveView(const Standard_Integer id)
859 if (Draw_Batch) return;
866 //=======================================================================
867 //function : RepaintView
869 //=======================================================================
870 void Draw_Viewer::RepaintView (const Standard_Integer id) const
872 if (Draw_Batch) return;
875 Standard_Integer n = myDrawables.Length();
876 for (Standard_Integer i = 1; i <= n; i++)
877 DrawOnView(id,myDrawables(i));
883 //=======================================================================
884 //function : ResizeView
885 //purpose : WNT re-drawing optimization
886 //=======================================================================
887 void Draw_Viewer::ResizeView (const Standard_Integer id) const
889 if (Draw_Batch) return;
890 if (myViews[id] && myViews[id]->GetUseBuffer()) {
891 myViews[id]->InitBuffer();
896 //=======================================================================
897 //function : UpdateView
898 //purpose : WNT re-drawing optimization
899 //=======================================================================
900 void Draw_Viewer::UpdateView (const Standard_Integer id, const Standard_Boolean forced) const
902 if (Draw_Batch) return;
904 if (!myViews[id]->GetUseBuffer() || forced) {
907 // Fast redrawing on WNT
908 if (myViews[id]->GetUseBuffer()) myViews[id]->Redraw();
913 //=======================================================================
914 //function : ConfigView
916 //=======================================================================
918 void Draw_Viewer::ConfigView (const Standard_Integer id) const
920 if (Draw_Batch) return;
922 myViews[id]->dX = myViews[id]->WidthWin() / 2;
923 myViews[id]->dY = - myViews[id]->HeightWin() / 2;
928 //=======================================================================
929 //function : PostScriptView
931 //=======================================================================
933 void Draw_Viewer::PostScriptView (const Standard_Integer id,
934 const Standard_Integer VXmin,
935 const Standard_Integer VYmin,
936 const Standard_Integer VXmax,
937 const Standard_Integer VYmax,
938 const Standard_Integer PXmin,
939 const Standard_Integer PYmin,
940 const Standard_Integer PXmax,
941 const Standard_Integer PYmax,
942 ostream& sortie) const
944 if (Draw_Batch) return;
950 ps_kx = ((Standard_Real) (PXmax - PXmin)) / ((Standard_Real) (VXmax - VXmin));
951 ps_ky = ((Standard_Real) (PYmax - PYmin)) / ((Standard_Real) (VYmax - VYmin));
953 Standard_Integer n = myDrawables.Length();
955 CurrentMode = POSTSCRIPT;
956 Draw_Display DF = MakeDisplay(id);
957 Standard_Boolean view2d = myViews[id]->Flag2d;
958 for (Standard_Integer i = 1; i <= n; i++)
959 if (myDrawables(i)->Is3D()) {
960 if (!view2d) myDrawables(i)->DrawOn(DF);
963 if (view2d) myDrawables(i)->DrawOn(DF);
965 sortie << "stroke\n";
970 //=======================================================================
971 //function : PostColor
973 //=======================================================================
975 void Draw_Viewer::PostColor(const Standard_Integer icol,
976 const Standard_Integer width,
977 const Standard_Real gray)
979 if (Draw_Batch) return;
980 if ((icol < 0) || (icol >= MAXCOLOR)) return;
981 ps_width[icol] = width;
982 ps_gray[icol] = gray;
985 //=======================================================================
986 //function : SaveView
988 //=======================================================================
990 Standard_Boolean Draw_Viewer::SaveView(const Standard_Integer id,
991 const char* filename)
993 if (Draw_Batch) return Standard_False;;
996 return myViews[id]->Save(filename);
1000 std::cerr << "View " << id << " doesn't exists!\n";
1001 return Standard_False;
1005 //=======================================================================
1006 //function : RepaintAll
1008 //=======================================================================
1010 void Draw_Viewer::RepaintAll () const
1012 if (Draw_Batch) return;
1013 for (Standard_Integer id = 0; id < MAXVIEW; id++)
1017 //=======================================================================
1018 //function : Repaint2D
1020 //=======================================================================
1022 void Draw_Viewer::Repaint2D () const
1024 if (Draw_Batch) return;
1025 for (Standard_Integer id = 0; id < MAXVIEW; id++)
1027 if (myViews[id]->Flag2d) RepaintView(id);
1031 //=======================================================================
1032 //function : Repaint3D
1034 //=======================================================================
1036 void Draw_Viewer::Repaint3D () const
1038 if (Draw_Batch) return;
1039 for (Standard_Integer id = 0; id < MAXVIEW; id++)
1041 if (!myViews[id]->Flag2d) RepaintView(id);
1045 //=======================================================================
1046 //function : GetWindow
1048 //=======================================================================
1049 unsigned long Draw_Viewer::GetWindow (const Standard_Integer id) const
1051 if (Draw_Batch) return 0;
1053 #if defined(_WIN32) || defined(__WIN32__)
1054 return (unsigned long)(myViews[id]->win);
1055 #elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
1056 return myViews[id]->win;
1062 //=======================================================================
1063 //function : DeleteView
1065 //=======================================================================
1067 void Draw_Viewer::DeleteView(const Standard_Integer id)
1069 if (Draw_Batch) return;
1070 if (myViews[id] != NULL) {
1076 //=======================================================================
1079 //=======================================================================
1081 void Draw_Viewer::Clear()
1083 if (Draw_Batch) return;
1084 for (Standard_Integer i = 1; i <= myDrawables.Length(); i++)
1085 myDrawables(i)->Visible(Standard_False);
1086 myDrawables.Clear();
1087 for (Standard_Integer id = 0; id < MAXVIEW; id++)
1091 //=======================================================================
1092 //function : Clear2D
1094 //=======================================================================
1096 void Draw_Viewer::Clear2D()
1098 if (Draw_Batch) return;
1099 Standard_Integer i = 1;
1100 while (i <= myDrawables.Length()) {
1101 if (myDrawables(i)->Is3D())
1104 myDrawables(i)->Visible(Standard_False);
1105 myDrawables.Remove(i);
1108 for (Standard_Integer id = 0; id < MAXVIEW; id++) {
1110 if (myViews[id]->Flag2d)
1116 //=======================================================================
1117 //function : Clear3D
1119 //=======================================================================
1121 void Draw_Viewer::Clear3D()
1123 if (Draw_Batch) return;
1124 Standard_Integer i = 1;
1125 while (i <= myDrawables.Length()) {
1126 if (myDrawables(i)->Is3D()) {
1127 myDrawables(i)->Visible(Standard_False);
1128 myDrawables.Remove(i);
1133 for (Standard_Integer id = 0; id < MAXVIEW; id++) {
1135 if (!myViews[id]->Flag2d)
1141 //=======================================================================
1144 //=======================================================================
1146 void Draw_Viewer::Flush()
1148 if (Draw_Batch) return;
1149 Draw_Window::Flush();
1152 //=======================================================================
1153 //function : DrawOnView
1155 //=======================================================================
1157 void Draw_Viewer::DrawOnView(const Standard_Integer id,
1158 const Handle(Draw_Drawable3D)& D) const
1160 if (Draw_Batch) return;
1162 Draw_Display d = MakeDisplay(id);
1163 xmin = ymin = DRAWINFINITE;
1164 xmax = ymax = -DRAWINFINITE;
1166 Standard_Boolean view2d = myViews[id]->Flag2d;
1167 myViews[id]->ResetFrame();
1168 if ((D->Is3D() && !view2d) ||
1169 (!D->Is3D() && view2d)) {
1172 if (CurrentMode == DRAW)
1173 D->SetBounds(xmin,xmax,ymin,ymax);
1179 //=======================================================================
1180 //function : HighlightOnView
1182 //=======================================================================
1184 void Draw_Viewer::HighlightOnView (const Standard_Integer id,
1185 const Handle(Draw_Drawable3D)& D,
1186 const Draw_ColorKind C) const
1188 if (Draw_Batch) return;
1189 highlight = Standard_True;
1192 highlight = Standard_False;
1195 //=======================================================================
1196 //function : AddDrawable
1198 //=======================================================================
1200 void Draw_Viewer::AddDrawable (const Handle(Draw_Drawable3D)& D)
1202 if (Draw_Batch) return;
1203 if (!D.IsNull() && !D->Visible()) {
1204 myDrawables.Append(D);
1205 D->Visible(Standard_True);
1209 //=======================================================================
1210 //function : RemoveDrawable
1212 //=======================================================================
1214 void Draw_Viewer::RemoveDrawable (const Handle(Draw_Drawable3D)& D)
1216 if (Draw_Batch) return;
1217 if (!D.IsNull() && D->Visible()) {
1218 Standard_Integer index;
1219 for (index = 1; index <= myDrawables.Length(); index++) {
1220 if (myDrawables(index) == D) {
1221 D->Visible(Standard_False);
1222 myDrawables.Remove(index);
1229 //=======================================================================
1230 //function : MakeDisplay
1231 //purpose : return a display on the view
1232 //=======================================================================
1234 Draw_Display Draw_Viewer::MakeDisplay (const Standard_Integer id) const
1236 if (Draw_Batch) {Draw_Display dis;return dis;}
1238 curview = myViews[id];
1241 Draw_Color initcol(Draw_blanc);
1242 // to force setting the color
1243 currentcolor = Draw_Color(Draw_rouge);
1245 dis.SetColor(initcol);
1246 dis.SetMode(GXcopy);
1250 //=======================================================================
1253 //=======================================================================
1254 void Draw_Viewer::Select (Standard_Integer& id, Standard_Integer& X, Standard_Integer& Y,
1255 Standard_Integer& Button, Standard_Boolean wait)
1257 if (Draw_Batch) return;
1259 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
1261 if (id >=0 && id < MAXVIEW) {
1262 if (myViews[id]) myViews[id]->Wait(wait);
1266 for(int i=0 ; i<MAXVIEW ; i++)
1267 if (myViews[i]) myViews[i]->Wait(wait);
1270 Standard_Boolean again = Standard_True;
1281 Standard_Integer iv;
1282 for (iv = 0; iv < MAXVIEW; iv++) {
1284 if (myViews[iv]->win == ev.window)
1288 if (wait || id == iv) {
1298 again = Standard_False;
1307 again = Standard_False;
1313 X = X - myViews[id]->dX;
1314 Y = -Y - myViews[id]->dY;
1316 if (!wait) myViews[id]->Wait(!wait);
1317 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
1318 Standard_Integer aWindowNumber;
1321 while (id >= MAXVIEW)
1323 GetNextEvent(wait, aWindowNumber, X, Y, Button);
1327 continue; // mouse clicked on window title
1330 for (Standard_Integer anIter = 0; anIter < MAXVIEW; anIter++)
1332 if (myViews[anIter] && myViews[anIter]->IsEqualWindows (aWindowNumber))
1339 X = X - myViews[id]->dX;
1340 Y = -Y - myViews[id]->dY;
1345 id = MAXVIEW; //:abv 29.05.02: cycle for working in console mode
1346 while ( id >= MAXVIEW ) {
1348 Draw_Window::SelectWait(hWnd, X, Y, Button);
1350 Draw_Window::SelectNoWait(hWnd, X, Y, Button);
1352 // Recherche du numero de la vue grace au HANDLE
1353 for(int i=0 ; i<MAXVIEW ; i++)
1354 if (myViews[i] && myViews[i]->win == hWnd ) id = i;
1356 X = X - myViews[id]->dX;
1357 Y = -Y - myViews[id]->dY;
1361 //=======================================================================
1364 //=======================================================================
1366 Standard_Integer Draw_Viewer::Pick(const Standard_Integer id,
1367 const Standard_Integer X, const Standard_Integer Y, const Standard_Integer Prec,
1368 Handle(Draw_Drawable3D)& D,
1369 const Standard_Integer first) const
1371 if (Draw_Batch) return 0;
1372 if (myViews[id] == NULL)
1375 // is this the only view in its category
1376 Standard_Integer is2d = myViews[id]->Flag2d;
1377 Standard_Integer i,nbviews = 0;
1378 for (i = 0; i < MAXVIEW; i++) {
1380 if (myViews[i]->Flag2d == is2d) nbviews++;
1383 Standard_Boolean only = (nbviews == 1);
1389 found = Standard_False;
1390 Standard_Real x1,x2,y1,y2;
1391 for (i = first+1; i <= myDrawables.Length(); i++) {
1392 Standard_Boolean reject = Standard_False;
1393 // rejection if only view
1395 myDrawables(i)->Bounds(x1,x2,y1,y2);
1396 if ((xpick+Prec < x1) || (xpick-Prec > x2) ||
1397 (ypick+Prec < y1) || (ypick-Prec > y2))
1398 reject = Standard_True;
1401 DrawOnView(id,myDrawables(i));
1407 found = Standard_False;
1408 if (i <= myDrawables.Length())
1415 //=======================================================================
1416 //function : LastPick
1418 //=======================================================================
1420 void Draw_Viewer::LastPick(gp_Pnt& P1, gp_Pnt& P2, Standard_Real& Param)
1422 if (Draw_Batch) return;
1425 Param = lastPickParam;
1428 //=======================================================================
1429 //function : ~Draw_Viewer
1431 //=======================================================================
1433 Draw_Viewer::~Draw_Viewer()
1435 if (Draw_Batch) return;
1436 for (Standard_Integer id = 0; id < MAXVIEW; id++)
1440 //=======================================================================
1441 //function : operator<<
1443 //=======================================================================
1445 Draw_Viewer& Draw_Viewer::operator<<(const Handle(Draw_Drawable3D)& d3d)
1447 if (Draw_Batch) return *this;
1448 if (!d3d.IsNull()) {
1450 for (Standard_Integer id = 0; id < MAXVIEW; id++)
1456 //=======================================================================
1457 //function : GetDrawables
1459 //=======================================================================
1460 const Draw_SequenceOfDrawable3D& Draw_Viewer::GetDrawables()
1465 // *******************************************************************
1467 // *******************************************************************
1472 if (Draw_Batch) return;
1473 if (highlight) curview->SetColor(highlightcol.ID());
1474 curview->DrawSegments(segm,nbseg);
1478 //=======================================================================
1479 //function : SetColor
1481 //=======================================================================
1483 void Draw_Display::SetColor (const Draw_Color& col) const
1485 if (Draw_Batch) return;
1486 if (col.ID() == currentcolor.ID()) return;
1489 switch (CurrentMode) {
1493 curview->SetColor(col.ID());
1497 (*ps_stream) << "stroke\nnewpath\n";
1498 (*ps_stream) << ps_width[col.ID()]<<" setlinewidth\n";
1499 (*ps_stream) << ps_gray[col.ID()]<<" setgray\n";
1506 //=======================================================================
1507 //function : SetMode
1509 //=======================================================================
1511 void Draw_Display::SetMode (const Standard_Integer M) const
1513 if (Draw_Batch) return;
1514 switch (CurrentMode) {
1518 curview->SetMode(M);
1527 //=======================================================================
1530 //=======================================================================
1532 Standard_Real Draw_Display::Zoom() const
1534 if (Draw_Batch) return 1.;
1535 return curview->Zoom;
1538 //=======================================================================
1541 //=======================================================================
1543 void Draw_Display::Flush () const
1545 if (Draw_Batch) return;
1549 //=======================================================================
1550 //function : DrawString
1552 //=======================================================================
1554 void Draw_Display::DrawString(const gp_Pnt2d& ppt,
1555 const Standard_CString S,
1556 const Standard_Real moveX,
1557 const Standard_Real moveY)
1559 if (Draw_Batch) return;
1560 if (ppt.X() > 1.e09 || ppt.X() < -1.e09 ) return;
1561 if (ppt.Y() > 1.e09 || ppt.Y() < -1.e09 ) return;
1563 gp_Pnt2d pt(ppt.X()*curview->Zoom,ppt.Y()*curview->Zoom);
1565 if (pt.X() > 1.e09 || pt.X() < -1.e09 ) return;
1566 if (pt.Y() > 1.e09 || pt.Y() < -1.e09 ) return;
1568 switch (CurrentMode) {
1572 int X = (int) ( pt.X() + moveX + curview->dX);
1573 int Y = (int) (-pt.Y() + moveY - curview->dY);
1574 curview->DrawString(X,Y,(char *)S);
1576 if (pt.X() + moveX > xmax) xmax = pt.X();
1577 if (pt.X() + moveX < xmin) xmin = pt.X();
1578 if (-pt.Y() - moveY > ymax) ymax = -pt.Y();
1579 if (-pt.Y() - moveY < ymin) ymin = -pt.Y();
1586 Standard_Integer x = (Standard_Integer )( (pt.X() + moveX - ps_vx) * ps_kx + ps_px);
1587 Standard_Integer y = (Standard_Integer )( (pt.Y() + moveY - ps_vy) * ps_ky + ps_py);
1588 (*ps_stream) <<"stroke\n";
1589 (*ps_stream) << x << " " << y << " m\n";
1590 (*ps_stream) <<"("<<S<<") show\nnewpath\n";
1599 //=======================================================================
1600 //function : DrawString
1602 //=======================================================================
1604 void Draw_Display::DrawString(const gp_Pnt2d& ppt,
1605 const Standard_CString S)
1607 if (Draw_Batch) return;
1608 DrawString(ppt,S,0.0,0.0);
1611 //=======================================================================
1612 //function : DrawString
1614 //=======================================================================
1616 void Draw_Display::DrawString(const gp_Pnt& pt,
1617 const Standard_CString S,
1618 const Standard_Real moveX,
1619 const Standard_Real moveY)
1621 if (Draw_Batch) return;
1622 DrawString(Project(pt),S,moveX,moveY);
1625 //=======================================================================
1626 //function : DrawString
1628 //=======================================================================
1630 void Draw_Display::DrawString(const gp_Pnt& pt,
1631 const Standard_CString S)
1633 if (Draw_Batch) return;
1634 DrawString(Project(pt),S,0.0,0.0);
1638 // *******************************************************************
1639 // Drawing data static variables
1640 // *******************************************************************
1641 static gp_Pnt2d PtCur; // current 2D point
1642 static gp_Pnt PtPers; // current 3D point for Pers
1644 //=======================================================================
1645 //function : Project
1647 //=======================================================================
1649 void Draw_Display::Project(const gp_Pnt& p, gp_Pnt2d& p2d) const
1651 if (Draw_Batch) return;
1653 pt.Transform(curview->Matrix);
1654 Standard_Real xp,yp,zp;
1656 if (curview->FlagPers) {
1657 xp = xp*curview->FocalDist/(curview->FocalDist-zp);
1658 yp = yp*curview->FocalDist/(curview->FocalDist-zp);
1660 p2d.SetCoord(xp,yp);
1663 //=======================================================================
1664 //function : Draw_Display
1666 //=======================================================================
1668 Draw_Display::Draw_Display ()
1670 if (Draw_Batch) return;
1672 PtPers.SetCoord(0,0,0);
1673 PtPers.Transform(curview->Matrix);
1674 PtCur.SetCoord(PtPers.X()*curview->Zoom,PtPers.Y()*curview->Zoom);
1678 //=======================================================================
1679 //function : MoveTo 2D
1681 //=======================================================================
1683 void Draw_Display::MoveTo (const gp_Pnt2d& pp)
1685 if (Draw_Batch) return;
1686 gp_Pnt2d pt(pp.X() * curview->Zoom, pp.Y() * curview->Zoom);
1687 switch (CurrentMode) {
1692 if (pt.X() > xmax) xmax = pt.X();
1693 if (pt.X() < xmin) xmin = pt.X();
1694 if (pt.Y() > ymax) ymax = pt.Y();
1695 if (pt.Y() < ymin) ymin = pt.Y();
1705 Standard_Integer x = (Standard_Integer )( (pt.X() - ps_vx) * ps_kx + ps_px);
1706 Standard_Integer y = (Standard_Integer )( (pt.Y() - ps_vy) * ps_ky + ps_py);
1707 (*ps_stream) <<"stroke\nnewpath\n"<< x << " " << y << " m\n";
1713 //=======================================================================
1714 //function : DrawTo 2D
1716 //=======================================================================
1717 inline Standard_Integer CalculRegion(const Standard_Real x,
1718 const Standard_Real y,
1719 const Standard_Real x1,
1720 const Standard_Real y1,
1721 const Standard_Real x2,
1722 const Standard_Real y2) {
1724 if(x<x1) { r=1; } else { if(x>x2) { r=2; } else { r=0; } }
1725 if(y<y1) { r|=4; } else { if(y>y2) { r|=8; } }
1729 Standard_Boolean Trim(gp_Pnt2d& P1,gp_Pnt2d& P2,
1734 Standard_Real xa=P1.X(),ya=P1.Y(),xb=P2.X(),yb=P2.Y();
1736 Standard_Integer regiona=0,regionb=0;
1737 regiona = CalculRegion(xa,ya,x0,y0,x1,y1);
1738 regionb = CalculRegion(xb,yb,x0,y0,x1,y1);
1739 if((regiona & regionb)==0) {
1740 Standard_Real dx=xb-xa;
1741 Standard_Real dy=yb-ya;
1742 Standard_Real dab=sqrt(dx*dx+dy*dy);
1743 if(dab<1e-10) return(Standard_False);
1747 Standard_Real xm,ym,mfenx,mfeny;
1748 mfenx=xm=0.5*(x0+x1);
1749 mfeny=ym=0.5*(y0+y1);
1751 Standard_Real d=sqrt(x1*x1+y1*y1) * 2;
1753 Standard_Real p=(xm-xa)*dx+(ym-ya)*dy;
1758 gp_Pnt2d MFen(mfenx,mfeny);
1759 if(MFen.SquareDistance(Pm) > d*d) return(Standard_False);
1761 Standard_Real PmDistP1 = Pm.Distance(P1);
1762 Standard_Real PmDistP2 = Pm.Distance(P2);
1764 Standard_Real amab = (xm-xa)*(xb-xa)+(ym-ya)*(yb-ya);
1766 if(amab > 0) { //-- M est compris entre A et B
1768 P1.SetCoord(xm-d*dx,ym-d*dy);
1771 P2.SetCoord(xm+d*dx,ym+d*dy);
1774 else if(PmDistP1 < PmDistP2) { //-- On a M P1 P2
1776 P2.SetCoord(xm+d*dx,ym+d*dy);
1779 else { //-- On a P1 P2 M
1781 P1.SetCoord(xm-d*dx,ym-d*dy);
1784 return(Standard_True);
1786 else return(Standard_False);
1792 void Draw_Display::DrawTo (const gp_Pnt2d& pp2)
1794 if (Draw_Batch) return;
1795 if (pp2.X() > 1.e09 || pp2.X() < -1.e09 ) return;
1796 if (pp2.Y() > 1.e09 || pp2.Y() < -1.e09 ) return;
1798 gp_Pnt2d p2(pp2.X() * curview->Zoom, pp2.Y() * curview->Zoom);
1800 if (p2.X() > 1.e09 || p2.X() < -1.e09 ) return;
1801 if (p2.Y() > 1.e09 || p2.Y() < -1.e09 ) return;
1803 gp_Pnt2d p1 = PtCur;
1804 if (p1.X() > 1.e09 || p1.X() < -1.e09 ) return;
1805 if (p1.Y() > 1.e09 || p1.Y() < -1.e09 ) return;
1809 switch (CurrentMode) {
1814 Standard_Integer x0,y0,x1,y1;
1815 curview->GetFrame(x0,y0,x1,y1);
1818 //Standard_Integer qx0,qy0,qx1,qy1;
1819 //curview->viewer->GetFrame(curview->id,qx0,qy0,qx1,qy1);
1820 //if(qx0!=x0 || qx1!=x1 || qy0!=y0 || qy1!=y1) {
1821 // x0=qx0; x1=qx1; y0=qy0; y1=qy1;
1829 if(Trim(PI1,PI2,x0,y0,x1,y1)) {
1830 segm[nbseg].Init((Standard_Integer )( PI1.X() + curview->dX),
1831 (Standard_Integer )(-PI1.Y() - curview->dY),
1832 (Standard_Integer )( PI2.X() + curview->dX),
1833 (Standard_Integer )(-PI2.Y() - curview->dY));
1838 segm[nbseg].Init(( p1.X() + curview->dX),
1839 (-p1.Y() - curview->dY),
1840 ( p2.X() + curview->dX),
1841 (-p2.Y() - curview->dY));
1845 if (nbseg == MAXSEGMENT) {
1849 if (p2.X() > xmax) xmax = p2.X();
1850 if (p2.X() < xmin) xmin = p2.X();
1851 if (p2.Y() > ymax) ymax = p2.Y();
1852 if (p2.Y() < ymin) ymin = p2.Y();
1859 Standard_Integer x1 = (int) p1.X() ;
1860 Standard_Integer y1 = (int) p1.Y() ;
1861 Standard_Integer x2 = (int) p2.X() ;
1862 Standard_Integer y2 = (int) p2.Y() ;
1863 if ((x1 >= xpick + precpick) && (x2 >= xpick + precpick)) break;
1864 if ((x1 <= xpick - precpick) && (x2 <= xpick - precpick)) break;
1865 if ((y1 >= ypick + precpick) && (y2 >= ypick + precpick)) break;
1866 if ((y1 <= ypick - precpick) && (y2 <= ypick - precpick)) break;
1868 Standard_Boolean inside = Standard_True;
1869 if ((x1 > xpick + precpick) || (x2 > xpick + precpick)) {
1870 Standard_Real y = (Standard_Real) y1 +
1871 (Standard_Real) (y2-y1) * (Standard_Real) (xpick+precpick-x1) /
1872 (Standard_Real) (x2 - x1);
1873 if ( (y < ypick+precpick) && (y > ypick - precpick)) {
1874 found = Standard_True;
1875 lastPickParam = (Standard_Real) (xpick - x1) /
1876 (Standard_Real) (x2 - x1);
1880 inside = Standard_False;
1883 if ((x1 < xpick - precpick) || (x2 < xpick - precpick)) {
1884 Standard_Real y = (Standard_Real) y1 +
1885 (Standard_Real) (y2-y1) * (Standard_Real) (xpick-precpick-x1) /
1886 (Standard_Real) (x2 - x1);
1887 if ( (y < ypick+precpick) && (y > ypick - precpick)) {
1888 found = Standard_True;
1889 lastPickParam = (Standard_Real) (xpick - x1) /
1890 (Standard_Real) (x2 - x1);
1894 inside = Standard_False;
1898 if ((y1 > ypick + precpick) || (y2 > ypick + precpick)) {
1899 Standard_Real x = (Standard_Real) x1 +
1900 (Standard_Real) (x2-x1) * (Standard_Real) (ypick+precpick-y1) /
1901 (Standard_Real) (y2 - y1);
1902 if ( (x < xpick+precpick) && (x > xpick - precpick)) {
1903 found = Standard_True;
1904 lastPickParam = (Standard_Real) (ypick - y1) /
1905 (Standard_Real) (y2 - y1);
1909 inside = Standard_False;
1913 if ((y1 < ypick - precpick) || (y2 < ypick - precpick)) {
1914 Standard_Real x = (Standard_Real) x1 +
1915 (Standard_Real) (x2-x1) * (Standard_Real) (ypick-precpick-y1) /
1916 (Standard_Real) (y2 - y1);
1917 if ( (x < xpick+precpick) && (x > xpick - precpick)) {
1918 found = Standard_True;
1919 lastPickParam = (Standard_Real) (ypick - y1) /
1920 (Standard_Real) (y2 - y1);
1924 inside = Standard_False;
1926 found = found || inside;
1928 if (Abs(x2-x1) > Abs(y2-y1)) {
1929 if (Abs(x2-x1) < 1e-5) lastPickParam = 0;
1931 lastPickParam = (Standard_Real)(xpick - x1) /
1932 (Standard_Real)(x2 - x1);
1935 if (Abs(y2-y1) < 1e-5) lastPickParam = 0;
1937 lastPickParam = (Standard_Real)(ypick - y1) /
1938 (Standard_Real)(y2 - y1);
1946 Standard_Integer x = (Standard_Integer )( (p2.X() - ps_vx) * ps_kx + ps_px);
1947 Standard_Integer y = (Standard_Integer )( (p2.Y() - ps_vy) * ps_ky + ps_py);
1948 (*ps_stream) << x << " " << y << " l\n";
1955 //=======================================================================
1958 //=======================================================================
1960 void Draw_Display::MoveTo (const gp_Pnt& pt)
1962 if (Draw_Batch) return;
1963 if (CurrentMode == PICK) {
1964 if (!found) lastPickP1 = pt;
1968 PtPers.Transform(curview->Matrix);
1969 Standard_Real xp = PtPers.X();
1970 Standard_Real yp = PtPers.Y();
1971 if (curview->FlagPers) {
1972 Standard_Real ZPers = PtPers.Z();
1973 if (ZPers < curview->FocalDist*precpers) {
1974 xp=xp*curview->FocalDist/(curview->FocalDist-ZPers);
1975 yp=yp*curview->FocalDist/(curview->FocalDist-ZPers);
1978 MoveTo(gp_Pnt2d(xp,yp));
1981 //=======================================================================
1984 //=======================================================================
1986 void Draw_Display::DrawTo (const gp_Pnt& pt)
1988 if (Draw_Batch) return;
1989 if ((CurrentMode == PICK) && found) return;
1991 gp_Pnt pt2 = pt.Transformed(curview->Matrix);
1992 Standard_Real xp2 = pt2.X();
1993 Standard_Real yp2 = pt2.Y();
1995 if (curview->FlagPers) {
1996 Standard_Real xp1 = PtPers.X();
1997 Standard_Real yp1 = PtPers.Y();
1998 Standard_Real zp1 = PtPers.Z();
1999 Standard_Real zp2 = pt2.Z();
2001 if ((zp1 >= curview->FocalDist*precpers) &&
2002 (zp2 >= curview->FocalDist*precpers) ) {
2003 return; // segment is not visible in perspective (behind the eye)
2005 else if (zp1 >= curview->FocalDist*precpers) {
2006 xp1=xp1+(xp2-xp1)*(curview->FocalDist*precpers-zp1)/(zp2-zp1);
2007 yp1=yp1+(yp2-yp1)*(curview->FocalDist*precpers-zp1)/(zp2-zp1);
2008 zp1=curview->FocalDist*precpers;
2009 xp1=xp1*curview->FocalDist/(curview->FocalDist-zp1);
2010 yp1=yp1*curview->FocalDist/(curview->FocalDist-zp1);
2011 MoveTo(gp_Pnt2d(xp1*curview->Zoom,yp1*curview->Zoom));
2013 else if (zp2 >= curview->FocalDist*precpers) {
2014 xp2=xp2+(xp1-xp2)*(curview->FocalDist*precpers-zp2)/(zp1-zp2);
2015 yp2=yp2+(yp1-yp2)*(curview->FocalDist*precpers-zp2)/(zp1-zp2);
2016 zp2=curview->FocalDist*precpers;
2018 xp2=xp2*curview->FocalDist/(curview->FocalDist-zp2);
2019 yp2=yp2*curview->FocalDist/(curview->FocalDist-zp2);
2021 DrawTo(gp_Pnt2d(xp2,yp2));
2022 if (CurrentMode == PICK) {
2023 if (!found) lastPickP1 = pt;
2024 else lastPickP2 = pt;
2028 //=======================================================================
2031 //=======================================================================
2033 void Draw_Display::Draw (const gp_Pnt& p1, const gp_Pnt& p2)
2035 if (Draw_Batch) return;
2040 //=======================================================================
2043 //=======================================================================
2045 void Draw_Display::Draw(const gp_Pnt2d& p1, const gp_Pnt2d& p2)
2047 if (Draw_Batch) return;
2053 //=======================================================================
2056 //=======================================================================
2058 Standard_Integer Draw_Display::ViewId() const
2060 if (Draw_Batch) return 0;
2065 //=======================================================================
2066 //function : HasPicked
2068 //=======================================================================
2070 Standard_Boolean Draw_Display::HasPicked() const
2072 if (Draw_Batch) return Standard_False;