0024947: Redesign OCCT legacy type system -- final corrections
[occt.git] / src / IFSelect / IFSelect_PacketList.cxx
1 // Created on: 1994-09-02
2 // Created by: Christian CAILLET
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 #include <IFSelect_PacketList.ixx>
18 #include <TColStd_HSequenceOfInteger.hxx>
19 #include <Interface_InterfaceError.hxx>
20
21
22
23 IFSelect_PacketList::IFSelect_PacketList
24   (const Handle(Interface_InterfaceModel)& model)
25     : thedupls (0,model->NbEntities()) , 
26       thepacks (100) ,
27       theflags (0,model->NbEntities()) ,
28       thename  ("Packets")
29 {
30   themodel = model;  thelast = 0;  thebegin = Standard_False;  // begin-begin
31   thedupls.Init(0);  theflags.Init(0);
32 }
33
34     void  IFSelect_PacketList::SetName (const Standard_CString name)
35       {  thename.Clear();  thename.AssignCat (name);  }
36
37     Standard_CString  IFSelect_PacketList::Name () const
38       {  return thename.ToCString();  }
39
40     Handle(Interface_InterfaceModel)  IFSelect_PacketList::Model () const
41       {  return themodel;  }
42
43     void  IFSelect_PacketList::AddPacket ()
44 {
45   Standard_Integer nbl = thepacks.NbEntities();
46   Standard_Integer nbe = theflags.Upper();
47   for (Standard_Integer i = 1; i <= nbe; i ++) theflags.SetValue(i,0);
48
49   if (thelast >= nbl) thepacks.SetNbEntities (nbl*2);
50
51   if (!thebegin) thelast ++;
52   thepacks.SetNumber (thelast);
53   thebegin = Standard_False;
54 }
55
56
57     void  IFSelect_PacketList::Add
58   (const Handle(Standard_Transient)& ent)
59 {
60   Standard_Integer num = themodel->Number(ent);
61   if (num == 0) Interface_InterfaceError::Raise
62     ("PacketList:Add, Entity not in Model");
63   if (thelast == 0) Interface_InterfaceError::Raise
64     ("PacketList:Add, no Packet yet added");
65   if (theflags(num) != 0) return;
66   theflags(num) = 1;
67   thedupls(num) ++;
68   thepacks.Add(num);
69   thebegin = Standard_False;
70 }
71
72     void  IFSelect_PacketList::AddList
73   (const Handle(TColStd_HSequenceOfTransient)& list)
74 {
75   if (list.IsNull()) return;
76   Standard_Integer i , nb = list->Length();
77   thepacks.Reservate (nb+1);
78   for (i = 1; i <= nb; i ++) Add (list->Value(i));
79 }
80
81
82     Standard_Integer  IFSelect_PacketList::NbPackets () const
83       {  return (thebegin ? thelast-1 : thelast);  }
84
85     Standard_Integer  IFSelect_PacketList::NbEntities
86   (const Standard_Integer numpack) const
87 {
88   if (numpack <= 0 || numpack > NbPackets()) return 0;
89   Interface_IntList lisi(thepacks,Standard_False);  lisi.SetNumber (numpack);
90   return lisi.Length();
91 }
92
93     Interface_EntityIterator  IFSelect_PacketList::Entities
94   (const Standard_Integer numpack) const
95 {
96   Interface_EntityIterator list;
97   if (numpack <= 0 || numpack > NbPackets()) return list;
98   Interface_IntList lisi(thepacks,Standard_False);  lisi.SetNumber (numpack);
99   Standard_Integer i , nb = lisi.Length();
100   for (i = 1; i <= nb; i ++)
101     list.AddItem(themodel->Value(lisi.Value(i)));
102   return list;
103 }
104
105     Standard_Integer  IFSelect_PacketList::HighestDuplicationCount () const
106 {
107   Standard_Integer i , nb = themodel->NbEntities();
108   Standard_Integer high = 0;
109   for (i = 1; i <= nb; i ++) {
110     Standard_Integer j = thedupls.Value(i);
111     if (j > high) high = j;
112   }
113   return high;
114 }
115
116     Standard_Integer  IFSelect_PacketList::NbDuplicated
117   (const Standard_Integer newcount, const Standard_Boolean andmore) const
118 {
119   Standard_Integer i, nb = themodel->NbEntities();
120   Standard_Integer nbdu = 0;
121
122   for (i = 1; i <= nb; i ++) {
123     Standard_Integer j = thedupls.Value(i);
124     if (j == newcount || (j > newcount && andmore)) nbdu ++;
125   }
126   return nbdu;
127 }
128
129     Interface_EntityIterator  IFSelect_PacketList::Duplicated
130   (const Standard_Integer newcount, const Standard_Boolean andmore) const
131 {
132   Standard_Integer nb = themodel->NbEntities();
133   Interface_EntityIterator list;
134
135   Standard_Integer i;
136   for (i = 1; i <= nb; i ++) {
137     Standard_Integer j = thedupls.Value(i);
138     if (j == newcount || (j > newcount && andmore)) list.AddItem(themodel->Value(i));
139   }
140   return list;
141 }