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