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