Merge pull request #17564 from kadet1090/new-transform-dialog
Gui: New transform dialog
This commit is contained in:
@@ -63,6 +63,7 @@
|
||||
#include <Base/BaseClass.h>
|
||||
#include <Base/BoundBoxPy.h>
|
||||
#include <Base/ConsoleObserver.h>
|
||||
#include <Base/ServiceProvider.h>
|
||||
#include <Base/CoordinateSystemPy.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/ExceptionFactory.h>
|
||||
@@ -89,6 +90,7 @@
|
||||
#include "Application.h"
|
||||
#include "CleanupProcess.h"
|
||||
#include "ComplexGeoData.h"
|
||||
#include "Services.h"
|
||||
#include "DocumentObjectFileIncluded.h"
|
||||
#include "DocumentObjectGroup.h"
|
||||
#include "DocumentObjectGroupPy.h"
|
||||
@@ -2217,6 +2219,8 @@ void Application::initTypes()
|
||||
new Base::ExceptionProducer<Base::CADKernelError>;
|
||||
new Base::ExceptionProducer<Base::RestoreError>;
|
||||
new Base::ExceptionProducer<Base::PropertyError>;
|
||||
|
||||
Base::registerServiceImplementation<CenterOfMassProvider>(new NullCenterOfMass);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -289,6 +289,7 @@ SET(FreeCADApp_CPP_SRCS
|
||||
MetadataPyImp.cpp
|
||||
ElementNamingUtils.cpp
|
||||
SafeMode.cpp
|
||||
Services.cpp
|
||||
StringHasher.cpp
|
||||
StringHasherPyImp.cpp
|
||||
StringIDPyImp.cpp
|
||||
@@ -313,6 +314,7 @@ SET(FreeCADApp_HPP_SRCS
|
||||
MeasureManager.h
|
||||
Metadata.h
|
||||
ElementNamingUtils.h
|
||||
Services.h
|
||||
StringHasher.h
|
||||
)
|
||||
|
||||
|
||||
@@ -184,6 +184,17 @@ bool ComplexGeoData::getCenterOfGravity(Base::Vector3d& unused) const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<Base::Vector3d> ComplexGeoData::centerOfGravity() const
|
||||
{
|
||||
Base::Vector3d centerOfGravity;
|
||||
|
||||
if (getCenterOfGravity(centerOfGravity)) {
|
||||
return centerOfGravity;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
const std::string& ComplexGeoData::elementMapPrefix()
|
||||
{
|
||||
static std::string prefix(ELEMENT_MAP_PREFIX);
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#define APP_COMPLEX_GEO_DATA_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
|
||||
#include <Base/Handle.h>
|
||||
#include <Base/Matrix.h>
|
||||
#include <Base/Persistence.h>
|
||||
@@ -200,6 +202,7 @@ public:
|
||||
* The default implementation only returns false.
|
||||
*/
|
||||
virtual bool getCenterOfGravity(Base::Vector3d& center) const;
|
||||
virtual std::optional<Base::Vector3d> centerOfGravity() const;
|
||||
//@}
|
||||
|
||||
static const std::string& elementMapPrefix();
|
||||
|
||||
@@ -61,12 +61,7 @@ void GeoFeature::transformPlacement(const Base::Placement& transform)
|
||||
|
||||
Base::Placement GeoFeature::globalPlacement() const
|
||||
{
|
||||
auto* group = GeoFeatureGroupExtension::getGroupOfObject(this);
|
||||
if (group) {
|
||||
auto ext = group->getExtensionByType<GeoFeatureGroupExtension>();
|
||||
return ext->globalGroupPlacement() * Placement.getValue();
|
||||
}
|
||||
return Placement.getValue();
|
||||
return GeoFeature::getGlobalPlacement(this);
|
||||
}
|
||||
|
||||
const PropertyComplexGeoData* GeoFeature::getPropertyOfGeometry() const
|
||||
@@ -316,6 +311,11 @@ Base::Placement GeoFeature::getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
return plc;
|
||||
}
|
||||
|
||||
if (rootObj->isLink()) {
|
||||
// Update doc in case its an external link.
|
||||
doc = rootObj->getLinkedObject()->getDocument();
|
||||
}
|
||||
|
||||
for (auto& name : names) {
|
||||
App::DocumentObject* obj = doc->getObject(name.c_str());
|
||||
if (!obj) {
|
||||
@@ -351,3 +351,20 @@ Base::Placement GeoFeature::getGlobalPlacement(App::DocumentObject* targetObj,
|
||||
|
||||
return getGlobalPlacement(targetObj, prop->getValue(), subs[0]);
|
||||
}
|
||||
|
||||
Base::Placement GeoFeature::getGlobalPlacement(const DocumentObject* obj)
|
||||
{
|
||||
auto placementProperty = obj->getPropertyByName<App::PropertyPlacement>("Placement");
|
||||
|
||||
if (!placementProperty) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto* group = GeoFeatureGroupExtension::getGroupOfObject(obj);
|
||||
if (group) {
|
||||
auto ext = group->getExtensionByType<GeoFeatureGroupExtension>();
|
||||
return ext->globalGroupPlacement() * placementProperty->getValue();
|
||||
}
|
||||
|
||||
return placementProperty->getValue();
|
||||
}
|
||||
|
||||
@@ -195,6 +195,7 @@ public:
|
||||
static Base::Placement
|
||||
getGlobalPlacement(DocumentObject* targetObj, DocumentObject* rootObj, const std::string& sub);
|
||||
static Base::Placement getGlobalPlacement(DocumentObject* targetObj, PropertyXLinkSub* prop);
|
||||
static Base::Placement getGlobalPlacement(const DocumentObject* obj);
|
||||
|
||||
protected:
|
||||
void onChanged(const Property* prop) override;
|
||||
|
||||
30
src/App/Services.cpp
Normal file
30
src/App/Services.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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"
|
||||
|
||||
std::optional<Base::Vector3d>
|
||||
App::NullCenterOfMass::ofDocumentObject([[maybe_unused]] DocumentObject* object) const
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
74
src/App/Services.h
Normal file
74
src/App/Services.h
Normal file
@@ -0,0 +1,74 @@
|
||||
// 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 APP_SERVICES_H
|
||||
#define APP_SERVICES_H
|
||||
|
||||
#include "DocumentObject.h"
|
||||
|
||||
#include <optional>
|
||||
#include <Base/Placement.h>
|
||||
|
||||
namespace App
|
||||
{
|
||||
|
||||
/**
|
||||
* This service should provide placement of given sub object (like for example face).
|
||||
* This feature is not implemented in the core and so it must be provided by module.
|
||||
*/
|
||||
class SubObjectPlacementProvider
|
||||
{
|
||||
public:
|
||||
virtual ~SubObjectPlacementProvider() = default;
|
||||
|
||||
/**
|
||||
* Returns placement of sub object relative to the base placement.
|
||||
*/
|
||||
virtual Base::Placement calculate(SubObjectT object, Base::Placement basePlacement) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* This service should provide center of mass calculation;
|
||||
*/
|
||||
class CenterOfMassProvider
|
||||
{
|
||||
public:
|
||||
virtual ~CenterOfMassProvider() = default;
|
||||
|
||||
virtual std::optional<Base::Vector3d> ofDocumentObject(DocumentObject* object) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Default implementation for the center of mass contract
|
||||
* It always returns empty optional
|
||||
*/
|
||||
class NullCenterOfMass final : public CenterOfMassProvider
|
||||
{
|
||||
public:
|
||||
std::optional<Base::Vector3d> ofDocumentObject(DocumentObject* object) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // APP_SERVICES_H
|
||||
Reference in New Issue
Block a user