0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / StepSelect / StepSelect_FloatFormat.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14
42cf5bc1 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>
7fd59977 21
42cf5bc1 22#include <stdio.h>
92efcf78 23IMPLEMENT_STANDARD_RTTIEXT(StepSelect_FloatFormat,StepSelect_FileModifier)
24
b311480e 25StepSelect_FloatFormat::StepSelect_FloatFormat ()
7fd59977 26 : thezerosup (Standard_True) , themainform ("%E") ,
27 theformrange ("%f") , therangemin (0.1) , therangemax (1000.)
28 { }
29
30 void StepSelect_FloatFormat::SetDefault (const Standard_Integer digits)
31{
32 themainform.Clear();
33 theformrange.Clear();
34 if (digits <= 0) {
35 themainform.AssignCat ("%E");
36 theformrange.AssignCat ("%f");
37 } else {
38 char format[20];
39 char pourcent = '%'; char point = '.';
91322f44 40 Sprintf(format, "%c%d%c%dE",pourcent,digits+2,point,digits);
7fd59977 41 themainform.AssignCat (format);
91322f44 42 Sprintf(format, "%c%d%c%df",pourcent,digits+2,point,digits);
7fd59977 43 theformrange.AssignCat (format);
44 }
45 therangemin = 0.1; therangemax = 1000.;
46 thezerosup = Standard_True;
47}
48
49 void StepSelect_FloatFormat::SetZeroSuppress (const Standard_Boolean mode)
50 { thezerosup = mode; }
51
52 void StepSelect_FloatFormat::SetFormat (const Standard_CString format)
53 { themainform.Clear(); themainform.AssignCat(format); }
54
55
56 void StepSelect_FloatFormat::SetFormatForRange
57 (const Standard_CString form, const Standard_Real R1, const Standard_Real R2)
58{
59 theformrange.Clear(); theformrange.AssignCat(form);
60 therangemin = R1; therangemax = R2;
61}
62
63 void StepSelect_FloatFormat::Format
64 (Standard_Boolean& zerosup, TCollection_AsciiString& mainform,
65 Standard_Boolean& hasrange, TCollection_AsciiString& formrange,
66 Standard_Real& rangemin, Standard_Real& rangemax) const
67{
68 zerosup = thezerosup;
69 mainform = themainform;
70 hasrange = (theformrange.Length() > 0);
71 formrange = theformrange;
72 rangemin = therangemin;
73 rangemax = therangemax;
74}
75
76
77 void StepSelect_FloatFormat::Perform
35e08fe8 78 (IFSelect_ContextWrite& /*ctx*/,
7fd59977 79 StepData_StepWriter& writer) const
80{
81 writer.FloatWriter().SetFormat (themainform.ToCString());
82 writer.FloatWriter().SetZeroSuppress (thezerosup);
83 if (theformrange.Length() > 0) writer.FloatWriter().SetFormatForRange
84 (theformrange.ToCString(), therangemin, therangemax);
85}
86
87 TCollection_AsciiString StepSelect_FloatFormat::Label () const
88{
89 TCollection_AsciiString lab("Float Format ");
90 if (thezerosup) lab.AssignCat(" ZeroSuppress");
91 lab.AssignCat (themainform);
92 if (theformrange.Length() > 0) {
93 char mess[30];
91322f44 94 Sprintf(mess,", in range %f %f %s",
7fd59977 95 therangemin,therangemax,theformrange.ToCString());
96 lab.AssignCat(mess);
97 }
98 return lab;
99}