Gui: Rework TaskCSysDragger into new Transform Dialog

This commit refactor ViewProviderDragger and TaskCSysDragger to be more
modern and to support selecting TransformOrigin.
This commit is contained in:
Kacper Donat
2024-10-27 18:39:51 +01:00
parent b470f74398
commit 1df3b5be6c
25 changed files with 1785 additions and 389 deletions

View File

@@ -34,6 +34,7 @@
#include <Base/ExceptionFactory.h>
#include <Base/Interpreter.h>
#include <Base/Parameter.h>
#include <Base/ServiceProvider.h>
#include <Base/PrecisionPy.h>
#include "ArcOfCirclePy.h"
@@ -187,8 +188,12 @@
#include <OCAF/ImportExportSettings.h>
#include "MeasureClient.h"
#include <FuzzyHelper.h>
#include <App/Services.h>
#include <Services.h>
namespace Part {
extern PyObject* initModule();
}
@@ -572,7 +577,10 @@ PyMOD_INIT_FUNC(Part)
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part/Boolean");
Part::FuzzyHelper::setBooleanFuzzy(hGrp->GetFloat("BooleanFuzzy",10.0));
Base::registerServiceImplementation<App::SubObjectPlacementProvider>(new AttacherSubObjectPlacement);
Base::registerServiceImplementation<App::CenterOfMassProvider>(new PartCenterOfMass);
PyMOD_Return(partModule);
}
// clang-format on

View File

@@ -553,6 +553,8 @@ SET(Part_SRCS
PreCompiled.h
ProgressIndicator.cpp
ProgressIndicator.h
Services.cpp
Services.h
TopoShape.cpp
TopoShape.h
TopoShapeCache.cpp

View File

@@ -0,0 +1,52 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
* Copyright (c) 2024 Kacper Donat <kacper@kadet.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#include "Services.h"
AttacherSubObjectPlacement::AttacherSubObjectPlacement()
: attacher(std::make_unique<Attacher::AttachEngine3D>())
{
attacher->setUp({}, Attacher::mmMidpoint);
}
Base::Placement AttacherSubObjectPlacement::calculate(App::SubObjectT object,
Base::Placement basePlacement) const
{
attacher->setReferences({object});
return basePlacement.inverse() * attacher->calculateAttachedPlacement(basePlacement);
}
std::optional<Base::Vector3d> PartCenterOfMass::ofDocumentObject(App::DocumentObject* object) const
{
if (const auto feature = dynamic_cast<Part::Feature*>(object)) {
const auto shape = feature->Shape.getShape();
if (const auto cog = shape.centerOfGravity()) {
const Base::Placement comPlacement { *cog, Base::Rotation { } };
return (feature->Placement.getValue().inverse() * comPlacement).getPosition();
}
}
return {};
}

View File

@@ -0,0 +1,47 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
* Copyright (c) 2024 Kacper Donat <kacper@kadet.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#ifndef PART_SERVICES_H
#define PART_SERVICES_H
#include <Attacher.h>
#include <App/Services.h>
class AttacherSubObjectPlacement final: public App::SubObjectPlacementProvider
{
public:
AttacherSubObjectPlacement();
Base::Placement calculate(App::SubObjectT object, Base::Placement basePlacement) const override;
private:
std::unique_ptr<Attacher::AttachEngine3D> attacher;
};
class PartCenterOfMass final: public App::CenterOfMassProvider
{
public:
std::optional<Base::Vector3d> ofDocumentObject(App::DocumentObject* object) const override;
};
#endif // PART_SERVICES_H