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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
26 IFSelect_PacketList::IFSelect_PacketList
27 (const Handle(Interface_InterfaceModel)& model)
28 : thedupls (0,model->NbEntities()) ,
30 theflags (0,model->NbEntities()) ,
33 themodel = model; thelast = 0; thebegin = Standard_False; // begin-begin
34 thedupls.Init(0); theflags.Init(0);
37 void IFSelect_PacketList::SetName (const Standard_CString name)
38 { thename.Clear(); thename.AssignCat (name); }
40 Standard_CString IFSelect_PacketList::Name () const
41 { return thename.ToCString(); }
43 Handle(Interface_InterfaceModel) IFSelect_PacketList::Model () const
46 void IFSelect_PacketList::AddPacket ()
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);
52 if (thelast >= nbl) thepacks.SetNbEntities (nbl*2);
54 if (!thebegin) thelast ++;
55 thepacks.SetNumber (thelast);
56 thebegin = Standard_False;
60 void IFSelect_PacketList::Add
61 (const Handle(Standard_Transient)& ent)
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;
72 thebegin = Standard_False;
75 void IFSelect_PacketList::AddList
76 (const Handle(TColStd_HSequenceOfTransient)& list)
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));
85 Standard_Integer IFSelect_PacketList::NbPackets () const
86 { return (thebegin ? thelast-1 : thelast); }
88 Standard_Integer IFSelect_PacketList::NbEntities
89 (const Standard_Integer numpack) const
91 if (numpack <= 0 || numpack > NbPackets()) return 0;
92 Interface_IntList lisi(thepacks,Standard_False); lisi.SetNumber (numpack);
96 Interface_EntityIterator IFSelect_PacketList::Entities
97 (const Standard_Integer numpack) const
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)));
108 Standard_Integer IFSelect_PacketList::HighestDuplicationCount () const
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;
119 Standard_Integer IFSelect_PacketList::NbDuplicated
120 (const Standard_Integer newcount, const Standard_Boolean andmore) const
122 Standard_Integer i, nb = themodel->NbEntities();
123 Standard_Integer nbdu = 0;
125 for (i = 1; i <= nb; i ++) {
126 Standard_Integer j = thedupls.Value(i);
127 if (j == newcount || (j > newcount && andmore)) nbdu ++;
132 Interface_EntityIterator IFSelect_PacketList::Duplicated
133 (const Standard_Integer newcount, const Standard_Boolean andmore) const
135 Standard_Integer nb = themodel->NbEntities();
136 Interface_EntityIterator list;
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));