mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[calculation] Dimension in additional output for values with units
This commit is contained in:
@@ -12,6 +12,21 @@ using namespace Shared;
|
||||
|
||||
namespace Calculation {
|
||||
|
||||
|
||||
UnitListController::UnitListController(EditExpressionController * editExpressionController) :
|
||||
ExpressionsListController(editExpressionController),
|
||||
m_dimensionMessage(I18n::Message::Default)
|
||||
{
|
||||
m_dimensionCell.setMessageFont(KDFont::LargeFont);
|
||||
}
|
||||
|
||||
bool UnitListController::handleEvent(Ion::Events::Event event) {
|
||||
if (selectedRow() == 0 && (event == Ion::Events::OK || event == Ion::Events::EXE)) {
|
||||
return true;
|
||||
}
|
||||
return ListController::handleEvent(event);
|
||||
}
|
||||
|
||||
void UnitListController::setExpression(Poincare::Expression e) {
|
||||
ExpressionsListController::setExpression(e);
|
||||
assert(!m_expression.isUninitialized());
|
||||
@@ -22,6 +37,7 @@ void UnitListController::setExpression(Poincare::Expression e) {
|
||||
for (size_t i = 0; i < k_maxNumberOfRows; i++) {
|
||||
expressions[i] = Expression();
|
||||
}
|
||||
m_dimensionMessage = I18n::Message::Default;
|
||||
|
||||
/* 1. First rows: miscellaneous classic units for some dimensions, in both
|
||||
* metric and imperial units. */
|
||||
@@ -37,7 +53,7 @@ void UnitListController::setExpression(Poincare::Expression e) {
|
||||
GlobalPreferences::sharedGlobalPreferences()->unitFormat(),
|
||||
ExpressionNode::ReductionTarget::User,
|
||||
ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithDefinitionsOrUndefined);
|
||||
int numberOfExpressions = Unit::SetAdditionalExpressions(units, value, expressions, k_maxNumberOfRows, reductionContext);
|
||||
int numberOfExpressions = Unit::SetAdditionalExpressionsAndMessage(units, value, expressions, k_maxNumberOfRows, reductionContext, &m_dimensionMessage);
|
||||
|
||||
// 2. SI units only
|
||||
assert(numberOfExpressions < k_maxNumberOfRows - 1);
|
||||
@@ -89,6 +105,44 @@ void UnitListController::setExpression(Poincare::Expression e) {
|
||||
}
|
||||
}
|
||||
|
||||
int UnitListController::numberOfRows() const {
|
||||
int messageRow = m_dimensionMessage != I18n::Message::Default ? 1 : 0;
|
||||
return ExpressionsListController::numberOfRows() + messageRow;
|
||||
}
|
||||
|
||||
void UnitListController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
if (index == 0) {
|
||||
MessageTableCell * messageTableCell = (MessageTableCell *)cell;
|
||||
messageTableCell->setMessage(m_dimensionMessage);
|
||||
} else {
|
||||
ExpressionsListController::willDisplayCellForIndex(cell, index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
KDCoordinate UnitListController::rowHeight(int index) {
|
||||
if (index == 0) {
|
||||
return 35;
|
||||
} else {
|
||||
return ExpressionsListController::rowHeight(index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
HighlightCell * UnitListController::reusableCell(int index, int type) {
|
||||
if (type == 0) {
|
||||
return ExpressionsListController::reusableCell(index, type);
|
||||
} else {
|
||||
return &m_dimensionCell;
|
||||
}
|
||||
}
|
||||
|
||||
int UnitListController::typeAtLocation(int i, int j) {
|
||||
if (j == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return ExpressionsListController::typeAtLocation(i, j - 1);
|
||||
}
|
||||
}
|
||||
|
||||
I18n::Message UnitListController::messageAtIndex(int index) {
|
||||
return (I18n::Message)0;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,23 @@ namespace Calculation {
|
||||
|
||||
class UnitListController : public ExpressionsListController {
|
||||
public:
|
||||
UnitListController(EditExpressionController * editExpressionController) :
|
||||
ExpressionsListController(editExpressionController) {}
|
||||
UnitListController(EditExpressionController * editExpressionController);
|
||||
|
||||
/* Responder */
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
|
||||
void setExpression(Poincare::Expression e) override;
|
||||
int reusableCellCount(int type) override { return type == 0 ? ExpressionsListController::reusableCellCount(type) : 1; }
|
||||
HighlightCell * reusableCell(int index, int type) override;
|
||||
KDCoordinate rowHeight(int j) override;
|
||||
int typeAtLocation(int i, int j) override;
|
||||
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
|
||||
int numberOfRows() const override;
|
||||
|
||||
private:
|
||||
I18n::Message messageAtIndex(int index) override;
|
||||
I18n::Message m_dimensionMessage;
|
||||
MessageTableCell m_dimensionCell;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -17,4 +17,28 @@ FactorizedForm = "Factorisierte Form"
|
||||
Discriminant = "Diskriminante"
|
||||
OnlyRoot = "Wurzel"
|
||||
FirstRoot = "Erste Wurzel"
|
||||
SecondRoot = "Zweite Wurzel"
|
||||
SecondRoot = "Zweite Wurzel"
|
||||
TimeDimension = "Zeit"
|
||||
DistanceDimension = "Distanz"
|
||||
MassDimension = "Masse"
|
||||
CurrentDimension = "Betrieb"
|
||||
TemperatureDimension = "Temperatur"
|
||||
AmountOfSubstanceDimension = "Quantität der Materie"
|
||||
LuminousIntensityDimension = "Lichtintensität"
|
||||
FrequencyDimension = "Frequenz"
|
||||
ForceDimension = "Stärke"
|
||||
PressureDimension = "Druck"
|
||||
EnergyDimension = "Energie"
|
||||
PowerDimension = "Mächtig"
|
||||
ElectricChargeDimension = "Elektrische Ladung"
|
||||
ElectricPotentialDimension = "Elektrisches Potenzial"
|
||||
ElectricCapacitanceDimension = "Elektrische Kapazität"
|
||||
ElectricResistanceDimension = "Elektrischer Wiederstand"
|
||||
ElectricConductanceDimension = "elektrische Leitfähigkeit"
|
||||
MagneticFluxDimension = "magnetischer Fluss"
|
||||
MagneticFieldDimension = "Magnetfeld"
|
||||
InductanceDimension = "Induktivität"
|
||||
CatalyticActivityDimension = "Katalytische Aktivität"
|
||||
SurfaceDimension = "Auftauchen"
|
||||
VolumeDimension = "Volumen"
|
||||
SpeedDimension = "Geschwindigkeit"
|
||||
|
||||
@@ -17,4 +17,28 @@ FactorizedForm = "Factorized form"
|
||||
Discriminant = "Discriminant"
|
||||
OnlyRoot = "Root"
|
||||
FirstRoot = "First root"
|
||||
SecondRoot = "Second root"
|
||||
SecondRoot = "Second root"
|
||||
TimeDimension = "Time"
|
||||
DistanceDimension = "Distance"
|
||||
MassDimension = "Mass"
|
||||
CurrentDimension = "Running"
|
||||
TemperatureDimension = "Temperature"
|
||||
AmountOfSubstanceDimension = "Quantity of matter"
|
||||
LuminousIntensityDimension = "Light intensity"
|
||||
FrequencyDimension = "Frequency"
|
||||
ForceDimension = "Strength"
|
||||
PressureDimension = "Pressure"
|
||||
EnergyDimension = "Energy"
|
||||
PowerDimension = "Powerful"
|
||||
ElectricChargeDimension = "Electrical charge"
|
||||
ElectricPotentialDimension = "Electric potential"
|
||||
ElectricCapacitanceDimension = "Electrical capacity"
|
||||
ElectricResistanceDimension = "Electrical resistance"
|
||||
ElectricConductanceDimension = "electrical conductance"
|
||||
MagneticFluxDimension = "magnetic flux"
|
||||
MagneticFieldDimension = "Magnetic field"
|
||||
InductanceDimension = "Inductance"
|
||||
CatalyticActivityDimension = "Catalytic activity"
|
||||
SurfaceDimension = "Surface"
|
||||
VolumeDimension = "Volume"
|
||||
SpeedDimension = "Speed"
|
||||
|
||||
@@ -17,4 +17,28 @@ FactorizedForm = "Forma factorizada"
|
||||
Discriminant = "Discriminante"
|
||||
OnlyRoot = "Raíz"
|
||||
FirstRoot = "Primera raíz"
|
||||
SecondRoot = "Segunda raíz"
|
||||
SecondRoot = "Segunda raíz"
|
||||
TimeDimension = "Tiempo"
|
||||
DistanceDimension = "Distancia"
|
||||
MassDimension = "Masa"
|
||||
CurrentDimension = "Correr"
|
||||
TemperatureDimension = "La temperatura"
|
||||
AmountOfSubstanceDimension = "cantidad de materia"
|
||||
LuminousIntensityDimension = "Intensidad de luz"
|
||||
FrequencyDimension = "Frecuencia"
|
||||
ForceDimension = "Fuerza"
|
||||
PressureDimension = "Presión"
|
||||
EnergyDimension = "Energía"
|
||||
PowerDimension = "Potencia"
|
||||
ElectricChargeDimension = "Carga eléctrica"
|
||||
ElectricPotentialDimension = "Potencial eléctrico"
|
||||
ElectricCapacitanceDimension = "Capacidad eléctrica"
|
||||
ElectricResistanceDimension = "Resistencia eléctrica"
|
||||
ElectricConductanceDimension = "conductancia eléctrica"
|
||||
MagneticFluxDimension = "flujo magnético"
|
||||
MagneticFieldDimension = "Campo magnético"
|
||||
InductanceDimension = "Inductancia"
|
||||
CatalyticActivityDimension = "Actividad catalítica"
|
||||
SurfaceDimension = "Superficie"
|
||||
VolumeDimension = "Volumen"
|
||||
SpeedDimension = "Velocidad"
|
||||
|
||||
@@ -17,4 +17,28 @@ FactorizedForm = "Forme factorisée"
|
||||
Discriminant = "Discriminant"
|
||||
OnlyRoot = "Racine"
|
||||
FirstRoot = "Première racine"
|
||||
SecondRoot = "Seconde racine"
|
||||
SecondRoot = "Seconde racine"
|
||||
TimeDimension = "Temps"
|
||||
DistanceDimension = "Distance"
|
||||
MassDimension = "Masse"
|
||||
CurrentDimension = "Courant"
|
||||
TemperatureDimension = "Température"
|
||||
AmountOfSubstanceDimension = "Quantité de matière"
|
||||
LuminousIntensityDimension = "Intensité lumineuse"
|
||||
FrequencyDimension = "Fréquence"
|
||||
ForceDimension = "Force"
|
||||
PressureDimension = "Pression"
|
||||
EnergyDimension = "Énergie"
|
||||
PowerDimension = "Puissance"
|
||||
ElectricChargeDimension = "Charge électrique"
|
||||
ElectricPotentialDimension = "Potentiel électrique"
|
||||
ElectricCapacitanceDimension = "Capacité électrique"
|
||||
ElectricResistanceDimension = "Résistance électrique"
|
||||
ElectricConductanceDimension = "Conductance électrique"
|
||||
MagneticFluxDimension = "Flux magnétique"
|
||||
MagneticFieldDimension = "Champ magnétique"
|
||||
InductanceDimension = "Inductance"
|
||||
CatalyticActivityDimension = "Activité catalytique"
|
||||
SurfaceDimension = "Surface"
|
||||
VolumeDimension = "Volume"
|
||||
SpeedDimension = "Vitesse"
|
||||
@@ -17,4 +17,28 @@ FactorizedForm = "Factorizált forma"
|
||||
Discriminant = "Discriminant"
|
||||
OnlyRoot = "Gyökér"
|
||||
FirstRoot = "Első gyökér"
|
||||
SecondRoot = "Második gyökér"
|
||||
SecondRoot = "Második gyökér"
|
||||
TimeDimension = "Idő"
|
||||
DistanceDimension = "Távolság"
|
||||
MassDimension = "Tömeg"
|
||||
CurrentDimension = "Futó"
|
||||
TemperatureDimension = "Hőfok"
|
||||
AmountOfSubstanceDimension = "Az anyag mennyisége"
|
||||
LuminousIntensityDimension = "Fény intenzitása"
|
||||
FrequencyDimension = "Frekvencia"
|
||||
ForceDimension = "Erő"
|
||||
PressureDimension = "Nyomás"
|
||||
EnergyDimension = "Energia"
|
||||
PowerDimension = "Erős"
|
||||
ElectricChargeDimension = "Elektromos töltő"
|
||||
ElectricPotentialDimension = "Elektromos potenciál"
|
||||
ElectricCapacitanceDimension = "Elektromos kapacitás"
|
||||
ElectricResistanceDimension = "Elektromos ellenállás"
|
||||
ElectricConductanceDimension = "elektromos vezetőképesség"
|
||||
MagneticFluxDimension = "mágneses fluxus"
|
||||
MagneticFieldDimension = "Mágneses mező"
|
||||
InductanceDimension = "Induktivitás"
|
||||
CatalyticActivityDimension = "Katalitikus aktivitás"
|
||||
SurfaceDimension = "Felület"
|
||||
VolumeDimension = "Hangerő"
|
||||
SpeedDimension = "Sebesség"
|
||||
|
||||
@@ -17,4 +17,28 @@ FactorizedForm = "Forma fattorizzata"
|
||||
Discriminant = "Discriminante"
|
||||
OnlyRoot = "Radice"
|
||||
FirstRoot = "Prima radice"
|
||||
SecondRoot = "Seconda radice"
|
||||
SecondRoot = "Seconda radice"
|
||||
TimeDimension = "Volta"
|
||||
DistanceDimension = "Distanza"
|
||||
MassDimension = "Messa"
|
||||
CurrentDimension = "In esecuzione"
|
||||
TemperatureDimension = "Temperatura"
|
||||
AmountOfSubstanceDimension = "Quantità di materia"
|
||||
LuminousIntensityDimension = "Intensità luminosa"
|
||||
FrequencyDimension = "Frequenza"
|
||||
ForceDimension = "Forza"
|
||||
PressureDimension = "Pressione"
|
||||
EnergyDimension = "Energia"
|
||||
PowerDimension = "Potere"
|
||||
ElectricChargeDimension = "Carica elettrica"
|
||||
ElectricPotentialDimension = "Potenziale elettrico"
|
||||
ElectricCapacitanceDimension = "Capacità elettrica"
|
||||
ElectricResistanceDimension = "Resistenza elettrica"
|
||||
ElectricConductanceDimension = "conduttanza elettrica"
|
||||
MagneticFluxDimension = "flusso magnetico"
|
||||
MagneticFieldDimension = "Campo magnetico"
|
||||
InductanceDimension = "Induttanza"
|
||||
CatalyticActivityDimension = "Attività catalitica"
|
||||
SurfaceDimension = "Superficie"
|
||||
VolumeDimension = "Volume"
|
||||
SpeedDimension = "Velocità"
|
||||
|
||||
@@ -17,4 +17,28 @@ FactorizedForm = "Factorized vorm"
|
||||
Discriminant = "Discriminant"
|
||||
OnlyRoot = "Wortel"
|
||||
FirstRoot = "Eerste wortel"
|
||||
SecondRoot = "Tweede wortel"
|
||||
SecondRoot = "Tweede wortel"
|
||||
TimeDimension = "Tijd"
|
||||
DistanceDimension = "Afstand"
|
||||
MassDimension = "Massa"
|
||||
CurrentDimension = "Rennen"
|
||||
TemperatureDimension = "Temperatuur"
|
||||
AmountOfSubstanceDimension = "Hoeveelheid materie"
|
||||
LuminousIntensityDimension = "Lichtsterkte"
|
||||
FrequencyDimension = "Frequentie"
|
||||
ForceDimension = "Kracht"
|
||||
PressureDimension = "Druk"
|
||||
EnergyDimension = "Energie"
|
||||
PowerDimension = "Kracht"
|
||||
ElectricChargeDimension = "Elektrische lading"
|
||||
ElectricPotentialDimension = "elektrische potentiaal"
|
||||
ElectricCapacitanceDimension = "elektrische capaciteit:"
|
||||
ElectricResistanceDimension = "Elektrische weerstand"
|
||||
ElectricConductanceDimension = "elektrische geleiding:"
|
||||
MagneticFluxDimension = "magnetische flux"
|
||||
MagneticFieldDimension = "Magnetisch veld"
|
||||
InductanceDimension = "Inductie"
|
||||
CatalyticActivityDimension = "Katalytische activiteit"
|
||||
SurfaceDimension = "Oppervlak"
|
||||
VolumeDimension = "Volume"
|
||||
SpeedDimension = "Snelheid"
|
||||
|
||||
@@ -17,4 +17,28 @@ FactorizedForm = "Factorized form"
|
||||
Discriminant = "Discriminante"
|
||||
OnlyRoot = "Raiz"
|
||||
FirstRoot = "Primeira raiz"
|
||||
SecondRoot = "Segunda raiz"
|
||||
SecondRoot = "Segunda raiz"
|
||||
TimeDimension = "Tempo"
|
||||
DistanceDimension = "Distância"
|
||||
MassDimension = "Massa"
|
||||
CurrentDimension = "Corrida"
|
||||
TemperatureDimension = "Temperatura"
|
||||
AmountOfSubstanceDimension = "Quantidade de matéria"
|
||||
LuminousIntensityDimension = "Intensidade da luz"
|
||||
FrequencyDimension = "Frequência"
|
||||
ForceDimension = "Força"
|
||||
PressureDimension = "Pressão"
|
||||
EnergyDimension = "Energia"
|
||||
PowerDimension = "Poderoso"
|
||||
ElectricChargeDimension = "Carga elétrica"
|
||||
ElectricPotentialDimension = "Potencial elétrico"
|
||||
ElectricCapacitanceDimension = "Capacidade elétrica"
|
||||
ElectricResistanceDimension = "Resistência elétrica"
|
||||
ElectricConductanceDimension = "condutância elétrica"
|
||||
MagneticFluxDimension = "fluxo magnético"
|
||||
MagneticFieldDimension = "Campo magnético"
|
||||
InductanceDimension = "Indutância"
|
||||
CatalyticActivityDimension = "Atividade catalítica"
|
||||
SurfaceDimension = "Superfície"
|
||||
VolumeDimension = "Volume"
|
||||
SpeedDimension = "Velocidade"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define POINCARE_UNIT_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <apps/i18n.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -105,6 +106,7 @@ public:
|
||||
{}
|
||||
|
||||
virtual const Vector<int> dimensionVector() const { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; };
|
||||
virtual const I18n::Message dimensionMessage() const = 0;
|
||||
virtual int numberOfRepresentatives() const { return 0; };
|
||||
/* representativesOfSameDimension returns a pointer to the array containing
|
||||
* all representatives for this's dimension. */
|
||||
@@ -146,6 +148,7 @@ public:
|
||||
public:
|
||||
constexpr static TimeRepresentative Default() { return TimeRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 1, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::TimeDimension; }
|
||||
int numberOfRepresentatives() const override { return 7; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -160,6 +163,7 @@ public:
|
||||
public:
|
||||
constexpr static DistanceRepresentative Default() { return DistanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 1, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::DistanceDimension; }
|
||||
int numberOfRepresentatives() const override { return 8; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -175,6 +179,7 @@ public:
|
||||
public:
|
||||
constexpr static MassRepresentative Default() { return MassRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::MassDimension; }
|
||||
int numberOfRepresentatives() const override { return 7; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
const Prefix * basePrefix() const override;
|
||||
@@ -191,6 +196,7 @@ public:
|
||||
public:
|
||||
constexpr static CurrentRepresentative Default() { return CurrentRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::CurrentDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -204,6 +210,7 @@ public:
|
||||
static double ConvertTemperatures(double value, const Representative * source, const Representative * target);
|
||||
constexpr static TemperatureRepresentative Default() { return TemperatureRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 1, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::TemperatureDimension; }
|
||||
int numberOfRepresentatives() const override { return 3; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -221,6 +228,7 @@ public:
|
||||
public:
|
||||
constexpr static AmountOfSubstanceRepresentative Default() { return AmountOfSubstanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 1, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::AmountOfSubstanceDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -233,6 +241,7 @@ public:
|
||||
public:
|
||||
constexpr static LuminousIntensityRepresentative Default() { return LuminousIntensityRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 1}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::LuminousIntensityDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool isBaseUnit() const override { return this == representativesOfSameDimension(); }
|
||||
@@ -245,6 +254,7 @@ public:
|
||||
public:
|
||||
constexpr static FrequencyRepresentative Default() { return FrequencyRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -1, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::FrequencyDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -256,6 +266,7 @@ public:
|
||||
public:
|
||||
constexpr static ForceRepresentative Default() { return ForceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 1, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::ForceDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -267,6 +278,7 @@ public:
|
||||
public:
|
||||
constexpr static PressureRepresentative Default() { return PressureRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = -1, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::PressureDimension; }
|
||||
int numberOfRepresentatives() const override { return 3; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -278,6 +290,7 @@ public:
|
||||
public:
|
||||
constexpr static EnergyRepresentative Default() { return EnergyRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 2, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::EnergyDimension; }
|
||||
int numberOfRepresentatives() const override { return 2; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
bool hasSpecialAdditionalExpressions(double value, Preferences::UnitFormat unitFormat) const override { return true; }
|
||||
@@ -291,6 +304,7 @@ public:
|
||||
public:
|
||||
constexpr static PowerRepresentative Default() { return PowerRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -3, .distance = 2, .mass = 1, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::PowerDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -303,6 +317,7 @@ public:
|
||||
using Representative::Representative;
|
||||
constexpr static ElectricChargeRepresentative Default() { return ElectricChargeRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 1, .distance = 0, .mass = 0, .current = 1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::ElectricChargeDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
};
|
||||
@@ -312,6 +327,7 @@ public:
|
||||
public:
|
||||
constexpr static ElectricPotentialRepresentative Default() { return ElectricPotentialRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -3, .distance = 2, .mass = 1, .current = -1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::ElectricPotentialDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -323,6 +339,7 @@ public:
|
||||
public:
|
||||
constexpr static ElectricCapacitanceRepresentative Default() { return ElectricCapacitanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 4, .distance = -2, .mass = -1, .current = 2, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::ElectricCapacitanceDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -334,6 +351,7 @@ public:
|
||||
public:
|
||||
constexpr static ElectricResistanceRepresentative Default() { return ElectricResistanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -3, .distance = 2, .mass = 1, .current = -2, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::ElectricResistanceDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -345,6 +363,7 @@ public:
|
||||
public:
|
||||
constexpr static ElectricConductanceRepresentative Default() { return ElectricConductanceRepresentative(nullptr, 1., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 3, .distance = -2, .mass = -1, .current = 2, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::ElectricConductanceDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -356,6 +375,7 @@ public:
|
||||
public:
|
||||
constexpr static MagneticFluxRepresentative Default() { return MagneticFluxRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 2, .mass = 1, .current = -1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::MagneticFluxDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -367,6 +387,7 @@ public:
|
||||
public:
|
||||
constexpr static MagneticFieldRepresentative Default() { return MagneticFieldRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 0, .mass = 1, .current = -1, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::MagneticFieldDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -378,6 +399,7 @@ public:
|
||||
public:
|
||||
constexpr static InductanceRepresentative Default() { return InductanceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -2, .distance = 2, .mass = 1, .current = -2, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::InductanceDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -389,6 +411,7 @@ public:
|
||||
public:
|
||||
constexpr static CatalyticActivityRepresentative Default() { return CatalyticActivityRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = -1, .distance = 0, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 1, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::CatalyticActivityDimension; }
|
||||
int numberOfRepresentatives() const override { return 1; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
private:
|
||||
@@ -400,6 +423,7 @@ public:
|
||||
public:
|
||||
constexpr static SurfaceRepresentative Default() { return SurfaceRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 2, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::SurfaceDimension; }
|
||||
int numberOfRepresentatives() const override { return 2; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
const Representative * standardRepresentative(double value, double exponent, ExpressionNode::ReductionContext reductionContext, const Prefix * * prefix) const override;
|
||||
@@ -414,6 +438,7 @@ public:
|
||||
public:
|
||||
constexpr static VolumeRepresentative Default() { return VolumeRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int> dimensionVector() const override { return Vector<int>{.time = 0, .distance = 3, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::VolumeDimension; }
|
||||
int numberOfRepresentatives() const override { return 8; }
|
||||
const Representative * representativesOfSameDimension() const override;
|
||||
const Representative * standardRepresentative(double value, double exponent, ExpressionNode::ReductionContext reductionContext, const Prefix * * prefix) const override;
|
||||
@@ -428,6 +453,7 @@ public:
|
||||
public:
|
||||
constexpr static SpeedRepresentative Default() { return SpeedRepresentative(nullptr, 0., Prefixable::None, Prefixable::None); }
|
||||
const Vector<int>dimensionVector() const override { return Vector<int>{.time = -1, .distance = 1, .mass = 0, .current = 0, .temperature = 0, .amountOfSubstance = 0, .luminousIntensity = 0}; }
|
||||
const I18n::Message dimensionMessage() const override { return I18n::Message::SpeedDimension; }
|
||||
const Representative * standardRepresentative(double value, double exponent, ExpressionNode::ReductionContext reductionContext, const Prefix * * prefix) const override { return nullptr; }
|
||||
bool hasSpecialAdditionalExpressions(double value, Preferences::UnitFormat unitFormat) const override { return true; }
|
||||
int setAdditionalExpressions(double value, Expression * dest, int availableLength, ExpressionNode::ReductionContext reductionContext) const override;
|
||||
@@ -680,7 +706,7 @@ public:
|
||||
static bool CanParse(const char * symbol, size_t length, const Representative * * representative, const Prefix * * prefix);
|
||||
static void ChooseBestRepresentativeAndPrefixForValue(Expression units, double * value, ExpressionNode::ReductionContext reductionContext);
|
||||
static bool ShouldDisplayAdditionalOutputs(double value, Expression unit, Preferences::UnitFormat unitFormat);
|
||||
static int SetAdditionalExpressions(Expression units, double value, Expression * dest, int availableLength, ExpressionNode::ReductionContext reductionContext);
|
||||
static int SetAdditionalExpressionsAndMessage(Expression units, double value, Expression * dest, int availableLength, ExpressionNode::ReductionContext reductionContext, I18n::Message * message);
|
||||
static Expression BuildSplit(double value, const Unit * units, int length, ExpressionNode::ReductionContext reductionContext);
|
||||
static Expression ConvertTemperatureUnits(Expression e, Unit unit, ExpressionNode::ReductionContext reductionContext);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <utility>
|
||||
#include <apps/i18n.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -775,11 +776,10 @@ bool Unit::ShouldDisplayAdditionalOutputs(double value, Expression unit, Prefere
|
||||
return e.type() == ExpressionNode::Type::Unit && !e.convert<Unit>().isBaseUnit();
|
||||
};
|
||||
|
||||
return (representative != nullptr && representative->hasSpecialAdditionalExpressions(value, unitFormat))
|
||||
|| unit.hasExpression(isNonBase, nullptr);
|
||||
return representative != nullptr || unit.hasExpression(isNonBase, nullptr);
|
||||
}
|
||||
|
||||
int Unit::SetAdditionalExpressions(Expression units, double value, Expression * dest, int availableLength, ExpressionNode::ReductionContext reductionContext) {
|
||||
int Unit::SetAdditionalExpressionsAndMessage(Expression units, double value, Expression * dest, int availableLength, ExpressionNode::ReductionContext reductionContext, I18n::Message * message) {
|
||||
if (units.isUninitialized()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -787,6 +787,7 @@ int Unit::SetAdditionalExpressions(Expression units, double value, Expression *
|
||||
if (!representative) {
|
||||
return 0;
|
||||
}
|
||||
*message = representative->dimensionMessage();
|
||||
return representative->setAdditionalExpressions(value, dest, availableLength, reductionContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -456,7 +456,8 @@ void assert_additional_results_compute_to(const char * expression, const char *
|
||||
quiz_assert(length == 0);
|
||||
return;
|
||||
}
|
||||
const int numberOfResults = Unit::SetAdditionalExpressions(units, value, additional, maxNumberOfResults, reductionContext);
|
||||
I18n::Message unitMessage;
|
||||
const int numberOfResults = Unit::SetAdditionalExpressionsAndMessage(units, value, additional, maxNumberOfResults, reductionContext, unitMessage);
|
||||
|
||||
quiz_assert(numberOfResults == length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user