0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / Geom2dHatch / Geom2dHatch_Elements.cxx
1 // Created on: 1994-12-16
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1994-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 //  Modified by skv - Fri Jul 14 17:03:47 2006 OCC12627
18
19 #include <Geom2dAdaptor_Curve.hxx>
20 #include <Geom2dHatch_Element.hxx>
21 #include <Geom2dHatch_Elements.hxx>
22 #include <gp.hxx>
23 #include <gp_Lin2d.hxx>
24 #include <gp_Pnt2d.hxx>
25 #include <gp_Vec2d.hxx>
26 #include <Standard_DomainError.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Standard_NoSuchObject.hxx>
29 #include <TColStd_MapIntegerHasher.hxx>
30 #include <TopAbs_Orientation.hxx>
31
32 Geom2dHatch_Elements::Geom2dHatch_Elements(const Geom2dHatch_Elements& )
33 {
34 #ifdef OCCT_DEBUG
35   cout<<" Magic Constructor in Geom2dHatch_Elements:: "<<endl;
36 #endif
37 }
38
39 Geom2dHatch_Elements::Geom2dHatch_Elements()
40 {
41   NumWire = 0;
42   NumEdge = 0;
43   myCurEdge = 1;
44 }
45
46 void Geom2dHatch_Elements::Clear()
47 {
48   myMap.Clear();
49 }
50
51 Standard_Boolean Geom2dHatch_Elements::IsBound(const Standard_Integer K) const
52 {
53   return(myMap.IsBound(K));
54 }
55
56 Standard_Boolean Geom2dHatch_Elements::UnBind(const Standard_Integer K)
57 {
58   return(myMap.UnBind(K));
59 }
60
61 Standard_Boolean Geom2dHatch_Elements::Bind(const Standard_Integer K,const Geom2dHatch_Element& I)
62 {
63   return(myMap.Bind(K,I));
64 }
65
66 const Geom2dHatch_Element& Geom2dHatch_Elements::Find(const Standard_Integer K) const
67 {
68   return(myMap.Find(K));
69 }
70
71 Geom2dHatch_Element& Geom2dHatch_Elements::ChangeFind(const Standard_Integer K)
72 {
73   return(myMap.ChangeFind(K));
74 }
75
76 //=======================================================================
77 //function : CheckPoint
78 //purpose  : 
79 //=======================================================================
80
81 Standard_Boolean  Geom2dHatch_Elements::CheckPoint(gp_Pnt2d&)
82 {
83   return Standard_True;
84 }
85
86 //=======================================================================
87 //function : Reject
88 //purpose  : 
89 //=======================================================================
90
91 Standard_Boolean  Geom2dHatch_Elements::Reject(const gp_Pnt2d&) const  {
92   return Standard_False;
93 }
94
95 //=======================================================================
96 //function : Segment
97 //purpose  : 
98 //=======================================================================
99
100 Standard_Boolean Geom2dHatch_Elements::Segment(const gp_Pnt2d& P, 
101                                                      gp_Lin2d& L, 
102                                                      Standard_Real& Par)
103 {
104   myCurEdge = 1;
105
106   return OtherSegment(P, L, Par);
107 }
108
109 //=======================================================================
110 //function : Segment
111 //purpose  : 
112 //=======================================================================
113
114 Standard_Boolean Geom2dHatch_Elements::OtherSegment(const gp_Pnt2d& P, 
115                                                           gp_Lin2d& L, 
116                                                           Standard_Real& Par)
117 {
118   Geom2dHatch_DataMapIteratorOfMapOfElements Itertemp;
119   Standard_Integer                        i;
120   
121   for(  Itertemp.Initialize(myMap), i = 1; Itertemp.More(); Itertemp.Next(), i++) { 
122     if (i < myCurEdge)
123       continue;
124
125     void *ptrmyMap = (void *)(&myMap);
126     Geom2dHatch_Element& Item=((Geom2dHatch_MapOfElements*)ptrmyMap)->ChangeFind(Itertemp.Key());
127     Geom2dAdaptor_Curve& E = Item.ChangeCurve();
128     TopAbs_Orientation Or= Item.Orientation();
129     gp_Pnt2d P2 = E.Value
130       ((E.FirstParameter() + E.LastParameter()) *0.5);
131     if ((Or == TopAbs_FORWARD) ||
132         (Or == TopAbs_REVERSED)) {
133       gp_Vec2d V(P,P2);
134       Par = V.Magnitude();
135       if (Par >= gp::Resolution()) {
136         L = gp_Lin2d(P,V);
137         myCurEdge++;
138         return Standard_True;
139       }
140     }
141   }
142
143   if (i == myCurEdge + 1) {
144     Par = RealLast();
145     L = gp_Lin2d(P,gp_Dir2d(1,0));
146     myCurEdge++;
147
148     return Standard_True;
149   }
150
151   return Standard_False;
152 }
153
154 //=======================================================================
155 //function : InitWires
156 //purpose  : 
157 //=======================================================================
158
159 void  Geom2dHatch_Elements::InitWires()  {
160   NumWire = 0;
161 }
162
163 //=======================================================================
164 //function : RejectWire NYI
165 //purpose  : 
166 //=======================================================================
167
168 Standard_Boolean Geom2dHatch_Elements::RejectWire(const gp_Lin2d& , 
169                                                    const Standard_Real) const 
170 {
171   return Standard_False;
172 }
173
174 //=======================================================================
175 //function : InitEdges
176 //purpose  : 
177 //=======================================================================
178
179 void  Geom2dHatch_Elements::InitEdges()  {
180   NumEdge = 0;
181   Iter.Initialize(myMap);
182 }
183
184 //=======================================================================
185 //function : RejectEdge NYI
186 //purpose  : 
187 //=======================================================================
188
189 Standard_Boolean Geom2dHatch_Elements::RejectEdge(const gp_Lin2d& , 
190                                                   const Standard_Real ) const 
191 {
192   return Standard_False;
193 }
194
195
196 //=======================================================================
197 //function : CurrentEdge
198 //purpose  : 
199 //=======================================================================
200
201 void  Geom2dHatch_Elements::CurrentEdge(Geom2dAdaptor_Curve& E, 
202                                         TopAbs_Orientation& Or) const 
203 {
204   void *ptrmyMap = (void *)(&myMap);
205   Geom2dHatch_Element& Item=((Geom2dHatch_MapOfElements*)ptrmyMap)->ChangeFind(Iter.Key());
206
207   E = Item.ChangeCurve();
208   Or= Item.Orientation();
209 #if 0 
210   E.Edge() = TopoDS::Edge(myEExplorer.Current());
211   E.Face() = myFace;
212   Or = E.Edge().Orientation();
213 #endif
214 }
215
216
217 //=======================================================================
218 //function : MoreWires
219 //purpose  : 
220 //=======================================================================
221
222 Standard_Boolean  Geom2dHatch_Elements::MoreWires() const 
223 {
224   return (NumWire == 0);
225 }
226
227 //=======================================================================
228 //function : NextWire
229 //purpose  : 
230 //=======================================================================
231
232 void Geom2dHatch_Elements::NextWire()  {
233   NumWire++;
234 }
235
236 //=======================================================================
237 //function : MoreEdges
238 //purpose  : 
239 //=======================================================================
240
241 Standard_Boolean  Geom2dHatch_Elements::MoreEdges() const  {
242   return(Iter.More());
243 }
244
245 //=======================================================================
246 //function : NextEdge
247 //purpose  : 
248 //=======================================================================
249
250 void Geom2dHatch_Elements::NextEdge()  {
251   Iter.Next();
252 }
253
254
255