0024002: Overall code and build procedure refactoring -- automatic
[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 : Reject
78 //purpose  : 
79 //=======================================================================
80
81 Standard_Boolean  Geom2dHatch_Elements::Reject(const gp_Pnt2d&) const  {
82   return Standard_False;
83 }
84
85 //=======================================================================
86 //function : Segment
87 //purpose  : 
88 //=======================================================================
89
90 Standard_Boolean Geom2dHatch_Elements::Segment(const gp_Pnt2d& P, 
91                                                      gp_Lin2d& L, 
92                                                      Standard_Real& Par)
93 {
94   myCurEdge = 1;
95
96   return OtherSegment(P, L, Par);
97 }
98
99 //=======================================================================
100 //function : Segment
101 //purpose  : 
102 //=======================================================================
103
104 Standard_Boolean Geom2dHatch_Elements::OtherSegment(const gp_Pnt2d& P, 
105                                                           gp_Lin2d& L, 
106                                                           Standard_Real& Par)
107 {
108   Geom2dHatch_DataMapIteratorOfMapOfElements Itertemp;
109   Standard_Integer                        i;
110   
111   for(  Itertemp.Initialize(myMap), i = 1; Itertemp.More(); Itertemp.Next(), i++) { 
112     if (i < myCurEdge)
113       continue;
114
115     void *ptrmyMap = (void *)(&myMap);
116     Geom2dHatch_Element& Item=((Geom2dHatch_MapOfElements*)ptrmyMap)->ChangeFind(Itertemp.Key());
117     Geom2dAdaptor_Curve& E = Item.ChangeCurve();
118     TopAbs_Orientation Or= Item.Orientation();
119     gp_Pnt2d P2 = E.Value
120       ((E.FirstParameter() + E.LastParameter()) *0.5);
121     if ((Or == TopAbs_FORWARD) ||
122         (Or == TopAbs_REVERSED)) {
123       gp_Vec2d V(P,P2);
124       Par = V.Magnitude();
125       if (Par >= gp::Resolution()) {
126         L = gp_Lin2d(P,V);
127         myCurEdge++;
128         return Standard_True;
129       }
130     }
131   }
132
133   if (i == myCurEdge + 1) {
134     Par = RealLast();
135     L = gp_Lin2d(P,gp_Dir2d(1,0));
136     myCurEdge++;
137
138     return Standard_True;
139   }
140
141   return Standard_False;
142 }
143
144 //=======================================================================
145 //function : InitWires
146 //purpose  : 
147 //=======================================================================
148
149 void  Geom2dHatch_Elements::InitWires()  {
150   NumWire = 0;
151 }
152
153 //=======================================================================
154 //function : RejectWire NYI
155 //purpose  : 
156 //=======================================================================
157
158 Standard_Boolean Geom2dHatch_Elements::RejectWire(const gp_Lin2d& , 
159                                                    const Standard_Real) const 
160 {
161   return Standard_False;
162 }
163
164 //=======================================================================
165 //function : InitEdges
166 //purpose  : 
167 //=======================================================================
168
169 void  Geom2dHatch_Elements::InitEdges()  {
170   NumEdge = 0;
171   Iter.Initialize(myMap);
172 }
173
174 //=======================================================================
175 //function : RejectEdge NYI
176 //purpose  : 
177 //=======================================================================
178
179 Standard_Boolean Geom2dHatch_Elements::RejectEdge(const gp_Lin2d& , 
180                                                   const Standard_Real ) const 
181 {
182   return Standard_False;
183 }
184
185
186 //=======================================================================
187 //function : CurrentEdge
188 //purpose  : 
189 //=======================================================================
190
191 void  Geom2dHatch_Elements::CurrentEdge(Geom2dAdaptor_Curve& E, 
192                                         TopAbs_Orientation& Or) const 
193 {
194   void *ptrmyMap = (void *)(&myMap);
195   Geom2dHatch_Element& Item=((Geom2dHatch_MapOfElements*)ptrmyMap)->ChangeFind(Iter.Key());
196
197   E = Item.ChangeCurve();
198   Or= Item.Orientation();
199 #if 0 
200   E.Edge() = TopoDS::Edge(myEExplorer.Current());
201   E.Face() = myFace;
202   Or = E.Edge().Orientation();
203 #endif
204 }
205
206
207 //=======================================================================
208 //function : MoreWires
209 //purpose  : 
210 //=======================================================================
211
212 Standard_Boolean  Geom2dHatch_Elements::MoreWires() const 
213 {
214   return (NumWire == 0);
215 }
216
217 //=======================================================================
218 //function : NextWire
219 //purpose  : 
220 //=======================================================================
221
222 void Geom2dHatch_Elements::NextWire()  {
223   NumWire++;
224 }
225
226 //=======================================================================
227 //function : MoreEdges
228 //purpose  : 
229 //=======================================================================
230
231 Standard_Boolean  Geom2dHatch_Elements::MoreEdges() const  {
232   return(Iter.More());
233 }
234
235 //=======================================================================
236 //function : NextEdge
237 //purpose  : 
238 //=======================================================================
239
240 void Geom2dHatch_Elements::NextEdge()  {
241   Iter.Next();
242 }
243
244
245