b311480e |
1 | // Created on: 1995-02-23 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <Draw.ixx> |
18 | |
19 | #include <TCollection_AsciiString.hxx> |
20 | #include <Units_Token.hxx> |
21 | #include <Units_UnitSentence.hxx> |
22 | #include <Units_TokensSequence.hxx> |
23 | #include <UnitsAPI.hxx> |
24 | #include <Units.hxx> |
25 | #include <Units_UnitsDictionary.hxx> |
26 | |
27 | |
28 | //======================================================================= |
29 | //function : parsing |
30 | //purpose : parsing of unit's expression |
31 | //======================================================================= |
32 | static Standard_Integer parsing |
33 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
34 | { |
35 | if (argc < 2) { |
36 | di << "Usage : " << argv[0] << " string [nbiter]" << "\n"; |
37 | return 1; |
38 | } |
39 | |
40 | TCollection_AsciiString aStrTok(argv[1]); |
41 | Standard_Integer nbIter =1; |
42 | if(argc >2) |
91322f44 |
43 | nbIter = Draw::Atoi(argv[2]); |
7fd59977 |
44 | UnitsAPI::SetLocalSystem(); |
45 | Handle(Units_Token) atoken; |
46 | Units_UnitSentence aUnitSent(aStrTok.ToCString()); |
47 | |
48 | if(!aUnitSent.IsDone()) { |
49 | di<<"can not create a sentence"<<"\n"; |
50 | return 1; |
51 | } |
52 | |
53 | Standard_Integer i =1; |
54 | for( ; i <= nbIter; i++) { |
55 | aUnitSent.Analyse(); |
56 | //aUnitSent.Dump(); |
57 | Handle(Units_TokensSequence) aseq = aUnitSent.Sequence(); |
58 | } |
59 | atoken = aUnitSent.Evaluate(); |
60 | di<<"Token word : "<<atoken->Word().ToCString()<<"\n"; |
61 | return 0; |
62 | } |
63 | |
64 | |
65 | //======================================================================= |
66 | //function : unitsdico |
67 | //purpose : dump dictionary of units |
68 | //======================================================================= |
69 | static Standard_Integer unitsdico |
70 | (Draw_Interpretor& /* di */, Standard_Integer /*argc*/, const char** /*argv*/) |
71 | { |
72 | UnitsAPI::SetLocalSystem(); |
73 | Standard_Integer mode = 2; |
74 | Units::DictionaryOfUnits(Standard_False)->Dump(mode); |
75 | return 0; |
76 | } |
77 | |
78 | |
79 | //======================================================================= |
80 | //function : converttoSI |
81 | //purpose : |
82 | //======================================================================= |
83 | static Standard_Integer converttoSI |
84 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
85 | { |
86 | if (argc < 3) { |
87 | di<<"Invalid number of parameter, use: unitconvtoSI real string"<<"\n"; |
88 | return 1; |
89 | } |
90 | |
91322f44 |
91 | Standard_Real aData = Draw::Atof(argv[1]); |
7fd59977 |
92 | Standard_CString aUnit = argv[2]; |
93 | |
94 | Standard_Real res = UnitsAPI::AnyToSI(aData,aUnit); |
95 | di<<"result: "<<res<<"\n"; |
96 | |
97 | return 0; |
98 | } |
99 | |
100 | |
101 | //======================================================================= |
102 | //function : converttoMDTV |
103 | //purpose : |
104 | //======================================================================= |
105 | static Standard_Integer converttoMDTV |
106 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
107 | { |
108 | if (argc < 3) { |
109 | di<<"Invalid number of parameter, use: unitconvtoMDTV real string"<<"\n"; |
110 | return 1; |
111 | } |
112 | |
91322f44 |
113 | Standard_Real aData = Draw::Atof(argv[1]); |
7fd59977 |
114 | Standard_CString aUnit = argv[2]; |
115 | |
116 | UnitsAPI::SetLocalSystem(UnitsAPI_MDTV); |
117 | Standard_Real res = UnitsAPI::AnyToLS(aData,aUnit); |
118 | di<<"result: "<<res<<"\n"; |
119 | |
120 | return 0; |
121 | } |
122 | |
123 | |
124 | //======================================================================= |
125 | //function : unit |
126 | //purpose : |
127 | //======================================================================= |
128 | |
129 | static Standard_Integer unit(Draw_Interpretor& , Standard_Integer n, const char** a) |
130 | { |
131 | if(n == 4) { |
91322f44 |
132 | cout << Units::Convert(Draw::Atof(a[1]), a[2], a[3]) << endl; |
7fd59977 |
133 | return 0; |
134 | } |
135 | else |
136 | return 1; |
137 | } |
138 | |
139 | |
140 | //======================================================================= |
141 | //function : UnitCommands |
142 | //purpose : |
143 | //======================================================================= |
144 | |
145 | void Draw::UnitCommands(Draw_Interpretor& theCommands) |
146 | { |
147 | static Standard_Boolean Done = Standard_False; |
148 | if (Done) return; |
149 | Done = Standard_True; |
150 | |
151 | const char* g = "DRAW Unit Commands"; |
152 | |
153 | theCommands.Add("unitparsing", "unitparsing string [nbiter]", |
154 | __FILE__,parsing,g); |
155 | theCommands.Add("unitsdico","unitsdico", |
156 | __FILE__,unitsdico,g); |
157 | theCommands.Add("unitconvtoSI","unitconvtoSI real string", |
158 | __FILE__,converttoSI,g); |
159 | theCommands.Add("unitconvtoMDTV","unitconvtoMDTV real string", |
160 | __FILE__,converttoMDTV,g); |
161 | theCommands.Add("unit","unit value unitfrom unitto", |
162 | __FILE__,unit,g); |
163 | } |