0024276: Memory leak due to a static variable
[occt.git] / src / Visual3d / Visual3d_PickDescriptor.cxx
1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21
22
23 //-Version      
24
25 //-Design       Declaration of variables specific to the class
26 //              describing marking.
27
28 //-Warning      A return of marking is defined by :
29 //              - sequence of (Elem_Num, Pick_Id, Structure)
30 //              - depth
31
32 //-References   
33
34 //-Language     C++ 2.0
35
36 //-Declarations
37
38 // for the class
39 #include <Visual3d_PickDescriptor.ixx>
40
41 //-Aliases
42
43 //-Global data definitions
44
45 //      -- sequence reperee
46 //      MyPickPathSequence      :       HSequenceOfPickPath;
47
48 //      -- contexte picking de reperage associe
49 //      MyContext               :       ContextPick;
50
51 //-Constructors
52
53 //-Destructors
54
55 //-Methods, in order
56
57 Visual3d_PickDescriptor::Visual3d_PickDescriptor (const Visual3d_ContextPick& CTXP):
58 MyContext (CTXP) {
59
60         MyPickPathSequence      = new Visual3d_HSequenceOfPickPath ();
61
62 }
63
64 void Visual3d_PickDescriptor::AddPickPath (const Visual3d_PickPath& APickPath) {
65
66         if (MyContext.Depth () > MyPickPathSequence->Length ())
67                 MyPickPathSequence->Append (APickPath);
68
69 }
70
71 void Visual3d_PickDescriptor::Clear () {
72
73         MyPickPathSequence->Clear ();
74
75 }
76
77 Standard_Integer Visual3d_PickDescriptor::Depth () const {
78
79         return (MyPickPathSequence->Length ());
80
81 }
82
83 Handle(Graphic3d_Structure) Visual3d_PickDescriptor::TopStructure () const {
84
85 Visual3d_PickPath Result;
86
87         if (MyPickPathSequence->IsEmpty ())
88                 Visual3d_PickError::Raise ("PickDescriptor empty");
89
90         switch (MyContext.Order ()) {
91
92                 case Visual3d_TOO_TOPFIRST :
93                         // MyPickPathSequence->First returns the first
94                         // PickPath found in the sequence.
95                         Result  = MyPickPathSequence->Sequence().First ();
96                 break;
97
98                 case Visual3d_TOO_BOTTOMFIRST :
99                         // MyPickPathSequence->Last returns the last
100                         // PickPath found in the sequence.
101                         Result  = MyPickPathSequence->Sequence().Last ();
102                 break;
103
104         }
105         return (Result.StructIdentifier ());
106 }
107
108 Standard_Integer Visual3d_PickDescriptor::TopPickId () const {
109
110 Visual3d_PickPath Result;
111
112         if (MyPickPathSequence->IsEmpty ())
113                 Visual3d_PickError::Raise ("PickDescriptor empty");
114
115         switch (MyContext.Order ()) {
116
117                 case Visual3d_TOO_TOPFIRST :
118                         // MyPickPathSequence->First returns the first
119                         // PickPath found in the sequence.
120                         Result  = MyPickPathSequence->Sequence().First ();
121                 break;
122
123                 case Visual3d_TOO_BOTTOMFIRST :
124                         // MyPickPathSequence->Last returns the last
125                         // PickPath found in the sequence.
126                         Result  = MyPickPathSequence->Sequence().Last ();
127                 break;
128
129         }
130         return (Result.PickIdentifier ());
131 }
132
133 Standard_Integer Visual3d_PickDescriptor::TopElementNumber () const {
134
135 Visual3d_PickPath Result;
136
137         if (MyPickPathSequence->IsEmpty ())
138                 Visual3d_PickError::Raise ("PickDescriptor empty");
139
140         switch (MyContext.Order ()) {
141
142                 case Visual3d_TOO_TOPFIRST :
143                         // MyPickPathSequence->First returns the first
144                         // PickPath found in the sequence.
145                         Result  = MyPickPathSequence->Sequence().First ();
146                 break;
147
148                 case Visual3d_TOO_BOTTOMFIRST :
149                         // MyPickPathSequence->Last returns the last
150                         // PickPath found in the sequence.
151                         Result  = MyPickPathSequence->Sequence().Last ();
152                 break;
153
154         }
155         return (Result.ElementNumber ());
156 }
157
158 Handle(Visual3d_HSequenceOfPickPath) Visual3d_PickDescriptor::PickPath () const {
159
160         return (Handle(Visual3d_HSequenceOfPickPath)::DownCast
161                                         (MyPickPathSequence->ShallowCopy ()));
162
163 }