1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <IFSelect_SelectSignature.ixx>
21 // theexact : -1 OUI 0 NON une seule valeur > 0 NON nb de valeurs
22 // signmode : 1 prendre si contenu, 2 refuser si contenu
23 // 3 prendre si egal, 4 refuser si egal
24 // ou test numerique, ajouter : 16 < 24 <= 32 > 40 >=
26 static Standard_Integer multsign
27 (const TCollection_AsciiString& signtext,
28 TColStd_SequenceOfAsciiString& signlist,
29 TColStd_SequenceOfInteger& signmode)
31 Standard_Integer i, nb = signtext.Length(), mode = 0;
32 for (i = 1; i <= nb; i ++) {
33 char unsign = signtext.Value(i);
34 if (unsign == '|' || unsign == '!' || unsign == '=') { mode = 1; break; }
35 if (unsign == '<' || unsign == '>') { mode = 1; break; }
37 if (mode == 0) return mode;
39 TCollection_AsciiString item; Standard_Integer imod = 1;
40 for (i = 1; i <= nb; i ++) {
41 char unsign = signtext.Value(i);
42 if (unsign == '|' || unsign == '!') {
43 if (item.Length() > 0) {
44 signlist.Append (item);
45 signmode.Append (imod);
49 imod = (unsign == '|' ? 1 : 2);
51 else if (unsign == '<') imod += 16;
52 else if (unsign == '>') imod += 32;
53 else if (unsign == '=') { if (imod < 8) imod += 2; else imod += 8; }
54 else item.AssignCat (unsign);
56 if (item.Length() > 0) {
57 signlist.Append (item);
58 signmode.Append (imod);
59 // mode ++; valait un au depart
66 IFSelect_SelectSignature::IFSelect_SelectSignature
67 (const Handle(IFSelect_Signature)& matcher,
68 const TCollection_AsciiString& signtext, const Standard_Boolean exact)
69 : thematcher (matcher) , thesigntext (signtext) , theexact (exact ? -1 : 0)
70 { if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode); }
72 IFSelect_SelectSignature::IFSelect_SelectSignature
73 (const Handle(IFSelect_Signature)& matcher,
74 const Standard_CString signtext, const Standard_Boolean exact)
75 : thematcher (matcher) , thesigntext (signtext) , theexact (exact ? -1 : 0)
76 { if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode); }
78 IFSelect_SelectSignature::IFSelect_SelectSignature
79 (const Handle(IFSelect_SignCounter)& counter,
80 const Standard_CString signtext, const Standard_Boolean exact)
81 : thecounter (counter) , thesigntext (signtext) , theexact (exact ? -1 : 0)
82 { if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode); }
84 Handle(IFSelect_Signature) IFSelect_SelectSignature::Signature () const
85 { return thematcher; }
87 Handle(IFSelect_SignCounter) IFSelect_SelectSignature::Counter () const
88 { return thecounter; }
91 Standard_Boolean IFSelect_SelectSignature::SortInGraph
92 (const Standard_Integer , const Handle(Standard_Transient)& ent,
93 const Interface_Graph& G) const
97 Handle(Interface_InterfaceModel) model = G.Model();
99 if (!thematcher.IsNull()) return thematcher->Matches (ent,model,thesigntext, (theexact < 0));
100 txt = thecounter->ComputedSign(ent,G);
101 return IFSelect_Signature::MatchValue (txt,thesigntext , (theexact < 0));
105 // Analyse en sequence : si alternance prend/prend-pas, le dernier a raison
106 // en consequence, si que des prend ou que des prend-pas, c est commutatif
107 // DONC recommandation : mettre les prend-pas en fin
109 // AU DEPART : prendre = ne prendre que. prend-pas = prend-tout-sauf ...
110 // Donc si le premier est un prend-pas, je commence par tout prendre
111 Standard_Integer hmod = thesignmode.Value(1);
112 Standard_Integer jmod = hmod/8;
113 Standard_Integer imod = hmod - (jmod*8);
114 res = (imod == 2 || imod == 4);
115 for (Standard_Integer i = 1; i <= theexact; i ++) {
116 Standard_CString signtext = thesignlist.Value(i).ToCString();
117 hmod = thesignmode.Value(i);
119 imod = hmod - (jmod*8);
120 Standard_Boolean quid;
122 if (!thematcher.IsNull()) quid = thematcher->Matches (ent,model,signtext,(imod > 2));
123 else quid = IFSelect_Signature::MatchValue
124 ( thecounter->ComputedSign(ent,G),signtext, (imod > 2) );
127 if (!thematcher.IsNull()) txt = thematcher->Value (ent,model);
128 else txt = thecounter->ComputedSign (ent,G);
130 Standard_Integer val = atoi(txt);
131 Standard_Integer lav = atoi (signtext);
133 case 2 : quid = (val < lav); break;
134 case 3 : quid = (val <= lav); break;
135 case 4 : quid = (val > lav); break;
136 case 5 : quid = (val >= lav); break;
137 default : quid = Standard_False; break;
140 if ((imod == 1 || imod == 3) && quid) res = Standard_True;
141 if ((imod == 2 || imod == 4) && quid) res = Standard_False;
146 Standard_Boolean IFSelect_SelectSignature::Sort
147 (const Standard_Integer , const Handle(Standard_Transient)& ent,
148 const Handle(Interface_InterfaceModel)& model) const
149 { return Standard_True; }
151 const TCollection_AsciiString& IFSelect_SelectSignature::SignatureText () const
152 { return thesigntext; }
154 Standard_Boolean IFSelect_SelectSignature::IsExact () const
155 { return (theexact < 0); }
157 TCollection_AsciiString IFSelect_SelectSignature::ExtractLabel () const
159 TCollection_AsciiString lab;
160 if (!thematcher.IsNull()) lab.AssignCat (thematcher->Name());
161 else lab.AssignCat (thecounter->Name());
162 if (theexact < 0) lab.AssignCat(" matching ");
163 else if (theexact == 0) lab.AssignCat(" containing ");
164 else lab.AssignCat(" matching list ");
165 lab.AssignCat(thesigntext);