summaryrefslogtreecommitdiff
path: root/src/TopOpeBRepTool/TopOpeBRepTool_connexity.cxx
blob: c402adf3389d459b80d5111aa76998d26761d021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// File:	TopOpeBRepTool_connexity.cxx
// Created:	Wed Dec  9 14:47:29 1998
// Author:	Xuan PHAM PHU
//		<xpu@poulopox.paris1.matra-dtv.fr>


#include <TopOpeBRepTool_connexity.ixx>
#include <TopOpeBRepTool_define.hxx>
#include <TopOpeBRepTool_TOOL.hxx>

#define M_FORWARD(sta)  (sta == TopAbs_FORWARD)
#define M_REVERSED(sta) (sta == TopAbs_REVERSED)
#define M_INTERNAL(sta) (sta == TopAbs_INTERNAL)
#define M_EXTERNAL(sta) (sta == TopAbs_EXTERNAL)

#define FORWARD  (1)
#define REVERSED (2)
#define INTERNAL (3)
#define EXTERNAL (4)
#define CLOSING  (5)

//=======================================================================
//function : TopOpeBRepTool_connexity
//purpose  : 
//=======================================================================

TopOpeBRepTool_connexity::TopOpeBRepTool_connexity()
: theItems(1,5)
{
}
//=======================================================================
//function : TopOpeBRepTool_connexity
//purpose  : 
//=======================================================================

TopOpeBRepTool_connexity::TopOpeBRepTool_connexity(const TopoDS_Shape& Key)
: theKey(Key), theItems(1,5)
{
}

//=======================================================================
//function : SetKey
//purpose  : 
//=======================================================================

void TopOpeBRepTool_connexity::SetKey(const TopoDS_Shape& Key)
{
  theKey = Key;
}



//=======================================================================
//function : Key
//purpose  : 
//=======================================================================

const TopoDS_Shape& TopOpeBRepTool_connexity::Key() const
{
  return theKey;
}

/*static Standard_Integer FUN_toI(const TopAbs_Orientation& O)
{
  Standard_Integer Index = 0;
  if      (O == TopAbs_FORWARD)  Index = 1;
  else if (O == TopAbs_REVERSED) Index = 2;
  else if (O == TopAbs_INTERNAL) Index = 3;
  else if (O == TopAbs_EXTERNAL) Index = 0;
  return Index;
}*/

//=======================================================================
//function : Item
//purpose  : 
//=======================================================================

Standard_Integer TopOpeBRepTool_connexity::Item(const Standard_Integer OriKey, TopTools_ListOfShape& Item) const
{
  Item.Clear();
  Item = theItems(OriKey);
  return (Item.Extent());
}

//=======================================================================
//function : AllItems
//purpose  : 
//=======================================================================

Standard_Integer TopOpeBRepTool_connexity::AllItems(TopTools_ListOfShape& Item) const
{
  Item.Clear();
  for (Standard_Integer i = 1; i <=4; i++) {
    TopTools_ListOfShape copy; copy.Assign(theItems.Value(i));
    Item.Append(copy);
  }
  return Item.Extent();
}

//=======================================================================
//function : AddItem
//purpose  : 
//=======================================================================

void TopOpeBRepTool_connexity::AddItem(const Standard_Integer OriKey, const TopTools_ListOfShape& Item)
{
  TopTools_ListOfShape copy; copy.Assign(Item);
  theItems(OriKey).Append(copy);
}

void TopOpeBRepTool_connexity::AddItem(const Standard_Integer OriKey, const TopoDS_Shape& Item)
{
  TopTools_ListOfShape copy; copy.Append(Item);
  theItems(OriKey).Append(copy);
}

//=======================================================================
//function : RemoveItem
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_connexity::RemoveItem(const Standard_Integer OriKey, const TopoDS_Shape& Item)
{
  TopTools_ListOfShape& item = theItems.ChangeValue(OriKey);
  TopTools_ListIteratorOfListOfShape it(item);
  while (it.More()) {
    if (it.Value().IsEqual(Item)) {item.Remove(it); return Standard_True;}
    else it.Next();
  }
  return Standard_False;
}

//=======================================================================
//function : RemoveItem
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_connexity::RemoveItem(const TopoDS_Shape& Item)
{
  Standard_Boolean removed = Standard_False;
  for (Standard_Integer i = 1; i<= 5; i++) {
    Standard_Boolean found = RemoveItem(i,Item);
    if (found) removed = Standard_True;
  }
  return removed;
}



//=======================================================================
//function : ChangeItem
//purpose  : 
//=======================================================================

TopTools_ListOfShape& TopOpeBRepTool_connexity::ChangeItem(const Standard_Integer OriKey)
{  
  return theItems.ChangeValue(OriKey);
}

//=======================================================================
//function : IsMultiple
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_connexity::IsMultiple() const
{
  TopTools_ListOfShape lfound; 
  Standard_Integer nkeyitem = Item(FORWARD,lfound);
//  nkeyRitem += Item(INTERNAL,lfound); NOT VALID
  // if key is vertex : key appears F in closing E, only one time
  nkeyitem += Item(CLOSING,lfound); 
  Standard_Boolean multiple = (nkeyitem > 1);
  return multiple;
}

//=======================================================================
//function : IsFaulty
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_connexity::IsFaulty() const
{
  TopTools_ListOfShape lfound; 
  Standard_Integer nkeyRintem = Item(FORWARD,lfound);
  Standard_Integer nkeyFitem  = Item(REVERSED,lfound);
  Standard_Boolean faulty = (nkeyRintem != nkeyFitem);
  return faulty;
}

//=======================================================================
//function : IsInternal
//purpose  : 
//=======================================================================

Standard_Integer TopOpeBRepTool_connexity::IsInternal(TopTools_ListOfShape& Item) const
{
  Item.Clear();

  // all subshapes of INTERNAL(EXTERNAL) are oriented INTERNAL(EXTERNAL)
  TopTools_ListOfShape lINT; lINT.Assign(theItems.Value(INTERNAL));
  TopTools_ListIteratorOfListOfShape it1(lINT);
  while (it1.More()) {
    const TopoDS_Shape& item1 = it1.Value();
    TopAbs_Orientation o1 = item1.Orientation();
    if (!M_INTERNAL(o1)) {it1.Next(); continue;}
    Standard_Integer oKey1 = TopOpeBRepTool_TOOL::OriinSor(theKey,item1.Oriented(TopAbs_FORWARD));
    if (oKey1 != INTERNAL) lINT.Remove(it1);
    else it1.Next();
  }

  TopTools_ListOfShape lEXT; lEXT.Assign(theItems.Value(EXTERNAL));
  TopTools_ListIteratorOfListOfShape it2(lEXT);
  while (it2.More()) {
    const TopoDS_Shape& item2 = it2.Value();
    TopAbs_Orientation o2 = item2.Orientation();
    if (!M_EXTERNAL(o2)) {it2.Next(); continue;}
    Standard_Integer oKey2 = TopOpeBRepTool_TOOL::OriinSor(theKey,item2.Oriented(TopAbs_FORWARD));
    if (oKey2 == INTERNAL) lINT.Append(item2);
    it2.Next();
  }

  Item.Append(lINT);  
  return Item.Extent();
}