1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <IFSelect_ContextWrite.hxx>
16 #include <Interface_FloatWriter.hxx>
17 #include <Standard_Type.hxx>
18 #include <StepData_StepWriter.hxx>
19 #include <StepSelect_FloatFormat.hxx>
20 #include <TCollection_AsciiString.hxx>
23 StepSelect_FloatFormat::StepSelect_FloatFormat ()
24 : thezerosup (Standard_True) , themainform ("%E") ,
25 theformrange ("%f") , therangemin (0.1) , therangemax (1000.)
28 void StepSelect_FloatFormat::SetDefault (const Standard_Integer digits)
33 themainform.AssignCat ("%E");
34 theformrange.AssignCat ("%f");
37 char pourcent = '%'; char point = '.';
38 Sprintf(format, "%c%d%c%dE",pourcent,digits+2,point,digits);
39 themainform.AssignCat (format);
40 Sprintf(format, "%c%d%c%df",pourcent,digits+2,point,digits);
41 theformrange.AssignCat (format);
43 therangemin = 0.1; therangemax = 1000.;
44 thezerosup = Standard_True;
47 void StepSelect_FloatFormat::SetZeroSuppress (const Standard_Boolean mode)
48 { thezerosup = mode; }
50 void StepSelect_FloatFormat::SetFormat (const Standard_CString format)
51 { themainform.Clear(); themainform.AssignCat(format); }
54 void StepSelect_FloatFormat::SetFormatForRange
55 (const Standard_CString form, const Standard_Real R1, const Standard_Real R2)
57 theformrange.Clear(); theformrange.AssignCat(form);
58 therangemin = R1; therangemax = R2;
61 void StepSelect_FloatFormat::Format
62 (Standard_Boolean& zerosup, TCollection_AsciiString& mainform,
63 Standard_Boolean& hasrange, TCollection_AsciiString& formrange,
64 Standard_Real& rangemin, Standard_Real& rangemax) const
67 mainform = themainform;
68 hasrange = (theformrange.Length() > 0);
69 formrange = theformrange;
70 rangemin = therangemin;
71 rangemax = therangemax;
75 void StepSelect_FloatFormat::Perform
76 (IFSelect_ContextWrite& /*ctx*/,
77 StepData_StepWriter& writer) const
79 writer.FloatWriter().SetFormat (themainform.ToCString());
80 writer.FloatWriter().SetZeroSuppress (thezerosup);
81 if (theformrange.Length() > 0) writer.FloatWriter().SetFormatForRange
82 (theformrange.ToCString(), therangemin, therangemax);
85 TCollection_AsciiString StepSelect_FloatFormat::Label () const
87 TCollection_AsciiString lab("Float Format ");
88 if (thezerosup) lab.AssignCat(" ZeroSuppress");
89 lab.AssignCat (themainform);
90 if (theformrange.Length() > 0) {
92 Sprintf(mess,", in range %f %f %s",
93 therangemin,therangemax,theformrange.ToCString());