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_SCRoots.hxx> |
42cf5bc1 |
16 | #include <IFGraph_SubPartsIterator.hxx> |
17 | #include <IFSelect_DispPerFiles.hxx> |
18 | #include <IFSelect_IntParam.hxx> |
19 | #include <IFSelect_Selection.hxx> |
7fd59977 |
20 | #include <Interface_EntityIterator.hxx> |
42cf5bc1 |
21 | #include <Interface_Graph.hxx> |
22 | #include <Interface_InterfaceError.hxx> |
23 | #include <Interface_InterfaceModel.hxx> |
24 | #include <Standard_Type.hxx> |
25 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
26 | |
92efcf78 |
27 | IMPLEMENT_STANDARD_RTTIEXT(IFSelect_DispPerFiles,IFSelect_Dispatch) |
28 | |
b311480e |
29 | IFSelect_DispPerFiles::IFSelect_DispPerFiles () { } |
7fd59977 |
30 | |
31 | Handle(IFSelect_IntParam) IFSelect_DispPerFiles::Count () const |
32 | { return thecount; } |
33 | |
34 | void IFSelect_DispPerFiles::SetCount |
35 | (const Handle(IFSelect_IntParam)& pcount) |
36 | { thecount = pcount; } |
37 | |
38 | Standard_Integer IFSelect_DispPerFiles::CountValue () const |
39 | { |
40 | Standard_Integer pcount = 0; |
41 | if (!thecount.IsNull()) pcount = thecount->Value(); |
42 | if (pcount <= 0) pcount = 1; // option prise par defaut |
43 | return pcount; |
44 | } |
45 | |
46 | TCollection_AsciiString IFSelect_DispPerFiles::Label () const |
47 | { |
48 | TCollection_AsciiString lab(CountValue()); |
49 | lab.Insert(1,"Maximum "); |
50 | lab.AssignCat(" Files"); |
51 | return lab; |
52 | } |
53 | |
54 | |
55 | Standard_Boolean IFSelect_DispPerFiles::LimitedMax |
56 | (const Standard_Integer /* nbent */, Standard_Integer& pcount) const |
57 | { |
58 | pcount = CountValue(); |
59 | return Standard_True; |
60 | } |
61 | |
62 | Standard_Boolean IFSelect_DispPerFiles::PacketsCount |
63 | (const Interface_Graph& G, Standard_Integer& /*count*/) const |
64 | { return (G.Size() < CountValue() ? G.Size() : CountValue()); } |
65 | |
66 | void IFSelect_DispPerFiles::Packets |
67 | (const Interface_Graph& G, IFGraph_SubPartsIterator& packs) const |
68 | { |
69 | // Ressemble a DispPerOne, mais fait "count" AddPart racines |
70 | Standard_Integer pcount = CountValue(); |
71 | |
72 | IFGraph_SCRoots roots(G,Standard_False); |
73 | roots.SetLoad(); |
74 | roots.GetFromIter(FinalSelection()->UniqueResult(G)); |
75 | // SCRoots a initie la resolution : decoupage en StrongComponants + selection |
76 | // des racines. Un paquet correspond des lors a <count> racines |
77 | // Donc, il faut iterer sur les Parts de roots et les prendre par <count> |
78 | roots.Start(); // Start fait Evaluate specifique |
79 | Standard_Integer nb = roots.NbParts(); |
80 | if (pcount > 0) pcount = (nb-1) / pcount +1; // par packet |
81 | |
82 | Standard_Integer i = 0; |
83 | for (; roots.More(); roots.Next()) { // Start deja fait |
84 | if (i == 0) packs.AddPart(); |
85 | i ++; if (i >= pcount) i = 0; // regroupement selon "count" |
86 | packs.GetFromIter(roots.Entities()); |
87 | } |
88 | } |