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 <StepSelect_FloatFormat.ixx> |
19 | #include <Interface_FloatWriter.hxx> |
20 | #include <stdio.h> |
21 | |
22 | |
23 | |
b311480e |
24 | StepSelect_FloatFormat::StepSelect_FloatFormat () |
7fd59977 |
25 | : thezerosup (Standard_True) , themainform ("%E") , |
26 | theformrange ("%f") , therangemin (0.1) , therangemax (1000.) |
27 | { } |
28 | |
29 | void StepSelect_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 StepSelect_FloatFormat::SetZeroSuppress (const Standard_Boolean mode) |
49 | { thezerosup = mode; } |
50 | |
51 | void StepSelect_FloatFormat::SetFormat (const Standard_CString format) |
52 | { themainform.Clear(); themainform.AssignCat(format); } |
53 | |
54 | |
55 | void StepSelect_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 StepSelect_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 StepSelect_FloatFormat::Perform |
77 | (IFSelect_ContextWrite& ctx, |
78 | StepData_StepWriter& 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 StepSelect_FloatFormat::Label () const |
87 | { |
88 | TCollection_AsciiString lab("Float Format "); |
89 | if (thezerosup) lab.AssignCat(" ZeroSuppress"); |
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 | } |
97 | return lab; |
98 | } |