0030153: Visualization, TKOpenGl - AIS_ColoredShape::SynchronizeAspects() doesn't...
[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
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 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>
7fd59977 25
25e59720 26IMPLEMENT_STANDARD_RTTIEXT(IFSelect_PacketList,Standard_Transient)
92efcf78 27
b311480e 28IFSelect_PacketList::IFSelect_PacketList
7fd59977 29 (const Handle(Interface_InterfaceModel)& model)
30 : thedupls (0,model->NbEntities()) ,
31 thepacks (100) ,
32 theflags (0,model->NbEntities()) ,
33 thename ("Packets")
34{
35 themodel = model; thelast = 0; thebegin = Standard_False; // begin-begin
36 thedupls.Init(0); theflags.Init(0);
37}
38
39 void IFSelect_PacketList::SetName (const Standard_CString name)
40 { thename.Clear(); thename.AssignCat (name); }
41
42 Standard_CString IFSelect_PacketList::Name () const
43 { return thename.ToCString(); }
44
45 Handle(Interface_InterfaceModel) IFSelect_PacketList::Model () const
46 { return themodel; }
47
48 void IFSelect_PacketList::AddPacket ()
49{
50 Standard_Integer nbl = thepacks.NbEntities();
51 Standard_Integer nbe = theflags.Upper();
52 for (Standard_Integer i = 1; i <= nbe; i ++) theflags.SetValue(i,0);
53
54 if (thelast >= nbl) thepacks.SetNbEntities (nbl*2);
55
56 if (!thebegin) thelast ++;
57 thepacks.SetNumber (thelast);
58 thebegin = Standard_False;
59}
60
61
62 void IFSelect_PacketList::Add
63 (const Handle(Standard_Transient)& ent)
64{
65 Standard_Integer num = themodel->Number(ent);
9775fa61 66 if (num == 0) throw Interface_InterfaceError("PacketList:Add, Entity not in Model");
67 if (thelast == 0) throw Interface_InterfaceError("PacketList:Add, no Packet yet added");
7fd59977 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}