1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <IFGraph_AllShared.hxx>
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>
22 #include <Interface_GraphContent.hxx>
23 #include <Interface_InterfaceError.hxx>
24 #include <Interface_InterfaceModel.hxx>
25 #include <Standard_NoSuchObject.hxx>
26 #include <TCollection_AsciiString.hxx>
28 IFSelect_ShareOutResult::IFSelect_ShareOutResult
29 (const Handle(IFSelect_ShareOut)& sho,
30 const Handle(Interface_InterfaceModel)& amodel)
31 : thegraph(amodel) , thedispres(amodel,Standard_False)
34 theeval = Standard_False;
35 // thedisplist = new TColStd_SequenceOfInteger();
38 IFSelect_ShareOutResult::IFSelect_ShareOutResult
39 (const Handle(IFSelect_ShareOut)& sho, const Interface_Graph& G)
40 : thegraph(G) , thedispres(G,Standard_False)
43 theeval = Standard_False;
44 // thedisplist = new TColStd_SequenceOfInteger();
47 IFSelect_ShareOutResult::IFSelect_ShareOutResult
48 (const Handle(IFSelect_Dispatch)& disp,
49 const Handle(Interface_InterfaceModel)& amodel)
50 : thegraph(amodel) , thedispres(amodel,Standard_False)
53 theeval = Standard_False;
54 // thedisplist = new TColStd_SequenceOfInteger();
57 IFSelect_ShareOutResult::IFSelect_ShareOutResult
58 (const Handle(IFSelect_Dispatch)& disp, const Interface_Graph& G)
59 : thegraph(G) , thedispres(G,Standard_False)
62 theeval = Standard_False;
63 // thedisplist = new TColStd_SequenceOfInteger();
67 Handle(IFSelect_ShareOut) IFSelect_ShareOutResult::ShareOut () const
68 { return theshareout; }
70 const Interface_Graph& IFSelect_ShareOutResult::Graph () const
73 void IFSelect_ShareOutResult::Reset ()
74 { theeval = Standard_False; }
76 void IFSelect_ShareOutResult::Evaluate ()
78 if (theeval) return; // deja fait. si pas OK, faire Reset avant
80 theeval = Standard_True;
84 Handle(IFSelect_PacketList) IFSelect_ShareOutResult::Packets
85 (const Standard_Boolean complete)
88 Handle(IFSelect_PacketList) list = new IFSelect_PacketList(thegraph.Model());
89 Interface_EntityIterator iter;
90 for ( ; More(); Next()) {
92 if (complete) list->AddList (PacketContent().Content());
93 else list->AddList (PacketRoot().Content());
98 Standard_Integer IFSelect_ShareOutResult::NbPackets ()
99 { Evaluate(); return thedispres.NbParts(); }
102 void IFSelect_ShareOutResult::Prepare ()
105 // On alimente thedispres, thedisplist
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;
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
127 thedisplist.Append(i); // n0 du dispatch producteur
130 thedispnum = thepacknum = 1;
131 thepackdisp = 1; // calcul sur 1er Dispatch
133 for (i = thepacknum; i <= thedisplist.Length(); i ++) {
134 if (thedisplist.Value(i) != thedispnum) break;
139 Standard_Boolean IFSelect_ShareOutResult::More ()
140 { return thedispres.More(); } // thepacknum < thedisplist.Length());
142 void IFSelect_ShareOutResult::Next ()
146 Standard_Integer dispnum;
147 if (thepacknum <= thedisplist.Length())
148 dispnum = thedisplist.Value(thepacknum);
151 #if !defined No_Exception
152 // std::cout<<" ** ** IFSelect_ShareOutResult::Next, void dispatch ignored"<<std::endl;
156 if (thedispnum == dispnum) thepackdisp ++;
158 thedispnum = dispnum;
161 for (Standard_Integer i = thepacknum; i <= thedisplist.Length(); i ++) {
162 if (thedisplist.Value(i) != thedispnum) break;
165 if (!theshareout.IsNull()) thedispatch = theshareout->Dispatch(thedispnum);
169 void IFSelect_ShareOutResult::NextDispatch ()
171 for (; thepacknum <= thedisplist.Length(); thepacknum ++) {
173 if (thedispnum != thedisplist.Value(thepacknum)) {
174 thedispnum = thedisplist.Value(thepacknum);
175 // Calcul donnees propres au Dispatch
178 for (Standard_Integer i = thepacknum; i <= thedisplist.Length(); i ++) {
179 if (thedisplist.Value(i) != thedispnum) break;
182 if (!theshareout.IsNull()) thedispatch = theshareout->Dispatch(thedispnum);
186 thepacknum = thedisplist.Length() + 1; // no next dispatch ...
187 thedispnum = thepackdisp = thenbindisp = 0;
190 Handle(IFSelect_Dispatch) IFSelect_ShareOutResult::Dispatch () const
191 { return thedispatch; }
193 Standard_Integer IFSelect_ShareOutResult::DispatchRank () const
194 { return thedispnum; }
196 void IFSelect_ShareOutResult::PacketsInDispatch
197 (Standard_Integer& numpack, Standard_Integer& nbpacks) const
198 { numpack = thepackdisp; nbpacks = thenbindisp; }
200 Interface_EntityIterator IFSelect_ShareOutResult::PacketRoot ()
201 { return thedispres.Entities(); }
203 Interface_EntityIterator IFSelect_ShareOutResult::PacketContent ()
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);
215 TCollection_AsciiString IFSelect_ShareOutResult::FileName () const
217 Standard_Integer nd = DispatchRank();
218 Standard_Integer np,nbp;
219 PacketsInDispatch(np,nbp);
220 return theshareout->FileName(nd,np,nbp);