Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Draw / Draw_UnitCommands.cxx
CommitLineData
7fd59977 1// File: Draw_UnitCommands.cxx
2// Created: Thu Feb 23 18:21:17 1995
3// Author: Remi LEQUETTE
4// <rle@bravox>
5
6#include <Draw.ixx>
7
8#include <TCollection_AsciiString.hxx>
9#include <Units_Token.hxx>
10#include <Units_UnitSentence.hxx>
11#include <Units_TokensSequence.hxx>
12#include <UnitsAPI.hxx>
13#include <Units.hxx>
14#include <Units_UnitsDictionary.hxx>
15
16
17//=======================================================================
18//function : parsing
19//purpose : parsing of unit's expression
20//=======================================================================
21static Standard_Integer parsing
22 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
23{
24 if (argc < 2) {
25 di << "Usage : " << argv[0] << " string [nbiter]" << "\n";
26 return 1;
27 }
28
29 TCollection_AsciiString aStrTok(argv[1]);
30 Standard_Integer nbIter =1;
31 if(argc >2)
32 nbIter = atoi(argv[2]);
33 UnitsAPI::SetLocalSystem();
34 Handle(Units_Token) atoken;
35 Units_UnitSentence aUnitSent(aStrTok.ToCString());
36
37 if(!aUnitSent.IsDone()) {
38 di<<"can not create a sentence"<<"\n";
39 return 1;
40 }
41
42 Standard_Integer i =1;
43 for( ; i <= nbIter; i++) {
44 aUnitSent.Analyse();
45 //aUnitSent.Dump();
46 Handle(Units_TokensSequence) aseq = aUnitSent.Sequence();
47 }
48 atoken = aUnitSent.Evaluate();
49 di<<"Token word : "<<atoken->Word().ToCString()<<"\n";
50 return 0;
51}
52
53
54//=======================================================================
55//function : unitsdico
56//purpose : dump dictionary of units
57//=======================================================================
58static Standard_Integer unitsdico
59 (Draw_Interpretor& /* di */, Standard_Integer /*argc*/, const char** /*argv*/)
60{
61 UnitsAPI::SetLocalSystem();
62 Standard_Integer mode = 2;
63 Units::DictionaryOfUnits(Standard_False)->Dump(mode);
64 return 0;
65}
66
67
68//=======================================================================
69//function : converttoSI
70//purpose :
71//=======================================================================
72static Standard_Integer converttoSI
73 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
74{
75 if (argc < 3) {
76 di<<"Invalid number of parameter, use: unitconvtoSI real string"<<"\n";
77 return 1;
78 }
79
80 Standard_Real aData = atof(argv[1]);
81 Standard_CString aUnit = argv[2];
82
83 Standard_Real res = UnitsAPI::AnyToSI(aData,aUnit);
84 di<<"result: "<<res<<"\n";
85
86 return 0;
87}
88
89
90//=======================================================================
91//function : converttoMDTV
92//purpose :
93//=======================================================================
94static Standard_Integer converttoMDTV
95 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
96{
97 if (argc < 3) {
98 di<<"Invalid number of parameter, use: unitconvtoMDTV real string"<<"\n";
99 return 1;
100 }
101
102 Standard_Real aData = atof(argv[1]);
103 Standard_CString aUnit = argv[2];
104
105 UnitsAPI::SetLocalSystem(UnitsAPI_MDTV);
106 Standard_Real res = UnitsAPI::AnyToLS(aData,aUnit);
107 di<<"result: "<<res<<"\n";
108
109 return 0;
110}
111
112
113//=======================================================================
114//function : unit
115//purpose :
116//=======================================================================
117
118static Standard_Integer unit(Draw_Interpretor& , Standard_Integer n, const char** a)
119{
120 if(n == 4) {
121 cout << Units::Convert(atof(a[1]), a[2], a[3]) << endl;
122 return 0;
123 }
124 else
125 return 1;
126}
127
128
129//=======================================================================
130//function : UnitCommands
131//purpose :
132//=======================================================================
133
134void Draw::UnitCommands(Draw_Interpretor& theCommands)
135{
136 static Standard_Boolean Done = Standard_False;
137 if (Done) return;
138 Done = Standard_True;
139
140 const char* g = "DRAW Unit Commands";
141
142 theCommands.Add("unitparsing", "unitparsing string [nbiter]",
143 __FILE__,parsing,g);
144 theCommands.Add("unitsdico","unitsdico",
145 __FILE__,unitsdico,g);
146 theCommands.Add("unitconvtoSI","unitconvtoSI real string",
147 __FILE__,converttoSI,g);
148 theCommands.Add("unitconvtoMDTV","unitconvtoMDTV real string",
149 __FILE__,converttoMDTV,g);
150 theCommands.Add("unit","unit value unitfrom unitto",
151 __FILE__,unit,g);
152}