1 // Created on: 1994-09-02
2 // Created by: Christian CAILLET
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <IFSelect_PacketList.ixx>
24 #include <TColStd_HSequenceOfInteger.hxx>
25 #include <Interface_InterfaceError.hxx>
29 IFSelect_PacketList::IFSelect_PacketList
30 (const Handle(Interface_InterfaceModel)& model)
31 : thedupls (0,model->NbEntities()) ,
33 theflags (0,model->NbEntities()) ,
36 themodel = model; thelast = 0; thebegin = Standard_False; // begin-begin
37 thedupls.Init(0); theflags.Init(0);
40 void IFSelect_PacketList::SetName (const Standard_CString name)
41 { thename.Clear(); thename.AssignCat (name); }
43 Standard_CString IFSelect_PacketList::Name () const
44 { return thename.ToCString(); }
46 Handle(Interface_InterfaceModel) IFSelect_PacketList::Model () const
49 void IFSelect_PacketList::AddPacket ()
51 Standard_Integer nbl = thepacks.NbEntities();
52 Standard_Integer nbe = theflags.Upper();
53 for (Standard_Integer i = 1; i <= nbe; i ++) theflags.SetValue(i,0);
55 if (thelast >= nbl) thepacks.SetNbEntities (nbl*2);
57 if (!thebegin) thelast ++;
58 thepacks.SetNumber (thelast);
59 thebegin = Standard_False;
63 void IFSelect_PacketList::Add
64 (const Handle(Standard_Transient)& ent)
66 Standard_Integer num = themodel->Number(ent);
67 if (num == 0) Interface_InterfaceError::Raise
68 ("PacketList:Add, Entity not in Model");
69 if (thelast == 0) Interface_InterfaceError::Raise
70 ("PacketList:Add, no Packet yet added");
71 if (theflags(num) != 0) return;
75 thebegin = Standard_False;
78 void IFSelect_PacketList::AddList
79 (const Handle(TColStd_HSequenceOfTransient)& list)
81 if (list.IsNull()) return;
82 Standard_Integer i , nb = list->Length();
83 thepacks.Reservate (nb+1);
84 for (i = 1; i <= nb; i ++) Add (list->Value(i));
88 Standard_Integer IFSelect_PacketList::NbPackets () const
89 { return (thebegin ? thelast-1 : thelast); }
91 Standard_Integer IFSelect_PacketList::NbEntities
92 (const Standard_Integer numpack) const
94 if (numpack <= 0 || numpack > NbPackets()) return 0;
95 Interface_IntList lisi(thepacks,Standard_False); lisi.SetNumber (numpack);
99 Interface_EntityIterator IFSelect_PacketList::Entities
100 (const Standard_Integer numpack) const
102 Interface_EntityIterator list;
103 if (numpack <= 0 || numpack > NbPackets()) return list;
104 Interface_IntList lisi(thepacks,Standard_False); lisi.SetNumber (numpack);
105 Standard_Integer i , nb = lisi.Length();
106 for (i = 1; i <= nb; i ++)
107 list.AddItem(themodel->Value(lisi.Value(i)));
111 Standard_Integer IFSelect_PacketList::HighestDuplicationCount () const
113 Standard_Integer i , nb = themodel->NbEntities();
114 Standard_Integer high = 0;
115 for (i = 1; i <= nb; i ++) {
116 Standard_Integer j = thedupls.Value(i);
117 if (j > high) high = j;
122 Standard_Integer IFSelect_PacketList::NbDuplicated
123 (const Standard_Integer newcount, const Standard_Boolean andmore) const
125 Standard_Integer i, nb = themodel->NbEntities();
126 Standard_Integer nbdu = 0;
128 for (i = 1; i <= nb; i ++) {
129 Standard_Integer j = thedupls.Value(i);
130 if (j == newcount || (j > newcount && andmore)) nbdu ++;
135 Interface_EntityIterator IFSelect_PacketList::Duplicated
136 (const Standard_Integer newcount, const Standard_Boolean andmore) const
138 Standard_Integer nb = themodel->NbEntities();
139 Interface_EntityIterator list;
142 for (i = 1; i <= nb; i ++) {
143 Standard_Integer j = thedupls.Value(i);
144 if (j == newcount || (j > newcount && andmore)) list.AddItem(themodel->Value(i));