0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / Select3D / Select3D_SensitivePoly.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <Select3D_SensitivePoly.ixx>
19 #include <gp_Pnt2d.hxx>
20 #include <gp_Pnt.hxx>
21 #include <Select3D_Pnt.hxx>
22 #include <Select3D_Pnt2d.hxx>
23 #include <Select3D_Box2d.hxx>
24 #include <TopLoc_Location.hxx>
25
26
27 //==================================================
28 // Function: faire disparaitre ce constructeur a la prochaine version...
29 // Purpose : simplement garde pour ne pas perturber la version update
30 //==================================================
31
32 Select3D_SensitivePoly::
33 Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
34                        const TColgp_Array1OfPnt& ThePoints):
35 Select3D_SensitiveEntity(OwnerId),
36 mypolyg(ThePoints.Upper()-ThePoints.Lower()+1)
37 {
38   for (Standard_Integer theIndex = 0 ; theIndex < mypolyg.Size(); ++theIndex)
39     mypolyg.SetPnt(theIndex, ThePoints.Value(ThePoints.Lower()+theIndex));
40 }
41
42 //==================================================
43 // Function: Creation
44 // Purpose :
45 //==================================================
46
47 Select3D_SensitivePoly::
48 Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
49                        const Handle(TColgp_HArray1OfPnt)& ThePoints):
50 Select3D_SensitiveEntity(OwnerId),
51 mypolyg(ThePoints->Upper()-ThePoints->Lower()+1)
52 {
53   for (Standard_Integer theIndex = 0; theIndex < mypolyg.Size(); theIndex++)
54     mypolyg.SetPnt(theIndex, ThePoints->Value(ThePoints->Lower()+theIndex));
55 }
56
57 //==================================================
58 // Function: Creation
59 // Purpose :
60 //==================================================
61
62 Select3D_SensitivePoly::
63 Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId, 
64                        const Standard_Integer NbPoints):
65 Select3D_SensitiveEntity(OwnerId),
66 mypolyg(NbPoints)
67 {
68 }
69
70 //==================================================
71 // Function: Project
72 // Purpose :
73 //==================================================
74
75 void Select3D_SensitivePoly::Project(const Handle(Select3D_Projector)& aProj)
76 {
77   mybox2d.SetVoid();
78
79   Standard_Boolean hasloc = HasLocation();
80   gp_Pnt2d aPnt2d;
81   gp_Pnt aPnt;
82   for (Standard_Integer theIndex = 0; theIndex < mypolyg.Size(); ++theIndex)
83   {
84     aPnt = mypolyg.Pnt(theIndex);
85     if (hasloc)
86     {
87       aProj->Project(aPnt.Transformed(Location().Transformation()), aPnt2d);
88     }
89     else
90     {
91       aProj->Project(aPnt, aPnt2d);
92     }
93     mybox2d.Update(aPnt2d);
94     mypolyg.SetPnt2d(theIndex, aPnt2d);
95   }
96 }
97
98 //==================================================
99 // Function: Areas
100 // Purpose :
101 //==================================================
102 void Select3D_SensitivePoly
103 ::Areas(SelectBasics_ListOfBox2d& aSeq)
104 {
105   aSeq.Append(mybox2d);
106 }
107