diff --git a/.gitignore b/.gitignore index 83118b313..6f275a76e 100644 --- a/.gitignore +++ b/.gitignore @@ -81,4 +81,5 @@ Thumbs.db desktop.ini # Editors temporary files -*~ \ No newline at end of file +*~ +/client.pro.user.2.7pre1 diff --git a/client.pro b/client.pro index fc6916e99..7f7855b9c 100644 --- a/client.pro +++ b/client.pro @@ -16,6 +16,7 @@ WITH_SAMPLES = ON equals(WITH_BLACKMISC, ON) { SUBDIRS += src/blackmisc + SUBDIRS += src/blackmisc_cpp2xml } equals(WITH_BLACKCORE, ON) { @@ -50,8 +51,9 @@ equals(WITH_SAMPLES, ON) { SUBDIRS += samples/logging/sample_logging.pro SUBDIRS += samples/plugin/sample_plugin.pro SUBDIRS += samples/pluginmgr/sample_pluginmgr.pro - SUBDIRS += samples/blackmiscquantities/sample_quantities_avionics.pro SUBDIRS += samples/blackmiscvectorgeo/sample_vector_geo.pro + SUBDIRS += samples/blackmiscquantities/sample_quantities_avionics.pro + SUBDIRS += samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro SUBDIRS += samples/dbusserver/sample_dbusserver.pro SUBDIRS += samples/dbusclient/sample_dbusclient.pro } diff --git a/samples/blackmiscquantities/main.cpp b/samples/blackmiscquantities/main.cpp index 906cb356f..147754977 100644 --- a/samples/blackmiscquantities/main.cpp +++ b/samples/blackmiscquantities/main.cpp @@ -2,10 +2,11 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include #include "samplesphysicalquantities.h" #include "samplesaviation.h" -#include +#include "blackmisc/blackmiscfreefunctions.h" using namespace BlackMisc; using namespace BlackMiscTest; @@ -15,8 +16,19 @@ using namespace BlackMiscTest; */ int main(int argc, char *argv[]) { + BlackMisc::initResources(); + QFile file(":/translations/blackmisc_i18n_de.qm"); + qDebug() << (file.exists() ? "Found translations in resources" : "No translations in resources"); + + QTranslator translator; + translator.load("blackmisc_i18n_de", ":/translations/"); QCoreApplication a(argc, argv); + qDebug() << "Use I18N version, y? n?"; + int yn = getchar(); + bool t = (yn == 'y' || yn == 'Y') ? a.installTranslator(&translator) : false; + qDebug() << (t ? "Installed translator" : "No translator "); + CSamplesPhysicalQuantities::samples(); CSamplesAviation::samples(); diff --git a/samples/blackmiscquantities/sample_quantities_avionics.pro b/samples/blackmiscquantities/sample_quantities_avionics.pro index 2e9e95d87..698e25923 100644 --- a/samples/blackmiscquantities/sample_quantities_avionics.pro +++ b/samples/blackmiscquantities/sample_quantities_avionics.pro @@ -1,13 +1,12 @@ -QT += core -QT -= gui +QT += core dbus -TARGET = sample_physicalquantities +TARGET = sample_quantities_avionics TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle -DEPENDPATH += . ../../src +DEPENDPATH += . ../../src/blackmisc INCLUDEPATH += . ../../src LIBS += -L../../lib -lblackmisc @@ -19,3 +18,5 @@ DESTDIR = ../../bin HEADERS += *.h SOURCES += *.cpp + +OTHER_FILES += diff --git a/samples/blackmiscquantities/samplesaviation.cpp b/samples/blackmiscquantities/samplesaviation.cpp index 8ca2ba9c1..a29f30791 100644 --- a/samples/blackmiscquantities/samplesaviation.cpp +++ b/samples/blackmiscquantities/samplesaviation.cpp @@ -16,16 +16,12 @@ namespace BlackMiscTest */ int CSamplesAviation::samples() { - CHeading h1(180, true, CAngleUnit::deg()); - CHeading h2(180, false, CAngleUnit::deg()); + CHeading h1(180, CHeading::Magnetic, CAngleUnit::deg()); + CHeading h2(180, CHeading::True, CAngleUnit::deg()); qDebug() << h1; qDebug() << h1 << h2 << (h1 == h2) << (h1 != h2) << (h1 == h1); - CAviationVerticalPositions vp1 = CAviationVerticalPositions::fromAltitudeAndElevationInFt(10000.0, 1111.0); - CAviationVerticalPositions vp2 = vp1; - qDebug() << vp1 << (vp1 == vp2) << (vp1 != vp2); - CComSystem c1 = CComSystem::getCom1System(125.3); qDebug() << c1; c1.setActiveUnicom(); diff --git a/samples/blackmiscquantities/samplesaviation.h b/samples/blackmiscquantities/samplesaviation.h index 67093c95e..f4ebe94af 100644 --- a/samples/blackmiscquantities/samplesaviation.h +++ b/samples/blackmiscquantities/samplesaviation.h @@ -8,7 +8,6 @@ #include "blackmisc/pqconstants.h" #include "blackmisc/avheading.h" -#include "blackmisc/avverticalpositions.h" #include "blackmisc/aviocomsystem.h" #include "blackmisc/avionavsystem.h" #include "blackmisc/aviotransponder.h" diff --git a/samples/blackmiscquantities/samplesphysicalquantities.cpp b/samples/blackmiscquantities/samplesphysicalquantities.cpp index 7b4eaafeb..bc9c87344 100644 --- a/samples/blackmiscquantities/samplesphysicalquantities.cpp +++ b/samples/blackmiscquantities/samplesphysicalquantities.cpp @@ -26,9 +26,9 @@ int CSamplesPhysicalQuantities::samples() CLengthUnit lu1(CLengthUnit::cm()); CLengthUnit lu2(CLengthUnit::ft()); - QString lu1s = lu1.toQString(); - QString lu2s = lu2.toQString(); - qDebug() << lu1 << lu2 << lu1s << lu2s; + QString lu1s = lu1.toQString(true); + QString lu2s = lu2.toQString(true); + qDebug() << lu1 << lu2 << lu1s << lu2s << lu1.getName(true) << lu2.getName(true); const CLength l1(5.0, CLengthUnit::ft()); // 5 ft CLength l2(1, CLengthUnit::NM()); // 1NM CLength l3(1, CLengthUnit::km()); @@ -57,7 +57,7 @@ int CSamplesPhysicalQuantities::samples() CSpeed s2 = CSpeed(1000, CSpeedUnit::ft_min()); CSpeed s3 = CSpeed(s2); s3.switchUnit(CSpeedUnit::m_s()); - qDebug() << s1 << s1.convertedSiValueRoundedWithUnit() << s1.valueRoundedWithUnit(CSpeedUnit::NM_h()); + qDebug() << s1 << s1.valueRoundedWithUnit(CSpeedUnit::defaultUnit()) << s1.valueRoundedWithUnit(CSpeedUnit::NM_h()); qDebug() << s2 << s3; CAngle a1(180, CAngleUnit::deg()); @@ -72,13 +72,13 @@ int CSamplesPhysicalQuantities::samples() a2 = a1 + a1; a2.switchUnit(CAngleUnit::deg()); - qDebug() << a1.unitValueRoundedWithUnit() << a1.piFactor(); + qDebug() << a1.valueRoundedWithUnit() << a1.piFactor(); qDebug() << a2; a3.switchUnit(CAngleUnit::sexagesimalDeg()); a4.switchUnit(CAngleUnit::deg()); qDebug() << a3 << a4; - CMass w1(1, CMassUnit::t()); + CMass w1(1, CMassUnit::tonne()); CMass w2(w1); w2.switchUnit(CMassUnit::lb()); qDebug() << w1 << w1.valueRoundedWithUnit(CMassUnit::kg()) << w2; @@ -89,8 +89,8 @@ int CSamplesPhysicalQuantities::samples() CTemperature t1; CTemperature t2(20, CTemperatureUnit::C()); CTemperature t3(1, CTemperatureUnit::F()); - qDebug() << t1 << t2 << t2.convertedSiValueRoundedWithUnit(); - qDebug() << t3 << t3.valueRoundedWithUnit(CTemperatureUnit::C()); + qDebug() << t1 << t2 << t2.valueRoundedWithUnit(CTemperatureUnit::defaultUnit(), -1, true); + qDebug() << t3.valueRoundedWithUnit(CTemperatureUnit::F(), -1, true) << t3.valueRoundedWithUnit(CTemperatureUnit::C(), -1, true) << "I18N/UTF"; // some logging with CLogMessage // bDebug << p1; @@ -108,10 +108,13 @@ int CSamplesPhysicalQuantities::samples() CTime ti1(1, CTimeUnit::h()); CTime ti2(ti1); ti2.switchUnit(CTimeUnit::ms()); - qDebug() << ti1 << ti2; + CTime ti3(1.0101, CTimeUnit::hms()); + CTime ti4(1.15, CTimeUnit::hrmin()); + CTime ti5(1.30, CTimeUnit::minsec()); + qDebug() << ti1 << ti2 << ti3 << ti4 << ti5; CAcceleration ac1(10, CAccelerationUnit::m_s2()); - qDebug() << ac1; + qDebug() << ac1 << ac1.valueRoundedWithUnit(-1, true) << "I18N/UTF"; // bye qDebug() << "-----------------------------------------------"; diff --git a/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml new file mode 100644 index 000000000..cdabcbf5a --- /dev/null +++ b/samples/blackmiscquantities_dbus/BlackMiscTest.Testservice.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/blackmiscquantities_dbus/main.cpp b/samples/blackmiscquantities_dbus/main.cpp new file mode 100644 index 000000000..6e571e3da --- /dev/null +++ b/samples/blackmiscquantities_dbus/main.cpp @@ -0,0 +1,176 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include +#include +#include +#include + +#include "testservice.h" +#include "testservice_adaptor.h" +#include "testservice_interface.h" +#include "testservicetool.h" + +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Math; +using namespace BlackMisc::Geo; +using namespace BlackMiscTest; + +/*! + * Sample tests + */ +int main(int argc, char *argv[]) +{ + BlackMisc::registerMetadata(); + QCoreApplication a(argc, argv); + + // init + if (argc < 1) { + qFatal("Missing name of executable"); + } + const QString executable = QString(argv[0]); + Testservice* pTestservice = NULL; + TestserviceAdaptor* pTestserviceAdaptor = NULL; + + // Create a Testservice instance and register it with the session bus only if + // the service isn't already available. + QDBusConnection connection = QDBusConnection::sessionBus(); + if (!connection.interface()->isServiceRegistered(Testservice::ServiceName)) { + pTestservice = new Testservice(&a); + pTestserviceAdaptor = new TestserviceAdaptor(pTestservice); + + if (!connection.registerService(Testservice::ServiceName)) { + QDBusError err = connection.lastError(); + qWarning() << err.message(); + qWarning() << "Started dbus-daemon.exe --session?"; + qWarning() << "Created directory session.d? See https://dev.vatsim-germany.org/projects/vatpilotclient/wiki/DBusExample#Running-the-example"; + qFatal("Could not register service!"); + } + + if (!connection.registerObject(Testservice::ServicePath, pTestservice)) { + qFatal("Could not register service object!"); + } + + qDebug() << "Registration running as pid: " << TestserviceTool::getPid(); + if (pTestservice) qDebug() << "Service registered"; + if (pTestserviceAdaptor) qDebug() << "Adaptor object registered"; + + new TestserviceAdaptor(pTestservice); // adaptor + QString service; // service not needed + if (QDBusConnection::sessionBus().connect( + service, Testservice::ServicePath, Testservice::ServiceName, + "sendStringMessage", pTestservice, SLOT(receiveStringMessage(const QString &)))) { + qDebug() << "Connected object with bus sendStringMessage"; + } else { + qFatal("Cannot connect service with DBus"); + } + + // Call myself to implement client + TestserviceTool::startNewProcess(executable, &a); + + } else { + qDebug() << "Already registered, assuming 2nd pid: " << TestserviceTool::getPid(); + BlackmisctestTestserviceInterface testserviceInterface(Testservice::ServiceName, Testservice::ServicePath, connection, &a); + + CSpeed speed(200, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h()); + CAltitude al(1000, CAltitude::MeanSeaLevel, CLengthUnit::ft()); + + while (true) { + QDBusMessage m = QDBusMessage::createSignal( + Testservice::ServicePath, Testservice::ServiceName, + "sendStringMessage"); + + //The << operator is used to add the parameters for the slot + QDateTime dtnow = QDateTime::currentDateTimeUtc(); + QString msg = QString("Message from %1 at %2").arg(TestserviceTool::getPid()).arg(dtnow.toString("MM/dd/yyyy @ hh:mm:ss")); + m << msg; + + // We send this as a non-replying message. This is used for sending errors, replys, signals, + // and method calls (slots) that don't return + if (connection.send(m)) { + qDebug() << "Send via low level method" << m; + } + + // same as interface message + testserviceInterface.receiveStringMessage(msg); + qDebug() << "Send string via interface" << msg; + + // a list + QList list; + list << 1.0 << 2.0 << 3.0; + testserviceInterface.receiveList(list); + qDebug() << "Send list via interface" << list; + + // PQs + testserviceInterface.receiveSpeed(speed); + qDebug() << "Send speed via interface" << speed; + + speed.switchUnit(CSpeedUnit::kts()); + testserviceInterface.receiveSpeed(speed); + qDebug() << "Send speed via interface" << speed; + TestserviceTool::sleep(2500); + speed.switchUnit(CSpeedUnit::km_h()); + speed.addValueSameUnit(1.0); + + // Aviation + CComSystem comSystem = CComSystem("DBUS COM1", CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress(), CPhysicalQuantitiesConstants::FrequencyUnicom()); + testserviceInterface.receiveComUnit(comSystem); + qDebug() << "Send COM via interface" << comSystem; + + QDBusVariant qv(QVariant::fromValue(al)); + testserviceInterface.receiveVariant(qv); + testserviceInterface.receiveAltitude(al); + qDebug() << "Send altitude via interface" << al; + al.addValueSameUnit(1); + + CTransponder transponder("transponder", 7000, CTransponder::ModeC); + testserviceInterface.receiveTransponder(transponder); + qDebug() << "Send transponder via interface" << transponder; + + CTrack track(123.45, CTrack::Magnetic, CAngleUnit::deg()); + testserviceInterface.receiveTrack(track); + qDebug() << "Send track via interface" << track; + + CLength len(33, CLengthUnit::m()); + testserviceInterface.receiveLength(len); + qDebug() << "Send length via interface" << len; + + CAltitude alt(33, CAltitude::MeanSeaLevel, CLengthUnit::m()); + testserviceInterface.receiveLength(alt); + qDebug() << "Send altitude via interface" << alt; + + QVariantList lengths; + lengths << QVariant::fromValue(len); + lengths << QVariant::fromValue(alt); + testserviceInterface.receiveLengths(lengths); + qDebug() << "Send lengths via interface"; + + TestserviceTool::sleep(2500); + + // Math + CMatrix3x3 m33; + m33.setCellIndex(); + testserviceInterface.receiveMatrix(m33); + qDebug() << "Send matrix" << m33; + + // Geo + // EDDF: 50° 2′ 0″ N, 8° 34′ 14″ E, 100m MSL + CLatitude lat = CLatitude::fromWgs84("50° 2′ 1″ 23 N"); + CLongitude lon = CLongitude::fromWgs84("8° 34′ 14″ E"); + CLength height(100, CLengthUnit::m()); + CCoordinateGeodetic geoPos(lat, lon, height); + testserviceInterface.receiveGeoPosition(geoPos); + qDebug() << "Send geo position" << geoPos; + + // next round? + qDebug() << "Key ......."; + getchar(); + } + } + + return a.exec(); +} diff --git a/samples/blackmiscquantities_dbus/readme.txt b/samples/blackmiscquantities_dbus/readme.txt new file mode 100644 index 000000000..6c74d5ca4 --- /dev/null +++ b/samples/blackmiscquantities_dbus/readme.txt @@ -0,0 +1,10 @@ +Starting: dbus-daemon.exe --session +- blocks CMD (sometimes daemon continues to run when pressing CTRL/C) +- does not start without directory session.d, i.e. ..\Qt\Qt5.1.0DBus\qtbase\etc\dbus-1\session.d + +qdbuscpp2xml testservice.h -x blackmisc_cpp2xml.dll -o BlackMiscTest.Testservice.xml +Set search path for plugins: env.var. QT_PLUGIN_PATH + +Done automatically, but if required manually +Interface: qdbusxml2cpp blackbus.testservice.xml -p itestservice +Adaptor: qdbusxml2cpp blackbus.testservice.xml -a atestservice diff --git a/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro b/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro new file mode 100644 index 000000000..ae5acc6c6 --- /dev/null +++ b/samples/blackmiscquantities_dbus/sample_quantities_avionics_dbus.pro @@ -0,0 +1,29 @@ +QT += core dbus + +TARGET = sample_quantities_avionics_dbus +TEMPLATE = app + +CONFIG += console c++11 +CONFIG -= app_bundle + +# Causes nmake to run qdbusxml2cpp to automatically generate the dbus adaptor and interface classes, +# then automatically adds them to the sources to compile +DBUS_ADAPTORS += BlackMiscTest.Testservice.xml +DBUS_INTERFACES += BlackMiscTest.Testservice.xml +QDBUSXML2CPP_INTERFACE_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h +QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h + +DEPENDPATH += . ../../src/blackmisc +INCLUDEPATH += . ../../src + +LIBS += -L../../lib -lblackmisc + +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a + +DESTDIR = ../../bin + +HEADERS += *.h +SOURCES += *.cpp + +OTHER_FILES += readme.txt BlackMiscTest.Testservice.xml diff --git a/samples/blackmiscquantities_dbus/testservice.cpp b/samples/blackmiscquantities_dbus/testservice.cpp new file mode 100644 index 000000000..6d88cf33c --- /dev/null +++ b/samples/blackmiscquantities_dbus/testservice.cpp @@ -0,0 +1,124 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "testservice.h" + +namespace BlackMiscTest +{ + +const QString Testservice::ServiceName = QString(BLACKMISCKTEST_SERVICENAME); +const QString Testservice::ServicePath = QString(BLACKMISCKTEST_SERVICEPATH); + +/* + * Constructor + */ +Testservice::Testservice(QObject *parent) : QObject(parent) +{ + // void +} + +/* + * Slot to receive messages + */ +void Testservice::receiveStringMessage(const QString &message) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received message:" << message; +} + +/* + * Receive variant + */ +void Testservice::receiveVariant(const QDBusVariant &variant) +{ + QVariant qv = variant.variant(); + BlackMisc::Aviation::CAltitude altitude = qv.value(); + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received variant:" << altitude; +} + +/* + * Receive speed + */ +void Testservice::receiveSpeed(const BlackMisc::PhysicalQuantities::CSpeed &speed) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received speed:" << speed; +} + +/* + * Receive COM unit + */ +void Testservice::receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received COM:" << comUnit; +} + +/* + * Receive altitude + */ +void Testservice::receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received altitude:" << altitude; +} + +/* + * Receive matrix + */ +void Testservice::receiveMatrix(const BlackMisc::Math::CMatrix3x3 &matrix) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received matrix:" << matrix; +} + +/* + * Receive a list + */ +void Testservice::receiveList(const QList &list) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received list:" << list; +} + +/* + * Receive a geo position + */ +void Testservice::receiveGeoPosition(const BlackMisc::Geo::CCoordinateGeodetic &geo) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received geo data:" << geo; +} + +/* + * Receive transponder + */ +void Testservice::receiveTransponder(const BlackMisc::Aviation::CTransponder &transponder) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received transponder:" << transponder; +} + +/* + * Receive track + */ +void Testservice::receiveTrack(const BlackMisc::Aviation::CTrack &track) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received track:" << track; +} + +/* + * Receive a length + */ +void Testservice::receiveLength(const BlackMisc::PhysicalQuantities::CLength &length) +{ + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received length:" << length; +} + +/* + * Receive lengths + */ +void Testservice::receiveLengths(const QVariantList &lengths) +{ + BlackMisc::PhysicalQuantities::CLength l; + foreach(QVariant lv, lengths) { + l = lv.value(); + qDebug() << "Pid:" << TestserviceTool::getPid() << "Received in list:" << l; + } +} + +} // namespace diff --git a/samples/blackmiscquantities_dbus/testservice.h b/samples/blackmiscquantities_dbus/testservice.h new file mode 100644 index 000000000..d9028b6a4 --- /dev/null +++ b/samples/blackmiscquantities_dbus/testservice.h @@ -0,0 +1,137 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISCKTEST_TESTSERVICEPQAV_H +#define BLACKMISCKTEST_TESTSERVICEPQAV_H + +// clash with struct interace in objbase.h used to happen +#pragma push_macro("interface") +#undef interface + +#define BLACKMISCKTEST_SERVICENAME "blackmisctest.testservice" +#define BLACKMISCKTEST_SERVICEPATH "/blackbus" + +#include +#include +#include +#include "blackmisc/blackmiscfreefunctions.h" +#include "testservicetool.h" + +namespace BlackMiscTest { + +/*! + * \brief Testservice for PQ DBus tests + */ +class Testservice : public QObject +{ + // http://techbase.kde.org/Development/Tutorials/D-Bus/CustomTypes#Write_a_class + // https://dev.vatsim-germany.org/projects/vatpilotclient/wiki/DBusExample + // http://qt-project.org/doc/qt-4.8/examples-dbus.html + // http://dbus.freedesktop.org/doc/dbus-tutorial.html#meta + + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKMISCKTEST_SERVICENAME) + + // For some reasons the interface name in the XML is not set correctly + // to the above name + + +signals: + /*! + * \brief Send string message + * \param message + */ + void sendStringMessage(const QString& message); + +public slots: + /*! + * \brief Receive string message + * \param message + */ + void receiveStringMessage(const QString &message); + + /*! + * \brief Receive a QVariant + * \param variant + */ + void receiveVariant(const QDBusVariant &variant); + + /*! + * \brief Receive speed + * \param speed + */ + void receiveSpeed(const BlackMisc::PhysicalQuantities::CSpeed &speed); + + /*! + * \brief Receive com unit + * \param comUnit + */ + void receiveComUnit(const BlackMisc::Aviation::CComSystem &comUnit); + + /*! + * \brief Receive altitude + * \param comUnit + */ + void receiveAltitude(const BlackMisc::Aviation::CAltitude &altitude); + + /*! + * \brief Receive matrix + * \param matrix + */ + void receiveMatrix(const BlackMisc::Math::CMatrix3x3 &matrix); + + /*! + * \brief Receive list + * \param list + */ + void receiveList(const QList &list); + + /*! + * \brief Receive a geo position + * \param geo + */ + void receiveGeoPosition(const BlackMisc::Geo::CCoordinateGeodetic &geo); + + /*! + * \brief Receive transponder + * \param transponder + */ + void receiveTransponder(const BlackMisc::Aviation::CTransponder &transponder); + + /*! + * \brief Receive track + * \param track + */ + void receiveTrack(const BlackMisc::Aviation::CTrack &track); + + /*! + * \brief Receive a length + * \param length + */ + void receiveLength(const BlackMisc::PhysicalQuantities::CLength &length); + + /*! + * \brief Receive lengths + * \param length + */ + void receiveLengths(const QVariantList &lengths); + +public: + static const QString ServiceName; + static const QString ServicePath; + + /*! + * \brief Constructor + * \param parent + */ + explicit Testservice(QObject *parent = 0); + +}; + +} // namespace + +#pragma pop_macro("interface") + +#endif // BLACKMISCKTEST_TESTSERVICEPQAV_H diff --git a/samples/blackmiscquantities_dbus/testservicetool.cpp b/samples/blackmiscquantities_dbus/testservicetool.cpp new file mode 100644 index 000000000..8c40db048 --- /dev/null +++ b/samples/blackmiscquantities_dbus/testservicetool.cpp @@ -0,0 +1,32 @@ +#include "testservicetool.h" + +namespace BlackMiscTest +{ + +/* + * Start a new process + */ +QProcess * TestserviceTool::startNewProcess(const QString &executable, QObject *parent = 0) +{ + QProcess *process = new QProcess(parent); + process->startDetached(executable); + return process; +} + +/* + * Sleep + */ +void TestserviceTool::sleep(qint32 ms) +{ + if (ms < 1) return; + +#ifdef Q_OS_WIN + Sleep(uint(ms)); +#else + struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; + nanosleep(&ts, NULL); +#endif + +} + +} // namespace diff --git a/samples/blackmiscquantities_dbus/testservicetool.h b/samples/blackmiscquantities_dbus/testservicetool.h new file mode 100644 index 000000000..5d5f2a2c4 --- /dev/null +++ b/samples/blackmiscquantities_dbus/testservicetool.h @@ -0,0 +1,55 @@ +#ifndef BLACKMISCTEST_TESTSERVICETOOL_H +#define BLACKMISCTEST_TESTSERVICETOOL_H + +#include +#include +#ifdef Q_OS_WIN +// for qdatetime, see here http://qt-project.org/forums/viewthread/22133 +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include // for Sleep +#endif + +namespace BlackMiscTest +{ + +/*! + * \brief Supporting functions for running the tests + */ +class TestserviceTool +{ +private: + /*! + * \brief Constructor + */ + TestserviceTool() {} + +public: + /*! + * \brief Get process id + * \return + */ + static qint64 getPid() { + return QCoreApplication::applicationPid(); + } + + /*! + * \brief Start a new process + * \param executable + * \param parent + * \return + */ + static QProcess *startNewProcess(const QString &executable, QObject *parent); + + /*! + * \brief Own sleep to avoid inlude of QTest + * \param ms + */ + static void sleep(qint32 ms); + +}; + +} // namespace + +#endif // BLACKMISCTEST_TESTSERVICETOOL_H diff --git a/samples/blackmiscvectorgeo/sample_vector_geo.pro b/samples/blackmiscvectorgeo/sample_vector_geo.pro index a44bebc4a..0dc821635 100644 --- a/samples/blackmiscvectorgeo/sample_vector_geo.pro +++ b/samples/blackmiscvectorgeo/sample_vector_geo.pro @@ -1,7 +1,7 @@ -QT += core +QT += core dbus TARGET = sample_vector_geo -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle TEMPLATE = app diff --git a/samples/blackmiscvectorgeo/samplesvectormatrix.cpp b/samples/blackmiscvectorgeo/samplesvectormatrix.cpp index c39d4507c..2423da9a0 100644 --- a/samples/blackmiscvectorgeo/samplesvectormatrix.cpp +++ b/samples/blackmiscvectorgeo/samplesvectormatrix.cpp @@ -10,13 +10,11 @@ int BlackMiscTest::CSamplesVectorMatrix::samples() CVector3D v1; CVector3D v2(1, 2, 3); qDebug() << v1 << "value:" << v2[2] << v2.length(); - v2 *= v2; // v2 * v2 - qDebug() << v2 << 2 * v1 << v1 *v1; + qDebug() << v2 << (2 * v1); CMatrix3x3 m; CMatrix3x3 mr = m; qDebug() << m << mr; - mr.setRandom(); bool im; CMatrix3x3 mi = mr.inverse(im); CMatrix3x3 mid = mr * mi; diff --git a/samples/com_client/client.cpp b/samples/com_client/client.cpp index 4fdb3e1aa..4f1eb8a1c 100644 --- a/samples/com_client/client.cpp +++ b/samples/com_client/client.cpp @@ -19,7 +19,7 @@ Client::~Client() { } -void Client::onError(QAbstractSocket::SocketError error, QString message) +void Client::onError(QAbstractSocket::SocketError /* error */, QString message) { bAppWarning << "Socket error!"; } diff --git a/samples/com_client/sample_com_client.pro b/samples/com_client/sample_com_client.pro index 61b68e378..ba2388745 100644 --- a/samples/com_client/sample_com_client.pro +++ b/samples/com_client/sample_com_client.pro @@ -3,7 +3,7 @@ QT -= gui TARGET = com_client -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle TEMPLATE = app diff --git a/samples/com_server/sample_com_server.pro b/samples/com_server/sample_com_server.pro index e6d61c03d..68c6521e8 100644 --- a/samples/com_server/sample_com_server.pro +++ b/samples/com_server/sample_com_server.pro @@ -4,7 +4,7 @@ QT -= gui TARGET = com_server TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src diff --git a/samples/config/sample_config.pro b/samples/config/sample_config.pro index 801d9f071..f6a151727 100644 --- a/samples/config/sample_config.pro +++ b/samples/config/sample_config.pro @@ -3,6 +3,7 @@ QT -= gui TARGET = sample_config TEMPLATE = app +CONFIG += c++11 DEPENDPATH += . ../../src INCLUDEPATH += . ../../src diff --git a/samples/interpolator/main.cpp b/samples/interpolator/main.cpp index a5baa7f1f..92c4b3bfa 100644 --- a/samples/interpolator/main.cpp +++ b/samples/interpolator/main.cpp @@ -46,9 +46,9 @@ int main(int argc, char *argv[]) CSpeed speed(20, CSpeedUnit::kts()); CCoordinateNed ned; - ned = interpolator.pushUpdate(vecGeo, speed, CHeading(80, false, CAngleUnit::deg()), zeroAngle, zeroAngle); + ned = interpolator.pushUpdate(vecGeo, speed, CHeading(80, CHeading::True, CAngleUnit::deg()), zeroAngle, zeroAngle); cout << "Interpolator NED 1: " << ned << endl; - ned = interpolator.pushUpdate(vecGeo2, speed, CHeading(250, false, CAngleUnit::deg()), zeroAngle, zeroAngle); + ned = interpolator.pushUpdate(vecGeo2, speed, CHeading(250, CHeading::True, CAngleUnit::deg()), zeroAngle, zeroAngle); cout << "Interpolator NED 2: " << ned << endl; double duration = timer.nsecsElapsed(); diff --git a/samples/interpolator/sample_interpolator.pro b/samples/interpolator/sample_interpolator.pro index aa2fea407..2f2cc4972 100644 --- a/samples/interpolator/sample_interpolator.pro +++ b/samples/interpolator/sample_interpolator.pro @@ -1,7 +1,7 @@ -QT += core +QT += core dbus TARGET = sample_interpolator -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle TEMPLATE = app diff --git a/samples/logging/sample_logging.pro b/samples/logging/sample_logging.pro index b262a6322..e5194585f 100644 --- a/samples/logging/sample_logging.pro +++ b/samples/logging/sample_logging.pro @@ -4,7 +4,7 @@ QT -= gui TARGET = sample_logging TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src diff --git a/samples/plugin/sample_plugin.pro b/samples/plugin/sample_plugin.pro index e0e3f7291..7aeb4abb3 100644 --- a/samples/plugin/sample_plugin.pro +++ b/samples/plugin/sample_plugin.pro @@ -3,7 +3,7 @@ QT -= gui TARGET = sample_plugin TEMPLATE = lib -CONFIG += plugin +CONFIG += plugin c++11 DEPENDPATH += . ../../src INCLUDEPATH += . ../../src diff --git a/samples/pluginmgr/sample_pluginmgr.pro b/samples/pluginmgr/sample_pluginmgr.pro index 11700db9a..c5758be6b 100644 --- a/samples/pluginmgr/sample_pluginmgr.pro +++ b/samples/pluginmgr/sample_pluginmgr.pro @@ -4,7 +4,7 @@ QT -= gui TARGET = sample_pluginmgr TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src diff --git a/src/blackbox/blackbox.pro b/src/blackbox/blackbox.pro index 79dad5973..d6b26bb9c 100644 --- a/src/blackbox/blackbox.pro +++ b/src/blackbox/blackbox.pro @@ -4,8 +4,9 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets INCLUDEPATH += . .. -TARGET = BlackBox +TARGET = blackbox TEMPLATE = app +CONFIG += c++11 SOURCES += *.cpp HEADERS += *.h diff --git a/src/blackbox/dialog_connect.cpp b/src/blackbox/dialog_connect.cpp index 956288dd4..802430a48 100644 --- a/src/blackbox/dialog_connect.cpp +++ b/src/blackbox/dialog_connect.cpp @@ -13,8 +13,10 @@ using namespace BlackMisc; CDialogConnect::CDialogConnect(QWidget *parent) : - QDialog(parent), m_hasComConnection(false), - ui(new Ui::CDialogConnect), comclient(IContext::getInstance()) + QDialog(parent), + ui(new Ui::CDialogConnect), + comclient(IContext::getInstance()), + m_hasComConnection(false) { ui->setupUi(this); diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index 98361abb9..bd22f107c 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -3,7 +3,7 @@ QT += network dbus TARGET = blackcore TEMPLATE = lib -CONFIG += staticlib +CONFIG += staticlib c++11 INCLUDEPATH += .. DEPENDPATH += . .. diff --git a/src/blackcore/fsd_client.cpp b/src/blackcore/fsd_client.cpp index 6a4e754c5..07796e03e 100644 --- a/src/blackcore/fsd_client.cpp +++ b/src/blackcore/fsd_client.cpp @@ -60,7 +60,7 @@ namespace FSD return m_tcp_socket->state() == QAbstractSocket::ConnectedState; } - QString CFSDClient::getErrorMessage(QAbstractSocket::SocketError error) + QString CFSDClient::getErrorMessage(QAbstractSocket::SocketError /* error */) { return QString("Unknown"); } diff --git a/src/blackcore/interpolator.cpp b/src/blackcore/interpolator.cpp index 6c12e9b79..4329d9c35 100644 --- a/src/blackcore/interpolator.cpp +++ b/src/blackcore/interpolator.cpp @@ -67,7 +67,7 @@ CCoordinateNed CInterpolator::pushUpdate(const CCoordinateGeodetic &pos, const C m_state_end->timestamp = m_time.elapsed(); m_state_end->position = CCoordinateTransformation::toEcef(pos); - m_state_end->orientation.heading = CHeading(normalizeRadians(heading), false); + m_state_end->orientation.heading = CHeading(normalizeRadians(heading), CHeading::True); m_state_end->orientation.pitch = normalizeRadians(pitch); m_state_end->orientation.bank = normalizeRadians(bank); m_state_end->groundspeed = groundSpeed; @@ -131,7 +131,7 @@ bool CInterpolator::stateNow(TPlaneState *state) // Plane Orientation double vEast = state->velNED.east(); double vNorth = state->velNED.north(); - state->orientation.heading = CHeading(atan2(vNorth, vEast), false, CAngleUnit::rad()); + state->orientation.heading = CHeading(atan2(vNorth, vEast), CHeading::True, CAngleUnit::rad()); return true; } diff --git a/src/blackcore/multiplayer.cpp b/src/blackcore/multiplayer.cpp index 79ab18a5c..017e59390 100644 --- a/src/blackcore/multiplayer.cpp +++ b/src/blackcore/multiplayer.cpp @@ -82,7 +82,7 @@ void CMultiPlayer::onPositionUpdate(const FSD::FSD_MSG_Plane_Position *plane_pos plane->addPosition(position, CSpeed(plane_position->Speed(), CSpeedUnit::kts()), - CHeading((qint32)pitchBankHeading.hdg, false, CAngleUnit::deg()), + CHeading((qint32)pitchBankHeading.hdg, CHeading::True, CAngleUnit::deg()), CAngle((qint32)pitchBankHeading.pitch, CAngleUnit::deg()), CAngle((qint32)pitchBankHeading.bank, CAngleUnit::deg())); @@ -93,9 +93,9 @@ void CMultiPlayer::addPlane(CPlane *plane) m_multiplayer_planes.insert(plane->callsign(), plane); } -void CMultiPlayer::removePlane(CPlane *plane) +void CMultiPlayer::removePlane(CPlane * /** plane **/) { - qint32 id; + qint32 id = 0; m_simulator->removePlane(id); } diff --git a/src/blackcore/multiplayer.h b/src/blackcore/multiplayer.h index 3aea55864..c61863383 100644 --- a/src/blackcore/multiplayer.h +++ b/src/blackcore/multiplayer.h @@ -81,7 +81,7 @@ namespace BlackCore { void addPlane(CPlane *plane); - void removePlane(CPlane *plane); + void removePlane(CPlane *); bool needsToRemoved(CPlane *plane); diff --git a/src/blackd/blackd.pro b/src/blackd/blackd.pro index 7ac44a843..6eaf7dc04 100644 --- a/src/blackd/blackd.pro +++ b/src/blackd/blackd.pro @@ -5,6 +5,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = blackd TEMPLATE = app +CONFIG += c++11 DEPENDPATH += . .. INCLUDEPATH += .. diff --git a/src/blackmisc/avallclasses.h b/src/blackmisc/avallclasses.h new file mode 100644 index 000000000..bc37c9a3f --- /dev/null +++ b/src/blackmisc/avallclasses.h @@ -0,0 +1,17 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_AVALLCLASSES_H +#define BLACKMISC_AVALLCLASSES_H + +#include "blackmisc/avaltitude.h" +#include "blackmisc/avheading.h" +#include "blackmisc/avioadfsystem.h" +#include "blackmisc/aviocomsystem.h" +#include "blackmisc/avionavsystem.h" +#include "blackmisc/aviotransponder.h" +#include "blackmisc/avtrack.h" + +#endif // guard diff --git a/src/blackmisc/avaltitude.cpp b/src/blackmisc/avaltitude.cpp index c2965d61f..d0b7becb8 100644 --- a/src/blackmisc/avaltitude.cpp +++ b/src/blackmisc/avaltitude.cpp @@ -16,38 +16,35 @@ namespace Aviation /* * Own implementation for streaming */ -QString CAltitude::stringForConverter() const +QString CAltitude::convertToQString(bool /* i18n */) const { - QString s = CLength::stringForConverter(); - return s.append(this->m_msl ? " MSL" : " AGL"); -} - -/* - * Assigment - */ -CAltitude &CAltitude::operator =(const CAltitude &otherAltitude) -{ - // Check for self-assignment! - if (this == &otherAltitude) return *this; - CLength::operator = (otherAltitude); - this->m_msl = otherAltitude.m_msl; - return (*this); + QString s = this->CLength::convertToQString(); + return s.append(this->isMeanSeaLevel() ? " MSL" : " AGL"); } /* * Equal? */ -bool CAltitude::operator ==(const CAltitude &otherAltitude) +bool CAltitude::operator ==(const CAltitude &other) { - return otherAltitude.m_msl == this->m_msl && CLength::operator ==(otherAltitude); + return other.m_datum == this->m_datum && this->CLength::operator ==(other); } /* * Unequal? */ -bool CAltitude::operator !=(const CAltitude &otherAltitude) +bool CAltitude::operator !=(const CAltitude &other) { - return !((*this) == otherAltitude); + return !((*this) == other); +} + +/* + * Register metadata + */ +void CAltitude::registerMetadata() +{ + qRegisterMetaType(typeid(CAltitude).name()); + qDBusRegisterMetaType(); } } // namespace diff --git a/src/blackmisc/avaltitude.h b/src/blackmisc/avaltitude.h index 7bc24ee39..cf74a0311 100644 --- a/src/blackmisc/avaltitude.h +++ b/src/blackmisc/avaltitude.h @@ -18,75 +18,83 @@ namespace Aviation */ class CAltitude : public BlackMisc::PhysicalQuantities::CLength { +public: + /*! + * Enum type to distinguish between MSL and AGL + */ + enum ReferenceDatum + { + MeanSeaLevel = 0, //!< MSL + AboveGround = 1, //!< AGL + }; + private: - bool m_msl; //!< MSL or AGL? + ReferenceDatum m_datum; //!< MSL or AGL? protected: /*! * \brief Specific stream operation for Altitude + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString convertToQString(bool i18n) const; + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CLength::marshallToDbus(argument); + argument << qint32(this->m_datum); + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CLength::unmarshallFromDbus(argument); + qint32 datum; + argument >> datum; + this->m_datum = static_cast(datum); + } public: - /*! * \brief Default constructor: 0 Altitude true */ - CAltitude() : BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_msl(true) {} + CAltitude() : BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_datum(MeanSeaLevel) {} /*! * \brief Constructor * \param value - * \param msl MSL or AGL? + * \param datum MSL or AGL? * \param unit */ - CAltitude(double value, bool msl, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : BlackMisc::PhysicalQuantities::CLength(value, unit), m_msl(msl) {} - - /*! - * \brief Constructor - * \param value - * \param msl MSL or AGL? - * \param unit - */ - CAltitude(int value, bool msl, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : CLength(value, unit), m_msl(msl) {} + CAltitude(double value, ReferenceDatum datum, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : BlackMisc::PhysicalQuantities::CLength(value, unit), m_datum(datum) {} /*! * \brief Constructor by CLength * \param altitude - * \param msl + * \param datum */ - CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, bool msl) : BlackMisc::PhysicalQuantities::CLength(), m_msl(msl) - { - BlackMisc::PhysicalQuantities::CLength::operator =(altitude); - } - - /*! - * \brief Copy constructor - * \param otherAltitude - */ - CAltitude(const CAltitude &otherAltitude) : BlackMisc::PhysicalQuantities::CLength(otherAltitude), m_msl(otherAltitude.m_msl) {} - - /*! - * \brief Assignment operator = - * \param otherAltitude - * @return - */ - CAltitude &operator =(const CAltitude &otherAltitude); + CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, ReferenceDatum datum) : BlackMisc::PhysicalQuantities::CLength(altitude), m_datum(datum) {} /*! * \brief Equal operator == - * \param otherAltitude + * \param other * @return */ - bool operator ==(const CAltitude &otherAltitude); + bool operator ==(const CAltitude &other); /*! * \brief Unequal operator == - * \param otherAltitude + * \param other * @return */ - bool operator !=(const CAltitude &otherAltitude); + bool operator !=(const CAltitude &other); /*! * \brief AGL Above ground level? @@ -94,7 +102,7 @@ public: */ bool isAboveGroundLevel() const { - return !this->m_msl; + return AboveGround == this->m_datum; } /*! @@ -103,11 +111,24 @@ public: */ bool isMeanSeaLevel() const { - return this->m_msl; + return MeanSeaLevel == this->m_datum; } + + /*! + * \brief Get reference datum (MSL or AGL) + * \return + */ + ReferenceDatum getReferenceDatum() const { return m_datum; } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); }; } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CAltitude) + #endif // guard diff --git a/src/blackmisc/avheading.cpp b/src/blackmisc/avheading.cpp index b66f56eeb..ffaddbbd9 100644 --- a/src/blackmisc/avheading.cpp +++ b/src/blackmisc/avheading.cpp @@ -16,38 +16,35 @@ namespace Aviation /* * Own implementation for streaming */ -QString CHeading::stringForConverter() const +QString CHeading::convertToQString(bool i18n) const { - QString s = CAngle::stringForConverter(); - return s.append(this->m_magnetic ? " magnetic" : " true"); -} - -/* - * Assigment - */ -CHeading& CHeading::operator =(const CHeading &otherHeading) -{ - // Check for self-assignment! - if (this == &otherHeading) return *this; - CAngle::operator = (otherHeading); - this->m_magnetic = otherHeading.m_magnetic; - return (*this); + QString s = CAngle::convertToQString(i18n); + return s.append(this->isMagneticHeading() ? " magnetic" : " true"); } /* * Equal? */ -bool CHeading::operator ==(const CHeading &otherHeading) +bool CHeading::operator ==(const CHeading &other) { - return otherHeading.m_magnetic == this->m_magnetic && CAngle::operator ==(otherHeading); + return other.m_north == this->m_north && this->CAngle::operator ==(other); } /* * Unequal? */ -bool CHeading::operator !=(const CHeading &otherHeading) +bool CHeading::operator !=(const CHeading &other) { - return !((*this) == otherHeading); + return !((*this) == other); +} + +/*! + * \brief Register metadata of unit and quantity + */ +void CHeading::registerMetadata() +{ + qRegisterMetaType(typeid(CHeading).name()); + qDBusRegisterMetaType(); } } // namespace diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index 778c44794..e187143ff 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -11,105 +11,118 @@ namespace BlackMisc { namespace Aviation { + /*! * \brief Heading as used in aviation, can be true or magnetic heading * \remarks Intentionally allowing +/- CAngle , and >= / <= CAngle. */ class CHeading : public BlackMisc::PhysicalQuantities::CAngle { +public: + /*! + * Enum type to distinguish between true north and magnetic north + */ + enum ReferenceNorth + { + Magnetic = 0, //!< magnetic north + True = 1, //!< true north + }; + private: - bool m_magnetic; //!< magnetic or true heading? + ReferenceNorth m_north; //!< magnetic or true? protected: /*! * \brief Specific stream operation for heading + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString convertToQString(bool i18n = false) const; + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CAngle::marshallToDbus(argument); + argument << qint32(this->m_north); + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CAngle::unmarshallFromDbus(argument); + qint32 north; + argument >> north; + this->m_north = static_cast(north); + } public: /*! * \brief Default constructor: 0 heading true */ - CHeading() : CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_magnetic(true) {} + CHeading() : CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_north(Magnetic) {} /*! * \brief Constructor * \param value - * \param magnetic + * \param north * \param unit */ - - CHeading(double value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_magnetic(magnetic) {} - /*! - * \brief Constructor - * \param value - * \param magnetic - * \param unit - */ - CHeading(int value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_magnetic(magnetic) {} + CHeading(double value, ReferenceNorth north, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_north(north) {} /*! * \brief Constructor by CAngle - * \param heading + * \param north * \param magnetic */ - CHeading(CAngle heading, bool magnetic) : CAngle(), m_magnetic(magnetic) - { - CAngle::operator =(heading); - } - - /*! - * \brief Copy constructor - * \param otherHeading - */ - CHeading(const CHeading &otherHeading) : CAngle(otherHeading), m_magnetic(otherHeading.m_magnetic) {} - - /*! - * \brief Assignment operator = - * \param otherHeading - * @return - */ - CHeading &operator =(const CHeading &otherHeading); + CHeading(CAngle heading, ReferenceNorth north) : CAngle(heading), m_north(north) {} /*! * \brief Equal operator == - * \param otherHeading + * \param other * @return */ - bool operator ==(const CHeading &otherHeading); + bool operator ==(const CHeading &other); /*! * \brief Unequal operator == - * \param otherHeading + * \param other * @return */ - bool operator !=(const CHeading &otherHeading); + bool operator !=(const CHeading &other); /*! * \brief Magnetic heading? * \return */ - bool isMagneticHeading() const { return this->m_magnetic; } + bool isMagneticHeading() const { return Magnetic == this->m_north; } /*! * \brief True heading? * \return */ - bool isTrueHeading() const { return !this->m_magnetic; } + bool isTrueHeading() const { return True == this->m_north; } /*! - * \brief Switch heading unit - * \param newUnit + * \brief Get reference north (magnetic or true) * \return */ - CHeading &switchUnit(const BlackMisc::PhysicalQuantities::CAngleUnit &newUnit) - { - CAngle::switchUnit(newUnit); - return (*this); - } + ReferenceNorth getReferenceNorth() const { return m_north; } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); }; } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::Aviation::CHeading) + #endif // guard diff --git a/src/blackmisc/avioadfsystem.h b/src/blackmisc/avioadfsystem.h index f940aad55..6dc056e82 100644 --- a/src/blackmisc/avioadfsystem.h +++ b/src/blackmisc/avioadfsystem.h @@ -7,6 +7,7 @@ #define BLACKMISC_AVIOADFSYSTEM_H #include "blackmisc/aviomodulator.h" +#include namespace BlackMisc { @@ -24,11 +25,12 @@ private: * \param f * \return */ - bool isValidFrequency(CFrequency f) const + bool isValidFrequency(PhysicalQuantities::CFrequency f) const { - double fr = f.valueRounded(CFrequencyUnit::kHz(), this->m_digits); + double fr = f.valueRounded(PhysicalQuantities::CFrequencyUnit::kHz(), this->m_digits); return fr >= 190.0 && fr <= 1750.0; } + /*! * \brief Constructor * \param validate @@ -38,7 +40,7 @@ private: * \param digits * */ - CAdfSystem(bool validate, const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency, int digits = 3): + CAdfSystem(bool validate, const QString &name, const PhysicalQuantities::CFrequency &activeFrequency, const PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3): CModulator(name, activeFrequency, standbyFrequency, digits) { this->validate(validate); @@ -53,8 +55,8 @@ protected: { if (this->isDefaultValue()) return true; // special case return - (this->isValidFrequency(this->getFrequencyActive()) && - (this->isValidFrequency(this->getFrequencyStandby()))); + this->isValidFrequency(this->getFrequencyActive()) && + this->isValidFrequency(this->getFrequencyStandby()); } /*! @@ -73,16 +75,19 @@ protected: if (!valid) throw std::range_error("Illegal values in CAdfSystem::validate"); return true; } + public: /*! * Default constructor */ CAdfSystem() : CModulator() {} + /*! * \brief Copy constructor - * \param otherSystem + * \param other */ - CAdfSystem(const CAdfSystem &otherSystem) : CModulator(otherSystem) {} + CAdfSystem(const CAdfSystem &other) : CModulator(other) {} + /*! * \brief Constructor * \param name @@ -90,39 +95,32 @@ public: * \param standbyFrequency * \param digits */ - CAdfSystem(const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3): + CAdfSystem(const QString &name, const PhysicalQuantities::CFrequency &activeFrequency, const PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3): CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits) { this->validate(true); } + /*! * \brief Set active frequency * \param frequencyKHz */ void setFrequencyActiveKHz(double frequencyKHz) { - CModulator::setFrequencyActiveKHz(frequencyKHz); + this->CModulator::setFrequencyActiveKHz(frequencyKHz); this->validate(true); } + /*! * \brief Set standby frequency * \param frequencyKHz */ - void setFrequencyActiveKHz(double frequencyKHz) + void setFrequencyStandbyKHz(double frequencyKHz) { - CModulator::setFrequencyStandbyKHz(frequencyKHz); + this->CModulator::setFrequencyStandbyKHz(frequencyKHz); this->validate(true); } - /*! - * \brief Assigment operator = - * \param otherSystem - * \return - */ - CAdfSystem &operator =(const CAdfSystem &otherSystem) - { - CModulator::operator =(otherSystem); - return (*this); - } + /*! * \brief operator == * \param otherSystem @@ -130,8 +128,9 @@ public: */ bool operator ==(const CAdfSystem &otherSystem) const { - return CModulator::operator ==(otherSystem); + return this->CModulator::operator ==(otherSystem); } + /*! * \brief operator == * \param otherSystem @@ -139,42 +138,43 @@ public: */ bool operator !=(const CAdfSystem &otherSystem) const { - return CModulator::operator !=(otherSystem); + return this->CModulator::operator !=(otherSystem); } /*! * Try to get a ADF unit with given name and frequency. Returns true in case an object - * has been sucessfully created, otherwise returns a default object. - * \param adfSystem + * has been sucessfully created, otherwise returns a default object and false. + * \param[out] o_adfSystem * \param name * \param activeFrequencyKHz * \param standbyFrequencyKHz * \return */ - static bool tryGetAdfSystem(CAdfSystem &adfSystem, const QString &name, double activeFrequencyKHz, double standbyFrequencyKHz = -1) + static bool tryGetAdfSystem(CAdfSystem &o_adfSystem, const QString &name, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - adfSystem = CAdfSystem(false, name, CFrequency(activeFrequencyKHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, CFrequencyUnit::MHz())); + o_adfSystem = CAdfSystem(false, name, PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); bool s; - if (!(s = adfSystem.validate(false))) adfSystem = CAdfSystem(); // reset to default + if (!(s = o_adfSystem.validate(false))) o_adfSystem = CAdfSystem(); // reset to default return s; } /*! * Try to get a ADF unit with given name and frequency. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param adfSystem + * \param[out] o_adfSystem * \param name * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetAdfSystem(CAdfSystem &adfSystem, const QString &name, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetAdfSystem(CAdfSystem &o_adfSystem, const QString &name, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - adfSystem = CAdfSystem(false, name, activeFrequency, standbyFrequency); + o_adfSystem = CAdfSystem(false, name, activeFrequency, standbyFrequency); bool s; - if (!(s = adfSystem.validate(false))) adfSystem = CAdfSystem(); // reset to default + if (!(s = o_adfSystem.validate(false))) o_adfSystem = CAdfSystem(); // reset to default return s; } + /*! * \brief ADF1 unit * \param activeFrequencyKHz @@ -183,40 +183,44 @@ public: */ static CAdfSystem GetAdf1System(double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - return CAdfSystem(CModulator::NameCom1(), CFrequency(activeFrequencyKHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, CFrequencyUnit::MHz())); + return CAdfSystem(CModulator::NameCom1(), PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief ADF1 unit * \param activeFrequency * \param standbyFrequency * \return */ - static CAdfSystem GetAdf1System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static CAdfSystem GetAdf1System(PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CAdfSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get ADF unit - * \param adfSystem + * \param[out] o_adfSystem * \param activeFrequencyKHz * \param standbyFrequencyKHz * \return */ - static bool tryGetAdf1Unit(CAdfSystem &adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) + static bool tryGetAdf1Unit(CAdfSystem &o_adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom1(), activeFrequencyKHz, standbyFrequencyKHz); + return CAdfSystem::tryGetAdfSystem(o_adfSystem, CModulator::NameCom1(), activeFrequencyKHz, standbyFrequencyKHz); } + /*! * \brief Try to get ADF unit - * \param adfSystem + * \param[out] o_adfSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetAdf1Unit(CAdfSystem &adfSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetAdf1Unit(CAdfSystem &o_adfSystem, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); + return CAdfSystem::tryGetAdfSystem(o_adfSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); } + /*! * \brief ADF2 unit * \param activeFrequencyKHz @@ -225,44 +229,48 @@ public: */ static CAdfSystem GetAdf2System(double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - return CAdfSystem(CModulator::NameCom2(), CFrequency(activeFrequencyKHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, CFrequencyUnit::MHz())); + return CAdfSystem(CModulator::NameCom2(), PhysicalQuantities::CFrequency(activeFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz()), PhysicalQuantities::CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief ADF2 unit * \param activeFrequency * \param standbyFrequency * \return */ - static CAdfSystem GetAdf2System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static CAdfSystem GetAdf2System(PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CAdfSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get ADF unit - * \param adfSystem + * \param[out] o_adfSystem * \param activeFrequencyKHz * \param standbyFrequencyKHz * \return */ - static bool tryGetAdf2System(CAdfSystem &adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) + static bool tryGetAdf2System(CAdfSystem &o_adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { - return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom2(), activeFrequencyKHz, standbyFrequencyKHz); + return CAdfSystem::tryGetAdfSystem(o_adfSystem, CModulator::NameCom2(), activeFrequencyKHz, standbyFrequencyKHz); } + /*! * \brief Try to get ADF unit - * \param adfSystem + * \param[out] o_adfSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetAdf2System(CAdfSystem &adfSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetAdf2System(CAdfSystem &o_adfSystem, PhysicalQuantities::CFrequency activeFrequency, PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); + return CAdfSystem::tryGetAdfSystem(o_adfSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); } }; } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CAdfSystem) #endif // BLACKMISC_AVIOADFSYSTEM_H diff --git a/src/blackmisc/aviobase.h b/src/blackmisc/aviobase.h index 1973f1ee7..fa77b57d3 100644 --- a/src/blackmisc/aviobase.h +++ b/src/blackmisc/aviobase.h @@ -7,7 +7,7 @@ #define BLACKMISC_AVIOBASE_H // QtGlobal is required for asserts -#include "blackmisc/basestreamstringifier.h" +#include "blackmisc/streamable.h" #include "blackmisc/pqconstants.h" #include @@ -19,16 +19,13 @@ namespace Aviation /*! * \brief Base class for avionics */ -class CAvionicsBase : public CBaseStreamStringifier +class CAvionicsBase : public BlackMisc::CStreamable { - -private: +protected: QString m_name; //!< name of the unit -protected: - /*! - * \brief Default constructor + * \brief Constructor */ CAvionicsBase(const QString &name) : m_name(name) {} @@ -52,13 +49,31 @@ protected: /*! * \brief operator == - * \param otherSystem + * \param other * \return */ - bool operator ==(const CAvionicsBase &otherSystem) const + bool operator ==(const CAvionicsBase &other) const { - if (this == &otherSystem) return true; - return this->m_name == otherSystem.m_name; + if (this == &other) return true; + return this->m_name == other.m_name; + } + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const + { + argument << this->m_name; + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> this->m_name; } public: @@ -76,6 +91,7 @@ public: return this->m_name; } }; + } // namespace } // namespace diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index ba558c73c..ab10eab81 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BLACKMISC_AVIOCOMUNIT_H -#define BLACKMISC_AVIOCOMUNIT_H +#ifndef BLACKMISC_AVIOCOMSYSTEM_H +#define BLACKMISC_AVIOCOMSYSTEM_H #include "blackmisc/aviomodulator.h" #include @@ -24,7 +24,8 @@ private: * \param f * \return */ - bool isValidCivilAviationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const { + bool isValidCivilAviationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const + { double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits); return fr >= 118.0 && fr <= 136.975; } @@ -34,7 +35,8 @@ private: * \param f * \return */ - bool isValidMilitaryFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const { + bool isValidMilitaryFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const + { double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits); return fr >= 220.0 && fr <= 399.95; } @@ -49,7 +51,8 @@ private: * */ CComSystem(bool validate, const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3): - CModulator(name, activeFrequency, standbyFrequency, digits) { + CModulator(name, activeFrequency, standbyFrequency, digits) + { this->validate(validate); } @@ -58,7 +61,8 @@ protected: * \brief Are the set values valid / in range? * \return */ - bool validValues() const { + bool validValues() const + { if (this->isDefaultValue()) return true; // special case return (this->isValidCivilAviationFrequency(this->getFrequencyActive()) || @@ -71,10 +75,11 @@ protected: * \brief Validate values by assert and exception * \param strict * \throws std::range_error - * \remarks Cannot be virtualsince already used in constructor + * \remarks Cannot be virtual because used in constructor * \return */ - bool validate(bool strict = true) const { + bool validate(bool strict = true) const + { if (this->isDefaultValue()) return true; bool valid = this->validValues(); if (!strict) return valid; @@ -91,9 +96,9 @@ public: /*! * \brief Copy constructor - * \param otherSystem + * \param other */ - CComSystem(const CComSystem &otherSystem) : CModulator(otherSystem) {} + CComSystem(const CComSystem &other) : CModulator(other) {} /*! * \brief Constructor @@ -103,7 +108,8 @@ public: * \param digits */ CComSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3): - CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits) { + CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits) + { this->validate(true); } @@ -111,8 +117,9 @@ public: * \brief Set active frequency * \param frequencyMHz */ - void setFrequencyActiveMHz(double frequencyMHz) { - CModulator::setFrequencyActiveMHz(frequencyMHz); + void setFrequencyActiveMHz(double frequencyMHz) + { + this->CModulator::setFrequencyActiveMHz(frequencyMHz); this->validate(true); } @@ -120,15 +127,17 @@ public: * \brief Set standby frequency * \param frequencyMHz */ - void setFrequencyStandbyMHz(double frequencyMHz) { - CModulator::setFrequencyStandbyMHz(frequencyMHz); + void setFrequencyStandbyMHz(double frequencyMHz) + { + this->CModulator::setFrequencyStandbyMHz(frequencyMHz); this->validate(true); } /*! * \brief Set UNICOM frequency as active */ - void setActiveUnicom() { + void setActiveUnicom() + { this->toggleActiveStandby(); this->setFrequencyActive(BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants::FrequencyUnicom()); } @@ -136,144 +145,156 @@ public: /*! * \brief Set International Air Distress 121.5MHz */ - void setActiveInternationalAirDistress() { + void setActiveInternationalAirDistress() + { this->toggleActiveStandby(); this->setFrequencyActive(BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress()); } /*! - * \brief Assigment operator = - * \param otherSystem + * \brief operator == + * \param other * \return */ - CComSystem& operator =(const CComSystem &otherSystem) { - CModulator::operator =(otherSystem); - return (*this); + bool operator ==(const CComSystem &other) const + { + return this->CModulator::operator ==(other); } /*! - * \brief operator == - * \param otherSystem + * \brief operator != + * \param other * \return */ - bool operator ==(const CComSystem &otherSystem) const { - return CModulator::operator ==(otherSystem); - } - /*! - * \brief operator == - * \param otherSystem - * \return - */ - bool operator !=(const CComSystem &otherSystem) const { - return CModulator::operator !=(otherSystem); + bool operator !=(const CComSystem &other) const + { + return this->CModulator::operator !=(other); } /*! * Try to get a COM unit with given name and frequency. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param comSystem + * \param[out] o_comSystem * \param name * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetComSystem(CComSystem &comSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - comSystem = CComSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); + static bool tryGetComSystem(CComSystem &o_comSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { + o_comSystem = CComSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); bool s; - if (!(s = comSystem.validate(false))) comSystem = CComSystem(); // reset to default + if (!(s = o_comSystem.validate(false))) o_comSystem = CComSystem(); // reset to default return s; } /*! * Try to get a COM unit with given name and frequency. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param comSystem + * \param[out] o_comSystem * \param name * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetComSystem(CComSystem &comSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - comSystem = CComSystem(false, name, activeFrequency, standbyFrequency); + static bool tryGetComSystem(CComSystem &o_comSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + o_comSystem = CComSystem(false, name, activeFrequency, standbyFrequency); bool s; - if (!(s = comSystem.validate(false))) comSystem = CComSystem(); // reset to default + if (!(s = o_comSystem.validate(false))) o_comSystem = CComSystem(); // reset to default return s; } + /*! * \brief COM1 unit * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { return CComSystem(CModulator::NameCom1(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief COM1 unit * \param activeFrequency * \param standbyFrequency * \return */ - static CComSystem getCom1System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); + static CComSystem getCom1System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + return CComSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetCom1Unit(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom1(), activeFrequencyMHz, standbyFrequencyMHz); + static bool tryGetCom1Unit(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom1(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetCom1Unit(CComSystem &comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); + static bool tryGetCom1Unit(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); } + /*! * \brief COM2 unit * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static CComSystem getCom2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + static CComSystem getCom2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { return CComSystem(CModulator::NameCom2(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief COM2 unit * \param activeFrequency * \param standbyFrequency * \return */ - static CComSystem getCom2System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + static CComSystem getCom2System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { return CComSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetCom2System(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom2(), activeFrequencyMHz, standbyFrequencyMHz); + static bool tryGetCom2System(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom2(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetCom2System(CComSystem &comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); + static bool tryGetCom2System(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); } /*! @@ -282,43 +303,50 @@ public: * \param standbyFrequencyMHz * \return */ - static CComSystem getCom3System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + static CComSystem getCom3System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { return CComSystem(CModulator::NameCom3(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief COM3 unit * \param activeFrequency * \param standbyFrequency * \return */ - static CComSystem getCom3System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + static CComSystem getCom3System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { return CComSystem(CModulator::NameCom3(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetCom3System(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom3(), activeFrequencyMHz, standbyFrequencyMHz); + static bool tryGetCom3System(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom3(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get COM unit - * \param comSystem + * \param[out] o_comSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetCom3System(CComSystem &comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom3(), activeFrequency, standbyFrequency); + static bool tryGetCom3System(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + { + return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom3(), activeFrequency, standbyFrequency); } }; } // namespace - } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem) + #endif // include guard diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index 6bf3bd4b8..c7de9a2df 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -6,6 +6,7 @@ #include "blackmisc/aviomodulator.h" #include "blackmisc/aviocomsystem.h" #include "blackmisc/avionavsystem.h" +#include "blackmisc/avioadfsystem.h" using BlackMisc::PhysicalQuantities::CFrequency; using BlackMisc::PhysicalQuantities::CFrequencyUnit; @@ -26,54 +27,38 @@ template void CModulator::toggleActiveStandby() } /* - * String representation + * Register metadata */ -template QString CModulator::stringForConverter() const +template void CModulator::registerMetadata() { - QString s(this->getName()); - s.append(" Active: ").append(this->m_frequencyActive.unitValueRoundedWithUnit(3)); - s.append(" Standby: ").append(this->m_frequencyStandby.unitValueRoundedWithUnit(3)); - return s; -} - -/* - * Assigment operator = - */ -template CModulator& CModulator::operator=(const CModulator &otherModulator) -{ - - if (this == &otherModulator) return *this; // Same object? - this->m_frequencyActive = otherModulator.m_frequencyActive; - this->m_frequencyStandby = otherModulator.m_frequencyStandby; - this->m_digits = otherModulator.m_digits; - this->setName(otherModulator.getName()); - return *this; + qRegisterMetaType(typeid(AVIO).name()); + qDBusRegisterMetaType(); } /* * Equal operator == */ -template bool CModulator::operator ==(const CModulator &otherModulator) const +template bool CModulator::operator ==(const CModulator &other) const { - if (this == &otherModulator) return true; - return (this->getName() == otherModulator.getName() && - this->m_frequencyActive == otherModulator.m_frequencyActive && - this->m_frequencyStandby == otherModulator.m_frequencyStandby); + if (this == &other) return true; + return (this->getName() == other.getName() && + this->m_frequencyActive == other.m_frequencyActive && + this->m_frequencyStandby == other.m_frequencyStandby); } /* * Equal operator != */ -template bool CModulator::operator !=(const CModulator &otherModulator) const +template bool CModulator::operator !=(const CModulator &other) const { - return !(otherModulator == (*this)); + return !(other == (*this)); } - // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CModulator; template class CModulator; +template class CModulator; } // namespace } // namespace diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 6a1bd90cd..3a39ee661 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -5,6 +5,8 @@ #ifndef BLACKMISC_AVIOMODULATORUNIT_H #define BLACKMISC_AVIOMODULATORUNIT_H + +#include #include "blackmisc/aviobase.h" namespace BlackMisc @@ -25,7 +27,6 @@ protected: int m_digits; //!< digits used protected: - /*! * \brief Default constructor */ @@ -33,10 +34,10 @@ protected: /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CModulator(const CModulator &otherUnit) : CAvionicsBase(otherUnit.getName()), - m_frequencyActive(otherUnit.m_frequencyActive), m_frequencyStandby(otherUnit.m_frequencyStandby), m_digits(otherUnit.m_digits) {} + CModulator(const CModulator &other) : CAvionicsBase(other.getName()), + m_frequencyActive(other.m_frequencyActive), m_frequencyStandby(other.m_frequencyStandby), m_digits(other.m_digits) {} /*! * \brief Constructor @@ -46,13 +47,20 @@ protected: * \param digits */ CModulator(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits) : - CAvionicsBase(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency), m_digits(digits) { } + CAvionicsBase(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency), m_digits(digits) {} /*! * \brief String for converter + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString convertToQString(bool i18n = false) const + { + QString s(this->getName()); + s.append(" Active: ").append(this->m_frequencyActive.valueRoundedWithUnit(3, i18n)); + s.append(" Standby: ").append(this->m_frequencyStandby.valueRoundedWithUnit(3, i18n)); + return s; + } /*! * \brief Set active frequency @@ -90,26 +98,20 @@ protected: this->m_frequencyStandby = BlackMisc::PhysicalQuantities::CFrequency(frequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()); } - /*! - * \brief Assigment operator = - * \param otherModulator - * \return - */ - CModulator &operator =(const CModulator &otherModulator); - /*! * \brief operator == - * \param otherModulator + * \param other * \return */ - bool operator ==(const CModulator &otherModulator) const; + bool operator ==(const CModulator &other) const; /*! * \brief operator != - * \param otherModulator + * \param other * \return */ - bool operator !=(const CModulator &otherModulator) const; + bool operator !=(const CModulator &other) const; + /*! * \brief COM1 * \return @@ -166,7 +168,7 @@ protected: */ static const QString &NameNav3() { - static QString n("NAV2"); + static QString n("NAV3"); return n; } @@ -200,6 +202,30 @@ protected: return f; } + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CAvionicsBase::marshallToDbus(argument); + argument << this->m_frequencyActive; + argument << this->m_frequencyStandby; + argument << this->m_digits; + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CAvionicsBase::unmarshallFromDbus(argument); + argument >> this->m_frequencyActive; + argument >> this->m_frequencyStandby; + argument >> this->m_digits; + } + public: /*! * \brief Virtual destructor @@ -214,6 +240,7 @@ public: { return this->m_frequencyActive == CModulator::FrequencyNotSet(); } + /*! * \brief Toggle active and standby frequencies */ @@ -254,6 +281,11 @@ public: { this->m_frequencyStandby = frequency; } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); }; } // namespace diff --git a/src/blackmisc/avionavsystem.h b/src/blackmisc/avionavsystem.h index 8beef0be8..188a42502 100644 --- a/src/blackmisc/avionavsystem.h +++ b/src/blackmisc/avionavsystem.h @@ -28,6 +28,7 @@ private: double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits); return fr >= 108.0 && fr <= 117.95; } + /*! * \brief Valid military aviation frequency? * \param f @@ -38,6 +39,7 @@ private: double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits); return fr >= 960.0 && fr <= 1215.0; // valid TACAN frequency } + /*! * \brief Constructor * \param validate @@ -45,7 +47,6 @@ private: * \param activeFrequency * \param standbyFrequency * \param digits - * */ CNavSystem(bool validate, const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3): CModulator(name, activeFrequency, standbyFrequency, digits) @@ -68,11 +69,12 @@ protected: this->isValidMilitaryNavigationFrequency(this->getFrequencyStandby())); return v; } + /*! * \brief Validate values by assert and exception * \param strict * \throws std::range_error - * \remarks Cannot be virtualsince already used in constructor + * \remarks Cannot be virtual because used in constructor * \return */ bool validate(bool strict = true) const @@ -84,16 +86,19 @@ protected: if (!valid) throw std::range_error("Illegal values in CModulator::validate"); return true; } + public: /*! * Default constructor */ CNavSystem() : CModulator() {} + /*! * \brief Copy constructor - * \param otherSystem + * \param other */ - CNavSystem(const CNavSystem &otherSystem) : CModulator(otherSystem) {} + CNavSystem(const CNavSystem &other) : CModulator(other) {} + /*! * \brief Constructor * \param name @@ -106,85 +111,81 @@ public: { this->validate(true); } + /*! * \brief Set active frequency * \param frequencyMHz */ void setFrequencyActiveMHz(double frequencyMHz) { - CModulator::setFrequencyActiveMHz(frequencyMHz); + this->CModulator::setFrequencyActiveMHz(frequencyMHz); this->validate(true); } + /*! * \brief Set standby frequency * \param frequencyMHz */ void setFrequencyStandbyMHz(double frequencyMHz) { - CModulator::setFrequencyStandbyMHz(frequencyMHz); + this->CModulator::setFrequencyStandbyMHz(frequencyMHz); this->validate(true); } - /*! - * \brief Assigment operator = - * \param otherSystem - * \return - */ - CNavSystem &operator =(const CNavSystem &otherSystem) - { - CModulator::operator =(otherSystem); - return (*this); - } + /*! * \brief operator == - * \param otherSystem + * \param other * \return */ - bool operator ==(const CNavSystem &otherSystem) const + bool operator ==(const CNavSystem &other) const { - return CModulator::operator ==(otherSystem); + return this->CModulator::operator ==(other); } + /*! * \brief operator == - * \param otherSystem + * \param other * \return */ - bool operator !=(const CNavSystem &otherSystem) const + bool operator !=(const CNavSystem &other) const { - return CModulator::operator !=(otherSystem); + return this->CModulator::operator !=(other); } /*! * Try to get a NAV unit with given name and frequency. Returns true in case an object * has been sucessfully created,otherwise returns a default object. - * \param navSystem + * \param[out] o_navSystem * \param name * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + static bool tryGetNavSystem(CNavSystem &o_navSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - navSystem = CNavSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); + o_navSystem = CNavSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); bool s; - if (!(s = navSystem.validate(false))) navSystem = CNavSystem(); // reset to default + if (!(s = o_navSystem.validate(false))) o_navSystem = CNavSystem(); // reset to default return s; } + /*! * Try to get a NAV unit with given name and frequency. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param navSystem + * \param[out] o_navSystem * \param name * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetNavSystem(CNavSystem &o_navSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - navSystem = CNavSystem(false, name, activeFrequency, standbyFrequency); + o_navSystem = CNavSystem(false, name, activeFrequency, standbyFrequency); bool s; - if (!(s = navSystem.validate(false))) navSystem = CNavSystem(); // reset to default + if (!(s = o_navSystem.validate(false))) o_navSystem = CNavSystem(); // reset to default return s; } + /*! * \brief NAV1 unit * \param activeFrequencyMHz @@ -195,6 +196,7 @@ public: { return CNavSystem(CModulator::NameNav1(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief NAV1 unit * \param activeFrequency @@ -205,28 +207,31 @@ public: { return CNavSystem(CModulator::NameNav1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get NAV unit - * \param navSystem + * \param[out] o_navSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetNav1System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + static bool tryGetNav1System(CNavSystem &o_navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav1(), activeFrequencyMHz, standbyFrequencyMHz); + return CNavSystem::tryGetNavSystem(o_navSystem, CModulator::NameNav1(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get NAV unit - * \param navSystem + * \param[out] o_navSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetNav1System(CNavSystem &navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetNav1System(CNavSystem &o_navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav1(), activeFrequency, standbyFrequency); + return CNavSystem::tryGetNavSystem(o_navSystem, CModulator::NameNav1(), activeFrequency, standbyFrequency); } + /*! * \brief NAV2 unit * \param activeFrequencyMHz @@ -237,6 +242,7 @@ public: { return CNavSystem(CModulator::NameNav2(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } + /*! * \brief NAV2 unit * \param activeFrequency @@ -247,31 +253,35 @@ public: { return CNavSystem(CModulator::NameNav2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } + /*! * \brief Try to get NAV unit - * \param navSystem + * \param[out] o_navSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static bool tryGetNav2System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) + static bool tryGetNav2System(CNavSystem &o_navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav2(), activeFrequencyMHz, standbyFrequencyMHz); + return CNavSystem::tryGetNavSystem(o_navSystem, CModulator::NameNav2(), activeFrequencyMHz, standbyFrequencyMHz); } + /*! * \brief Try to get NAV unit - * \param navSystem + * \param[out] o_navSystem * \param activeFrequency * \param standbyFrequency * \return */ - static bool tryGetNav2System(CNavSystem &navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) + static bool tryGetNav2System(CNavSystem &o_navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav2(), activeFrequency, standbyFrequency); + return CNavSystem::tryGetNavSystem(o_navSystem, CModulator::NameNav2(), activeFrequency, standbyFrequency); } }; } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CNavSystem) + #endif // BLACKMISC_AVIONAVSYSTEM_H diff --git a/src/blackmisc/aviotransponder.cpp b/src/blackmisc/aviotransponder.cpp index d5ffbab9b..676508e4a 100644 --- a/src/blackmisc/aviotransponder.cpp +++ b/src/blackmisc/aviotransponder.cpp @@ -45,7 +45,7 @@ bool CTransponder::validate(bool strict) const /** * String representation */ -QString CTransponder::stringForConverter() const +QString CTransponder::convertToQString(bool /* i18n */) const { QString s = this->getName(); s = s.append(" ").append(this->getTransponderCodeFormatted()).append(" ").append(this->getModeAsString()); @@ -99,5 +99,38 @@ QString CTransponder::getTransponderCodeFormatted() const return f.right(4); } +/*! + * \brief Stream to DBus << + * \param argument + */ +void CTransponder::marshallToDbus(QDBusArgument &argument) const +{ + this->CAvionicsBase::marshallToDbus(argument); + argument << this->m_transponderCode; + argument << static_cast(this->m_transponderMode); +} + +/*! + * \brief Stream from DBus >> + * \param argument + */ +void CTransponder::unmarshallFromDbus(const QDBusArgument &argument) +{ + this->CAvionicsBase::unmarshallFromDbus(argument); + qint32 tm; + argument >> this->m_transponderCode; + argument >> tm; + this->m_transponderMode = static_cast(tm); +} + +/*! + * \brief Register metadata of unit and quantity + */ +void CTransponder::registerMetadata() +{ + qRegisterMetaType(typeid(CTransponder).name()); + qDBusRegisterMetaType(); +} + } // namespace } // namespace diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index c742e5240..3d09cb1cc 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -31,6 +31,7 @@ public: ModeC = 12, ModeS = 20 }; + private: qint32 m_transponderCode; //m_transponderCode = transponderCode.toUInt(&ok); - if (!ok)this->m_transponderCode = -1; // will cause assert / exception + if (!ok) this->m_transponderCode = -1; // will cause assert / exception this->validate(validate); } + protected: /*! * \brief Are the set values valid / in range? @@ -90,9 +92,22 @@ protected: /*! * \brief Meaningful string representation + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString convertToQString(bool i18n = false) const; + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const; + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument); public: /*! @@ -102,10 +117,10 @@ public: /*! * \brief Copy constructor - * \param otherTransponder + * \param other */ - CTransponder(const CTransponder &otherTransponder) : CAvionicsBase(otherTransponder.getName()), - m_transponderCode(otherTransponder.m_transponderCode), m_transponderMode(otherTransponder.m_transponderMode) {} + CTransponder(const CTransponder &other) : CAvionicsBase(other.getName()), + m_transponderCode(other.m_transponderCode), m_transponderMode(other.m_transponderMode) {} /*! * \brief Constructor @@ -130,7 +145,7 @@ public: { bool ok = false; this->m_transponderCode = transponderCode.toUInt(&ok); - if (!ok)this->m_transponderCode = -1; // will cause assert / exception + if (!ok) this->m_transponderCode = -1; // will cause assert / exception this->validate(true); } @@ -194,7 +209,7 @@ public: } /*! - * \brief Set emergency + * \brief Set VFR */ void setVFR() { @@ -202,81 +217,70 @@ public: } /*! - * \brief Set emergency + * \brief Set IFR */ void setIFR() { this->m_transponderCode = 2000; } - /*! - * \brief Assigment operator = - * \param otherTransponder - * \return - */ - CTransponder &operator =(const CTransponder &otherTransponder) - { - CAvionicsBase::operator =(otherTransponder); - this->m_transponderMode = otherTransponder.m_transponderMode; - this->m_transponderCode = otherTransponder.m_transponderCode; - return (*this); - } - /*! * \brief operator == - * \param otherTransponder + * \param other * \return */ - bool operator ==(const CTransponder &otherTransponder) const + bool operator ==(const CTransponder &other) const { return - this->m_transponderCode == otherTransponder.m_transponderCode && - this->m_transponderMode == otherTransponder.m_transponderMode && - CAvionicsBase::operator ==(otherTransponder); + this->m_transponderCode == other.m_transponderCode && + this->m_transponderMode == other.m_transponderMode && + this->CAvionicsBase::operator ==(other); } /*! * \brief operator =! - * \param otherSystem + * \param other * \return */ - bool operator !=(const CTransponder &otherSystem) const + bool operator !=(const CTransponder &other) const { - return !((*this) == otherSystem); + return !((*this) == other); } /*! * Try to get a Transponder unit with given name and code. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param transponder + * \param[out] o_transponder * \param name * \param transponderCode * \param mode * \return */ - static bool tryGetTransponder(CTransponder &transponder, const QString &name, qint32 transponderCode, TransponderMode mode) + static bool tryGetTransponder(CTransponder &o_transponder, const QString &name, qint32 transponderCode, TransponderMode mode) { - transponder = CTransponder(false, name, transponderCode, mode); + o_transponder = CTransponder(false, name, transponderCode, mode); bool s; - if (!(s = transponder.validate(false))) transponder = CTransponder(); // reset to default + if (!(s = o_transponder.validate(false))) o_transponder = CTransponder(); // reset to default return s; } + /*! * Try to get a Transponder unit with given name and code. Returns true in case an object * has been sucessfully created, otherwise returns a default object. - * \param transponder + * \param[out] o_transponder * \param name * \param transponderCode * \param mode * \return */ - static bool tryGetTransponder(CTransponder &transponder, const QString &name, const QString &transponderCode, TransponderMode mode) + static bool tryGetTransponder(CTransponder &o_transponder, const QString &name, const QString &transponderCode, TransponderMode mode) { - transponder = CTransponder(false, name, transponderCode, mode); + o_transponder = CTransponder(false, name, transponderCode, mode); bool s; - if (!(s = transponder.validate(false))) transponder = CTransponder(); // reset to default + if (!(s = o_transponder.validate(false))) o_transponder = CTransponder(); // reset to default return s; } + /*! * \brief Transponder unit * \param transponderCode @@ -287,33 +291,41 @@ public: { return CTransponder("Transponder", transponderCode, mode); } + /*! * \brief Try to get Transponder unit - * \param transponder + * \param[out] o_transponder * \param transponderCode * \param mode * \return */ - static bool tryGetStandardTransponder(CTransponder &transponder, qint32 transponderCode, TransponderMode mode) + static bool tryGetStandardTransponder(CTransponder &o_transponder, qint32 transponderCode, TransponderMode mode) { - return CTransponder::tryGetTransponder(transponder, "Transponder", transponderCode, mode); + return CTransponder::tryGetTransponder(o_transponder, "Transponder", transponderCode, mode); } /*! * \brief Try to get Transponder unit - * \param transponder + * \param[out] o_transponder * \param transponderCode * \param mode * \return */ - static bool tryGetStandardTransponder(CTransponder &transponder, const QString &transponderCode, TransponderMode mode) + static bool tryGetStandardTransponder(CTransponder &o_transponder, const QString &transponderCode, TransponderMode mode) { - return CTransponder::tryGetTransponder(transponder, "Transponder", transponderCode, mode); + return CTransponder::tryGetTransponder(o_transponder, "Transponder", transponderCode, mode); } + /*! + * \brief Register metadata of unit and quantity + */ + static void registerMetadata(); + }; } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CTransponder) + #endif // BLACKMISC_AVIOTRANSPONDER_H diff --git a/src/blackmisc/avtrack.cpp b/src/blackmisc/avtrack.cpp index c70aab144..0569216f1 100644 --- a/src/blackmisc/avtrack.cpp +++ b/src/blackmisc/avtrack.cpp @@ -16,38 +16,35 @@ namespace Aviation /* * Own implementation for streaming */ -QString CTrack::stringForConverter() const +QString CTrack::convertToQString(bool i18n) const { - QString s = CAngle::stringForConverter(); - return s.append(this->m_magnetic ? " magnetic" : " true"); -} - -/* - * Assigment - */ -CTrack& CTrack::operator =(const CTrack &otherTrack) -{ - // Check for self-assignment! - if (this == &otherTrack) return *this; - CAngle::operator = (otherTrack); - this->m_magnetic = otherTrack.m_magnetic; - return (*this); + QString s = CAngle::convertToQString(i18n); + return s.append(this->isMagneticTrack() ? " magnetic" : " true"); } /* * Equal? */ -bool CTrack::operator ==(const CTrack &otherTrack) +bool CTrack::operator ==(const CTrack &other) { - return otherTrack.m_magnetic == this->m_magnetic && CAngle::operator ==(otherTrack); + return other.m_north == this->m_north && this->CAngle::operator ==(other); } /* * Unequal? */ -bool CTrack::operator !=(const CTrack &otherTrack) +bool CTrack::operator !=(const CTrack &other) { - return !((*this) == otherTrack); + return !((*this) == other); +} + +/*! + * \brief Register metadata of unit and quantity + */ +void CTrack::registerMetadata() +{ + qRegisterMetaType(typeid(CTrack).name()); + qDBusRegisterMetaType(); } } // namespace diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index f81725634..3600f71ba 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -7,7 +7,6 @@ #define BLACKMISC_AVTRACK_H #include "blackmisc/pqangle.h" - namespace BlackMisc { namespace Aviation @@ -19,84 +18,118 @@ namespace Aviation */ class CTrack : public BlackMisc::PhysicalQuantities::CAngle { +public: + /*! + * Enum type to distinguish between true north and magnetic north + */ + enum ReferenceNorth + { + Magnetic = 0, //!< magnetic north + True = 1, //!< true north + }; + private: - bool m_magnetic; //!< magnetic or true Track? + ReferenceNorth m_north; //!< magnetic or true? protected: /*! * \brief Specific stream operation for Track * \return */ - virtual QString stringForConverter() const; + virtual QString convertToQString(bool i18n = false) const; + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CAngle::marshallToDbus(argument); + argument << qint32(this->m_north); + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CAngle::unmarshallFromDbus(argument); + qint32 north; + argument >> north; + this->m_north = static_cast(north); + } public: /*! * \brief Default constructor: 0 Track magnetic */ - CTrack() : BlackMisc::PhysicalQuantities::CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_magnetic(true) {} + CTrack() : BlackMisc::PhysicalQuantities::CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_north(Magnetic) {} + /*! * \brief Constructor * \param value - * \param magnetic + * \param north * \param unit */ - CTrack(double value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_magnetic(magnetic) {} - /*! - * \brief Constructor - * \param value - * \param magnetic - * \param unit - */ - CTrack(int value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_magnetic(magnetic) {} + CTrack(double value, ReferenceNorth north, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_north(north) {} + /*! * \brief Constructor by CAngle * \param track - * \param magnetic + * \param north */ - CTrack(BlackMisc::PhysicalQuantities::CAngle track, bool magnetic) : BlackMisc::PhysicalQuantities::CAngle(), m_magnetic(magnetic) { - BlackMisc::PhysicalQuantities::CAngle::operator =(track); - } - /*! - * \brief Copy constructor - * \param otherTrack - */ - CTrack(const CTrack &otherTrack) : BlackMisc::PhysicalQuantities::CAngle(otherTrack), m_magnetic(otherTrack.m_magnetic) {} - /*! - * \brief Assignment operator = - * \param otherTrack - * @return - */ - CTrack &operator =(const CTrack &otherTrack); + CTrack(BlackMisc::PhysicalQuantities::CAngle track, ReferenceNorth north) : BlackMisc::PhysicalQuantities::CAngle(track), m_north(north) {} + /*! * \brief Equal operator == - * \param otherTrack - * @return + * \param other + * \return */ - bool operator ==(const CTrack &otherTrack); + bool operator ==(const CTrack &other); + /*! * \brief Unequal operator == - * \param otherTrack - * @return + * \param other + * \return */ - bool operator !=(const CTrack &otherTrack); + bool operator !=(const CTrack &other); + /*! * \brief Magnetic Track? * \return */ - bool isMagneticTrack() const { - return this->m_magnetic; + bool isMagneticTrack() const + { + return Magnetic == this->m_north; + (void)QT_TRANSLATE_NOOP("Aviation", "magnetic"); } + /*! * \brief True Track? * \return */ - bool isTrueTrack() const { - return !this->m_magnetic; + bool isTrueTrack() const + { + return True == this->m_north; + (void)QT_TRANSLATE_NOOP("Aviation", "true"); } + + /*! + * \brief Get reference north (magnetic or true) + * \return + */ + ReferenceNorth getReferenceNorth() const { return m_north; } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); }; } // namespace - } // namespace +Q_DECLARE_METATYPE(BlackMisc::Aviation::CTrack) + #endif // BLACKMISC_AVTRACK_H diff --git a/src/blackmisc/avverticalpositions.cpp b/src/blackmisc/avverticalpositions.cpp deleted file mode 100644 index 398113626..000000000 --- a/src/blackmisc/avverticalpositions.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "avverticalpositions.h" - -using BlackMisc::PhysicalQuantities::CLength; -using BlackMisc::PhysicalQuantities::CLengthUnit; -using BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants; - -namespace BlackMisc -{ -namespace Aviation -{ - -/* - * Constructor - */ -CAviationVerticalPositions::CAviationVerticalPositions() : - m_altitude(CAltitude(0, true, CLengthUnit::ft())), - m_elevation(CPhysicalQuantitiesConstants::Length0ft()), - m_height(CPhysicalQuantitiesConstants::Length0ft()) -{ - // void -} - -/* - * Constructor - */ -CAviationVerticalPositions::CAviationVerticalPositions(const CAltitude &altitude, const CLength &elevation, const CLength &height) : - m_altitude(altitude), m_elevation(elevation), m_height(height) -{ - // void -} - -/* - * Copy constructor - */ -CAviationVerticalPositions::CAviationVerticalPositions(const CAviationVerticalPositions &otherPosition) : - m_altitude(otherPosition.m_altitude), m_elevation(otherPosition.m_elevation), m_height(otherPosition.m_height) -{ - // void -} - -/* - * Assigment - */ -CAviationVerticalPositions &CAviationVerticalPositions::operator =(const CAviationVerticalPositions &otherPositions) -{ - if (this == &otherPositions) return *this; // Same object? - this->m_altitude = otherPositions.m_altitude; - this->m_elevation = otherPositions.m_elevation; - this->m_height = otherPositions.m_height; - return *this; -} - -/* - * Equal operator - */ -bool CAviationVerticalPositions::operator ==(const CAviationVerticalPositions &otherPositions) -{ - return this->m_altitude == otherPositions.m_altitude && - this->m_elevation == otherPositions.m_elevation && - this->m_height == otherPositions.m_height; -} - -/* - * Unequal operator - */ -bool CAviationVerticalPositions::operator !=(const CAviationVerticalPositions &otherPositions) -{ - return !(*this == otherPositions); -} - -/* - * String representation for streaming - */ -QString CAviationVerticalPositions::stringForStreamingOperator() const -{ - QString s = QString("Altitude: "). - append(this->m_altitude.unitValueRoundedWithUnit()). - append(" Elevation: "). - append(this->m_elevation.unitValueRoundedWithUnit()). - append(" Height: "). - append(this->m_height.unitValueRoundedWithUnit()); - return s; -} - -/* - * Factory by elevation and altitude - */ -CAviationVerticalPositions CAviationVerticalPositions::fromAltitudeAndElevationInFt(double altitudeMslFt, double elevationFt) -{ - CAltitude a(altitudeMslFt, true, CLengthUnit::ft()); - CLength e(elevationFt, CLengthUnit::ft()); - CLength h(altitudeMslFt - elevationFt, CLengthUnit::ft()); - return CAviationVerticalPositions(a, e, h); -} - -/* - * Factory by elevation and altitude - */ -CAviationVerticalPositions CAviationVerticalPositions::fromAltitudeAndElevationInM(double altitudeMslM, double elevationM) -{ - CAltitude a(altitudeMslM, true, CLengthUnit::m()); - CLength e(elevationM, CLengthUnit::m()); - CLength h(altitudeMslM - elevationM, CLengthUnit::m()); - return CAviationVerticalPositions(a, e, h); -} - -/* - * Stream for log message - */ -CLogMessage operator <<(CLogMessage log, const CAviationVerticalPositions &positions) -{ - log << positions.stringForStreamingOperator(); - return log; -} - -/* - * Stream for qDebug - */ -QDebug operator <<(QDebug d, const CAviationVerticalPositions &positions) -{ - d << positions.stringForStreamingOperator(); - return d; -} - -} // namespace -} // namespace diff --git a/src/blackmisc/avverticalpositions.h b/src/blackmisc/avverticalpositions.h deleted file mode 100644 index 167739a57..000000000 --- a/src/blackmisc/avverticalpositions.h +++ /dev/null @@ -1,129 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BLACKMISC_AVLATERALPOSITION_H -#define BLACKMISC_AVLATERALPOSITION_H - -#include "blackmisc/avaltitude.h" -#include "blackmisc/pqconstants.h" - -namespace BlackMisc -{ -namespace Aviation -{ - -/*! - * \brief Vertical (Z) positions of an aircraft - */ -class CAviationVerticalPositions -{ - /*! - * \brief Stream << overload to be used in debugging messages - * \param d - * \param positions - * \return - */ - friend QDebug operator<<(QDebug d, const CAviationVerticalPositions &positions); - - /*! - * Stream operator for log messages - * \brief operator << - * \param log - * \param positions - * \return - */ - friend CLogMessage operator<<(CLogMessage log, const CAviationVerticalPositions &positions); - -private: - CAltitude m_altitude; //!< altitude - BlackMisc::PhysicalQuantities::CLength m_elevation; //!< elevation - BlackMisc::PhysicalQuantities::CLength m_height; //!< height - -protected: - /*! - * \brief Specific stream operation for heading - * \return - */ - virtual QString stringForStreamingOperator() const; - -public: - /*! - * \brief Default constructor - */ - CAviationVerticalPositions(); - /*! - * \brief Constructor - * \param altitude - * \param elevation - * \param height - */ - CAviationVerticalPositions(const CAltitude &altitude, const BlackMisc::PhysicalQuantities::CLength &elevation, const BlackMisc::PhysicalQuantities::CLength &height); - /*! - * \brief Copy constructor - * \param otherPosition - */ - CAviationVerticalPositions(const CAviationVerticalPositions &otherPosition); - /*! - * \brief Assignment operator = - * \param otherPositions - * @return - */ - CAviationVerticalPositions &operator =(const CAviationVerticalPositions &otherPositions); - /*! - * \brief Equal operator == - * \param otherPositions - * @return - */ - bool operator ==(const CAviationVerticalPositions &otherPositions); - /*! - * \brief Unequal operator == - * \param otherPositions - * @return - */ - bool operator !=(const CAviationVerticalPositions &otherPositions); - /*! - * \brief Height - * \return - */ - BlackMisc::PhysicalQuantities::CLength getHeight() const - { - return this->m_height; - } - /*! - * \brief Elevation - * \return - */ - BlackMisc::PhysicalQuantities::CLength getElevation() const - { - return this->m_elevation; - } - /*! - * \brief Altitude - * \return - */ - CAltitude getAltitude()const - { - return this->m_altitude; - } - /*! - * \brief Factory getting tupel frome levation and altitude values in ft - * \param altitudeMslFt - * \param elevationFt - * \return - */ - static CAviationVerticalPositions fromAltitudeAndElevationInFt(double altitudeMslFt, double elevationFt); - /*! - * \brief Factory getting tupel frome levation and altitude values in meters - * \param altitudeMslM - * \param elevationM - * \return - */ - static CAviationVerticalPositions fromAltitudeAndElevationInM(double altitudeMslM, double elevationM); -}; - -} // namespace -} // namespace - -#endif // BLACKMISC_AVLATERALPOSITION_H diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h deleted file mode 100644 index 412ff78f6..000000000 --- a/src/blackmisc/basestreamstringifier.h +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef BLACKMISC_BASESTREAMSTRINGIFIER_H -#define BLACKMISC_BASESTREAMSTRINGIFIER_H - -#include "blackmisc/debug.h" -#include -#include -#include -#include -#include - -namespace BlackMisc -{ -/*! - * \brief Provides "to QString" and stream operators - */ -class CBaseStreamStringifier -{ - /*! - * \brief Stream << overload to be used in debugging messages - * \param debug - * \param uc - * \return - */ - friend QDebug operator<<(QDebug debug, const CBaseStreamStringifier &uc) - { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method - debug << sf.stringForStreaming(); - return debug; - } - // msvc2010: friend QDebug &operator<<(QDebug &debug, const CBaseStreamStringifier &uc) - // MinGW: No reference - - /*! - * \brief Operator << based on text stream - * \param textStream - * \param uc - * \return - */ - friend QTextStream &operator<<(QTextStream &textStream, const CBaseStreamStringifier &uc) - { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method - textStream << sf.stringForStreaming(); - return textStream; - } - - /*! - * \brief Operator << when there is no debug stream - * \param nodebug - * \param uc - * \return - */ - friend QNoDebug operator<<(QNoDebug nodebug, const CBaseStreamStringifier & /* uc */) - { - return nodebug; - } - - /*! - * \brief Stream operator << for QDataStream - * \param stream - * \param uc - * \return - */ - friend QDataStream &operator<<(QDataStream &stream, const CBaseStreamStringifier &uc) - { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method - stream << sf.stringForStreaming(); - return stream; - } - - /*! - * \brief Stream operator << for log messages - * \param log - * \param uc - * \return - */ - friend CLogMessage operator<<(CLogMessage log, const CBaseStreamStringifier &uc) - { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method - log << sf.stringForStreaming(); - return log; - } - - /*! - * \brief Stream operator << for std::cout - * \param ostr - * \param uc - * \return - */ - friend std::ostream &operator<<(std::ostream &ostr, const CBaseStreamStringifier &uc) - { - const CBaseStreamStringifier &sf = uc; // allows to acces protected method - ostr << sf.stringForStreaming().toStdString(); - return ostr; - } - -public: - /*! - * \brief Virtual destructor - */ - virtual ~CBaseStreamStringifier() {} - - /*! - * \brief Cast as QString - * \remarks operator cast caused too many ambiguity trouble - */ - QString toQString() const - { - return this->stringForConverter(); - } - -protected: - - /*! - * \brief String for streaming operators - * \return - */ - virtual QString stringForStreaming() const - { - // simplest default implementation requires only one method - return this->stringForConverter(); - } - - /*! - * \brief String for converter - * \return - */ - virtual QString stringForConverter() const = 0; - - /*! - * \brief Copy assignment operator. - * This is protected in order to forbid slicing an instance of one derived - * class into an instance of a completely unrelated derived class. - * \return - */ - CBaseStreamStringifier& operator=(const CBaseStreamStringifier&) { return *this; } -}; - -} // namespace - -#endif // guard diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 6eb4b7008..071684d66 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -1,20 +1,27 @@ -QT += network +QT += network dbus TARGET = blackmisc TEMPLATE = lib -CONFIG += staticlib +CONFIG += staticlib c++11 INCLUDEPATH += .. # DEPENDPATH += . .. // BlackMisc should be independent - # PRECOMPILED_HEADER = stdpch.h precompile_header:!isEmpty(PRECOMPILED_HEADER) { DEFINES += USING_PCH } DEFINES += LOG_IN_FILE +RESOURCES += blackmisc.qrc + +# lupdate +CODECFORTR = UTF-8 +TRANSLATIONS += translations/blackmisc_i18n_de.ts \ + translations/blackmisc_i18n_fr.ts \ + translations/blackmisc_i18n_en.ts HEADERS += *.h SOURCES += *.cpp - DESTDIR = ../../lib +OTHER_FILES += $$TRANSLATIONS \ + readme.txt diff --git a/src/blackmisc/blackmisc.qrc b/src/blackmisc/blackmisc.qrc new file mode 100644 index 000000000..d2d0e250e --- /dev/null +++ b/src/blackmisc/blackmisc.qrc @@ -0,0 +1,7 @@ + + + translations/blackmisc_i18n_de.qm + translations/blackmisc_i18n_fr.qm + translations/blackmisc_i18n_en.qm + + diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp new file mode 100644 index 000000000..70020caa3 --- /dev/null +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -0,0 +1,79 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmiscfreefunctions.h" + +/* + * Metadata for PQs + */ +void BlackMisc::PhysicalQuantities::registerMetadata() +{ + CAcceleration::registerMetadata(); + CAngle::registerMetadata(); + CFrequency::registerMetadata(); + CLength::registerMetadata(); + CMass::registerMetadata(); + CPressure::registerMetadata(); + CSpeed::registerMetadata(); + CTemperature::registerMetadata(); + CTime::registerMetadata(); +} + +/* + * Metadata for aviation + */ +void BlackMisc::Aviation::registerMetadata() +{ + CComSystem::registerMetadata(); + CNavSystem::registerMetadata(); + CAdfSystem::registerMetadata(); + CAltitude::registerMetadata(); + CTransponder::registerMetadata(); + CHeading::registerMetadata(); + CTrack::registerMetadata(); +} + +/* + * Metadata for Math + */ +void BlackMisc::Math::registerMetadata() +{ + CMatrix3x3::registerMetadata(); + CMatrix3x1::registerMetadata(); + CMatrix1x3::registerMetadata(); + CVector3D::registerMetadata(); +} + + +/* + * Metadata for Geo + */ +void BlackMisc::Geo::registerMetadata() +{ + CCoordinateEcef::registerMetadata(); + CCoordinateNed::registerMetadata(); + CCoordinateGeodetic::registerMetadata(); + CLatitude::registerMetadata(); + CLongitude::registerMetadata(); +} + +/* + * Metadata for Blackmisc + */ +void BlackMisc::registerMetadata() +{ + PhysicalQuantities::registerMetadata(); + Aviation::registerMetadata(); + Math::registerMetadata(); + Geo::registerMetadata(); +} + +/* + * Init resources + */ +void BlackMisc::initResources() +{ + initBlackMiscResources(); +} diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h new file mode 100644 index 000000000..4dce58ddd --- /dev/null +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -0,0 +1,79 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_FREEFUNCTIONS_H +#define BLACKMISC_FREEFUNCTIONS_H +#include "avallclasses.h" +#include "pqallquantities.h" +#include "mathallclasses.h" +#include "geoallclasses.h" + +/*! + * \brief Workaround, to call initResource from namespace + */ +// cannot be declare within namespace, see docu +inline void initBlackMiscResources() { Q_INIT_RESOURCE(blackmisc); } + +/*! + * Free functions in BlackMisc + */ +namespace BlackMisc { + +/*! + * Free functions in PQ + */ +namespace PhysicalQuantities { + +/*! + * \brief Register all metadata for PQs + */ +void registerMetadata(); + +} // PQ + +/*! + * Free functions in aviation + */ +namespace Aviation { + +/*! + * \brief Register metadata for aviation + */ +void registerMetadata(); + +} // Aviation + +namespace Math { + +/*! + * \brief Register metadata for math (matrices, vectors) + */ +void registerMetadata(); + +} // Math + +namespace Geo { + +/*! + * \brief Register metadata for geo (coordinates) + */ +void registerMetadata(); + +} // Geo + +/*! + * \brief Register all relevant metadata in BlackMisc + */ +void registerMetadata(); + +/*! + * \brief Init resources + */ +void initResources(); + + +} // BlackMisc + +#endif // BLACKMISC_FREEFUNCTIONS_H diff --git a/src/blackmisc/com_handler.cpp b/src/blackmisc/com_handler.cpp index ec87385d7..0a95e7e43 100644 --- a/src/blackmisc/com_handler.cpp +++ b/src/blackmisc/com_handler.cpp @@ -100,8 +100,8 @@ namespace BlackMisc ///////////////////////////////////////////////// data.resize(message_length); + // creates warning when compiled as RELEASE qint32 bytes = stream.readRawData(data.data(), message_length); - Q_ASSERT (bytes == message_length); Q_ASSERT (data.size() == message_length); diff --git a/src/blackmisc/com_server.cpp b/src/blackmisc/com_server.cpp index 4b67198aa..510f920b9 100644 --- a/src/blackmisc/com_server.cpp +++ b/src/blackmisc/com_server.cpp @@ -92,7 +92,7 @@ void CComServer::sendToAll(const QString &messageID, const QByteArray &data) } } -QString CComServer::getErrorMessage(const QAbstractSocket::SocketError error) +QString CComServer::getErrorMessage(const QAbstractSocket::SocketError /** error **/) { return QString(); } @@ -128,7 +128,7 @@ void CComServer::onClientDisconnected(uint clientID) m_client_buffers.take(clientID)->deleteLater(); } -void CComServer::onClientMessageReceived(uint clientID, QString &messageID, QByteArray &message) +void CComServer::onClientMessageReceived(uint /** clientID **/, QString &messageID, QByteArray &message) { emit doMessageReceived(messageID, message); } diff --git a/src/blackmisc/coordinateecef.h b/src/blackmisc/coordinateecef.h index ac9d27a52..e660b72ef 100644 --- a/src/blackmisc/coordinateecef.h +++ b/src/blackmisc/coordinateecef.h @@ -11,6 +11,7 @@ namespace BlackMisc { namespace Geo { + /*! * \brief Earth centered, earth fixed position */ @@ -104,7 +105,7 @@ protected: * \brief String for converter * \return */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { QString s = "ECEF: {x %1, y %2, z %3}"; s = s.arg(QString::number(this->x(), 'f', 6)). @@ -112,11 +113,11 @@ protected: arg(QString::number(this->z(), 'f', 6)); return s; } - }; } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateEcef) #endif // guard diff --git a/src/blackmisc/coordinategeodetic.cpp b/src/blackmisc/coordinategeodetic.cpp new file mode 100644 index 000000000..b1d675b33 --- /dev/null +++ b/src/blackmisc/coordinategeodetic.cpp @@ -0,0 +1,52 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmisc/coordinategeodetic.h" + +namespace BlackMisc +{ +namespace Geo +{ + +/* + * String for converter + */ +QString CCoordinateGeodetic::convertToQString(bool i18n) const +{ + QString s = "Geodetic: {%1, %2, %3}"; + return s.arg(this->m_latitude.valueRoundedWithUnit(6, i18n)).arg(this->m_longitude.valueRoundedWithUnit(6, i18n)).arg(this->m_height.valueRoundedWithUnit(i18n)); +} + +/* + * Marshall to Dbus + */ +void CCoordinateGeodetic::marshallToDbus(QDBusArgument &argument) const +{ + argument << this->m_latitude; + argument << this->m_longitude; + argument << this->m_height; +} + +/* + * Unmarshall from Dbus + */ +void CCoordinateGeodetic::unmarshallFromDbus(const QDBusArgument &argument) +{ + argument >> this->m_latitude; + argument >> this->m_longitude; + argument >> this->m_height; +} + +/* + * Register metadata + */ +void CCoordinateGeodetic::registerMetadata() +{ + qRegisterMetaType(typeid(CCoordinateGeodetic).name()); + qDBusRegisterMetaType(); +} + +} // namespace +} // namespace diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index 228ab7bed..864acff1c 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -16,6 +16,7 @@ namespace Geo { /*! + * Latitude and longitude interface * \brief Interface for geodetic ccordinates */ class ICoordinateGeodetic @@ -24,39 +25,44 @@ class ICoordinateGeodetic * \brief Latitude * \return */ - virtual CLatitude latitude() const = 0; + virtual const CLatitude &latitude() const = 0; /*! * \brief Longitude * \return */ - virtual CLongitude longitude() const = 0; + virtual const CLongitude &longitude() const = 0; }; /*! * \brief Geodetic coordinate */ -class CCoordinateGeodetic : - public CBaseStreamStringifier, - public ICoordinateGeodetic +class CCoordinateGeodetic : public CStreamable, public ICoordinateGeodetic { - private: - CLatitude m_latitude; //!< Latitude - CLongitude m_longitude; //!< Longitude + BlackMisc::Geo::CLatitude m_latitude; //!< Latitude + BlackMisc::Geo::CLongitude m_longitude; //!< Longitude BlackMisc::PhysicalQuantities::CLength m_height; //!< height protected: - /*! * \brief String for converter + * \param i18n * \return */ - virtual QString stringForConverter() const - { - QString s = "Geodetic: {%1, %2, %3}"; - return s.arg(this->m_latitude.unitValueRoundedWithUnit(6)).arg(this->m_longitude.unitValueRoundedWithUnit(6)).arg(this->m_height.unitValueRoundedWithUnit()); - } + virtual QString convertToQString(bool i18n = false) const; + + /*! + * \brief Stream to DBus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const; + + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument); public: /*! @@ -92,7 +98,7 @@ public: * \brief Latitude * \return */ - CLatitude latitude() const + const CLatitude &latitude() const { return this->m_latitude; } @@ -101,7 +107,7 @@ public: * \brief Longitude * \return */ - CLongitude longitude() const + const CLongitude &longitude() const { return this->m_longitude; } @@ -110,7 +116,7 @@ public: * \brief Height * \return */ - BlackMisc::PhysicalQuantities::CLength height() const + const BlackMisc::PhysicalQuantities::CLength &height() const { return this->m_height; } @@ -124,7 +130,7 @@ public: { this->m_latitude.switchUnit(unit); this->m_longitude.switchUnit(unit); - return (*this); + return *this; } /*! @@ -135,14 +141,14 @@ public: CCoordinateGeodetic &switchUnit(const BlackMisc::PhysicalQuantities::CLengthUnit &unit) { this->m_height.switchUnit(unit); - return (*this); + return *this; } /*! * \brief Set latitude * \param latitude */ - void setLatitude(CLatitude latitude) + void setLatitude(const CLatitude &latitude) { this->m_latitude = latitude; } @@ -151,7 +157,7 @@ public: * \brief Set longitude * \param longitude */ - void setLongitude(CLongitude longitude) + void setLongitude(const CLongitude &longitude) { this->m_longitude = longitude; } @@ -160,52 +166,43 @@ public: * \brief Set height * \param height */ - void setHeight(BlackMisc::PhysicalQuantities::CLength height) + void setHeight(const BlackMisc::PhysicalQuantities::CLength &height) { this->m_height = height; } /*! * \brief Equal operator == - * \param otherGeodetic + * \param other * \return */ - bool operator ==(const CCoordinateGeodetic &otherGeodetic) const + bool operator ==(const CCoordinateGeodetic &other) const { - if (this == &otherGeodetic) return true; - return this->m_height == otherGeodetic.m_height && - this->m_latitude == otherGeodetic.m_latitude && - this->m_longitude == otherGeodetic.m_longitude; + if (this == &other) return true; + return this->m_height == other.m_height && + this->m_latitude == other.m_latitude && + this->m_longitude == other.m_longitude; } /*! * \brief Unequal operator != - * \param otherGeodetic + * \param other * \return */ - bool operator !=(const CCoordinateGeodetic &otherGeodetic) const + bool operator !=(const CCoordinateGeodetic &other) const { - if (this == &otherGeodetic) return false; - return !((*this) == otherGeodetic); + return !((*this) == other); } - /*! - * \brief Assigment operator = - * \param otherGeodetic - * \return + /* + * Register metadata */ - CCoordinateGeodetic &operator =(const CCoordinateGeodetic &otherGeodetic) - { - if (this == &otherGeodetic) return *this; // Same object? - this->m_height = otherGeodetic.m_height; - this->m_latitude = otherGeodetic.m_latitude; - this->m_longitude = otherGeodetic.m_longitude; - return (*this); - } + static void registerMetadata(); }; } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateGeodetic) #endif // guard diff --git a/src/blackmisc/coordinatened.h b/src/blackmisc/coordinatened.h index d1677c795..78c40638e 100644 --- a/src/blackmisc/coordinatened.h +++ b/src/blackmisc/coordinatened.h @@ -18,7 +18,6 @@ namespace Geo */ class CCoordinateNed : public BlackMisc::Math::CVector3DBase { - private: CCoordinateGeodetic m_referencePosition; //!< geodetic reference position bool m_hasReferencePosition; //!< valid reference position? @@ -28,7 +27,7 @@ protected: * \brief String for converter * \return */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { QString s = "NED: {N %1, E %2, D %3}"; s = s.arg(QString::number(this->north(), 'f', 6)). @@ -70,58 +69,43 @@ public: * \brief Copy constructor * \param otherNed */ - CCoordinateNed(const CCoordinateNed &otherNed) : - CVector3DBase(otherNed), m_referencePosition(otherNed.m_referencePosition), m_hasReferencePosition(otherNed.m_hasReferencePosition) {} + CCoordinateNed(const CCoordinateNed &other) : + CVector3DBase(other), m_referencePosition(other.m_referencePosition), m_hasReferencePosition(other.m_hasReferencePosition) {} /*! * \brief Constructor by math vector * \param vector */ - explicit CCoordinateNed(const BlackMisc::Math::CVector3D vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(), m_hasReferencePosition(false) {} + explicit CCoordinateNed(const BlackMisc::Math::CVector3D &vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(), m_hasReferencePosition(false) {} /*! * \brief Constructor by math vector and reference position * \param referencePosition * \param vector */ - CCoordinateNed(const CCoordinateGeodetic &referencePosition, const BlackMisc::Math::CVector3D vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(referencePosition), m_hasReferencePosition(true) {} + CCoordinateNed(const CCoordinateGeodetic &referencePosition, const BlackMisc::Math::CVector3D &vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(referencePosition), m_hasReferencePosition(true) {} /*! * \brief Equal operator == - * \param otherNed + * \param other * \return */ - bool operator ==(const CCoordinateNed &otherNed) const + bool operator ==(const CCoordinateNed &other) const { - if (this == &otherNed) return true; - return this->m_hasReferencePosition == otherNed.m_hasReferencePosition && - this->m_referencePosition == otherNed.m_referencePosition && - CVector3DBase::operator== (otherNed); + if (this == &other) return true; + return this->m_hasReferencePosition == other.m_hasReferencePosition && + this->m_referencePosition == other.m_referencePosition && + this->CVector3DBase::operator== (other); } /*! * \brief Unequal operator != - * \param otherNed + * \param other * \return */ - bool operator !=(const CCoordinateNed &otherNed) const + bool operator !=(const CCoordinateNed &other) const { - if (this == &otherNed) return false; - return !((*this) == otherNed); - } - - /*! - * \brief Assigment operator = - * \param otherNed - * \return - */ - CCoordinateNed &operator =(const CCoordinateNed &otherNed) - { - if (this == &otherNed) return *this; // Same object? - CVector3DBase::operator = (otherNed); - this->m_hasReferencePosition = otherNed.m_hasReferencePosition; - this->m_referencePosition = otherNed.m_referencePosition; - return (*this); + return !((*this) == other); } /*! @@ -219,5 +203,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateNed) #endif // guard diff --git a/src/blackmisc/coordinatetransformation.cpp b/src/blackmisc/coordinatetransformation.cpp index a79483ce9..28c70fbc4 100644 --- a/src/blackmisc/coordinatetransformation.cpp +++ b/src/blackmisc/coordinatetransformation.cpp @@ -80,7 +80,7 @@ CCoordinateEcef CCoordinateTransformation::toEcef(const CCoordinateGeodetic &geo double clambda = cos(lambdaRad); - double h = geo.height().convertedSiValueToDouble(); + double h = geo.height().value(CLengthUnit::m()); double x = (n + h) * cphi; double y = x * slambda; x *= clambda; diff --git a/src/blackmisc/coordinatetransformation.h b/src/blackmisc/coordinatetransformation.h index b4e9a62e3..519eb586b 100644 --- a/src/blackmisc/coordinatetransformation.h +++ b/src/blackmisc/coordinatetransformation.h @@ -91,9 +91,9 @@ private: } /*! - * \brief Default constructor, avoid object instantiation + * \brief Default constructor, deleted */ - CCoordinateTransformation() {} + CCoordinateTransformation(); public: /*! @@ -124,7 +124,6 @@ public: * \return */ static CCoordinateGeodetic toGeodetic(const CCoordinateEcef &ecef); - }; } // namespace diff --git a/src/blackmisc/debug.cpp b/src/blackmisc/debug.cpp index 01bef4277..a07368c82 100644 --- a/src/blackmisc/debug.cpp +++ b/src/blackmisc/debug.cpp @@ -14,7 +14,7 @@ CDebug::CDebug() } -void CDebug::create(const char *logPath, bool logInFile, bool eraseLastLog) +void CDebug::create(const char * /** logPath **/, bool logInFile, bool eraseLastLog) { if (!m_isInitialized) { diff --git a/src/blackmisc/display.cpp b/src/blackmisc/display.cpp index 843d024b2..3647bbf2c 100644 --- a/src/blackmisc/display.cpp +++ b/src/blackmisc/display.cpp @@ -225,7 +225,7 @@ namespace BlackMisc if (m_file->handle() == -1) { if ( !m_file->open(QIODevice::WriteOnly) ) - printf ("Can't open log file '%s': %s\n", m_fileName.toLatin1().constData(), strerror (errno)); + printf ("Can't open log file '%s': %s\n", m_fileName.toLatin1().constData(), strerror(errno)); } if (m_file->handle() != -1) diff --git a/src/blackmisc/geoallclasses.h b/src/blackmisc/geoallclasses.h new file mode 100644 index 000000000..a8b82f0e9 --- /dev/null +++ b/src/blackmisc/geoallclasses.h @@ -0,0 +1,16 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_GEOALLCLASSES_H +#define BLACKMISC_GEOALLCLASSES_H + +#include "blackmisc/geoearthangle.h" +#include "blackmisc/geolatitude.h" +#include "blackmisc/geolongitude.h" +#include "blackmisc/coordinateecef.h" +#include "blackmisc/coordinatened.h" +#include "blackmisc/coordinategeodetic.h" + +#endif // guard diff --git a/src/blackmisc/geoearthangle.cpp b/src/blackmisc/geoearthangle.cpp new file mode 100644 index 000000000..219bc85c0 --- /dev/null +++ b/src/blackmisc/geoearthangle.cpp @@ -0,0 +1,77 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmisc/geoearthangle.h" +#include "blackmisc/geolatitude.h" +#include "blackmisc/geolongitude.h" + +namespace BlackMisc +{ +namespace Geo +{ + +/* + * Register metadata + */ +template void CEarthAngle::registerMetadata() +{ + qRegisterMetaType(typeid(LATorLON).name()); + qDBusRegisterMetaType(); +} + +/* + * Latitude or Longitude from a WGS string + */ +template LATorLON CEarthAngle::fromWgs84(const QString &wgsCoordinate) +{ + // http://www.regular-expressions.info/floatingpoint.html + QRegExp rx("([-+]?[0-9]*\\.?[0-9]+)"); + qint32 deg = 0; + qint32 min = 0; + double sec = 0.0; + double secFragment = 0.0; + int fragmentLength = 0; + int c = 0; + int pos= 0; + while ((pos = rx.indexIn(wgsCoordinate, pos)) != -1) { + QString cap = rx.cap(1); + pos += rx.matchedLength(); + switch(c++) { + case 0: + deg = cap.toInt(); + break; + case 1: + min = cap.toInt(); + break; + case 2: + sec = cap.toDouble(); + break; + case 3: + secFragment = cap.toDouble(); + fragmentLength = cap.length(); + break; + default: + break; + } + } + if (fragmentLength > 0) { + // we do have given ms + sec += secFragment / qPow(10,fragmentLength); + } + + if (wgsCoordinate.contains('S', Qt::CaseInsensitive) || + wgsCoordinate.contains('W', Qt::CaseInsensitive)) deg *= -1; + + CAngle a(deg, min, sec); + return LATorLON(a); +} + +// see here for the reason of thess forward instantiations +// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html +template class CEarthAngle; +template class CEarthAngle; + +} // namespace +} // namespace diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index 1c33b8c53..7491af0de 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BLACKMISC_GEOLATLONBASE_H -#define BLACKMISC_GEOLATLONBASE_H +#ifndef BLACKMISC_GEOEARTHANGLE_H +#define BLACKMISC_GEOEARTHANGLE_H #include "blackmisc/pqangle.h" namespace BlackMisc @@ -22,30 +22,47 @@ protected: */ CEarthAngle() : CAngle(0.0, BlackMisc::PhysicalQuantities::CAngleUnit::deg()) {} - /*! - * \brief Copy constructor - * \param latOrLon - */ - CEarthAngle(const LATorLON &latOrLon) : CAngle(latOrLon) { } - /*! * \brief Init by double value * \param value * \param unit */ - CEarthAngle(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CAngle(value, unit) {} + CEarthAngle(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit) {} + + /*! + * \brief Init by double value + * \param angle + */ + CEarthAngle(const BlackMisc::PhysicalQuantities::CAngle &angle) : CAngle(angle) {} /*! * \brief String for converter and streaming * \return */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { - return this->unitValueRoundedWithUnit(6); + return this->valueRoundedWithUnit(6); + } + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const + { + this->CAngle::marshallToDbus(argument); + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + this->CAngle::unmarshallFromDbus(argument); } public: - /*! * \brief Virtual destructor */ @@ -58,7 +75,7 @@ public: */ bool operator==(const LATorLON &latOrLon) const { - return CAngle::operator ==(latOrLon); + return this->CAngle::operator ==(latOrLon); } /*! @@ -68,7 +85,7 @@ public: */ bool operator!=(const LATorLON &latOrLon) const { - return CAngle::operator !=(latOrLon); + return this->CAngle::operator !=(latOrLon); } /*! @@ -78,8 +95,8 @@ public: */ CEarthAngle &operator +=(const CEarthAngle &latOrLon) { - CAngle::operator +=(latOrLon); - return (*this); + this->CAngle::operator +=(latOrLon); + return *this; } /*! @@ -89,8 +106,8 @@ public: */ CEarthAngle &operator -=(const CEarthAngle &latOrLon) { - CAngle::operator -=(latOrLon); - return (*this); + this->CAngle::operator -=(latOrLon); + return *this; } /*! @@ -100,7 +117,7 @@ public: */ bool operator >(const LATorLON &latOrLon) const { - return CAngle::operator >(latOrLon); + return this->CAngle::operator >(latOrLon); } /*! @@ -110,7 +127,7 @@ public: */ bool operator <(const LATorLON &latOrLon) const { - return CAngle::operator >(latOrLon); + return this->CAngle::operator >(latOrLon); } /*! @@ -120,7 +137,7 @@ public: */ bool operator <=(const LATorLON &latOrLon) const { - return CAngle::operator <=(latOrLon); + return this->CAngle::operator <=(latOrLon); } /*! @@ -130,18 +147,7 @@ public: */ bool operator >=(const LATorLON &latOrLon) const { - return CAngle::operator >=(latOrLon); - } - - /*! - * \brief Assignment operator = - * \param latOrLon - * \return - */ - CEarthAngle &operator =(const LATorLON &latOrLon) - { - CAngle::operator =(latOrLon); - return (*this); + return this->CAngle::operator >=(latOrLon); } /*! @@ -151,8 +157,7 @@ public: */ LATorLON operator +(const LATorLON &latOrLon) const { - LATorLON l(0.0, this->getUnit()); - l += (*this); + LATorLON l(*this); l += latOrLon; return l; } @@ -164,11 +169,22 @@ public: */ LATorLON operator -(const LATorLON &latOrLon) const { - LATorLON l(0.0, this->getUnit()); - l += (*this); + LATorLON l(*this); l -= latOrLon; return l; } + + /*! + * Register metadata + */ + static void registerMetadata(); + + /*! + * \brief Latitude / Longitude from a WGS string such as + * \param wgsCoordinate 50° 2′ 0″ N / 8° 34′ 14″ E + * \return + */ + static LATorLON fromWgs84(const QString &wgsCoordinate); }; } // namespace diff --git a/src/blackmisc/geolatitude.h b/src/blackmisc/geolatitude.h index 1f0d18d19..82fb40285 100644 --- a/src/blackmisc/geolatitude.h +++ b/src/blackmisc/geolatitude.h @@ -1,7 +1,10 @@ #ifndef BLACKMISC_GEOLATITUDE_H #define BLACKMISC_GEOLATITUDE_H + +#include #include "blackmisc/geoearthangle.h" + namespace BlackMisc { namespace Geo @@ -16,10 +19,10 @@ protected: /*! * \brief Specific string representation */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { QString s = "latitude "; - return s.append(CEarthAngle::stringForConverter()); + return s.append(CEarthAngle::convertToQString()); } public: @@ -29,17 +32,17 @@ public: CLatitude() : CEarthAngle() {} /*! - * \brief Copy constructor - * \param latitude + * \brief Constructor + * \param angle */ - CLatitude(const CLatitude &latitude) : CEarthAngle(latitude) {} + explicit CLatitude(const BlackMisc::PhysicalQuantities::CAngle &angle) : CEarthAngle(angle) {} /*! * \brief Init by double value * \param value * \param unit */ - CLatitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CEarthAngle(value, unit) {} + CLatitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CEarthAngle(value, unit) {} /*! * \brief Virtual destructor @@ -50,5 +53,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Geo::CLatitude) #endif // guard diff --git a/src/blackmisc/geolongitude.h b/src/blackmisc/geolongitude.h index 1d47a9180..64880ef51 100644 --- a/src/blackmisc/geolongitude.h +++ b/src/blackmisc/geolongitude.h @@ -16,10 +16,10 @@ protected: /*! * \brief Specific string representation */ - virtual QString stringForConverter() const + virtual QString convertToQString() const { QString s = "longitude "; - return s.append(CEarthAngle::stringForConverter()); + return s.append(CEarthAngle::convertToQString()); } public: @@ -29,17 +29,17 @@ public: CLongitude() : CEarthAngle() {} /*! - * \brief Copy constructor - * \param Longitude + * \brief Constructor + * \param angle */ - CLongitude(const CLongitude &Longitude) : CEarthAngle(Longitude) {} + explicit CLongitude(const BlackMisc::PhysicalQuantities::CAngle &angle) : CEarthAngle(angle) {} /*! * \brief Init by double value * \param value * \param unit */ - CLongitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit): CEarthAngle(value, unit) {} + CLongitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CEarthAngle(value, unit) {} /*! * \brief Virtual destructor @@ -50,4 +50,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::Geo::CLongitude) + #endif // guard diff --git a/src/blackmisc/mathallclasses.h b/src/blackmisc/mathallclasses.h new file mode 100644 index 000000000..0bdf4325f --- /dev/null +++ b/src/blackmisc/mathallclasses.h @@ -0,0 +1,14 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_MATHALLCLASSES_H +#define BLACKMISC_MATHALLCLASSES_H + +#include "blackmisc/mathmatrix1x3.h" +#include "blackmisc/mathmatrix3x3.h" +#include "blackmisc/mathmatrix3x1.h" +#include "blackmisc/mathvector3d.h" + +#endif // guard diff --git a/src/blackmisc/mathematics.h b/src/blackmisc/mathematics.h index e97a72382..fa0eeada8 100644 --- a/src/blackmisc/mathematics.h +++ b/src/blackmisc/mathematics.h @@ -6,6 +6,7 @@ #ifndef BLACKMISC_MATHEMATICS_H #define BLACKMISC_MATHEMATICS_H #include +#include namespace BlackMisc { @@ -70,6 +71,26 @@ public: */ static double roundEpsilon(double value, double epsilon); + /*! + * \brief Nearest integer not greater in magnitude than value, correcting for epsilon + * \param value + * \param epsilon + */ + static inline double trunc(double value, double epsilon = 1e-10) + { + return value < 0 ? ceil(value - epsilon) : floor(value + epsilon); + } + + /*! + * \brief Fractional part of value + * \param value + */ + static inline double fract(double value) + { + double unused; + return modf(value, &unused); + } + /*! * \brief PI * \return @@ -102,9 +123,9 @@ public: private: /*! - * \brief Avoid object init + * \brief Deleted */ - CMath() {} + CMath(); }; } // namespace diff --git a/src/blackmisc/mathmatrix1x3.h b/src/blackmisc/mathmatrix1x3.h index 614c456cc..fede41204 100644 --- a/src/blackmisc/mathmatrix1x3.h +++ b/src/blackmisc/mathmatrix1x3.h @@ -15,21 +15,21 @@ namespace Math { /*! - * \brief 3D matrix + * \brief Matrix 1x3 */ class CMatrix1x3 : public CMatrixBase { public: /*! - * \brief Matrix 1x3 + * \brief Constructor */ CMatrix1x3() : CMatrixBase() {} /*! * \brief Copy constructor - * \param otherMatrix + * \param other */ - CMatrix1x3(const CMatrix1x3 &otherMatrix) : CMatrixBase(otherMatrix) {} + CMatrix1x3(const CMatrix1x3 &other) : CMatrixBase(other) {} /*! * \brief Init by fill value @@ -38,7 +38,7 @@ public: explicit CMatrix1x3(double fillValue) : CMatrixBase(fillValue) {} /*! - * \brief CMatrix 3x1 + * \brief Constructor * \param c1 * \param c2 * \param c3 @@ -52,7 +52,8 @@ public: }; } // namespace - } // namespace +Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix1x3) + #endif // guard diff --git a/src/blackmisc/mathmatrix3x1.h b/src/blackmisc/mathmatrix3x1.h index c2da2aefd..b28bbc979 100644 --- a/src/blackmisc/mathmatrix3x1.h +++ b/src/blackmisc/mathmatrix3x1.h @@ -14,26 +14,28 @@ namespace BlackMisc namespace Math { +class CMatrix3x3; + /*! * \brief Matrix 3x1 */ class CMatrix3x1 : public CMatrixBase { - friend class CMatrix3x3; // for matrix multiplicaion to access m_matrix + friend class CMatrix3x3; public: /*! - * \brief CMatrix 3x1 + * \brief Constructor */ CMatrix3x1() : CMatrixBase() {} /*! - * \brief CMatrix 3x1 + * \brief Constructor * \param r1 * \param r2 * \param r3 */ - CMatrix3x1(qreal r1, qreal r2, qreal r3) : CMatrixBase() + CMatrix3x1(double r1, double r2, double r3) : CMatrixBase() { this->m_matrix(0, 0) = r1; this->m_matrix(1, 0) = r2; @@ -44,7 +46,7 @@ public: * \brief Copy constructor * \param otherMatrix */ - CMatrix3x1(const CMatrix3x1 &otherMatrix) : CMatrixBase(otherMatrix) {} + CMatrix3x1(const CMatrix3x1 &other) : CMatrixBase(other) {} /*! * \brief Init by fill value @@ -74,7 +76,8 @@ public: }; } // namespace - } // namespace +Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x1) + #endif // guard diff --git a/src/blackmisc/mathmatrix3x3.cpp b/src/blackmisc/mathmatrix3x3.cpp index 7ef0e6905..fed2ad73f 100644 --- a/src/blackmisc/mathmatrix3x3.cpp +++ b/src/blackmisc/mathmatrix3x3.cpp @@ -15,27 +15,25 @@ namespace Math */ double CMatrix3x3::determinant() const { - double determinant = + return this->m_matrix(0, 0) * this->m_matrix(1, 1) * this->m_matrix(2, 2) + this->m_matrix(0, 1) * this->m_matrix(1, 2) * this->m_matrix(2, 0) + this->m_matrix(0, 2) * this->m_matrix(1, 0) * this->m_matrix(2, 1) - this->m_matrix(0, 1) * this->m_matrix(1, 0) * this->m_matrix(2, 2) - this->m_matrix(0, 2) * this->m_matrix(1, 1) * this->m_matrix(2, 0) - this->m_matrix(0, 0) * this->m_matrix(1, 2) * this->m_matrix(2, 1); - - return determinant; } /* * Inverse */ -CMatrix3x3 CMatrix3x3::inverse(bool &invertible) const +CMatrix3x3 CMatrix3x3::inverse(bool &o_invertible) const { CMatrix3x3 inverse; - double det; - if (this->allValuesEqual() || (det = determinant()) == 0) + double det = this->determinant(); + if (det == 0) { - invertible = false; + o_invertible = false; inverse.setZero(); return inverse; } @@ -51,7 +49,7 @@ CMatrix3x3 CMatrix3x3::inverse(bool &invertible) const inverse.m_matrix(2, 1) = (- this->m_matrix(0, 0) * this->m_matrix(2, 1) + this->m_matrix(0, 1) * this->m_matrix(2, 0)) * invdet; inverse.m_matrix(2, 2) = (this->m_matrix(0, 0) * this->m_matrix(1, 1) - this->m_matrix(0, 1) * this->m_matrix(1, 0)) * invdet; - invertible = true; + o_invertible = true; return inverse; } @@ -78,5 +76,4 @@ CMatrix3x1 CMatrix3x3::getColumn(int column) const } } // namespace - } // namespace diff --git a/src/blackmisc/mathmatrix3x3.h b/src/blackmisc/mathmatrix3x3.h index 80878ac94..f21a1d7be 100644 --- a/src/blackmisc/mathmatrix3x3.h +++ b/src/blackmisc/mathmatrix3x3.h @@ -27,9 +27,9 @@ public: /*! * \brief Copy constructor - * \param otherMatrix + * \param other */ - CMatrix3x3(const CMatrix3x3 &otherMatrix) : CMatrixBase(otherMatrix) {} + CMatrix3x3(const CMatrix3x3 &other) : CMatrixBase(other) {} /*! * \brief Init by fill value @@ -72,56 +72,64 @@ public: /*! * \brief Calculate the inverse - * \param invertible + * \param[out] o_isInvertible * \return */ - CMatrix3x3 inverse(bool &invertible) const; + CMatrix3x3 inverse(bool &o_isInvertible) const; /*! * \brief Operator *= - * \param otherMatrix + * \param other * \return */ - CMatrix3x3 &operator *=(const CMatrix3x3 &otherMatrix) + CMatrix3x3 &operator *=(const CMatrix3x3 &other) { - this->m_matrix = this->m_matrix * otherMatrix.m_matrix; - return (*this); + this->m_matrix = this->m_matrix * other.m_matrix; + return *this; } - /*! * \brief Operator * - * \param otherMatrix + * \param other * \return */ - CMatrix3x1 operator *(const CMatrix3x1 &otherMatrix) const - { - CMatrix3x1 m; - m.m_matrix = this->m_matrix * otherMatrix.m_matrix; - return m; - } - - /*! - * \brief Operator * - * \param otherMatrix - * \return - */ - CMatrix3x3 operator *(const CMatrix3x3 &otherMatrix) const + CMatrix3x3 operator *(const CMatrix3x3 &other) const { CMatrix3x3 m(*this); - m *= otherMatrix; + m *= other; return m; } /*! - * \brief Multiply vector with this 3x3 matrix + * \brief Operator * + * \param other + * \return + */ + CMatrix3x1 operator *(const CMatrix3x1 &other) const + { + CMatrix3x1 m; + m.m_matrix = this->m_matrix * other.m_matrix; + return m; + } + + /*! + * \brief Multiply this matrix with vector * \param vector * \return */ CVector3D operator *(const CVector3D &vector) const { - CVector3D v(vector); - v.matrixMultiplication(*this); - return v; + return ((*this) * CMatrix3x1(vector.toMatrix3x1())).toVector3D(); + } + + /*! + * \brief Multiply with factor + * \param factor + * \return + */ + CMatrix3x3 &operator *=(double factor) + { + this->CMatrixBase::operator *=(factor); + return *this; } /*! @@ -136,17 +144,6 @@ public: return m; } - /*! - * \brief Multiply with factor - * \param factor - * \return - */ - CMatrix3x3 &operator *=(double factor) - { - CMatrixBase::operator *=(factor); - return (*this); - } - /*! * \brief Transposed matrix * \return @@ -171,11 +168,11 @@ public: * \return */ CMatrix1x3 getRow(int row) const; - }; } // namespace - } // namespace +Q_DECLARE_METATYPE(BlackMisc::Math::CMatrix3x3) + #endif // guard diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index 07dfc60b2..d0a7b01b8 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -5,6 +5,7 @@ #include "blackmisc/mathmatrix3x3.h" #include "blackmisc/mathmatrix3x1.h" +#include namespace BlackMisc { @@ -34,26 +35,11 @@ template void CMatrixBase void CMatrixBase::checkRange(size_t row, size_t column) const { - // no >=0 comparison since unsinged comparison always >=0 bool valid = (row < Rows && column < Columns); Q_ASSERT_X(valid, "getElement()", "Row or column invalid"); if (!valid) throw std::range_error("Row or column invalid"); } -/* - * All values to random value - */ -template void CMatrixBase::setRandom() -{ - for (int r = 0; r < Rows; r++) - { - for (int c = 0; c < Columns; c++) - { - this->m_matrix(r, c) = (qrand() % 101); // 0...100 - } - } -} - /* * All values zero? */ @@ -69,20 +55,51 @@ template bool CMatrixBase bool CMatrixBase::allValuesEqual() const +template void CMatrixBase::setCellIndex() { - double v = this->getElement(0, 0); for (int r = 0; r < Rows; r++) { for (int c = 0; c < Columns; c++) { - if (this->m_matrix(r, c) != v) return false; + this->m_matrix(r, c) = r + 0.1 * c; + } + } +} + +/* + * To list + */ +template QList CMatrixBase::toList() const +{ + QList list; + for (int r = 0; r < Rows; r++) + { + for (int c = 0; c < Columns; c++) + { + list.append(this->m_matrix(r, c)); + } + } + return list; +} + +/* + * From list + */ +template void CMatrixBase::fromList(const QList &list) +{ + Q_ASSERT_X(Rows * Columns == list.count(), "fromList()", "Mismatch of elements in list"); + int ct = 0; + for (int r = 0; r < Rows; r++) + { + for (int c = 0; c < Columns; c++) + { + this->m_matrix(r, c) = list.at(ct++); } } - return true; } /* @@ -102,7 +119,7 @@ template void CMatrixBase QString CMatrixBase::stringForConverter() const +template QString CMatrixBase::convertToQString(bool /* i18n */) const { QString s = "{"; for (int r = 0; r < Rows; r++) @@ -120,6 +137,15 @@ template QString CMatrixBase void CMatrixBase::registerMetadata() +{ + qRegisterMetaType(typeid(ImplMatrix).name()); + qDBusRegisterMetaType(); +} + // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CMatrixBase; @@ -127,8 +153,4 @@ template class CMatrixBase; template class CMatrixBase; } // namespace - } // namespace - -#include "mathmatrixbase.h" - diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index bfd2d8c81..48a9e310b 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -6,9 +6,10 @@ #ifndef BLACKMISC_MATHMATRIXBASE_H #define BLACKMISC_MATHMATRIXBASE_H -#include "blackmisc/basestreamstringifier.h" +#include "blackmisc/streamable.h" #include "blackmisc/mathvector3dbase.h" #include +#include namespace BlackMisc { @@ -18,7 +19,7 @@ namespace Math /*! * \brief Base functionality of a matrix */ -template class CMatrixBase : public BlackMisc::CBaseStreamStringifier +template class CMatrixBase : public BlackMisc::CStreamable { private: /*! @@ -45,9 +46,40 @@ protected: /*! * \brief Conversion to string + * \param i18n * \return */ - QString stringForConverter() const; + QString convertToQString(bool i18n = false) const; + + /*! + * \brief Stream to DBus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const + { + const QList l = this->toList(); + + // there is an issue with the signature of QList, so I use + // individual values + foreach(double v, l) { + argument << v; + } + } + + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QList list; + double v; + while(!argument.atEnd()) { + argument >> v; + list.append(v); + } + this->fromList(list); + } public: /*! @@ -57,9 +89,9 @@ public: /*! * \brief Copy constructor - * \param otherMatrix + * \param other */ - CMatrixBase(const CMatrixBase &otherMatrix) : m_matrix(otherMatrix.m_matrix) {} + CMatrixBase(const CMatrixBase &other) : m_matrix(other.m_matrix) {} /*! * \brief Fill with value @@ -76,37 +108,36 @@ public: virtual ~CMatrixBase() {} /*! - * \brief Equal operator == - * \param otherMatrix + * \brief List of values * \return */ - bool operator ==(const ImplMatrix &otherMatrix) const + QList toList() const; + + /*! + * \brief List of values + * \return + */ + void fromList(const QList &list); + + /*! + * \brief Equal operator == + * \param other + * \return + */ + bool operator ==(const ImplMatrix &other) const { - if (this == &otherMatrix) return true; - return this->m_matrix == otherMatrix.m_matrix; + if (this == &other) return true; + return this->m_matrix == other.m_matrix; } /*! * \brief Unequal operator != - * \param otherMatrix + * \param other * \return */ - bool operator !=(const ImplMatrix &otherMatrix) const + bool operator !=(const ImplMatrix &other) const { - if (this == &otherMatrix) return false; - return !((*this) == otherMatrix); - } - - /*! - * \brief Assigment operator = - * \param otherMatrix - * \return - */ - CMatrixBase &operator =(const CMatrixBase &otherMatrix) - { - if (this == &otherMatrix) return *this; // Same object? - this->m_matrix = otherMatrix.m_matrix; - return (*this); + return !((*this) == other); } /*! @@ -117,7 +148,7 @@ public: CMatrixBase &operator *=(double factor) { this->m_matrix *= factor; - return (*this); + return *this; } /*! @@ -133,23 +164,16 @@ public: } /*! - * \brief Operator to support commutative multiplication + * \brief Operator to support commutative scalar multiplication * \param factor - * \param otherMatrix + * \param other * \return */ - friend ImplMatrix operator *(double factor, const ImplMatrix &otherMatrix) + friend ImplMatrix operator *(double factor, const ImplMatrix &other) { - return otherMatrix * factor; + return other * factor; } - /*! - * \brief Multiply with 3D vector operator * - * \param matrix - * \return - */ - template ImplVector operator*(const ImplVector matrix) const; - /*! * \brief Operator /= * \param factor @@ -158,7 +182,7 @@ public: CMatrixBase &operator /=(double factor) { this->m_matrix /= factor; - return (*this); + return *this; } /*! @@ -175,47 +199,47 @@ public: /*! * \brief Operator += - * \param otherMatrix + * \param other * \return */ - CMatrixBase &operator +=(const CMatrixBase &otherMatrix) + CMatrixBase &operator +=(const CMatrixBase &other) { - this->m_matrix += otherMatrix.m_matrix; - return (*this); + this->m_matrix += other.m_matrix; + return *this; } /*! * \brief Operator + - * \param otherMatrix + * \param other * \return */ - ImplMatrix operator +(const ImplMatrix &otherMatrix) const + ImplMatrix operator +(const ImplMatrix &other) const { ImplMatrix m = *derived(); - m += otherMatrix; + m += other; return m; } /*! * \brief Operator -= - * \param otherMatrix + * \param other * \return */ - CMatrixBase &operator -=(const CMatrixBase &otherMatrix) + CMatrixBase &operator -=(const CMatrixBase &other) { - this->m_matrix -= otherMatrix.m_matrix; - return (*this); + this->m_matrix -= other.m_matrix; + return *this; } /*! * \brief Operator - - * \param otherMatrix + * \param other * \return */ - ImplMatrix operator -(const ImplMatrix &otherMatrix) const + ImplMatrix operator -(const ImplMatrix &other) const { ImplMatrix m = *derived(); - m -= otherMatrix; + m -= other; return m; } @@ -248,11 +272,6 @@ public: this->m_matrix.setToIdentity(); } - /*! - * \brief Fills the matrix with random elements - */ - void setRandom(); - /*! * \brief All values to zero */ @@ -264,6 +283,11 @@ public: */ bool isZero() const; + /*! + * \brief Each cell gets a unique index (used primarily for testing) + */ + void setCellIndex(); + /*! * \brief Is identity matrix? Epsilon considered. * \return @@ -276,13 +300,7 @@ public: } /*! - * \brief All values equal, if so matirx is not invertible - * \return - */ - bool allValuesEqual() const; - - /*! - * \brief Set a dedicated value + * \brief Set all elements the same * \param value */ void fill(double value) { this->m_matrix.fill(value); } @@ -342,6 +360,11 @@ public: return this->getElement(row, column); } + /*! + * \brief Register metadata + */ + static void registerMetadata(); + private: /*! * \brief Check range of row / column @@ -350,11 +373,9 @@ private: * \throws std::range_error if index out of bounds */ void checkRange(size_t row, size_t column) const; - }; } // namespace - } // namespace #endif // guard diff --git a/src/blackmisc/mathvector3d.h b/src/blackmisc/mathvector3d.h index 116c7f806..dd8520bd0 100644 --- a/src/blackmisc/mathvector3d.h +++ b/src/blackmisc/mathvector3d.h @@ -35,9 +35,9 @@ public: /*! * \brief Copy constructor - * \param otherVector + * \param other */ - CVector3D(const CVector3D &otherVector) : CVector3DBase(otherVector) {} + CVector3D(const CVector3D &other) : CVector3DBase(other) {} /*! * \brief i @@ -97,4 +97,7 @@ public: } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::Math::CVector3D) + #endif // guard diff --git a/src/blackmisc/mathvector3dbase.cpp b/src/blackmisc/mathvector3dbase.cpp index 7d8c83bc0..6484e6ae9 100644 --- a/src/blackmisc/mathvector3dbase.cpp +++ b/src/blackmisc/mathvector3dbase.cpp @@ -16,12 +16,12 @@ namespace Math /* * Convert to string */ -template QString CVector3DBase::stringForConverter() const +template QString CVector3DBase::convertToQString(bool /* i18n */) const { QString s = ("{%1, %2, %3}"); s = s.arg(QString::number(this->m_i, 'f')). - arg(QString::number(this->m_j, 'f')). - arg(QString::number(this->m_k, 'f')); + arg(QString::number(this->m_j, 'f')). + arg(QString::number(this->m_k, 'f')); return s; } @@ -43,29 +43,31 @@ template void CVector3DBase::fill(double value) this->m_k = value; } +/* + * Element (return by reference) + */ +template double &CVector3DBase::getElement(size_t row) +{ + switch (row) + { + case 0: + return this->m_i; + case 1: + return this->m_j; + case 2: + return this->m_k; + default: + Q_ASSERT_X(true, "getElement", "Detected invalid index in 3D vector"); + throw std::range_error("Detected invalid index in 3D vector"); + } +} + /* * Element */ template double CVector3DBase::getElement(size_t row) const { - double d; - switch (row) - { - case 0: - d = this->m_i; - break; - case 1: - d = this->m_j; - break; - case 2: - d = this->m_k; - break; - default: - Q_ASSERT_X(true, "getElement", "Detected invalid index in 3D vector"); - throw std::range_error("Detected invalid index in 3D vector"); - break; - } - return d; + return const_cast*>(this)->getElement(row); } /* @@ -94,35 +96,24 @@ template void CVector3DBase::setElement(size_t ro /* * Cross product */ -template ImplVector CVector3DBase::crossProduct(const ImplVector &otherVector) const +template ImplVector CVector3DBase::crossProduct(const ImplVector &other) const { - ImplVector v(otherVector); - v.m_i = this->m_j * otherVector.m_k - this->m_k * otherVector.m_j; - v.m_j = this->m_k * otherVector.m_i - this->m_i * otherVector.m_k; - v.m_k = this->m_i * otherVector.m_j - this->m_j * otherVector.m_i; + ImplVector v(other); + v.m_i = this->m_j * other.m_k - this->m_k * other.m_j; + v.m_j = this->m_k * other.m_i - this->m_i * other.m_k; + v.m_k = this->m_i * other.m_j - this->m_j * other.m_i; return v; } /* * Cross product */ -template double CVector3DBase::dotProduct(const ImplVector &otherVector) const +template double CVector3DBase::dotProduct(const ImplVector &other) const { - return this->m_i * otherVector.m_i + this->m_j * otherVector.m_j + this->m_k * otherVector.m_k; + return this->m_i * other.m_i + this->m_j * other.m_j + this->m_k * other.m_k; } -/* - * Multiply with matrix - */ -template void CVector3DBase::matrixMultiplication(const CMatrix3x3 &matrix) -{ - CMatrix3x1 m = matrix * (this->toMatrix3x1()); - this->m_i = m(0, 0); - this->m_j = m(1, 0); - this->m_k = m(2, 0); -} - /* * Convert to matrix */ @@ -131,6 +122,38 @@ template CMatrix3x1 CVector3DBase::toMatrix3x1() return CMatrix3x1(this->m_i, this->m_j, this->m_k); } + +/*! + * \brief Stream to DBus + * \param argument + */ +template void CVector3DBase::marshallToDbus(QDBusArgument &argument) const +{ + argument << this->m_i; + argument << this->m_j; + argument << this->m_k; +} + +/*! + * \brief Stream from DBus + * \param argument + */ +template void CVector3DBase::unmarshallFromDbus(const QDBusArgument &argument) +{ + argument >> this->m_i; + argument >> this->m_j; + argument >> this->m_k; +} + +/* + * Register metadata + */ +template void CVector3DBase::registerMetadata() +{ + qRegisterMetaType(typeid(ImplVector).name()); + qDBusRegisterMetaType(); +} + // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CVector3DBase; @@ -138,5 +161,4 @@ template class CVector3DBase; template class CVector3DBase; } // namespace - } // namespace diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index 48ea18b38..bd0bec9d7 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -6,7 +6,7 @@ #ifndef BLACKMISC_MATHVECTOR3DBASE_H #define BLACKMISC_MATHVECTOR3DBASE_H -#include "blackmisc/basestreamstringifier.h" +#include "blackmisc/streamable.h" #include "blackmisc/mathematics.h" namespace BlackMisc @@ -14,16 +14,13 @@ namespace BlackMisc namespace Math { -class CMatrix3x3; // forward declaration -class CMatrix3x1; // forward declaration - +class CMatrix3x1; /*! * \brief 3D vector base (x, y, z) */ -template class CVector3DBase : public CBaseStreamStringifier +template class CVector3DBase : public CStreamable { - private: /*! * \brief Easy access to derived class (CRTP template parameter) @@ -44,7 +41,6 @@ private: } protected: - // using own value since Qt QVector3D stores internally as float double m_i; //!< Vector data i double m_j; //!< Vector data j @@ -71,18 +67,37 @@ protected: /*! * \brief Copy constructor - * \param otherVector + * \param other */ - CVector3DBase(const CVector3DBase &otherVector) : m_i(otherVector.m_i), m_j(otherVector.m_j), m_k(otherVector.m_k) {} + CVector3DBase(const CVector3DBase &other) : m_i(other.m_i), m_j(other.m_j), m_k(other.m_k) {} + + /*! + * \brief Get element + * \param row + * \return Mutable reference + */ + double &getElement(size_t row); /*! * \brief String for converter + * \param i18n * \return */ - virtual QString stringForConverter() const; + virtual QString convertToQString(bool i18n = false) const; + + /*! + * \brief Unmarshall from Dbus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument); + + /*! + * \brief Marshall to Dbus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const; public: - // getter and setters are implemented in the derived classes // as they have different names (x, i, north) @@ -97,7 +112,7 @@ public: void setZero(); /*! - * \brief Set zeros + * \brief Is zero */ bool isZero() const { @@ -111,13 +126,14 @@ public: bool isZeroEpsilon() const { ImplVector v; - v += (*this); + v += *this; v.round(); return v.isZero(); } /*! - * \brief Set zeros + * \brief Set all elements the same + * \param value */ void fill(double value); @@ -142,124 +158,83 @@ public: */ double operator[](size_t row) const { return this->getElement(row); } - /*! - * \brief Get row element by () + * \brief Operator [] * \param row - * \return + * \return Mutable reference */ - double operator()(size_t row) const { return this->getElement(row); } + double &operator[](size_t row) { return this->getElement(row); } /*! * \brief Equal operator == - * \param otherVector + * \param other * \return */ - bool operator ==(const CVector3DBase &otherVector) const + bool operator ==(const CVector3DBase &other) const { - if (this == &otherVector) return true; - return this->m_i == otherVector.m_i && - this->m_j == otherVector.m_j && - this->m_k == otherVector.m_k; + if (this == &other) return true; + return this->m_i == other.m_i && + this->m_j == other.m_j && + this->m_k == other.m_k; } /*! * \brief Unequal operator != - * \param otherVector + * \param other * \return */ - bool operator !=(const CVector3DBase &otherVector) const + bool operator !=(const CVector3DBase &other) const { - if (this == &otherVector) return false; - return !((*this) == otherVector); - } - - /*! - * \brief Assigment operator = - * \param otherVector - * \return - */ - CVector3DBase &operator =(const CVector3DBase &otherVector) - { - if (this == &otherVector) return *this; // Same object? - this->m_i = otherVector.m_i; - this->m_j = otherVector.m_j; - this->m_k = otherVector.m_k; - return (*this); + return !((*this) == other); } /*! * \brief Operator += - * \param otherVector + * \param other * \return */ - CVector3DBase &operator +=(const CVector3DBase &otherVector) + CVector3DBase &operator +=(const CVector3DBase &other) { - this->m_i += otherVector.m_i; - this->m_j += otherVector.m_j; - this->m_k += otherVector.m_k; - return (*this); + this->m_i += other.m_i; + this->m_j += other.m_j; + this->m_k += other.m_k; + return *this; } /*! * \brief Operator + - * \param otherVector + * \param other * \return */ - ImplVector operator +(const ImplVector &otherVector) const + ImplVector operator +(const ImplVector &other) const { ImplVector v = *derived(); - v += otherVector; + v += other; return v; } /*! * \brief Operator -= - * \param otherVector + * \param other * \return */ - CVector3DBase &operator -=(const CVector3DBase &otherVector) + CVector3DBase &operator -=(const CVector3DBase &other) { - this->m_i -= otherVector.m_i; - this->m_j -= otherVector.m_j; - this->m_k -= otherVector.m_k; - return (*this); + this->m_i -= other.m_i; + this->m_j -= other.m_j; + this->m_k -= other.m_k; + return *this; } /*! * \brief Operator - - * \param otherVector + * \param other * \return */ - ImplVector operator -(const ImplVector &otherVector) const + ImplVector operator -(const ImplVector &other) const { ImplVector v = *derived(); - v -= otherVector; - return v; - } - - /*! - * \brief Operator *=, just x*x, y*y, z*z neither vector nor dot product (like a matrix produc) - * \param otherVector - * \return - */ - CVector3DBase &operator *=(const CVector3DBase &otherVector) - { - this->m_i *= otherVector.m_i; - this->m_j *= otherVector.m_j; - this->m_k *= otherVector.m_k; - return (*this); - } - - /*! - * \brief Operator, just x*x, y*y, z*z neither vector nor dot product, (like a matrix produc) - * \param otherVector - * \return - */ - ImplVector operator *(const ImplVector &otherVector) const - { - ImplVector v = *derived(); - v *= otherVector; + v -= other; return v; } @@ -273,7 +248,7 @@ public: this->m_i *= factor; this->m_j *= factor; this->m_k *= factor; - return (*this); + return *this; } /*! @@ -294,9 +269,9 @@ public: * \param otherVector * \return */ - friend ImplVector operator *(double factor, const ImplVector &otherVector) + friend ImplVector operator *(double factor, const ImplVector &other) { - return otherVector * factor; + return other * factor; } /*! @@ -309,7 +284,7 @@ public: this->m_i /= divisor; this->m_j /= divisor; this->m_k /= divisor; - return (*this); + return *this; } /*! @@ -324,51 +299,19 @@ public: return v; } - /*! - * \brief Operator /=, just x/x, y/y, z/z - * \param otherVector - * \return - */ - CVector3DBase &operator /=(const CVector3DBase &otherVector) - { - this->m_i /= otherVector.m_i; - this->m_j /= otherVector.m_j; - this->m_k /= otherVector.m_k; - return (*this); - } - - /*! - * \brief Operator, just x/x, y/y, z/z - * \param otherVector - * \return - */ - ImplVector operator /(const ImplVector &otherVector) const - { - ImplVector v = *derived(); - v /= otherVector; - return v; - } - /*! * \brief Dot product - * \param otherVector + * \param other * \return */ - double dotProduct(const ImplVector &otherVector) const; + double dotProduct(const ImplVector &other) const; /*! * \brief Cross product - * \param otherVector + * \param other * \return */ - ImplVector crossProduct(const ImplVector &otherVector) const; - - /*! - * \brief Matrix * this vector - * \param matrix - * \return - */ - void matrixMultiplication(const CMatrix3x3 &matrix); + ImplVector crossProduct(const ImplVector &other) const; /*! * \brief Reciprocal value @@ -410,16 +353,20 @@ public: * \brief Rounded vector * \return */ - ImplVector roundedVector() const + ImplVector rounded() const { ImplVector v = *derived(); v.round(); return v; } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); }; } // namespace - } // namespace #endif // guard diff --git a/src/blackmisc/pqacceleration.h b/src/blackmisc/pqacceleration.h index 70962cd79..6d7c7718e 100644 --- a/src/blackmisc/pqacceleration.h +++ b/src/blackmisc/pqacceleration.h @@ -21,34 +21,30 @@ public: /*! * \brief Default constructor */ - CAcceleration() : CPhysicalQuantity(0, CAccelerationUnit::m_s2(), CAccelerationUnit::m_s2()) {} - - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CAcceleration(qint32 value, const CAccelerationUnit &unit) : CPhysicalQuantity(value, unit, CAccelerationUnit::m_s2()) {} + CAcceleration() : CPhysicalQuantity(0, CAccelerationUnit::defaultUnit()) {} /*! * \brief Init by double value * \param value * \param unit */ - CAcceleration(double value, const CAccelerationUnit &unit) : CPhysicalQuantity(value, unit, CAccelerationUnit::m_s2()) {} + CAcceleration(double value, const CAccelerationUnit &unit) : CPhysicalQuantity(value, unit) {} /*! - * \brief Copy constructor - * \param acceleration + * \brief Copy constructor by base type + * \param base */ - CAcceleration(const CPhysicalQuantity &acceleration) : CPhysicalQuantity(acceleration) {} + CAcceleration(const CPhysicalQuantity &base) : CPhysicalQuantity(base) {} /*! * \brief Virtual destructor */ virtual ~CAcceleration() {} }; + } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAcceleration) + #endif // guard diff --git a/src/blackmisc/pqallquantities.h b/src/blackmisc/pqallquantities.h index 0381c0b60..1a402e504 100644 --- a/src/blackmisc/pqallquantities.h +++ b/src/blackmisc/pqallquantities.h @@ -7,7 +7,7 @@ #define BLACKMISC_PQUNITSALL_H // All units / quantities, required for the instantiations of the template -// especially as CRTP is used. +// especially as CRTP (Curiously recurring template pattern) is used. // http://www.parashift.com/c++-faq-lite/separate-template-fn-defn-from-decl.html // http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern @@ -20,5 +20,6 @@ #include "blackmisc/pqangle.h" #include "blackmisc/pqtime.h" #include "blackmisc/pqacceleration.h" +#include "blackmisc/pqunits.h" #endif // guard diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index 9ba211680..c8209d8cd 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -12,6 +12,7 @@ namespace BlackMisc { namespace PhysicalQuantities { + /*! * \brief Physical unit angle (radians, degrees) */ @@ -21,26 +22,37 @@ public: /*! * \brief Default constructor */ - CAngle() : CPhysicalQuantity(0, CAngleUnit::rad(), CAngleUnit::rad()) {} - - /*! - * \brief Copy constructor - */ - CAngle(const CAngle &angle) : CPhysicalQuantity(angle) {} - - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CAngle(qint32 value, const CAngleUnit &unit): CPhysicalQuantity(value, unit, CAngleUnit::rad()) {} + CAngle() : CPhysicalQuantity(0, CAngleUnit::defaultUnit()) {} /*! * \brief Init by double value * \param value * \param unit */ - CAngle(double value, const CAngleUnit &unit): CPhysicalQuantity(value, unit, CAngleUnit::rad()) {} + CAngle(double value, const CAngleUnit &unit): CPhysicalQuantity(value, unit) {} + + /*! + * \brief Init as sexagesimal degrees, minutes, seconds + * The sign of all parameters must be the same, either all positive or all negative. + * \param degrees + * \param minutes + * \param seconds + */ + CAngle(int degrees, int minutes, double seconds) : + CPhysicalQuantity( + degrees + minutes / 100.0 + seconds / 10000.0, + CAngleUnit::sexagesimalDeg()) {} + + /*! + * \brief Init as sexagesimal degrees, minutes + * The sign of both parameters must be the same, either both positive or both negative. + * \param degrees + * \param minutes + */ + CAngle(int degrees, double minutes) : + CPhysicalQuantity( + degrees + minutes / 100.0, + CAngleUnit::sexagesimalDegMin()) {} /*! * \brief Virtual destructor @@ -53,7 +65,7 @@ public: */ double piFactor() const { - return BlackMisc::Math::CMath::round(this->convertedSiValueToDouble() / BlackMisc::Math::CMath::PI() , 6); + return BlackMisc::Math::CMath::round(this->value(CAngleUnit::rad()) / BlackMisc::Math::CMath::PI() , 6); } /*! @@ -69,4 +81,6 @@ public: } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAngle) + #endif // BLACKMISC_PQANGLE_H diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index 3e612bd3e..f7e9f47f0 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -14,71 +14,24 @@ namespace PhysicalQuantities { // ----------------------------------------------------------------------- -// --- Mulitplier -------------------------------------------------------- +// --- Prefix ------------------------------------------------------------ // ----------------------------------------------------------------------- -/* - * Constructor - */ -CMeasurementPrefix::CMeasurementPrefix(const QString &name, const QString &unitName, double factor): - m_name(name), m_prefix(unitName), m_factor(factor) -{ - // void -} - -/* - * Constructor - */ -CMeasurementPrefix::CMeasurementPrefix(const CMeasurementPrefix &otherMultiplier) : - m_name(otherMultiplier.m_name), m_prefix(otherMultiplier.m_prefix), m_factor(otherMultiplier.m_factor) -{ - // void -} - -/* - * Assignment operator - */ -CMeasurementPrefix &CMeasurementPrefix::operator=(const CMeasurementPrefix &otherMultiplier) -{ - - if (this == &otherMultiplier) return *this; // Same object? Yes, so skip assignment, and just return *this - this->m_name = otherMultiplier.m_name; - this->m_prefix = otherMultiplier.m_prefix; - this->m_factor = otherMultiplier.m_factor; - return *this; -} - /* * Equal? */ -bool CMeasurementPrefix::operator ==(const CMeasurementPrefix &otherMultiplier) const +bool CMeasurementPrefix::operator ==(const CMeasurementPrefix &other) const { - if (this == &otherMultiplier) return true; - return this->m_factor == otherMultiplier.m_factor && this->m_name == otherMultiplier.m_name; + if (this == &other) return true; + return this->m_factor == other.m_factor && this->m_name == other.m_name; } /* * Not equal */ -bool CMeasurementPrefix::operator !=(const CMeasurementPrefix &otherMultiplier) const +bool CMeasurementPrefix::operator !=(const CMeasurementPrefix &other) const { - return !(*this == otherMultiplier); -} - -/* - * Greater? - */ -bool CMeasurementPrefix::operator >(const CMeasurementPrefix &otherMultiplier) const -{ - return this->m_factor > otherMultiplier.m_factor; -} - -/* - * Less? - */ -bool CMeasurementPrefix::operator <(const CMeasurementPrefix &otherMultiplier) const -{ - return this->m_factor < otherMultiplier.m_factor; + return !(*this == other); } // ----------------------------------------------------------------------- @@ -88,89 +41,84 @@ bool CMeasurementPrefix::operator <(const CMeasurementPrefix &otherMultiplier) c /* * Constructor */ -CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &unitName, const QString &type, bool isSIUnit, bool isSIBaseUnit, - double conversionFactorToSI, const CMeasurementPrefix &multiplier, qint32 displayDigits, double epsilon, - UnitConverter toSiConverter, UnitConverter fromSiConverter): - m_name(name), m_unitName(unitName), m_type(type), m_isSiUnit(isSIUnit), m_isSiBaseUnit(isSIBaseUnit), - m_conversionFactorToSIConversionUnit(conversionFactorToSI), - m_epsilon(epsilon), m_displayDigits(displayDigits), m_multiplier(multiplier), m_fromSiConverter(fromSiConverter), m_toSiConverter(toSiConverter) +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, int displayDigits, double epsilon) : + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(new LinearConverter(factor)) +{ +} + +/* + * Constructor + */ +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, double factor, double offset, int displayDigits, double epsilon) : + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(new AffineConverter(factor, offset)) +{ +} + +/* + * Constructor + */ +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits, double epsilon) : + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(converter) +{ +} + +/* + * Constructor + */ +CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &symbol, const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits, double epsilon) : + m_name(name), m_symbol(symbol), m_epsilon(epsilon), m_displayDigits(displayDigits), m_converter(base.m_converter->clone(prefix)) { - // void } /* * Copy constructor */ -CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &otherUnit): - m_name(otherUnit.m_name), m_unitName(otherUnit.m_unitName), m_type(otherUnit.m_type), m_isSiUnit(otherUnit.m_isSiUnit), - m_isSiBaseUnit(otherUnit.m_isSiBaseUnit), m_conversionFactorToSIConversionUnit(otherUnit.m_conversionFactorToSIConversionUnit), - m_epsilon(otherUnit.m_epsilon), m_displayDigits(otherUnit.m_displayDigits), m_multiplier(otherUnit.m_multiplier), m_fromSiConverter(otherUnit.m_fromSiConverter), m_toSiConverter(otherUnit.m_toSiConverter) +CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &other) : + m_name(other.m_name), m_symbol(other.m_symbol), m_epsilon(other.m_epsilon), m_displayDigits(other.m_displayDigits), m_converter(other.m_converter) { - // void -} - -/* - * Assigment operator - */ -CMeasurementUnit &CMeasurementUnit::operator =(const CMeasurementUnit &otherUnit) -{ - if (this == &otherUnit) return *this; // Same object? Yes, so skip assignment, and just return *this - this->m_name = otherUnit.m_name; - this->m_unitName = otherUnit.m_unitName; - this->m_type = otherUnit.m_type; - this->m_isSiUnit = otherUnit.m_isSiUnit; - this->m_isSiBaseUnit = otherUnit.m_isSiBaseUnit; - this->m_conversionFactorToSIConversionUnit = otherUnit.m_conversionFactorToSIConversionUnit; - this->m_multiplier = otherUnit.m_multiplier; - this->m_displayDigits = otherUnit.m_displayDigits; - this->m_epsilon = otherUnit.m_epsilon; - this->m_fromSiConverter = otherUnit.m_fromSiConverter; - this->m_toSiConverter = otherUnit.m_toSiConverter; - return *this; } /* * Equal operator */ -bool CMeasurementUnit::operator ==(const CMeasurementUnit &otherUnit) const +bool CMeasurementUnit::operator ==(const CMeasurementUnit &other) const { - if (this == &otherUnit) return true; - if (this->m_type != otherUnit.m_type) return false; - return this->m_multiplier == otherUnit.m_multiplier && this->m_name == otherUnit.m_name - && this->m_isSiUnit == otherUnit.m_isSiUnit; + if (this == &other) return true; + return this->m_name == other.m_name; } /* * Unequal operator */ -bool CMeasurementUnit::operator !=(const CMeasurementUnit &otherUnit) const +bool CMeasurementUnit::operator !=(const CMeasurementUnit &other) const { - return !(otherUnit == *this); + return !(other == *this); } /* - * Conversion factor from unit x to y + * Conversion */ -double CMeasurementUnit::conversionToUnit(double value, const CMeasurementUnit &to) const +double CMeasurementUnit::convertFrom(double value, const CMeasurementUnit &unit) const { - if (to == (*this)) return value; - double siValue = this->convertToSiConversionUnit(value); - return to.convertFromSiConversionUnit(siValue); + Q_ASSERT(this->m_converter); + Q_ASSERT(unit.m_converter); + if (this->m_converter == unit.m_converter) return value; + return this->m_converter->fromDefault(unit.m_converter->toDefault(value)); } /* * Value to QString with unit, e.g. "5.00m" * @return */ -QString CMeasurementUnit::valueRoundedWithUnit(double value, int digits) const +QString CMeasurementUnit::makeRoundedQStringWithUnit(double value, int digits, bool i18n) const { - return this->toQStringRounded(value, digits).append(this->getUnitName()); + return this->makeRoundedQString(value, digits).append(this->getSymbol(i18n)); } /* * Value rounded */ -double CMeasurementUnit::valueRounded(double value, int digits) const +double CMeasurementUnit::roundValue(double value, int digits) const { if (digits < 0) digits = this->m_displayDigits; return CMath::round(value, digits); @@ -179,7 +127,7 @@ double CMeasurementUnit::valueRounded(double value, int digits) const /* * Rounded to QString */ -QString CMeasurementUnit::toQStringRounded(double value, int digits) const +QString CMeasurementUnit::makeRoundedQString(double value, int digits, bool /* i18n */) const { if (digits < 0) digits = this->m_displayDigits; double v = CMath::round(value, digits); @@ -187,17 +135,5 @@ QString CMeasurementUnit::toQStringRounded(double value, int digits) const return s; } -/* - * Epsilon rounding - */ -double CMeasurementUnit::epsilonUpRounding(double value) const -{ - // Rounds a little up in order to avoid fractions - double eps = value > 0 ? this->m_epsilon : -1.0 * this->m_epsilon; - double v = floor((value + eps) / this->m_epsilon); - v *= this->m_epsilon; - return v; -} - } // namespace } // namespace diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index ae37c6a8f..c66127013 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -6,11 +6,16 @@ #ifndef BLACKMISC_PQBASE_H #define BLACKMISC_PQBASE_H -#include "blackmisc/basestreamstringifier.h" +#include "blackmisc/streamable.h" #include "blackmisc/debug.h" +#include "blackmisc/mathematics.h" +#include +#include #include #include #include +#include +#include namespace BlackMisc { @@ -20,15 +25,15 @@ namespace PhysicalQuantities /*! * \brief Typical prefixes (multipliers) such as kilo, mega, hecto. * See here for an overview. - * Use the static values such CMeasurementMultiplier::k() as to specify values. - * \author KWB + * Use the static values such as CMeasurementPrefix::k() to specify values. */ -class CMeasurementPrefix : public CBaseStreamStringifier +class CMeasurementPrefix : public CStreamable { private: QString m_name; //!< name, e.g. "kilo" - QString m_prefix; //!< prefix, e.g. "k" for kilo + QString m_symbol; //!< prefix, e.g. "k" for kilo double m_factor; //!< factor, e.g. 1000 for kilo 1/100 for centi + /*! * Constructor by parameters * \brief CMeasurementMultiplier @@ -36,63 +41,54 @@ private: * \param prefixName * \param factor */ - CMeasurementPrefix(const QString &name, const QString &prefixName, double factor); + CMeasurementPrefix(const QString &name, const QString &symbol, double factor) : + m_name(name), m_symbol(symbol), m_factor(factor) {} protected: /*! - * \brief Name as stringification + * \brief Name as string + * \param i18n * \return */ - virtual QString stringForConverter() const + virtual QString convertToQString(bool /* i18n */ = false) const { return this->m_name; } + /*! + * \brief Stream to DBus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const + { + argument << this->m_name; + } + + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString name; + argument >> name; + (*this) = CMeasurementPrefix::fromPrefixName(name); + } + public: - /*! - * \brief Copy constructor - * \param otherMultiplier - */ - CMeasurementPrefix(const CMeasurementPrefix &otherMultiplier); - - /*! - * \brief Assigmnet operator = - * \param otherMultiplier - * \return - */ - CMeasurementPrefix &operator =(const CMeasurementPrefix &otherMultiplier); - /*! * \brief Equal operator == - * \param otherMultiplier + * \param other * \return */ - bool operator == (const CMeasurementPrefix &otherMultiplier) const; + bool operator == (const CMeasurementPrefix &other) const; /*! * \brief Unequal operator != - * \param otherMultiplier + * \param other * \return */ - bool operator != (const CMeasurementPrefix &otherMultiplier) const; - - /*! - * \brief Greater operator > - * \param otherMultiplier - * \return - */ - bool operator > (const CMeasurementPrefix &otherMultiplier) const; - - /*! - * \brief Less operator < - * \param otherMultiplier - * \return - */ - bool operator < (const CMeasurementPrefix &otherMultiplier) const; - - /*! - * \brief Cast as double - */ + bool operator != (const CMeasurementPrefix &other) const; /*! * \brief Factor, e.g.1000 for "kilo" @@ -116,26 +112,18 @@ public: * \brief Name, e.g. "kilo" * \return */ - QString getName() const + QString getName(bool i18n = false) const { - return this->m_name; + return i18n ? QCoreApplication::translate("CMeasurementPrefix", this->m_name.toStdString().c_str()) : this->m_name; } /*! * \brief Prefix, e.g. "k" for "kilo" * \return */ - QString getPrefix() const + QString getSymbol(bool i18n = false) const { - return this->m_prefix; - } - - /*! - * \brief Operator as double - */ - operator double() const - { - return this->m_factor; + return i18n ? QCoreApplication::translate("CMeasurementPrefix", this->m_symbol.toStdString().c_str()) : this->m_symbol; } // --- static units, always use these for initialization @@ -158,7 +146,7 @@ public: */ static const CMeasurementPrefix &One() { - static CMeasurementPrefix one("one", "", 1.0); + static CMeasurementPrefix one(QT_TR_NOOP("one"), "", 1.0); return one; } @@ -168,7 +156,7 @@ public: */ static const CMeasurementPrefix &M() { - static CMeasurementPrefix mega("mega", "M", 1E6); + static CMeasurementPrefix mega(QT_TR_NOOP("mega"), "M", 1E6); return mega; } @@ -178,7 +166,7 @@ public: */ static const CMeasurementPrefix &k() { - static CMeasurementPrefix kilo("kilo", "k", 1000.0); + static CMeasurementPrefix kilo(QT_TR_NOOP("kilo"), "k", 1000.0); return kilo; } @@ -188,7 +176,7 @@ public: */ static const CMeasurementPrefix &G() { - static CMeasurementPrefix giga("giga", "G", 1E9); + static CMeasurementPrefix giga(QT_TR_NOOP("giga"), "G", 1E9); return giga; } @@ -198,7 +186,7 @@ public: */ static const CMeasurementPrefix &h() { - static CMeasurementPrefix hecto("hecto", "h", 100.0); + static CMeasurementPrefix hecto(QT_TR_NOOP("hecto"), "h", 100.0); return hecto; } @@ -208,7 +196,7 @@ public: */ static const CMeasurementPrefix &c() { - static CMeasurementPrefix centi("centi", "c", 0.01); + static CMeasurementPrefix centi(QT_TR_NOOP("centi"), "c", 0.01); return centi; } @@ -218,10 +206,46 @@ public: */ static const CMeasurementPrefix &m() { - static CMeasurementPrefix milli("milli", "m", 1E-03); + static CMeasurementPrefix milli(QT_TR_NOOP("milli"), "m", 1E-03); return milli; } + /*! + * \brief All prefixes + * \return + */ + static const QList &prefixes() + { + static QList prefixes; + if (prefixes.isEmpty()) + { + prefixes.append(CMeasurementPrefix::c()); + prefixes.append(CMeasurementPrefix::G()); + prefixes.append(CMeasurementPrefix::h()); + prefixes.append(CMeasurementPrefix::k()); + prefixes.append(CMeasurementPrefix::M()); + prefixes.append(CMeasurementPrefix::m()); + prefixes.append(CMeasurementPrefix::None()); + prefixes.append(CMeasurementPrefix::One()); + } + return prefixes; + } + + /*! + * \brief Prefix from name + * \param prefixName must be valid! + * \return + */ + static const CMeasurementPrefix &fromPrefixName(const QString &prefixName) + { + const QList &prefixes = CMeasurementPrefix::prefixes(); + for (int i = 0; i < prefixes.size(); ++i) { + if (prefixes.at(i).getName() == prefixName) return (prefixes.at(i)); + } + qFatal("Illegal unit name"); + return CMeasurementPrefix::None(); // just suppress "not all control paths return a value" + } + }; // --------------------------------------------------------------------------------- @@ -231,225 +255,293 @@ public: /*! * \brief Base class for all units, such as meter, hertz. */ -class CMeasurementUnit: public CBaseStreamStringifier +class CMeasurementUnit : public CStreamable { protected: /*! - * \brief Points to an individual converter method - * Conversion as perobject, as required for CAnglewith sexagesimal conversion + * Abstract strategy pattern that encapsulates a unit conversion strategy. */ - typedef double(*UnitConverter)(const CMeasurementUnit &, double); + class Converter : public QSharedData + { + public: + /*! + * Virtual destructor. + */ + virtual ~Converter() {} + /*! + * Convert from this unit to default unit. + * \param factor + * \return + */ + virtual double toDefault(double factor) const = 0; + /*! + * Convert from default unit to this unit. + * \param factor + * \return + */ + virtual double fromDefault(double factor) const = 0; + /*! + * Make a copy of this object with a different prefix. + * \param prefix + * \return + */ + virtual Converter *clone(const CMeasurementPrefix &prefix) const = 0; + }; + + /*! + * Concrete strategy pattern for converting unit with linear conversion. + */ + class LinearConverter : public Converter + { + double m_factor; + public: + /*! + * Constructor + * \param factor + */ + LinearConverter(double factor) : m_factor(factor) {} + virtual double toDefault(double factor) const { return factor * m_factor; } + virtual double fromDefault(double factor) const { return factor / m_factor; } + virtual Converter *clone(const CMeasurementPrefix &prefix) const { auto ret = new LinearConverter(*this); ret->m_factor *= prefix.getFactor(); return ret; } + }; + + /*! + * Concrete strategy pattern for converting unit with affine conversion. + */ + class AffineConverter : public Converter + { + double m_factor; + double m_offset; + public: + /*! + * Constructor + * \param factor + * \param offset + */ + AffineConverter(double factor, double offset) : m_factor(factor), m_offset(offset) {} + virtual double toDefault(double factor) const { return (factor - m_offset) * m_factor; } + virtual double fromDefault(double factor) const { return factor / m_factor + m_offset; } + virtual Converter *clone(const CMeasurementPrefix &prefix) const { auto ret = new AffineConverter(*this); ret->m_factor *= prefix.getFactor(); return ret; } + }; + + /*! + * Concrete strategy pattern for converting unit with subdivision conversion. + */ + template + class SubdivisionConverter : public Converter + { + double m_factor; + public: + /*! + * Constructor + */ + SubdivisionConverter(double factor = 1) : m_factor(factor) {} + virtual double toDefault(double factor) const { using BlackMisc::Math::CMath; + double ret = CMath::trunc(factor); factor = CMath::fract(factor) * Den; + ret += factor / Num; + return ret * m_factor; } + virtual double fromDefault(double factor) const { using BlackMisc::Math::CMath; + factor /= m_factor; + double ret = CMath::trunc(factor); factor = CMath::fract(factor) * Num; + return ret += factor / Den; } + virtual Converter *clone(const CMeasurementPrefix &) const { qFatal("Not implemented"); return 0; } + }; + + /*! + * Concrete strategy pattern for converting unit with subdivision conversion. + */ + template + class SubdivisionConverter2 : public Converter + { + double m_factor; + public: + /*! + * Constructor + */ + SubdivisionConverter2(double factor = 1) : m_factor(factor) {} + virtual double toDefault(double factor) const { using BlackMisc::Math::CMath; + double ret = CMath::trunc(factor); factor = CMath::fract(factor) * Den1; + ret += CMath::trunc(factor) / Num1; factor = CMath::fract(factor) * Den2; + ret += factor / (Num1 * Num2); + return ret * m_factor; } + virtual double fromDefault(double factor) const { using BlackMisc::Math::CMath; + factor /= m_factor; + double ret = CMath::trunc(factor); factor = CMath::fract(factor) * Num1; + ret += CMath::trunc(factor) / Den1; factor = CMath::fract(factor) * Num2; + return ret += factor / (Den1 * Den2); } + virtual Converter *clone(const CMeasurementPrefix &) const { qFatal("Not implemented"); return 0; } + }; private: QString m_name; //!< name, e.g. "meter" - QString m_unitName; //!< unit name, e.g. "m" - QString m_type; //!< type,such as distance. Somehow redundant, but simplifies unit comparisons - bool m_isSiUnit; //!< is this a SI unit? - bool m_isSiBaseUnit; //!< SI base unit? - double m_conversionFactorToSIConversionUnit; //!< factor to convert to SI, set to 0 if not applicable (rare cases, e.g. temperature) + QString m_symbol; //!< unit name, e.g. "m" double m_epsilon; //!< values with differences below epsilon are the equal int m_displayDigits; //!< standard rounding for string conversions - CMeasurementPrefix m_multiplier; //!< multiplier (kilo, Mega) - UnitConverter m_fromSiConverter; //! allows an arbitrary conversion method as per object - UnitConverter m_toSiConverter; //! allows an arbitrary conversion method as per object + QSharedDataPointer m_converter; //!< strategy pattern allows an arbitrary conversion method as per object protected: /*! - * Constructor by parameter + * Construct a unit with linear conversion * \param name - * \param unitName - * \param type - * \param isSiUnit - * \param isSiBaseUnit - * \param conversionFactorToSI - * \param multiplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon - * \param toSiConverter - * \param fromSiConverter */ - CMeasurementUnit(const QString &name, const QString &unitName, const QString &type, bool isSiUnit, bool isSiBaseUnit, double conversionFactorToSI = 1, - const CMeasurementPrefix &multiplier = CMeasurementPrefix::None(), qint32 displayDigits = 2, - double epsilon = 1E-10, UnitConverter toSiConverter = 0, UnitConverter fromSiConverter = 0); + CMeasurementUnit(const QString &name, const QString &symbol, double factor, int displayDigits, double epsilon); + + /*! + * Construct a unit with affine conversion + * \param name + * \param symbol + * \param factor + * \param offset + * \param displayDigits + * \param epsilon + */ + CMeasurementUnit(const QString &name, const QString &symbol, double factor, double offset, int displayDigits, double epsilon); + + /*! + * Construct a unit with custom conversion + * \param name + * \param symbol + * \param converter + * \param displayDigits + * \param epsilon + */ + CMeasurementUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits, double epsilon); + + /*! + * Construct from base unit and prefix + * \param base + * \param prefix + * \param displayDigits + * \param epsilon + */ + CMeasurementUnit(const QString &name, const QString &symbol, const CMeasurementUnit &base, const CMeasurementPrefix &prefix, int displayDigits = 2, double epsilon = 1E-10); /*! * \brief Copy constructor - * \param otherUnit + * \param other */ - CMeasurementUnit(const CMeasurementUnit &otherUnit); + CMeasurementUnit(const CMeasurementUnit &other); - /*! - * \brief Assignment operator = - * \param otherUnit - * \return - */ - CMeasurementUnit &operator =(const CMeasurementUnit &otherUnit); - -protected: /*! * \brief String for streaming operators is full name * \return */ virtual QString stringForStreaming() const { - return this->m_name; + return this->getName(false); } /*! - * \brief String for converter is unit + * \brief Name as stringification + * \param i18n * \return */ - virtual QString stringForConverter() const + virtual QString convertToQString(bool i18n = false) const { - return this->m_unitName; + return this->getSymbol(i18n); } /*! - * \brief Conversion factor to SI conversion unit - * \return + * \brief Stream to DBus + * \param argument */ - double getConversionFactorToSI() const + virtual void marshallToDbus(QDBusArgument &argument) const { - return this->m_conversionFactorToSIConversionUnit; + argument << this->m_symbol; } /*! - * Given value to conversion SI conversion unit (e.g. meter, hertz). - * Standard implementaion is simply factor based. - * \param value - * \return + * \brief Stream from DBus + * \param argument */ - virtual double conversionToSiConversionUnit(double value) const + virtual void unmarshallFromDbus(const QDBusArgument &) { - return value * this->m_conversionFactorToSIConversionUnit; + // the concrete implementations will override this default + // this is required so I can also stream None + (*this) = CMeasurementUnit::None(); } /*! - * \brief Value from SI conversion unit to this unit. - * Standard implementation is simply factor based. - * \param value + * \brief Unit from symbol + * \param symbol must be a valid unit symbol (without i18n) or empty string (empty means default unit) * \return */ - virtual double conversionFromSiConversionUnit(double value) const + template static const U &unitFromSymbol(const QString &symbol) { - return value / this->m_conversionFactorToSIConversionUnit; + if (symbol.isEmpty()) return U::defaultUnit(); + const QList &units = U::allUnits(); + for (int i = 0; i < units.size(); ++i) { + if (units.at(i).getSymbol() == symbol) return units.at(i); + } + qFatal("Illegal unit name"); + return U::defaultUnit(); // just suppress "not all control paths return a value" } public: /*! * \brief Equal operator == - * \param otherUnit + * \param other * \return */ - bool operator == (const CMeasurementUnit &otherUnit) const; + bool operator == (const CMeasurementUnit &other) const; /*! * \brief Unequal operator != - * \param otherUnit + * \param other * \return */ - bool operator != (const CMeasurementUnit &otherUnit) const; - - /*! - * \brief Representing an SI unit? Examples: kilometer, meter, hertz - * \return - */ - bool isSiUnit() const - { - return this->m_isSiUnit; - } - - /*! - * \brief Representing an base SI unit? Examples: second, meter - * \return - */ - bool isSiBaseUnit() const - { - return this->m_isSiUnit; - } - - /*! - * \brief Representing an SI base unit? Example: meter - * \return - */ - bool isUnprefixedSiUnit() const - { - return this->m_isSiUnit && this->m_multiplier.getFactor() == 1; - } + bool operator != (const CMeasurementUnit &other) const; /*! * \brief Name such as "meter" + * \param i18n * \return */ - QString getName() const + QString getName(bool i18n = false) const { - return this->m_name; + return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_name.toStdString().c_str()) : this->m_name; } /*! * \brief Unit name such as "m" + * \param i18n * \return */ - QString getUnitName() const + QString getSymbol(bool i18n = false) const { - return this->m_unitName; + return i18n ? QCoreApplication::translate("CMeasurementUnit", this->m_symbol.toStdString().c_str()) : this->m_symbol; } - /*! - * \brief Type such as "distance", "frequency" - * \return - */ - QString getType() const - { - return this->m_type; - } - - /*! - * Given value to conversion SI conversion unit (e.g. meter, hertz). - * Standard implementation is simply factor based. - * \param value - * \return - */ - double convertToSiConversionUnit(double value) const - { - return (this->m_toSiConverter) ? this->m_toSiConverter((*this), value) : this->conversionToSiConversionUnit(value); - } - - /*! - * Value from SI conversion unit to this unit. - * Standard implementation is simply factor based. - * \param value - * \return - */ - double convertFromSiConversionUnit(double value) const - { - return (this->m_fromSiConverter) ? this->m_fromSiConverter((*this), value) : this->conversionFromSiConversionUnit(value); - } - - /*! - * Rounded string utility method, virtual so units can have - * specialized formatting - * \param value - * \param digits - * \return - */ - virtual QString toQStringRounded(double value, int digits = -1) const; - /*! * \brief Rounded value * \param value * \param digits * \return */ - double valueRounded(double value, int digits = -1) const; + double roundValue(double value, int digits = -1) const; + + /*! + * Rounded string utility method, virtual so units can have + * specialized formatting + * \param value + * \param digits + * \param i18n + * \return + */ + virtual QString makeRoundedQString(double value, int digits = -1, bool i18n = false) const; /*! * \brief Value rounded with unit, e.g. "5.00m", "30kHz" * \param value * \param digits + * \param i18n * \return */ - virtual QString valueRoundedWithUnit(double value, int digits = -1) const; + virtual QString makeRoundedQStringWithUnit(double value, int digits = -1, bool i18n = false) const; /*! * \brief Threshold for rounding @@ -464,45 +556,26 @@ public: * \brief getDisplayDigits * \return */ - qint32 getDisplayDigits() const + int getDisplayDigits() const { return this->m_displayDigits; } /*! - * \brief Multiplier such as "kilo" - * \return + * Convert from other unit to this unit. + * \param */ - CMeasurementPrefix getMultiplier() const - { - return this->m_multiplier; - } - - /*! - * \brief Factor to convert to given unit - * \param value - * \param to - * \return - */ - double conversionToUnit(double value, const CMeasurementUnit &to) const; - - /*! - * Epsilon rounding. In some conversion rouding is required to avoid - * periodical numbers. - * \param value - * \return - */ - double epsilonUpRounding(double value) const; + double convertFrom(double value, const CMeasurementUnit &unit) const; /*! * \brief Is given value <= epsilon? - * \param checkValue + * \param value * \return */ - bool isEpsilon(double checkValue) const + bool isEpsilon(double value) const { - if (checkValue == 0) return true; - return abs(checkValue) <= this->m_epsilon; + if (value == 0) return true; + return abs(value) <= this->m_epsilon; } // -------------------------------------------------------------------- @@ -510,12 +583,12 @@ public: // -------------------------------------------------------------------- /*! - * \brief Unit is not specified + * \brief Dimensionless unit * \return */ static CMeasurementUnit &None() { - static CMeasurementUnit none("none", "", "", false, false, 0.0, CMeasurementPrefix::None(), 0, 0); + static CMeasurementUnit none("none", "", 0.0, 0, 0); return none; } }; diff --git a/src/blackmisc/pqconstants.h b/src/blackmisc/pqconstants.h index 959ea75e8..fa67d9a4e 100644 --- a/src/blackmisc/pqconstants.h +++ b/src/blackmisc/pqconstants.h @@ -12,86 +12,106 @@ namespace BlackMisc { namespace PhysicalQuantities { + /*! * \brief Physical quantities constants */ class CPhysicalQuantitiesConstants { - public: - /*! - * \brief Temperature absolute Zero in °C - * \return - */ - static const CTemperature& TemperatureAbsoluteZero() { - static CTemperature t(-273.15, CTemperatureUnit::C()); - return t; - } /*! * \brief Tripe point of purified water, 0.01°C * \return */ - static const CTemperature& TemperatureTriplePointOfVSMOW() { + static const CTemperature& TemperatureTriplePointOfVSMOW() + { static CTemperature t(-273.16, CTemperatureUnit::K()); return t; } + /*! * \brief Temperature absolute Zero in °C * \return */ - static const CTemperature& TemperatureAbsoluteZeroC() { + static const CTemperature& TemperatureAbsoluteZeroC() + { static CTemperature t(-273.15, CTemperatureUnit::C()); return t; } + /*! - * \brief Standard pressure 1013,25mbar / 29.92inHg + * \brief International Standard Atmosphere pressure at mean sea level, 1013.25hPa * \return */ - static const CPressure& InternationalStandardSeaLevelPressure() { + static const CPressure& ISASeaLevelPressure() + { static CPressure p(1013.25, CPressureUnit::hPa()); return p; } + /*! - * \brief 0m + * \brief ICAO standard pressure datum for flight levels, 1013.2hPa * \return */ - static const CLength& Length0m() { - static CLength l(0, CLengthUnit::m()); - return l; + static const CPressure& ICAOFlightLevelPressure() + { + static CPressure p(1013.2, CPressureUnit::hPa()); + return p; } + /*! - * \brief 0ft + * \brief Standard pressure datum for flight levels in USA, Canada, parts of Latin America, 29.92inHg * \return */ - static const CLength& Length0ft() { - static CLength l(0, CLengthUnit::ft()); - return l; + static const CPressure& USFlightLevelPressure() + { + static CPressure p(29.92, CPressureUnit::inHg()); + return p; } + + /*! + * \brief Standard pressure datum for flight levels expressed in mmHg, such as in Russia, 760mmHg + * \return + */ + static const CPressure& RuFlightLevelPressure() + { + static CPressure p(760, CPressureUnit::mmHg()); + return p; + } + /*! * \brief Unicom frequency * \return */ - static const CFrequency& FrequencyUnicom() { + static const CFrequency& FrequencyUnicom() + { static CFrequency f(122.8, CFrequencyUnit::MHz()); return f; } + /*! * \brief Civil aircraft emergency frequency * \return */ - static const CFrequency& FrequencyInternationalAirDistress() { + static const CFrequency& FrequencyInternationalAirDistress() + { static CFrequency f(121.5, CFrequencyUnit::MHz()); return f; } + /*! * \brief Military aircraft emergency frequency * \return */ - static const CFrequency& FrequencyMilitaryAirDistress() { + + static const CFrequency& FrequencyMilitaryAirDistress() + { static CFrequency f(243.0, CFrequencyUnit::MHz()); return f; } }; + } // namespace } // namespace + #endif // guard diff --git a/src/blackmisc/pqfrequency.h b/src/blackmisc/pqfrequency.h index 6a1fd94b4..d86a89f76 100644 --- a/src/blackmisc/pqfrequency.h +++ b/src/blackmisc/pqfrequency.h @@ -22,28 +22,24 @@ public: /*! * \brief Default constructor */ - CFrequency() : CPhysicalQuantity(0, CFrequencyUnit::Hz(), CFrequencyUnit::Hz()) {} - /** - *\brief Copy constructor - */ - CFrequency(const CFrequency &frequency) : CPhysicalQuantity(frequency) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CFrequency(qint32 value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()) {} + CFrequency() : CPhysicalQuantity(0, CFrequencyUnit::defaultUnit()) {} + /*! * \brief Init by double value * \param value * \param unit */ - CFrequency(double value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()) {} + CFrequency(double value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit) {} + /*! * \brief Virtual destructor */ virtual ~CFrequency() {} }; + } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequency) + #endif // BLACKMISC_PQFREQUENCY_H diff --git a/src/blackmisc/pqlength.h b/src/blackmisc/pqlength.h index 41846948b..15cecf3ef 100644 --- a/src/blackmisc/pqlength.h +++ b/src/blackmisc/pqlength.h @@ -22,28 +22,24 @@ public: /*! * \brief Default constructor */ - CLength() : CPhysicalQuantity(0, CLengthUnit::m(), CLengthUnit::m()) {} - /** - *\brief Copy constructor - */ - CLength(const CLength &length) : CPhysicalQuantity(length) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CLength(qint32 value, const CLengthUnit &unit) : CPhysicalQuantity(value, unit, CLengthUnit::m()) {} + CLength() : CPhysicalQuantity(0, CLengthUnit::defaultUnit()) {} + /*! *\brief Init by double value * \param value * \param unit */ - CLength(double value, const CLengthUnit &unit) : CPhysicalQuantity(value, unit, CLengthUnit::m()) {} + CLength(double value, const CLengthUnit &unit) : CPhysicalQuantity(value, unit) {} + /*! * \brief Virtual destructor */ virtual ~CLength() {} }; + } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CLength) + #endif // BLACKMISC_PQLENGTH_H diff --git a/src/blackmisc/pqmass.h b/src/blackmisc/pqmass.h index f4127174b..00483b3b1 100644 --- a/src/blackmisc/pqmass.h +++ b/src/blackmisc/pqmass.h @@ -21,34 +21,24 @@ public: /*! * \brief Default constructor */ - CMass() : CPhysicalQuantity(0, CMassUnit::kg(), CMassUnit::kg()) {} - - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CMass(qint32 value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()) {} + CMass() : CPhysicalQuantity(0, CMassUnit::defaultUnit()) {} /*! * \brief Init by double value * \param value * \param unit */ - CMass(double value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()) {} - - /*! - * \brief Copy constructor - * \param mass - */ - CMass(const CPhysicalQuantity &mass) : CPhysicalQuantity(mass) {} + CMass(double value, const CMassUnit &unit) : CPhysicalQuantity(value, unit) {} /*! * \brief Virtual destructor */ virtual ~CMass() {} }; + } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CMass) + #endif // guard diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 611a928ba..b83c3ce29 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -10,269 +10,159 @@ namespace BlackMisc namespace PhysicalQuantities { -/* - * Constructor by integer - */ -template CPhysicalQuantity::CPhysicalQuantity(qint32 baseValue, const MU &unit, const MU &siConversionUnit) : - m_unit(unit), m_conversionSiUnit(siConversionUnit) -{ - this->setUnitValue(baseValue); -} - /* * Constructor by double */ -template CPhysicalQuantity::CPhysicalQuantity(double baseValue, const MU &unit, const MU &siConversionUnit) : - m_unit(unit), m_conversionSiUnit(siConversionUnit) +template CPhysicalQuantity::CPhysicalQuantity(double value, const MU &unit) : + m_value(value), m_unit(unit) { - this->setUnitValue(baseValue); -} - -/* - * Copy constructor - */ -template CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &otherQuantity) : - m_unitValueD(otherQuantity.m_unitValueD), m_unitValueI(otherQuantity.m_unitValueI), m_convertedSiUnitValueD(otherQuantity.m_convertedSiUnitValueD), - m_isIntegerBaseValue(otherQuantity.m_isIntegerBaseValue), m_unit(otherQuantity.m_unit), m_conversionSiUnit(otherQuantity.m_conversionSiUnit) -{ - // void -} - -/* - * Destructor - */ -template CPhysicalQuantity::~CPhysicalQuantity() -{ - // void } /* * Equal operator == */ -template bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return true; - if (this->m_unit.getType() != otherQuantity.m_unit.getType()) return false; - - // some special cases for best quality - double diff; - const double lenient = 1.001; // even diff already has a rounding issue to be avoided - bool eq = false; - if (this->m_unit == otherQuantity.m_unit) - { - // same unit - if (this->m_isIntegerBaseValue && otherQuantity.m_isIntegerBaseValue) - { - // pure integer comparison, no rounding issues - eq = this->m_unitValueI == otherQuantity.m_unitValueI; - } - else - { - // same unit, comparison based on double - diff = qAbs(this->m_unitValueD - otherQuantity.m_unitValueD); - eq = diff <= (lenient * this->m_unit.getEpsilon()); - } - } - else - { - // based on SI value - diff = qAbs(this->m_convertedSiUnitValueD - otherQuantity.m_convertedSiUnitValueD); - eq = diff <= (lenient * this->m_conversionSiUnit.getEpsilon()); - } - return eq; + if (this == &other) return true; + double diff = abs(this->m_value - other.value(this->m_unit)); + return diff <= this->m_unit.getEpsilon(); } /* * Not equal */ -template bool CPhysicalQuantity::operator !=(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator !=(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return false; - return !((*this) == otherQuantity); + return !((*this) == other); } /* - * Assignment operator = + * Plus operator */ -template CPhysicalQuantity& CPhysicalQuantity::operator=(const CPhysicalQuantity &otherQuantity) +template CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &other) { - - // Check for self-assignment! - if (this == &otherQuantity) return *this; // Same object? - - this->m_unitValueI = otherQuantity.m_unitValueI; - this->m_unitValueD = otherQuantity.m_unitValueD; - this->m_convertedSiUnitValueD = otherQuantity.m_convertedSiUnitValueD; - this->m_isIntegerBaseValue = otherQuantity.m_isIntegerBaseValue; - this->m_unit = otherQuantity.m_unit; - this->m_conversionSiUnit = otherQuantity.m_conversionSiUnit; + this->m_value += other.value(this->m_unit); return *this; } /* * Plus operator */ -template CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &otherQuantity) +template PQ CPhysicalQuantity::operator +(const PQ &other) const { - if (this->m_unit == otherQuantity.m_unit) - { - // same unit - if (this->m_isIntegerBaseValue && otherQuantity.m_isIntegerBaseValue) - { - // pure integer, no rounding issues - this->setUnitValue(otherQuantity.m_unitValueI + this->m_unitValueI); - } - else - { - this->setUnitValue(otherQuantity.m_unitValueD + this->m_unitValueD); - } - } - else - { - double v = otherQuantity.value(this->m_unit); - this->setUnitValue(v + this->m_unitValueD); - } - return *this; + PQ copy(other); + copy += *this; + return copy; } -/* - * Plus operator - */ -template PQ CPhysicalQuantity::operator +(const PQ &otherQuantity) const -{ - PQ plus(otherQuantity); - plus += (*this); - return plus; -} - - /* * Explicit plus */ -template void CPhysicalQuantity::addUnitValue(double value) +template void CPhysicalQuantity::addValueSameUnit(double value) { - this->setUnitValue(this->m_unitValueD + value); + this->m_value += value; } /* * Explicit minus */ -template void CPhysicalQuantity::substractUnitValue(double value) +template void CPhysicalQuantity::substractValueSameUnit(double value) { - this->setUnitValue(this->m_unitValueD - value); + this->m_value -= value; } /* * Minus operator */ -template CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &otherQuantity) +template CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &other) { - if (this->m_unit == otherQuantity.m_unit) - { - // same unit - if (this->m_isIntegerBaseValue && otherQuantity.m_isIntegerBaseValue) - { - // pure integer, no rounding issues - this->setUnitValue(otherQuantity.m_unitValueI - this->m_unitValueI); - } - else - { - this->setUnitValue(otherQuantity.m_unitValueD - this->m_unitValueD); - } - } - else - { - double v = otherQuantity.value(this->m_unit); - this->setUnitValue(v - this->m_unitValueD); - } + this->m_value -= other.value(this->m_unit); return *this; } /* * Minus operator */ -template PQ CPhysicalQuantity::operator -(const PQ &otherQuantity) const +template PQ CPhysicalQuantity::operator -(const PQ &other) const { - PQ minus = *derived(); - minus -= otherQuantity; - return minus; + PQ copy = *derived(); + copy -= other; + return copy; } /* * Multiply operator */ -template CPhysicalQuantity &CPhysicalQuantity::operator *=(double multiply) +template CPhysicalQuantity &CPhysicalQuantity::operator *=(double factor) { - this->setUnitValue(this->m_unitValueD * multiply); + this->m_value *= factor; return *this; } /* * Multiply operator */ -template PQ CPhysicalQuantity::operator *(double multiply) const +template PQ CPhysicalQuantity::operator *(double factor) const { - PQ times = *derived(); - times *= multiply; - return times; + PQ copy = *derived(); + copy *= factor; + return copy; } /* * Divide operator /= */ -template CPhysicalQuantity &CPhysicalQuantity::operator /=(double divide) +template CPhysicalQuantity &CPhysicalQuantity::operator /=(double divisor) { - this->setUnitValue(this->m_unitValueD / divide); + this->m_value /= divisor; return *this; } /* * Divide operator / */ -template PQ CPhysicalQuantity::operator /(double divide) const +template PQ CPhysicalQuantity::operator /(double divisor) const { - PQ div = *derived(); - div /= divide; - return div; + PQ copy = *derived(); + copy /= divisor; + return copy; } /* * Less operator < */ -template bool CPhysicalQuantity::operator <(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator <(const CPhysicalQuantity &other) const { - if ((*this) == otherQuantity) return false; + if ((*this) == other) return false; - // == considers epsilon, so we now have a diff > epsilon here - double diff = this->m_convertedSiUnitValueD - otherQuantity.m_convertedSiUnitValueD; - return (diff < 0); + return (this->m_value < other.value(this->m_unit)); } /* * Greater than */ -template bool CPhysicalQuantity::operator >(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator >(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return false; - return otherQuantity < (*this); + if (this == &other) return false; + return other < *this; } /* * Greater / Equal */ -template bool CPhysicalQuantity::operator >=(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator >=(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return true; - return !(*this < otherQuantity); + if (this == &other) return true; + return !(*this < other); } /* * Less equal */ -template bool CPhysicalQuantity::operator <=(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator <=(const CPhysicalQuantity &other) const { - if (this == &otherQuantity) return true; - return !(*this > otherQuantity); + if (this == &other) return true; + return !(*this > other); } /* @@ -282,94 +172,26 @@ template PQ &CPhysicalQuantity::switchUnit(const MU { if (this->m_unit != newUnit) { - double cf = this->m_unit.conversionToUnit(this->m_unitValueD, newUnit); + this->m_value = newUnit.convertFrom(this->m_value, this->m_unit); this->m_unit = newUnit; - this->setUnitValue(cf); } return *derived(); } -/* - * Init by integer - */ -template void CPhysicalQuantity::setUnitValue(qint32 baseValue) -{ - this->m_unitValueI = baseValue; - this->m_unitValueD = double(baseValue); - this->m_isIntegerBaseValue = true; - this->setConversionSiUnitValue(); -} - /* * Init by double */ -template void CPhysicalQuantity::setUnitValue(double baseValue) +template void CPhysicalQuantity::setValueSameUnit(double baseValue) { - this->m_unitValueD = baseValue; - this->m_unitValueI = qRound(baseValue); - this->m_isIntegerBaseValue = false; - this->setConversionSiUnitValue(); -} - -/* - * Set SI value - */ -template void CPhysicalQuantity::setConversionSiUnitValue() -{ - double si = this->m_unit.convertToSiConversionUnit(this->m_unitValueD); - this->m_convertedSiUnitValueD = si; -} - -/* - * Round - */ -template double CPhysicalQuantity::unitValueToDoubleRounded(int digits) const -{ - return this->m_unit.valueRounded(this->m_unitValueD, digits); -} - -/* - * Rounded value to QString - */ -template QString CPhysicalQuantity::unitValueToQStringRounded(int digits) const -{ - return this->m_unit.toQStringRounded(this->m_unitValueD, digits); -} - -/* - * Rounded with unit - */ -template QString CPhysicalQuantity::unitValueRoundedWithUnit(int digits) const -{ - return this->m_unit.valueRoundedWithUnit(this->m_unitValueD, digits); -} - -/* - * Rounded SI value to QString - */ -template QString CPhysicalQuantity::convertedSiValueToQStringRounded(int digits) const -{ - if (digits < 1) digits = this->m_conversionSiUnit.getDisplayDigits(); - return this->m_conversionSiUnit.toQStringRounded(this->m_convertedSiUnitValueD, digits); -} - -/* - * SI base unit value with unit - */ -template QString CPhysicalQuantity::convertedSiValueRoundedWithUnit(int digits) const -{ - if (digits < 1) digits = this->m_conversionSiUnit.getDisplayDigits(); - return this->convertedSiValueToQStringRounded(digits).append(this->m_conversionSiUnit.getUnitName()); + this->m_value = baseValue; } /* * Value rounded in unit */ -template QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits) const +template QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits, bool i18n) const { - if (unit == this->m_unit) return this->unitValueRoundedWithUnit(digits); - if (unit == this->m_conversionSiUnit) return this->convertedSiValueRoundedWithUnit(digits); - return unit.valueRoundedWithUnit(this->value(unit), digits); + return unit.makeRoundedQStringWithUnit(this->value(unit), digits, i18n); } /* @@ -377,7 +199,7 @@ template QString CPhysicalQuantity::valueRoundedWit */ template double CPhysicalQuantity::valueRounded(const MU &unit, int digits) const { - return unit.valueRounded(this->value(unit), digits); + return unit.roundValue(this->value(unit), digits); } /* @@ -385,22 +207,9 @@ template double CPhysicalQuantity::valueRounded(con */ template double CPhysicalQuantity::value(const MU &unit) const { - if (unit == this->m_unit) return this->m_unitValueD; - if (unit == this->m_conversionSiUnit) return this->m_convertedSiUnitValueD; - double v = unit.convertFromSiConversionUnit(this->m_convertedSiUnitValueD); - return v; + return unit.convertFrom(this->m_value, this->m_unit); } -/* - * Round utility method - */ -template double CPhysicalQuantity::convertedSiValueToDoubleRounded(int digits) const -{ - if (digits < 1) digits = this->m_conversionSiUnit.getDisplayDigits(); - return this->m_conversionSiUnit.valueRounded(this->m_convertedSiUnitValueD, digits); -} - - // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CPhysicalQuantity; diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 815bc9ca2..ce3c80786 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -10,24 +10,30 @@ #include "blackmisc/pqbase.h" #include "blackmisc/pqunits.h" #include "blackmisc/debug.h" +#include #include #include #include +#include namespace BlackMisc { namespace PhysicalQuantities { + /*! * \brief A physical quantity such as "5m", "20s", "1500ft/s" */ -template class CPhysicalQuantity : public BlackMisc::CBaseStreamStringifier +template class CPhysicalQuantity : public BlackMisc::CStreamable { private: - double m_unitValueD; //!< value backed by double - qint32 m_unitValueI; //!< value backed by integer, allows sole integer arithmetic - double m_convertedSiUnitValueD; //!< SI unit value - bool m_isIntegerBaseValue; //!< flag integer? / double? + double m_value; //!< numeric part + MU m_unit; //!< unit part + + /*! + * Which subclass of CMeasurementUnit does this quantity use? + */ + typedef MU UnitClass; /*! * \brief Easy access to derived class (CRTP template parameter) @@ -48,63 +54,34 @@ private: } protected: - MU m_unit; //!< unit - MU m_conversionSiUnit; //!< corresponding SI base unit - - /*! - * \brief Constructor by integer - * \param baseValue - * \param unit - * \param siConversionUnit - */ - CPhysicalQuantity(qint32 baseValue, const MU &unit, const MU &siConversionUnit); - /*! * \brief Constructor with double - * \param baseValue + * \param value * \param unit - * \param siConversionUnit */ - CPhysicalQuantity(double baseValue, const MU &unit, const MU &siConversionUnit); + CPhysicalQuantity(double value, const MU &unit); /*! - * \brief String for converter and streaming + * \brief Name as string + * \param i18n * \return */ - virtual QString stringForConverter() const + virtual QString convertToQString(bool i18n = false) const { - return this->unitValueRoundedWithUnit(-1); + return this->valueRoundedWithUnit(this->getUnit(), -1, i18n); } /*! - * \brief Init by integer - * \param baseValue + * \brief Change value without changing unit + * \param value */ - void setUnitValue(qint32 baseValue); - - /*! - * \brief Init by double - * \param baseValue - */ - - void setUnitValue(double baseValue); - - /*! - * \brief Set the SI value - */ - void setConversionSiUnitValue(); + void setValueSameUnit(double value); public: - /*! - * \brief Copy constructor - * \param otherQuantity - */ - CPhysicalQuantity(const CPhysicalQuantity &otherQuantity); - /*! * \brief Virtual destructor */ - virtual ~CPhysicalQuantity(); + virtual ~CPhysicalQuantity() {} /*! * \brief Unit of the distance @@ -116,48 +93,12 @@ public: } /*! - * \brief Conversion SI unit - * \return - */ - MU getConversionSiUnit() const - { - return this->m_conversionSiUnit; - } - - /*! - * \brief Switch unit, e.g. feet to meter + * \brief Change unit, and convert value to maintain the same quantity * \param newUnit * \return */ PQ &switchUnit(const MU &newUnit); - /*! - * \brief Value in SI base unit? Meter is an SI base unit, hertz not! - * \return - */ - bool isSiBaseUnit() const - { - return this->m_unit.isSiBaseUnit(); - } - - /*! - * \brief Value in SI unit? Hertz is an derived SI unit, NM not! - * \return - */ - bool isSiUnit() const - { - return this->m_unit.isSiUnit(); - } - - /*! - * \brief Value in unprefixed SI unit? Meter is a unprefixed, kilometer a prefixed SI Unit - * \return - */ - bool isUnprefixedSiUnit() const - { - return this->m_unit.isUnprefixedSiUnit(); - } - /*! * \brief Value in given unit * \param unit @@ -166,7 +107,16 @@ public: double value(const MU &unit) const; /*! - * \brief Rounded value in unit + * \brief Value in current unit + * \return + */ + double value() const + { + return this->m_value; + } + + /*! + * \brief Rounded value in given unit * \param unit * \param digits * \return @@ -174,105 +124,46 @@ public: double valueRounded(const MU &unit, int digits = -1) const; /*! - * \brief Value to QString with unit, e.g. "5.00m" + * \brief Rounded value in current unit + * \param digits + * \return + */ + double valueRounded(int digits = -1) const + { + return this->valueRounded(this->m_unit, digits); + } + + /*! + * \brief Value to QString with the given unit, e.g. "5.00m" * \param unit * \param digits + * \param i18n * \return */ - QString valueRoundedWithUnit(const MU &unit, int digits = -1) const; + QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const; /*! - * \brief Value as int + * \brief Value to QString with the current unit, e.g. "5.00m" + * \param digits + * \param i18n * \return */ - qint32 unitValueToInteger() const + QString valueRoundedWithUnit(int digits = -1, bool i18n = false) const { - return this->m_unitValueI; + return this->valueRoundedWithUnit(this->m_unit, digits, i18n); } /*! - * \brief Value as double - * \return - */ - double unitValueToDouble() const - { - return this->m_unitValueD; - } - - /*! - * \brief Value to QString with unit, e.g. "5.00m" - * \param digits - * \return - */ - QString unitValueRoundedWithUnit(int digits = -1) const; - - /*! - * \brief Rounded value by n digits - * \param digits - * \return - */ - double unitValueToDoubleRounded(int digits = -1) const; - - /*! - * \brief Rounded value by n digits - * \param digits if no value is provided, unit rounding is taken - * \return - */ - QString unitValueToQStringRounded(int digits = -1) const; - - /*! - * \brief Conversion SI value as double - * \return - */ - double convertedSiValueToDouble() const - { - return this->m_convertedSiUnitValueD; - } - - /*! - * \brief SI value as integer - * \return - */ - qint32 convertedSiValueToInteger() const - { - return static_cast( - BlackMisc::Math::CMath::round(this->m_convertedSiUnitValueD, 0)); - } - - /*! - * \brief Rounded SI value by n digits - * \param digits - * \return - */ - double convertedSiValueToDoubleRounded(int digits = -1) const; - - /*! - * \brief Rounded value by n digits - * \param digits if no value is provided, unit rounding is taken - * \return - */ - QString convertedSiValueToQStringRounded(int digits = -1) const; - - /*! - * \brief SI Base unit value rounded - * \param digits - * \return - */ - QString convertedSiValueRoundedWithUnit(int digits = -1) const; - - /*! - * \brief Add to the unit value. - * \remarks Since overloading the + operator with double did lead to unintended conversions, as explicit method + * \brief Add to the value in the current unit. * \param value */ - void addUnitValue(double value); + void addValueSameUnit(double value); /*! - * \brief Substratc to the unit value. - * \remarks Since overloading the - operator with double did lead to unintended conversions, as explicit method + * \brief Substract from the value in the current unit. * \param value */ - void substractUnitValue(double value); + void substractValueSameUnit(double value); /*! * \brief Multiply operator *= @@ -298,12 +189,12 @@ public: /*! * \brief Operator to support commutative multiplication * \param factor - * \param otherQuantity + * \param other * \return */ - friend PQ operator *(double factor, const PQ &otherQuantity) + friend PQ operator *(double factor, const PQ &other) { - return otherQuantity * factor; + return other * factor; } /*! @@ -315,80 +206,73 @@ public: /*! * \brief Equal operator == - * \param otherQuantity + * \param other * \return */ - bool operator==(const CPhysicalQuantity &otherQuantity) const; + bool operator==(const CPhysicalQuantity &other) const; /*! * \brief Not equal operator != - * \param otherQuantity + * \param other * \return */ - bool operator!=(const CPhysicalQuantity &otherQuantity) const; + bool operator!=(const CPhysicalQuantity &other) const; /*! * \brief Plus operator += - * \param otherQuantity + * \param other * \return */ - CPhysicalQuantity &operator +=(const CPhysicalQuantity &otherQuantity); + CPhysicalQuantity &operator +=(const CPhysicalQuantity &other); /*! * \brief Minus operator-= - * \param otherQuantity + * \param other * \return */ - CPhysicalQuantity &operator -=(const CPhysicalQuantity &otherQuantity); + CPhysicalQuantity &operator -=(const CPhysicalQuantity &other); /*! * \brief Greater operator > - * \param otherQuantity + * \param other * \return */ - bool operator >(const CPhysicalQuantity &otherQuantity) const; + bool operator >(const CPhysicalQuantity &other) const; /*! * \brief Less operator < - * \param otherQuantity + * \param other * \return */ - bool operator <(const CPhysicalQuantity &otherQuantity) const; + bool operator <(const CPhysicalQuantity &other) const; /*! * \brief Less equal operator <= - * \param otherQuantity + * \param other * \return */ - bool operator <=(const CPhysicalQuantity &otherQuantity) const; + bool operator <=(const CPhysicalQuantity &other) const; /*! * \brief Greater equal operator >= - * \param otherQuantity + * \param other * \return */ - bool operator >=(const CPhysicalQuantity &otherQuantity) const; - - /*! - * \brief Assignment operator = - * \param otherQuantity - * \return - */ - CPhysicalQuantity &operator =(const CPhysicalQuantity &otherQuantity); + bool operator >=(const CPhysicalQuantity &other) const; /*! * \brief Plus operator + - * \param otherQuantity + * \param other * \return */ - PQ operator +(const PQ &otherQuantity) const; + PQ operator +(const PQ &other) const; /*! * \brief Minus operator - - * \param otherQuantity + * \param other * \return */ - PQ operator -(const PQ &otherQuantity) const; + PQ operator -(const PQ &other) const; /*! * \brief Quantity value <= epsilon @@ -396,26 +280,61 @@ public: */ bool isZeroEpsilon() const { - if (this->m_isIntegerBaseValue) return this->m_unitValueI == 0; - return this->m_unit.isEpsilon(this->m_unitValueD); + return this->m_unit.isEpsilon(this->m_value); } /*! * \brief Value >= 0 epsilon considered * \return */ - bool isGreaterOrEqualZeroEpsilon() const + bool isNonNegativeEpsilon() const { - return this->isZeroEpsilon() || this->m_unitValueD > 0; + return this->isZeroEpsilon() || this->m_value > 0; } /*! * \brief Value <= 0 epsilon considered * \return */ - bool isLessOrEqualZeroEpsilon() const + bool isNonPositiveEpsilon() const { - return this->isZeroEpsilon() || this->m_unitValueD < 0; + return this->isZeroEpsilon() || this->m_value < 0; + } + + /*! + * \brief Stream to DBus << + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &argument) const + { + argument << this->value(UnitClass::defaultUnit()); + argument << this->m_value; + argument << this->m_unit; + } + + /*! + * \brief Stream from DBus >> + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + double ignore; + argument >> ignore; + argument >> this->m_value; + argument >> this->m_unit; + } + + /*! + * \brief Register metadata of unit and quantity + */ + static void registerMetadata() + { + qRegisterMetaType(typeid(MU).name()); + qDBusRegisterMetaType(); + qDBusRegisterMetaType >(); + qRegisterMetaType(typeid(PQ).name()); + qDBusRegisterMetaType(); + qDBusRegisterMetaType >(); } }; diff --git a/src/blackmisc/pqpressure.h b/src/blackmisc/pqpressure.h index c330d63fe..febb338b1 100644 --- a/src/blackmisc/pqpressure.h +++ b/src/blackmisc/pqpressure.h @@ -23,28 +23,24 @@ public: /*! * \brief Default constructor */ - CPressure() : CPhysicalQuantity(0, CPressureUnit::Pa(), CPressureUnit::Pa()) {} - /** - *\brief Copy constructor - */ - CPressure(const CPressure &pressure) : CPhysicalQuantity(pressure) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CPressure(qint32 value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()) {} + CPressure() : CPhysicalQuantity(0, CPressureUnit::defaultUnit()) {} + /*! *\brief Init by double value * \param value * \param unit */ - CPressure(double value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()) {} + CPressure(double value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit) {} + /*! * \brief Virtual destructor */ virtual ~CPressure() {} }; + } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressure) + #endif // BLACKMISC_PQPRESSURE_H diff --git a/src/blackmisc/pqspeed.h b/src/blackmisc/pqspeed.h index ed4d2968e..a783b4b9c 100644 --- a/src/blackmisc/pqspeed.h +++ b/src/blackmisc/pqspeed.h @@ -18,33 +18,29 @@ namespace PhysicalQuantities */ class CSpeed : public CPhysicalQuantity { + public: /*! * \brief Default constructor */ - CSpeed() : CPhysicalQuantity(0, CSpeedUnit::m_s(), CSpeedUnit::m_s()) {} - /** - *\brief Copy constructor - */ - CSpeed(const CPhysicalQuantity &speed): CPhysicalQuantity(speed) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CSpeed(qint32 value, const CSpeedUnit &unit) : CPhysicalQuantity(value, unit, CSpeedUnit::m_s()) {} + CSpeed() : CPhysicalQuantity(0, CSpeedUnit::defaultUnit()) {} + /*! *\brief Init by double value * \param value * \param unit */ - CSpeed(double value, const CSpeedUnit &unit) : CPhysicalQuantity(value, unit, CSpeedUnit::m_s()) {} + CSpeed(double value, const CSpeedUnit &unit) : CPhysicalQuantity(value, unit) {} + /*! * \brief Destructor */ virtual ~CSpeed() {} }; + } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeed) + #endif // BLACKMISC_CSPEED_H diff --git a/src/blackmisc/pqtemperature.h b/src/blackmisc/pqtemperature.h index 892e88bbf..a94540967 100644 --- a/src/blackmisc/pqtemperature.h +++ b/src/blackmisc/pqtemperature.h @@ -22,28 +22,24 @@ public: /*! * \brief Default constructor */ - CTemperature() : CPhysicalQuantity(0, CTemperatureUnit::K(), CTemperatureUnit::K()) {} - /** - *\brief Copy constructor - */ - CTemperature(const CTemperature &temperature) : CPhysicalQuantity(temperature) {} + CTemperature() : CPhysicalQuantity(0, CTemperatureUnit::defaultUnit()) {} + /*! - * \brief Init by int value + * \brief Init by double value * \param value * \param unit */ - CTemperature(qint32 value, const CTemperatureUnit &unit): CPhysicalQuantity(value, unit, CTemperatureUnit::K()) {} - /*! - *\brief Init by double value - * \param value - * \param unit - */ - CTemperature(double value, const CTemperatureUnit &unit): CPhysicalQuantity(value, unit, CTemperatureUnit::K()) {} + CTemperature(double value, const CTemperatureUnit &unit): CPhysicalQuantity(value, unit) {} + /*! * \brief Destructor */ virtual ~CTemperature() {} }; + } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTemperature) + #endif // BLACKMISC_CTEMPERATURE_H diff --git a/src/blackmisc/pqtime.h b/src/blackmisc/pqtime.h index 00f3479a7..8ecd81fc7 100644 --- a/src/blackmisc/pqtime.h +++ b/src/blackmisc/pqtime.h @@ -23,29 +23,24 @@ public: /*! * \brief Default constructor */ - CTime() : CPhysicalQuantity(0, CTimeUnit::s(), CTimeUnit::s()) {} - /** - *\brief Copy constructor - */ - CTime(const CPhysicalQuantity &time): CPhysicalQuantity(time) {} - /*! - * \brief Init by int value - * \param value - * \param unit - */ - CTime(qint32 value, const CTimeUnit &unit) : CPhysicalQuantity(value, unit, CTimeUnit::s()) {} + CTime() : CPhysicalQuantity(0, CTimeUnit::defaultUnit()) {} + /*! *\brief Init by double value * \param value * \param unit */ - CTime(double value, const CTimeUnit &unit) : CPhysicalQuantity(value, unit, CTimeUnit::s()) {} + CTime(double value, const CTimeUnit &unit) : CPhysicalQuantity(value, unit) {} + /*! * \brief Destructor */ virtual ~CTime() {} }; + } // namespace } // namespace +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTime) + #endif // BLACKMISC_PQTIME_H diff --git a/src/blackmisc/pqunits.cpp b/src/blackmisc/pqunits.cpp index 396f05332..e03e8f00b 100644 --- a/src/blackmisc/pqunits.cpp +++ b/src/blackmisc/pqunits.cpp @@ -10,78 +10,84 @@ namespace BlackMisc namespace PhysicalQuantities { -/* - * Convert to SI - */ -double CTemperatureUnit::conversionToSiConversionUnit(double value) const -{ - double v = value + this->m_conversionOffsetToSi; - v *= this->getConversionFactorToSI(); - return v; -} +using BlackMisc::Math::CMath; /* - * Convert from SI + * Rounded to QString */ -double CTemperatureUnit::conversionFromSiConversionUnit(double value) const +QString CAngleUnit::makeRoundedQStringWithUnit(double value, int digits, bool i18n) const { - double v = value / this->getConversionFactorToSI(); - v -= this->m_conversionOffsetToSi; - return v; -} - -/* - * Convert from SI - */ -double CAngleUnit::conversionSexagesimalFromSi(const CMeasurementUnit &angleUnit, double value) -{ - // using rounding here, since fractions can lead to ugly sexagesimal conversion - // e.g. 185.499999 gives 185 29' 59.9999" - value = angleUnit.epsilonUpRounding(value * 180 / M_PI); // degree - double v = floor(value); - double c = value - v; - double mr = c * 60.0; - double m = floor(mr); // minutes - double s = (mr - m) * 60; // seconds + rest fraction - v = (v + (m / 100) + (s / 10000)); - return v; -} - -/* - * Convert to SI - */ -double CAngleUnit::conversionSexagesimalToSi(const CMeasurementUnit &, double value) -{ - double v = floor(value); // degrees - double c = value - v; - c = c * 100.0; - double m = floor(c); - c = c - m; - m /= 60.0; // minutes back to decimals - double s = c / 36.0; // seconds back to decimals - v = v + m + s; - return v / 180.0 * M_PI; + if (digits < 0) digits = this->getDisplayDigits(); + QString s; + if ((*this) == CAngleUnit::sexagesimalDeg()) + { + digits -= 4; + Q_ASSERT(digits >= 0); + double de = CMath::trunc(value); + double mi = CMath::trunc((value - de) * 100.0); + double se = CMath::trunc((value - de - mi / 100.0) * 1000000) / 100.0; + const char *fmt = value < 0 ? "-%L1 %L2 %L3" : "%L1 %L2 %L3"; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(de), 0, 'f', 0).arg(fabs(mi), 2, 'f', 0, '0').arg(fabs(se), 2, 'f', digits, '0'); + } + else if ((*this) == CAngleUnit::sexagesimalDegMin()) + { + digits -= 2; + Q_ASSERT(digits >= 0); + double de = CMath::trunc(value); + double mi = CMath::trunc((value - de) * 100.0); + const char *fmt = value < 0 ? "-%L1 %L2" : "%L1 %L2"; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(de), 0, 'f', 0).arg(fabs(mi), 2, 'f', digits, '0'); + } + else + { + s = this->CMeasurementUnit::makeRoundedQStringWithUnit(value, digits, i18n); + } + return s; } /* * Rounded to QString */ -QString CAngleUnit::toQStringRounded(double value, int digits) const +QString CTimeUnit::makeRoundedQStringWithUnit(double value, int digits, bool i18n) const { + if (digits < 0) digits = this->getDisplayDigits(); QString s; - if ((*this) == CAngleUnit::sexagesimalDeg()) + if ((*this) == CTimeUnit::hms()) { - // special formatting for sexagesimal degrees - double de = floor(value); - double mi = floor((value - de) * 100.0); - double se = floor((value - de - mi / 100.0) * 1000000) / 100.0; - QString ses = QLocale::system().toString(se, 'f', 2); - s = QString::number(de).append(this->getUnitName()).append(QString::number(mi)) - .append("'").append(ses).append("\""); + digits -= 4; + Q_ASSERT(digits >= 0); + double hr = CMath::trunc(value); + double mi = CMath::trunc((value - hr) * 100.0); + double se = CMath::trunc((value - hr - mi / 100.0) * 1000000) / 100.0; + const char *fmt = value < 0 ? "-%L1h%L2m%L3s" : "%L1h%L2m%L3s"; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(hr), 0, 'f', 0).arg(fabs(mi), 2, 'f', 0, '0').arg(fabs(se), 2, 'f', digits, '0'); + } + else if ((*this) == CTimeUnit::hrmin()) + { + digits -= 2; + Q_ASSERT(digits >= 0); + double hr = CMath::trunc(value); + double mi = CMath::trunc((value - hr) * 100.0); + const char *fmt = value < 0 ? "-%L1h%L2m" : "%L1h%L2m"; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(hr), 0, 'f', 0).arg(fabs(mi), 2, 'f', digits, '0'); + } + else if ((*this) == CTimeUnit::minsec()) + { + digits -= 2; + Q_ASSERT(digits >= 0); + double mi = CMath::trunc(value); + double se = CMath::trunc((value - mi) * 100.0); + const char *fmt = value < 0 ? "-%L2m%L3s" : "%L2m%L3s"; + s = i18n ? QCoreApplication::translate("CMeasurementUnit", fmt) : fmt; + s = s.arg(fabs(mi), 0, 'f', 0).arg(fabs(se), 2, 'f', digits, '0'); } else { - s = CMeasurementUnit::toQStringRounded(value, digits); + s = this->CMeasurementUnit::makeRoundedQStringWithUnit(value, digits, i18n); } return s; } diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 736ef86b8..d94f8db96 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -7,12 +7,18 @@ #define BLACKMISC_PQUNITS_H #include "blackmisc/pqbase.h" +#include +#include #include +#include + // // Used with the template for quantities. This is the reason for // having all units in one file, since template requires concrete instantiations // +// I18N: http://qt-project.org/doc/qt-4.8/linguist-programmers.html#translating-text-that-is-outside-of-a-qobject-subclass +// namespace BlackMisc { namespace PhysicalQuantities @@ -25,30 +31,45 @@ class CLengthUnit : public CMeasurementUnit { private: /*! - * \brief Constructor Distance unit + * \brief Constructor length unit * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CLengthUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "distance", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) - { - // void - } + CLengthUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * \brief Constructor length unit + * \param name + * \param symbol + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CLengthUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CLengthUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} + public: /*! - * \brief Copy constructor - * \param otherUnit + * Default constructor, required for Qt Metasystem */ - CLengthUnit(const CLengthUnit &otherUnit) : CMeasurementUnit(otherUnit) - { - // void - } + CLengthUnit() : CMeasurementUnit(defaultUnit()) {} + + /*! + * \brief Copy constructor + * \param other + */ + CLengthUnit(const CLengthUnit &other) : CMeasurementUnit(other) {} + + /*! + * \brief Default unit + * \return + */ + static const CLengthUnit &defaultUnit() { return m(); } /*! * \brief Meter m @@ -56,7 +77,7 @@ public: */ static const CLengthUnit &m() { - static CLengthUnit m("meter", "m", true, true); + static CLengthUnit m(QT_TRANSLATE_NOOP("CMeasurementUnit", "meter"), "m", 1); return m; } @@ -66,7 +87,7 @@ public: */ static const CLengthUnit &NM() { - static CLengthUnit NM("nautical miles", "NM", false, false, 1000.0 * 1.85200, CMeasurementPrefix::One(), 3); + static CLengthUnit NM(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical mile"), "NM", 1000.0 * 1.85200, 3); return NM; } @@ -76,7 +97,7 @@ public: */ static const CLengthUnit &ft() { - static CLengthUnit ft("foot", "ft", false, false, 0.3048, CMeasurementPrefix::One(), 0); + static CLengthUnit ft(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot"), "ft", 0.3048, 0); return ft; } @@ -86,7 +107,7 @@ public: */ static const CLengthUnit &km() { - static CLengthUnit km("kilometer", "km", true, false, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 3); + static CLengthUnit km(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometer"), "km", CMeasurementPrefix::k(), m(), 3); return km; } @@ -96,7 +117,7 @@ public: */ static const CLengthUnit &cm() { - static CLengthUnit cm("centimeter", "cm", true, false, CMeasurementPrefix::c().getFactor(), CMeasurementPrefix::c(), 1); + static CLengthUnit cm(QT_TRANSLATE_NOOP("CMeasurementUnit", "centimeter"), "cm", CMeasurementPrefix::c(), m(), 1); return cm; } @@ -106,7 +127,7 @@ public: */ static const CLengthUnit &mi() { - static CLengthUnit mi("mile", "mi", false, false, 1609.344, CMeasurementPrefix::None(), 3); + static CLengthUnit mi(QT_TRANSLATE_NOOP("CMeasurementUnit", "mile"), "mi", 1609.344, 3); return mi; } @@ -114,12 +135,43 @@ public: * \brief Statute mile * \return */ - static const CLengthUnit &miStatute() + static const CLengthUnit &SM() { - static CLengthUnit mi("mile(statute)", "mi(statute)", false, false, 1609.3472, CMeasurementPrefix::None(), 3); - return mi; + static CLengthUnit sm(QT_TRANSLATE_NOOP("CMeasurementUnit", "statute mile"), "SM", 1609.3472, 3); + return sm; } + /*! + * \brief All units + * \return + */ + static const QList &allUnits() + { + static QList u; + if (u.isEmpty()) + { + u.append(CLengthUnit::cm()); + u.append(CLengthUnit::ft()); + u.append(CLengthUnit::km()); + u.append(CLengthUnit::m()); + u.append(CLengthUnit::mi()); + u.append(CLengthUnit::SM()); + u.append(CLengthUnit::NM()); + } + return u; + } + +protected: + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString unitName; + argument >> unitName; + (*this) = CMeasurementUnit::unitFromSymbol(unitName); + } }; /*! @@ -131,48 +183,51 @@ private: /*! * \brief Constructor angle units: Radian, degree * \param name - * \param unitName - * \param isSiUnit - * \param conversionFactorToSI - * \param multiplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CAngleUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, - const CMeasurementPrefix &multiplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, - double epsilon = 1E-9, UnitConverter converterToSi = 0, UnitConverter converterFromSi = 0) : - CMeasurementUnit(name, unitName, "angle", isSiUnit, false, conversionFactorToSI, - multiplier, displayDigits, epsilon, converterToSi, converterFromSi) - { - // void - } + CAngleUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + /*! - * \brief Special conversion for sexagesimal degrees - * \param value - * \return + * \brief Constructor angle units: Sexagesimal + * \param name + * \param symbol + * \param converter + * \param displayDigits + * \param epsilon */ - static double conversionSexagesimalToSi(const CMeasurementUnit &angleUnit, double value); - /*! - * \brief Special conversion for sexagesimal degrees - * \param value - * \return - */ - static double conversionSexagesimalFromSi(const CMeasurementUnit &angleUnit, double value); + CAngleUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, converter, displayDigits, epsilon) {} public: /*! - * \brief Copy constructor - * \param otherUnit + * Default constructor, required for Qt Metasystem */ - CAngleUnit(const CAngleUnit &otherUnit) : CMeasurementUnit(otherUnit) { } + CAngleUnit() : CMeasurementUnit(defaultUnit()) {} /*! - * \brief Special conversion to QString for sexagesimal degrees. - * \param value - * \param digits + * \brief Copy constructor + * \param other + */ + CAngleUnit(const CAngleUnit &other) : CMeasurementUnit(other) {} + + /*! + * \brief Default unit * \return */ - virtual QString toQStringRounded(double value, int digits) const; + static const CAngleUnit &defaultUnit() { return deg(); } + + /*! + * \brief Override for sexagesimal degrees. + * \param value + * \param digits + * \param i18n + * \return + */ + virtual QString makeRoundedQStringWithUnit(double value, int digits = -1, bool i18n = false) const; /*! * \brief Radians @@ -180,7 +235,7 @@ public: */ static const CAngleUnit &rad() { - static CAngleUnit rad("radian", "rad", true); + static CAngleUnit rad(QT_TRANSLATE_NOOP("CMeasurementUnit", "radian"), "rad", 180.0 / M_PI); return rad; } @@ -190,18 +245,61 @@ public: */ static const CAngleUnit °() { - static CAngleUnit deg("degree", "°", false, M_PI / 180); + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree"), QT_TRANSLATE_NOOP("CMeasurementUnit", "deg"), 1); return deg; } /*! - * \brief Sexagesimal degree (degree, minute, seconds) + * \brief Sexagesimal degree (degrees, minutes, seconds, decimal seconds) * \return */ static const CAngleUnit &sexagesimalDeg() { - static CAngleUnit deg("segadecimal degree", "°", false, M_PI / 180, - CMeasurementPrefix::One(), 0, 1E-9, CAngleUnit::conversionSexagesimalToSi, CAngleUnit::conversionSexagesimalFromSi); return deg; + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute, second"), "DMS", new SubdivisionConverter2<60, 100, 60, 100>, 4); + return deg; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2 %L3"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1 %L2 %L3"); + } + + /*! + * \brief Sexagesimal degree (degrees, minutes, decimal minutes) + * \return + */ + static const CAngleUnit &sexagesimalDegMin() + { + static CAngleUnit deg(QT_TRANSLATE_NOOP("CMeasurementUnit", "degree, minute"), "MinDec", new SubdivisionConverter<60, 100>, 4); + return deg; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1 %L2"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1 %L2"); + } + + /*! + * \brief All units + * \return + */ + static const QList &allUnits() + { + static QList u; + if (u.isEmpty()) + { + u.append(CAngleUnit::deg()); + u.append(CAngleUnit::rad()); + u.append(CAngleUnit::sexagesimalDeg()); + u.append(CAngleUnit::sexagesimalDegMin()); + } + return u; + } + +protected: + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString unitName; + argument >> unitName; + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -212,27 +310,45 @@ class CFrequencyUnit : public CMeasurementUnit { private: /*! - * Constructor - * \brief CFrequencyUnit + * Constructor frequency unit * \param name - * \param unitName - * \param isSiUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CFrequencyUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "frequency", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CFrequencyUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * Constructor frequency unit + * \param name + * \param symbol + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CFrequencyUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CFrequencyUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} + public: /*! - * \brief Copy constructor - * \param otherUnit + * Default constructor, required for Qt Metasystem */ - CFrequencyUnit(const CFrequencyUnit &otherUnit) : CMeasurementUnit(otherUnit) - { - // void - } + CFrequencyUnit() : CMeasurementUnit(defaultUnit()) {} + + /*! + * \brief Copy constructor + * \param other + */ + CFrequencyUnit(const CFrequencyUnit &other) : CMeasurementUnit(other) {} + + /*! + * \brief Default unit + * \return + */ + static const CFrequencyUnit &defaultUnit() { return Hz(); } /*! * \brief Hertz @@ -240,7 +356,7 @@ public: */ static const CFrequencyUnit &Hz() { - static CFrequencyUnit Hz("hertz", "Hz", true); + static CFrequencyUnit Hz(QT_TRANSLATE_NOOP("CMeasurementUnit", "hertz"), "Hz", 1); return Hz; } @@ -250,7 +366,7 @@ public: */ static const CFrequencyUnit &kHz() { - static CFrequencyUnit kHz("kilohertz", "kHz", true, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 1); + static CFrequencyUnit kHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilohertz"), "kHz", CMeasurementPrefix::k(), Hz(), 1); return kHz; } @@ -260,7 +376,7 @@ public: */ static const CFrequencyUnit &MHz() { - static CFrequencyUnit MHz("megahertz", "MHz", false, CMeasurementPrefix::M().getFactor(), CMeasurementPrefix::M(), 2); + static CFrequencyUnit MHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "megahertz"), "MHz", CMeasurementPrefix::M(), Hz(), 2); return MHz; } @@ -270,9 +386,38 @@ public: */ static const CFrequencyUnit &GHz() { - static CFrequencyUnit GHz("gigahertz", "GHz", true, CMeasurementPrefix::G().getFactor(), CMeasurementPrefix::G(), 2); + static CFrequencyUnit GHz(QT_TRANSLATE_NOOP("CMeasurementUnit", "gigahertz"), "GHz", CMeasurementPrefix::G(), Hz(), 2); return GHz; } + + /*! + * \brief All units + * \return + */ + static const QList &allUnits() + { + static QList u; + if (u.isEmpty()) + { + u.append(CFrequencyUnit::GHz()); + u.append(CFrequencyUnit::Hz()); + u.append(CFrequencyUnit::kHz()); + u.append(CFrequencyUnit::MHz()); + } + return u; + } + +protected: + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString unitName; + argument >> unitName; + (*this) = CMeasurementUnit::unitFromSymbol(unitName); + } }; /*! @@ -284,25 +429,43 @@ private: /*! * \brief Constructor mass units * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CMassUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "mass", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CMassUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * \brief Constructor mass units + * \param name + * \param symbol + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CMassUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CMassUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} + public: /*! - * \brief Copy constructor - * \param otherUnit + * Default constructor, required for Qt Metasystem */ - CMassUnit(const CMassUnit &otherUnit) : CMeasurementUnit(otherUnit) - { - // void - } + CMassUnit() : CMeasurementUnit(defaultUnit()) {} + + /*! + * \brief Copy constructor + * \param other + */ + CMassUnit(const CMassUnit &other) : CMeasurementUnit(other) {} + + /*! + * \brief Default unit + * \return + */ + static const CMassUnit &defaultUnit() { return kg(); } /*! * \brief Kilogram, SI base unit @@ -310,7 +473,7 @@ public: */ static const CMassUnit &kg() { - static CMassUnit kg("kilogram", "kg", true, true, 1.0, CMeasurementPrefix::k(), 1); + static CMassUnit kg(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilogram"), "kg", CMeasurementPrefix::k(), g(), 1); return kg; } @@ -320,29 +483,69 @@ public: */ static const CMassUnit &g() { - static CMassUnit g("gram", "g", true, false, 1.0 / 1000.0, CMeasurementPrefix::One(), 0); + static CMassUnit g(QT_TRANSLATE_NOOP("CMeasurementUnit", "gram"), "g", 0.001, 0); return g; } /*! - * \brief Tonne, aka metric tonne (1000kg) + * \brief Tonne, aka metric ton (1000kg) * \return */ - static const CMassUnit &t() + static const CMassUnit &tonne() { - static CMassUnit t("tonne", "t", false, false, 1000.0, CMeasurementPrefix::One(), 3); + static CMassUnit t(QT_TRANSLATE_NOOP("CMeasurementUnit", "tonne"), "t", 1000.0, 3); return t; } + /*! + * \brief Short ton (2000lb) used in the United States + * \return + */ + static const CMassUnit &shortTon() + { + static CMassUnit ton(QT_TRANSLATE_NOOP("CMeasurementUnit", "short ton"), "ton", 907.18474, 3); + return ton; + } + /*! * \brief Pound, aka mass pound * \return */ static const CMassUnit &lb() { - static CMassUnit lbs("pound", "lb", false, false, 0.45359237, CMeasurementPrefix::One(), 1); + static CMassUnit lbs(QT_TRANSLATE_NOOP("CMeasurementUnit", "pound"), "lb", 0.45359237, 1); return lbs; } + + /*! + * \brief All units + * \return + */ + static const QList &allUnits() + { + static QList u; + if (u.isEmpty()) + { + u.append(CMassUnit::g()); + u.append(CMassUnit::kg()); + u.append(CMassUnit::lb()); + u.append(CMassUnit::tonne()); + u.append(CMassUnit::shortTon()); + } + return u; + } + +protected: + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString unitName; + argument >> unitName; + (*this) = CMeasurementUnit::unitFromSymbol(unitName); + } }; /*! @@ -352,27 +555,45 @@ class CPressureUnit : public CMeasurementUnit { private: /*! - * Constructor - * \brief Pressure unit + * \brief Pressure unit constructor * \param name - * \param unitName - * \param isSiUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CPressureUnit(const QString &name, const QString &unitName, bool isSiUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "frequency", isSiUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CPressureUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * \brief Pressure unit constructor + * \param name + * \param symbol + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CPressureUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CPressureUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} + public: /*! - * \brief Copy constructor - * \param otherUnit + * Default constructor, required for Qt Metasystem */ - CPressureUnit(const CPressureUnit &otherUnit) : CMeasurementUnit(otherUnit) - { - // void - } + CPressureUnit() : CMeasurementUnit(defaultUnit()) {} + + /*! + * \brief Copy constructor + * \param other + */ + CPressureUnit(const CPressureUnit &other) : CMeasurementUnit(other) {} + + /*! + * \brief Default unit + * \return + */ + static const CPressureUnit &defaultUnit() { return hPa(); } /*! * \brief Pascal @@ -380,7 +601,7 @@ public: */ static const CPressureUnit &Pa() { - static CPressureUnit Pa("pascal", "Pa", true); + static CPressureUnit Pa(QT_TRANSLATE_NOOP("CMeasurementUnit", "pascal"), "Pa", 0.01); return Pa; } @@ -390,7 +611,7 @@ public: */ static const CPressureUnit &hPa() { - static CPressureUnit hPa("hectopascal", "hPa", true, CMeasurementPrefix::h().getFactor(), CMeasurementPrefix::h()); + static CPressureUnit hPa(QT_TRANSLATE_NOOP("CMeasurementUnit", "hectopascal"), "hPa", CMeasurementPrefix::h(), Pa()); return hPa; } @@ -400,7 +621,7 @@ public: */ static const CPressureUnit &psi() { - static CPressureUnit psi("pounds per square inch", "psi", false, 6894.8, CMeasurementPrefix::One(), 2); + static CPressureUnit psi(QT_TRANSLATE_NOOP("CMeasurementUnit", "pound per square inch"), "psi", 68.948, 2); return psi; } @@ -410,7 +631,7 @@ public: */ static const CPressureUnit &bar() { - static CPressureUnit bar("bar", "bar", false, 1E5); + static CPressureUnit bar(QT_TRANSLATE_NOOP("CMeasurementUnit", "bar"), "bar", 1000, 1); return bar; } @@ -420,8 +641,8 @@ public: */ static const CPressureUnit &mbar() { - static CPressureUnit bar("bar", "bar", false, 1E2); - return bar; + static CPressureUnit mbar(QT_TRANSLATE_NOOP("CMeasurementUnit", "millibar"), "mbar", CMeasurementPrefix::m(), bar(), 1); + return mbar; } /*! @@ -430,18 +651,49 @@ public: */ static const CPressureUnit &inHg() { - static CPressureUnit inhg("Inch of mercury 0°C", "inHg", false, 3386.389); + static CPressureUnit inhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "inch of mercury"), "inHg", 33.86389); return inhg; } /*! - * \brief Inch of mercury for flight level 29,92inHg = 1013,25mbar = 1013,25hPa + * \brief Millimeter of mercury * \return */ - static const CPressureUnit &inHgFL() + static const CPressureUnit &mmHg() { - static CPressureUnit inhg("Inch of mercury ", "inHg", false, 3386.5307486631); - return inhg; + static CPressureUnit mmhg(QT_TRANSLATE_NOOP("CMeasurementUnit", "millimeter of mercury"), "mmHg", 860.142806); + return mmhg; + } + + /*! + * \brief All units + * \return + */ + static const QList &allUnits() + { + static QList u; + if (u.isEmpty()) + { + u.append(CPressureUnit::bar()); + u.append(CPressureUnit::hPa()); + u.append(CPressureUnit::inHg()); + u.append(CPressureUnit::mmHg()); + u.append(CPressureUnit::mbar()); + u.append(CPressureUnit::psi()); + } + return u; + } + +protected: + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString unitName; + argument >> unitName; + (*this) = CMeasurementUnit::unitFromSymbol(unitName); } }; @@ -450,55 +702,36 @@ public: */ class CTemperatureUnit : public CMeasurementUnit { -private: - double m_conversionOffsetToSi; private: /*! * Constructor temperature unit * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param temperatureOffsetToSI - * \param mulitplier + * \param symbol + * \param factor + * \param offset * \param displayDigits * \param epsilon */ - CTemperatureUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, double temperatureOffsetToSI = 0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "temperature", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon), m_conversionOffsetToSi(temperatureOffsetToSI) {} -protected: - /*! - * \brief Convert to SI conversion unit, specific for temperature - * \param value - * \return - */ - virtual double conversionToSiConversionUnit(double value) const; - - /*! - * \brief Convert from SI conversion unit, specific for temperature - * \param value - * \return - */ - virtual double conversionFromSiConversionUnit(double value) const; + CTemperatureUnit(const QString &name, const QString &symbol, double factor, double offset, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, offset, displayDigits, epsilon) {} public: /*! - * \brief Copy constructor - * \param otherUnit + * Default constructor, required for Qt Metasystem */ - CTemperatureUnit(const CTemperatureUnit &otherUnit) : CMeasurementUnit(otherUnit), m_conversionOffsetToSi(otherUnit.m_conversionOffsetToSi) {} + CTemperatureUnit() : CMeasurementUnit(defaultUnit()) {} /*! - * Assigment operator + * \brief Copy constructor + * \param other */ - CTemperatureUnit &operator =(const CTemperatureUnit &otherUnit) - { - if (this == &otherUnit) return *this; // Same object? Yes, so skip assignment, and just return *this - CMeasurementUnit::operator = (otherUnit); - this->m_conversionOffsetToSi = otherUnit.m_conversionOffsetToSi; - return (*this); - } + CTemperatureUnit(const CTemperatureUnit &other) : CMeasurementUnit(other) {} + + /*! + * \brief Default unit + * \return + */ + static const CTemperatureUnit &defaultUnit() { return C(); } /*! * \brief Kelvin @@ -506,7 +739,7 @@ public: */ static const CTemperatureUnit &K() { - static CTemperatureUnit K("Kelvin", "K", true, true); + static CTemperatureUnit K(QT_TRANSLATE_NOOP("CMeasurementUnit", "Kelvin"), "K", 1, 273.15); return K; } @@ -516,7 +749,7 @@ public: */ static const CTemperatureUnit &C() { - static CTemperatureUnit C("centigrade", "°C", false, false, 1.0, 273.15); + static CTemperatureUnit C(QT_TRANSLATE_NOOP("CMeasurementUnit", "centigrade"), QT_TRANSLATE_NOOP("CMeasurementUnit", "C"), 1, 0); return C; } @@ -526,9 +759,37 @@ public: */ static const CTemperatureUnit &F() { - static CTemperatureUnit F("Fahrenheit", "°F", false, false, 5.0 / 9.0, 459.67); + static CTemperatureUnit F(QT_TRANSLATE_NOOP("CMeasurementUnit", "Fahrenheit"), QT_TRANSLATE_NOOP("CMeasurementUnit", "F"), 5.0 / 9.0, 32); return F; } + + /*! + * \brief All units + * \return + */ + static const QList &allUnits() + { + static QList u; + if (u.isEmpty()) + { + u.append(CTemperatureUnit::C()); + u.append(CTemperatureUnit::F()); + u.append(CTemperatureUnit::K()); + } + return u; + } + +protected: + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString unitName; + argument >> unitName; + (*this) = CMeasurementUnit::unitFromSymbol(unitName); + } }; /*! @@ -538,25 +799,33 @@ class CSpeedUnit : public CMeasurementUnit { private: /*! - * Constructor * \brief Speed unit constructor * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CSpeedUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "speed", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CSpeedUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + public: /*! - * Constructor, allows to implement methods in base class - * \param otherUnit + * Default constructor, required for Qt Metasystem */ - CSpeedUnit(const CSpeedUnit &otherUnit) : CMeasurementUnit(otherUnit) {} + CSpeedUnit() : CMeasurementUnit(defaultUnit()) {} + + /*! + * Constructor, allows to implement methods in base class + * \param other + */ + CSpeedUnit(const CSpeedUnit &other) : CMeasurementUnit(other) {} + + /*! + * Default unit + * \return + */ + static const CSpeedUnit &defaultUnit() { return m_s(); } /*! * \brief Meter/second m/s @@ -564,7 +833,7 @@ public: */ static const CSpeedUnit &m_s() { - static CSpeedUnit ms("meters/second", "m/s", true, false); + static CSpeedUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "meter per second"), "m/s", 1); return ms; } @@ -574,7 +843,7 @@ public: */ static const CSpeedUnit &kts() { - static CSpeedUnit kts("knot", "kts", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); + static CSpeedUnit kts(QT_TRANSLATE_NOOP("CMeasurementUnit", "knot"), "kts", 1852.0 / 3600.0, 1); return kts; } @@ -584,7 +853,7 @@ public: */ static const CSpeedUnit &NM_h() { - static CSpeedUnit NMh("nautical miles/hour", "NM/h", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); + static CSpeedUnit NMh(QT_TRANSLATE_NOOP("CMeasurementUnit", "nautical mile per hour"), "NM/h", 1852.0 / 3600.0, 1); return NMh; } @@ -594,7 +863,7 @@ public: */ static const CSpeedUnit &ft_s() { - static CSpeedUnit fts("feet/seconds", "ft/s", false, false, 0.3048, CMeasurementPrefix::One(), 0); + static CSpeedUnit fts(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot per second"), "ft/s", 0.3048, 0); return fts; } @@ -604,7 +873,7 @@ public: */ static const CSpeedUnit &ft_min() { - static CSpeedUnit ftmin("feet/minute", "ft/min", false, false, 0.3048 / 60.0, CMeasurementPrefix::One(), 0); + static CSpeedUnit ftmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot per minute"), "ft/min", 0.3048 / 60.0, 0); return ftmin; } @@ -614,9 +883,40 @@ public: */ static const CSpeedUnit &km_h() { - static CSpeedUnit kmh("kilometers/hour", "km/h", false, false, 1.0 / 3.6, CMeasurementPrefix::One(), 1); + static CSpeedUnit kmh(QT_TRANSLATE_NOOP("CMeasurementUnit", "kilometer per hour"), "km/h", 1.0 / 3.6, 1); return kmh; } + + /*! + * \brief All units + * \return + */ + static const QList &allUnits() + { + static QList u; + if (u.isEmpty()) + { + u.append(CSpeedUnit::ft_min()); + u.append(CSpeedUnit::ft_s()); + u.append(CSpeedUnit::km_h()); + u.append(CSpeedUnit::kts()); + u.append(CSpeedUnit::m_s()); + u.append(CSpeedUnit::NM_h()); + } + return u; + } + +protected: + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString unitName; + argument >> unitName; + (*this) = CMeasurementUnit::unitFromSymbol(unitName); + } }; /*! @@ -626,26 +926,65 @@ class CTimeUnit : public CMeasurementUnit { private: /*! - * Constructor * \brief Time unit constructor * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CTimeUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "time", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CTimeUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + + /*! + * \brief Time unit constructor + * \param name + * \param symbol + * \param prefix + * \param base + * \param displayDigits + * \param epsilon + */ + CTimeUnit(const QString &name, const QString &symbol, const CMeasurementPrefix &prefix, const CTimeUnit &base, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, base, prefix, displayDigits, epsilon) {} + + /*! + * \brief Time unit constructor + * \param name + * \param symbol + * \param converter + * \param displayDigits + * \param epsilon + */ + CTimeUnit(const QString &name, const QString &symbol, Converter *converter, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, converter, displayDigits, epsilon) {} + public: + /*! + * Default constructor, required for Qt Metasystem + */ + CTimeUnit() : CMeasurementUnit(defaultUnit()) {} /*! * Constructor, allows to implement methods in base class - * \param otherUnit + * \param other */ - CTimeUnit(const CTimeUnit &otherUnit) : CMeasurementUnit(otherUnit) {} + CTimeUnit(const CTimeUnit &other) : CMeasurementUnit(other) {} + + /*! + * Default unit + * \return + */ + static const CTimeUnit &defaultUnit() { return s(); } + + /*! + * \brief Override for subdivisional units. + * \param value + * \param digits + * \param i18n + * \return + */ + virtual QString makeRoundedQStringWithUnit(double value, int digits = -1, bool i18n = false) const; /*! * \brief Second s @@ -653,7 +992,7 @@ public: */ static const CTimeUnit &s() { - static CTimeUnit s("second", "s", true, true, 1, CMeasurementPrefix::None(), 1); + static CTimeUnit s(QT_TRANSLATE_NOOP("CMeasurementUnit", "second"), "s", 1, 1); return s; } @@ -663,7 +1002,7 @@ public: */ static const CTimeUnit &ms() { - static CTimeUnit ms("millisecond", "ms", true, false, 1E-03, CMeasurementPrefix::m(), 0); + static CTimeUnit ms(QT_TRANSLATE_NOOP("CMeasurementUnit", "millisecond"), "ms", CMeasurementPrefix::m(), s(), 0); return ms; } @@ -673,7 +1012,7 @@ public: */ static const CTimeUnit &h() { - static CTimeUnit h("hour", "h", false, false, 3600, CMeasurementPrefix::None(), 1); + static CTimeUnit h(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour"), "h", 3600, 1); return h; } @@ -683,7 +1022,7 @@ public: */ static const CTimeUnit &min() { - static CTimeUnit min("minute", "min", false, false, 60, CMeasurementPrefix::None(), 2); + static CTimeUnit min(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute"), "min", 60, 2); return min; } @@ -693,10 +1032,72 @@ public: */ static const CTimeUnit &d() { - static CTimeUnit day("day", "d", false, false, 3600 * 24, CMeasurementPrefix::None(), 1); + static CTimeUnit day(QT_TRANSLATE_NOOP("CMeasurementUnit", "day"), "d", 3600 * 24, 1); return day; } + /*! + * \brief Hours, minutes, seconds + */ + static const CTimeUnit &hms() + { + static CTimeUnit hms(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour, minute, second"), "hms", new SubdivisionConverter2<60, 100, 60, 100>(3600), 4); + return hms; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1h%L2m%L3s"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%-L1h%L2m%L3s"); + } + + /*! + * \brief Hours, minutes + */ + static const CTimeUnit &hrmin() + { + static CTimeUnit hrmin(QT_TRANSLATE_NOOP("CMeasurementUnit", "hour, minute"), "hm", new SubdivisionConverter<60, 100>(3600), 3); + return hrmin; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1h%L2m"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1h%L2m"); + } + + /*! + * \brief Minutes, seconds + */ + static const CTimeUnit &minsec() + { + static CTimeUnit minsec(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute, second"), "minsec", new SubdivisionConverter<60, 100>(60), 2); + return minsec; + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "%L1m%L2s"); + (void)QT_TRANSLATE_NOOP("CMeasurementUnit", "-%L1m%L2s"); + } + + /*! + * \brief All units + * \return + */ + static const QList &allUnits() + { + static QList u; + if (u.isEmpty()) + { + u.append(CTimeUnit::d()); + u.append(CTimeUnit::h()); + u.append(CTimeUnit::min()); + u.append(CTimeUnit::ms()); + u.append(CTimeUnit::s()); + } + return u; + } + +protected: + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString unitName; + argument >> unitName; + (*this) = CMeasurementUnit::unitFromSymbol(unitName); + } }; /*! @@ -706,25 +1107,33 @@ class CAccelerationUnit : public CMeasurementUnit { private: /*! - * Constructor * \brief Acceleration unit constructor * \param name - * \param unitName - * \param isSiUnit - * \param isSIBaseUnit - * \param conversionFactorToSI - * \param mulitplier + * \param symbol + * \param factor * \param displayDigits * \param epsilon */ - CAccelerationUnit(const QString &name, const QString &unitName, bool isSiUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : - CMeasurementUnit(name, unitName, "time", isSiUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {} + CAccelerationUnit(const QString &name, const QString &symbol, double factor, int displayDigits = 2, double epsilon = 1E-9) : + CMeasurementUnit(name, symbol, factor, displayDigits, epsilon) {} + public: /*! - * Constructor, allows to implement methods in base class - * \param otherUnit + * Default constructor, required for Qt Metasystem */ - CAccelerationUnit(const CAccelerationUnit &otherUnit) : CMeasurementUnit(otherUnit) {} + CAccelerationUnit() : CMeasurementUnit(defaultUnit()) {} + + /*! + * Copy constructor + * \param other + */ + CAccelerationUnit(const CAccelerationUnit &other) : CMeasurementUnit(other) {} + + /*! + * Default unit + * \return + */ + static const CAccelerationUnit &defaultUnit() { return m_s2(); } /*! * \brief Meter/second^2 (m/s^2) @@ -732,7 +1141,7 @@ public: */ static const CAccelerationUnit &m_s2() { - static CAccelerationUnit ms2("meter/second²", "m/s²", true, false, 1, CMeasurementPrefix::None(), 1); + static CAccelerationUnit ms2(QT_TRANSLATE_NOOP("CMeasurementUnit", "meter per second per second"), QT_TRANSLATE_NOOP("CMeasurementUnit", "m/s^2"), 1, 1); return ms2; } @@ -742,11 +1151,49 @@ public: */ static const CAccelerationUnit &ft_s2() { - static CAccelerationUnit fts2("feet/seconds²", "ft/s²", true, false, 3.28084, CMeasurementPrefix::m(), 0); + static CAccelerationUnit fts2(QT_TRANSLATE_NOOP("CMeasurementUnit", "foot per second per second"), QT_TRANSLATE_NOOP("CMeasurementUnit", "ft/s^2"), 3.28084, 0); return fts2; } + + /*! + * \brief All units + * \return + */ + static const QList &allUnits() + { + static QList u; + if (u.isEmpty()) + { + u.append(CAccelerationUnit::ft_s2()); + u.append(CAccelerationUnit::m_s2()); + } + return u; + } + +protected: + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &argument) + { + QString unitName; + argument >> unitName; + (*this) = CMeasurementUnit::unitFromSymbol(unitName); + } }; } // namespace } // namespace + +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CLengthUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAngleUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequencyUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CMassUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressureUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTemperatureUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeedUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTimeUnit) +Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAccelerationUnit) + #endif // guard diff --git a/src/blackmisc/readme.txt b/src/blackmisc/readme.txt new file mode 100644 index 000000000..9f0846c5e --- /dev/null +++ b/src/blackmisc/readme.txt @@ -0,0 +1 @@ +I18N: lupdate -noobsolete blackmisc.pro diff --git a/src/blackmisc/streamable.h b/src/blackmisc/streamable.h new file mode 100644 index 000000000..76f3881d6 --- /dev/null +++ b/src/blackmisc/streamable.h @@ -0,0 +1,201 @@ +#ifndef BLACKMISC_STREAMABLE_H +#define BLACKMISC_STREAMABLE_H + +#include "blackmisc/debug.h" +#include +#include +#include +#include +#include +#include + +namespace BlackMisc { + +/*! + * \brief Base class for streamable value objects. + * Public non-virtual interface with protected virtual implementation. + */ +// Virtual operators: http://stackoverflow.com/a/4571634/356726 +class CStreamable +{ + /*! + * \brief Stream << overload to be used in debugging messages + * \param debug + * \param uc + * \return + */ + friend QDebug operator<<(QDebug debug, const CStreamable &uc) + { + debug << uc.stringForStreaming(); + return debug; + } + + /*! + * \brief Operator << based on text stream + * \param textStream + * \param uc + * \return + */ + friend QTextStream &operator<<(QTextStream &textStream, const CStreamable &uc) + { + textStream << uc.stringForStreaming(); + return textStream; + } + + /*! + * \brief Operator << when there is no debug stream + * \param nodebug + * \param uc + * \return + */ + friend QNoDebug operator<<(QNoDebug nodebug, const CStreamable & /* uc */) + { + return nodebug; + } + + /*! + * \brief Stream operator << for QDataStream + * \param stream + * \param uc + * \return + */ + friend QDataStream &operator<<(QDataStream &stream, const CStreamable &uc) + { + stream << uc.stringForStreaming(); + return stream; + } + + /*! + * \brief Stream operator << for log messages + * \param log + * \param uc + * \return + */ + friend CLogMessage operator<<(CLogMessage log, const CStreamable &uc) + { + log << uc.stringForStreaming(); + return log; + } + + /*! + * \brief Stream operator << for std::cout + * \param ostr + * \param uc + * \return + */ + friend std::ostream &operator<<(std::ostream &ostr, const CStreamable &uc) + { + ostr << uc.stringForStreaming().toStdString(); + return ostr; + } + + /*! + * \brief Unmarshalling operator >>, DBus to object + * \param argument + * \param uc + * \return + */ + friend const QDBusArgument &operator>>(const QDBusArgument &argument, CStreamable &uc) + { + argument.beginStructure(); + uc.unmarshallFromDbus(argument); + argument.endStructure(); + return argument; + } + + /*! + * \brief Marshalling operator <<, object to DBus + * \param argument + * \param pq + * \return + */ + friend QDBusArgument &operator<<(QDBusArgument &argument, const CStreamable &uc) + { + argument.beginStructure(); + uc.marshallToDbus(argument); + argument.endStructure(); + return argument; + } + +public: + /*! + * \brief Virtual destructor + */ + virtual ~CStreamable() {} + + /*! + * \brief Cast as QString + * \bool i18n + */ + QString toQString(bool i18n = false) const + { + return this->convertToQString(i18n); + } + +protected: + /*! + * \brief Default constructor + */ + CStreamable() {} + + /*! + * \brief String for streaming operators + * \return + */ + virtual QString stringForStreaming() const + { + // simplest default implementation requires only one method + return this->convertToQString(); + } + + /*! + * \brief String for QString conversion + * \param i18n + * \return + */ + virtual QString convertToQString(bool i18n = false) const = 0; + + /*! + * \brief Stream to DBus + * \param argument + */ + virtual void marshallToDbus(QDBusArgument &) const = 0; + + /*! + * \brief Stream from DBus + * \param argument + */ + virtual void unmarshallFromDbus(const QDBusArgument &) = 0; +}; + +/*! + * Non-member non-friend operator for streaming T objects to QDBusArgument. + * Needed because we can't rely on the friend operator in some cases due to + * an unrelated template for streaming Container in QtDBus/qdbusargument.h + * which matches more types than it can actually handle. + * \param argument + * \param uc + */ +template typename std::enable_if::value, QDBusArgument>::type const& +operator>>(const QDBusArgument &argument, T &uc) +{ + return argument >> static_cast(uc); +} + +/*! + * Non-member non-friend operator for streaming T objects from QDBusArgument. + * Needed because we can't rely on the friend operator in some cases due to + * an unrelated template for streaming Container in QtDBus/qdbusargument.h + * which matches more types than it can actually handle. + * \param argument + * \param uc + */ +template typename std::enable_if::value, QDBusArgument>::type& +operator<<(QDBusArgument &argument, T &uc) +{ + return argument << static_cast(uc); +} + +} // namespace + +#endif // guard diff --git a/src/blackmisc/translations/blackmisc_i18n_de.qm b/src/blackmisc/translations/blackmisc_i18n_de.qm new file mode 100644 index 000000000..44c59b835 Binary files /dev/null and b/src/blackmisc/translations/blackmisc_i18n_de.qm differ diff --git a/src/blackmisc/translations/blackmisc_i18n_de.ts b/src/blackmisc/translations/blackmisc_i18n_de.ts new file mode 100644 index 000000000..b1ddd7165 --- /dev/null +++ b/src/blackmisc/translations/blackmisc_i18n_de.ts @@ -0,0 +1,228 @@ + + + + + Aviation + + + magnetic + Magnetischer Kurs + missweisend + + + + true + Rechtweisend Kurs (TH) + rechtweisend + + + + CMeasurementUnit + + + meter + Meter + + + + nautical mile + Nautische Meile + + + + foot + Fuß + + + + kilometer + Kilometer + + + + centimeter + Zentimeter + + + + mile + Meile + + + + mile(statute) + Statute Meile + + + + radian + Bogenmaß + + + + degree + Grad + + + + deg + ° + + + + segadecimal degree + Segadezimal + + + + kilogram + + + + + gram + + + + + tonne + + + + + pound + + + + + pascal + + + + + hectopascal + + + + + pounds per square inch + + + + + bar + + + + + millibar + + + + + + inch of mercury 0C + Inch Hg bei 0°C + + + + Kelvin + + + + + centigrade + Grad Celcsius + + + + C + °C + + + + Fahrenheit + Fahrenheit + + + + F + °F + + + + meters/second + Meter/Sekunde + + + + knot + Knoten + + + + nautical miles/hour + + + + + feet/second + + + + + feet/minute + Fuß/Minute + + + + kilometers/hour + Kilometer/Stunde + + + + second + Sekunde + + + + millisecond + Millisekunde + + + + hour + Stunde + + + + minute + Minute + + + + day + Tag + + + + meters/second^2 + Meter/Sekunde² + + + + m/s^2 + m/s² + + + + ft/s^2 + ft/s² + + + + feet/second^2 + Fuß/Sekunde² + + + diff --git a/src/blackmisc/translations/blackmisc_i18n_en.qm b/src/blackmisc/translations/blackmisc_i18n_en.qm new file mode 100644 index 000000000..0d750e7d9 Binary files /dev/null and b/src/blackmisc/translations/blackmisc_i18n_en.qm differ diff --git a/src/blackmisc/translations/blackmisc_i18n_en.ts b/src/blackmisc/translations/blackmisc_i18n_en.ts new file mode 100644 index 000000000..99ff1dfef --- /dev/null +++ b/src/blackmisc/translations/blackmisc_i18n_en.ts @@ -0,0 +1,226 @@ + + + + + Aviation + + + magnetic + + + + + true + + + + + CMeasurementUnit + + + meter + + + + + nautical mile + + + + + foot + + + + + kilometer + + + + + centimeter + + + + + mile + + + + + mile(statute) + + + + + radian + + + + + degree + + + + + deg + ° + + + + segadecimal degree + + + + + kilogram + + + + + gram + + + + + tonne + + + + + pound + + + + + pascal + + + + + hectopascal + + + + + pounds per square inch + + + + + bar + + + + + millibar + + + + + + inch of mercury 0C + + + + + Kelvin + + + + + centigrade + + + + + C + °C + + + + Fahrenheit + + + + + F + °F + + + + meters/second + + + + + knot + + + + + nautical miles/hour + + + + + feet/second + + + + + feet/minute + + + + + kilometers/hour + + + + + second + + + + + millisecond + + + + + hour + + + + + minute + + + + + day + + + + + meters/second^2 + + + + + m/s^2 + m/s² + + + + ft/s^2 + ft/s² + + + + feet/second^2 + + + + diff --git a/src/blackmisc/translations/blackmisc_i18n_fr.qm b/src/blackmisc/translations/blackmisc_i18n_fr.qm new file mode 100644 index 000000000..836d44dd2 Binary files /dev/null and b/src/blackmisc/translations/blackmisc_i18n_fr.qm differ diff --git a/src/blackmisc/translations/blackmisc_i18n_fr.ts b/src/blackmisc/translations/blackmisc_i18n_fr.ts new file mode 100644 index 000000000..ca61ab8a9 --- /dev/null +++ b/src/blackmisc/translations/blackmisc_i18n_fr.ts @@ -0,0 +1,226 @@ + + + + + Aviation + + + magnetic + + + + + true + + + + + CMeasurementUnit + + + meter + mètre + + + + nautical mile + nautique mile + + + + foot + foot + + + + kilometer + kilomètre + + + + centimeter + + + + + mile + + + + + mile(statute) + + + + + radian + + + + + degree + degré + + + + deg + ° + + + + segadecimal degree + segadecimal + + + + kilogram + + + + + gram + + + + + tonne + + + + + pound + + + + + pascal + + + + + hectopascal + + + + + pounds per square inch + + + + + bar + + + + + millibar + + + + + + inch of mercury 0C + + + + + Kelvin + + + + + centigrade + + + + + C + °C + + + + Fahrenheit + Fahrenheit + + + + F + °F + + + + meters/second + + + + + knot + + + + + nautical miles/hour + + + + + feet/second + + + + + feet/minute + + + + + kilometers/hour + + + + + second + + + + + millisecond + + + + + hour + + + + + minute + + + + + day + + + + + meters/second^2 + + + + + m/s^2 + m/s² + + + + ft/s^2 + ft/s² + + + + feet/second^2 + + + + diff --git a/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro b/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro new file mode 100644 index 000000000..164fa3cf9 --- /dev/null +++ b/src/blackmisc_cpp2xml/blackmisc_cpp2xml.pro @@ -0,0 +1,19 @@ +QT += core dbus + +TARGET = blackmisc_cpp2xml +TEMPLATE = lib + +CONFIG += plugin c++11 + +DEPENDPATH += . ../../src/blackmisc +INCLUDEPATH += . ../../src + +LIBS += -L../../lib -lblackmisc + +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a + +DESTDIR = ../../bin + +HEADERS += *.h +SOURCES += *.cpp diff --git a/src/blackmisc_cpp2xml/blackmiscplugin.cpp b/src/blackmisc_cpp2xml/blackmiscplugin.cpp new file mode 100644 index 000000000..93beffe00 --- /dev/null +++ b/src/blackmisc_cpp2xml/blackmiscplugin.cpp @@ -0,0 +1,15 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmiscplugin.h" +#include "blackmisc/blackmiscfreefunctions.h" + +/* + * Register all metatypes + */ +void BlackmiscPlugin::registerMetaTypes() +{ + BlackMisc::registerMetadata(); +} diff --git a/src/blackmisc_cpp2xml/blackmiscplugin.h b/src/blackmisc_cpp2xml/blackmiscplugin.h new file mode 100644 index 000000000..b57584559 --- /dev/null +++ b/src/blackmisc_cpp2xml/blackmiscplugin.h @@ -0,0 +1,28 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_CPP2XML_H +#define BLACKMISC_CPP2XML_H + +#include +#include + +/*! + * \brief Plugin to register all relevant blackmisc classes for QDBusCpp2XmlPlugin + */ +class BlackmiscPlugin : public QObject, public QDBusCpp2XmlPlugin +{ + Q_OBJECT + Q_INTERFACES(QDBusCpp2XmlPlugin) + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.DBus.Cpp2XmlPlugin") + +public: + /*! + * \brief Register Metatypes + */ + virtual void registerMetaTypes(); +}; + +#endif // BLACKMISC_CPP2XML_H diff --git a/src/blackx/CMakeLists.txt b/src/blackx/CMakeLists.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/driver/fs9/driver_fs9.pro b/src/driver/fs9/driver_fs9.pro index 236b65797..ed91f1d0a 100644 --- a/src/driver/fs9/driver_fs9.pro +++ b/src/driver/fs9/driver_fs9.pro @@ -1,6 +1,6 @@ TARGET = bb_driver_fs9 TEMPLATE = lib -CONFIG += dll +CONFIG += dll c++11 INCLUDEPATH += .. ../../ diff --git a/src/driver/fsx/driver_fsx.pro b/src/driver/fsx/driver_fsx.pro index 81ecfc425..98f2cfdc8 100644 --- a/src/driver/fsx/driver_fsx.pro +++ b/src/driver/fsx/driver_fsx.pro @@ -1,6 +1,6 @@ TARGET = bb_driver_fsx TEMPLATE = lib -CONFIG += dll +CONFIG += dll c++11 INCLUDEPATH += .. ../../ diff --git a/src/driver/xplane/driver_xplane.pro b/src/driver/xplane/driver_xplane.pro index 7116b9cf8..21a93cfe0 100644 --- a/src/driver/xplane/driver_xplane.pro +++ b/src/driver/xplane/driver_xplane.pro @@ -1,6 +1,6 @@ TARGET = bb_driver_xplane TEMPLATE = lib -CONFIG += dll +CONFIG += dll c++11 INCLUDEPATH += .. ../../ diff --git a/tests/blackcore/test_blackcore.pro b/tests/blackcore/test_blackcore.pro index d4076c16a..1a681b773 100644 --- a/tests/blackcore/test_blackcore.pro +++ b/tests/blackcore/test_blackcore.pro @@ -1,9 +1,9 @@ -QT += core testlib +QT += core testlib dbus TARGET = test_blackcore TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src diff --git a/tests/blackmisc/test_blackmisc.pro b/tests/blackmisc/test_blackmisc.pro index dbbab21ba..11fb266df 100644 --- a/tests/blackmisc/test_blackmisc.pro +++ b/tests/blackmisc/test_blackmisc.pro @@ -1,9 +1,9 @@ -QT += core testlib +QT += core testlib dbus TARGET = test_blackmisc TEMPLATE = app -CONFIG += console +CONFIG += console c++11 CONFIG -= app_bundle DEPENDPATH += . ../../src diff --git a/tests/blackmisc/testaviation.cpp b/tests/blackmisc/testaviation.cpp index 4652a9100..191c5bac6 100644 --- a/tests/blackmisc/testaviation.cpp +++ b/tests/blackmisc/testaviation.cpp @@ -24,9 +24,9 @@ CTestAviation::CTestAviation(QObject *parent): QObject(parent) */ void CTestAviation::headingBasics() { - CHeading h1(180, true, CAngleUnit::deg()); - CHeading h2(180, false, CAngleUnit::deg()); - CHeading h3(181, true, CAngleUnit::deg()); + CHeading h1(180, CHeading::Magnetic, CAngleUnit::deg()); + CHeading h2(180, CHeading::True, CAngleUnit::deg()); + CHeading h3(181, CHeading::Magnetic, CAngleUnit::deg()); CAngle a1(200, CAngleUnit::deg()); CHeading h4; h4 = h1; @@ -37,21 +37,11 @@ void CTestAviation::headingBasics() QVERIFY2(h4 == h1, "Values shall be equal"); h1 -= h1; - QVERIFY2(h1.unitValueToDouble() == 0, "Value shall be 0"); + QVERIFY2(h1.value() == 0, "Value shall be 0"); // h4 = h1 + h2; does not work, because misleading h2 += h2; // add just angle - QVERIFY2(h2.unitValueToDouble() == 360, "Value shall be 360"); -} - -/* - * Vertical positions - */ -void CTestAviation::verticalPosition() -{ - CAviationVerticalPositions vp1 = CAviationVerticalPositions::fromAltitudeAndElevationInFt(10000.0, 3000.0); - CAviationVerticalPositions vp2 = vp1; - QVERIFY2(vp1 == vp2, "Values shall be equal"); + QVERIFY2(h2.value() == 360, "Value shall be 360"); } /* diff --git a/tests/blackmisc/testaviation.h b/tests/blackmisc/testaviation.h index 45ffbd2f0..b3c153ee1 100644 --- a/tests/blackmisc/testaviation.h +++ b/tests/blackmisc/testaviation.h @@ -8,7 +8,6 @@ #include "blackmisc/pqconstants.h" #include "blackmisc/avheading.h" -#include "blackmisc/avverticalpositions.h" #include "blackmisc/aviocomsystem.h" #include "blackmisc/avionavsystem.h" #include "blackmisc/aviotransponder.h" @@ -36,10 +35,6 @@ private slots: * \brief Basic unit tests for physical units */ void headingBasics(); - /*! - * \brief Vertical positions - */ - void verticalPosition(); /*! * \brief COM and NAV units */ diff --git a/tests/blackmisc/testgeo.cpp b/tests/blackmisc/testgeo.cpp index 6ea4cc34d..8c5b5b21b 100644 --- a/tests/blackmisc/testgeo.cpp +++ b/tests/blackmisc/testgeo.cpp @@ -14,7 +14,7 @@ void CTestGeo::geoBasics() CLatitude lati(10, CAngleUnit::deg()); QVERIFY2(lati * 2 == lati + lati, "Latitude addition should be equal"); lati += CLatitude(20, CAngleUnit::deg()); - QVERIFY2(lati.unitValueToDoubleRounded() == 30.0, "Latitude should be 30 degrees"); + QVERIFY2(lati.valueRounded() == 30.0, "Latitude should be 30 degrees"); double lat = 27.999999, lon = 86.999999, h = 8820.999999; // Mt Everest CCoordinateGeodetic startGeoVec(lat, lon, h); @@ -28,7 +28,7 @@ void CTestGeo::geoBasics() CCoordinateEcef ecefReconvert = CCoordinateTransformation::toEcef(nedVec); // check against rounded reconvert - QVERIFY2(mediumEcefVec.roundedVector() == ecefReconvert.roundedVector(), "Reconverted geo vector should be equal"); + QVERIFY2(mediumEcefVec.rounded() == ecefReconvert.rounded(), "Reconverted geo vector should be equal"); } } // namespace diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index 6dabc06cb..b082256d7 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -15,8 +15,6 @@ namespace BlackMiscTest */ void CTestPhysicalQuantities::unitsBasics() { - QVERIFY2(CMeasurementPrefix::k() > CMeasurementPrefix::h(), "kilo > hecto"); - // some tests on units CLengthUnit du1 = CLengthUnit::m(); // Copy CLengthUnit du2 = CLengthUnit::m(); // Copy @@ -25,7 +23,6 @@ void CTestPhysicalQuantities::unitsBasics() du2 = CLengthUnit::m(); // Copy QVERIFY2(du1 == du2, "Compare by value 2"); QVERIFY2(CLengthUnit::m() == CLengthUnit::m(), "Compare by value"); - QVERIFY2(CMeasurementPrefix::h() < CMeasurementPrefix::M(), "hecto < mega"); CFrequencyUnit fu1 = CFrequencyUnit::Hz(); QVERIFY2(fu1 != du1, "Hz must not be meter"); @@ -54,12 +51,12 @@ void CTestPhysicalQuantities::lengthBasics() // epsilon tests d1 = d2; // both in same unit - d1.addUnitValue(d1.getUnit().getEpsilon()); // this should be still the same + d1.addValueSameUnit(d1.getUnit().getEpsilon() / 2.0); // this should be still the same QVERIFY2(d1 == d2, "Epsilon: 100cm + epsilon shall be 100cm"); QVERIFY2(!(d1 != d2), "Epsilon: 100cm + epsilon shall be still 100cm"); QVERIFY2(!(d1 > d2), "d1 shall not be greater"); - d1.addUnitValue(d1.getUnit().getEpsilon()); // now over epsilon threshold + d1.addValueSameUnit(d1.getUnit().getEpsilon()); // now over epsilon threshold QVERIFY2(d1 != d2, "Epsilon exceeded: 100 cm + 2 epsilon shall not be 100cm"); QVERIFY2(d1 > d2, "d1 shall be greater"); } @@ -82,8 +79,8 @@ void CTestPhysicalQuantities::frequencyTests() { CFrequency f1(1, CFrequencyUnit::MHz()); QVERIFY2(f1.valueRounded(CFrequencyUnit::kHz(), 2) == 1000, "Mega is 1000kHz"); - QVERIFY2(f1.unitValueToDouble() == 1 , "1MHz"); - QVERIFY2(f1.convertedSiValueToDouble() == 1000000 , "1E6 Hz"); + QVERIFY2(f1.value() == 1 , "1MHz"); + QVERIFY2(f1.value(CFrequencyUnit::defaultUnit()) == 1000000 , "1E6 Hz"); CFrequency f2(CMeasurementPrefix::M().toDouble(), CFrequencyUnit::Hz()) ; // 1 Megahertz QVERIFY2(f1 == f2 , "MHz is 1E6 Hz"); } @@ -96,10 +93,13 @@ void CTestPhysicalQuantities::angleTests() CAngle a1(180, CAngleUnit::deg()); CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad()); CAngle a3(35.4336, CAngleUnit::sexagesimalDeg()); // 35.72666 + CAngle a4(35.436, CAngleUnit::sexagesimalDegMin()); // 35.72666 + CAngle a5(-60.3015, CAngleUnit::sexagesimalDeg()); // negative angles = west longitude or south latitude a2.switchUnit(CAngleUnit::deg()); - QVERIFY2(a2.unitValueToInteger() == 270, qPrintable(QString("1.5Pi should be 270deg, not %1 deg").arg(a2.unitValueToInteger()))); QVERIFY2(a1.piFactor() == 1, qPrintable(QString("Pi should be 1PI, not %1").arg(a1.piFactor()))); QVERIFY2(a3.valueRounded(CAngleUnit::deg()) == 35.73, "Expecting 35.73"); + QVERIFY2(a4.valueRounded(CAngleUnit::deg()) == 35.73, "Expecting 35.73"); + QVERIFY2(a5.valueRounded(CAngleUnit::deg(), 4) == -60.5042, "Expecting -60.5042"); } /* @@ -108,11 +108,11 @@ void CTestPhysicalQuantities::angleTests() void CTestPhysicalQuantities::massTests() { CMass w1(1000, CMassUnit::kg()); - CMass w2(w1.unitValueToInteger(), CMassUnit::kg()); - w2.switchUnit(CMassUnit::t()); - QVERIFY2(w2.unitValueToInteger() == 1, "1tonne shall be 1000kg"); + CMass w2(w1.value(), CMassUnit::kg()); + w2.switchUnit(CMassUnit::tonne()); + QVERIFY2(w2.value() == 1, "1tonne shall be 1000kg"); w2.switchUnit(CMassUnit::lb()); - QVERIFY2(w2.unitValueToDoubleRounded(2) == 2204.62, "1tonne shall be 2204pounds"); + QVERIFY2(w2.valueRounded(2) == 2204.62, "1tonne shall be 2204pounds"); QVERIFY2(w1 == w2, "Masses shall be equal"); } @@ -123,14 +123,12 @@ void CTestPhysicalQuantities::pressureTests() { CPressure p1(1013.25, CPressureUnit::hPa()); CPressure p2(29.92, CPressureUnit::inHg()); - CPressure p3(29.92, CPressureUnit::inHgFL()); CPressure p4(p1); p4.switchUnit(CPressureUnit::mbar()); // does not match exactly QVERIFY2(p1 != p2, "Standard pressure test little difference"); - QVERIFY2(p1 == p3, "Standard pressure test matching"); - QVERIFY2(p1.unitValueToDouble() == p4.unitValueToDouble(), "mbar/hPa test"); + QVERIFY2(p1.value() == p4.value(), "mbar/hPa test"); } /* @@ -142,19 +140,25 @@ void CTestPhysicalQuantities::temperatureTests() CTemperature t2(1, CTemperatureUnit::F()); // 1F CTemperature t3(220.15, CTemperatureUnit::F()); CTemperature t4(10, CTemperatureUnit::F()); - QVERIFY2(t1.convertedSiValueToDoubleRounded() == 273.15, qPrintable(QString("0C shall be 273.15K, not %1 K").arg(t1.convertedSiValueToDoubleRounded()))); + QVERIFY2(t1.valueRounded(CTemperatureUnit::K()) == 273.15, qPrintable(QString("0C shall be 273.15K, not %1 K").arg(t1.valueRounded(CTemperatureUnit::K())))); QVERIFY2(t2.valueRounded(CTemperatureUnit::C()) == -17.22, qPrintable(QString("1F shall be -17.22C, not %1 C").arg(t2.valueRounded(CTemperatureUnit::C())))); QVERIFY2(t3.valueRounded(CTemperatureUnit::C()) == 104.53, qPrintable(QString("220.15F shall be 104.53C, not %1 C").arg(t3.valueRounded(CTemperatureUnit::C())))); QVERIFY2(t4.valueRounded(CTemperatureUnit::K()) == 260.93, qPrintable(QString("10F shall be 260.93K, not %1 K").arg(t4.valueRounded(CTemperatureUnit::K())))); } /* - * Temperature tests + * Time tests */ void CTestPhysicalQuantities::timeTests() { CTime t1(1, CTimeUnit::h()); - QVERIFY2(t1.convertedSiValueToInteger() == 3600, "1hour shall be 3600s"); + CTime t2(1.5, CTimeUnit::h()); + CTime t3(1.25, CTimeUnit::min()); + CTime t4(1.0101, CTimeUnit::hms()); + QVERIFY2(t1.value(CTimeUnit::defaultUnit()) == 3600, "1hour shall be 3600s"); + QVERIFY2(t2.value(CTimeUnit::hrmin()) == 1.30, "1.5hour shall be 1h30m"); + QVERIFY2(t3.value(CTimeUnit::minsec()) == 1.15, "1.25min shall be 1m15s"); + QVERIFY2(t4.value(CTimeUnit::s()) == 3661, "1h01m01s shall be 3661s"); } /* @@ -163,13 +167,13 @@ void CTestPhysicalQuantities::timeTests() void CTestPhysicalQuantities::accelerationTests() { CLength oneMeter(1, CLengthUnit::m()); - double ftFactor = oneMeter.switchUnit(CLengthUnit::ft()).unitValueToDouble(); + double ftFactor = oneMeter.switchUnit(CLengthUnit::ft()).value(); CAcceleration a1(10.0, CAccelerationUnit::m_s2()); CAcceleration a2(a1); a1.switchUnit(CAccelerationUnit::ft_s2()); QVERIFY2(a1 == a2, "Accelerations should be similar"); - QVERIFY2(BlackMisc::Math::CMath::round(a1.unitValueToDouble() * ftFactor, 6) == a2.unitValueToDoubleRounded(6), + QVERIFY2(BlackMisc::Math::CMath::round(a1.value() * ftFactor, 6) == a2.valueRounded(6), "Numerical values should be equal"); } @@ -180,13 +184,13 @@ void CTestPhysicalQuantities::memoryTests() { CLength *c = new CLength(100, CLengthUnit::m()); c->switchUnit(CLengthUnit::NM()); - QVERIFY2(c->getUnit() == CLengthUnit::NM() && c->getConversionSiUnit() == CLengthUnit::m(), + QVERIFY2(c->getUnit() == CLengthUnit::NM() && CLengthUnit::defaultUnit() == CLengthUnit::m(), "Testing distance units failed"); delete c; CAngle *a = new CAngle(100, CAngleUnit::rad()); a->switchUnit(CAngleUnit::deg()); - QVERIFY2(a->getUnit() == CAngleUnit::deg() && c->getConversionSiUnit() == CAngleUnit::rad(), + QVERIFY2(a->getUnit() == CAngleUnit::deg() && CAngleUnit::defaultUnit() == CAngleUnit::deg(), "Testing angle units failed"); delete a; } @@ -196,7 +200,7 @@ void CTestPhysicalQuantities::memoryTests() */ void CTestPhysicalQuantities::basicArithmetic() { - CPressure p1 = CPhysicalQuantitiesConstants::InternationalStandardSeaLevelPressure(); + CPressure p1 = CPhysicalQuantitiesConstants::ISASeaLevelPressure(); CPressure p2(p1); p2 *= 2.0; CPressure p3 = p1 + p1; @@ -204,7 +208,7 @@ void CTestPhysicalQuantities::basicArithmetic() p3 /= 2.0; QVERIFY2(p3 == p1, "Pressure needs to be the same (1time)"); p3 = p3 - p3; - QVERIFY2(p3.unitValueToDouble() == 0, "Value needs to be zero"); + QVERIFY2(p3.value() == 0, "Value needs to be zero"); p3 = CPressure(1013, CPressureUnit::hPa()); QVERIFY2(p3 * 1.5 == 1.5 * p3, "Basic commutative test on PQ failed"); }