0024157: Parallelization of assembly part of BO
[occt.git] / src / IFSelect / IFSelect_SelectSignature.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
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.
7//
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.
10//
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.
17
7fd59977 18#include <IFSelect_SelectSignature.ixx>
19
20
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 >=
25
26static Standard_Integer multsign
27 (const TCollection_AsciiString& signtext,
28 TColStd_SequenceOfAsciiString& signlist,
29 TColStd_SequenceOfInteger& signmode)
30{
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; }
36 }
37 if (mode == 0) return mode;
38// On va tronconner
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);
46 item.Clear();
47 mode ++;
48 }
49 imod = (unsign == '|' ? 1 : 2);
50 }
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);
55 }
56 if (item.Length() > 0) {
57 signlist.Append (item);
58 signmode.Append (imod);
59// mode ++; valait un au depart
60 }
61 return mode;
62}
63
64
65
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); }
71
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); }
77
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); }
83
84 Handle(IFSelect_Signature) IFSelect_SelectSignature::Signature () const
85 { return thematcher; }
86
87 Handle(IFSelect_SignCounter) IFSelect_SelectSignature::Counter () const
88 { return thecounter; }
89
90
91 Standard_Boolean IFSelect_SelectSignature::SortInGraph
92 (const Standard_Integer , const Handle(Standard_Transient)& ent,
93 const Interface_Graph& G) const
94{
95 Standard_Boolean res;
96 Standard_CString txt;
97 Handle(Interface_InterfaceModel) model = G.Model();
98 if (theexact <= 0) {
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));
102 }
103
104// sinon : liste
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
108
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);
118 jmod = hmod/8;
119 imod = hmod - (jmod*8);
120 Standard_Boolean quid;
121 if (jmod == 0) {
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) );
125 }
126 else {
127 if (!thematcher.IsNull()) txt = thematcher->Value (ent,model);
128 else txt = thecounter->ComputedSign (ent,G);
129
130 Standard_Integer val = atoi(txt);
131 Standard_Integer lav = atoi (signtext);
132 switch (jmod) {
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;
138 }
139 }
140 if ((imod == 1 || imod == 3) && quid) res = Standard_True;
141 if ((imod == 2 || imod == 4) && quid) res = Standard_False;
142 }
143 return res;
144}
145
146 Standard_Boolean IFSelect_SelectSignature::Sort
35e08fe8 147 (const Standard_Integer , const Handle(Standard_Transient)& /*ent*/,
148 const Handle(Interface_InterfaceModel)& /*model*/) const
7fd59977 149{ return Standard_True; }
150
151 const TCollection_AsciiString& IFSelect_SelectSignature::SignatureText () const
152 { return thesigntext; }
153
154 Standard_Boolean IFSelect_SelectSignature::IsExact () const
155 { return (theexact < 0); }
156
157 TCollection_AsciiString IFSelect_SelectSignature::ExtractLabel () const
158{
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);
166 return lab;
167}