| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| |
|
| | #include <QMessageBox>
|
| |
|
| |
|
| | #include <App/Document.h>
|
| | #include <App/DocumentObject.h>
|
| | #include <App/Origin.h>
|
| | #include <Base/Console.h>
|
| | #include <Gui/Application.h>
|
| | #include <Gui/Command.h>
|
| | #include <Gui/Selection/Selection.h>
|
| | #include <Gui/ViewProviderCoordinateSystem.h>
|
| | #include <Mod/PartDesign/App/Body.h>
|
| | #include <Mod/PartDesign/App/FeatureMirrored.h>
|
| |
|
| | #include "ui_TaskMirroredParameters.h"
|
| | #include "TaskMirroredParameters.h"
|
| | #include "ReferenceSelection.h"
|
| | #include "TaskMultiTransformParameters.h"
|
| |
|
| | using namespace PartDesignGui;
|
| | using namespace Gui;
|
| |
|
| |
|
| |
|
| | TaskMirroredParameters::TaskMirroredParameters(ViewProviderTransformed* TransformedView, QWidget* parent)
|
| | : TaskTransformedParameters(TransformedView, parent)
|
| | , ui(new Ui_TaskMirroredParameters)
|
| | {
|
| | setupUI();
|
| | }
|
| |
|
| | TaskMirroredParameters::TaskMirroredParameters(
|
| | TaskMultiTransformParameters* parentTask,
|
| | QWidget* parameterWidget
|
| | )
|
| | : TaskTransformedParameters(parentTask)
|
| | , ui(new Ui_TaskMirroredParameters)
|
| | {
|
| | setupParameterUI(parameterWidget);
|
| | }
|
| |
|
| | void TaskMirroredParameters::setupParameterUI(QWidget* widget)
|
| | {
|
| | ui->setupUi(widget);
|
| | QMetaObject::connectSlotsByName(this);
|
| |
|
| | connect(
|
| | ui->comboPlane,
|
| | qOverload<int>(&QComboBox::activated),
|
| | this,
|
| | &TaskMirroredParameters::onPlaneChanged
|
| | );
|
| |
|
| | this->planeLinks.setCombo(ui->comboPlane);
|
| | ui->comboPlane->setEnabled(true);
|
| |
|
| | App::DocumentObject* sketch = getSketchObject();
|
| | if (sketch && sketch->isDerivedFrom<Part::Part2DObject>()) {
|
| | this->fillPlanesCombo(planeLinks, static_cast<Part::Part2DObject*>(sketch));
|
| | }
|
| | else {
|
| | this->fillPlanesCombo(planeLinks, nullptr);
|
| | }
|
| |
|
| |
|
| | PartDesign::Body* body = PartDesign::Body::findBodyOf(getObject());
|
| | if (body) {
|
| | try {
|
| | App::Origin* origin = body->getOrigin();
|
| | auto vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
|
| | Gui::Application::Instance->getViewProvider(origin)
|
| | );
|
| | vpOrigin->setTemporaryVisibility(Gui::DatumElement::Planes);
|
| | }
|
| | catch (const Base::Exception& ex) {
|
| | Base::Console().error("%s\n", ex.what());
|
| | }
|
| | }
|
| |
|
| | updateUI();
|
| | }
|
| |
|
| | void TaskMirroredParameters::retranslateParameterUI(QWidget* widget)
|
| | {
|
| | ui->retranslateUi(widget);
|
| | }
|
| |
|
| | void TaskMirroredParameters::updateUI()
|
| | {
|
| | if (blockUpdate) {
|
| | return;
|
| | }
|
| | blockUpdate = true;
|
| |
|
| | auto pcMirrored = getObject<PartDesign::Mirrored>();
|
| |
|
| | if (planeLinks.setCurrentLink(pcMirrored->MirrorPlane) == -1) {
|
| |
|
| | planeLinks.addLink(
|
| | pcMirrored->MirrorPlane,
|
| | getRefStr(pcMirrored->MirrorPlane.getValue(), pcMirrored->MirrorPlane.getSubValues())
|
| | );
|
| | planeLinks.setCurrentLink(pcMirrored->MirrorPlane);
|
| | }
|
| |
|
| | blockUpdate = false;
|
| | }
|
| |
|
| | void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
| | {
|
| |
|
| | if (selectionMode == SelectionMode::None || msg.Type != Gui::SelectionChanges::AddSelection) {
|
| | return;
|
| | }
|
| |
|
| | if (originalSelected(msg)) {
|
| | exitSelectionMode();
|
| | return;
|
| | }
|
| |
|
| | auto pcMirrored = getObject<PartDesign::Mirrored>();
|
| |
|
| | std::vector<std::string> mirrorPlanes;
|
| | App::DocumentObject* selObj = nullptr;
|
| | getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes);
|
| | if (!selObj) {
|
| | return;
|
| | }
|
| |
|
| | if (selectionMode == SelectionMode::Reference || selObj->isDerivedFrom<App::Plane>()) {
|
| | setupTransaction();
|
| | pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes);
|
| | recomputeFeature();
|
| | updateUI();
|
| | }
|
| | exitSelectionMode();
|
| | }
|
| |
|
| | void TaskMirroredParameters::onPlaneChanged(int )
|
| | {
|
| | if (blockUpdate) {
|
| | return;
|
| | }
|
| | setupTransaction();
|
| | auto pcMirrored = getObject<PartDesign::Mirrored>();
|
| | try {
|
| | if (!planeLinks.getCurrentLink().getValue()) {
|
| |
|
| | hideObject();
|
| | showBase();
|
| | selectionMode = SelectionMode::Reference;
|
| | Gui::Selection().clearSelection();
|
| | addReferenceSelectionGate(AllowSelection::FACE | AllowSelection::PLANAR);
|
| | }
|
| | else {
|
| | exitSelectionMode();
|
| | pcMirrored->MirrorPlane.Paste(planeLinks.getCurrentLink());
|
| | }
|
| | }
|
| | catch (Base::Exception& e) {
|
| | QMessageBox::warning(nullptr, tr("Error"), QApplication::translate("Exception", e.what()));
|
| | }
|
| |
|
| | recomputeFeature();
|
| | }
|
| |
|
| | void TaskMirroredParameters::onUpdateView(bool on)
|
| | {
|
| | blockUpdate = !on;
|
| | if (on) {
|
| | setupTransaction();
|
| |
|
| | auto pcMirrored = getObject<PartDesign::Mirrored>();
|
| | std::vector<std::string> mirrorPlanes;
|
| | App::DocumentObject* obj = nullptr;
|
| |
|
| | getMirrorPlane(obj, mirrorPlanes);
|
| | pcMirrored->MirrorPlane.setValue(obj, mirrorPlanes);
|
| |
|
| | recomputeFeature();
|
| | }
|
| | }
|
| |
|
| | void TaskMirroredParameters::getMirrorPlane(App::DocumentObject*& obj, std::vector<std::string>& sub) const
|
| | {
|
| | const App::PropertyLinkSub& lnk = planeLinks.getCurrentLink();
|
| | obj = lnk.getValue();
|
| | sub = lnk.getSubValues();
|
| | }
|
| |
|
| | void TaskMirroredParameters::apply()
|
| | {
|
| | std::vector<std::string> mirrorPlanes;
|
| | App::DocumentObject* obj = nullptr;
|
| | getMirrorPlane(obj, mirrorPlanes);
|
| | std::string mirrorPlane = buildLinkSingleSubPythonStr(obj, mirrorPlanes);
|
| |
|
| | FCMD_OBJ_CMD(getObject(), "MirrorPlane = " << mirrorPlane);
|
| | }
|
| |
|
| | TaskMirroredParameters::~TaskMirroredParameters()
|
| | {
|
| |
|
| | try {
|
| | PartDesign::Body* body = PartDesign::Body::findBodyOf(getObject());
|
| | if (body) {
|
| | App::Origin* origin = body->getOrigin();
|
| | auto vpOrigin = static_cast<ViewProviderCoordinateSystem*>(
|
| | Gui::Application::Instance->getViewProvider(origin)
|
| | );
|
| | vpOrigin->resetTemporaryVisibility();
|
| | }
|
| | }
|
| | catch (const Base::Exception& ex) {
|
| | Base::Console().error("%s\n", ex.what());
|
| | }
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | TaskDlgMirroredParameters::TaskDlgMirroredParameters(ViewProviderMirrored* MirroredView)
|
| | : TaskDlgTransformedParameters(MirroredView)
|
| | {
|
| | parameter = new TaskMirroredParameters(MirroredView);
|
| |
|
| | Content.push_back(parameter);
|
| | Content.push_back(preview);
|
| | }
|
| |
|
| | #include "moc_TaskMirroredParameters.cpp"
|
| |
|