0031425: Visualization - free Edge has selection sensitivity inconsistent to presentation
[occt.git] / src / StdPrs / StdPrs_WFPoleSurface.cxx
1 // Created on: 1995-07-24
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Adaptor3d_Surface.hxx>
19 #include <Geom_BezierSurface.hxx>
20 #include <Geom_BSplineSurface.hxx>
21 #include <Graphic3d_ArrayOfPolylines.hxx>
22 #include <Graphic3d_Group.hxx>
23 #include <Prs3d_IsoAspect.hxx>
24 #include <Prs3d_Presentation.hxx>
25 #include <StdPrs_WFPoleSurface.hxx>
26 #include <TColgp_Array2OfPnt.hxx>
27
28 static void AddPoles(const Handle (Prs3d_Presentation)& aPresentation,
29                      const TColgp_Array2OfPnt&          A,
30                      const Handle (Prs3d_Drawer)&       aDrawer)
31 {
32   Standard_Integer i,j;
33   const Standard_Integer n = A.ColLength();
34   const Standard_Integer m = A.RowLength();
35
36   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(aDrawer->UIsoAspect()->Aspect());    
37   Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(n*m,n);
38   for (i=1; i<=n; i++){
39     aPrims->AddBound(m);
40     for (j=1; j<=m; j++)
41       aPrims->AddVertex(A(i,j));
42   }
43   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
44
45   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(aDrawer->VIsoAspect()->Aspect());    
46   aPrims = new Graphic3d_ArrayOfPolylines(n*m,m);
47   for (j=1; j<=m; j++){
48     aPrims->AddBound(n);
49     for (i=1; i<=n; i++)
50       aPrims->AddVertex(A(i,j));
51   }
52   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
53 }
54
55
56 //=======================================================================
57 //function : Add
58 //purpose  : 
59 //=======================================================================
60
61 void StdPrs_WFPoleSurface::Add (const Handle (Prs3d_Presentation)& aPresentation,
62                                 const Adaptor3d_Surface&             aSurface,
63                                 const Handle (Prs3d_Drawer)&       aDrawer)
64 {
65
66   GeomAbs_SurfaceType SType = aSurface.GetType();
67   if (SType == GeomAbs_BezierSurface || SType == GeomAbs_BSplineSurface) {
68     Standard_Integer n , m;
69     if (SType == GeomAbs_BezierSurface) {
70       Handle(Geom_BezierSurface) B = aSurface.Bezier();
71       n = aSurface.NbUPoles();
72       m = aSurface.NbVPoles();
73       TColgp_Array2OfPnt A(1,n,1,m);
74       (aSurface.Bezier())->Poles(A);
75       AddPoles(aPresentation, A, aDrawer);
76     }
77     else if (SType == GeomAbs_BSplineSurface) {
78       Handle(Geom_BSplineSurface) B = aSurface.BSpline();
79       n = (aSurface.BSpline())->NbUPoles();
80       m = (aSurface.BSpline())->NbVPoles();
81       TColgp_Array2OfPnt A(1,n,1,m);
82       (aSurface.BSpline())->Poles(A);
83       AddPoles(aPresentation, A, aDrawer);
84     }
85
86   }
87 }
88