From 00a25d5998c39652e75c8ac60d3cb2c6e01d8cca Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 19 Dec 2016 17:32:39 +0100 Subject: [PATCH] issue #0002673: Not memorize the rotation --- src/Gui/propertyeditor/PropertyItem.cpp | 23 +++++++++++++++++++++-- src/Gui/propertyeditor/PropertyItem.h | 2 ++ src/Gui/propertyeditor/PropertyModel.cpp | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 918c34cfc8..5f65b52a3a 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -160,6 +160,10 @@ bool PropertyItem::hasProperty(const App::Property* prop) const return false; } +void PropertyItem::assignProperty(const App::Property*) +{ +} + bool PropertyItem::removeProperty(const App::Property* prop) { std::vector::iterator it = std::find(propertyItems.begin(), propertyItems.end(), prop); @@ -1835,6 +1839,21 @@ void PropertyPlacementItem::setPosition(const Base::Vector3d& pos) setValue(QVariant::fromValue(val)); } +void PropertyPlacementItem::assignProperty(const App::Property* prop) +{ + if (prop->getTypeId().isDerivedFrom(App::PropertyPlacement::getClassTypeId())) { + const Base::Placement& value = static_cast(prop)->getValue(); + double angle; + Base::Vector3d dir; + value.getRotation().getValue(dir, angle); + Base::Vector3d cross = this->rot_axis.Cross(dir); + if (cross.Sqr() > Base::Vector3d::epsilon()) { + this->rot_axis = dir; + } + this->rot_angle = Base::toDegrees(angle); + } +} + QVariant PropertyPlacementItem::value(const App::Property* prop) const { assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyPlacement::getClassTypeId())); @@ -1928,13 +1947,13 @@ QWidget* PropertyPlacementItem::createEditor(QWidget* parent, const QObject* rec void PropertyPlacementItem::setEditorData(QWidget *editor, const QVariant& data) const { - Gui::LabelButton *pe = qobject_cast(editor); + PlacementEditor *pe = qobject_cast(editor); pe->setValue(data); } QVariant PropertyPlacementItem::editorData(QWidget *editor) const { - Gui::LabelButton *pe = qobject_cast(editor); + PlacementEditor *pe = qobject_cast(editor); return pe->value(); } diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index ac9c821fa0..972b8019db 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -114,6 +114,7 @@ public: void updateData(); const std::vector& getPropertyData() const; bool hasProperty(const App::Property*) const; + virtual void assignProperty(const App::Property*); bool removeProperty(const App::Property*); App::Property* getFirstProperty(); const App::Property* getFirstProperty() const; @@ -582,6 +583,7 @@ class GuiExport PropertyPlacementItem: public PropertyItem virtual QVariant editorData(QWidget *editor) const; virtual void propertyBound(); + virtual void assignProperty(const App::Property*); Base::Quantity getAngle() const; void setAngle(Base::Quantity); diff --git a/src/Gui/propertyeditor/PropertyModel.cpp b/src/Gui/propertyeditor/PropertyModel.cpp index b0cc7b856a..59e8066705 100644 --- a/src/Gui/propertyeditor/PropertyModel.cpp +++ b/src/Gui/propertyeditor/PropertyModel.cpp @@ -268,6 +268,7 @@ void PropertyModel::updateProperty(const App::Property& prop) child->updateData(); QModelIndex data = this->index(row, column, QModelIndex()); if (data.isValid()) { + child->assignProperty(&prop); dataChanged(data, data); updateChildren(child, column, data); }