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