0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / IFSelect / IFSelect_SelectSent.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
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>
22
23 #include <stdio.h>
24 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectSent,IFSelect_SelectExtract)
25
26 IFSelect_SelectSent::IFSelect_SelectSent
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 }