1 // Created on: 1998-12-09
2 // Created by: Xuan PHAM PHU
3 // Copyright (c) 1998-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 <TopoDS_Shape.hxx>
19 #include <TopOpeBRepTool_connexity.hxx>
20 #include <TopOpeBRepTool_define.hxx>
21 #include <TopOpeBRepTool_TOOL.hxx>
22
23 #define M_FORWARD(sta) (sta == TopAbs_FORWARD)
24 #define M_REVERSED(sta) (sta == TopAbs_REVERSED)
25 #define M_INTERNAL(sta) (sta == TopAbs_INTERNAL)
26 #define M_EXTERNAL(sta) (sta == TopAbs_EXTERNAL)
27
28 #define FORWARD (1)
29 #define REVERSED (2)
30 #define INTERNAL (3)
31 #define EXTERNAL (4)
32 #define CLOSING (5)
33
34 //=======================================================================
35 //function : TopOpeBRepTool_connexity
36 //purpose :
37 //=======================================================================
38
TopOpeBRepTool_connexity()39 TopOpeBRepTool_connexity::TopOpeBRepTool_connexity()
40 : theItems(1,5)
41 {
42 }
43 //=======================================================================
44 //function : TopOpeBRepTool_connexity
45 //purpose :
46 //=======================================================================
47
TopOpeBRepTool_connexity(const TopoDS_Shape & Key)48 TopOpeBRepTool_connexity::TopOpeBRepTool_connexity(const TopoDS_Shape& Key)
49 : theKey(Key), theItems(1,5)
50 {
51 }
52
53 //=======================================================================
54 //function : SetKey
55 //purpose :
56 //=======================================================================
57
SetKey(const TopoDS_Shape & Key)58 void TopOpeBRepTool_connexity::SetKey(const TopoDS_Shape& Key)
59 {
60 theKey = Key;
61 }
62
63
64
65 //=======================================================================
66 //function : Key
67 //purpose :
68 //=======================================================================
69
Key() const70 const TopoDS_Shape& TopOpeBRepTool_connexity::Key() const
71 {
72 return theKey;
73 }
74
75 /*static Standard_Integer FUN_toI(const TopAbs_Orientation& O)
76 {
77 Standard_Integer Index = 0;
78 if (O == TopAbs_FORWARD) Index = 1;
79 else if (O == TopAbs_REVERSED) Index = 2;
80 else if (O == TopAbs_INTERNAL) Index = 3;
81 else if (O == TopAbs_EXTERNAL) Index = 0;
82 return Index;
83 }*/
84
85 //=======================================================================
86 //function : Item
87 //purpose :
88 //=======================================================================
89
Item(const Standard_Integer OriKey,TopTools_ListOfShape & Item) const90 Standard_Integer TopOpeBRepTool_connexity::Item(const Standard_Integer OriKey, TopTools_ListOfShape& Item) const
91 {
92 Item.Clear();
93 Item = theItems(OriKey);
94 return (Item.Extent());
95 }
96
97 //=======================================================================
98 //function : AllItems
99 //purpose :
100 //=======================================================================
101
AllItems(TopTools_ListOfShape & Item) const102 Standard_Integer TopOpeBRepTool_connexity::AllItems(TopTools_ListOfShape& Item) const
103 {
104 Item.Clear();
105 for (Standard_Integer i = 1; i <=4; i++) {
106 TopTools_ListOfShape copy; copy.Assign(theItems.Value(i));
107 Item.Append(copy);
108 }
109 return Item.Extent();
110 }
111
112 //=======================================================================
113 //function : AddItem
114 //purpose :
115 //=======================================================================
116
AddItem(const Standard_Integer OriKey,const TopTools_ListOfShape & Item)117 void TopOpeBRepTool_connexity::AddItem(const Standard_Integer OriKey, const TopTools_ListOfShape& Item)
118 {
119 TopTools_ListOfShape copy; copy.Assign(Item);
120 theItems(OriKey).Append(copy);
121 }
122
AddItem(const Standard_Integer OriKey,const TopoDS_Shape & Item)123 void TopOpeBRepTool_connexity::AddItem(const Standard_Integer OriKey, const TopoDS_Shape& Item)
124 {
125 TopTools_ListOfShape copy; copy.Append(Item);
126 theItems(OriKey).Append(copy);
127 }
128
129 //=======================================================================
130 //function : RemoveItem
131 //purpose :
132 //=======================================================================
133
RemoveItem(const Standard_Integer OriKey,const TopoDS_Shape & Item)134 Standard_Boolean TopOpeBRepTool_connexity::RemoveItem(const Standard_Integer OriKey, const TopoDS_Shape& Item)
135 {
136 TopTools_ListOfShape& item = theItems.ChangeValue(OriKey);
137 TopTools_ListIteratorOfListOfShape it(item);
138 while (it.More()) {
139 if (it.Value().IsEqual(Item)) {item.Remove(it); return Standard_True;}
140 else it.Next();
141 }
142 return Standard_False;
143 }
144
145 //=======================================================================
146 //function : RemoveItem
147 //purpose :
148 //=======================================================================
149
RemoveItem(const TopoDS_Shape & Item)150 Standard_Boolean TopOpeBRepTool_connexity::RemoveItem(const TopoDS_Shape& Item)
151 {
152 Standard_Boolean removed = Standard_False;
153 for (Standard_Integer i = 1; i<= 5; i++) {
154 Standard_Boolean found = RemoveItem(i,Item);
155 if (found) removed = Standard_True;
156 }
157 return removed;
158 }
159
160
161
162 //=======================================================================
163 //function : ChangeItem
164 //purpose :
165 //=======================================================================
166
ChangeItem(const Standard_Integer OriKey)167 TopTools_ListOfShape& TopOpeBRepTool_connexity::ChangeItem(const Standard_Integer OriKey)
168 {
169 return theItems.ChangeValue(OriKey);
170 }
171
172 //=======================================================================
173 //function : IsMultiple
174 //purpose :
175 //=======================================================================
176
IsMultiple() const177 Standard_Boolean TopOpeBRepTool_connexity::IsMultiple() const
178 {
179 TopTools_ListOfShape lfound;
180 Standard_Integer nkeyitem = Item(FORWARD,lfound);
181 // nkeyRitem += Item(INTERNAL,lfound); NOT VALID
182 // if key is vertex : key appears F in closing E, only one time
183 nkeyitem += Item(CLOSING,lfound);
184 Standard_Boolean multiple = (nkeyitem > 1);
185 return multiple;
186 }
187
188 //=======================================================================
189 //function : IsFaulty
190 //purpose :
191 //=======================================================================
192
IsFaulty() const193 Standard_Boolean TopOpeBRepTool_connexity::IsFaulty() const
194 {
195 TopTools_ListOfShape lfound;
196 Standard_Integer nkeyRintem = Item(FORWARD,lfound);
197 Standard_Integer nkeyFitem = Item(REVERSED,lfound);
198 Standard_Boolean faulty = (nkeyRintem != nkeyFitem);
199 return faulty;
200 }
201
202 //=======================================================================
203 //function : IsInternal
204 //purpose :
205 //=======================================================================
206
IsInternal(TopTools_ListOfShape & Item) const207 Standard_Integer TopOpeBRepTool_connexity::IsInternal(TopTools_ListOfShape& Item) const
208 {
209 Item.Clear();
210
211 // all subshapes of INTERNAL(EXTERNAL) are oriented INTERNAL(EXTERNAL)
212 TopTools_ListOfShape lINT; lINT.Assign(theItems.Value(INTERNAL));
213 TopTools_ListIteratorOfListOfShape it1(lINT);
214 while (it1.More()) {
215 const TopoDS_Shape& item1 = it1.Value();
216 TopAbs_Orientation o1 = item1.Orientation();
217 if (!M_INTERNAL(o1)) {it1.Next(); continue;}
218 Standard_Integer oKey1 = TopOpeBRepTool_TOOL::OriinSor(theKey,item1.Oriented(TopAbs_FORWARD));
219 if (oKey1 != INTERNAL) lINT.Remove(it1);
220 else it1.Next();
221 }
222
223 TopTools_ListOfShape lEXT; lEXT.Assign(theItems.Value(EXTERNAL));
224 TopTools_ListIteratorOfListOfShape it2(lEXT);
225 while (it2.More()) {
226 const TopoDS_Shape& item2 = it2.Value();
227 TopAbs_Orientation o2 = item2.Orientation();
228 if (!M_EXTERNAL(o2)) {it2.Next(); continue;}
229 Standard_Integer oKey2 = TopOpeBRepTool_TOOL::OriinSor(theKey,item2.Oriented(TopAbs_FORWARD));
230 if (oKey2 == INTERNAL) lINT.Append(item2);
231 it2.Next();
232 }
233
234 Item.Append(lINT);
235 return Item.Extent();
236 }
237
238
239
240