From ad49408c588dc72c8084bf6678eacdb437340105 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 30 Mar 2013 12:32:53 +0100 Subject: [PATCH] Support to write vector list and float lists in old format, fix issues in property editor, move back to float for curvature type --- src/App/Document.cpp | 3 +- src/App/PropertyGeo.cpp | 14 ++- src/App/PropertyStandard.cpp | 12 ++- src/Base/Writer.cpp | 12 ++- src/Base/Writer.h | 3 + src/Gui/SoFCDB.cpp | 1 - src/Gui/propertyeditor/PropertyItem.cpp | 111 +----------------------- src/Gui/propertyeditor/PropertyItem.h | 37 +------- src/Mod/PartDesign/App/FeatureDraft.cpp | 2 +- src/Mod/Points/App/Points.cpp | 20 +++-- src/Mod/Points/App/Points.h | 8 +- src/Mod/Points/App/Properties.cpp | 4 +- src/Mod/Points/App/Properties.h | 4 +- 13 files changed, 64 insertions(+), 167 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 8bf40b596a..560c917240 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -601,7 +601,8 @@ void Document::Save (Base::Writer &writer) const writer.Stream() << "" << endl; + << App::Application::Config()["BuildRevision"] + << "\" FileVersion=\"" << writer.getFileVersion() << "\">" << endl; PropertyContainer::Save(writer); diff --git a/src/App/PropertyGeo.cpp b/src/App/PropertyGeo.cpp index 3e025c10a2..3196d32b80 100644 --- a/src/App/PropertyGeo.cpp +++ b/src/App/PropertyGeo.cpp @@ -296,8 +296,18 @@ void PropertyVectorList::SaveDocFile (Base::Writer &writer) const Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); str << uCt; - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - str << it->x << it->y << it->z; + if (writer.getFileVersion() > 0) { + for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { + str << it->x << it->y << it->z; + } + } + else { + for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { + float x = (float)it->x; + float y = (float)it->y; + float z = (float)it->z; + str << x << y << z; + } } } diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 2b2f4846e3..b860e6871a 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -1122,8 +1122,16 @@ void PropertyFloatList::SaveDocFile (Base::Writer &writer) const Base::OutputStream str(writer.Stream()); uint32_t uCt = (uint32_t)getSize(); str << uCt; - for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { - str << *it; + if (writer.getFileVersion() > 0) { + for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { + str << *it; + } + } + else { + for (std::vector::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) { + float v = (float)*it; + str << v; + } } } diff --git a/src/Base/Writer.cpp b/src/Base/Writer.cpp index 621893a8a3..875408e8c6 100644 --- a/src/Base/Writer.cpp +++ b/src/Base/Writer.cpp @@ -49,7 +49,7 @@ using namespace zipios; // --------------------------------------------------------------------------- Writer::Writer(void) - : indent(0),forceXML(false) + : indent(0),forceXML(false),fileVersion(1) { indBuf[0] = '\0'; } @@ -98,6 +98,16 @@ bool Writer::isForceXML(void) return forceXML; } +void Writer::setFileVersion(int v) +{ + fileVersion = v; +} + +int Writer::getFileVersion() const +{ + return fileVersion; +} + std::string Writer::addFile(const char* Name,const Base::Persistence *Object) { // always check isForceXML() before requesting a file! diff --git a/src/Base/Writer.h b/src/Base/Writer.h index 083a5174df..f1eb7c3edf 100644 --- a/src/Base/Writer.h +++ b/src/Base/Writer.h @@ -62,6 +62,8 @@ public: void setForceXML(bool on); /// check on state bool isForceXML(void); + void setFileVersion(int); + int getFileVersion() const; /// insert a file as CDATA section in the XML file void insertAsciiFile(const char* FileName); @@ -106,6 +108,7 @@ protected: char indBuf[256]; bool forceXML; + int fileVersion; }; diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 9a5680ab12..80436b7323 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -112,7 +112,6 @@ void Gui::SoFCDB::init() PropertyAngleItem ::init(); PropertyBoolItem ::init(); PropertyVectorItem ::init(); - PropertyDoubleVectorItem ::init(); PropertyMatrixItem ::init(); PropertyPlacementItem ::init(); PropertyEnumItem ::init(); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index c5d8cb9b91..2c97d3f0ee 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -864,7 +864,7 @@ PropertyVectorItem::PropertyVectorItem() QVariant PropertyVectorItem::toString(const QVariant& prop) const { - const Base::Vector3f& value = prop.value(); + const Base::Vector3d& value = prop.value(); QString data = QString::fromAscii("[%1 %2 %3]") .arg(QLocale::system().toString(value.x, 'f', 2)) .arg(QLocale::system().toString(value.y, 'f', 2)) @@ -903,7 +903,7 @@ QWidget* PropertyVectorItem::createEditor(QWidget* parent, const QObject* /*rece void PropertyVectorItem::setEditorData(QWidget *editor, const QVariant& data) const { QLineEdit* le = qobject_cast(editor); - const Base::Vector3f& value = data.value(); + const Base::Vector3d& value = data.value(); QString text = QString::fromAscii("[%1 %2 %3]") .arg(QLocale::system().toString(value.x, 'f', 2)) .arg(QLocale::system().toString(value.y, 'f', 2)) @@ -949,109 +949,6 @@ void PropertyVectorItem::setZ(double z) // --------------------------------------------------------------- -TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyDoubleVectorItem, Gui::PropertyEditor::PropertyItem); - -PropertyDoubleVectorItem::PropertyDoubleVectorItem() -{ - m_x = static_cast(PropertyFloatItem::create()); - m_x->setParent(this); - m_x->setPropertyName(QLatin1String("x")); - this->appendChild(m_x); - m_y = static_cast(PropertyFloatItem::create()); - m_y->setParent(this); - m_y->setPropertyName(QLatin1String("y")); - this->appendChild(m_y); - m_z = static_cast(PropertyFloatItem::create()); - m_z->setParent(this); - m_z->setPropertyName(QLatin1String("z")); - this->appendChild(m_z); -} - -QVariant PropertyDoubleVectorItem::toString(const QVariant& prop) const -{ - const Base::Vector3d& value = prop.value(); - QString data = QString::fromAscii("[%1 %2 %3]") - .arg(QLocale::system().toString(value.x, 'f', 2)) - .arg(QLocale::system().toString(value.y, 'f', 2)) - .arg(QLocale::system().toString(value.z, 'f', 2)); - return QVariant(data); -} - -QVariant PropertyDoubleVectorItem::value(const App::Property* prop) const -{ - // no real property class is using this - return QVariant::fromValue(Base::Vector3d()); -} - -void PropertyDoubleVectorItem::setValue(const QVariant& value) -{ - if (!value.canConvert()) - return; - const Base::Vector3d& val = value.value(); - QString data = QString::fromAscii("(%1, %2, %3)") - .arg(val.x,0,'f',decimals()) - .arg(val.y,0,'f',decimals()) - .arg(val.z,0,'f',decimals()); - setPropertyValue(data); -} - -QWidget* PropertyDoubleVectorItem::createEditor(QWidget* parent, const QObject* /*receiver*/, const char* /*method*/) const -{ - QLineEdit *le = new QLineEdit(parent); - le->setFrame(false); - le->setReadOnly(true); - return le; -} - -void PropertyDoubleVectorItem::setEditorData(QWidget *editor, const QVariant& data) const -{ - QLineEdit* le = qobject_cast(editor); - const Base::Vector3d& value = data.value(); - QString text = QString::fromAscii("[%1 %2 %3]") - .arg(QLocale::system().toString(value.x, 'f', 2)) - .arg(QLocale::system().toString(value.y, 'f', 2)) - .arg(QLocale::system().toString(value.z, 'f', 2)); - le->setText(text); -} - -QVariant PropertyDoubleVectorItem::editorData(QWidget *editor) const -{ - QLineEdit *le = qobject_cast(editor); - return QVariant(le->text()); -} - -double PropertyDoubleVectorItem::x() const -{ - return data(1,Qt::EditRole).value().x; -} - -void PropertyDoubleVectorItem::setX(double x) -{ - setData(QVariant::fromValue(Base::Vector3d(x, y(), z()))); -} - -double PropertyDoubleVectorItem::y() const -{ - return data(1,Qt::EditRole).value().y; -} - -void PropertyDoubleVectorItem::setY(double y) -{ - setData(QVariant::fromValue(Base::Vector3d(x(), y, z()))); -} - -double PropertyDoubleVectorItem::z() const -{ - return data(1,Qt::EditRole).value().z; -} - -void PropertyDoubleVectorItem::setZ(double z) -{ - setData(QVariant::fromValue(Base::Vector3d(x(), y(), z))); -} - -// --------------------------------------------------------------- - TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyMatrixItem, Gui::PropertyEditor::PropertyItem); PropertyMatrixItem::PropertyMatrixItem() @@ -1481,12 +1378,12 @@ PropertyPlacementItem::PropertyPlacementItem() : init_axis(false), changed_value m_a->setParent(this); m_a->setPropertyName(QLatin1String("Angle")); this->appendChild(m_a); - m_d = static_cast(PropertyDoubleVectorItem::create()); + m_d = static_cast(PropertyVectorItem::create()); m_d->setParent(this); m_d->setPropertyName(QLatin1String("Axis")); m_d->setReadOnly(true); this->appendChild(m_d); - m_p = static_cast(PropertyDoubleVectorItem::create()); + m_p = static_cast(PropertyVectorItem::create()); m_p->setParent(this); m_p->setPropertyName(QLatin1String("Position")); m_p->setReadOnly(true); diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index e9990136de..a1a8f528d1 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -335,39 +335,6 @@ private: PropertyFloatItem* m_z; }; -class GuiExport PropertyDoubleVectorItem: public PropertyItem -{ - Q_OBJECT - Q_PROPERTY(double x READ x WRITE setX DESIGNABLE true USER true) - Q_PROPERTY(double y READ y WRITE setY DESIGNABLE true USER true) - Q_PROPERTY(double z READ z WRITE setZ DESIGNABLE true USER true) - TYPESYSTEM_HEADER(); - - virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const; - virtual void setEditorData(QWidget *editor, const QVariant& data) const; - virtual QVariant editorData(QWidget *editor) const; - - double x() const; - void setX(double x); - double y() const; - void setY(double y); - double z() const; - void setZ(double z); - -protected: - virtual QVariant toString(const QVariant&) const; - virtual QVariant value(const App::Property*) const; - virtual void setValue(const QVariant&); - -protected: - PropertyDoubleVectorItem(); - -private: - PropertyFloatItem* m_x; - PropertyFloatItem* m_y; - PropertyFloatItem* m_z; -}; - class GuiExport PropertyMatrixItem: public PropertyItem { Q_OBJECT @@ -510,8 +477,8 @@ private: bool changed_value; Base::Vector3d rot_axis; PropertyAngleItem * m_a; - PropertyDoubleVectorItem* m_d; - PropertyDoubleVectorItem* m_p; + PropertyVectorItem* m_d; + PropertyVectorItem* m_p; }; /** diff --git a/src/Mod/PartDesign/App/FeatureDraft.cpp b/src/Mod/PartDesign/App/FeatureDraft.cpp index b614afccc9..bf787cd30f 100644 --- a/src/Mod/PartDesign/App/FeatureDraft.cpp +++ b/src/Mod/PartDesign/App/FeatureDraft.cpp @@ -61,7 +61,7 @@ using namespace PartDesign; PROPERTY_SOURCE(PartDesign::Draft, PartDesign::DressUp) -const App::PropertyFloatConstraint::Constraints floatAngle = {0.0,89.9,0.1}; +const App::PropertyFloatConstraint::Constraints floatAngle = {0.0,89.99,0.1}; Draft::Draft() { diff --git a/src/Mod/Points/App/Points.cpp b/src/Mod/Points/App/Points.cpp index 28083b1327..ebc38ecb41 100644 --- a/src/Mod/Points/App/Points.cpp +++ b/src/Mod/Points/App/Points.cpp @@ -70,8 +70,8 @@ Data::Segment* PointKernel::getSubElement(const char* Type, unsigned long n) con void PointKernel::transformGeometry(const Base::Matrix4D &rclMat) { - std::vector& kernel = getBasicPoints(); - for (std::vector::iterator it = kernel.begin(); it != kernel.end(); ++it) + std::vector& kernel = getBasicPoints(); + for (std::vector::iterator it = kernel.begin(); it != kernel.end(); ++it) *it = rclMat * (*it); } @@ -94,7 +94,7 @@ void PointKernel::operator = (const PointKernel& Kernel) unsigned int PointKernel::getMemSize (void) const { - return _Points.size() * sizeof(Base::Vector3d); + return _Points.size() * sizeof(value_type); } void PointKernel::Save (Base::Writer &writer) const @@ -112,7 +112,7 @@ void PointKernel::SaveDocFile (Base::Writer &writer) const uint32_t uCt = (uint32_t)size(); str << uCt; // store the data without transforming it - for (std::vector::const_iterator it = _Points.begin(); it != _Points.end(); ++it) { + for (std::vector::const_iterator it = _Points.begin(); it != _Points.end(); ++it) { str << it->x << it->y << it->z; } } @@ -176,12 +176,12 @@ void PointKernel::getFaces(std::vector &Points,std::vector::const_iterator index) +(const PointKernel* kernel, std::vector::const_iterator index) : _kernel(kernel), _p_it(index) { if(_p_it != kernel->_Points.end()) { - Base::Vector3d vertd(_p_it->x, _p_it->y, _p_it->z); + value_type vertd(_p_it->x, _p_it->y, _p_it->z); this->_point = _kernel->_Mtrx * vertd; } } @@ -207,17 +207,19 @@ PointKernel::const_point_iterator::operator=(const PointKernel::const_point_iter void PointKernel::const_point_iterator::dereference() { - Base::Vector3d vertd(_p_it->x, _p_it->y, _p_it->z); + value_type vertd(_p_it->x, _p_it->y, _p_it->z); this->_point = _kernel->_Mtrx * vertd; } -const Base::Vector3d& PointKernel::const_point_iterator::operator*() +const PointKernel::const_point_iterator::value_type& +PointKernel::const_point_iterator::operator*() { dereference(); return this->_point; } -const Base::Vector3d* PointKernel::const_point_iterator::operator->() +const PointKernel::const_point_iterator::value_type* +PointKernel::const_point_iterator::operator->() { dereference(); return &(this->_point); diff --git a/src/Mod/Points/App/Points.h b/src/Mod/Points/App/Points.h index ae48d841d9..b042572079 100644 --- a/src/Mod/Points/App/Points.h +++ b/src/Mod/Points/App/Points.h @@ -134,15 +134,15 @@ public: class PointsExport const_point_iterator { public: - typedef Base::Vector3f value_single; + typedef PointKernel::value_type kernel_type; typedef Base::Vector3d value_type; - typedef std::vector::const_iterator iter_type; + typedef std::vector::const_iterator iter_type; typedef iter_type::difference_type difference_type; typedef iter_type::iterator_category iterator_category; typedef const value_type* pointer; typedef const value_type& reference; - const_point_iterator(const PointKernel*, std::vector::const_iterator index); + const_point_iterator(const PointKernel*, std::vector::const_iterator index); const_point_iterator(const const_point_iterator& pi); //~const_point_iterator(); @@ -164,7 +164,7 @@ public: void dereference(); const PointKernel* _kernel; value_type _point; - std::vector::const_iterator _p_it; + std::vector::const_iterator _p_it; }; typedef const_point_iterator const_iterator; diff --git a/src/Mod/Points/App/Properties.cpp b/src/Mod/Points/App/Properties.cpp index b2e195272d..0c227f840a 100644 --- a/src/Mod/Points/App/Properties.cpp +++ b/src/Mod/Points/App/Properties.cpp @@ -444,10 +444,10 @@ void PropertyCurvatureList::setValues(const std::vector& lValues) hasSetValue(); } -std::vector PropertyCurvatureList::getCurvature( int mode ) const +std::vector PropertyCurvatureList::getCurvature( int mode ) const { const std::vector& fCurvInfo = getValues(); - std::vector fValues; + std::vector fValues; fValues.reserve(fCurvInfo.size()); // Mean curvature diff --git a/src/Mod/Points/App/Properties.h b/src/Mod/Points/App/Properties.h index 004cfecf5b..584515bb35 100644 --- a/src/Mod/Points/App/Properties.h +++ b/src/Mod/Points/App/Properties.h @@ -155,7 +155,7 @@ private: /** Curvature information. */ struct PointsExport CurvatureInfo { - double fMaxCurvature, fMinCurvature; + float fMaxCurvature, fMinCurvature; Base::Vector3f cMaxCurvDir, cMinCurvDir; }; @@ -182,7 +182,7 @@ public: int getSize(void) const {return _lValueList.size();} void setValue(const CurvatureInfo&); void setValues(const std::vector&); - std::vector getCurvature( int tMode) const; + std::vector getCurvature( int tMode) const; /// index operator const CurvatureInfo& operator[] (const int idx) const {return _lValueList.operator[] (idx);}