0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / IFSelect / IFSelect_SelectSent.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
7fd59977 14
42cf5bc1 15#include <IFSelect_SelectSent.hxx>
16#include <Interface_EntityIterator.hxx>
17#include <Interface_Graph.hxx>
18#include <Interface_InterfaceModel.hxx>
19#include <Standard_Transient.hxx>
20#include <Standard_Type.hxx>
21#include <TCollection_AsciiString.hxx>
7fd59977 22
42cf5bc1 23#include <stdio.h>
92efcf78 24IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectSent,IFSelect_SelectExtract)
25
b311480e 26IFSelect_SelectSent::IFSelect_SelectSent
7fd59977 27 (const Standard_Integer sentcount, const Standard_Boolean atleast)
28 { thecnt = sentcount; thelst = atleast; }
29
30 Standard_Integer IFSelect_SelectSent::SentCount () const
31 { return thecnt; }
32
33 Standard_Boolean IFSelect_SelectSent::AtLeast () const
34 { return thelst; }
35
36 Interface_EntityIterator IFSelect_SelectSent::RootResult
37 (const Interface_Graph& G) const
38{
39 Standard_Boolean direct = IsDirect();
40 Interface_EntityIterator res;
41 Interface_EntityIterator inp = InputResult(G);
42
43 for (inp.Start(); inp.More(); inp.Next()) {
44 Standard_Integer num = G.EntityNumber(inp.Value());
45 if (num == 0) continue;
46 Standard_Integer nb = G.Status(num); // nb sent
47 Standard_Boolean ok;
48 if (thecnt == 0) ok = (nb == 0);
49 else if (thelst) ok = (nb >= thecnt);
50 else ok = (nb == thecnt);
51 if (ok == direct) res.AddItem (G.Entity(num));
52 }
53 return res;
54}
55
56 Standard_Boolean IFSelect_SelectSent::Sort
57 (const Standard_Integer ,
58 const Handle(Standard_Transient)&,
59 const Handle(Interface_InterfaceModel)& ) const
60 { return Standard_False; }
61
62
63 TCollection_AsciiString IFSelect_SelectSent::ExtractLabel () const
64{
65 char lb[80];
66 TCollection_AsciiString lab;
67 if (thecnt == 0) lab.AssignCat ("Remaining (non-sent) entities");
68 if (thecnt == 1 && thelst) lab.AssignCat ("Sent entities");
69 if (thecnt == 1 && !thelst) lab.AssignCat ("Sent once (non-duplicated) entities");
70 if (thecnt == 2 && thelst) lab.AssignCat ("Sent several times entities");
71 if (thecnt == 2 && !thelst) lab.AssignCat ("Sent just twice entities");
72 if (thecnt > 2) {
73 if (thelst) sprintf (lb,"Sent at least %d times entities", thecnt);
74 else sprintf (lb,"Sent just %d times entities", thecnt);
75 lab.AssignCat (lb);
76 }
77 return lab;
78}