Format code with clang-format

This commit is contained in:
André Althaus
2024-05-23 12:23:28 +02:00
parent 98d46c41be
commit 75bba376c4
6 changed files with 297 additions and 221 deletions

View File

@@ -23,9 +23,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepGProp.hxx>
# include <GProp_GProps.hxx>
# include <Precision.hxx>
#include <BRepGProp.hxx>
#include <GProp_GProps.hxx>
#include <Precision.hxx>
#endif
#include "FeatureMultiTransform.h"
@@ -35,14 +35,15 @@
using namespace PartDesign;
namespace PartDesign {
namespace PartDesign
{
PROPERTY_SOURCE(PartDesign::MultiTransform, PartDesign::Transformed)
MultiTransform::MultiTransform()
{
ADD_PROPERTY(Transformations,(nullptr));
ADD_PROPERTY(Transformations, (nullptr));
Transformations.setSize(0);
}
@@ -51,8 +52,9 @@ void MultiTransform::positionBySupport()
PartDesign::Transformed::positionBySupport();
std::vector<App::DocumentObject*> transFeatures = Transformations.getValues();
for (auto f : transFeatures) {
if (!(f->isDerivedFrom<PartDesign::Transformed>()))
if (!(f->isDerivedFrom<PartDesign::Transformed>())) {
throw Base::TypeError("Transformation features must be subclasses of Transformed");
}
PartDesign::Transformed* transFeature = static_cast<PartDesign::Transformed*>(f);
transFeature->Placement.setValue(this->Placement.getValue());
@@ -66,27 +68,29 @@ void MultiTransform::positionBySupport()
short MultiTransform::mustExecute() const
{
if (Transformations.isTouched())
if (Transformations.isTouched()) {
return 1;
}
return Transformed::mustExecute();
}
const std::list<gp_Trsf> MultiTransform::getTransformations(const std::vector<App::DocumentObject*> originals)
const std::list<gp_Trsf>
MultiTransform::getTransformations(const std::vector<App::DocumentObject*> originals)
{
std::vector<App::DocumentObject*> transFeatures = Transformations.getValues();
gp_Pnt cog;
if (!originals.empty()) {
// Find centre of gravity of first original
// FIXME: This method will NOT give the expected result for more than one original!
if (auto addFeature =
Base::freecad_dynamic_cast<PartDesign::FeatureAddSub>(originals.front())) {
TopoDS_Shape original = addFeature->AddSubShape.getShape().getShape();
// Find centre of gravity of first original
// FIXME: This method will NOT give the expected result for more than one original!
if (auto addFeature =
Base::freecad_dynamic_cast<PartDesign::FeatureAddSub>(originals.front())) {
TopoDS_Shape original = addFeature->AddSubShape.getShape().getShape();
GProp_GProps props;
BRepGProp::VolumeProperties(original, props);
cog = props.CentreOfMass();
}
GProp_GProps props;
BRepGProp::VolumeProperties(original, props);
cog = props.CentreOfMass();
}
}
std::list<gp_Trsf> result;
@@ -94,24 +98,28 @@ const std::list<gp_Trsf> MultiTransform::getTransformations(const std::vector<Ap
std::vector<App::DocumentObject*>::const_iterator f;
for (f = transFeatures.begin(); f != transFeatures.end(); ++f) {
if (!((*f)->isDerivedFrom<PartDesign::Transformed>()))
if (!((*f)->isDerivedFrom<PartDesign::Transformed>())) {
throw Base::TypeError("Transformation features must be subclasses of Transformed");
}
PartDesign::Transformed* transFeature = static_cast<PartDesign::Transformed*>(*f);
std::list<gp_Trsf> newTransformations = transFeature->getTransformations(originals);
if (result.empty()) {
// First transformation Feature
result = newTransformations;
for (std::list<gp_Trsf>::const_iterator nt = newTransformations.begin(); nt != newTransformations.end(); ++nt) {
for (std::list<gp_Trsf>::const_iterator nt = newTransformations.begin();
nt != newTransformations.end();
++nt) {
cogs.push_back(cog.Transformed(*nt));
}
} else {
}
else {
// Retain a copy of the first set of transformations for iterator ot
// We can't iterate through result if we are also adding elements with push_back()!
std::list<gp_Trsf> oldTransformations;
result.swap(oldTransformations); // empty result to receive new transformations
result.swap(oldTransformations); // empty result to receive new transformations
std::list<gp_Pnt> oldCogs;
cogs.swap(oldCogs); // empty cogs to receive new cogs
cogs.swap(oldCogs); // empty cogs to receive new cogs
if ((*f)->is<PartDesign::Scaled>()) {
// Diagonal method
@@ -123,25 +131,33 @@ const std::list<gp_Trsf> MultiTransform::getTransformations(const std::vector<Ap
// In other words, the length of the result vector is equal to the length of the
// oldTransformations vector
if (newTransformations.empty())
throw Base::ValueError("Number of occurrences must be a divisor of previous number of occurrences");
if (oldTransformations.size() % newTransformations.size() != 0)
throw Base::ValueError("Number of occurrences must be a divisor of previous number of occurrences");
if (newTransformations.empty()) {
throw Base::ValueError("Number of occurrences must be a divisor of previous "
"number of occurrences");
}
if (oldTransformations.size() % newTransformations.size() != 0) {
throw Base::ValueError("Number of occurrences must be a divisor of previous "
"number of occurrences");
}
unsigned sliceLength = oldTransformations.size() / newTransformations.size();
std::list<gp_Trsf>::const_iterator ot = oldTransformations.begin();
std::list<gp_Pnt>::const_iterator oc = oldCogs.begin();
for (std::list<gp_Trsf>::const_iterator nt = newTransformations.begin(); nt != newTransformations.end(); ++nt) {
for (std::list<gp_Trsf>::const_iterator nt = newTransformations.begin();
nt != newTransformations.end();
++nt) {
for (unsigned s = 0; s < sliceLength; s++) {
gp_Trsf trans;
double factor = nt->ScaleFactor(); // extract scale factor
double factor = nt->ScaleFactor(); // extract scale factor
if (factor > Precision::Confusion()) {
trans.SetScale(*oc, factor); // recreate the scaled transformation to use the correct COG
trans.SetScale(*oc, factor); // recreate the scaled transformation to
// use the correct COG
trans = trans * (*ot);
cogs.push_back(*oc); // Scaling does not affect the COG
} else {
cogs.push_back(*oc); // Scaling does not affect the COG
}
else {
trans = (*nt) * (*ot);
cogs.push_back(oc->Transformed(*nt));
}
@@ -150,30 +166,35 @@ const std::list<gp_Trsf> MultiTransform::getTransformations(const std::vector<Ap
++oc;
}
}
} else {
}
else {
// Multiplication method: Combine the new transformations with the old ones.
// All old transformations are multiplied with all new ones, so that the length of the
// result vector is the length of the old and new transformations multiplied.
// All old transformations are multiplied with all new ones, so that the length of
// the result vector is the length of the old and new transformations multiplied.
// a11 a12 b1 a11*b1 a12*b1 a11*b2 a12*b2 a11*b3 a12*b3
// a21 a22 mul b2 = a21*b1 a22*b1 a21*b2 a22*b2 a21*b3 a22*b3
// b3
for (std::list<gp_Trsf>::const_iterator nt = newTransformations.begin(); nt != newTransformations.end(); ++nt) {
for (std::list<gp_Trsf>::const_iterator nt = newTransformations.begin();
nt != newTransformations.end();
++nt) {
std::list<gp_Pnt>::const_iterator oc = oldCogs.begin();
for (std::list<gp_Trsf>::const_iterator ot = oldTransformations.begin(); ot != oldTransformations.end(); ++ot) {
for (std::list<gp_Trsf>::const_iterator ot = oldTransformations.begin();
ot != oldTransformations.end();
++ot) {
result.push_back((*nt) * (*ot));
cogs.push_back(oc->Transformed(*nt));
++oc;
}
}
}
// What about the Additive method: Take the last (set of) transformations and use them as
// "originals" for the next transformationFeature, so that something similar to a sweep
// for transformations could be put together?
// What about the Additive method: Take the last (set of) transformations and use them
// as "originals" for the next transformationFeature, so that something similar to a
// sweep for transformations could be put together?
}
}
return result;
}
}
} // namespace PartDesign