0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / IFSelect / IFSelect_ShareOutResult.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
7fd59977 15#include <IFGraph_AllShared.hxx>
42cf5bc1 16#include <IFSelect_Dispatch.hxx>
17#include <IFSelect_PacketList.hxx>
18#include <IFSelect_ShareOut.hxx>
19#include <IFSelect_ShareOutResult.hxx>
20#include <Interface_EntityIterator.hxx>
21#include <Interface_Graph.hxx>
7fd59977 22#include <Interface_GraphContent.hxx>
42cf5bc1 23#include <Interface_InterfaceError.hxx>
24#include <Interface_InterfaceModel.hxx>
25#include <Standard_NoSuchObject.hxx>
26#include <TCollection_AsciiString.hxx>
7fd59977 27
b311480e 28IFSelect_ShareOutResult::IFSelect_ShareOutResult
7fd59977 29 (const Handle(IFSelect_ShareOut)& sho,
30 const Handle(Interface_InterfaceModel)& amodel)
31 : thegraph(amodel) , thedispres(amodel,Standard_False)
32{
33 theshareout = sho;
34 theeval = Standard_False;
35// thedisplist = new TColStd_SequenceOfInteger();
36}
37
38 IFSelect_ShareOutResult::IFSelect_ShareOutResult
39 (const Handle(IFSelect_ShareOut)& sho, const Interface_Graph& G)
40 : thegraph(G) , thedispres(G,Standard_False)
41{
42 theshareout = sho;
43 theeval = Standard_False;
44// thedisplist = new TColStd_SequenceOfInteger();
45}
46
47 IFSelect_ShareOutResult::IFSelect_ShareOutResult
48 (const Handle(IFSelect_Dispatch)& disp,
49 const Handle(Interface_InterfaceModel)& amodel)
50 : thegraph(amodel) , thedispres(amodel,Standard_False)
51{
52 thedispatch = disp;
53 theeval = Standard_False;
54// thedisplist = new TColStd_SequenceOfInteger();
55}
56
57 IFSelect_ShareOutResult::IFSelect_ShareOutResult
58 (const Handle(IFSelect_Dispatch)& disp, const Interface_Graph& G)
59 : thegraph(G) , thedispres(G,Standard_False)
60{
61 thedispatch = disp;
62 theeval = Standard_False;
63// thedisplist = new TColStd_SequenceOfInteger();
64}
65
66
67 Handle(IFSelect_ShareOut) IFSelect_ShareOutResult::ShareOut () const
68 { return theshareout; }
69
70 const Interface_Graph& IFSelect_ShareOutResult::Graph () const
71 { return thegraph; }
72
73 void IFSelect_ShareOutResult::Reset ()
74 { theeval = Standard_False; }
75
76 void IFSelect_ShareOutResult::Evaluate ()
77{
78 if (theeval) return; // deja fait. si pas OK, faire Reset avant
79 Prepare();
80 theeval = Standard_True;
81}
82
83
84 Handle(IFSelect_PacketList) IFSelect_ShareOutResult::Packets
85 (const Standard_Boolean complete)
86{
87 Evaluate();
88 Handle(IFSelect_PacketList) list = new IFSelect_PacketList(thegraph.Model());
89 Interface_EntityIterator iter;
90 for ( ; More(); Next()) {
91 list->AddPacket();
92 if (complete) list->AddList (PacketContent().Content());
93 else list->AddList (PacketRoot().Content());
94 }
95 return list;
96}
97
98 Standard_Integer IFSelect_ShareOutResult::NbPackets ()
99 { Evaluate(); return thedispres.NbParts(); }
100
101
102 void IFSelect_ShareOutResult::Prepare ()
103{
104 thedisplist.Clear();
105// On alimente thedispres, thedisplist
106 thedispres.Reset();
107 IFGraph_AllShared A(thegraph);
108 Handle(IFSelect_Dispatch) disp = thedispatch;
109 Standard_Integer nb = 1, first = 1;
110 if (!theshareout.IsNull()) {
111 nb = theshareout->NbDispatches();
112 first = theshareout->LastRun() + 1;
113 }
114 Standard_Integer i; // svv Jan11 2000 : porting on DEC
115 for (i = first; i <= nb; i ++) {
116 if (!theshareout.IsNull()) disp = theshareout->Dispatch(i);
117 if (disp->FinalSelection().IsNull()) continue; // Dispatch neutralise
118 IFGraph_SubPartsIterator packs(thegraph,Standard_False);
119 disp->Packets(thegraph,packs);
120 for (packs.Start(); packs.More(); packs.Next()) {
121 Interface_EntityIterator iter = packs.Entities();
122 if (iter.NbEntities() == 0) continue;
123 thedispres.AddPart();
124 thedispres.GetFromIter(iter); // on enregistre ce paquet
125 A.ResetData();
126 A.GetFromIter(iter);
127 thedisplist.Append(i); // n0 du dispatch producteur
128 }
129 }
130 thedispnum = thepacknum = 1;
131 thepackdisp = 1; // calcul sur 1er Dispatch
132 thenbindisp = 0;
133 for (i = thepacknum; i <= thedisplist.Length(); i ++) {
134 if (thedisplist.Value(i) != thedispnum) break;
135 thenbindisp ++;
136 }
137}
138
139 Standard_Boolean IFSelect_ShareOutResult::More ()
140 { return thedispres.More(); } // thepacknum < thedisplist.Length());
141
142 void IFSelect_ShareOutResult::Next ()
143{
144 thedispres.Next();
145 thepacknum ++;
146 Standard_Integer dispnum;
147 if (thepacknum <= thedisplist.Length())
148 dispnum = thedisplist.Value(thepacknum);
149 else {
150 thenbindisp = 0;
151#if !defined No_Exception
152// cout<<" ** ** IFSelect_ShareOutResult::Next, void dispatch ignored"<<endl;
153#endif
154 return;
155 }
156 if (thedispnum == dispnum) thepackdisp ++;
157 else {
158 thedispnum = dispnum;
159 thepackdisp = 1;
160 thenbindisp = 0;
161 for (Standard_Integer i = thepacknum; i <= thedisplist.Length(); i ++) {
162 if (thedisplist.Value(i) != thedispnum) break;
163 thenbindisp ++;
164 }
165 if (!theshareout.IsNull()) thedispatch = theshareout->Dispatch(thedispnum);
166 }
167}
168
169 void IFSelect_ShareOutResult::NextDispatch ()
170{
171 for (; thepacknum <= thedisplist.Length(); thepacknum ++) {
172 thedispres.Next();
173 if (thedispnum != thedisplist.Value(thepacknum)) {
174 thedispnum = thedisplist.Value(thepacknum);
175// Calcul donnees propres au Dispatch
176 thepackdisp = 1;
177 thenbindisp = 0;
178 for (Standard_Integer i = thepacknum; i <= thedisplist.Length(); i ++) {
179 if (thedisplist.Value(i) != thedispnum) break;
180 thenbindisp ++;
181 }
182 if (!theshareout.IsNull()) thedispatch = theshareout->Dispatch(thedispnum);
183 return;
184 }
185 }
186 thepacknum = thedisplist.Length() + 1; // no next dispatch ...
187 thedispnum = thepackdisp = thenbindisp = 0;
188}
189
190 Handle(IFSelect_Dispatch) IFSelect_ShareOutResult::Dispatch () const
191 { return thedispatch; }
192
193 Standard_Integer IFSelect_ShareOutResult::DispatchRank () const
194 { return thedispnum; }
195
196 void IFSelect_ShareOutResult::PacketsInDispatch
197 (Standard_Integer& numpack, Standard_Integer& nbpacks) const
198 { numpack = thepackdisp; nbpacks = thenbindisp; }
199
200 Interface_EntityIterator IFSelect_ShareOutResult::PacketRoot ()
201 { return thedispres.Entities(); }
202
203 Interface_EntityIterator IFSelect_ShareOutResult::PacketContent ()
204{
205// IFGraph_Cumulate G(thegraph);
206 Interface_EntityIterator iter = thedispres.Entities();
207 Interface_Graph G(thegraph);
208// G.GetFromIter(thedispres.Entities(),0);
209 for (iter.Start(); iter.More(); iter.Next())
210 G.GetFromEntity(iter.Value(),Standard_True);
211 Interface_GraphContent GC(G);
212 return GC.Result();
213}
214
215 TCollection_AsciiString IFSelect_ShareOutResult::FileName () const
216{
217 Standard_Integer nd = DispatchRank();
218 Standard_Integer np,nbp;
219 PacketsInDispatch(np,nbp);
220 return theshareout->FileName(nd,np,nbp);
221}