0024157: Parallelization of assembly part of BO
[occt.git] / src / IFSelect / IFSelect_PacketList.cxx
CommitLineData
b311480e 1// Created on: 1994-09-02
2// Created by: Christian CAILLET
3// Copyright (c) 1994-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <IFSelect_PacketList.ixx>
24#include <TColStd_HSequenceOfInteger.hxx>
25#include <Interface_InterfaceError.hxx>
26
27
28
b311480e 29IFSelect_PacketList::IFSelect_PacketList
7fd59977 30 (const Handle(Interface_InterfaceModel)& model)
31 : thedupls (0,model->NbEntities()) ,
32 thepacks (100) ,
33 theflags (0,model->NbEntities()) ,
34 thename ("Packets")
35{
36 themodel = model; thelast = 0; thebegin = Standard_False; // begin-begin
37 thedupls.Init(0); theflags.Init(0);
38}
39
40 void IFSelect_PacketList::SetName (const Standard_CString name)
41 { thename.Clear(); thename.AssignCat (name); }
42
43 Standard_CString IFSelect_PacketList::Name () const
44 { return thename.ToCString(); }
45
46 Handle(Interface_InterfaceModel) IFSelect_PacketList::Model () const
47 { return themodel; }
48
49 void IFSelect_PacketList::AddPacket ()
50{
51 Standard_Integer nbl = thepacks.NbEntities();
52 Standard_Integer nbe = theflags.Upper();
53 for (Standard_Integer i = 1; i <= nbe; i ++) theflags.SetValue(i,0);
54
55 if (thelast >= nbl) thepacks.SetNbEntities (nbl*2);
56
57 if (!thebegin) thelast ++;
58 thepacks.SetNumber (thelast);
59 thebegin = Standard_False;
60}
61
62
63 void IFSelect_PacketList::Add
64 (const Handle(Standard_Transient)& ent)
65{
66 Standard_Integer num = themodel->Number(ent);
67 if (num == 0) Interface_InterfaceError::Raise
68 ("PacketList:Add, Entity not in Model");
69 if (thelast == 0) Interface_InterfaceError::Raise
70 ("PacketList:Add, no Packet yet added");
71 if (theflags(num) != 0) return;
72 theflags(num) = 1;
73 thedupls(num) ++;
74 thepacks.Add(num);
75 thebegin = Standard_False;
76}
77
78 void IFSelect_PacketList::AddList
79 (const Handle(TColStd_HSequenceOfTransient)& list)
80{
81 if (list.IsNull()) return;
82 Standard_Integer i , nb = list->Length();
83 thepacks.Reservate (nb+1);
84 for (i = 1; i <= nb; i ++) Add (list->Value(i));
85}
86
87
88 Standard_Integer IFSelect_PacketList::NbPackets () const
89 { return (thebegin ? thelast-1 : thelast); }
90
91 Standard_Integer IFSelect_PacketList::NbEntities
92 (const Standard_Integer numpack) const
93{
94 if (numpack <= 0 || numpack > NbPackets()) return 0;
95 Interface_IntList lisi(thepacks,Standard_False); lisi.SetNumber (numpack);
96 return lisi.Length();
97}
98
99 Interface_EntityIterator IFSelect_PacketList::Entities
100 (const Standard_Integer numpack) const
101{
102 Interface_EntityIterator list;
103 if (numpack <= 0 || numpack > NbPackets()) return list;
104 Interface_IntList lisi(thepacks,Standard_False); lisi.SetNumber (numpack);
105 Standard_Integer i , nb = lisi.Length();
106 for (i = 1; i <= nb; i ++)
107 list.AddItem(themodel->Value(lisi.Value(i)));
108 return list;
109}
110
111 Standard_Integer IFSelect_PacketList::HighestDuplicationCount () const
112{
113 Standard_Integer i , nb = themodel->NbEntities();
114 Standard_Integer high = 0;
115 for (i = 1; i <= nb; i ++) {
116 Standard_Integer j = thedupls.Value(i);
117 if (j > high) high = j;
118 }
119 return high;
120}
121
122 Standard_Integer IFSelect_PacketList::NbDuplicated
123 (const Standard_Integer newcount, const Standard_Boolean andmore) const
124{
125 Standard_Integer i, nb = themodel->NbEntities();
126 Standard_Integer nbdu = 0;
127
128 for (i = 1; i <= nb; i ++) {
129 Standard_Integer j = thedupls.Value(i);
130 if (j == newcount || (j > newcount && andmore)) nbdu ++;
131 }
132 return nbdu;
133}
134
135 Interface_EntityIterator IFSelect_PacketList::Duplicated
136 (const Standard_Integer newcount, const Standard_Boolean andmore) const
137{
138 Standard_Integer nb = themodel->NbEntities();
139 Interface_EntityIterator list;
140
141 Standard_Integer i;
142 for (i = 1; i <= nb; i ++) {
143 Standard_Integer j = thedupls.Value(i);
144 if (j == newcount || (j > newcount && andmore)) list.AddItem(themodel->Value(i));
145 }
146 return list;
147}