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.
16 #include <Interface_FloatWriter.hxx>
18 Interface_FloatWriter::Interface_FloatWriter (const Standard_Integer chars)
23 // .... Controle d Envoi des Flottants ....
25 void Interface_FloatWriter::SetFormat
26 (const Standard_CString form, const Standard_Boolean reset)
28 strcpy(themainform,form);
30 therange1 = therange2 = 0.; // second form : inhibee
31 thezerosup = Standard_False;
34 void Interface_FloatWriter::SetFormatForRange
35 (const Standard_CString form,
36 const Standard_Real R1, const Standard_Real R2)
38 strcpy(therangeform,form);
43 void Interface_FloatWriter::SetZeroSuppress (const Standard_Boolean mode)
44 { thezerosup = mode; }
46 void Interface_FloatWriter::SetDefaults (const Standard_Integer chars)
49 strcpy(themainform ,"%E");
50 strcpy(therangeform ,"%f");
52 char pourcent = '%'; char point = '.';
53 Sprintf(themainform, "%c%d%c%dE",pourcent,chars+2,point,chars);
54 Sprintf(therangeform, "%c%d%c%df",pourcent,chars+2,point,chars);
56 therange1 = 0.1; therange2 = 1000.;
57 thezerosup = Standard_True;
60 void Interface_FloatWriter::Options
61 (Standard_Boolean& zerosup, Standard_Boolean& range,
62 Standard_Real& R1, Standard_Real& R2) const
65 range = (therange2 >= therange1 && therange1 >= 0.);
70 Standard_CString Interface_FloatWriter::MainFormat () const
71 { const Standard_CString mainform = Standard_CString(&themainform[0]); return mainform; }
73 Standard_CString Interface_FloatWriter::FormatForRange () const
74 { const Standard_CString rangeform = Standard_CString(&therangeform[0]); return rangeform; }
76 // ########################################################################
78 Standard_Integer Interface_FloatWriter::Write
79 (const Standard_Real val, const Standard_CString text) const
81 const Standard_CString mainform = Standard_CString(themainform);
82 const Standard_CString rangeform = Standard_CString(therangeform);
84 (val,text,thezerosup,therange1,therange2,mainform,rangeform);
87 //=======================================================================
90 //=======================================================================
91 Standard_Integer Interface_FloatWriter::Convert (const Standard_Real val,
92 const Standard_CString text,
93 const Standard_Boolean zsup,
94 const Standard_Real R1,
95 const Standard_Real R2,
96 const Standard_CString mainform,
97 const Standard_CString rangeform)
99 // Valeur flottante, expurgee de "0000" qui trainent et de "E+00"
100 const Standard_Integer anMasSize = 5; // change 6 to 5: index 5 is not used below
101 char lxp[anMasSize], *pText;
104 for (Standard_Integer i = 0; i < anMasSize; ++i)
109 if ( (val >= R1 && val < R2) || (val <= -R1 && val > -R2) )
110 Sprintf(pText,rangeform,val);
112 Sprintf(pText,mainform,val);
116 for (int i = 0; i < 16; i ++)
119 if (text[i] == 'e' || text[i] == 'E')
127 if (lxp[1] == '+' && lxp[2] == '0' && lxp[3] == '0' && lxp[4] == '\0')
132 if (text[i] == '\0') break;
134 //#52 rln 23.12.98 converting 1e-07 throws exception
135 for (int j = i0-1; j >= 0; j --)
145 pText[j0+1] = lxp[0];
146 pText[j0+2] = lxp[1];
147 pText[j0+3] = lxp[2];
148 pText[j0+4] = lxp[3];
149 pText[j0+5] = lxp[4];
152 return (Standard_Integer)strlen(text);