0024023: Revamp the OCCT Handle -- general
[occt.git] / src / IFSelect / IFSelect_DispPerFiles.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <IFSelect_DispPerFiles.ixx>
15 #include <IFSelect_Selection.hxx>
16 #include <IFGraph_SCRoots.hxx>
17 #include <Interface_InterfaceModel.hxx>
18 #include <Interface_EntityIterator.hxx>
19
20
21 IFSelect_DispPerFiles::IFSelect_DispPerFiles ()    {  }
22
23     Handle(IFSelect_IntParam)  IFSelect_DispPerFiles::Count () const 
24       {  return thecount;  }
25
26     void  IFSelect_DispPerFiles::SetCount
27   (const Handle(IFSelect_IntParam)& pcount)
28       {  thecount = pcount;  }
29
30     Standard_Integer  IFSelect_DispPerFiles::CountValue () const
31 {
32   Standard_Integer pcount = 0;
33   if (!thecount.IsNull()) pcount = thecount->Value();
34   if (pcount <= 0) pcount = 1;    // option prise par defaut
35   return pcount;
36 }
37
38     TCollection_AsciiString  IFSelect_DispPerFiles::Label () const
39 {
40   TCollection_AsciiString lab(CountValue());
41   lab.Insert(1,"Maximum ");
42   lab.AssignCat(" Files");
43   return lab;
44 }
45
46
47     Standard_Boolean  IFSelect_DispPerFiles::LimitedMax
48   (const Standard_Integer /* nbent */, Standard_Integer& pcount) const 
49 {
50   pcount = CountValue();
51   return Standard_True;
52 }
53
54     Standard_Boolean  IFSelect_DispPerFiles::PacketsCount
55   (const Interface_Graph& G, Standard_Integer& /*count*/) const 
56       {  return (G.Size() < CountValue() ? G.Size() : CountValue());  }
57
58     void  IFSelect_DispPerFiles::Packets
59   (const Interface_Graph& G, IFGraph_SubPartsIterator& packs) const 
60 {
61 //  Ressemble a DispPerOne, mais fait "count" AddPart racines
62   Standard_Integer pcount = CountValue();
63
64   IFGraph_SCRoots roots(G,Standard_False);
65   roots.SetLoad();
66   roots.GetFromIter(FinalSelection()->UniqueResult(G));
67 //   SCRoots a initie la resolution : decoupage en StrongComponants + selection
68 //   des racines. Un paquet correspond des lors a <count> racines
69 //   Donc, il faut iterer sur les Parts de roots et les prendre par <count>
70   roots.Start();                            // Start fait Evaluate specifique
71   Standard_Integer nb = roots.NbParts();
72   if (pcount > 0) pcount = (nb-1) / pcount +1;    // par packet
73
74   Standard_Integer i = 0;
75   for (; roots.More(); roots.Next()) {      // Start deja fait
76     if (i == 0) packs.AddPart();
77     i ++;  if (i >= pcount) i = 0;  // regroupement selon "count"
78     packs.GetFromIter(roots.Entities());
79   }
80 }