From fc8d9f2bf37b9edabaaaf546511e82d849d7ba4c Mon Sep 17 00:00:00 2001 From: mwganson Date: Sat, 15 Sep 2018 21:40:05 -0500 Subject: [PATCH] Add select point(s) option to Placement dialog --- src/Gui/Placement.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++ src/Gui/Placement.h | 3 ++ src/Gui/Placement.ui | 20 ++++------- 3 files changed, 88 insertions(+), 13 deletions(-) diff --git a/src/Gui/Placement.cpp b/src/Gui/Placement.cpp index ddcc4a9f38..9db46cf97a 100644 --- a/src/Gui/Placement.cpp +++ b/src/Gui/Placement.cpp @@ -82,6 +82,12 @@ public: Placement::Placement(QWidget* parent, Qt::WindowFlags fl) : Gui::LocationDialog(parent, fl) { + std::vector selection = Gui::Selection().getSelectionEx(); + if (selection.size()>=1){ + documentName = selection[0].getDocName(); //save info so we can reselect + featureName = selection[0].getFeatName(); //after select points button clicked + } + propertyName = "Placement"; // default name ui = new Ui_PlacementComp(this); ui->applyPlacementChange->hide(); @@ -296,6 +302,78 @@ void Placement::on_centerOfMass_toggled(bool on) } } +void Placement::on_selectedVertex_clicked() +{ + cntOfMass.Set(0,0,0); + ui->centerOfMass->setChecked(false); + + bool success=false; + std::vector selection = Gui::Selection().getSelectionEx(); + std::vector picked; + std::vector subnames; + //combine all pickedpoints and subnames into single vectors + //even if points are from separate objects + for (std::vector::iterator it=selection.begin(); it!=selection.end(); ++it){ + std::vector points = it->getPickedPoints(); + picked.insert(picked.begin(),points.begin(),points.end()); + std::vector names = it->getSubNames(); + subnames.insert(subnames.begin(),names.begin(),names.end()); + } + if (picked.size()==1 && (std::string(subnames[0]).substr(0,6)==std::string("Vertex") + || std::string(subnames[0]).substr(0,5)==std::string("Point"))){ + ui->xCnt->setValue(picked[0].x); + ui->yCnt->setValue(picked[0].y); + ui->zCnt->setValue(picked[0].z); + cntOfMass.x=picked[0].x; + cntOfMass.y=picked[0].y; + cntOfMass.z=picked[0].z; + success=true; + } else if (picked.size()==2 && (std::string(subnames[0]).substr(0,6)==std::string("Vertex") + || std::string(subnames[0]).substr(0,5)==std::string("Point")) + && (std::string(subnames[1]).substr(0,6)==std::string("Vertex") + || std::string(subnames[1]).substr(0,5)==std::string("Point"))){ + //average the coords to get center of rotation + ui->xCnt->setValue((picked[0].x+picked[1].x)/2.0); + ui->yCnt->setValue((picked[0].y+picked[1].y)/2.0); + ui->zCnt->setValue((picked[0].z+picked[1].z)/2.0); + cntOfMass.x=(picked[0].x+picked[1].x)/2.0; + cntOfMass.y=(picked[0].y+picked[1].y)/2.0; + cntOfMass.z=(picked[0].z+picked[1].z)/2.0; + //setup a customized axis since the user selected 2 points + //keep any existing angle, but setup our own axis + Base::Placement plm = getPlacement(); + Base::Rotation rot = plm.getRotation(); + Base::Vector3d tmp; + double angle; + rot.getRawValue(tmp, angle); + Base::Vector3d axis(picked[0].x-picked[1].x,picked[0].y-picked[1].y,picked[0].z-picked[1].z); + axis.Normalize(); + rot.setValue(axis, angle); + plm.setRotation(rot); + setPlacementData(plm); //creates custom axis, if needed + + //we have to clear selection and reselect one point or else + //later on the rotation is applied twice because there will + //be 2 (vertex) objects in the selection, and even if both are subobjects + //of the same object the rotation still gets applied twice + Gui::Selection().clearSelection(); + //reselect original object that was selected when placment dlg first opened + Gui::Selection().addSelection(documentName.c_str(),featureName.c_str()); + ui->rotationInput->setCurrentIndex(0); //use rotation with axis instead of euler + ui->stackedWidget->setCurrentIndex(0); + success=true; + } + + if (!success){ + Base::Console().Warning("Placement selection error. Select either 1 or 2 points.\n"); + + ui->xCnt->setValue(0); + ui->yCnt->setValue(0); + ui->zCnt->setValue(0); + return; + } +} + void Placement::on_applyIncrementalPlacement_toggled(bool on) { if (on) { diff --git a/src/Gui/Placement.h b/src/Gui/Placement.h index b5f546090a..95e4c035c5 100644 --- a/src/Gui/Placement.h +++ b/src/Gui/Placement.h @@ -65,6 +65,7 @@ private Q_SLOTS: void onPlacementChanged(int); void on_resetButton_clicked(); void on_centerOfMass_toggled(bool); + void on_selectedVertex_clicked(); private: bool onApply(); @@ -93,6 +94,8 @@ private: Base::Vector3d cntOfMass; std::string propertyName; // the name of the placement property std::set documents; + std::string documentName; //store these so we can reselect original object + std::string featureName; //after user selects points and clicks Selected point(s) friend class TaskPlacement; }; diff --git a/src/Gui/Placement.ui b/src/Gui/Placement.ui index 00725d5d8a..0ad441c602 100644 --- a/src/Gui/Placement.ui +++ b/src/Gui/Placement.ui @@ -108,19 +108,6 @@ 6 - - - - Qt::Vertical - - - - 20 - 66 - - - - @@ -176,6 +163,13 @@ + + + + Selected point(s) + + +