1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <IFSelect_SelectSignature.ixx>
17 // theexact : -1 OUI 0 NON une seule valeur > 0 NON nb de valeurs
18 // signmode : 1 prendre si contenu, 2 refuser si contenu
19 // 3 prendre si egal, 4 refuser si egal
20 // ou test numerique, ajouter : 16 < 24 <= 32 > 40 >=
22 static Standard_Integer multsign
23 (const TCollection_AsciiString& signtext,
24 TColStd_SequenceOfAsciiString& signlist,
25 TColStd_SequenceOfInteger& signmode)
27 Standard_Integer i, nb = signtext.Length(), mode = 0;
28 for (i = 1; i <= nb; i ++) {
29 char unsign = signtext.Value(i);
30 if (unsign == '|' || unsign == '!' || unsign == '=') { mode = 1; break; }
31 if (unsign == '<' || unsign == '>') { mode = 1; break; }
33 if (mode == 0) return mode;
35 TCollection_AsciiString item; Standard_Integer imod = 1;
36 for (i = 1; i <= nb; i ++) {
37 char unsign = signtext.Value(i);
38 if (unsign == '|' || unsign == '!') {
39 if (item.Length() > 0) {
40 signlist.Append (item);
41 signmode.Append (imod);
45 imod = (unsign == '|' ? 1 : 2);
47 else if (unsign == '<') imod += 16;
48 else if (unsign == '>') imod += 32;
49 else if (unsign == '=') { if (imod < 8) imod += 2; else imod += 8; }
50 else item.AssignCat (unsign);
52 if (item.Length() > 0) {
53 signlist.Append (item);
54 signmode.Append (imod);
55 // mode ++; valait un au depart
62 IFSelect_SelectSignature::IFSelect_SelectSignature
63 (const Handle(IFSelect_Signature)& matcher,
64 const TCollection_AsciiString& signtext, const Standard_Boolean exact)
65 : thematcher (matcher) , thesigntext (signtext) , theexact (exact ? -1 : 0)
66 { if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode); }
68 IFSelect_SelectSignature::IFSelect_SelectSignature
69 (const Handle(IFSelect_Signature)& matcher,
70 const Standard_CString signtext, const Standard_Boolean exact)
71 : thematcher (matcher) , thesigntext (signtext) , theexact (exact ? -1 : 0)
72 { if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode); }
74 IFSelect_SelectSignature::IFSelect_SelectSignature
75 (const Handle(IFSelect_SignCounter)& counter,
76 const Standard_CString signtext, const Standard_Boolean exact)
77 : thecounter (counter) , thesigntext (signtext) , theexact (exact ? -1 : 0)
78 { if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode); }
80 Handle(IFSelect_Signature) IFSelect_SelectSignature::Signature () const
81 { return thematcher; }
83 Handle(IFSelect_SignCounter) IFSelect_SelectSignature::Counter () const
84 { return thecounter; }
87 Standard_Boolean IFSelect_SelectSignature::SortInGraph
88 (const Standard_Integer , const Handle(Standard_Transient)& ent,
89 const Interface_Graph& G) const
93 Handle(Interface_InterfaceModel) model = G.Model();
95 if (!thematcher.IsNull()) return thematcher->Matches (ent,model,thesigntext, (theexact < 0));
96 txt = thecounter->ComputedSign(ent,G);
97 return IFSelect_Signature::MatchValue (txt,thesigntext , (theexact < 0));
101 // Analyse en sequence : si alternance prend/prend-pas, le dernier a raison
102 // en consequence, si que des prend ou que des prend-pas, c est commutatif
103 // DONC recommandation : mettre les prend-pas en fin
105 // AU DEPART : prendre = ne prendre que. prend-pas = prend-tout-sauf ...
106 // Donc si le premier est un prend-pas, je commence par tout prendre
107 Standard_Integer hmod = thesignmode.Value(1);
108 Standard_Integer jmod = hmod/8;
109 Standard_Integer imod = hmod - (jmod*8);
110 res = (imod == 2 || imod == 4);
111 for (Standard_Integer i = 1; i <= theexact; i ++) {
112 Standard_CString signtext = thesignlist.Value(i).ToCString();
113 hmod = thesignmode.Value(i);
115 imod = hmod - (jmod*8);
116 Standard_Boolean quid;
118 if (!thematcher.IsNull()) quid = thematcher->Matches (ent,model,signtext,(imod > 2));
119 else quid = IFSelect_Signature::MatchValue
120 ( thecounter->ComputedSign(ent,G),signtext, (imod > 2) );
123 if (!thematcher.IsNull()) txt = thematcher->Value (ent,model);
124 else txt = thecounter->ComputedSign (ent,G);
126 Standard_Integer val = atoi(txt);
127 Standard_Integer lav = atoi (signtext);
129 case 2 : quid = (val < lav); break;
130 case 3 : quid = (val <= lav); break;
131 case 4 : quid = (val > lav); break;
132 case 5 : quid = (val >= lav); break;
133 default : quid = Standard_False; break;
136 if ((imod == 1 || imod == 3) && quid) res = Standard_True;
137 if ((imod == 2 || imod == 4) && quid) res = Standard_False;
142 Standard_Boolean IFSelect_SelectSignature::Sort
143 (const Standard_Integer , const Handle(Standard_Transient)& /*ent*/,
144 const Handle(Interface_InterfaceModel)& /*model*/) const
145 { return Standard_True; }
147 const TCollection_AsciiString& IFSelect_SelectSignature::SignatureText () const
148 { return thesigntext; }
150 Standard_Boolean IFSelect_SelectSignature::IsExact () const
151 { return (theexact < 0); }
153 TCollection_AsciiString IFSelect_SelectSignature::ExtractLabel () const
155 TCollection_AsciiString lab;
156 if (!thematcher.IsNull()) lab.AssignCat (thematcher->Name());
157 else lab.AssignCat (thecounter->Name());
158 if (theexact < 0) lab.AssignCat(" matching ");
159 else if (theexact == 0) lab.AssignCat(" containing ");
160 else lab.AssignCat(" matching list ");
161 lab.AssignCat(thesigntext);