0024023: Revamp the OCCT Handle -- general
[occt.git] / src / IGESSelect / IGESSelect_FloatFormat.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <IGESSelect_FloatFormat.ixx>
15 #include <Interface_FloatWriter.hxx>
16 #include <stdio.h>
17
18
19
20 IGESSelect_FloatFormat::IGESSelect_FloatFormat ()
21     : thezerosup (Standard_True) , themainform ("%E") ,
22       theformrange ("%f") , therangemin (0.1) , therangemax (1000.)
23       {  }
24
25     void  IGESSelect_FloatFormat::SetDefault (const Standard_Integer digits)
26 {
27   themainform.Clear();
28   theformrange.Clear();
29   if (digits <= 0) {
30     themainform.AssignCat  ("%E");
31     theformrange.AssignCat ("%f");
32   } else {
33     char format[20];
34     char pourcent = '%'; char point = '.';
35     Sprintf(format,  "%c%d%c%dE",pourcent,digits+2,point,digits);
36     themainform.AssignCat  (format);
37     Sprintf(format,  "%c%d%c%df",pourcent,digits+2,point,digits);
38     theformrange.AssignCat (format);
39   }
40   therangemin = 0.1; therangemax = 1000.;
41   thezerosup = Standard_True;
42 }
43
44     void  IGESSelect_FloatFormat::SetZeroSuppress (const Standard_Boolean mode)
45       {  thezerosup = mode;  }
46
47     void  IGESSelect_FloatFormat::SetFormat (const Standard_CString format)
48       {  themainform.Clear();  themainform.AssignCat(format);  }
49
50
51     void  IGESSelect_FloatFormat::SetFormatForRange
52   (const Standard_CString form, const Standard_Real R1, const Standard_Real R2)
53 {
54   theformrange.Clear();  theformrange.AssignCat(form);
55   therangemin = R1;  therangemax = R2;
56 }
57
58     void  IGESSelect_FloatFormat::Format
59   (Standard_Boolean& zerosup,  TCollection_AsciiString& mainform,
60    Standard_Boolean& hasrange, TCollection_AsciiString& formrange,
61    Standard_Real& rangemin,    Standard_Real& rangemax) const
62 {
63   zerosup   = thezerosup;
64   mainform  = themainform;
65   hasrange  = (theformrange.Length() > 0);
66   formrange = theformrange;
67   rangemin  = therangemin;
68   rangemax  = therangemax;
69 }
70
71
72     void  IGESSelect_FloatFormat::Perform
73   (IFSelect_ContextWrite& /*ctx*/,
74    IGESData_IGESWriter& writer) const
75 {
76   writer.FloatWriter().SetFormat (themainform.ToCString());
77   writer.FloatWriter().SetZeroSuppress (thezerosup);
78   if (theformrange.Length() > 0) writer.FloatWriter().SetFormatForRange
79     (theformrange.ToCString(), therangemin, therangemax);
80 }
81
82     TCollection_AsciiString  IGESSelect_FloatFormat::Label () const
83 {
84   TCollection_AsciiString lab("Float Format ");
85   if (thezerosup) lab.AssignCat(" ZeroSup ");
86   lab.AssignCat (themainform);
87   if (theformrange.Length() > 0) {
88     char mess[30];
89 //    Sprintf(mess,", in range %f %f %s",
90 //          therangemin,therangemax,theformrange.ToCString());
91 //    lab.AssignCat(mess);
92 //    ... FloatFormat a droit aussi a un beau format pour son propre compte ...
93     lab.AssignCat (", in range ");
94     Standard_Integer convlen = Interface_FloatWriter::Convert
95       (therangemin,mess,Standard_True,therangemin/2.,therangemax*2.,"%f","%f");
96     mess[convlen] = ' ';  mess[convlen+1] = '\0';
97     lab.AssignCat(mess);
98     convlen = Interface_FloatWriter::Convert
99       (therangemax,mess,Standard_True,therangemin/2.,therangemax*2.,"%f","%f");
100     mess[convlen] = ':';  mess[convlen+1] = '\0';
101     lab.AssignCat(mess);
102     lab.AssignCat(theformrange.ToCString());
103   }
104   return lab;
105 }