0023042: Potential mistakes in (s)printf usage
[occt.git] / src / IFSelect / IFSelect_ContextWrite.cxx
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
18 #include <IFSelect_ContextWrite.ixx>
19 #include <Standard_NoSuchObject.hxx>
20
21
22 //=======================================================================
23 //function : IFSelect_ContextWrite
24 //purpose  : 
25 //=======================================================================
26
27 IFSelect_ContextWrite::IFSelect_ContextWrite
28   (const Handle(Interface_InterfaceModel)& model,
29    const Handle(Interface_Protocol)& proto,
30    const Handle(IFSelect_AppliedModifiers)& applieds,
31    const Standard_CString filename)
32     : themodel (model) , theproto (proto) , thefile (filename) ,
33       theapply (applieds) , thenumod(0) , thenbent (0) , thecurr (0)      {  }
34
35
36 //=======================================================================
37 //function : IFSelect_ContextWrite
38 //purpose  : 
39 //=======================================================================
40
41 IFSelect_ContextWrite::IFSelect_ContextWrite
42   (const Handle(Interface_HGraph)& hgraph,
43    const Handle(Interface_Protocol)& proto,
44    const Handle(IFSelect_AppliedModifiers)& applieds,
45    const Standard_CString filename)
46     : themodel (hgraph->Graph().Model()) ,
47       theproto (proto)   , thefile (filename) , theapply (applieds) , 
48       thehgraf (hgraph) , thenumod(0) , thenbent (0) , thecurr (0)      {  }
49
50
51 //=======================================================================
52 //function : Model
53 //purpose  : 
54 //=======================================================================
55
56 Handle(Interface_InterfaceModel)  IFSelect_ContextWrite::Model () const
57 {
58   return themodel;
59 }
60
61
62 //=======================================================================
63 //function : Protocol
64 //purpose  : 
65 //=======================================================================
66
67 Handle(Interface_Protocol)  IFSelect_ContextWrite::Protocol () const
68 {
69   return theproto;
70 }
71
72
73 //=======================================================================
74 //function : FileName
75 //purpose  : 
76 //=======================================================================
77
78 Standard_CString  IFSelect_ContextWrite::FileName () const
79 {
80   return thefile.ToCString();
81 }
82
83
84 //=======================================================================
85 //function : AppliedModifiers
86 //purpose  : 
87 //=======================================================================
88
89 Handle(IFSelect_AppliedModifiers)  IFSelect_ContextWrite::AppliedModifiers () const
90 {
91   return theapply;
92 }
93
94
95 //=======================================================================
96 //function : Graph
97 //purpose  : 
98 //=======================================================================
99
100 const Interface_Graph&  IFSelect_ContextWrite::Graph ()
101 {
102   if (thehgraf.IsNull()) thehgraf = new Interface_HGraph(themodel,theproto);
103   return thehgraf->Graph();
104 }
105
106
107 //=======================================================================
108 //function : NbModifiers
109 //purpose  : 
110 //=======================================================================
111
112 Standard_Integer  IFSelect_ContextWrite::NbModifiers () const
113       {  return (theapply.IsNull() ? 0 : theapply->Count());  }
114
115     Standard_Boolean  IFSelect_ContextWrite::SetModifier
116   (const Standard_Integer numod)
117 {
118   themodif.Nullify();  thenumod = thenbent = thecurr = 0;
119   if (theapply.IsNull()) return Standard_False;
120   if (numod < 1 || numod > theapply->Count()) return Standard_False;
121   theapply->Item(numod,themodif,thenbent);
122   return Standard_True;
123 }
124
125
126 //=======================================================================
127 //function : FileModifier
128 //purpose  : 
129 //=======================================================================
130
131 Handle(IFSelect_GeneralModifier)  IFSelect_ContextWrite::FileModifier () const
132 {
133   return themodif;
134 }
135
136
137 //=======================================================================
138 //function : IsForNone
139 //purpose  : 
140 //=======================================================================
141
142 Standard_Boolean  IFSelect_ContextWrite::IsForNone () const
143 {
144   return (thenbent == 0);
145 }
146
147
148 //=======================================================================
149 //function : IsForAll
150 //purpose  : 
151 //=======================================================================
152
153 Standard_Boolean  IFSelect_ContextWrite::IsForAll () const
154 {
155   return theapply->IsForAll();
156 }
157
158
159 //=======================================================================
160 //function : NbEntities
161 //purpose  : 
162 //=======================================================================
163
164 Standard_Integer  IFSelect_ContextWrite::NbEntities () const
165 {
166   return thenbent;
167 }
168
169
170 //=======================================================================
171 //function : Start
172 //purpose  : 
173 //=======================================================================
174
175 void  IFSelect_ContextWrite::Start ()
176 {
177   thecurr = 1;
178 }
179
180
181 //=======================================================================
182 //function : More
183 //purpose  : 
184 //=======================================================================
185
186 Standard_Boolean  IFSelect_ContextWrite::More () const
187 {
188   return (thecurr <= thenbent);
189 }
190
191
192 //=======================================================================
193 //function : Next
194 //purpose  : 
195 //=======================================================================
196
197 void IFSelect_ContextWrite::Next ()
198 {
199   thecurr ++;
200 }
201
202
203 //=======================================================================
204 //function : Value
205 //purpose  : 
206 //=======================================================================
207
208 Handle(Standard_Transient) IFSelect_ContextWrite::Value() const
209 {
210   if (thecurr < 1 || thecurr > thenbent)
211     Standard_NoSuchObject::Raise("IFSelect_ContextWrite:Value");
212   Standard_Integer num = theapply->ItemNum (thecurr);
213   return themodel->Value(num);
214 }
215
216
217 //=======================================================================
218 //function : AddCheck
219 //purpose  : 
220 //=======================================================================
221
222 void IFSelect_ContextWrite::AddCheck (const Handle(Interface_Check)& check)
223 {
224   if (check->NbFails() + check->NbWarnings() == 0) return;
225   const Handle(Standard_Transient)& ent = check->Entity();
226   Standard_Integer num = themodel->Number(ent);
227   if (num == 0 && !ent.IsNull()) num = -1;  // force enregistrement
228   thecheck.Add(check,num);
229 }
230
231
232 //=======================================================================
233 //function : AddWarning
234 //purpose  : 
235 //=======================================================================
236
237 void IFSelect_ContextWrite::AddWarning(const Handle(Standard_Transient)& start,
238                                        const Standard_CString mess,
239                                        const Standard_CString orig)
240 {
241   thecheck.CCheck(themodel->Number(start))->AddWarning(mess,orig);
242 }
243
244
245 //=======================================================================
246 //function : AddFail
247 //purpose  : 
248 //=======================================================================
249
250 void IFSelect_ContextWrite::AddFail(const Handle(Standard_Transient)& start,
251                                     const Standard_CString mess,
252                                     const Standard_CString orig)
253 {
254   thecheck.CCheck(themodel->Number(start))->AddFail(mess,orig);
255 }
256
257
258 //=======================================================================
259 //function : CCheck
260 //purpose  : 
261 //=======================================================================
262
263 Handle(Interface_Check) IFSelect_ContextWrite::CCheck (const Standard_Integer num)
264 {
265   Handle(Interface_Check) ach = thecheck.CCheck(num);
266   if (num > 0 && num <= themodel->NbEntities()) ach->SetEntity(themodel->Value(num));
267   return ach;
268 }
269
270
271 //=======================================================================
272 //function : CCheck
273 //purpose  : 
274 //=======================================================================
275
276 Handle(Interface_Check) IFSelect_ContextWrite::CCheck(const Handle(Standard_Transient)& ent)
277 {
278   Standard_Integer num = themodel->Number(ent);
279   if (num == 0) num = -1;    // force l enregistrement
280   Handle(Interface_Check) ach = thecheck.CCheck(num);
281   ach->SetEntity(ent);
282   return ach;
283 }
284
285
286 //=======================================================================
287 //function : CheckList
288 //purpose  : 
289 //=======================================================================
290
291 Interface_CheckIterator  IFSelect_ContextWrite::CheckList () const
292 {
293   return thecheck;
294 }