1 // Created on: 1995-02-23
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <Draw_Drawable3D.hxx>
20 #include <Draw_ProgressIndicator.hxx>
21 #include <TCollection_AsciiString.hxx>
23 #include <Units_Token.hxx>
24 #include <Units_TokensSequence.hxx>
25 #include <Units_UnitsDictionary.hxx>
26 #include <Units_UnitSentence.hxx>
27 #include <UnitsAPI.hxx>
29 //=======================================================================
31 //purpose : parsing of unit's expression
32 //=======================================================================
33 static Standard_Integer parsing
34 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
37 di << "Usage : " << argv[0] << " string [nbiter]\n";
41 TCollection_AsciiString aStrTok(argv[1]);
42 Standard_Integer nbIter =1;
44 nbIter = Draw::Atoi(argv[2]);
45 UnitsAPI::SetLocalSystem();
46 Handle(Units_Token) atoken;
47 Units_UnitSentence aUnitSent(aStrTok.ToCString());
49 if(!aUnitSent.IsDone()) {
50 di<<"can not create a sentence\n";
54 Standard_Integer i =1;
55 for( ; i <= nbIter; i++) {
58 Handle(Units_TokensSequence) aseq = aUnitSent.Sequence();
60 atoken = aUnitSent.Evaluate();
61 di<<"Token word : "<<atoken->Word().ToCString()<<"\n";
66 //=======================================================================
67 //function : unitsdico
68 //purpose : dump dictionary of units
69 //=======================================================================
70 static Standard_Integer unitsdico
71 (Draw_Interpretor& /* di */, Standard_Integer /*argc*/, const char** /*argv*/)
73 UnitsAPI::SetLocalSystem();
74 Standard_Integer mode = 2;
75 Units::DictionaryOfUnits(Standard_False)->Dump(mode);
80 //=======================================================================
81 //function : converttoSI
83 //=======================================================================
84 static Standard_Integer converttoSI
85 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
88 di<<"Invalid number of parameter, use: unitconvtoSI real string\n";
92 Standard_Real aData = Draw::Atof(argv[1]);
93 Standard_CString aUnit = argv[2];
95 Standard_Real res = UnitsAPI::AnyToSI(aData,aUnit);
96 di<<"result: "<<res<<"\n";
102 //=======================================================================
103 //function : converttoMDTV
105 //=======================================================================
106 static Standard_Integer converttoMDTV
107 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
110 di<<"Invalid number of parameter, use: unitconvtoMDTV real string\n";
114 Standard_Real aData = Draw::Atof(argv[1]);
115 Standard_CString aUnit = argv[2];
117 UnitsAPI::SetLocalSystem(UnitsAPI_MDTV);
118 Standard_Real res = UnitsAPI::AnyToLS(aData,aUnit);
119 di<<"result: "<<res<<"\n";
125 //=======================================================================
128 //=======================================================================
130 static Standard_Integer unit(Draw_Interpretor& , Standard_Integer n, const char** a)
133 cout << Units::Convert(Draw::Atof(a[1]), a[2], a[3]) << endl;
141 //=======================================================================
142 //function : UnitCommands
144 //=======================================================================
146 void Draw::UnitCommands(Draw_Interpretor& theCommands)
148 static Standard_Boolean Done = Standard_False;
150 Done = Standard_True;
152 const char* g = "DRAW Unit Commands";
154 theCommands.Add("unitparsing", "unitparsing string [nbiter]",
156 theCommands.Add("unitsdico","unitsdico",
157 __FILE__,unitsdico,g);
158 theCommands.Add("unitconvtoSI","unitconvtoSI real string",
159 __FILE__,converttoSI,g);
160 theCommands.Add("unitconvtoMDTV","unitconvtoMDTV real string",
161 __FILE__,converttoMDTV,g);
162 theCommands.Add("unit","unit value unitfrom unitto",