0028449: Data Exchange - Wrong orientation of Annotation Plane in GD&T
[occt.git] / src / TestTopOpeTools / TestTopOpeTools_Trace.cxx
1 // Created on: 1994-08-01
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TestTopOpeTools_Trace.hxx>
18
19 TestTopOpeTools_Trace::TestTopOpeTools_Trace
20 (const Standard_Integer nbmaxentry,
21  const TCollection_AsciiString& genre) :
22  mygenre(genre),
23  myfirstentry(1),mynbmaxentry(nbmaxentry),mynbentries(0),
24  myflag(myfirstentry,mynbmaxentry), 
25  myftyp(myfirstentry,mynbmaxentry),
26  myverbose(Standard_False),
27  myfverbose(myfirstentry,mynbmaxentry)
28 {}
29
30 TestTopOpeTools_Trace::TestTopOpeTools_Trace
31 (const Standard_Integer nbmaxentry) :
32 mygenre("flag"),
33 myfirstentry(1),mynbmaxentry(nbmaxentry),mynbentries(0),
34 myflag(myfirstentry,mynbmaxentry), 
35 myftyp(myfirstentry,mynbmaxentry),
36 myverbose(Standard_False),
37 myfverbose(myfirstentry,mynbmaxentry)
38 {}
39
40 Standard_Integer TestTopOpeTools_Trace::Add
41 (const t_flag flag,tf_value func)
42 { return Add(flag,(tf_value)func,te_value); }
43
44 Standard_Integer TestTopOpeTools_Trace::SetVerbose
45 (const Standard_Boolean b)
46 { myverbose = b; return 0;}
47
48 Standard_Integer TestTopOpeTools_Trace::SetVerbose
49 (const t_flag flag,const Standard_Boolean b)
50
51   Standard_Integer index = 0;
52   if ( !Exist(flag,index) ) return 1;
53   if (b) cout<<"set "<<mygenre<<" "<<flag<<" verbose"<<endl;
54   else   cout<<"set "<<mygenre<<" "<<flag<<" not verbose"<<endl;
55   myfverbose.SetValue(index,b);
56   return 0;
57 }
58
59 Standard_Integer TestTopOpeTools_Trace::Set
60 (const Standard_Integer mute,const t_flag flag,const t_value value)
61
62   Standard_Integer index = 0;
63   if ( !Exist(flag,index) ) return 1;
64   if (mute==0) {
65     if (value) cout<<"activation de "<<mygenre<<" "<<flag<<endl;
66     else       cout<<"desactivation de "<<mygenre<<" "<<flag<<endl;
67   }
68   (*((tf_value)Getfunc(index)))(value);
69   return 0;
70 }
71
72 Standard_Integer TestTopOpeTools_Trace::Add
73 (const t_flag flag,tf_intarg func)
74 { return Add(flag,(tf_value)func,te_intarg); }
75
76 Standard_Integer TestTopOpeTools_Trace::Add
77 (const t_flag flag,tf_int_intarg func)
78 { return Add(flag,(tf_value)func,te_int_intarg); }
79
80 Standard_Integer TestTopOpeTools_Trace::Set
81 (const Standard_Integer mute,const t_flag flag, const t_value value,
82  Standard_Integer n, const char** a)
83
84   Standard_Integer index = 0;
85   if ( !Exist(flag,index) ) return 1;
86   if      ( Getftyp(index) == te_intarg ) {
87     (*((tf_intarg)Getfunc(index)))(value,n,a);
88     if (mute==0) {
89       cout<<mygenre<<" "<<flag<<" active avec :";
90       cout<<" "<<value;
91       for(Standard_Integer i=0;i<n;i++) cout<<" "<<a[i];
92       cout<<endl;
93     }
94   }
95   else if ( Getftyp(index) == te_int_intarg ) {
96     Standard_Integer err = (*((tf_int_intarg)Getfunc(index)))(value,n,a);
97     if (err) {
98       cout<<"ERREUR activation de "<<mygenre<<" "<<flag<<" "<<value;
99       for(Standard_Integer i=0;i<n;i++) cout<<" "<<a[i];cout<<endl;
100     }
101     else {
102       if (mute==0) {
103         cout<<mygenre<<" "<<flag<<" active avec :";
104         cout<<" "<<value;
105         for(Standard_Integer i=0;i<n;i++) cout<<" "<<a[i];
106         cout<<endl;
107       }
108     }
109   }
110   else if ( Getftyp(index) == te_value ) {
111     return Set(mute,flag,value);
112   }
113   else {
114     cout<<"TestTopOpeTools_Trace::Set : unknown function type"<<endl;
115     return 1;
116   }
117   return 0;
118 }
119
120 void TestTopOpeTools_Trace::Dump()
121
122   for (Standard_Integer i=myfirstentry; i<=mynbentries; i++) {
123     if (i==myfirstentry) cout<<"Defined "<<mygenre<<"s :";
124     cout<<" "<<Getflag(i);
125     if (i==mynbentries) cout<<endl;
126   }
127 }
128
129 void TestTopOpeTools_Trace::Reset(const t_value value)
130 {
131   for (Standard_Integer i=myfirstentry;i<=mynbentries;i++)
132     if      (Getftyp(i)==te_value)
133       (*((tf_value)Getfunc(i)))(value);
134     else if (Getftyp(i)==te_intarg)
135       (*((tf_intarg)Getfunc(i)))(value,0,NULL);    
136     else if (Getftyp(i)==te_int_intarg)
137       (*((tf_int_intarg)Getfunc(i)))(value,0,NULL);    
138 }
139
140 // ==== Private
141
142 Standard_Boolean TestTopOpeTools_Trace::Exist
143 (const t_flag flag, Standard_Integer& index)
144
145   for (Standard_Integer i=myfirstentry; i<=mynbentries; i++)
146     if (myflag.Value(i).IsEqual(flag)) { index = i; return Standard_True; }
147   return Standard_False;         
148 }
149
150 Standard_Boolean TestTopOpeTools_Trace::Exist
151 (const tf_value func, Standard_Integer& index)
152
153   for (Standard_Integer i=myfirstentry; i<=mynbentries; i++)
154     if (myfunc.Value(i) == func) { index = i; return Standard_True; }
155   return Standard_False;
156 }
157
158 const t_flag TestTopOpeTools_Trace::Getflag(const Standard_Integer index)
159 { return (t_flag)myflag.Value(index); }
160
161 tf_value TestTopOpeTools_Trace::Getfunc(const Standard_Integer index)
162 { return myfunc.Value(index); }
163
164 te_ftyp TestTopOpeTools_Trace::Getftyp(const Standard_Integer index)
165 {
166 //JR/Hp :
167   Standard_Integer intenum = myftyp.Value(index);
168   return (te_ftyp) intenum ;
169 //  return (te_ftyp) myftyp.Value(index);
170 }
171
172 Standard_Integer TestTopOpeTools_Trace::Add
173 (const t_flag flag, const tf_value func, const te_ftyp ftyp)
174
175   Standard_Integer index;
176   if ( Exist(flag,index) || ( mynbentries >= mynbmaxentry) ) return 1;
177   mynbentries++;
178   myflag.SetValue(mynbentries,flag);
179   myfunc.SetValue(mynbentries,func);
180   myftyp.SetValue(mynbentries,(Standard_Integer)ftyp);
181   myfverbose.SetValue(mynbentries,Standard_False);
182   return 0;
183 }