From f0af88ecae739fa632f30875be24ad91b59999a5 Mon Sep 17 00:00:00 2001 From: donovaly Date: Sun, 8 Nov 2020 17:50:40 +0100 Subject: [PATCH] [Part] add preview for changes to primitives location - unset keyboardTracking for the dialog edits - don't hide the location dialog on creation --- src/Mod/Part/Gui/DlgPrimitives.cpp | 130 ++++++++++++++++++- src/Mod/Part/Gui/DlgPrimitives.h | 5 + src/Mod/Part/Gui/DlgPrimitives.ui | 201 +++++++++++++++++++++++++++++ src/Mod/Part/Gui/Location.ui | 9 ++ 4 files changed, 343 insertions(+), 2 deletions(-) diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index 34a954cab8..6bdf27faad 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -1573,8 +1573,9 @@ void DlgPrimitives::onChangeRegularPolygon(QWidget* widget) /* TRANSLATOR PartGui::Location */ Location::Location(QWidget* parent, Part::Feature* feature) + : QWidget(parent) + , featurePtr(feature) { - Q_UNUSED(parent); mode = 0; ui.setupUi(this); @@ -1600,8 +1601,19 @@ Location::Location(QWidget* parent, Part::Feature* feature) ui.XDirectionEdit->setValue(rotationAxes.x); ui.YDirectionEdit->setValue(rotationAxes.y); ui.ZDirectionEdit->setValue(rotationAxes.z); - // the angle is in this format: 180° = PI, thus transform it to deg + // the angle is rad, transform it for display to degrees ui.AngleQSB->setValue(Base::toDegrees(rotationAngle)); + + //connect signals + QSignalMapper* mapper = new QSignalMapper(this); + connect(mapper, SIGNAL(mapped(QWidget*)), this, SLOT(onChangePosRot(QWidget*))); + connectSignalMapper(ui.XPositionQSB, SIGNAL(valueChanged(double)), mapper); + connectSignalMapper(ui.YPositionQSB, SIGNAL(valueChanged(double)), mapper); + connectSignalMapper(ui.ZPositionQSB, SIGNAL(valueChanged(double)), mapper); + connectSignalMapper(ui.AngleQSB, SIGNAL(valueChanged(double)), mapper); + connectSignalMapper(ui.XDirectionEdit, SIGNAL(valueChanged(double)), mapper); + connectSignalMapper(ui.YDirectionEdit, SIGNAL(valueChanged(double)), mapper); + connectSignalMapper(ui.ZDirectionEdit, SIGNAL(valueChanged(double)), mapper); } } @@ -1620,6 +1632,120 @@ Location::~Location() } } +void Location::connectSignalMapper(QWidget* sender, const char* signal, QSignalMapper* mapper) +{ + connect(sender, signal, mapper, SLOT(map())); + mapper->setMapping(sender, sender); +} + +void Location::onChangePosRot(QWidget* widget) +{ + App::Document* doc = featurePtr->getDocument(); + Base::Type type = featurePtr->getTypeId(); + + // read dialog values + Base::Vector3d loc; + loc.x = ui.XPositionQSB->rawValue(); + loc.y = ui.YPositionQSB->rawValue(); + loc.z = ui.ZPositionQSB->rawValue(); + double angle = ui.AngleQSB->rawValue(); + // the angle is displayed in degrees, transform it to rad + angle = Base::toRadians(angle); + Base::Vector3d rot; + rot.x = ui.XDirectionEdit->value(); + rot.y = ui.YDirectionEdit->value(); + rot.z = ui.ZDirectionEdit->value(); + + // set placement and rotation + Base::Placement placement; + Base::Rotation rotation(rot, angle); + placement.setPosition(loc); + placement.setRotation(rotation); + + // apply new placement to the feature + + if (type == Part::Plane::getClassTypeId()) { + Part::Plane* plane = featurePtr.get(); + plane->Placement.setValue(placement); + plane->recomputeFeature(); + } + else if (type == Part::Box::getClassTypeId()) { + Part::Box* box = featurePtr.get(); + box->Placement.setValue(placement); + box->recomputeFeature(); + } + else if (type == Part::Cylinder::getClassTypeId()) { + Part::Cylinder* cylinder = featurePtr.get(); + cylinder->Placement.setValue(placement); + cylinder->recomputeFeature(); + } + else if (type == Part::Cone::getClassTypeId()) { + Part::Cone* cone = featurePtr.get(); + cone->Placement.setValue(placement); + cone->recomputeFeature(); + } + else if (type == Part::Sphere::getClassTypeId()) { + Part::Sphere* sphere = featurePtr.get(); + sphere->Placement.setValue(placement); + sphere->recomputeFeature(); + } + else if (type == Part::Ellipsoid::getClassTypeId()) { + Part::Ellipsoid* ellipsoid = featurePtr.get(); + ellipsoid->Placement.setValue(placement); + ellipsoid->recomputeFeature(); + } + else if (type == Part::Torus::getClassTypeId()) { + Part::Torus* torus = featurePtr.get(); + torus->Placement.setValue(placement); + torus->recomputeFeature(); + } + else if (type == Part::Prism::getClassTypeId()) { + Part::Prism* prism = featurePtr.get(); + prism->Placement.setValue(placement); + prism->recomputeFeature(); + } + else if (type == Part::Wedge::getClassTypeId()) { + Part::Wedge* wedge = featurePtr.get(); + wedge->Placement.setValue(placement); + wedge->recomputeFeature(); + } + else if (type == Part::Helix::getClassTypeId()) { + Part::Helix* helix = featurePtr.get(); + helix->Placement.setValue(placement); + helix->recomputeFeature(); + } + else if (type == Part::Spiral::getClassTypeId()) { + Part::Spiral* spiral = featurePtr.get(); + spiral->Placement.setValue(placement); + spiral->recomputeFeature(); + } + else if (type == Part::Circle::getClassTypeId()) { + Part::Circle* circle = featurePtr.get(); + circle->Placement.setValue(placement); + circle->recomputeFeature(); + } + else if (type == Part::Ellipse::getClassTypeId()) { + Part::Ellipse* ellipse = featurePtr.get(); + ellipse->Placement.setValue(placement); + ellipse->recomputeFeature(); + } + else if (type == Part::Vertex::getClassTypeId()) { + Part::Vertex* vertex = featurePtr.get(); + vertex->Placement.setValue(placement); + vertex->recomputeFeature(); + } + else if (type == Part::Line::getClassTypeId()) { + Part::Line* line = featurePtr.get(); + line->Placement.setValue(placement); + line->recomputeFeature(); + } + else if (type == Part::RegularPolygon::getClassTypeId()) { + Part::RegularPolygon* polygon = featurePtr.get(); + polygon->Placement.setValue(placement); + polygon->recomputeFeature(); + } +} + void Location::on_viewPositionButton_clicked() { Gui::Document* doc = Gui::Application::Instance->activeDocument(); diff --git a/src/Mod/Part/Gui/DlgPrimitives.h b/src/Mod/Part/Gui/DlgPrimitives.h index 08ef31ca10..d6752ace80 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.h +++ b/src/Mod/Part/Gui/DlgPrimitives.h @@ -112,13 +112,18 @@ public: QString toPlacement() const; private Q_SLOTS: + void onChangePosRot(QWidget*); void on_viewPositionButton_clicked(); +private: + void connectSignalMapper(QWidget* sender, const char* signal, QSignalMapper* mapper); + private: static void pickCallback(void * ud, SoEventCallback * n); int mode; QPointer activeView; Ui_Location ui; + App::DocumentObjectWeakPtrT featurePtr; }; class TaskPrimitives : public Gui::TaskView::TaskDialog diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index 6014ad7290..2755bbd4b1 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -236,6 +236,9 @@ + + false + mm @@ -260,6 +263,9 @@ + + false + mm @@ -337,6 +343,9 @@ + + false + mm @@ -347,6 +356,9 @@ + + false + mm @@ -378,6 +390,9 @@ + + false + mm @@ -433,6 +448,9 @@ + + false + deg @@ -502,6 +520,9 @@ + + false + mm @@ -512,6 +533,9 @@ + + false + mm @@ -567,6 +591,9 @@ + + false + deg @@ -622,6 +649,9 @@ + + false + mm @@ -632,6 +662,9 @@ + + false + mm @@ -663,6 +696,9 @@ + + false + mm @@ -751,6 +787,9 @@ + + false + deg @@ -761,6 +800,9 @@ + + false + deg @@ -771,6 +813,9 @@ + + false + deg @@ -823,6 +868,9 @@ + + false + mm @@ -915,6 +963,9 @@ + + false + mm @@ -925,6 +976,9 @@ + + false + mm @@ -935,6 +989,9 @@ + + false + mm @@ -994,6 +1051,9 @@ + + false + deg @@ -1004,6 +1064,9 @@ + + false + deg @@ -1014,6 +1077,9 @@ + + false + deg @@ -1102,6 +1168,9 @@ + + false + deg @@ -1112,6 +1181,9 @@ + + false + deg @@ -1122,6 +1194,9 @@ + + false + deg @@ -1167,6 +1242,9 @@ + + false + mm @@ -1191,6 +1269,9 @@ + + false + mm @@ -1239,6 +1320,9 @@ + + false + mm @@ -1256,6 +1340,9 @@ + + false + 3 @@ -1283,6 +1370,9 @@ + + false + mm @@ -1303,6 +1393,9 @@ Angle in first direction + + false + deg @@ -1326,6 +1419,9 @@ Angle in second direction + + false + deg @@ -1401,6 +1497,9 @@ + + false + mm @@ -1408,6 +1507,9 @@ + + false + mm @@ -1418,6 +1520,9 @@ + + false + mm @@ -1425,6 +1530,9 @@ + + false + mm @@ -1435,6 +1543,9 @@ + + false + mm @@ -1442,6 +1553,9 @@ + + false + mm @@ -1452,6 +1566,9 @@ + + false + mm @@ -1462,6 +1579,9 @@ + + false + mm @@ -1472,6 +1592,9 @@ + + false + mm @@ -1482,6 +1605,9 @@ + + false + mm @@ -1605,6 +1731,9 @@ + + false + deg @@ -1612,6 +1741,9 @@ + + false + mm @@ -1622,6 +1754,9 @@ + + false + mm @@ -1632,6 +1767,9 @@ + + false + mm @@ -1714,6 +1852,9 @@ + + false + mm @@ -1724,6 +1865,9 @@ + + false + 1000.000000000000000 @@ -1734,6 +1878,9 @@ + + false + mm @@ -1788,6 +1935,9 @@ + + false + deg @@ -1795,6 +1945,9 @@ + + false + deg @@ -1805,6 +1958,9 @@ + + false + mm @@ -1888,6 +2044,9 @@ + + false + mm @@ -1898,6 +2057,9 @@ + + false + mm @@ -1908,6 +2070,9 @@ + + false + deg @@ -1915,6 +2080,9 @@ + + false + deg @@ -1976,6 +2144,9 @@ + + false + mm @@ -1983,6 +2154,9 @@ + + false + mm @@ -1990,6 +2164,9 @@ + + false + mm @@ -2102,6 +2279,9 @@ + + false + mm @@ -2109,6 +2289,9 @@ + + false + mm @@ -2116,6 +2299,9 @@ + + false + mm @@ -2123,6 +2309,9 @@ + + false + mm @@ -2133,6 +2322,9 @@ + + false + mm @@ -2143,6 +2335,9 @@ + + false + mm @@ -2211,6 +2406,9 @@ + + false + 3 @@ -2231,6 +2429,9 @@ + + false + mm diff --git a/src/Mod/Part/Gui/Location.ui b/src/Mod/Part/Gui/Location.ui index 8935cab708..e180e645da 100644 --- a/src/Mod/Part/Gui/Location.ui +++ b/src/Mod/Part/Gui/Location.ui @@ -40,6 +40,9 @@ + + false + @@ -58,6 +61,9 @@ + + false + @@ -76,6 +82,9 @@ + + false +