Seamly2D
Code documentation
vtranslatevars.h
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.h
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 #ifndef VTRANSLATEVARS_H
53 #define VTRANSLATEVARS_H
54 
55 #include <qcompilerdetection.h>
56 #include <QtGlobal>
57 
58 #include "vtranslatemeasurements.h"
59 
61 {
62 public:
63  explicit VTranslateVars();
64  virtual ~VTranslateVars() Q_DECL_OVERRIDE;
65 
66  bool VariablesFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
67  bool PostfixOperatorsFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
68  bool FunctionsFromUser(QString &newFormula, int position, const QString &token, int &bias) const;
69  bool VariablesToUser(QString &newFormula, int position, const QString &token, int &bias) const;
70 
71  QString InternalVarToUser(const QString &var) const;
72  QString PlaceholderToUser(const QString &var) const;
73 
74  QString PlaceholderToUserText(QString text) const;
75  QString PlaceholderFromUserText(QString text) const;
76 
77  QString VarToUser(const QString &var) const;
78  QString VarFromUser(const QString &var) const;
79 
80  QString PMSystemName(const QString &code) const;
81  QString PMSystemAuthor(const QString &code) const;
82  QString PMSystemBook(const QString &code) const;
83 
84  QString PostfixOperator(const QString &name) const;
85 
86  QString FormulaFromUser(const QString &formula, bool osSeparator) const;
87  static QString TryFormulaFromUser(const QString &formula, bool osSeparator);
88  QString FormulaToUser(const QString &formula, bool osSeparator) const;
89 
90  virtual void Retranslate() Q_DECL_OVERRIDE;
91 
93 
94  static void BiasTokens(int position, int bias, QMap<int, QString> &tokens);
95 
96 private:
97  Q_DISABLE_COPY(VTranslateVars)
98  QMap<QString, qmu::QmuTranslation> PMSystemNames;
99  QMap<QString, qmu::QmuTranslation> PMSystemAuthors;
100  QMap<QString, qmu::QmuTranslation> PMSystemBooks;
101  QMap<QString, qmu::QmuTranslation> variables;
102  QMap<QString, qmu::QmuTranslation> functions;
103  QMap<QString, qmu::QmuTranslation> postfixOperators;
104  QMap<QString, qmu::QmuTranslation> placeholders;
105  QMap<QString, qmu::QmuTranslation> stDescriptions;
106 
108  void InitVariables();
109  void InitFunctions();
110  void InitPostfixOperators();
111  void InitPlaceholder();
112 
113  void InitSystem(const QString &code, const qmu::QmuTranslation &name, const qmu::QmuTranslation &author,
114  const qmu::QmuTranslation &book);
115 
116  void CorrectionsPositions(int position, int bias, QMap<int, QString> &tokens, QMap<int, QString> &numbers) const;
117 
118 };
119 
120 #endif // VTRANSLATEVARS_H
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
Namespace for mathematical applications.