0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <Draw.ixx>
23
24#include <TCollection_AsciiString.hxx>
25#include <Units_Token.hxx>
26#include <Units_UnitSentence.hxx>
27#include <Units_TokensSequence.hxx>
28#include <UnitsAPI.hxx>
29#include <Units.hxx>
30#include <Units_UnitsDictionary.hxx>
31
32
33//=======================================================================
34//function : parsing
35//purpose : parsing of unit's expression
36//=======================================================================
37static Standard_Integer parsing
38 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
39{
40 if (argc < 2) {
41 di << "Usage : " << argv[0] << " string [nbiter]" << "\n";
42 return 1;
43 }
44
45 TCollection_AsciiString aStrTok(argv[1]);
46 Standard_Integer nbIter =1;
47 if(argc >2)
91322f44 48 nbIter = Draw::Atoi(argv[2]);
7fd59977 49 UnitsAPI::SetLocalSystem();
50 Handle(Units_Token) atoken;
51 Units_UnitSentence aUnitSent(aStrTok.ToCString());
52
53 if(!aUnitSent.IsDone()) {
54 di<<"can not create a sentence"<<"\n";
55 return 1;
56 }
57
58 Standard_Integer i =1;
59 for( ; i <= nbIter; i++) {
60 aUnitSent.Analyse();
61 //aUnitSent.Dump();
62 Handle(Units_TokensSequence) aseq = aUnitSent.Sequence();
63 }
64 atoken = aUnitSent.Evaluate();
65 di<<"Token word : "<<atoken->Word().ToCString()<<"\n";
66 return 0;
67}
68
69
70//=======================================================================
71//function : unitsdico
72//purpose : dump dictionary of units
73//=======================================================================
74static Standard_Integer unitsdico
75 (Draw_Interpretor& /* di */, Standard_Integer /*argc*/, const char** /*argv*/)
76{
77 UnitsAPI::SetLocalSystem();
78 Standard_Integer mode = 2;
79 Units::DictionaryOfUnits(Standard_False)->Dump(mode);
80 return 0;
81}
82
83
84//=======================================================================
85//function : converttoSI
86//purpose :
87//=======================================================================
88static Standard_Integer converttoSI
89 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
90{
91 if (argc < 3) {
92 di<<"Invalid number of parameter, use: unitconvtoSI real string"<<"\n";
93 return 1;
94 }
95
91322f44 96 Standard_Real aData = Draw::Atof(argv[1]);
7fd59977 97 Standard_CString aUnit = argv[2];
98
99 Standard_Real res = UnitsAPI::AnyToSI(aData,aUnit);
100 di<<"result: "<<res<<"\n";
101
102 return 0;
103}
104
105
106//=======================================================================
107//function : converttoMDTV
108//purpose :
109//=======================================================================
110static Standard_Integer converttoMDTV
111 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
112{
113 if (argc < 3) {
114 di<<"Invalid number of parameter, use: unitconvtoMDTV real string"<<"\n";
115 return 1;
116 }
117
91322f44 118 Standard_Real aData = Draw::Atof(argv[1]);
7fd59977 119 Standard_CString aUnit = argv[2];
120
121 UnitsAPI::SetLocalSystem(UnitsAPI_MDTV);
122 Standard_Real res = UnitsAPI::AnyToLS(aData,aUnit);
123 di<<"result: "<<res<<"\n";
124
125 return 0;
126}
127
128
129//=======================================================================
130//function : unit
131//purpose :
132//=======================================================================
133
134static Standard_Integer unit(Draw_Interpretor& , Standard_Integer n, const char** a)
135{
136 if(n == 4) {
91322f44 137 cout << Units::Convert(Draw::Atof(a[1]), a[2], a[3]) << endl;
7fd59977 138 return 0;
139 }
140 else
141 return 1;
142}
143
144
145//=======================================================================
146//function : UnitCommands
147//purpose :
148//=======================================================================
149
150void Draw::UnitCommands(Draw_Interpretor& theCommands)
151{
152 static Standard_Boolean Done = Standard_False;
153 if (Done) return;
154 Done = Standard_True;
155
156 const char* g = "DRAW Unit Commands";
157
158 theCommands.Add("unitparsing", "unitparsing string [nbiter]",
159 __FILE__,parsing,g);
160 theCommands.Add("unitsdico","unitsdico",
161 __FILE__,unitsdico,g);
162 theCommands.Add("unitconvtoSI","unitconvtoSI real string",
163 __FILE__,converttoSI,g);
164 theCommands.Add("unitconvtoMDTV","unitconvtoMDTV real string",
165 __FILE__,converttoMDTV,g);
166 theCommands.Add("unit","unit value unitfrom unitto",
167 __FILE__,unit,g);
168}