0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / IGESSelect / IGESSelect_FloatFormat.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 <IGESSelect_FloatFormat.ixx>
19 #include <Interface_FloatWriter.hxx>
20 #include <stdio.h>
21
22
23
24 IGESSelect_FloatFormat::IGESSelect_FloatFormat ()
25     : thezerosup (Standard_True) , themainform ("%E") ,
26       theformrange ("%f") , therangemin (0.1) , therangemax (1000.)
27       {  }
28
29     void  IGESSelect_FloatFormat::SetDefault (const Standard_Integer digits)
30 {
31   themainform.Clear();
32   theformrange.Clear();
33   if (digits <= 0) {
34     themainform.AssignCat  ("%E");
35     theformrange.AssignCat ("%f");
36   } else {
37     char format[20];
38     char pourcent = '%'; char point = '.';
39     Sprintf(format,  "%c%d%c%dE",pourcent,digits+2,point,digits);
40     themainform.AssignCat  (format);
41     Sprintf(format,  "%c%d%c%df",pourcent,digits+2,point,digits);
42     theformrange.AssignCat (format);
43   }
44   therangemin = 0.1; therangemax = 1000.;
45   thezerosup = Standard_True;
46 }
47
48     void  IGESSelect_FloatFormat::SetZeroSuppress (const Standard_Boolean mode)
49       {  thezerosup = mode;  }
50
51     void  IGESSelect_FloatFormat::SetFormat (const Standard_CString format)
52       {  themainform.Clear();  themainform.AssignCat(format);  }
53
54
55     void  IGESSelect_FloatFormat::SetFormatForRange
56   (const Standard_CString form, const Standard_Real R1, const Standard_Real R2)
57 {
58   theformrange.Clear();  theformrange.AssignCat(form);
59   therangemin = R1;  therangemax = R2;
60 }
61
62     void  IGESSelect_FloatFormat::Format
63   (Standard_Boolean& zerosup,  TCollection_AsciiString& mainform,
64    Standard_Boolean& hasrange, TCollection_AsciiString& formrange,
65    Standard_Real& rangemin,    Standard_Real& rangemax) const
66 {
67   zerosup   = thezerosup;
68   mainform  = themainform;
69   hasrange  = (theformrange.Length() > 0);
70   formrange = theformrange;
71   rangemin  = therangemin;
72   rangemax  = therangemax;
73 }
74
75
76     void  IGESSelect_FloatFormat::Perform
77   (IFSelect_ContextWrite& /*ctx*/,
78    IGESData_IGESWriter& writer) const
79 {
80   writer.FloatWriter().SetFormat (themainform.ToCString());
81   writer.FloatWriter().SetZeroSuppress (thezerosup);
82   if (theformrange.Length() > 0) writer.FloatWriter().SetFormatForRange
83     (theformrange.ToCString(), therangemin, therangemax);
84 }
85
86     TCollection_AsciiString  IGESSelect_FloatFormat::Label () const
87 {
88   TCollection_AsciiString lab("Float Format ");
89   if (thezerosup) lab.AssignCat(" ZeroSup ");
90   lab.AssignCat (themainform);
91   if (theformrange.Length() > 0) {
92     char mess[30];
93 //    Sprintf(mess,", in range %f %f %s",
94 //          therangemin,therangemax,theformrange.ToCString());
95 //    lab.AssignCat(mess);
96 //    ... FloatFormat a droit aussi a un beau format pour son propre compte ...
97     lab.AssignCat (", in range ");
98     Standard_Integer convlen = Interface_FloatWriter::Convert
99       (therangemin,mess,Standard_True,therangemin/2.,therangemax*2.,"%f","%f");
100     mess[convlen] = ' ';  mess[convlen+1] = '\0';
101     lab.AssignCat(mess);
102     convlen = Interface_FloatWriter::Convert
103       (therangemax,mess,Standard_True,therangemin/2.,therangemax*2.,"%f","%f");
104     mess[convlen] = ':';  mess[convlen+1] = '\0';
105     lab.AssignCat(mess);
106     lab.AssignCat(theformrange.ToCString());
107   }
108   return lab;
109 }