All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent eafd18dac0
commit 25c3ba7338
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -59,18 +59,22 @@ PROPERTY_SOURCE(Assembly::AssemblyLink, App::Part)
AssemblyLink::AssemblyLink()
{
ADD_PROPERTY_TYPE(Rigid,
(true),
"General",
(App::PropertyType)(App::Prop_None),
"If the sub-assembly is set to Rigid, it will act "
"as a rigid body. Else its joints will be taken into account.");
ADD_PROPERTY_TYPE(
Rigid,
(true),
"General",
(App::PropertyType)(App::Prop_None),
"If the sub-assembly is set to Rigid, it will act "
"as a rigid body. Else its joints will be taken into account."
);
ADD_PROPERTY_TYPE(LinkedObject,
(nullptr),
"General",
(App::PropertyType)(App::Prop_None),
"The linked assembly.");
ADD_PROPERTY_TYPE(
LinkedObject,
(nullptr),
"General",
(App::PropertyType)(App::Prop_None),
"The linked assembly."
);
}
AssemblyLink::~AssemblyLink() = default;
@@ -105,8 +109,9 @@ void AssemblyLink::onChanged(const App::Property* prop)
// If a rigid sub-assembly has an object that is grounded, we also remove it.
auto groundedJoints = getParentAssembly()->getGroundedJoints();
for (auto* joint : groundedJoints) {
auto* propObj =
dynamic_cast<App::PropertyLink*>(joint->getPropertyByName("ObjectToGround"));
auto* propObj = dynamic_cast<App::PropertyLink*>(
joint->getPropertyByName("ObjectToGround")
);
if (!propObj) {
continue;
}
@@ -125,8 +130,7 @@ void AssemblyLink::onChanged(const App::Property* prop)
// movePlc needs to be computed before updateContents.
App::DocumentObject* firstLink = nullptr;
for (auto* obj : Group.getValues()) {
if (obj
&& (obj->isDerivedFrom<App::Link>() || obj->isDerivedFrom<AssemblyLink>())) {
if (obj && (obj->isDerivedFrom<App::Link>() || obj->isDerivedFrom<AssemblyLink>())) {
firstLink = obj;
break;
}
@@ -143,9 +147,11 @@ void AssemblyLink::onChanged(const App::Property* prop)
if (sourceObj) {
auto* propSource = dynamic_cast<App::PropertyPlacement*>(
sourceObj->getPropertyByName("Placement"));
sourceObj->getPropertyByName("Placement")
);
auto* propLink = dynamic_cast<App::PropertyPlacement*>(
firstLink->getPropertyByName("Placement"));
firstLink->getPropertyByName("Placement")
);
if (propSource && propLink) {
movePlc = propLink->getValue() * propSource->getValue().inverse();
@@ -179,8 +185,8 @@ void AssemblyLink::onChanged(const App::Property* prop)
if (obj->isLinkGroup()) {
auto* srcLink = static_cast<App::Link*>(obj);
const std::vector<App::DocumentObject*> srcElements =
srcLink->ElementList.getValues();
const std::vector<App::DocumentObject*> srcElements
= srcLink->ElementList.getValues();
for (auto elt : srcElements) {
if (!elt) {
@@ -188,7 +194,8 @@ void AssemblyLink::onChanged(const App::Property* prop)
}
auto* prop = dynamic_cast<App::PropertyPlacement*>(
elt->getPropertyByName("Placement"));
elt->getPropertyByName("Placement")
);
if (prop) {
prop->setValue(plc * prop->getValue());
}
@@ -196,7 +203,8 @@ void AssemblyLink::onChanged(const App::Property* prop)
}
else {
auto* prop = dynamic_cast<App::PropertyPlacement*>(
obj->getPropertyByName("Placement"));
obj->getPropertyByName("Placement")
);
if (prop) {
prop->setValue(plc * prop->getValue());
}
@@ -278,10 +286,10 @@ void AssemblyLink::synchronizeComponents()
// same number of elements.
linkGroupsAdded.insert(srcLink);
const std::vector<App::DocumentObject*> srcElements =
srcLink->ElementList.getValues();
const std::vector<App::DocumentObject*> newElements =
link2->ElementList.getValues();
const std::vector<App::DocumentObject*> srcElements
= srcLink->ElementList.getValues();
const std::vector<App::DocumentObject*> newElements
= link2->ElementList.getValues();
for (int i = 0; i < srcElements.size(); ++i) {
objLinkMap[srcElements[i]] = newElements[i];
}
@@ -309,8 +317,8 @@ void AssemblyLink::synchronizeComponents()
if (obj->isDerivedFrom<AssemblyLink>()) {
auto* asmLink = static_cast<AssemblyLink*>(obj);
App::DocumentObject* newObj =
doc->addObject("Assembly::AssemblyLink", obj->getNameInDocument());
App::DocumentObject* newObj
= doc->addObject("Assembly::AssemblyLink", obj->getNameInDocument());
auto* subAsmLink = static_cast<AssemblyLink*>(newObj);
subAsmLink->LinkedObject.setValue(obj);
subAsmLink->Rigid.setValue(asmLink->Rigid.getValue());
@@ -321,18 +329,17 @@ void AssemblyLink::synchronizeComponents()
else if (obj->isDerivedFrom<App::Link>() && obj->isLinkGroup()) {
auto* srcLink = static_cast<App::Link*>(obj);
auto* newLink =
static_cast<App::Link*>(doc->addObject("App::Link", obj->getNameInDocument()));
auto* newLink = static_cast<App::Link*>(
doc->addObject("App::Link", obj->getNameInDocument())
);
newLink->LinkedObject.setValue(srcLink->getTrueLinkedObject(false));
newLink->Label.setValue(obj->Label.getValue());
addObject(newLink);
newLink->ElementCount.setValue(srcLink->ElementCount.getValue());
const std::vector<App::DocumentObject*> srcElements =
srcLink->ElementList.getValues();
const std::vector<App::DocumentObject*> newElements =
newLink->ElementList.getValues();
const std::vector<App::DocumentObject*> srcElements = srcLink->ElementList.getValues();
const std::vector<App::DocumentObject*> newElements = newLink->ElementList.getValues();
for (int i = 0; i < srcElements.size(); ++i) {
auto* newObj = newElements[i];
auto* srcObj = srcElements[i];
@@ -387,9 +394,11 @@ void AssemblyLink::synchronizeComponents()
namespace
{
template<typename T>
void copyPropertyIfDifferent(App::DocumentObject* source,
App::DocumentObject* target,
const char* propertyName)
void copyPropertyIfDifferent(
App::DocumentObject* source,
App::DocumentObject* target,
const char* propertyName
)
{
auto sourceProp = freecad_cast<T*>(source->getPropertyByName(propertyName));
auto targetProp = freecad_cast<T*>(target->getPropertyByName(propertyName));
@@ -412,8 +421,11 @@ std::string removeUpToName(const std::string& sub, const std::string& name)
return sub;
}
std::string
replaceLastOccurrence(const std::string& str, const std::string& oldStr, const std::string& newStr)
std::string replaceLastOccurrence(
const std::string& str,
const std::string& oldStr,
const std::string& newStr
)
{
size_t pos = str.rfind(oldStr);
if (pos != std::string::npos) {
@@ -435,8 +447,8 @@ void AssemblyLink::synchronizeJoints()
JointGroup* jGroup = ensureJointGroup();
std::vector<App::DocumentObject*> assemblyJoints =
assembly->getJoints(assembly->isTouched(), false, false);
std::vector<App::DocumentObject*> assemblyJoints
= assembly->getJoints(assembly->isTouched(), false, false);
std::vector<App::DocumentObject*> assemblyLinkJoints = getJoints();
// We delete the excess of joints if any
@@ -495,9 +507,11 @@ void AssemblyLink::synchronizeJoints()
}
void AssemblyLink::handleJointReference(App::DocumentObject* joint,
App::DocumentObject* lJoint,
const char* refName)
void AssemblyLink::handleJointReference(
App::DocumentObject* joint,
App::DocumentObject* lJoint,
const char* refName
)
{
AssemblyObject* assembly = getLinkedAssembly();

View File

@@ -75,9 +75,11 @@ public:
void synchronizeComponents();
void synchronizeJoints();
void handleJointReference(App::DocumentObject* joint,
App::DocumentObject* lJoint,
const char* refName);
void handleJointReference(
App::DocumentObject* joint,
App::DocumentObject* lJoint,
const char* refName
);
void ensureNoJointGroup();
JointGroup* ensureJointGroup();
std::vector<App::DocumentObject*> getJoints();

View File

@@ -129,7 +129,8 @@ App::DocumentObjectExecReturn* AssemblyObject::execute()
App::DocumentObjectExecReturn* ret = App::Part::execute();
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Assembly");
"User parameter:BaseApp/Preferences/Mod/Assembly"
);
if (hGrp->GetBool("SolveOnRecompute", true)) {
solve();
}
@@ -305,7 +306,8 @@ void AssemblyObject::doDragStep()
Base::Placement plc = getPlacementFromProp(part, "Placement");
Base::Vector3d pos = plc.getPosition();
mbdPart->updateMbDFromPosition3D(
std::make_shared<FullColumn<double>>(ListD {pos.x, pos.y, pos.z}));
std::make_shared<FullColumn<double>>(ListD {pos.x, pos.y, pos.z})
);
// Update the MBD part's rotation
Base::Rotation rot = plc.getRotation();
@@ -314,8 +316,7 @@ void AssemblyObject::doDragStep()
Base::Vector3d r0 = mat.getRow(0);
Base::Vector3d r1 = mat.getRow(1);
Base::Vector3d r2 = mat.getRow(2);
mbdPart
->updateMbDFromRotationMatrix(r0.x, r0.y, r0.z, r1.x, r1.y, r1.z, r2.x, r2.y, r2.z);
mbdPart->updateMbDFromRotationMatrix(r0.x, r0.y, r0.z, r1.x, r1.y, r1.z, r2.x, r2.y, r2.z);
}
// Timing mbdAssembly->runDragStep()
@@ -362,8 +363,9 @@ bool AssemblyObject::validateNewPlacements()
// First we check if a grounded object has moved. It can happen that they flip.
auto groundedParts = getGroundedParts();
for (auto* obj : groundedParts) {
auto* propPlacement =
dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
auto* propPlacement = dynamic_cast<App::PropertyPlacement*>(
obj->getPropertyByName("Placement")
);
if (propPlacement) {
Base::Placement oldPlc = propPlacement->getValue();
@@ -378,7 +380,8 @@ bool AssemblyObject::validateNewPlacements()
if (!oldPlc.isSame(newPlacement, Precision::Confusion())) {
Base::Console().warning(
"Assembly : Ignoring bad solve, a grounded object (%s) moved.\n",
obj->getFullLabel());
obj->getFullLabel()
);
return false;
}
}
@@ -432,8 +435,9 @@ void AssemblyObject::undoSolve()
}
// Check if the object has a "Placement" property
auto* propPlacement =
dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
auto* propPlacement = dynamic_cast<App::PropertyPlacement*>(
obj->getPropertyByName("Placement")
);
if (!propPlacement) {
continue;
}
@@ -475,8 +479,9 @@ void AssemblyObject::setNewPlacements()
}
// Check if the object has a "Placement" property
auto* propPlacement =
dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
auto* propPlacement = dynamic_cast<App::PropertyPlacement*>(
obj->getPropertyByName("Placement")
);
if (!propPlacement) {
continue;
}
@@ -562,7 +567,8 @@ std::shared_ptr<ASMTAssembly> AssemblyObject::makeMbdAssembly()
assembly->setName("OndselAssembly");
ParameterGrp::handle hPgr = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Assembly");
"User parameter:BaseApp/Preferences/Mod/Assembly"
);
assembly->setDebug(hPgr->GetBool("LogSolverDebug", false));
return assembly;
@@ -571,7 +577,8 @@ std::shared_ptr<ASMTAssembly> AssemblyObject::makeMbdAssembly()
App::DocumentObject* AssemblyObject::getJointOfPartConnectingToGround(
App::DocumentObject* part,
std::string& name,
const std::vector<App::DocumentObject*>& excludeJoints)
const std::vector<App::DocumentObject*>& excludeJoints
)
{
if (!part) {
return nullptr;
@@ -644,8 +651,7 @@ ViewGroup* AssemblyObject::getExplodedViewGroup() const
return nullptr;
}
std::vector<App::DocumentObject*>
AssemblyObject::getJoints(bool updateJCS, bool delBadJoints, bool subJoints)
std::vector<App::DocumentObject*> AssemblyObject::getJoints(bool updateJCS, bool delBadJoints, bool subJoints)
{
std::vector<App::DocumentObject*> joints = {};
@@ -775,8 +781,7 @@ std::unordered_set<App::DocumentObject*> AssemblyObject::getGroundedParts()
continue;
}
auto* propObj =
dynamic_cast<App::PropertyLink*>(gJoint->getPropertyByName("ObjectToGround"));
auto* propObj = dynamic_cast<App::PropertyLink*>(gJoint->getPropertyByName("ObjectToGround"));
if (propObj) {
App::DocumentObject* objToGround = propObj->getValue();
@@ -830,9 +835,7 @@ std::unordered_set<App::DocumentObject*> AssemblyObject::fixGroundedParts()
return groundedParts;
}
void AssemblyObject::fixGroundedPart(App::DocumentObject* obj,
Base::Placement& plc,
std::string& name)
void AssemblyObject::fixGroundedPart(App::DocumentObject* obj, Base::Placement& plc, std::string& name)
{
if (!obj) {
return;
@@ -937,8 +940,10 @@ bool AssemblyObject::isObjInSetOfObjRefs(App::DocumentObject* obj, const std::ve
return false;
}
void AssemblyObject::removeUnconnectedJoints(std::vector<App::DocumentObject*>& joints,
std::unordered_set<App::DocumentObject*> groundedObjs)
void AssemblyObject::removeUnconnectedJoints(
std::vector<App::DocumentObject*>& joints,
std::unordered_set<App::DocumentObject*> groundedObjs
)
{
std::vector<ObjRef> connectedParts;
@@ -953,22 +958,28 @@ void AssemblyObject::removeUnconnectedJoints(std::vector<App::DocumentObject*>&
}
// Filter out unconnected joints
joints.erase(std::remove_if(joints.begin(),
joints.end(),
[&](App::DocumentObject* joint) {
App::DocumentObject* obj1 =
getMovingPartFromRef(this, joint, "Reference1");
App::DocumentObject* obj2 =
getMovingPartFromRef(this, joint, "Reference2");
return (!isObjInSetOfObjRefs(obj1, connectedParts)
|| !isObjInSetOfObjRefs(obj2, connectedParts));
}),
joints.end());
joints.erase(
std::remove_if(
joints.begin(),
joints.end(),
[&](App::DocumentObject* joint) {
App::DocumentObject* obj1 = getMovingPartFromRef(this, joint, "Reference1");
App::DocumentObject* obj2 = getMovingPartFromRef(this, joint, "Reference2");
return (
!isObjInSetOfObjRefs(obj1, connectedParts)
|| !isObjInSetOfObjRefs(obj2, connectedParts)
);
}
),
joints.end()
);
}
void AssemblyObject::traverseAndMarkConnectedParts(App::DocumentObject* currentObj,
std::vector<ObjRef>& connectedParts,
const std::vector<App::DocumentObject*>& joints)
void AssemblyObject::traverseAndMarkConnectedParts(
App::DocumentObject* currentObj,
std::vector<ObjRef>& connectedParts,
const std::vector<App::DocumentObject*>& joints
)
{
// getConnectedParts returns the objs connected to the currentObj by any joint
auto connectedObjs = getConnectedParts(currentObj, joints);
@@ -981,9 +992,10 @@ void AssemblyObject::traverseAndMarkConnectedParts(App::DocumentObject* currentO
}
}
std::vector<ObjRef>
AssemblyObject::getConnectedParts(App::DocumentObject* part,
const std::vector<App::DocumentObject*>& joints)
std::vector<ObjRef> AssemblyObject::getConnectedParts(
App::DocumentObject* part,
const std::vector<App::DocumentObject*>& joints
)
{
if (!part) {
return {};
@@ -1004,16 +1016,14 @@ AssemblyObject::getConnectedParts(App::DocumentObject* part,
}
if (obj1 == part) {
auto* ref =
dynamic_cast<App::PropertyXLinkSub*>(joint->getPropertyByName("Reference2"));
auto* ref = dynamic_cast<App::PropertyXLinkSub*>(joint->getPropertyByName("Reference2"));
if (!ref) {
continue;
}
connectedParts.push_back({obj2, ref});
}
else if (obj2 == part) {
auto* ref =
dynamic_cast<App::PropertyXLinkSub*>(joint->getPropertyByName("Reference1"));
auto* ref = dynamic_cast<App::PropertyXLinkSub*>(joint->getPropertyByName("Reference1"));
if (!ref) {
continue;
}
@@ -1105,8 +1115,7 @@ void Assembly::AssemblyObject::create_mbdSimulationParameters(App::DocumentObjec
mbdSim->seterrorTol(valueOf(sim, "fGlobalErrorTolerance"));
}
std::shared_ptr<ASMTJoint> AssemblyObject::makeMbdJointOfType(App::DocumentObject* joint,
JointType type)
std::shared_ptr<ASMTJoint> AssemblyObject::makeMbdJointOfType(App::DocumentObject* joint, JointType type)
{
switch (type) {
case JointType::Fixed:
@@ -1222,8 +1231,8 @@ std::shared_ptr<ASMTJoint> AssemblyObject::makeMbdJointDistance(App::DocumentObj
case DistanceType::CircleCircle: {
auto mbdJoint = CREATE<ASMTRevCylJoint>::With();
mbdJoint->distanceIJ =
getJointDistance(joint) + getEdgeRadius(obj1, elt1) + getEdgeRadius(obj2, elt2);
mbdJoint->distanceIJ = getJointDistance(joint) + getEdgeRadius(obj1, elt1)
+ getEdgeRadius(obj2, elt2);
return mbdJoint;
}
@@ -1254,22 +1263,22 @@ std::shared_ptr<ASMTJoint> AssemblyObject::makeMbdJointDistance(App::DocumentObj
case DistanceType::CylinderCylinder: {
auto mbdJoint = CREATE<ASMTRevCylJoint>::With();
mbdJoint->distanceIJ =
getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2);
mbdJoint->distanceIJ = getJointDistance(joint) + getFaceRadius(obj1, elt1)
+ getFaceRadius(obj2, elt2);
return mbdJoint;
}
case DistanceType::CylinderSphere: {
auto mbdJoint = CREATE<ASMTCylSphJoint>::With();
mbdJoint->distanceIJ =
getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2);
mbdJoint->distanceIJ = getJointDistance(joint) + getFaceRadius(obj1, elt1)
+ getFaceRadius(obj2, elt2);
return mbdJoint;
}
case DistanceType::CylinderTorus: {
auto mbdJoint = CREATE<ASMTRevCylJoint>::With();
mbdJoint->distanceIJ =
getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2);
mbdJoint->distanceIJ = getJointDistance(joint) + getFaceRadius(obj1, elt1)
+ getFaceRadius(obj2, elt2);
return mbdJoint;
}
@@ -1281,15 +1290,15 @@ std::shared_ptr<ASMTJoint> AssemblyObject::makeMbdJointDistance(App::DocumentObj
case DistanceType::TorusSphere: {
auto mbdJoint = CREATE<ASMTCylSphJoint>::With();
mbdJoint->distanceIJ =
getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2);
mbdJoint->distanceIJ = getJointDistance(joint) + getFaceRadius(obj1, elt1)
+ getFaceRadius(obj2, elt2);
return mbdJoint;
}
case DistanceType::SphereSphere: {
auto mbdJoint = CREATE<ASMTSphSphJoint>::With();
mbdJoint->distanceIJ =
getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2);
mbdJoint->distanceIJ = getJointDistance(joint) + getFaceRadius(obj1, elt1)
+ getFaceRadius(obj2, elt2);
return mbdJoint;
}
@@ -1345,8 +1354,7 @@ std::shared_ptr<ASMTJoint> AssemblyObject::makeMbdJointDistance(App::DocumentObj
}
}
std::vector<std::shared_ptr<MbD::ASMTJoint>>
AssemblyObject::makeMbdJoint(App::DocumentObject* joint)
std::vector<std::shared_ptr<MbD::ASMTJoint>> AssemblyObject::makeMbdJoint(App::DocumentObject* joint)
{
if (!joint) {
return {};
@@ -1378,17 +1386,16 @@ AssemblyObject::makeMbdJoint(App::DocumentObject* joint)
// Add limits if needed. We do not add if this is a simulation or their might clash.
if (motions.empty()) {
if (jointType == JointType::Slider || jointType == JointType::Cylindrical) {
auto* pLenMin =
dynamic_cast<App::PropertyFloat*>(joint->getPropertyByName("LengthMin"));
auto* pLenMax =
dynamic_cast<App::PropertyFloat*>(joint->getPropertyByName("LengthMax"));
auto* pMinEnabled =
dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("EnableLengthMin"));
auto* pMaxEnabled =
dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("EnableLengthMax"));
auto* pLenMin = dynamic_cast<App::PropertyFloat*>(joint->getPropertyByName("LengthMin"));
auto* pLenMax = dynamic_cast<App::PropertyFloat*>(joint->getPropertyByName("LengthMax"));
auto* pMinEnabled = dynamic_cast<App::PropertyBool*>(
joint->getPropertyByName("EnableLengthMin")
);
auto* pMaxEnabled = dynamic_cast<App::PropertyBool*>(
joint->getPropertyByName("EnableLengthMax")
);
if (pLenMin && pLenMax && pMinEnabled
&& pMaxEnabled) { // Make sure properties do exist
if (pLenMin && pLenMax && pMinEnabled && pMaxEnabled) { // Make sure properties do exist
// Swap the values if necessary.
bool minEnabled = pMinEnabled->getValue();
bool maxEnabled = pMaxEnabled->getValue();
@@ -1433,13 +1440,14 @@ AssemblyObject::makeMbdJoint(App::DocumentObject* joint)
if (jointType == JointType::Revolute || jointType == JointType::Cylindrical) {
auto* pRotMin = dynamic_cast<App::PropertyFloat*>(joint->getPropertyByName("AngleMin"));
auto* pRotMax = dynamic_cast<App::PropertyFloat*>(joint->getPropertyByName("AngleMax"));
auto* pMinEnabled =
dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("EnableAngleMin"));
auto* pMaxEnabled =
dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("EnableAngleMax"));
auto* pMinEnabled = dynamic_cast<App::PropertyBool*>(
joint->getPropertyByName("EnableAngleMin")
);
auto* pMaxEnabled = dynamic_cast<App::PropertyBool*>(
joint->getPropertyByName("EnableAngleMax")
);
if (pRotMin && pRotMax && pMinEnabled
&& pMaxEnabled) { // Make sure properties do exist
if (pRotMin && pRotMax && pMinEnabled && pMaxEnabled) { // Make sure properties do exist
// Swap the values if necessary.
bool minEnabled = pMinEnabled->getValue();
bool maxEnabled = pMaxEnabled->getValue();
@@ -1497,8 +1505,7 @@ AssemblyObject::makeMbdJoint(App::DocumentObject* joint)
continue;
}
auto* pType =
dynamic_cast<App::PropertyEnumeration*>(motion->getPropertyByName("MotionType"));
auto* pType = dynamic_cast<App::PropertyEnumeration*>(motion->getPropertyByName("MotionType"));
auto* pFormula = dynamic_cast<App::PropertyString*>(motion->getPropertyByName("Formula"));
if (!pType || !pFormula) {
continue;
@@ -1521,10 +1528,10 @@ AssemblyObject::makeMbdJoint(App::DocumentObject* joint)
continue;
}
auto* pType2 =
dynamic_cast<App::PropertyEnumeration*>(motion2->getPropertyByName("MotionType"));
auto* pFormula2 =
dynamic_cast<App::PropertyString*>(motion2->getPropertyByName("Formula"));
auto* pType2 = dynamic_cast<App::PropertyEnumeration*>(
motion2->getPropertyByName("MotionType")
);
auto* pFormula2 = dynamic_cast<App::PropertyString*>(motion2->getPropertyByName("Formula"));
if (!pType2 || !pFormula2) {
continue;
}
@@ -1569,17 +1576,18 @@ AssemblyObject::makeMbdJoint(App::DocumentObject* joint)
return {mbdJoint};
}
std::string AssemblyObject::handleOneSideOfJoint(App::DocumentObject* joint,
const char* propRefName,
const char* propPlcName)
std::string AssemblyObject::handleOneSideOfJoint(
App::DocumentObject* joint,
const char* propRefName,
const char* propPlcName
)
{
App::DocumentObject* part = getMovingPartFromRef(this, joint, propRefName);
App::DocumentObject* obj = getObjFromRef(joint, propRefName);
if (!part || !obj) {
Base::Console().warning("The property %s of Joint %s is bad.",
propRefName,
joint->getFullName());
Base::Console()
.warning("The property %s of Joint %s is bad.", propRefName, joint->getFullName());
return "";
}
@@ -1614,9 +1622,11 @@ std::string AssemblyObject::handleOneSideOfJoint(App::DocumentObject* joint,
return "/OndselAssembly/" + mbdPart->name + "/" + markerName;
}
void AssemblyObject::getRackPinionMarkers(App::DocumentObject* joint,
std::string& markerNameI,
std::string& markerNameJ)
void AssemblyObject::getRackPinionMarkers(
App::DocumentObject* joint,
std::string& markerNameI,
std::string& markerNameJ
)
{
// ASMT rack pinion joint must get the rack as I and pinion as J.
// - rack marker has to have Z axis parallel to pinion Z axis.
@@ -1741,8 +1751,7 @@ int AssemblyObject::slidingPartIndex(App::DocumentObject* joint)
double y1, p1, r1, y2, p2, r2;
plcjt.getRotation().getYawPitchRoll(y1, p1, r1);
plci.getRotation().getYawPitchRoll(y2, p2, r2);
if (fabs(p1 - p2) < Precision::Confusion()
&& fabs(r1 - r2) < Precision::Confusion()) {
if (fabs(p1 - p2) < Precision::Confusion() && fabs(r1 - r2) < Precision::Confusion()) {
slidingFound = found;
}
}
@@ -1767,7 +1776,8 @@ bool AssemblyObject::isMbDJointValid(App::DocumentObject* joint)
Base::Console().warning(
"Assembly: Ignoring joint (%s) because its parts are connected by a fixed "
"joint bundle. This joint is a conflicting or redundant constraint.\n",
joint->getFullLabel());
joint->getFullLabel()
);
return false;
}
return true;
@@ -1828,8 +1838,7 @@ std::shared_ptr<ASMTPart> AssemblyObject::getMbDPart(App::DocumentObject* part)
return getMbDData(part).part;
}
std::shared_ptr<ASMTPart>
AssemblyObject::makeMbdPart(std::string& name, Base::Placement plc, double mass)
std::shared_ptr<ASMTPart> AssemblyObject::makeMbdPart(std::string& name, Base::Placement plc, double mass)
{
auto mbdPart = CREATE<ASMTPart>::With();
mbdPart->setName(name);
@@ -1875,8 +1884,10 @@ std::shared_ptr<ASMTMarker> AssemblyObject::makeMbdMarker(std::string& name, Bas
return mbdMarker;
}
std::vector<ObjRef> AssemblyObject::getDownstreamParts(App::DocumentObject* part,
App::DocumentObject* joint)
std::vector<ObjRef> AssemblyObject::getDownstreamParts(
App::DocumentObject* part,
App::DocumentObject* joint
)
{
if (!part) {
return {};
@@ -1908,11 +1919,12 @@ std::vector<ObjRef> AssemblyObject::getDownstreamParts(App::DocumentObject* part
return downstreamParts;
}
App::DocumentObject*
AssemblyObject::getUpstreamMovingPart(App::DocumentObject* part,
App::DocumentObject*& joint,
std::string& name,
std::vector<App::DocumentObject*> excludeJoints)
App::DocumentObject* AssemblyObject::getUpstreamMovingPart(
App::DocumentObject* part,
App::DocumentObject*& joint,
std::string& name,
std::vector<App::DocumentObject*> excludeJoints
)
{
if (!part || isPartGrounded(part)) {
return nullptr;
@@ -1956,8 +1968,9 @@ std::vector<AssemblyLink*> AssemblyObject::getSubAssemblies()
App::Document* doc = getDocument();
std::vector<DocumentObject*> assemblies =
doc->getObjectsOfType(Assembly::AssemblyLink::getClassTypeId());
std::vector<DocumentObject*> assemblies = doc->getObjectsOfType(
Assembly::AssemblyLink::getClassTypeId()
);
for (auto assembly : assemblies) {
if (hasObject(assembly)) {
subAssemblies.push_back(freecad_cast<AssemblyLink*>(assembly));

View File

@@ -118,8 +118,11 @@ public:
// Ondsel Solver interface
std::shared_ptr<MbD::ASMTAssembly> makeMbdAssembly();
void create_mbdSimulationParameters(App::DocumentObject* sim);
std::shared_ptr<MbD::ASMTPart>
makeMbdPart(std::string& name, Base::Placement plc = Base::Placement(), double mass = 1.0);
std::shared_ptr<MbD::ASMTPart> makeMbdPart(
std::string& name,
Base::Placement plc = Base::Placement(),
double mass = 1.0
);
std::shared_ptr<MbD::ASMTPart> getMbDPart(App::DocumentObject* obj);
// To help the solver, during dragging, we are bundling parts connected by a fixed joint.
// So several assembly components are bundled in a single ASMTPart.
@@ -133,15 +136,18 @@ public:
MbDPartData getMbDData(App::DocumentObject* part);
std::shared_ptr<MbD::ASMTMarker> makeMbdMarker(std::string& name, Base::Placement& plc);
std::vector<std::shared_ptr<MbD::ASMTJoint>> makeMbdJoint(App::DocumentObject* joint);
std::shared_ptr<MbD::ASMTJoint> makeMbdJointOfType(App::DocumentObject* joint,
JointType jointType);
std::shared_ptr<MbD::ASMTJoint> makeMbdJointOfType(App::DocumentObject* joint, JointType jointType);
std::shared_ptr<MbD::ASMTJoint> makeMbdJointDistance(App::DocumentObject* joint);
std::string handleOneSideOfJoint(App::DocumentObject* joint,
const char* propRefName,
const char* propPlcName);
void getRackPinionMarkers(App::DocumentObject* joint,
std::string& markerNameI,
std::string& markerNameJ);
std::string handleOneSideOfJoint(
App::DocumentObject* joint,
const char* propRefName,
const char* propPlcName
);
void getRackPinionMarkers(
App::DocumentObject* joint,
std::string& markerNameI,
std::string& markerNameJ
);
int slidingPartIndex(App::DocumentObject* joint);
void jointParts(std::vector<App::DocumentObject*> joints);
@@ -150,15 +156,19 @@ public:
template<typename T>
T* getGroup();
std::vector<App::DocumentObject*>
getJoints(bool updateJCS = true, bool delBadJoints = false, bool subJoints = true);
std::vector<App::DocumentObject*> getJoints(
bool updateJCS = true,
bool delBadJoints = false,
bool subJoints = true
);
std::vector<App::DocumentObject*> getGroundedJoints();
std::vector<App::DocumentObject*> getJointsOfObj(App::DocumentObject* obj);
std::vector<App::DocumentObject*> getJointsOfPart(App::DocumentObject* part);
App::DocumentObject*
getJointOfPartConnectingToGround(App::DocumentObject* part,
std::string& name,
const std::vector<App::DocumentObject*>& excludeJoints = {});
App::DocumentObject* getJointOfPartConnectingToGround(
App::DocumentObject* part,
std::string& name,
const std::vector<App::DocumentObject*>& excludeJoints = {}
);
std::unordered_set<App::DocumentObject*> getGroundedParts();
std::unordered_set<App::DocumentObject*> fixGroundedParts();
void fixGroundedPart(App::DocumentObject* obj, Base::Placement& plc, std::string& jointName);
@@ -167,23 +177,32 @@ public:
bool isJointTypeConnecting(App::DocumentObject* joint);
bool isObjInSetOfObjRefs(App::DocumentObject* obj, const std::vector<ObjRef>& pairs);
void removeUnconnectedJoints(std::vector<App::DocumentObject*>& joints,
std::unordered_set<App::DocumentObject*> groundedObjs);
void traverseAndMarkConnectedParts(App::DocumentObject* currentPart,
std::vector<ObjRef>& connectedParts,
const std::vector<App::DocumentObject*>& joints);
std::vector<ObjRef> getConnectedParts(App::DocumentObject* part,
const std::vector<App::DocumentObject*>& joints);
void removeUnconnectedJoints(
std::vector<App::DocumentObject*>& joints,
std::unordered_set<App::DocumentObject*> groundedObjs
);
void traverseAndMarkConnectedParts(
App::DocumentObject* currentPart,
std::vector<ObjRef>& connectedParts,
const std::vector<App::DocumentObject*>& joints
);
std::vector<ObjRef> getConnectedParts(
App::DocumentObject* part,
const std::vector<App::DocumentObject*>& joints
);
bool isPartGrounded(App::DocumentObject* part);
bool isPartConnected(App::DocumentObject* part);
std::vector<ObjRef> getDownstreamParts(App::DocumentObject* part,
App::DocumentObject* joint = nullptr);
App::DocumentObject*
getUpstreamMovingPart(App::DocumentObject* part,
App::DocumentObject*& joint,
std::string& name,
std::vector<App::DocumentObject*> excludeJoints = {});
std::vector<ObjRef> getDownstreamParts(
App::DocumentObject* part,
App::DocumentObject* joint = nullptr
);
App::DocumentObject* getUpstreamMovingPart(
App::DocumentObject* part,
App::DocumentObject*& joint,
std::string& name,
std::vector<App::DocumentObject*> excludeJoints = {}
);
double getObjMass(App::DocumentObject* obj);
void setObjMasses(std::vector<std::pair<App::DocumentObject*, double>> objectMasses);

View File

@@ -205,12 +205,14 @@ PyObject* AssemblyObjectPy::getDownstreamParts(PyObject* args) const
PyObject* pyJoint;
// Parse the two arguments: a part object and a joint object
if (!PyArg_ParseTuple(args,
"O!O!",
&(App::DocumentObjectPy::Type),
&pyPart,
&(App::DocumentObjectPy::Type),
&pyJoint)) {
if (!PyArg_ParseTuple(
args,
"O!O!",
&(App::DocumentObjectPy::Type),
&pyPart,
&(App::DocumentObjectPy::Type),
&pyJoint
)) {
return nullptr;
}
@@ -218,8 +220,8 @@ PyObject* AssemblyObjectPy::getDownstreamParts(PyObject* args) const
auto* joint = static_cast<App::DocumentObjectPy*>(pyJoint)->getDocumentObjectPtr();
// Call the C++ method
std::vector<Assembly::ObjRef> downstreamParts =
this->getAssemblyObjectPtr()->getDownstreamParts(part, joint);
std::vector<Assembly::ObjRef> downstreamParts
= this->getAssemblyObjectPtr()->getDownstreamParts(part, joint);
// Convert the result into a Python list of DocumentObjects
Py::List ret;

View File

@@ -84,9 +84,7 @@ void swapJCS(const App::DocumentObject* joint)
}
}
bool isEdgeType(const App::DocumentObject* obj,
const std::string& elName,
const GeomAbs_CurveType type)
bool isEdgeType(const App::DocumentObject* obj, const std::string& elName, const GeomAbs_CurveType type)
{
auto* base = dynamic_cast<const PartApp::Feature*>(obj);
if (!base) {
@@ -102,9 +100,7 @@ bool isEdgeType(const App::DocumentObject* obj,
return sf.GetType() == type;
}
bool isFaceType(const App::DocumentObject* obj,
const std::string& elName,
const GeomAbs_SurfaceType type)
bool isFaceType(const App::DocumentObject* obj, const std::string& elName, const GeomAbs_SurfaceType type)
{
auto* base = dynamic_cast<const PartApp::Feature*>(obj);
if (!base) {
@@ -537,8 +533,8 @@ App::DocumentObject* getObjFromRef(const App::DocumentObject* obj, const std::st
const auto isBodySubObject = [](App::DocumentObject* obj) -> bool {
// PartDesign::Point + Line + Plane + CoordinateSystem
// getViewProviderName instead of isDerivedFrom to avoid dependency on sketcher
const auto isDerivedFromVpSketch =
strcmp(obj->getViewProviderName(), "SketcherGui::ViewProviderSketch") == 0;
const auto isDerivedFromVpSketch
= strcmp(obj->getViewProviderName(), "SketcherGui::ViewProviderSketch") == 0;
return isDerivedFromVpSketch || obj->isDerivedFrom<PartApp::Datum>()
|| obj->isDerivedFrom<App::DatumElement>()
|| obj->isDerivedFrom<App::LocalCoordinateSystem>();
@@ -645,9 +641,11 @@ App::DocumentObject* getLinkedObjFromRef(const App::DocumentObject* joint, const
return nullptr;
}
App::DocumentObject* getMovingPartFromRef(const AssemblyObject* assemblyObject,
App::DocumentObject* obj,
const std::string& sub)
App::DocumentObject* getMovingPartFromRef(
const AssemblyObject* assemblyObject,
App::DocumentObject* obj,
const std::string& sub
)
{
if (!obj) {
return nullptr;
@@ -700,8 +698,10 @@ App::DocumentObject* getMovingPartFromRef(const AssemblyObject* assemblyObject,
return nullptr;
}
App::DocumentObject* getMovingPartFromRef(const AssemblyObject* assemblyObject,
App::PropertyXLinkSub* prop)
App::DocumentObject* getMovingPartFromRef(
const AssemblyObject* assemblyObject,
App::PropertyXLinkSub* prop
)
{
if (!prop) {
return nullptr;
@@ -719,9 +719,11 @@ App::DocumentObject* getMovingPartFromRef(const AssemblyObject* assemblyObject,
return getMovingPartFromRef(assemblyObject, obj, subs[0]);
}
App::DocumentObject* getMovingPartFromRef(const AssemblyObject* assemblyObject,
App::DocumentObject* joint,
const char* pName)
App::DocumentObject* getMovingPartFromRef(
const AssemblyObject* assemblyObject,
App::DocumentObject* joint,
const char* pName
)
{
if (!joint) {
return nullptr;
@@ -733,8 +735,7 @@ App::DocumentObject* getMovingPartFromRef(const AssemblyObject* assemblyObject,
void syncPlacements(App::DocumentObject* src, App::DocumentObject* to)
{
auto* plcPropSource =
dynamic_cast<App::PropertyPlacement*>(src->getPropertyByName("Placement"));
auto* plcPropSource = dynamic_cast<App::PropertyPlacement*>(src->getPropertyByName("Placement"));
auto* plcPropLink = dynamic_cast<App::PropertyPlacement*>(to->getPropertyByName("Placement"));
if (plcPropSource && plcPropLink) {

View File

@@ -134,11 +134,16 @@ class JointGroup;
AssemblyExport void swapJCS(const App::DocumentObject* joint);
AssemblyExport bool
isEdgeType(const App::DocumentObject* obj, const std::string& elName, const GeomAbs_CurveType type);
AssemblyExport bool isFaceType(const App::DocumentObject* obj,
const std::string& elName,
const GeomAbs_SurfaceType type);
AssemblyExport bool isEdgeType(
const App::DocumentObject* obj,
const std::string& elName,
const GeomAbs_CurveType type
);
AssemblyExport bool isFaceType(
const App::DocumentObject* obj,
const std::string& elName,
const GeomAbs_SurfaceType type
);
AssemblyExport double getFaceRadius(const App::DocumentObject* obj, const std::string& elName);
AssemblyExport double getEdgeRadius(const App::DocumentObject* obj, const std::string& elName);
@@ -153,28 +158,37 @@ AssemblyExport double getJointDistance(const App::DocumentObject* joint);
AssemblyExport double getJointDistance2(const App::DocumentObject* joint);
AssemblyExport JointType getJointType(const App::DocumentObject* joint);
AssemblyExport std::string getElementFromProp(const App::DocumentObject* obj, const char* propName);
AssemblyExport std::string getElementTypeFromProp(const App::DocumentObject* obj,
const char* propName);
AssemblyExport App::DocumentObject* getObjFromProp(const App::DocumentObject* joint,
const char* propName);
AssemblyExport App::DocumentObject* getObjFromRef(const App::DocumentObject* obj,
const std::string& sub);
AssemblyExport std::string getElementTypeFromProp(const App::DocumentObject* obj, const char* propName);
AssemblyExport App::DocumentObject* getObjFromProp(
const App::DocumentObject* joint,
const char* propName
);
AssemblyExport App::DocumentObject* getObjFromRef(const App::DocumentObject* obj, const std::string& sub);
AssemblyExport App::DocumentObject* getObjFromRef(const App::PropertyXLinkSub* prop);
AssemblyExport App::DocumentObject* getObjFromRef(const App::DocumentObject* joint,
const char* propName);
AssemblyExport App::DocumentObject* getLinkedObjFromRef(const App::DocumentObject* joint,
const char* propName);
AssemblyExport App::DocumentObject* getMovingPartFromRef(const AssemblyObject* assemblyObject,
App::DocumentObject* obj,
const std::string& sub);
AssemblyExport App::DocumentObject* getMovingPartFromRef(const AssemblyObject* assemblyObject,
const App::PropertyXLinkSub* prop);
AssemblyExport App::DocumentObject* getMovingPartFromRef(const AssemblyObject* assemblyObject,
App::DocumentObject* joint,
const char* pName);
AssemblyExport App::DocumentObject* getObjFromRef(const App::DocumentObject* joint, const char* propName);
AssemblyExport App::DocumentObject* getLinkedObjFromRef(
const App::DocumentObject* joint,
const char* propName
);
AssemblyExport App::DocumentObject* getMovingPartFromRef(
const AssemblyObject* assemblyObject,
App::DocumentObject* obj,
const std::string& sub
);
AssemblyExport App::DocumentObject* getMovingPartFromRef(
const AssemblyObject* assemblyObject,
const App::PropertyXLinkSub* prop
);
AssemblyExport App::DocumentObject* getMovingPartFromRef(
const AssemblyObject* assemblyObject,
App::DocumentObject* joint,
const char* pName
);
AssemblyExport std::vector<std::string> getSubAsList(const App::PropertyXLinkSub* prop);
AssemblyExport std::vector<std::string> getSubAsList(const App::DocumentObject* joint,
const char* propName);
AssemblyExport std::vector<std::string> getSubAsList(
const App::DocumentObject* joint,
const char* propName
);
AssemblyExport void syncPlacements(App::DocumentObject* src, App::DocumentObject* to);
} // namespace Assembly

View File

@@ -58,30 +58,37 @@ PROPERTY_SOURCE(Assembly::BomObject, Spreadsheet::Sheet)
BomObject::BomObject()
: Spreadsheet::Sheet()
{
ADD_PROPERTY_TYPE(columnsNames,
("Index"),
"Bom",
(App::PropertyType)(App::Prop_None),
"List of the columns of the Bill of Materials.");
ADD_PROPERTY_TYPE(
columnsNames,
("Index"),
"Bom",
(App::PropertyType)(App::Prop_None),
"List of the columns of the Bill of Materials."
);
ADD_PROPERTY_TYPE(detailSubAssemblies,
(true),
"Bom",
(App::PropertyType)(App::Prop_None),
"Detail sub-assemblies components.");
ADD_PROPERTY_TYPE(
detailSubAssemblies,
(true),
"Bom",
(App::PropertyType)(App::Prop_None),
"Detail sub-assemblies components."
);
ADD_PROPERTY_TYPE(detailParts,
(true),
"Bom",
(App::PropertyType)(App::Prop_None),
"Detail Parts sub-components.");
ADD_PROPERTY_TYPE(
detailParts,
(true),
"Bom",
(App::PropertyType)(App::Prop_None),
"Detail Parts sub-components."
);
ADD_PROPERTY_TYPE(
onlyParts,
(false),
"Bom",
(App::PropertyType)(App::Prop_None),
"Only Part containers will be added. Solids like PartDesign Bodies will be ignored.");
"Only Part containers will be added. Solids like PartDesign Bodies will be ignored."
);
}
BomObject::~BomObject() = default;
@@ -157,9 +164,11 @@ void BomObject::generateBOM()
}
}
void BomObject::addObjectChildrenToBom(std::vector<App::DocumentObject*> objs,
size_t& row,
std::string index)
void BomObject::addObjectChildrenToBom(
std::vector<App::DocumentObject*> objs,
size_t& row,
std::string index
)
{
int quantityColIndex = getColumnIndex("Quantity");
bool hasQuantityCol = hasQuantityColumn();

View File

@@ -77,8 +77,7 @@ public:
void generateBOM();
void addObjectToBom(App::DocumentObject* obj, size_t row, std::string index);
void
addObjectChildrenToBom(std::vector<App::DocumentObject*> objs, size_t& row, std::string index);
void addObjectChildrenToBom(std::vector<App::DocumentObject*> objs, size_t& row, std::string index);
void saveCustomColumnData();
AssemblyObject* getAssembly();

View File

@@ -24,25 +24,25 @@
#include <FCGlobal.h>
#ifndef ASSEMBLY_GLOBAL_H
#define ASSEMBLY_GLOBAL_H
# define ASSEMBLY_GLOBAL_H
// Assembly
#ifndef AssemblyExport
#ifdef Assembly_EXPORTS
#define AssemblyExport FREECAD_DECL_EXPORT
#else
#define AssemblyExport FREECAD_DECL_IMPORT
#endif
#endif
# ifndef AssemblyExport
# ifdef Assembly_EXPORTS
# define AssemblyExport FREECAD_DECL_EXPORT
# else
# define AssemblyExport FREECAD_DECL_IMPORT
# endif
# endif
// AssemblyGui
#ifndef AssemblyGuiExport
#ifdef AssemblyGui_EXPORTS
#define AssemblyGuiExport FREECAD_DECL_EXPORT
#else
#define AssemblyGuiExport FREECAD_DECL_IMPORT
#endif
#endif
# ifndef AssemblyGuiExport
# ifdef AssemblyGui_EXPORTS
# define AssemblyGuiExport FREECAD_DECL_EXPORT
# else
# define AssemblyGuiExport FREECAD_DECL_IMPORT
# endif
# endif
#endif // ASSEMBLY_GLOBAL_H

View File

@@ -40,7 +40,8 @@ TaskAssemblyMessages::TaskAssemblyMessages(ViewProviderAssembly* vp)
{
// NOLINTBEGIN
connectionSetUp = vp->signalSetUp.connect(
std::bind(&TaskAssemblyMessages::slotSetUp, this, sp::_1, sp::_2, sp::_3, sp::_4));
std::bind(&TaskAssemblyMessages::slotSetUp, this, sp::_1, sp::_2, sp::_3, sp::_4)
);
// NOLINTEND
}
@@ -58,8 +59,10 @@ void TaskAssemblyMessages::updateToolTip(const QString& link)
setLinkTooltip(tr("Click to select these redundant joints."));
}
else if (link == QStringLiteral("#dofs")) {
setLinkTooltip(tr("The assembly has unconstrained components giving rise to those "
"Degrees Of Freedom. Click to select these unconstrained components."));
setLinkTooltip(
tr("The assembly has unconstrained components giving rise to those "
"Degrees Of Freedom. Click to select these unconstrained components.")
);
}
else if (link == QStringLiteral("#malformed")) {
setLinkTooltip(tr("Click to select these malformed joints."));

View File

@@ -99,7 +99,8 @@ void printPlacement(Base::Placement plc, const char* name)
axis.x,
axis.y,
axis.z,
angle);
angle
);
}
PROPERTY_SOURCE(AssemblyGui::ViewProviderAssembly, Gui::ViewProviderPart)
@@ -118,7 +119,8 @@ ViewProviderAssembly::ViewProviderAssembly()
, docsToMove({})
{
m_preTransactionConn = App::GetApplication().signalBeforeOpenTransaction.connect(
std::bind(&ViewProviderAssembly::slotAboutToOpenTransaction, this, std::placeholders::_1));
std::bind(&ViewProviderAssembly::slotAboutToOpenTransaction, this, std::placeholders::_1)
);
}
ViewProviderAssembly::~ViewProviderAssembly()
@@ -138,9 +140,7 @@ void ViewProviderAssembly::setupContextMenu(QMenu* menu, QObject* receiver, cons
QAction* act = menu->addAction(QObject::tr("Active object"));
act->setCheckable(true);
act->setChecked(isActivePart());
func->trigger(act, [this]() {
this->doubleClicked();
});
func->trigger(act, [this]() { this->doubleClicked(); });
ViewProviderDragger::setupContextMenu(menu, receiver, member); // NOLINT
}
@@ -175,8 +175,7 @@ bool ViewProviderAssembly::canDragObject(App::DocumentObject* obj) const
return obj && !obj->is<Assembly::JointGroup>();
}
bool ViewProviderAssembly::canDragObjectToTarget(App::DocumentObject* obj,
App::DocumentObject* target) const
bool ViewProviderAssembly::canDragObjectToTarget(App::DocumentObject* obj, App::DocumentObject* target) const
{
// If a solid is removed from the assembly, its joints need to be removed.
bool prompted = false;
@@ -206,7 +205,8 @@ bool ViewProviderAssembly::canDragObjectToTarget(App::DocumentObject* obj,
QMessageBox msgBox(Gui::getMainWindow());
msgBox.setText(tr("The object is associated to one or more joints."));
msgBox.setInformativeText(
tr("Do you want to move the object and delete associated joints?"));
tr("Do you want to move the object and delete associated joints?")
);
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec();
@@ -215,9 +215,11 @@ bool ViewProviderAssembly::canDragObjectToTarget(App::DocumentObject* obj,
return false;
}
}
Gui::Command::doCommand(Gui::Command::Gui,
"App.activeDocument().removeObject('%s')",
joint->getNameInDocument());
Gui::Command::doCommand(
Gui::Command::Gui,
"App.activeDocument().removeObject('%s')",
joint->getNameInDocument()
);
}
}
return true;
@@ -276,13 +278,15 @@ bool ViewProviderAssembly::setEdit(int mode)
getDocument()->setEditRestore(true);
// Set the part as 'Activated' ie bold in the tree.
Gui::Command::doCommand(Gui::Command::Gui,
"appDoc = App.getDocument('%s')\n"
"Gui.getDocument(appDoc).ActiveView.setActiveObject('%s', "
"appDoc.getObject('%s'))",
this->getObject()->getDocument()->getName(),
PARTKEY,
this->getObject()->getNameInDocument());
Gui::Command::doCommand(
Gui::Command::Gui,
"appDoc = App.getDocument('%s')\n"
"Gui.getDocument(appDoc).ActiveView.setActiveObject('%s', "
"appDoc.getObject('%s'))",
this->getObject()->getDocument()->getName(),
PARTKEY,
this->getObject()->getNameInDocument()
);
setDragger();
@@ -297,7 +301,8 @@ bool ViewProviderAssembly::setEdit(int mode)
auto* assembly = getObject<AssemblyObject>();
connectSolverUpdate = assembly->signalSolverUpdate.connect(
boost::bind(&ViewProviderAssembly::UpdateSolverInformation, this));
boost::bind(&ViewProviderAssembly::UpdateSolverInformation, this)
);
return true;
}
@@ -321,11 +326,13 @@ void ViewProviderAssembly::unsetEdit(int mode)
}
// Set the part as not 'Activated' ie not bold in the tree.
Gui::Command::doCommand(Gui::Command::Gui,
"appDoc = App.getDocument('%s')\n"
"Gui.getDocument(appDoc).ActiveView.setActiveObject('%s', None)",
this->getObject()->getDocument()->getName(),
PARTKEY);
Gui::Command::doCommand(
Gui::Command::Gui,
"appDoc = App.getDocument('%s')\n"
"Gui.getDocument(appDoc).ActiveView.setActiveObject('%s', None)",
this->getObject()->getDocument()->getName(),
PARTKEY
);
Gui::TaskView::TaskView* taskView = Gui::Control().taskPanel();
if (taskView) {
@@ -345,9 +352,11 @@ void ViewProviderAssembly::setDragger()
// Create the dragger coin object
assert(!asmDragger);
asmDragger = new Gui::SoTransformDragger();
asmDragger->setAxisColors(Gui::ViewParams::instance()->getAxisXColor(),
Gui::ViewParams::instance()->getAxisYColor(),
Gui::ViewParams::instance()->getAxisZColor());
asmDragger->setAxisColors(
Gui::ViewParams::instance()->getAxisXColor(),
Gui::ViewParams::instance()->getAxisYColor(),
Gui::ViewParams::instance()->getAxisZColor()
);
asmDragger->draggerSize.setValue(Gui::ViewParams::instance()->getDraggerScale());
asmDraggerSwitch = new SoSwitch(SO_SWITCH_NONE);
@@ -399,7 +408,8 @@ bool ViewProviderAssembly::keyPressed(bool pressed, int key)
}
ParameterGrp::handle hPgr = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Assembly");
"User parameter:BaseApp/Preferences/Mod/Assembly"
);
return !hPgr->GetBool("LeaveEditWithEscape", true);
}
@@ -474,20 +484,22 @@ bool ViewProviderAssembly::tryMouseMove(const SbVec2s& cursorPos, Gui::View3DInv
for (auto& objToMove : docsToMove) {
App::DocumentObject* obj = objToMove.obj;
auto* propPlacement =
dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
auto* propPlacement = dynamic_cast<App::PropertyPlacement*>(
obj->getPropertyByName("Placement")
);
if (propPlacement) {
Base::Placement plc = objToMove.plc;
if (dragMode == DragMode::RotationOnPlane) {
Base::Vector3d center = jcsGlobalPlc.getPosition();
Base::Vector3d norm =
jcsGlobalPlc.getRotation().multVec(Base::Vector3d(0., 0., -1.));
double angle =
(newPosRot - center).GetAngleOriented(initialPositionRot - center, norm);
Base::Vector3d norm = jcsGlobalPlc.getRotation().multVec(
Base::Vector3d(0., 0., -1.)
);
double angle
= (newPosRot - center).GetAngleOriented(initialPositionRot - center, norm);
Base::Rotation zRotation = Base::Rotation(Base::Vector3d(0., 0., 1.), angle);
Base::Placement rotatedGlovalJcsPlc =
jcsGlobalPlc * Base::Placement(Base::Vector3d(), zRotation);
Base::Placement rotatedGlovalJcsPlc = jcsGlobalPlc
* Base::Placement(Base::Vector3d(), zRotation);
Base::Placement jcsPlcRelativeToPart = plc.inverse() * jcsGlobalPlc;
plc = rotatedGlovalJcsPlc * jcsPlcRelativeToPart.inverse();
}
@@ -500,21 +512,23 @@ bool ViewProviderAssembly::tryMouseMove(const SbVec2s& cursorPos, Gui::View3DInv
plc.setPosition(pos);
Base::Placement newJcsGlobalPlc = jcsGlobalPlc;
newJcsGlobalPlc.setPosition(jcsGlobalPlc.getPosition()
+ (newPos - initialPosition));
newJcsGlobalPlc.setPosition(
jcsGlobalPlc.getPosition() + (newPos - initialPosition)
);
Base::Vector3d center = newJcsGlobalPlc.getPosition();
Base::Vector3d norm =
newJcsGlobalPlc.getRotation().multVec(Base::Vector3d(0., 0., -1.));
Base::Vector3d norm = newJcsGlobalPlc.getRotation().multVec(
Base::Vector3d(0., 0., -1.)
);
Base::Vector3d projInitialPositionRot =
initialPositionRot.ProjectToPlane(newJcsGlobalPlc.getPosition(), norm);
Base::Vector3d projInitialPositionRot
= initialPositionRot.ProjectToPlane(newJcsGlobalPlc.getPosition(), norm);
boost::ignore_unused(projInitialPositionRot);
double angle =
(newPosRot - center).GetAngleOriented(initialPositionRot - center, norm);
double angle
= (newPosRot - center).GetAngleOriented(initialPositionRot - center, norm);
Base::Rotation zRotation = Base::Rotation(Base::Vector3d(0., 0., 1.), angle);
Base::Placement rotatedGlovalJcsPlc =
newJcsGlobalPlc * Base::Placement(Base::Vector3d(), zRotation);
Base::Placement rotatedGlovalJcsPlc = newJcsGlobalPlc
* Base::Placement(Base::Vector3d(), zRotation);
Base::Placement jcsPlcRelativeToPart = plc.inverse() * newJcsGlobalPlc;
plc = rotatedGlovalJcsPlc * jcsPlcRelativeToPart.inverse();
}
@@ -536,7 +550,8 @@ bool ViewProviderAssembly::tryMouseMove(const SbVec2s& cursorPos, Gui::View3DInv
auto* assemblyPart = getObject<AssemblyObject>();
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Assembly");
"User parameter:BaseApp/Preferences/Mod/Assembly"
);
bool solveOnMove = hGrp->GetBool("SolveOnMove", true);
if (solveOnMove && dragMode != DragMode::TranslationNoSolve) {
assemblyPart->doDragStep();
@@ -548,10 +563,12 @@ bool ViewProviderAssembly::tryMouseMove(const SbVec2s& cursorPos, Gui::View3DInv
return false;
}
bool ViewProviderAssembly::mouseButtonPressed(int Button,
bool pressed,
const SbVec2s& cursorPos,
const Gui::View3DInventorViewer* viewer)
bool ViewProviderAssembly::mouseButtonPressed(
int Button,
bool pressed,
const SbVec2s& cursorPos,
const Gui::View3DInventorViewer* viewer
)
{
Q_UNUSED(cursorPos);
Q_UNUSED(viewer);
@@ -565,9 +582,8 @@ bool ViewProviderAssembly::mouseButtonPressed(int Button,
if (pressed && !getDraggerVisibility()) {
// Check for double-click
auto now = std::chrono::steady_clock::now();
long nowMillis =
std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch())
.count();
long nowMillis
= std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
if (nowMillis - lastClickTime < 500) {
auto* joint = getSelectedJoint();
if (joint) {
@@ -578,9 +594,7 @@ bool ViewProviderAssembly::mouseButtonPressed(int Button,
// singleShot timer to make sure this happens after the release of the click.
// Else the release will trigger a removeSelection of what
// doubleClickedIn3dView adds to the selection.
QTimer::singleShot(50, [this]() {
doubleClickedIn3dView();
});
QTimer::singleShot(50, [this]() { doubleClickedIn3dView(); });
return true;
}
}
@@ -651,8 +665,7 @@ bool ViewProviderAssembly::canDragObjectIn3d(App::DocumentObject* obj) const
return false;
}
auto* propPlacement =
dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
auto* propPlacement = dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
if (!propPlacement) {
return false;
}
@@ -677,8 +690,7 @@ App::DocumentObject* ViewProviderAssembly::getSelectedJoint()
if (sel.size() == 1) { // Handle double click only if only one obj selected.
App::DocumentObject* obj = sel[0].getObject();
if (obj) {
auto* prop =
dynamic_cast<App::PropertyBool*>(obj->getPropertyByName("EnableLengthMin"));
auto* prop = dynamic_cast<App::PropertyBool*>(obj->getPropertyByName("EnableLengthMin"));
if (prop) {
return obj;
}
@@ -703,9 +715,11 @@ bool ViewProviderAssembly::getSelectedObjectsWithinAssembly(bool addPreselection
}
if (!moveOnlyPreselected) {
for (auto& selObj : Gui::Selection().getSelectionEx("",
App::DocumentObject::getClassTypeId(),
Gui::ResolveMode::NoResolve)) {
for (auto& selObj : Gui::Selection().getSelectionEx(
"",
App::DocumentObject::getClassTypeId(),
Gui::ResolveMode::NoResolve
)) {
// getSubNames() returns ["Body001.Pad.Face14", "Body002.Pad.Face7"]
// if you have several objects within the same assembly selected.
@@ -751,8 +765,7 @@ bool ViewProviderAssembly::getSelectedObjectsWithinAssembly(bool addPreselection
}
if (!alreadyIn) {
auto* pPlc =
dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
auto* pPlc = dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement"));
if (!ctrlPressed && !moveOnlyPreselected) {
Gui::Selection().clearSelection();
docsToMove.clear();
@@ -766,10 +779,12 @@ bool ViewProviderAssembly::getSelectedObjectsWithinAssembly(bool addPreselection
return !docsToMove.empty();
}
void ViewProviderAssembly::collectMovableObjects(App::DocumentObject* selRoot,
const std::string& subNamePrefix,
App::DocumentObject* currentObject,
bool onlySolids)
void ViewProviderAssembly::collectMovableObjects(
App::DocumentObject* selRoot,
const std::string& subNamePrefix,
App::DocumentObject* currentObject,
bool onlySolids
)
{
// Get the AssemblyObject for context
auto* assemblyPart = getObject<AssemblyObject>();
@@ -785,8 +800,7 @@ void ViewProviderAssembly::collectMovableObjects(App::DocumentObject* selRoot,
auto* link = static_cast<App::Link*>(child);
std::vector<App::DocumentObject*> elts = link->ElementList.getValues();
for (auto* elt : elts) {
std::string eltSubNamePrefix =
newSubNamePrefix + elt->getNameInDocument() + ".";
std::string eltSubNamePrefix = newSubNamePrefix + elt->getNameInDocument() + ".";
collectMovableObjects(selRoot, eltSubNamePrefix, elt, onlySolids);
}
}
@@ -799,10 +813,11 @@ void ViewProviderAssembly::collectMovableObjects(App::DocumentObject* selRoot,
// Base case: This is not a flexible link, process it as a potential movable part.
if (onlySolids
&& !(currentObject->isDerivedFrom<App::Part>()
|| currentObject->isDerivedFrom<Part::Feature>()
|| currentObject->isDerivedFrom<App::Link>()
|| currentObject->isDerivedFrom<App::LinkElement>())) {
&& !(
currentObject->isDerivedFrom<App::Part>() || currentObject->isDerivedFrom<Part::Feature>()
|| currentObject->isDerivedFrom<App::Link>()
|| currentObject->isDerivedFrom<App::LinkElement>()
)) {
return;
}
@@ -823,8 +838,9 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
if (!partRef.obj) {
continue;
}
auto* pPlc =
dynamic_cast<App::PropertyPlacement*>(partRef.obj->getPropertyByName("Placement"));
auto* pPlc = dynamic_cast<App::PropertyPlacement*>(
partRef.obj->getPropertyByName("Placement")
);
if (pPlc) {
App::DocumentObject* selRoot = partRef.ref->getValue();
if (!selRoot) {
@@ -849,8 +865,8 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
// In this case the user is moving an object that is not grounded
// Then we want to also move other parts that may be connected to it.
// In particular for case of flexible subassemblies or it looks really weird
std::vector<Assembly::ObjRef> connectedParts =
assemblyPart->getDownstreamParts(docsToMove[0].obj, movingJoint);
std::vector<Assembly::ObjRef> connectedParts
= assemblyPart->getDownstreamParts(docsToMove[0].obj, movingJoint);
addPartsToMove(connectedParts);
return DragMode::TranslationNoSolve;
@@ -863,8 +879,7 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
// actually move A
movingJoint = nullptr; // reinitialize because getUpstreamMovingPart will call
// getJointOfPartConnectingToGround again which will find the same joint.
auto* upPart =
assemblyPart->getUpstreamMovingPart(docsToMove[0].obj, movingJoint, pName);
auto* upPart = assemblyPart->getUpstreamMovingPart(docsToMove[0].obj, movingJoint, pName);
if (!movingJoint) {
return DragMode::Translation;
}
@@ -873,11 +888,11 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
return DragMode::None;
}
auto* pPlc =
dynamic_cast<App::PropertyPlacement*>(upPart->getPropertyByName("Placement"));
auto* pPlc = dynamic_cast<App::PropertyPlacement*>(upPart->getPropertyByName("Placement"));
if (pPlc) {
auto* ref = dynamic_cast<App::PropertyXLinkSub*>(
movingJoint->getPropertyByName(pName.c_str()));
movingJoint->getPropertyByName(pName.c_str())
);
App::DocumentObject* selRoot = ref->getValue();
if (!selRoot) {
@@ -900,8 +915,7 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
jcsPlc = App::GeoFeature::getPlacementFromProp(movingJoint, plcPropName);
// Make jcsGlobalPlc relative to the origin of the doc
auto* ref =
dynamic_cast<App::PropertyXLinkSub*>(movingJoint->getPropertyByName(pName.c_str()));
auto* ref = dynamic_cast<App::PropertyXLinkSub*>(movingJoint->getPropertyByName(pName.c_str()));
if (!ref) {
return DragMode::Translation;
}
@@ -910,8 +924,8 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
jcsGlobalPlc = global_plc * jcsPlc;
// Add downstream parts so that they move together
std::vector<Assembly::ObjRef> downstreamParts =
assemblyPart->getDownstreamParts(docsToMove[0].obj, movingJoint);
std::vector<Assembly::ObjRef> downstreamParts
= assemblyPart->getDownstreamParts(docsToMove[0].obj, movingJoint);
addPartsToMove(downstreamParts);
if (jointType == JointType::Revolute) {
@@ -1017,7 +1031,8 @@ void ViewProviderAssembly::tryInitMove(const SbVec2s& cursorPos, Gui::View3DInve
viewer->setSelectionEnabled(false);
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Assembly");
"User parameter:BaseApp/Preferences/Mod/Assembly"
);
bool solveOnMove = hGrp->GetBool("SolveOnMove", true);
if (solveOnMove && dragMode != DragMode::TranslationNoSolve) {
objectMasses.clear();
@@ -1061,7 +1076,8 @@ void ViewProviderAssembly::endMove()
}
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Assembly");
"User parameter:BaseApp/Preferences/Mod/Assembly"
);
bool solveOnMove = hGrp->GetBool("SolveOnMove", true);
if (solveOnMove) {
assemblyPart->postDrag();
@@ -1080,8 +1096,8 @@ void ViewProviderAssembly::initMoveDragger()
// find the placement for the dragger.
App::DocumentObject* part = docsToMove[0].obj;
draggerInitPlc =
App::GeoFeature::getGlobalPlacement(part, docsToMove[0].rootObj, docsToMove[0].sub);
draggerInitPlc
= App::GeoFeature::getGlobalPlacement(part, docsToMove[0].rootObj, docsToMove[0].sub);
std::vector<App::DocumentObject*> listOfObjs;
std::vector<App::PropertyXLinkSub*> listOfRefs;
for (auto& movingObj : docsToMove) {
@@ -1112,8 +1128,7 @@ void ViewProviderAssembly::draggerMotionCallback(void* data, SoDragger* d)
Base::Placement movePlc = draggerPlc * sudoThis->draggerInitPlc.inverse();
// Transform the global delta `movePlc` in case the assembly is transformed.
Base::Placement asmPlc =
App::GeoFeature::getGlobalPlacement(sudoThis->getObject<AssemblyObject>());
Base::Placement asmPlc = App::GeoFeature::getGlobalPlacement(sudoThis->getObject<AssemblyObject>());
if (!asmPlc.isIdentity()) {
movePlc = asmPlc.inverse() * movePlc * asmPlc;
}
@@ -1180,13 +1195,15 @@ bool ViewProviderAssembly::onDelete(const std::vector<std::string>& subNames)
|| obj->is<Assembly::BomGroup>()) {
// Delete the group content first.
Gui::Command::doCommand(Gui::Command::Doc,
"doc = App.getDocument(\"%s\")\n"
"objName = \"%s\"\n"
"doc.getObject(objName).removeObjectsFromDocument()\n"
"doc.removeObject(objName)\n",
obj->getDocument()->getName(),
obj->getNameInDocument());
Gui::Command::doCommand(
Gui::Command::Doc,
"doc = App.getDocument(\"%s\")\n"
"objName = \"%s\"\n"
"doc.getObject(objName).removeObjectsFromDocument()\n"
"doc.removeObject(objName)\n",
obj->getDocument()->getName(),
obj->getNameInDocument()
);
}
}
@@ -1204,8 +1221,8 @@ bool ViewProviderAssembly::canDelete(App::DocumentObject* objBeingDeleted) const
std::vector<App::DocumentObject*> objsBeingDeleted;
objsBeingDeleted.push_back(objBeingDeleted);
auto addSubComponents =
std::function<void(AssemblyLink*, std::vector<App::DocumentObject*>&)> {};
auto addSubComponents
= std::function<void(AssemblyLink*, std::vector<App::DocumentObject*>&)> {};
addSubComponents = [&](AssemblyLink* asmLink, std::vector<App::DocumentObject*>& objs) {
std::vector<App::DocumentObject*> assemblyLinkGroup = asmLink->Group.getValues();
for (auto* obj : assemblyLinkGroup) {
@@ -1257,10 +1274,12 @@ bool ViewProviderAssembly::canDelete(App::DocumentObject* objBeingDeleted) const
// Deletes them.
for (auto* joint : objToDel) {
Gui::Command::doCommand(Gui::Command::Doc,
"App.getDocument(\"%s\").removeObject(\"%s\")",
joint->getDocument()->getName(),
joint->getNameInDocument());
Gui::Command::doCommand(
Gui::Command::Doc,
"App.getDocument(\"%s\").removeObject(\"%s\")",
joint->getDocument()->getName(),
joint->getNameInDocument()
);
}
}
return res;
@@ -1287,8 +1306,10 @@ void ViewProviderAssembly::setDraggerPlacement(Base::Placement plc)
Base::Placement ViewProviderAssembly::getDraggerPlacement()
{
return {Base::convertTo<Base::Vector3d>(asmDragger->translation.getValue()),
Base::convertTo<Base::Rotation>(asmDragger->rotation.getValue())};
return {
Base::convertTo<Base::Vector3d>(asmDragger->translation.getValue()),
Base::convertTo<Base::Rotation>(asmDragger->rotation.getValue())
};
}
Gui::SoTransformDragger* ViewProviderAssembly::getDragger()
@@ -1305,10 +1326,12 @@ PyObject* ViewProviderAssembly::getPyObject()
return pyViewObject;
}
void ViewProviderAssembly::applyIsolationRecursively(App::DocumentObject* current,
std::set<App::DocumentObject*>& isolateSet,
IsolateMode mode,
std::set<App::DocumentObject*>& visited)
void ViewProviderAssembly::applyIsolationRecursively(
App::DocumentObject* current,
std::set<App::DocumentObject*>& isolateSet,
IsolateMode mode,
std::set<App::DocumentObject*>& visited
)
{
if (!current || !visited.insert(current).second) {
return; // Object is null or already processed
@@ -1392,7 +1415,8 @@ void ViewProviderAssembly::applyIsolationRecursively(App::DocumentObject* curren
if (child->isDerivedFrom<App::Link>() && child->getLinkedObject() == current) {
// In this case we need to reverse isolate this!
auto* childVp = freecad_cast<Gui::ViewProviderLink*>(
Gui::Application::Instance->getViewProvider(child));
Gui::Application::Instance->getViewProvider(child)
);
// we give the child the color the current had before we changed it
childVp->OverrideMaterial.setValue(true);
@@ -1403,8 +1427,7 @@ void ViewProviderAssembly::applyIsolationRecursively(App::DocumentObject* curren
}
}
void ViewProviderAssembly::isolateComponents(std::set<App::DocumentObject*>& isolateSet,
IsolateMode mode)
void ViewProviderAssembly::isolateComponents(std::set<App::DocumentObject*>& isolateSet, IsolateMode mode)
{
if (!stateBackup.empty()) {
clearIsolate();
@@ -1462,13 +1485,15 @@ void ViewProviderAssembly::clearIsolate()
component->Visibility.setValue(state.visibility);
if (auto* vpl = dynamic_cast<Gui::ViewProviderLink*>(
Gui::Application::Instance->getViewProvider(component))) {
Gui::Application::Instance->getViewProvider(component)
)) {
vpl->Selectable.setValue(state.selectable);
vpl->ShapeMaterial.setValue(state.shapeMaterial);
vpl->OverrideMaterial.setValue(state.overrideMaterial);
}
else if (auto* vpg = dynamic_cast<Gui::ViewProviderGeometryObject*>(
Gui::Application::Instance->getViewProvider(component))) {
Gui::Application::Instance->getViewProvider(component)
)) {
vpg->Selectable.setValue(state.selectable);
vpg->ShapeAppearance.setValue(state.shapeMaterial);
}
@@ -1484,15 +1509,13 @@ void ViewProviderAssembly::slotAboutToOpenTransaction(const std::string& cmdName
}
// UTILS
Base::Vector3d
ViewProviderAssembly::getCenterOfBoundingBox(const std::vector<MovingObject>& movingObjs)
Base::Vector3d ViewProviderAssembly::getCenterOfBoundingBox(const std::vector<MovingObject>& movingObjs)
{
int count = 0;
Base::Vector3d center; // feujhzef
for (auto& movingObj : movingObjs) {
Gui::ViewProvider* viewProvider =
Gui::Application::Instance->getViewProvider(movingObj.obj);
Gui::ViewProvider* viewProvider = Gui::Application::Instance->getViewProvider(movingObj.obj);
if (!viewProvider) {
continue;
}
@@ -1510,8 +1533,8 @@ ViewProviderAssembly::getCenterOfBoundingBox(const std::vector<MovingObject>& mo
Base::Placement objPlc = App::GeoFeature::getPlacementFromProp(movingObj.obj, "Placement");
plc = objPlc.inverse() * plc;
// Change plc to be relative to the origin of the document.
Base::Placement global_plc =
App::GeoFeature::getGlobalPlacement(movingObj.obj, movingObj.rootObj, movingObj.sub);
Base::Placement global_plc
= App::GeoFeature::getGlobalPlacement(movingObj.obj, movingObj.rootObj, movingObj.sub);
plc = global_plc * plc;
bboxCenter = plc.getPosition();
@@ -1565,47 +1588,54 @@ void ViewProviderAssembly::UpdateSolverInformation()
signalSetUp(QStringLiteral("empty"), tr("Empty Assembly"), QString(), QString());
}
else if (dofs < 0 || hasConflicts) { // over-constrained
signalSetUp(QStringLiteral("conflicting_constraints"),
tr("Over-constrained:") + QLatin1String(" "),
QStringLiteral("#conflicting"),
QStringLiteral("(%1)").arg(intListHelper(assembly->getLastConflicting())));
signalSetUp(
QStringLiteral("conflicting_constraints"),
tr("Over-constrained:") + QLatin1String(" "),
QStringLiteral("#conflicting"),
QStringLiteral("(%1)").arg(intListHelper(assembly->getLastConflicting()))
);
}
else if (hasMalformed) { // malformed joints
signalSetUp(
QStringLiteral("malformed_constraints"),
tr("Malformed joints:") + QLatin1String(" "),
QStringLiteral("#malformed"),
QStringLiteral("(%1)").arg(intListHelper(assembly->getLastMalformedConstraints())));
QStringLiteral("(%1)").arg(intListHelper(assembly->getLastMalformedConstraints()))
);
}
else if (hasRedundancies) {
signalSetUp(QStringLiteral("redundant_constraints"),
tr("Redundant joints:") + QLatin1String(" "),
QStringLiteral("#redundant"),
QStringLiteral("(%1)").arg(intListHelper(assembly->getLastRedundant())));
signalSetUp(
QStringLiteral("redundant_constraints"),
tr("Redundant joints:") + QLatin1String(" "),
QStringLiteral("#redundant"),
QStringLiteral("(%1)").arg(intListHelper(assembly->getLastRedundant()))
);
}
else if (hasPartiallyRedundant) {
signalSetUp(
QStringLiteral("partially_redundant_constraints"),
tr("Partially redundant:") + QLatin1String(" "),
QStringLiteral("#partiallyredundant"),
QStringLiteral("(%1)").arg(intListHelper(assembly->getLastPartiallyRedundant())));
QStringLiteral("(%1)").arg(intListHelper(assembly->getLastPartiallyRedundant()))
);
}
else if (assembly->getLastSolverStatus() != 0) {
signalSetUp(QStringLiteral("solver_failed"),
tr("Solver failed to converge"),
QStringLiteral(""),
QStringLiteral(""));
signalSetUp(
QStringLiteral("solver_failed"),
tr("Solver failed to converge"),
QStringLiteral(""),
QStringLiteral("")
);
}
else if (dofs > 0) {
signalSetUp(QStringLiteral("under_constrained"),
tr("Under-constrained:") + QLatin1String(" "),
QStringLiteral("#dofs"),
tr("%n Degrees of Freedom", "", dofs));
signalSetUp(
QStringLiteral("under_constrained"),
tr("Under-constrained:") + QLatin1String(" "),
QStringLiteral("#dofs"),
tr("%n Degrees of Freedom", "", dofs)
);
}
else {
signalSetUp(QStringLiteral("fully_constrained"),
tr("Fully constrained"),
QString(),
QString());
signalSetUp(QStringLiteral("fully_constrained"), tr("Fully constrained"), QString(), QString());
}
}

View File

@@ -56,10 +56,12 @@ struct MovingObject
const std::string sub; // sub name given by the selection.
// Constructor
MovingObject(App::DocumentObject* o,
const Base::Placement& p,
App::DocumentObject* ro,
const std::string& s)
MovingObject(
App::DocumentObject* o,
const Base::Placement& p,
App::DocumentObject* ro,
const std::string& s
)
: obj(o)
, plc(p)
, ref(nullptr)
@@ -132,8 +134,7 @@ public:
}
bool canDragObject(App::DocumentObject*) const override;
bool canDragObjectToTarget(App::DocumentObject* obj,
App::DocumentObject* target) const override;
bool canDragObjectToTarget(App::DocumentObject* obj, App::DocumentObject* target) const override;
App::DocumentObject* getActivePart() const;
@@ -143,10 +144,12 @@ public:
/// is called when the provider is in edit and the mouse is moved
bool mouseMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer) override;
/// is called when the Provider is in edit and the mouse is clicked
bool mouseButtonPressed(int Button,
bool pressed,
const SbVec2s& cursorPos,
const Gui::View3DInventorViewer* viewer) override;
bool mouseButtonPressed(
int Button,
bool pressed,
const SbVec2s& cursorPos,
const Gui::View3DInventorViewer* viewer
) override;
// Function to handle double click event
void doubleClickedIn3dView();
@@ -212,8 +215,7 @@ public:
void UpdateSolverInformation();
void isolateComponents(std::set<App::DocumentObject*>& parts, IsolateMode mode);
void isolateJointReferences(App::DocumentObject* joint,
IsolateMode mode = IsolateMode::Transparent);
void isolateJointReferences(App::DocumentObject* joint, IsolateMode mode = IsolateMode::Transparent);
void clearIsolate();
DragMode dragMode;
@@ -253,10 +255,12 @@ private:
bool tryMouseMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer);
void tryInitMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer);
void collectMovableObjects(App::DocumentObject* selRoot,
const std::string& subNamePrefix,
App::DocumentObject* currentObject,
bool onlySolids);
void collectMovableObjects(
App::DocumentObject* selRoot,
const std::string& subNamePrefix,
App::DocumentObject* currentObject,
bool onlySolids
);
void slotAboutToOpenTransaction(const std::string& cmdName);
@@ -273,10 +277,12 @@ private:
App::DocumentObject* isolatedJoint {nullptr};
bool isolatedJointVisibilityBackup {false};
void applyIsolationRecursively(App::DocumentObject* current,
std::set<App::DocumentObject*>& isolateSet,
IsolateMode mode,
std::set<App::DocumentObject*>& visited);
void applyIsolationRecursively(
App::DocumentObject* current,
std::set<App::DocumentObject*>& isolateSet,
IsolateMode mode,
std::set<App::DocumentObject*>& visited
);
TaskAssemblyMessages* taskSolver;
boost::signals2::connection connectSolverUpdate;

View File

@@ -74,8 +74,7 @@ bool ViewProviderAssemblyLink::setEdit(int mode)
auto* assemblyLink = dynamic_cast<Assembly::AssemblyLink*>(getObject());
if (!assemblyLink->isRigid() && mode == (int)ViewProvider::Transform) {
Base::Console().userTranslatedNotification(
"Flexible sub-assemblies cannot be transformed.");
Base::Console().userTranslatedNotification("Flexible sub-assemblies cannot be transformed.");
return true;
}
@@ -91,8 +90,9 @@ bool ViewProviderAssemblyLink::doubleClicked()
}
auto* assembly = link->getLinkedAssembly();
auto* vpa =
freecad_cast<ViewProviderAssembly*>(Gui::Application::Instance->getViewProvider(assembly));
auto* vpa = freecad_cast<ViewProviderAssembly*>(
Gui::Application::Instance->getViewProvider(assembly)
);
if (!vpa) {
return true;
}
@@ -104,10 +104,12 @@ bool ViewProviderAssemblyLink::onDelete(const std::vector<std::string>& subNames
{
Q_UNUSED(subNames)
Gui::Command::doCommand(Gui::Command::Doc,
"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()",
getObject()->getDocument()->getName(),
getObject()->getNameInDocument());
Gui::Command::doCommand(
Gui::Command::Doc,
"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()",
getObject()->getDocument()->getName(),
getObject()->getNameInDocument()
);
// getObject()->purgeTouched();
@@ -121,21 +123,25 @@ void ViewProviderAssemblyLink::setupContextMenu(QMenu* menu, QObject* receiver,
auto* assemblyLink = dynamic_cast<Assembly::AssemblyLink*>(getObject());
if (assemblyLink->isRigid()) {
act = menu->addAction(QObject::tr("Turn flexible"));
act->setToolTip(QObject::tr(
"Your sub-assembly is currently rigid. This will make it flexible instead."));
act->setToolTip(
QObject::tr("Your sub-assembly is currently rigid. This will make it flexible instead.")
);
}
else {
act = menu->addAction(QObject::tr("Turn rigid"));
act->setToolTip(QObject::tr(
"Your sub-assembly is currently flexible. This will make it rigid instead."));
act->setToolTip(
QObject::tr("Your sub-assembly is currently flexible. This will make it rigid instead.")
);
}
func->trigger(act, [this]() {
auto* assemblyLink = dynamic_cast<Assembly::AssemblyLink*>(getObject());
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Toggle Rigid"));
Gui::cmdAppObjectArgs(assemblyLink,
"Rigid = %s",
assemblyLink->Rigid.getValue() ? "False" : "True");
Gui::cmdAppObjectArgs(
assemblyLink,
"Rigid = %s",
assemblyLink->Rigid.getValue() ? "False" : "True"
);
Gui::Command::commitCommand();
Gui::Selection().clearSelection();