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.
17 #include <IFSelect_PacketList.ixx>
18 #include <TColStd_HSequenceOfInteger.hxx>
19 #include <Interface_InterfaceError.hxx>
23 IFSelect_PacketList::IFSelect_PacketList
24 (const Handle(Interface_InterfaceModel)& model)
25 : thedupls (0,model->NbEntities()) ,
27 theflags (0,model->NbEntities()) ,
30 themodel = model; thelast = 0; thebegin = Standard_False; // begin-begin
31 thedupls.Init(0); theflags.Init(0);
34 void IFSelect_PacketList::SetName (const Standard_CString name)
35 { thename.Clear(); thename.AssignCat (name); }
37 Standard_CString IFSelect_PacketList::Name () const
38 { return thename.ToCString(); }
40 Handle(Interface_InterfaceModel) IFSelect_PacketList::Model () const
43 void IFSelect_PacketList::AddPacket ()
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);
49 if (thelast >= nbl) thepacks.SetNbEntities (nbl*2);
51 if (!thebegin) thelast ++;
52 thepacks.SetNumber (thelast);
53 thebegin = Standard_False;
57 void IFSelect_PacketList::Add
58 (const Handle(Standard_Transient)& ent)
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;
69 thebegin = Standard_False;
72 void IFSelect_PacketList::AddList
73 (const Handle(TColStd_HSequenceOfTransient)& list)
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));
82 Standard_Integer IFSelect_PacketList::NbPackets () const
83 { return (thebegin ? thelast-1 : thelast); }
85 Standard_Integer IFSelect_PacketList::NbEntities
86 (const Standard_Integer numpack) const
88 if (numpack <= 0 || numpack > NbPackets()) return 0;
89 Interface_IntList lisi(thepacks,Standard_False); lisi.SetNumber (numpack);
93 Interface_EntityIterator IFSelect_PacketList::Entities
94 (const Standard_Integer numpack) const
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)));
105 Standard_Integer IFSelect_PacketList::HighestDuplicationCount () const
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;
116 Standard_Integer IFSelect_PacketList::NbDuplicated
117 (const Standard_Integer newcount, const Standard_Boolean andmore) const
119 Standard_Integer i, nb = themodel->NbEntities();
120 Standard_Integer nbdu = 0;
122 for (i = 1; i <= nb; i ++) {
123 Standard_Integer j = thedupls.Value(i);
124 if (j == newcount || (j > newcount && andmore)) nbdu ++;
129 Interface_EntityIterator IFSelect_PacketList::Duplicated
130 (const Standard_Integer newcount, const Standard_Boolean andmore) const
132 Standard_Integer nb = themodel->NbEntities();
133 Interface_EntityIterator list;
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));