From f004858fe51aef50ddf7cd792941605b339720e8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 23 Oct 2018 19:38:03 +0200 Subject: [PATCH] implement a direct way to set single or double precision when writing/reading properties using floating point numbers --- src/App/Property.h | 10 ++++++++++ src/App/PropertyGeo.cpp | 8 ++++---- src/App/PropertyStandard.cpp | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/App/Property.h b/src/App/Property.h index 83727038f4..adfabd2de0 100644 --- a/src/App/Property.h +++ b/src/App/Property.h @@ -62,6 +62,7 @@ public: Immutable = 1, // can't modify property ReadOnly = 2, // for property editor Hidden = 3, // for property editor + Single = 4, // for save/load of floating point numbers User1 = 28, // user-defined status User2 = 29, // user-defined status User3 = 30, // user-defined status @@ -143,6 +144,15 @@ public: inline bool isReadOnly() const { return testStatus(App::Property::ReadOnly); } + /// Sets precision of properties using floating point + /// numners to single, the default is double. + void setSinglePrecision(bool single) { + setStatus(App::Property::Single, single); + } + /// Gets precision of properties using floating point numbers + inline bool isSinglePrecision() const { + return testStatus(App::Property::Single); + } //@} /// Returns a new copy of the property (mainly for Undo/Redo and transactions) diff --git a/src/App/PropertyGeo.cpp b/src/App/PropertyGeo.cpp index 9033a077ec..ed09541ff2 100644 --- a/src/App/PropertyGeo.cpp +++ b/src/App/PropertyGeo.cpp @@ -418,7 +418,7 @@ void PropertyVectorList::SaveDocFile (Base::Writer &writer) const Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); str << uCt; - if (writer.getFileVersion() > 0) { + if (!isSinglePrecision()) { for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { str << it->x << it->y << it->z; } @@ -439,7 +439,7 @@ void PropertyVectorList::RestoreDocFile(Base::Reader &reader) uint32_t uCt=0; str >> uCt; std::vector values(uCt); - if (reader.getFileVersion() > 0) { + if (!isSinglePrecision()) { for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { str >> it->x >> it->y >> it->z; } @@ -917,7 +917,7 @@ void PropertyPlacementList::SaveDocFile (Base::Writer &writer) const Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); str << uCt; - if (writer.getFileVersion() > 0) { + if (!isSinglePrecision()) { for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { str << it->getPosition().x << it->getPosition().y << it->getPosition().z << it->getRotation()[0] << it->getRotation()[1] << it->getRotation()[2] << it->getRotation()[3] ; @@ -943,7 +943,7 @@ void PropertyPlacementList::RestoreDocFile(Base::Reader &reader) uint32_t uCt=0; str >> uCt; std::vector values(uCt); - if (reader.getFileVersion() > 0) { + if (!isSinglePrecision()) { for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { Base::Vector3d pos; double q0, q1, q2, q3; diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index c995e34a23..1ea44cead0 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -1380,7 +1380,7 @@ void PropertyFloatList::SaveDocFile (Base::Writer &writer) const Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); str << uCt; - if (writer.getFileVersion() > 0) { + if (!isSinglePrecision()) { for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { str << *it; } @@ -1399,7 +1399,7 @@ void PropertyFloatList::RestoreDocFile(Base::Reader &reader) uint32_t uCt=0; str >> uCt; std::vector values(uCt); - if (reader.getFileVersion() > 0) { + if (!isSinglePrecision()) { for (std::vector::iterator it = values.begin(); it != values.end(); ++it) { str >> *it; }