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 | #include <IFSelect_SelectSignature.ixx> |
15 | |
16 | |
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 >= |
21 | |
22 | static Standard_Integer multsign |
23 | (const TCollection_AsciiString& signtext, |
24 | TColStd_SequenceOfAsciiString& signlist, |
25 | TColStd_SequenceOfInteger& signmode) |
26 | { |
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; } |
32 | } |
33 | if (mode == 0) return mode; |
34 | // On va tronconner |
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); |
42 | item.Clear(); |
43 | mode ++; |
44 | } |
45 | imod = (unsign == '|' ? 1 : 2); |
46 | } |
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); |
51 | } |
52 | if (item.Length() > 0) { |
53 | signlist.Append (item); |
54 | signmode.Append (imod); |
55 | // mode ++; valait un au depart |
56 | } |
57 | return mode; |
58 | } |
59 | |
60 | |
61 | |
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); } |
67 | |
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); } |
73 | |
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); } |
79 | |
80 | Handle(IFSelect_Signature) IFSelect_SelectSignature::Signature () const |
81 | { return thematcher; } |
82 | |
83 | Handle(IFSelect_SignCounter) IFSelect_SelectSignature::Counter () const |
84 | { return thecounter; } |
85 | |
86 | |
87 | Standard_Boolean IFSelect_SelectSignature::SortInGraph |
88 | (const Standard_Integer , const Handle(Standard_Transient)& ent, |
89 | const Interface_Graph& G) const |
90 | { |
91 | Standard_Boolean res; |
92 | Standard_CString txt; |
93 | Handle(Interface_InterfaceModel) model = G.Model(); |
94 | if (theexact <= 0) { |
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)); |
98 | } |
99 | |
100 | // sinon : liste |
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 |
104 | |
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); |
114 | jmod = hmod/8; |
115 | imod = hmod - (jmod*8); |
116 | Standard_Boolean quid; |
117 | if (jmod == 0) { |
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) ); |
121 | } |
122 | else { |
123 | if (!thematcher.IsNull()) txt = thematcher->Value (ent,model); |
124 | else txt = thecounter->ComputedSign (ent,G); |
125 | |
126 | Standard_Integer val = atoi(txt); |
127 | Standard_Integer lav = atoi (signtext); |
128 | switch (jmod) { |
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; |
134 | } |
135 | } |
136 | if ((imod == 1 || imod == 3) && quid) res = Standard_True; |
137 | if ((imod == 2 || imod == 4) && quid) res = Standard_False; |
138 | } |
139 | return res; |
140 | } |
141 | |
142 | Standard_Boolean IFSelect_SelectSignature::Sort |
35e08fe8 |
143 | (const Standard_Integer , const Handle(Standard_Transient)& /*ent*/, |
144 | const Handle(Interface_InterfaceModel)& /*model*/) const |
7fd59977 |
145 | { return Standard_True; } |
146 | |
147 | const TCollection_AsciiString& IFSelect_SelectSignature::SignatureText () const |
148 | { return thesigntext; } |
149 | |
150 | Standard_Boolean IFSelect_SelectSignature::IsExact () const |
151 | { return (theexact < 0); } |
152 | |
153 | TCollection_AsciiString IFSelect_SelectSignature::ExtractLabel () const |
154 | { |
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); |
162 | return lab; |
163 | } |