summaryrefslogtreecommitdiff
path: root/src/IFSelect/IFSelect_SelectSignature.cxx
blob: e75935876e9f34da46e8ab788b501b6aebe4694a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <IFSelect_SelectSignature.ixx>


//  theexact : -1  OUI   0  NON une seule valeur  > 0 NON nb de valeurs
//  signmode : 1 prendre si contenu, 2 refuser si contenu
//             3 prendre si egal,    4 refuser si egal
//  ou test numerique, ajouter : 16 <  24 <=  32 >  40 >=

static Standard_Integer multsign
  (const TCollection_AsciiString& signtext,
   TColStd_SequenceOfAsciiString& signlist,
   TColStd_SequenceOfInteger&     signmode)
{
  Standard_Integer i, nb = signtext.Length(), mode = 0;
  for (i = 1; i <= nb; i ++) {
    char unsign = signtext.Value(i);
    if (unsign == '|' || unsign == '!' || unsign == '=') { mode = 1; break; }
    if (unsign == '<' || unsign == '>') { mode = 1; break; }
  }
  if (mode == 0) return mode;
//  On va tronconner
  TCollection_AsciiString item;  Standard_Integer imod = 1;
  for (i = 1; i <= nb; i ++) {
    char unsign = signtext.Value(i);
    if (unsign == '|' || unsign == '!') {
      if (item.Length() > 0) {
	signlist.Append (item);
	signmode.Append (imod);
	item.Clear();
	mode ++;
      }
      imod = (unsign == '|' ? 1 : 2);
    }
    else if (unsign == '<') imod += 16;
    else if (unsign == '>') imod += 32;
    else if (unsign == '=') { if (imod < 8) imod += 2; else imod += 8; }
    else item.AssignCat (unsign);
  }
  if (item.Length() > 0) {
    signlist.Append (item);
    signmode.Append (imod);
//    mode ++;  valait un au depart
  }
  return mode;
}



    IFSelect_SelectSignature::IFSelect_SelectSignature
  (const Handle(IFSelect_Signature)& matcher,
   const TCollection_AsciiString& signtext, const Standard_Boolean exact)
    : thematcher (matcher) , thesigntext (signtext) , theexact (exact ? -1 : 0)
{  if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode);  }

    IFSelect_SelectSignature::IFSelect_SelectSignature
  (const Handle(IFSelect_Signature)& matcher,
   const Standard_CString signtext, const Standard_Boolean exact)
    : thematcher (matcher) , thesigntext (signtext) , theexact (exact ? -1 : 0)
{  if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode);  }

    IFSelect_SelectSignature::IFSelect_SelectSignature
  (const Handle(IFSelect_SignCounter)& counter,
   const Standard_CString signtext, const Standard_Boolean exact)
    : thecounter (counter) , thesigntext (signtext) , theexact (exact ? -1 : 0)
{  if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode);  }

    Handle(IFSelect_Signature)  IFSelect_SelectSignature::Signature () const
      {  return thematcher;  }

    Handle(IFSelect_SignCounter)  IFSelect_SelectSignature::Counter () const
      {  return thecounter;  }


    Standard_Boolean  IFSelect_SelectSignature::SortInGraph
  (const Standard_Integer , const Handle(Standard_Transient)& ent,
   const Interface_Graph& G) const
{
  Standard_Boolean res;
  Standard_CString txt;
  Handle(Interface_InterfaceModel) model = G.Model();
  if (theexact <= 0) {
    if (!thematcher.IsNull()) return thematcher->Matches (ent,model,thesigntext, (theexact < 0));
    txt = thecounter->ComputedSign(ent,G);
    return IFSelect_Signature::MatchValue (txt,thesigntext , (theexact < 0));
  }

//  sinon : liste
//  Analyse en sequence : si alternance prend/prend-pas, le dernier a raison
//   en consequence, si que des prend ou que des prend-pas, c est commutatif
//   DONC recommandation : mettre les prend-pas en fin

//  AU DEPART : prendre = ne prendre que. prend-pas = prend-tout-sauf ...
//  Donc si le premier est un prend-pas, je commence par tout prendre
  Standard_Integer hmod = thesignmode.Value(1);
  Standard_Integer jmod = hmod/8;
  Standard_Integer imod = hmod - (jmod*8);
  res = (imod == 2 || imod == 4);
  for (Standard_Integer i = 1; i <= theexact; i ++) {
    Standard_CString signtext = thesignlist.Value(i).ToCString();
    hmod = thesignmode.Value(i);
    jmod = hmod/8;
    imod = hmod - (jmod*8);
    Standard_Boolean quid;
    if (jmod == 0) {
      if (!thematcher.IsNull()) quid = thematcher->Matches (ent,model,signtext,(imod > 2));
      else quid = IFSelect_Signature::MatchValue
	( thecounter->ComputedSign(ent,G),signtext, (imod > 2) );
    }
    else {
      if (!thematcher.IsNull()) txt = thematcher->Value (ent,model);
      else txt = thecounter->ComputedSign (ent,G);

      Standard_Integer val = atoi(txt);
      Standard_Integer lav = atoi (signtext);
      switch (jmod) {
        case 2 : quid = (val <  lav); break;
        case 3 : quid = (val <= lav); break;
        case 4 : quid = (val >  lav); break;
        case 5 : quid = (val >= lav); break;
	default : quid = Standard_False; break;
      }
    }
    if ((imod == 1 || imod == 3) && quid) res = Standard_True;
    if ((imod == 2 || imod == 4) && quid) res = Standard_False;
  }
  return res;
}

    Standard_Boolean  IFSelect_SelectSignature::Sort
  (const Standard_Integer , const Handle(Standard_Transient)& ent,
   const Handle(Interface_InterfaceModel)& model) const
{  return Standard_True;  }

    const TCollection_AsciiString&  IFSelect_SelectSignature::SignatureText () const
      {  return thesigntext;  }

    Standard_Boolean  IFSelect_SelectSignature::IsExact () const
      {  return (theexact < 0);  }

    TCollection_AsciiString  IFSelect_SelectSignature::ExtractLabel () const
{
  TCollection_AsciiString lab;
  if (!thematcher.IsNull()) lab.AssignCat (thematcher->Name());
  else                      lab.AssignCat (thecounter->Name());
  if      (theexact  < 0) lab.AssignCat(" matching ");
  else if (theexact == 0) lab.AssignCat(" containing ");
  else                    lab.AssignCat(" matching list ");
  lab.AssignCat(thesigntext);
  return lab;
}