7fd59977 |
1 | #include <StepSelect_FloatFormat.ixx> |
2 | #include <Interface_FloatWriter.hxx> |
3 | #include <stdio.h> |
4 | |
5 | |
6 | |
7 | StepSelect_FloatFormat::StepSelect_FloatFormat () |
8 | : thezerosup (Standard_True) , themainform ("%E") , |
9 | theformrange ("%f") , therangemin (0.1) , therangemax (1000.) |
10 | { } |
11 | |
12 | void StepSelect_FloatFormat::SetDefault (const Standard_Integer digits) |
13 | { |
14 | themainform.Clear(); |
15 | theformrange.Clear(); |
16 | if (digits <= 0) { |
17 | themainform.AssignCat ("%E"); |
18 | theformrange.AssignCat ("%f"); |
19 | } else { |
20 | char format[20]; |
21 | char pourcent = '%'; char point = '.'; |
22 | sprintf(format, "%c%d%c%dE",pourcent,digits+2,point,digits); |
23 | themainform.AssignCat (format); |
24 | sprintf(format, "%c%d%c%df",pourcent,digits+2,point,digits); |
25 | theformrange.AssignCat (format); |
26 | } |
27 | therangemin = 0.1; therangemax = 1000.; |
28 | thezerosup = Standard_True; |
29 | } |
30 | |
31 | void StepSelect_FloatFormat::SetZeroSuppress (const Standard_Boolean mode) |
32 | { thezerosup = mode; } |
33 | |
34 | void StepSelect_FloatFormat::SetFormat (const Standard_CString format) |
35 | { themainform.Clear(); themainform.AssignCat(format); } |
36 | |
37 | |
38 | void StepSelect_FloatFormat::SetFormatForRange |
39 | (const Standard_CString form, const Standard_Real R1, const Standard_Real R2) |
40 | { |
41 | theformrange.Clear(); theformrange.AssignCat(form); |
42 | therangemin = R1; therangemax = R2; |
43 | } |
44 | |
45 | void StepSelect_FloatFormat::Format |
46 | (Standard_Boolean& zerosup, TCollection_AsciiString& mainform, |
47 | Standard_Boolean& hasrange, TCollection_AsciiString& formrange, |
48 | Standard_Real& rangemin, Standard_Real& rangemax) const |
49 | { |
50 | zerosup = thezerosup; |
51 | mainform = themainform; |
52 | hasrange = (theformrange.Length() > 0); |
53 | formrange = theformrange; |
54 | rangemin = therangemin; |
55 | rangemax = therangemax; |
56 | } |
57 | |
58 | |
59 | void StepSelect_FloatFormat::Perform |
60 | (IFSelect_ContextWrite& ctx, |
61 | StepData_StepWriter& writer) const |
62 | { |
63 | writer.FloatWriter().SetFormat (themainform.ToCString()); |
64 | writer.FloatWriter().SetZeroSuppress (thezerosup); |
65 | if (theformrange.Length() > 0) writer.FloatWriter().SetFormatForRange |
66 | (theformrange.ToCString(), therangemin, therangemax); |
67 | } |
68 | |
69 | TCollection_AsciiString StepSelect_FloatFormat::Label () const |
70 | { |
71 | TCollection_AsciiString lab("Float Format "); |
72 | if (thezerosup) lab.AssignCat(" ZeroSuppress"); |
73 | lab.AssignCat (themainform); |
74 | if (theformrange.Length() > 0) { |
75 | char mess[30]; |
76 | sprintf(mess,", in range %f %f %s", |
77 | therangemin,therangemax,theformrange.ToCString()); |
78 | lab.AssignCat(mess); |
79 | } |
80 | return lab; |
81 | } |