Seamly2D
Code documentation
vtranslatevars.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vtranslatevars.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 10 6, 2015
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "vtranslatevars.h"
53 
54 #include <QList>
55 #include <QLocale>
56 #include <QMap>
57 #include <QMessageLogger>
58 #include <QString>
59 #include <QtDebug>
60 
61 #include "pmsystems.h"
62 #include "vtranslatemeasurements.h"
63 #include "../ifc/ifcdef.h"
64 #include "../vmisc/def.h"
65 #include "../vmisc/vabstractapplication.h"
66 #include "../qmuparser/qmuparsererror.h"
67 #include "../qmuparser/qmutokenparser.h"
68 #include "../qmuparser/qmutranslation.h"
69 #include "../vpatterndb/vtranslatevars.h"
70 
71 //---------------------------------------------------------------------------------------------------------------------
74  PMSystemNames(QMap<QString, qmu::QmuTranslation>()),
75  PMSystemAuthors(QMap<QString, qmu::QmuTranslation>()),
76  PMSystemBooks(QMap<QString, qmu::QmuTranslation>()),
77  variables(QMap<QString, qmu::QmuTranslation>()),
78  functions(QMap<QString, qmu::QmuTranslation>()),
79  postfixOperators(QMap<QString, qmu::QmuTranslation>()),
80  placeholders(QMap<QString, qmu::QmuTranslation>()),
81  stDescriptions(QMap<QString, qmu::QmuTranslation>())
82 {
84  InitVariables();
85  InitFunctions();
88 }
89 
90 //---------------------------------------------------------------------------------------------------------------------
92 {}
93 
94 #define translate(context, source, disambiguation) qmu::QmuTranslation::translate((context), (source), (disambiguation))
95 
96 //---------------------------------------------------------------------------------------------------------------------
98 {
99  //Note. We can't use here function and variables because lupdate tool doesn't see string in variables and doesn't
100  //mark such string to translation.
101  qmu::QmuTranslation name;
102  qmu::QmuTranslation author;
103  qmu::QmuTranslation book;
104 
105  //=================================================================================================================
106  name = translate("VTranslateVars", "Bunka", "System name");
107  author = translate("VTranslateVars", "Bunka Fashion College", "Author name");
108  book = translate("VTranslateVars", "Fundamentals of Garment Design", "Book name");
109  InitSystem(p0_S, name, author, book);
110  //=================================================================================================================
111  name = translate("VTranslateVars", "Barnfield and Richard", "System name");
112  author = translate("VTranslateVars", "Jo Barnfield and Andrew Richards", "Author name");
113  book = translate("VTranslateVars", "Pattern Making Primer", "Book name");
114  InitSystem(p1_S, name, author, book);
115  //=================================================================================================================
116  name = translate("VTranslateVars", "Friendship/Women", "System name");
117  author = translate("VTranslateVars", "Elizabeth Friendship", "Author name");
118  book = translate("VTranslateVars",
119  "Creating Historical Clothes - Pattern Cutting from the 16th to the 19th Centuries", "Book name");
120  InitSystem(p2_S, name, author, book);
121  //=================================================================================================================
122  name = translate("VTranslateVars", "Morris, K.", "System name");
123  author = translate("VTranslateVars", "Karen Morris", "Author name");
124  book = translate("VTranslateVars", "Sewing Lingerie that Fits", "Book name");
125  InitSystem(p3_S, name, author, book);
126  //=================================================================================================================
127  name = translate("VTranslateVars", "Castro", "System name");
128  author = translate("VTranslateVars", "Lucia Mors de Castro", "Author name");
129  book = translate("VTranslateVars", "Patternmaking in Practic", "Book name");
130  InitSystem(p4_S, name, author, book);
131  //=================================================================================================================
132  name = translate("VTranslateVars", "Kim & Uh", "System name");
133  author = translate("VTranslateVars", "Injoo Kim and Mykyung Uh", "Author name");
134  book = translate("VTranslateVars", "Apparel Making in Fashion Design", "Book name");
135  InitSystem(p5_S, name, author, book);
136  //=================================================================================================================
137  name = translate("VTranslateVars", "Waugh", "System name");
138  author = translate("VTranslateVars", "Norah Waugh", "Author name");
139  book = translate("VTranslateVars", "Corsets and Crinolines", "Book name");
140  InitSystem(p6_S, name, author, book);
141  //=================================================================================================================
142  name = translate("VTranslateVars", "Grimble", "System name");
143  author = translate("VTranslateVars", "Frances Grimble", "Author name");
144  book = translate("VTranslateVars", "Fashions of the Gilded Age", "Book name");
145  InitSystem(p7_S, name, author, book);
146  //=================================================================================================================
147  name = translate("VTranslateVars", "Thornton's International System", "System name");
148  author = translate("VTranslateVars", "ed. R. L. Shep", "Author name");
149  book = translate("VTranslateVars", "The Great War: Styles and Patterns of the 1910s", "Book name");
150  InitSystem(p8_S, name, author, book);
151  //=================================================================================================================
152  name = translate("VTranslateVars", "Hillhouse & Mansfield", "System name");
153  author = translate("VTranslateVars", "Marion S. Hillhouse and Evelyn A. Mansfield", "Author name");
154  book = translate("VTranslateVars", "Dress Design: Draping and Flat Pattern Making", "Book name");
155  InitSystem(p9_S, name, author, book);
156  //=================================================================================================================
157  name = translate("VTranslateVars", "Pivnick", "System name");
158  author = translate("VTranslateVars", "Esther Kaplan Pivnick", "Author name");
159  book = translate("VTranslateVars", "How to Design Beautiful Clothes: Designing and Pattern Making", "Book name");
160  InitSystem(p10_S, name, author, book);
161  //=================================================================================================================
162  name = translate("VTranslateVars", "Minister & Son", "System name");
163  author = translate("VTranslateVars", "Edward Minister & Son, ed. R. L. Shep", "Author name");
164  book = translate("VTranslateVars", "The Complete Guide to Practical Cutting (1853)", "Book name");
165  InitSystem(p11_S, name, author, book);
166  //=================================================================================================================
167  name = translate("VTranslateVars", "Strickland", "System name");
168  author = translate("VTranslateVars", "Gertrude Strickland", "Author name");
169  book = translate("VTranslateVars", "A Tailoring Manual", "Book name");
170  InitSystem(p12_S, name, author, book);
171  //=================================================================================================================
172  name = translate("VTranslateVars", "Loh & Lewis", "System name");
173  author = translate("VTranslateVars", "May Loh and Diehl Lewis", "Author name");
174  book = translate("VTranslateVars", "Patternless Fashion Design", "Book name");
175  InitSystem(p13_S, name, author, book);
176  //=================================================================================================================
177  name = translate("VTranslateVars", "Morris, F. R.", "System name");
178  author = translate("VTranslateVars", "F. R. Morris", "Author name");
179  book = translate("VTranslateVars", "Ladies Garment Cutting and Making", "Book name");
180  InitSystem(p14_S, name, author, book);
181  //=================================================================================================================
182  name = translate("VTranslateVars", "Mason", "System name");
183  author = translate("VTranslateVars", "Gertrude Mason", "Author name");
184  book = translate("VTranslateVars", "Gertrude Mason's Patternmaking Book", "Book name");
185  InitSystem(p15_S, name, author, book);
186  //=================================================================================================================
187  name = translate("VTranslateVars", "Kimata", "System name");
188  author = translate("VTranslateVars", "K. Kimata", "Author name");
189  book = translate("VTranslateVars", "K.Kimata's Simplified Drafting Book for Dressmaking", "Book name");
190  InitSystem(p16_S, name, author, book);
191  //=================================================================================================================
192  name = translate("VTranslateVars", "Master Designer", "System name");
193  author = translate("VTranslateVars", "The Master Designer (Chicago, IL)", "Author name");
194  book = translate("VTranslateVars", "Master Designer's System of Designing, Cutting and Grading", "Book name");
195  InitSystem(p17_S, name, author, book);
196  //=================================================================================================================
197  name = translate("VTranslateVars", "Kopp", "System name");
198  author = translate("VTranslateVars", "Ernestine Kopp, Vittorina Rolfo, Beatrice Zelin, Lee Gross", "Author name");
199  book = translate("VTranslateVars", "How to Draft Basic Patterns", "Book name");
200  InitSystem(p18_S, name, author, book);
201  //=================================================================================================================
202  name = translate("VTranslateVars", "Ekern", "System name");
203  author = translate("VTranslateVars", "Doris Ekern", "Author name");
204  book = translate("VTranslateVars", "Slacks Cut-to-Fit for Your Figure", "Book name");
205  InitSystem(p19_S, name, author, book);
206  //=================================================================================================================
207  name = translate("VTranslateVars", "Doyle", "System name");
208  author = translate("VTranslateVars", "Sarah J. Doyle", "Author name");
209  book = translate("VTranslateVars", "Sarah's Key to Pattern Drafting", "Book name");
210  InitSystem(p20_S, name, author, book);
211  //=================================================================================================================
212  name = translate("VTranslateVars", "Shelton", "System name");
213  author = translate("VTranslateVars", "Karla J. Shelton", "Author name");
214  book = translate("VTranslateVars", "Design and Sew Jeans", "Book name");
215  InitSystem(p21_S, name, author, book);
216  //=================================================================================================================
217  name = translate("VTranslateVars", "Lady Boutique", "System name");
218  author = translate("VTranslateVars", "Lady Boutique", "Author name");
219  book = translate("VTranslateVars", "Lady Boutique magazine (Japan)", "Book name");
220  InitSystem(p22_S, name, author, book);
221  //=================================================================================================================
222  name = translate("VTranslateVars", "Rohr", "System name");
223  author = translate("VTranslateVars", "M. Rohr", "Author name");
224  book = translate("VTranslateVars", "Pattern Drafting and Grading: Women's nd Misses' Garment Design", "Book name");
225  InitSystem(p23_S, name, author, book);
226  //=================================================================================================================
227  name = translate("VTranslateVars", "Moore", "System name");
228  author = translate("VTranslateVars", "Dorothy Moore", "Author name");
229  book = translate("VTranslateVars", "Dorothy Moore's Pattern Drafting and Dressmaking", "Book name");
230  InitSystem(p24_S, name, author, book);
231  //=================================================================================================================
232  name = translate("VTranslateVars", "Abling", "System name");
233  author = translate("VTranslateVars", "Bina Abling", "Author name");
234  book = translate("VTranslateVars", "Integrating Draping, Drafting and Drawing", "Book name");
235  InitSystem(p25_S, name, author, book);
236  //=================================================================================================================
237  name = translate("VTranslateVars", "Fukomoto", "System name");
238  author = translate("VTranslateVars", "Sue S. Fukomoto", "Author name");
239  book = translate("VTranslateVars", "Scientific Pattern Drafting as taught at Style Center School of Costume "
240  "Design, Dressmaking and Millinery", "Book name");
241  InitSystem(p26_S, name, author, book);
242  //=================================================================================================================
243  name = translate("VTranslateVars", "Dressmaking International", "System name");
244  author = translate("VTranslateVars", "Dressmaking International", "Author name");
245  book = translate("VTranslateVars", "Dressmaking International magazine (Japan)", "Book name");
246  InitSystem(p27_S, name, author, book);
247  //=================================================================================================================
248  name = translate("VTranslateVars", "Erwin", "System name");
249  author = translate("VTranslateVars", "Mabel D. Erwin", "Author name");
250  book = translate("VTranslateVars", "Practical Dress Design", "Book name");
251  InitSystem(p28_S, name, author, book);
252  //=================================================================================================================
253  name = translate("VTranslateVars", "Gough", "System name");
254  author = translate("VTranslateVars", "E. L. G. Gough", "Author name");
255  book = translate("VTranslateVars", "Principles of Garment Cutting", "Book name");
256  InitSystem(p29_S, name, author, book);
257  //=================================================================================================================
258  name = translate("VTranslateVars", "Allemong", "System name");
259  author = translate("VTranslateVars", "Elizabeth M. Allemong", "Author name");
260  book = translate("VTranslateVars", "European Cut", "Book name");
261  InitSystem(p30_S, name, author, book);
262  //=================================================================================================================
263  name = translate("VTranslateVars", "McCunn", "System name");
264  author = translate("VTranslateVars", "Donald H. McCunn", "Author name");
265  book = translate("VTranslateVars", "How to Make Your Own Sewing Patterns", "Book name");
266  InitSystem(p31_S, name, author, book);
267  //=================================================================================================================
268  name = translate("VTranslateVars", "Zarapkar", "System name");
269  author = translate("VTranslateVars", "Shri K. R. Zarapkar and Shri Arvind K. Zarapkar", "Author name");
270  book = translate("VTranslateVars", "Zarapkar System of Cutting", "Book name");
271  InitSystem(p32_S, name, author, book);
272  //=================================================================================================================
273  name = translate("VTranslateVars", "Kunick", "System name");
274  author = translate("VTranslateVars", "Philip Kunick", "Author name");
275  book = translate("VTranslateVars", "Sizing, Pattern Construction and Grading for Women's and Children's Garments",
276  "Book name");
277  InitSystem(p33_S, name, author, book);
278  //=================================================================================================================
279  name = translate("VTranslateVars", "Handford", "System name");
280  author = translate("VTranslateVars", "Jack Handford", "Author name");
281  book = translate("VTranslateVars", "Professional Patternmaking for Designers: Women's Wear, Men's Casual Wear",
282  "Book name");
283  InitSystem(p34_S, name, author, book);
284  //=================================================================================================================
285  name = translate("VTranslateVars", "Davis", "System name");
286  author = translate("VTranslateVars", "R. I. Davis", "Author name");
287  book = translate("VTranslateVars", "Men's 17th & 18th Century Costume, Cut & Fashion", "Book name");
288  InitSystem(p35_S, name, author, book);
289  //=================================================================================================================
290  name = translate("VTranslateVars", "MacLochlainn", "System name");
291  author = translate("VTranslateVars", "Jason MacLochlainn", "Author name");
292  book = translate("VTranslateVars", "The Victorian Tailor: An Introduction to Period Tailoring", "Book name");
293  InitSystem(p36_S, name, author, book);
294  //=================================================================================================================
295  name = translate("VTranslateVars", "Joseph-Armstrong", "System name");
296  author = translate("VTranslateVars", "Helen Joseph-Armstrong", "Author name");
297  book = translate("VTranslateVars", "Patternmaking for Fashion Design", "Book name");
298  InitSystem(p37_S, name, author, book);
299  //=================================================================================================================
300  name = translate("VTranslateVars", "Supreme System", "System name");
301  author = translate("VTranslateVars", "Frederick T. Croonberg", "Author name");
302  book = translate("VTranslateVars", "The Blue Book of Men's Tailoring, Grand Edition of Supreme System for "
303  "Producing Mens Garments (1907)", "Book name");
304  InitSystem(p38_S, name, author, book);
305  //=================================================================================================================
306  name = translate("VTranslateVars", "Sugino", "System name");
307  author = translate("VTranslateVars", "Dressmaking", "Author name");
308  book = translate("VTranslateVars", "Pattern Drafting Vols. I, II, III (Japan)", "Book name");
309  InitSystem(p39_S, name, author, book);
310  //=================================================================================================================
311  name = translate("VTranslateVars", "Centre Point System", "System name");
312  author = translate("VTranslateVars", "Louis Devere", "Author name");
313  book = translate("VTranslateVars", "The Handbook of Practical Cutting on the Centre Point System", "Book name");
314  InitSystem(p40_S, name, author, book);
315  //=================================================================================================================
316  name = translate("VTranslateVars", "Aldrich/Men", "System name");
317  author = translate("VTranslateVars", "Winifred Aldrich", "Author name");
318  book = translate("VTranslateVars", "Metric Pattern Cutting for Menswear", "Book name");
319  InitSystem(p41_S, name, author, book);
320  //=================================================================================================================
321  name = translate("VTranslateVars", "Aldrich/Women", "System name");
322  author = translate("VTranslateVars", "Winifred Aldrich", "Author name");
323  book = translate("VTranslateVars", "Metric Pattern Cutting for Women's Wear", "Book name");
324  InitSystem(p42_S, name, author, book);
325  //=================================================================================================================
326  name = translate("VTranslateVars", "Kershaw", "System name");
327  author = translate("VTranslateVars", "Gareth Kershaw", "Author name");
328  book = translate("VTranslateVars", "Patternmaking for Menswear", "Book name");
329  InitSystem(p43_S, name, author, book);
330  //=================================================================================================================
331  name = translate("VTranslateVars", "Gilewska", "System name");
332  author = translate("VTranslateVars", "Teresa Gilewska", "Author name");
333  book = translate("VTranslateVars", "Pattern-Drafting for Fashion: The Basics", "Book name");
334  InitSystem(p44_S, name, author, book);
335  //=================================================================================================================
336  name = translate("VTranslateVars", "Lo", "System name");
337  author = translate("VTranslateVars", "Dennic Chunman Lo", "Author name");
338  book = translate("VTranslateVars", "Pattern Cutting", "Book name");
339  InitSystem(p45_S, name, author, book);
340  //=================================================================================================================
341  name = translate("VTranslateVars", "Bray", "System name");
342  author = translate("VTranslateVars", "Natalie Bray", "Author name");
343  book = translate("VTranslateVars", "Dress Pattern Designing: The Basic Principles of Cut and Fit", "Book name");
344  InitSystem(p46_S, name, author, book);
345  //=================================================================================================================
346  name = translate("VTranslateVars", "Knowles/Men", "System name");
347  author = translate("VTranslateVars", "Lori A. Knowles", "Author name");
348  book = translate("VTranslateVars", "The Practical Guide to Patternmaking for Fashion Designers: Menswear",
349  "Book name");
350  InitSystem(p47_S, name, author, book);
351  //=================================================================================================================
352  name = translate("VTranslateVars", "Friendship/Men", "System name");
353  author = translate("VTranslateVars", "Elizabeth Friendship", "Author name");
354  book = translate("VTranslateVars", "Pattern Cutting for Men's Costume", "Book name");
355  InitSystem(p48_S, name, author, book);
356  //=================================================================================================================
357  name = translate("VTranslateVars", "Brown", "System name");
358  author = translate("VTranslateVars", "P. Clement Brown", "Author name");
359  book = translate("VTranslateVars", "Art in Dress", "Book name");
360  InitSystem(p49_S, name, author, book);
361  //=================================================================================================================
362  name = translate("VTranslateVars", "Mitchell", "System name");
363  author = translate("VTranslateVars", "Jno. J. Mitchell", "Author name");
364  book = translate("VTranslateVars", "\"Standard\" Work on Cutting (Men's Garments) 1886: The Art and Science of "
365  "Garment Cutting", "Book name");
366  InitSystem(p50_S, name, author, book);
367  //=================================================================================================================
368  name = translate("VTranslateVars", "GOST 17917-86", "System name");
369  author = translate("VTranslateVars", "Ministry of consumer industry of the USSR", "Author name");
370  book = translate("VTranslateVars", "Standard figure boys", "Book name");
371  InitSystem(p51_S, name, author, book);
372  //=================================================================================================================
373  name = translate("VTranslateVars", "Eddy", "System name");
374  author = translate("VTranslateVars", "Josephine F. Eddy and Elizabeth C. B. Wiley", "Author name");
375  book = translate("VTranslateVars", "Pattern and Dress Design", "Book name");
376  InitSystem(p52_S, name, author, book);
377  //=================================================================================================================
378  name = translate("VTranslateVars", "Knowles/Women", "System name");
379  author = translate("VTranslateVars", "Lori A. Knowles", "Author name");
380  book = translate("VTranslateVars", "Practical Guide to Patternmaking for Fashion Designers: Juniors, Misses, and "
381  "Women", "Book name");
382  InitSystem(p53_S, name, author, book);
383  //=================================================================================================================
384  name = translate("VTranslateVars", "American Garment Cutter", "System name");
385  author = translate("VTranslateVars", "ed. R. L. Shep", "Author name");
386  book = translate("VTranslateVars", "The Great War: Styles and Patterns of the 1910s", "Book name");
387  InitSystem(p54_S, name, author, book);
388  //=================================================================================================================
389  name = translate("VTranslateVars", "None", "System name");
390  author = translate("VTranslateVars", "Seamly2D team", "Author name");
391  book = translate("VTranslateVars", "Seamly2D's internal standard", "Book name");
392  InitSystem(p998_S, name, author, book);
393  //=================================================================================================================
394 }
395 
396 //---------------------------------------------------------------------------------------------------------------------
398 {
399  variables.insert(measurement_, translate("VTranslateVars", "M_", "Left symbol _ in the name"));
400  variables.insert(variable_, translate("VTranslateVars", "Variable_", "Left symbol _ in the name"));
401  variables.insert(line_, translate("VTranslateVars", "Line_", "Left symbol _ in the name"));
402  variables.insert(angleLine_, translate("VTranslateVars", "AngleLine_", "Left symbol _ in the name"));
403  variables.insert(arc_, translate("VTranslateVars", "Arc_", "Left symbol _ in the name"));
404  variables.insert(elarc_, translate("VTranslateVars", "ElArc_", "Left symbol _ in the name"));
405  variables.insert(spl_, translate("VTranslateVars", "Spl_", "Left symbol _ in the name"));
406  variables.insert(splPath, translate("VTranslateVars", "SplPath", "Do not add symbol _ to the end of the name"));
407  variables.insert(radiusArc_, translate("VTranslateVars", "RadiusArc_", "Left symbol _ in the name"));
408  variables.insert(radius1ElArc_, translate("VTranslateVars", "Radius1ElArc_", "Left symbol _ in the name"));
409  variables.insert(radius2ElArc_, translate("VTranslateVars", "Radius2ElArc_", "Left symbol _ in the name"));
410  variables.insert(angle1Arc_, translate("VTranslateVars", "Angle1Arc_", "Left symbol _ in the name"));
411  variables.insert(angle2Arc_, translate("VTranslateVars", "Angle2Arc_", "Left symbol _ in the name"));
412  variables.insert(angle1ElArc_, translate("VTranslateVars", "Angle1ElArc_", "Left symbol _ in the name"));
413  variables.insert(angle2ElArc_, translate("VTranslateVars", "Angle2ElArc_", "Left symbol _ in the name"));
414  variables.insert(angle1Spl_, translate("VTranslateVars", "Angle1Spl_", "Left symbol _ in the name"));
415  variables.insert(angle2Spl_, translate("VTranslateVars", "Angle2Spl_", "Left symbol _ in the name"));
416  variables.insert(angle1SplPath, translate("VTranslateVars", "Angle1SplPath",
417  "Do not add symbol _ to the end of the name"));
418  variables.insert(angle2SplPath, translate("VTranslateVars", "Angle2SplPath",
419  "Do not add symbol _ to the end of the name"));
420  variables.insert(seg_, translate("VTranslateVars", "Seg_", "Segment. Left symbol _ in the name"));
421  variables.insert(currentLength, translate("VTranslateVars", "CurrentLength", "Do not add space between words"));
422  variables.insert(currentSeamAllowance, translate("VTranslateVars", "CurrentSeamAllowance",
423  "Do not add space between words"));
424  variables.insert(c1LengthSpl_, translate("VTranslateVars", "C1LengthSpl_", "Left symbol _ in the name"));
425  variables.insert(c2LengthSpl_, translate("VTranslateVars", "C2LengthSpl_", "Left symbol _ in the name"));
426  variables.insert(c1LengthSplPath, translate("VTranslateVars", "C1LengthSplPath",
427  "Do not add symbol _ to the end of the name"));
428  variables.insert(c2LengthSplPath, translate("VTranslateVars", "C2LengthSplPath",
429  "Do not add symbol _ to the end of the name"));
430 }
431 
432 //---------------------------------------------------------------------------------------------------------------------
434 {
435  functions.insert(degTorad_F, translate("VTranslateVars", "degTorad", "Converts degrees to radians\nUsage: degTorad(angle θ in degrees)"));
436  functions.insert(radTodeg_F, translate("VTranslateVars", "radTodeg", "Converts radians to degrees\nUsage: radTodeg(angle θ in radians)"));
437  functions.insert(sin_F, translate("VTranslateVars", "sin", "Sine function working with radians\nUsage: sin(angle θ in radians)"));
438  functions.insert(cos_F, translate("VTranslateVars", "cos", "Cosine function working with radians\nUsage: cos(angle θ in radians)"));
439  functions.insert(tan_F, translate("VTranslateVars", "tan", "Tangent function working with radians\nUsage: tan(angle θ in radians)"));
440  functions.insert(asin_F, translate("VTranslateVars", "asin", "Inverse sine function working with radians\nUsage: asin(x)"));
441  functions.insert(acos_F, translate("VTranslateVars", "acos", "Inverse cosine function working with radians\nUsage: acos(x)"));
442  functions.insert(atan_F, translate("VTranslateVars", "atan", "Inverse tangent function working with radians\nUsage: atan(x)"));
443  functions.insert(sinh_F, translate("VTranslateVars", "sinh", "Hyperbolic sine function\nUsage: sinh(angle θ in radians)"));
444  functions.insert(cosh_F, translate("VTranslateVars", "cosh", "Hyperbolic cosine\nUsage: cosh(angle θ in radians)"));
445  functions.insert(tanh_F, translate("VTranslateVars", "tanh", "Hyperbolic tangent function\nUsage: tanh(angle θ in radians)"));
446  functions.insert(asinh_F, translate("VTranslateVars", "asinh", "Inverse Hyperbolic sine function\nUsage: asinh(x)"));
447  functions.insert(acosh_F, translate("VTranslateVars", "acosh", "Inverse Hyperbolic cosine function\nUsage: acosh(x)"));
448  functions.insert(atanh_F, translate("VTranslateVars", "atanh", "Inverse Hyperbolic tangent function\nUsage: atanh(x)"));
449  functions.insert(sinD_F, translate("VTranslateVars", "sinD", "Sine function working with degrees\nUsage: sinD(angle θ in degrees)"));
450  functions.insert(cosD_F, translate("VTranslateVars", "cosD", "Cosine function working with degrees\nUsage: cosD(angle θ in degrees)"));
451  functions.insert(tanD_F, translate("VTranslateVars", "tanD", "Tangent function working with degrees\nUsage: tanD(angle θ in degrees)"));
452  functions.insert(asinD_F, translate("VTranslateVars", "asinD", "Inverse sine function working with degrees\nUsage: asinD(x)"));
453  functions.insert(acosD_F, translate("VTranslateVars", "acosD", "Inverse cosine function working with degrees\nUsage: acosD(x)"));
454  functions.insert(atanD_F, translate("VTranslateVars", "atanD", "Inverse tangent function working with degrees\nUsage: atanD(x)"));
455  functions.insert(log2_F, translate("VTranslateVars", "log2", "Logarithm to the base 2\nUsage: log2(x)"));
456  functions.insert(log10_F, translate("VTranslateVars", "log10", "Logarithm to the base 10\nUsage: log10(x)"));
457  functions.insert(log_F, translate("VTranslateVars", "log", "Logarithm to the base 10\nUsage: log(x)"));
458  functions.insert(ln_F, translate("VTranslateVars", "ln", "Logarithm to base e (2.71828...)\nUsage: ln(x)"));
459  functions.insert(exp_F, translate("VTranslateVars", "exp", "E raised to the power of x\nUsage: exp(x) where e = 2.718"));
460  functions.insert(sqrt_F, translate("VTranslateVars", "sqrt", "Square root of a value\nUsage: sqrt(x)"));
461  functions.insert(sign_F, translate("VTranslateVars", "sign", "Sign function -1 if x<0; 1 if x>0\nUsage: sign(x)"));
462  functions.insert(rint_F, translate("VTranslateVars", "rint", "Round to nearest integer\nUsage: rint(float x)"));
463  functions.insert(abs_F, translate("VTranslateVars", "abs", "Absolute value\nUsage: abs(x)"));
464  functions.insert(min_F, translate("VTranslateVars", "min", "Min of all arguments\nUsage: min(arg 1; arg 2; ... arg n)"));
465  functions.insert(max_F, translate("VTranslateVars", "max", "Max of all arguments\nUsage: max(arg 1; arg 2; ... arg n)"));
466  functions.insert(sum_F, translate("VTranslateVars", "sum", "Sum of all arguments\nUsage: sum(arg 1; arg 2; ... arg n)"));
467  functions.insert(avg_F, translate("VTranslateVars", "avg", "Mean value of all arguments\nUsage: avg(arg 1; arg 2; ... arg n)"));
468  functions.insert(fmod_F, translate("VTranslateVars", "fmod",
469  "Returns the floating-point remainder of x/y (rounded towards zero)\nUsage: fmod(x; y)"));
470 }
471 
472 //---------------------------------------------------------------------------------------------------------------------
474 {
475  postfixOperators.insert(cm_Oprt, translate("VTranslateVars", "cm", "centimeter"));
476  postfixOperators.insert(mm_Oprt, translate("VTranslateVars", "mm", "millimeter"));
477  postfixOperators.insert(in_Oprt, translate("VTranslateVars", "in", "inch"));
478 }
479 
480 //---------------------------------------------------------------------------------------------------------------------
482 {
483  placeholders.insert(pl_size, translate("VTranslateVars", "size", "placeholder"));
484  placeholders.insert(pl_height, translate("VTranslateVars", "height", "placeholder"));
485  placeholders.insert(pl_date, translate("VTranslateVars", "date", "placeholder"));
486  placeholders.insert(pl_time, translate("VTranslateVars", "time", "placeholder"));
487  placeholders.insert(pl_patternName, translate("VTranslateVars", "patternName", "placeholder"));
488  placeholders.insert(pl_patternNumber, translate("VTranslateVars", "patternNumber", "placeholder"));
489  placeholders.insert(pl_author, translate("VTranslateVars", "author", "placeholder"));
490  placeholders.insert(pl_customer, translate("VTranslateVars", "customer", "placeholder"));
491  placeholders.insert(pl_pExt, translate("VTranslateVars", "pExt", "placeholder"));
492  placeholders.insert(pl_pFileName, translate("VTranslateVars", "pFileName", "placeholder"));
493  placeholders.insert(pl_mFileName, translate("VTranslateVars", "mFileName", "placeholder"));
494  placeholders.insert(pl_mExt, translate("VTranslateVars", "mExt", "placeholder"));
495  placeholders.insert(pl_pLetter, translate("VTranslateVars", "pLetter", "placeholder"));
496  placeholders.insert(pl_pAnnotation, translate("VTranslateVars", "pAnnotation", "placeholder"));
497  placeholders.insert(pl_pOrientation, translate("VTranslateVars", "pOrientation", "placeholder"));
498  placeholders.insert(pl_pRotation, translate("VTranslateVars", "pRotation", "placeholder"));
499  placeholders.insert(pl_pTilt, translate("VTranslateVars", "pTilt", "placeholder"));
500  placeholders.insert(pl_pFoldPosition, translate("VTranslateVars", "pFoldPosition", "placeholder"));
501  placeholders.insert(pl_pName, translate("VTranslateVars", "pName", "placeholder"));
502  placeholders.insert(pl_pQuantity, translate("VTranslateVars", "pQuantity", "placeholder"));
503  placeholders.insert(pl_mFabric, translate("VTranslateVars", "mFabric", "placeholder"));
504  placeholders.insert(pl_mLining, translate("VTranslateVars", "mLining", "placeholder"));
505  placeholders.insert(pl_mInterfacing, translate("VTranslateVars", "mInterfacing", "placeholder"));
506  placeholders.insert(pl_mInterlining, translate("VTranslateVars", "mInterlining", "placeholder"));
507  placeholders.insert(pl_wCut, translate("VTranslateVars", "wCut", "placeholder"));
508  placeholders.insert(pl_wOnFold, translate("VTranslateVars", "wOnFold", "placeholder"));
509 }
510 
511 #undef translate
512 
513 //---------------------------------------------------------------------------------------------------------------------
514 void VTranslateVars::InitSystem(const QString &code, const qmu::QmuTranslation &name, const qmu::QmuTranslation &author,
515  const qmu::QmuTranslation &book)
516 {
517  PMSystemNames.insert(code, name);
518  PMSystemAuthors.insert(code, author);
519  PMSystemBooks.insert(code, book);
520 }
521 
522 //---------------------------------------------------------------------------------------------------------------------
523 /**
524  * @brief CorrectionsPositions correct position tokens in expression after token translation.
525  *
526  * Because translated string can have different length compare to original need make correction after each translation.
527  * If bias = 0 correction will not happens.
528  *
529  * @param position position currecnt token in expression
530  * @param bias difference between original token length and translated
531  * @param tokens all tokens
532  * @param numbers all numbers
533  */
534 void VTranslateVars::CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens,
535  QMap<int, QString> &numbers) const
536 {
537  if (bias == 0)
538  {
539  return;// Nothing to correct;
540  }
541 
542  BiasTokens(position, bias, tokens);
543  BiasTokens(position, bias, numbers);
544 }
545 
546 //---------------------------------------------------------------------------------------------------------------------
547 /**
548  * @brief BiasTokens change position for each token that have position more then "position".
549  * @param position token position
550  * @param bias difference between original token length and translated
551  * @param tokens all tokens
552  */
553 void VTranslateVars::BiasTokens(int position, int bias, QMap<int, QString> &tokens)
554 {
555  QMap<int, QString> newTokens;
556  QMap<int, QString>::const_iterator i = tokens.constBegin();
557  while (i != tokens.constEnd())
558  {
559  if (i.key()<= position)
560  { // Tokens before position "position" did not change his positions.
561  newTokens.insert(i.key(), i.value());
562  }
563  else
564  {
565  newTokens.insert(i.key()-bias, i.value());
566  }
567  ++i;
568  }
569  tokens = newTokens;
570 }
571 
572 
573 
574 //---------------------------------------------------------------------------------------------------------------------
575 /**
576  * @brief VariablesFromUser translate variable to internal look.
577  * @param newFormula [in|out] expression to translate
578  * @param position token position
579  * @param token token to translate
580  * @param bias hold change of length between translated and origin token string
581  * @return true if was found variable with same name.
582  */
583 bool VTranslateVars::VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const
584 {
585  const QString currentLengthTr = variables.value(currentLength).translate();
586  const QString currentSeamAllowanceTr = variables.value(currentSeamAllowance).translate();
587 
589  while (i != variables.constEnd())
590  {
591  const qmu::QmuTranslation &var = i.value();
592  const QString varTr = var.translate();
593 
594  if (token.indexOf(varTr) == 0)
595  {
596  if ((varTr == currentLengthTr || varTr == currentSeamAllowanceTr) && token != varTr)
597  {
598  ++i;
599  continue;
600  }
601 
602  newFormula.replace(position, varTr.length(), i.key());
603  QString newToken = token;
604  newToken.replace(0, varTr.length(), i.key());
605  bias = token.length() - newToken.length();
606  return true;
607  }
608  ++i;
609  }
610  return false;
611 }
612 
613 //---------------------------------------------------------------------------------------------------------------------
614 /**
615  * @brief PostfixOperatorsFromUser translate postfix operator to internal look.
616  * @param newFormula [in|out] expression to translate
617  * @param position token position
618  * @param token token to translate
619  * @param bias hold change of length between translated and origin token string
620  * @return true if was found postfix operator with same name.
621  */
622 bool VTranslateVars::PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
623 {
625  while (i != postfixOperators.constEnd())
626  {
627  if (token == i.value().translate())
628  {
629  newFormula.replace(position, token.length(), i.key());
630  bias = token.length() - i.key().length();
631  return true;
632  }
633  ++i;
634  }
635  return false;
636 }
637 
638 //---------------------------------------------------------------------------------------------------------------------
639 /**
640  * @brief FunctionsFromUser translate function name to internal look.
641  * @param newFormula [in|out] expression to translate
642  * @param position token position
643  * @param token token to translate
644  * @param bias hold change of length between translated and origin token string
645  * @return true if was found function with same name.
646  */
647 bool VTranslateVars::FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
648 {
650  while (i != functions.constEnd())
651  {
652  if (token == i.value().translate())
653  {
654  newFormula.replace(position, token.length(), i.key());
655  bias = token.length() - i.key().length();
656  return true;
657  }
658  ++i;
659  }
660  return false;
661 }
662 
663 //---------------------------------------------------------------------------------------------------------------------
664 /**
665  * @brief VariablesToUser translate variable name to user.
666  * @param newFormula [in|out] expression to translate
667  * @param position token position
668  * @param token token to translate
669  * @param bias hold change of length between translated and origin token string
670  * @return true if was found variable with same name.
671  */
672 bool VTranslateVars::VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const
673 {
675  while (i != variables.constEnd())
676  {
677  if (token.indexOf( i.key() ) == 0)
678  {
679  if ((i.key() == currentLength || i.key() == currentSeamAllowance) && token != i.key())
680  {
681  ++i;
682  continue;
683  }
684 
685  newFormula.replace(position, i.key().length(), i.value().translate());
686 
687  QString newToken = token;
688  newToken.replace(0, i.key().length(), i.value().translate());
689  bias = token.length() - newToken.length();
690  return true;
691  }
692  ++i;
693  }
694  return false;
695 }
696 
697 //---------------------------------------------------------------------------------------------------------------------
698 QString VTranslateVars::InternalVarToUser(const QString &var) const
699 {
700  QString newVar = var;
701  int bias = 0;
702  if (VariablesToUser(newVar, 0, var, bias))
703  {
704  return newVar;
705  }
706  else
707  {
708  return var;
709  }
710 }
711 
712 //---------------------------------------------------------------------------------------------------------------------
713 QString VTranslateVars::PlaceholderToUser(const QString &var) const
714 {
715  if (placeholders.contains(var))
716  {
717  return placeholders.value(var).translate();
718  }
719 
720  return var;
721 }
722 
723 //---------------------------------------------------------------------------------------------------------------------
724 QString VTranslateVars::PlaceholderToUserText(QString text) const
725 {
726  QChar per('%');
727  auto i = placeholders.constBegin();
728  while (i != placeholders.constEnd())
729  {
730  const QString translated = per + i.value().translate() + per;
731  const QString original = per + i.key() + per;
732 
733  if (translated != original)
734  {
735  text.replace(original, translated);
736  }
737  ++i;
738  }
739  return text;
740 }
741 
742 //---------------------------------------------------------------------------------------------------------------------
743 QString VTranslateVars::PlaceholderFromUserText(QString text) const
744 {
745  QChar per('%');
746  auto i = placeholders.constBegin();
747  while (i != placeholders.constEnd())
748  {
749  const QString translated = per + i.value().translate() + per;
750  const QString original = per + i.key() + per;
751 
752  if (translated != original)
753  {
754  text.replace(translated, original);
755  }
756  ++i;
757  }
758  return text;
759 }
760 
761 //---------------------------------------------------------------------------------------------------------------------
762 QString VTranslateVars::VarToUser(const QString &var) const
763 {
764  if (m_measurements.contains(var))
765  {
766  return m_measurements.value(var).translate();
767  }
768 
769  if (functions.contains(var))
770  {
771  return functions.value(var).translate();
772  }
773 
774  if (postfixOperators.contains(var))
775  {
776  return postfixOperators.value(var).translate();
777  }
778 
779  return InternalVarToUser(var);
780 }
781 
782 //---------------------------------------------------------------------------------------------------------------------
783 QString VTranslateVars::VarFromUser(const QString &var) const
784 {
785  QString newVar = var;
786  int bias = 0;
787  if (MeasurementsFromUser(newVar, 0, var, bias))
788  {
789  return newVar;
790  }
791 
792  if (VariablesFromUser(newVar, 0, var, bias))
793  {
794  return newVar;
795  }
796 
797  if (PostfixOperatorsFromUser(newVar, 0, var, bias))
798  {
799  return newVar;
800  }
801 
802  if (FunctionsFromUser(newVar, 0, var, bias))
803  {
804  return newVar;
805  }
806  return newVar;
807 }
808 
809 //---------------------------------------------------------------------------------------------------------------------
810 QString VTranslateVars::PMSystemName(const QString &code) const
811 {
812  return PMSystemNames.value(code).translate();
813 }
814 
815 //---------------------------------------------------------------------------------------------------------------------
816 QString VTranslateVars::PMSystemAuthor(const QString &code) const
817 {
818  return PMSystemAuthors.value(code).translate();
819 }
820 
821 //---------------------------------------------------------------------------------------------------------------------
822 QString VTranslateVars::PMSystemBook(const QString &code) const
823 {
824  return PMSystemBooks.value(code).translate();
825 }
826 
827 //---------------------------------------------------------------------------------------------------------------------
828 // cppcheck-suppress unusedFunction
829 QString VTranslateVars::PostfixOperator(const QString &name) const
830 {
831  return postfixOperators.value(name).translate();
832 }
833 
834 //---------------------------------------------------------------------------------------------------------------------
835 /**
836  * @brief FormulaFromUser replace all known tokens in formula to internal look. Also change decimal
837  * separator in numbers.
838  * @param formula expression that need translate
839  * @throw qmu::QmuParserError in case of a wrong expression
840  * @return translated expression
841  */
842 QString VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator) const
843 {
844  if (formula.isEmpty())
845  {
846  return formula;
847  }
848  QString newFormula = formula;// Local copy for making changes
849 
850  QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(formula, osSeparator));// Eval formula
851  QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
852  QMap<int, QString> numbers = cal->GetNumbers();// All numbers in expression for changing decimal separator
853  delete cal.take();
854 
855  QList<int> tKeys = tokens.keys();// Take all tokens positions
856  QList<QString> tValues = tokens.values();
857  for (int i = 0; i < tKeys.size(); ++i)
858  {
859  int bias = 0;
860  if (MeasurementsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
861  {
862  if (bias != 0)
863  {// Translated token has different length than original. Position next tokens need to be corrected.
864  CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
865  tKeys = tokens.keys();
866  tValues = tokens.values();
867  }
868  continue;
869  }
870 
871  if (VariablesFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
872  {
873  if (bias != 0)
874  {// Translated token has different length than original. Position next tokens need to be corrected.
875  CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
876  tKeys = tokens.keys();
877  tValues = tokens.values();
878  }
879  continue;
880  }
881 
882  if (PostfixOperatorsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
883  {
884  if (bias != 0)
885  {// Translated token has different length than original. Position next tokens need to be corrected.
886  CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
887  tKeys = tokens.keys();
888  tValues = tokens.values();
889  }
890  continue;
891  }
892 
893  if (FunctionsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
894  {
895  if (bias != 0)
896  {// Translated token has different length than original. Position next tokens need to be corrected.
897  CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
898  tKeys = tokens.keys();
899  tValues = tokens.values();
900  }
901  continue;
902  }
903 
904  if (tValues.at(i) == QLocale().negativeSign())
905  {// unary minus
906  newFormula.replace(tKeys.at(i), 1, '-');
907  }
908  }
909 
910  QLocale loc = QLocale(); // User locale
911  if (loc != QLocale::c() && osSeparator)
912  {// User want use Os separator
913  QList<int> nKeys = numbers.keys();// Positions for all numbers in expression
914  QList<QString> nValues = numbers.values();
915  for (int i = 0; i < nKeys.size(); ++i)
916  {
917  loc = QLocale();// From system locale
918  bool ok = false;
919  const qreal d = loc.toDouble(nValues.at(i), &ok);
920  if (ok == false)
921  {
922  qDebug()<<"Can't convert to double token"<<nValues.at(i);
923  continue;//Leave with out translation
924  }
925 
926  loc = QLocale::c();// To internal locale
927  const QString dStr = loc.toString(d);// Internal look for number
928  newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
929  const int bias = nValues.at(i).length() - dStr.length();
930  if (bias != 0)
931  {// Translated number has different length than original. Position next tokens need to be corrected.
932  CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
933  nKeys = numbers.keys();
934  nValues = numbers.values();
935  }
936  }
937  }
938 
939  return newFormula;
940 }
941 
942 //---------------------------------------------------------------------------------------------------------------------
943 QString VTranslateVars::TryFormulaFromUser(const QString &formula, bool osSeparator)
944 {
945  try
946  {
947  return qApp->TrVars()->FormulaFromUser(formula, osSeparator);
948  }
949  catch (qmu::QmuParserError &e)// In case something bad will happen
950  {
951  Q_UNUSED(e)
952  return formula;
953  }
954 }
955 
956 //---------------------------------------------------------------------------------------------------------------------
957 /**
958  * @brief FormulaToUser replace all known tokens in formula to user look. Also change decimal
959  * separator in numbers.
960  * @param formula expression that need translate
961  * @return translated expression
962  */
963 QString VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator) const
964 {
965  if (formula.isEmpty())
966  {
967  return formula;
968  }
969 
970  QString newFormula = formula;// Local copy for making changes
971 
972  QMap<int, QString> tokens;
973  QMap<int, QString> numbers;
974  try
975  {
976  QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(formula, false, false));// Eval formula
977  tokens = cal->GetTokens();// Tokens (variables, measurements)
978  numbers = cal->GetNumbers();// All numbers in expression for changing decimal separator
979  }
980  catch (qmu::QmuParserError &e)
981  {
982  qDebug() << "\nMath parser error:\n"
983  << "--------------------------------------\n"
984  << "Message: " << e.GetMsg() << "\n"
985  << "Expression: " << e.GetExpr() << "\n"
986  << "--------------------------------------";
987  return newFormula;
988  }
989 
990  QList<int> tKeys = tokens.keys();
991  QList<QString> tValues = tokens.values();
992  for (int i = 0; i < tKeys.size(); ++i)
993  {
994  if (m_measurements.contains(tValues.at(i)))
995  {
996  newFormula.replace(tKeys.at(i), tValues.at(i).length(), m_measurements.value(tValues.at(i)).translate());
997  int bias = tValues.at(i).length() - m_measurements.value(tValues.at(i)).translate().length();
998  if (bias != 0)
999  {// Translated token has different length than original. Position next tokens need to be corrected.
1000  CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
1001  tKeys = tokens.keys();
1002  tValues = tokens.values();
1003  }
1004  continue;
1005  }
1006 
1007  if (functions.contains(tValues.at(i)))
1008  {
1009  newFormula.replace(tKeys.at(i), tValues.at(i).length(), functions.value(tValues.at(i)).translate());
1010  int bias = tValues.at(i).length() - functions.value(tValues.at(i)).translate().length();
1011  if (bias != 0)
1012  {// Translated token has different length than original. Position next tokens need to be corrected.
1013  CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
1014  tKeys = tokens.keys();
1015  tValues = tokens.values();
1016  }
1017  continue;
1018  }
1019 
1020  if (postfixOperators.contains(tValues.at(i)))
1021  {
1022  newFormula.replace(tKeys.at(i), tValues.at(i).length(), postfixOperators.value(tValues.at(i)).translate());
1023  int bias = tValues.at(i).length() - postfixOperators.value(tValues.at(i)).translate().length();
1024  if (bias != 0)
1025  {// Translated token has different length than original. Position next tokens need to be corrected.
1026  CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
1027  tKeys = tokens.keys();
1028  tValues = tokens.values();
1029  }
1030  continue;
1031  }
1032 
1033  int bias = 0;
1034  if (VariablesToUser(newFormula, tKeys.at(i), tValues.at(i), bias))
1035  {
1036  if (bias != 0)
1037  {// Translated token has different length than original. Position next tokens need to be corrected.
1038  CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
1039  tKeys = tokens.keys();
1040  tValues = tokens.values();
1041  }
1042  continue;
1043  }
1044 
1045  if (tValues.at(i) == QChar('-'))
1046  {// unary minus
1047  newFormula.replace(tKeys.at(i), 1, QLocale().negativeSign());
1048  }
1049  }
1050 
1051  QLocale loc = QLocale();// User locale
1052  if (loc != QLocale::C && osSeparator)
1053  {// User want use Os separator
1054  QList<int> nKeys = numbers.keys();// Positions for all numbers in expression
1055  QList<QString> nValues = numbers.values();
1056  for (int i = 0; i < nKeys.size(); ++i)
1057  {
1058  loc = QLocale::c();// From pattern locale
1059  bool ok = false;
1060  const qreal d = loc.toDouble(nValues.at(i), &ok);
1061  if (ok == false)
1062  {
1063  qDebug()<<"Can't convert to double token"<<nValues.at(i);
1064  continue;//Leave with out translation
1065  }
1066 
1067  loc = QLocale();// To user locale
1068  QString dStr = loc.toString(d);// Number string in user locale
1069  newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
1070  const int bias = nValues.at(i).length() - dStr.length();
1071  if (bias != 0)
1072  {// Translated number has different length than original. Position next tokens need to be corrected.
1073  CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
1074  nKeys = numbers.keys();
1075  nValues = numbers.values();
1076  }
1077  }
1078  }
1079 
1080  return newFormula;
1081 }
1082 
1083 //---------------------------------------------------------------------------------------------------------------------
1085 {
1087 
1088  PMSystemNames.clear();
1089  PMSystemAuthors.clear();
1090  PMSystemBooks.clear();
1091  variables.clear();
1092  functions.clear();
1093  postfixOperators.clear();
1094  stDescriptions.clear();
1095 
1097  InitVariables();
1098  InitFunctions();
1100  InitPlaceholder();
1101 }
1102 
1103 //---------------------------------------------------------------------------------------------------------------------
1105 {
1106  return functions;
1107 }
bool MeasurementsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
MeasurementsFromUser translate measurement to internal look.
QMap< QString, qmu::QmuTranslation > m_measurements
QString VarToUser(const QString &var) const
QString PlaceholderFromUserText(QString text) const
QString PMSystemName(const QString &code) const
QString PlaceholderToUserText(QString text) const
QString VarFromUser(const QString &var) const
virtual ~VTranslateVars() Q_DECL_OVERRIDE
QMap< QString, qmu::QmuTranslation > functions
virtual void Retranslate() Q_DECL_OVERRIDE
QString InternalVarToUser(const QString &var) const
QMap< QString, qmu::QmuTranslation > getFunctions() const
QMap< QString, qmu::QmuTranslation > PMSystemAuthors
void InitSystem(const QString &code, const qmu::QmuTranslation &name, const qmu::QmuTranslation &author, const qmu::QmuTranslation &book)
void InitPostfixOperators()
void CorrectionsPositions(int position, int bias, QMap< int, QString > &tokens, QMap< int, QString > &numbers) const
CorrectionsPositions correct position tokens in expression after token translation.
void InitPatternMakingSystems()
QMap< QString, qmu::QmuTranslation > PMSystemNames
QMap< QString, qmu::QmuTranslation > PMSystemBooks
static QString TryFormulaFromUser(const QString &formula, bool osSeparator)
bool PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
PostfixOperatorsFromUser translate postfix operator to internal look.
bool FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const
FunctionsFromUser translate function name to internal look.
QString PlaceholderToUser(const QString &var) const
QMap< QString, qmu::QmuTranslation > placeholders
QString FormulaToUser(const QString &formula, bool osSeparator) const
FormulaToUser replace all known tokens in formula to user look. Also change decimal separator in numb...
bool VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const
VariablesFromUser translate variable to internal look.
QMap< QString, qmu::QmuTranslation > postfixOperators
bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const
VariablesToUser translate variable name to user.
QString FormulaFromUser(const QString &formula, bool osSeparator) const
FormulaFromUser replace all known tokens in formula to internal look. Also change decimal separator i...
static void BiasTokens(int position, int bias, QMap< int, QString > &tokens)
BiasTokens change position for each token that have position more then "position".
QString PostfixOperator(const QString &name) const
QMap< QString, qmu::QmuTranslation > variables
QString PMSystemBook(const QString &code) const
QMap< QString, qmu::QmuTranslation > stDescriptions
QString PMSystemAuthor(const QString &code) const
Error class of the parser.
const QString & GetMsg() const
Returns the message string for this error.
const QString & GetExpr() const
gets the expression related tp this error.
QString translate() const
const QString pl_size
Definition: def.cpp:137
const QString asinD_F
Definition: def.cpp:102
const QString pl_customer
Definition: def.cpp:144
const QString log10_F
Definition: def.cpp:106
const QString cm_Oprt
Definition: def.cpp:129
const QString pl_pExt
Definition: def.cpp:145
const QString tanh_F
Definition: def.cpp:95
const QString pl_mExt
Definition: def.cpp:148
const QString ln_F
Definition: def.cpp:108
const QString pl_pFoldPosition
Definition: def.cpp:154
const QString mm_Oprt
Definition: def.cpp:130
const QString tanD_F
Definition: def.cpp:101
const QString pl_wCut
Definition: def.cpp:161
const QString acos_F
Definition: def.cpp:91
const QString pl_author
Definition: def.cpp:143
const QString sum_F
Definition: def.cpp:116
const QString pl_time
Definition: def.cpp:140
const QString tan_F
Definition: def.cpp:89
const QString pl_pQuantity
Definition: def.cpp:156
const QString atan_F
Definition: def.cpp:92
const QString min_F
Definition: def.cpp:114
const QString sin_F
Definition: def.cpp:87
const QString pl_mFileName
Definition: def.cpp:147
const QString pl_patternName
Definition: def.cpp:141
const QString acosD_F
Definition: def.cpp:103
const QString pl_pAnnotation
Definition: def.cpp:150
const QString cosD_F
Definition: def.cpp:100
const QString in_Oprt
Definition: def.cpp:131
const QString sinD_F
Definition: def.cpp:99
const QString pl_pName
Definition: def.cpp:155
const QString pl_wOnFold
Definition: def.cpp:162
const QString sinh_F
Definition: def.cpp:93
const QString rint_F
Definition: def.cpp:112
const QString pl_patternNumber
Definition: def.cpp:142
const QString cos_F
Definition: def.cpp:88
const QString avg_F
Definition: def.cpp:117
const QString acosh_F
Definition: def.cpp:97
const QString pl_mLining
Definition: def.cpp:158
const QString atanD_F
Definition: def.cpp:104
const QString atanh_F
Definition: def.cpp:98
const QString log2_F
Definition: def.cpp:105
const QString asinh_F
Definition: def.cpp:96
const QString fmod_F
Definition: def.cpp:118
const QString pl_pFileName
Definition: def.cpp:146
const QString cosh_F
Definition: def.cpp:94
const QString radTodeg_F
Definition: def.cpp:86
const QString abs_F
Definition: def.cpp:113
const QString sign_F
Definition: def.cpp:111
const QString pl_date
Definition: def.cpp:139
const QString pl_mInterfacing
Definition: def.cpp:159
const QString sqrt_F
Definition: def.cpp:110
const QString pl_mFabric
Definition: def.cpp:157
const QString pl_pOrientation
Definition: def.cpp:151
const QString pl_pRotation
Definition: def.cpp:152
const QString asin_F
Definition: def.cpp:90
const QString pl_mInterlining
Definition: def.cpp:160
const QString degTorad_F
Definition: def.cpp:85
const QString pl_pTilt
Definition: def.cpp:153
const QString max_F
Definition: def.cpp:115
const QString exp_F
Definition: def.cpp:109
const QString pl_height
Definition: def.cpp:138
const QString pl_pLetter
Definition: def.cpp:149
const QString log_F
Definition: def.cpp:107
const QString splPath
Definition: ifcdef.cpp:419
const QString angle1ElArc_
Definition: ifcdef.cpp:434
const QString angle1SplPath
Definition: ifcdef.cpp:438
const QString elarc_
Definition: ifcdef.cpp:418
const QString radius2ElArc_
Definition: ifcdef.cpp:423
const QString c1LengthSpl_
Definition: ifcdef.cpp:428
const QString angle1Arc_
Definition: ifcdef.cpp:432
const QString arc_
Definition: ifcdef.cpp:417
const QString angle2Arc_
Definition: ifcdef.cpp:433
const QString seg_
Definition: ifcdef.cpp:440
const QString angle2ElArc_
Definition: ifcdef.cpp:435
const QString currentSeamAllowance
Definition: ifcdef.cpp:442
const QString line_
Definition: ifcdef.cpp:414
const QString angle2SplPath
Definition: ifcdef.cpp:439
const QString variable_
Definition: ifcdef.cpp:413
const QString c1LengthSplPath
Definition: ifcdef.cpp:430
const QString spl_
Definition: ifcdef.cpp:416
const QString c2LengthSpl_
Definition: ifcdef.cpp:429
const QString angle1Spl_
Definition: ifcdef.cpp:436
const QString radiusArc_
Definition: ifcdef.cpp:421
const QString angleLine_
Definition: ifcdef.cpp:415
const QString currentLength
Definition: ifcdef.cpp:441
const QString c2LengthSplPath
Definition: ifcdef.cpp:431
const QString angle2Spl_
Definition: ifcdef.cpp:437
const QString measurement_
Definition: ifcdef.cpp:412
const QString radius1ElArc_
Definition: ifcdef.cpp:422
Namespace for mathematical applications.
const QString p49_S
Definition: pmsystems.cpp:108
const QString p19_S
Definition: pmsystems.cpp:78
const QString p48_S
Definition: pmsystems.cpp:107
const QString p50_S
Definition: pmsystems.cpp:109
const QString p27_S
Definition: pmsystems.cpp:86
const QString p32_S
Definition: pmsystems.cpp:91
const QString p30_S
Definition: pmsystems.cpp:89
const QString p20_S
Definition: pmsystems.cpp:79
const QString p33_S
Definition: pmsystems.cpp:92
const QString p998_S
Definition: pmsystems.cpp:114
const QString p54_S
Definition: pmsystems.cpp:113
const QString p23_S
Definition: pmsystems.cpp:82
const QString p34_S
Definition: pmsystems.cpp:93
const QString p47_S
Definition: pmsystems.cpp:106
const QString p25_S
Definition: pmsystems.cpp:84
const QString p39_S
Definition: pmsystems.cpp:98
const QString p16_S
Definition: pmsystems.cpp:75
const QString p21_S
Definition: pmsystems.cpp:80
const QString p18_S
Definition: pmsystems.cpp:77
const QString p38_S
Definition: pmsystems.cpp:97
const QString p36_S
Definition: pmsystems.cpp:95
const QString p1_S
Definition: pmsystems.cpp:60
const QString p43_S
Definition: pmsystems.cpp:102
const QString p8_S
Definition: pmsystems.cpp:67
const QString p9_S
Definition: pmsystems.cpp:68
const QString p3_S
Definition: pmsystems.cpp:62
const QString p15_S
Definition: pmsystems.cpp:74
const QString p24_S
Definition: pmsystems.cpp:83
const QString p35_S
Definition: pmsystems.cpp:94
const QString p31_S
Definition: pmsystems.cpp:90
const QString p14_S
Definition: pmsystems.cpp:73
const QString p4_S
Definition: pmsystems.cpp:63
const QString p28_S
Definition: pmsystems.cpp:87
const QString p13_S
Definition: pmsystems.cpp:72
const QString p22_S
Definition: pmsystems.cpp:81
const QString p42_S
Definition: pmsystems.cpp:101
const QString p46_S
Definition: pmsystems.cpp:105
const QString p40_S
Definition: pmsystems.cpp:99
const QString p12_S
Definition: pmsystems.cpp:71
const QString p11_S
Definition: pmsystems.cpp:70
const QString p51_S
Definition: pmsystems.cpp:110
const QString p53_S
Definition: pmsystems.cpp:112
const QString p29_S
Definition: pmsystems.cpp:88
const QString p5_S
Definition: pmsystems.cpp:64
const QString p52_S
Definition: pmsystems.cpp:111
const QString p37_S
Definition: pmsystems.cpp:96
const QString p26_S
Definition: pmsystems.cpp:85
const QString p0_S
Definition: pmsystems.cpp:59
const QString p44_S
Definition: pmsystems.cpp:103
const QString p10_S
Definition: pmsystems.cpp:69
const QString p2_S
Definition: pmsystems.cpp:61
const QString p45_S
Definition: pmsystems.cpp:104
const QString p7_S
Definition: pmsystems.cpp:66
const QString p17_S
Definition: pmsystems.cpp:76
const QString p6_S
Definition: pmsystems.cpp:65
const QString p41_S
Definition: pmsystems.cpp:100
#define qApp
Definition: vapplication.h:67
#define translate(context, source, disambiguation)