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

@@ -22,8 +22,8 @@
#include <QMessageBox>
# include <gp_Pln.hxx>
# include <Precision.hxx>
#include <gp_Pln.hxx>
#include <Precision.hxx>
#include <App/Origin.h>
@@ -44,14 +44,15 @@
#include "WorkflowManager.h"
FC_LOG_LEVEL_INIT("PartDesignGui",true,true)
FC_LOG_LEVEL_INIT("PartDesignGui", true, true)
//===========================================================================
// Helper for Body
//===========================================================================
using namespace Attacher;
namespace PartDesignGui {
namespace PartDesignGui
{
// TODO: Refactor DocumentObjectItem::getSubName() that has similar logic
App::DocumentObject* getParent(App::DocumentObject* obj, std::string& subname)
@@ -70,7 +71,8 @@ App::DocumentObject* getParent(App::DocumentObject* obj, std::string& subname)
return obj;
}
bool setEdit(App::DocumentObject *obj, PartDesign::Body *body) {
bool setEdit(App::DocumentObject* obj, PartDesign::Body* body)
{
if (!obj || !obj->isAttachedToDocument()) {
FC_ERR("invalid object");
return false;
@@ -82,10 +84,11 @@ bool setEdit(App::DocumentObject *obj, PartDesign::Body *body) {
return false;
}
}
auto *activeView = Gui::Application::Instance->activeView();
if (!activeView)
auto* activeView = Gui::Application::Instance->activeView();
if (!activeView) {
return false;
App::DocumentObject *parent = nullptr;
}
App::DocumentObject* parent = nullptr;
std::string subname;
auto activeBody = activeView->getActiveObject<PartDesign::Body*>(PDBODYKEY, &parent, &subname);
if (activeBody != body) {
@@ -97,9 +100,11 @@ bool setEdit(App::DocumentObject *obj, PartDesign::Body *body) {
subname += '.';
}
Gui::cmdGuiDocument(parent, std::ostringstream() << "setEdit("
<< Gui::Command::getObjectCmd(parent)
<< ", 0, '" << subname << "')");
Gui::cmdGuiDocument(
parent,
std::ostringstream() << "setEdit(" << Gui::Command::getObjectCmd(parent) << ", 0, '"
<< subname << "')"
);
return true;
}
@@ -111,22 +116,27 @@ bool setEdit(App::DocumentObject *obj, PartDesign::Body *body) {
* \param autoActivate
* \return Body
*/
PartDesign::Body *getBody(bool messageIfNot, bool autoActivate, bool assertModern,
App::DocumentObject **topParent, std::string *subname)
PartDesign::Body* getBody(
bool messageIfNot,
bool autoActivate,
bool assertModern,
App::DocumentObject** topParent,
std::string* subname
)
{
PartDesign::Body * activeBody = nullptr;
Gui::MDIView *activeView = Gui::Application::Instance->activeView();
PartDesign::Body* activeBody = nullptr;
Gui::MDIView* activeView = Gui::Application::Instance->activeView();
if (activeView) {
auto doc = activeView->getAppDocument();
bool singleBodyDocument = doc->countObjectsOfType<PartDesign::Body>() == 1;
if (assertModern) {
activeBody = activeView->getActiveObject<PartDesign::Body*>(PDBODYKEY,topParent,subname);
activeBody = activeView->getActiveObject<PartDesign::Body*>(PDBODYKEY, topParent, subname);
if (!activeBody && singleBodyDocument && autoActivate) {
auto bodies = doc->getObjectsOfType(PartDesign::Body::getClassTypeId());
App::DocumentObject *body = nullptr;
if(bodies.size()==1) {
App::DocumentObject* body = nullptr;
if (bodies.size() == 1) {
body = bodies[0];
activeBody = makeBodyActive(body, doc, topParent, subname);
}
@@ -135,12 +145,16 @@ PartDesign::Body *getBody(bool messageIfNot, bool autoActivate, bool assertModer
DlgActiveBody dia(
Gui::getMainWindow(),
doc,
QObject::tr("To use Part Design, an active body is required in the document. "
"Activate a body (double-click) or create a new one."
"\n\nFor legacy documents with Part Design objects lacking a body, "
"use the migrate function in Part Design to place them into a body."));
if (dia.exec() == QDialog::DialogCode::Accepted)
QObject::tr(
"To use Part Design, an active body is required in the document. "
"Activate a body (double-click) or create a new one."
"\n\nFor legacy documents with Part Design objects lacking a body, "
"use the migrate function in Part Design to place them into a body."
)
);
if (dia.exec() == QDialog::DialogCode::Accepted) {
activeBody = dia.getActiveBody();
}
}
}
}
@@ -148,17 +162,21 @@ PartDesign::Body *getBody(bool messageIfNot, bool autoActivate, bool assertModer
return activeBody;
}
PartDesign::Body * makeBodyActive(App::DocumentObject *body, App::Document *doc,
App::DocumentObject **topParent,
std::string *subname)
PartDesign::Body* makeBodyActive(
App::DocumentObject* body,
App::Document* doc,
App::DocumentObject** topParent,
std::string* subname
)
{
App::DocumentObject *parent = nullptr;
App::DocumentObject* parent = nullptr;
std::string sub;
for(auto &v : body->getParents()) {
if(v.first->getDocument()!=doc)
for (auto& v : body->getParents()) {
if (v.first->getDocument() != doc) {
continue;
if(parent) {
}
if (parent) {
body = nullptr;
break;
}
@@ -166,14 +184,16 @@ PartDesign::Body * makeBodyActive(App::DocumentObject *body, App::Document *doc,
sub = v.second;
}
if(body) {
auto _doc = parent?parent->getDocument():body->getDocument();
Gui::cmdGuiDocument(_doc, std::stringstream()
<< "ActiveView.setActiveObject('" << PDBODYKEY
<< "'," << Gui::Command::getObjectCmd(parent?parent:body)
<< ",'" << sub << "')");
return Gui::Application::Instance->activeView()->
getActiveObject<PartDesign::Body*>(PDBODYKEY,topParent,subname);
if (body) {
auto _doc = parent ? parent->getDocument() : body->getDocument();
Gui::cmdGuiDocument(
_doc,
std::stringstream() << "ActiveView.setActiveObject('" << PDBODYKEY << "',"
<< Gui::Command::getObjectCmd(parent ? parent : body) << ",'" << sub
<< "')"
);
return Gui::Application::Instance->activeView()
->getActiveObject<PartDesign::Body*>(PDBODYKEY, topParent, subname);
}
return dynamic_cast<PartDesign::Body*>(body);
@@ -181,280 +201,342 @@ PartDesign::Body * makeBodyActive(App::DocumentObject *body, App::Document *doc,
void needActiveBodyError()
{
QMessageBox::warning( Gui::getMainWindow(),
QMessageBox::warning(
Gui::getMainWindow(),
QObject::tr("Active Body Required"),
QObject::tr("To create a new Part Design object, an active body is required in the document. "
"Activate an existing body (double-click) or create a new one."));
QObject::tr(
"To create a new Part Design object, an active body is required in the document. "
"Activate an existing body (double-click) or create a new one."
)
);
}
PartDesign::Body * makeBody(App::Document *doc)
PartDesign::Body* makeBody(App::Document* doc)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp/Preferences/Mod/PartDesign");
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup(
"BaseApp/Preferences/Mod/PartDesign"
);
bool allowCompound = hGrp->GetBool("AllowCompoundDefault", true);
// This is intended as a convenience when starting a new document.
auto bodyName( doc->getUniqueObjectName("Body") );
Gui::Command::doCommand( Gui::Command::Doc,
"App.getDocument('%s').addObject('PartDesign::Body','%s')",
doc->getName(), bodyName.c_str() );
Gui::Command::doCommand( Gui::Command::Doc,
"App.getDocument('%s').getObject('%s').AllowCompound = %s",
doc->getName(), bodyName.c_str(), allowCompound ? "True" : "False" );
auto bodyName(doc->getUniqueObjectName("Body"));
Gui::Command::doCommand(
Gui::Command::Doc,
"App.getDocument('%s').addObject('PartDesign::Body','%s')",
doc->getName(),
bodyName.c_str()
);
Gui::Command::doCommand(
Gui::Command::Doc,
"App.getDocument('%s').getObject('%s').AllowCompound = %s",
doc->getName(),
bodyName.c_str(),
allowCompound ? "True" : "False"
);
auto body = dynamic_cast<PartDesign::Body*>(doc->getObject(bodyName.c_str()));
if(body)
if (body) {
makeBodyActive(body, doc);
}
return body;
}
PartDesign::Body *getBodyFor(const App::DocumentObject* obj, bool messageIfNot,
bool autoActivate, bool assertModern,
App::DocumentObject **topParent, std::string *subname)
PartDesign::Body* getBodyFor(
const App::DocumentObject* obj,
bool messageIfNot,
bool autoActivate,
bool assertModern,
App::DocumentObject** topParent,
std::string* subname
)
{
if(!obj)
if (!obj) {
return nullptr;
}
PartDesign::Body * rv = getBody(/*messageIfNot =*/false, autoActivate, assertModern, topParent, subname);
if (rv && rv->hasObject(obj))
PartDesign::Body* rv
= getBody(/*messageIfNot =*/false, autoActivate, assertModern, topParent, subname);
if (rv && rv->hasObject(obj)) {
return rv;
}
rv = PartDesign::Body::findBodyOf(obj);
if (rv) {
return rv;
}
if (messageIfNot){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Feature is not in a body"),
QObject::tr("In order to use this feature it needs to belong to a body object in the document."));
if (messageIfNot) {
QMessageBox::warning(
Gui::getMainWindow(),
QObject::tr("Feature is not in a body"),
QObject::tr(
"In order to use this feature it needs to belong to a body object in the document."
)
);
}
return nullptr;
}
App::Part* getActivePart() {
Gui::MDIView *activeView = Gui::Application::Instance->activeView();
if ( activeView ) {
return activeView->getActiveObject<App::Part*> (PARTKEY);
} else {
App::Part* getActivePart()
{
Gui::MDIView* activeView = Gui::Application::Instance->activeView();
if (activeView) {
return activeView->getActiveObject<App::Part*>(PARTKEY);
}
else {
return nullptr;
}
}
App::Part* getPartFor(const App::DocumentObject* obj, bool messageIfNot) {
App::Part* getPartFor(const App::DocumentObject* obj, bool messageIfNot)
{
if(!obj)
if (!obj) {
return nullptr;
}
PartDesign::Body* body = getBodyFor(obj, false);
if(body)
if (body) {
obj = body;
}
//get the part
for(App::Part* p : obj->getDocument()->getObjectsOfType<App::Part>()) {
if(p->hasObject(obj)) {
// get the part
for (App::Part* p : obj->getDocument()->getObjectsOfType<App::Part>()) {
if (p->hasObject(obj)) {
return p;
}
}
if (messageIfNot){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Feature is not in a part"),
QObject::tr("In order to use this feature it needs to belong to a part object in the document."));
if (messageIfNot) {
QMessageBox::warning(
Gui::getMainWindow(),
QObject::tr("Feature is not in a part"),
QObject::tr(
"In order to use this feature it needs to belong to a part object in the document."
)
);
}
return nullptr;
}
//static void buildDefaultPartAndBody(const App::Document* doc)
// static void buildDefaultPartAndBody(const App::Document* doc)
//{
// // This adds both the base planes and the body
// std::string PartName = doc->getUniqueObjectName("Part");
// //// create a PartDesign Part for now, can be later any kind of Part or an empty one
// Gui::Command::addModule(Gui::Command::Doc, "PartDesignGui");
// Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')", PartName.c_str());
// Gui::Command::doCommand(Gui::Command::Doc, "PartDesignGui.setUpPart(App.activeDocument().%s)", PartName.c_str());
// Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('Part',App.activeDocument().%s)", PartName.c_str());
//}
// // This adds both the base planes and the body
// std::string PartName = doc->getUniqueObjectName("Part");
// //// create a PartDesign Part for now, can be later any kind of Part or an empty one
// Gui::Command::addModule(Gui::Command::Doc, "PartDesignGui");
// Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().Tip =
// App.activeDocument().addObject('App::Part','%s')", PartName.c_str());
// Gui::Command::doCommand(Gui::Command::Doc, "PartDesignGui.setUpPart(App.activeDocument().%s)",
// PartName.c_str()); Gui::Command::doCommand(Gui::Command::Gui,
// "Gui.activeView().setActiveObject('Part',App.activeDocument().%s)", PartName.c_str());
// }
void fixSketchSupport (Sketcher::SketchObject* sketch)
void fixSketchSupport(Sketcher::SketchObject* sketch)
{
App::DocumentObject* support = sketch->AttachmentSupport.getValue();
if (support)
return; // Sketch is on a face of a solid, do nothing
if (support) {
return; // Sketch is on a face of a solid, do nothing
}
const App::Document* doc = sketch->getDocument();
PartDesign::Body *body = getBodyFor(sketch, /*messageIfNot*/ false);
PartDesign::Body* body = getBodyFor(sketch, /*messageIfNot*/ false);
if (!body) {
throw Base::RuntimeError ("Could not find a body for the sketch");
throw Base::RuntimeError("Could not find a body for the sketch");
}
// Get the Origin for the body
App::Origin *origin = body->getOrigin (); // May throw by itself
App::Origin* origin = body->getOrigin(); // May throw by itself
Base::Placement plm = sketch->Placement.getValue();
Base::Vector3d pnt = plm.getPosition();
// Currently we only handle positions that are parallel to the base planes
Base::Rotation rot = plm.getRotation();
Base::Vector3d sketchVector(0,0,1);
Base::Vector3d sketchVector(0, 0, 1);
rot.multVec(sketchVector, sketchVector);
bool reverseSketch = (sketchVector.x + sketchVector.y + sketchVector.z) < 0.0 ;
if (reverseSketch) sketchVector *= -1.0;
bool reverseSketch = (sketchVector.x + sketchVector.y + sketchVector.z) < 0.0;
if (reverseSketch) {
sketchVector *= -1.0;
}
App::Plane *plane =nullptr;
App::Plane* plane = nullptr;
if (sketchVector == Base::Vector3d(0,0,1))
plane = origin->getXY ();
else if (sketchVector == Base::Vector3d(0,1,0))
plane = origin->getXZ ();
else if (sketchVector == Base::Vector3d(1,0,0))
plane = origin->getYZ ();
if (sketchVector == Base::Vector3d(0, 0, 1)) {
plane = origin->getXY();
}
else if (sketchVector == Base::Vector3d(0, 1, 0)) {
plane = origin->getXZ();
}
else if (sketchVector == Base::Vector3d(1, 0, 0)) {
plane = origin->getYZ();
}
else {
throw Base::ValueError("Sketch plane cannot be migrated");
}
assert (plane);
assert(plane);
// Find the normal distance from origin to the sketch plane
gp_Pln pln(gp_Pnt (pnt.x, pnt.y, pnt.z), gp_Dir(sketchVector.x, sketchVector.y, sketchVector.z));
double offset = pln.Distance(gp_Pnt(0,0,0));
gp_Pln pln(gp_Pnt(pnt.x, pnt.y, pnt.z), gp_Dir(sketchVector.x, sketchVector.y, sketchVector.z));
double offset = pln.Distance(gp_Pnt(0, 0, 0));
// TODO Issue a message if sketch have coordinates offset inside the plain (2016-08-15, Fat-Zer)
if (fabs(offset) < Precision::Confusion()) {
// One of the base planes
FCMD_OBJ_CMD(sketch,"AttachmentSupport = (" << Gui::Command::getObjectCmd(plane) << ",[''])");
FCMD_OBJ_CMD(sketch,"MapReversed = " << (reverseSketch ? "True" : "False"));
FCMD_OBJ_CMD(sketch,"MapMode = '" << Attacher::AttachEngine::getModeName(Attacher::mmFlatFace) << "'");
} else {
FCMD_OBJ_CMD(sketch, "AttachmentSupport = (" << Gui::Command::getObjectCmd(plane) << ",[''])");
FCMD_OBJ_CMD(sketch, "MapReversed = " << (reverseSketch ? "True" : "False"));
FCMD_OBJ_CMD(
sketch,
"MapMode = '" << Attacher::AttachEngine::getModeName(Attacher::mmFlatFace) << "'"
);
}
else {
// Offset to base plane
// Find out which direction we need to offset
double a = sketchVector.GetAngle(pnt);
if ((a < -std::numbers::pi/2) || (a > std::numbers::pi/2))
if ((a < -std::numbers::pi / 2) || (a > std::numbers::pi / 2)) {
offset *= -1.0;
}
std::string Datum = doc->getUniqueObjectName("DatumPlane");
FCMD_DOC_CMD(doc,"addObject('PartDesign::Plane','"<<Datum<<"')");
FCMD_DOC_CMD(doc, "addObject('PartDesign::Plane','" << Datum << "')");
auto obj = doc->getObject(Datum.c_str());
FCMD_OBJ_CMD(obj,"AttachmentSupport = [(" << Gui::Command::getObjectCmd(plane) << ",'')]");
FCMD_OBJ_CMD(obj,"MapMode = '" << AttachEngine::getModeName(Attacher::mmFlatFace) << "'");
FCMD_OBJ_CMD(obj,"AttachmentOffset.Base.z = " << offset);
FCMD_OBJ_CMD(body,"insertObject("<<Gui::Command::getObjectCmd(obj)<<','<<
Gui::Command::getObjectCmd(sketch)<<")");
FCMD_OBJ_CMD(sketch,"AttachmentSupport = (" << Gui::Command::getObjectCmd(obj) << ",[''])");
FCMD_OBJ_CMD(sketch,"MapReversed = " << (reverseSketch ? "True" : "False"));
FCMD_OBJ_CMD(sketch,"MapMode = '" << Attacher::AttachEngine::getModeName(Attacher::mmFlatFace) << "'");
FCMD_OBJ_CMD(obj, "AttachmentSupport = [(" << Gui::Command::getObjectCmd(plane) << ",'')]");
FCMD_OBJ_CMD(obj, "MapMode = '" << AttachEngine::getModeName(Attacher::mmFlatFace) << "'");
FCMD_OBJ_CMD(obj, "AttachmentOffset.Base.z = " << offset);
FCMD_OBJ_CMD(
body,
"insertObject(" << Gui::Command::getObjectCmd(obj) << ','
<< Gui::Command::getObjectCmd(sketch) << ")"
);
FCMD_OBJ_CMD(sketch, "AttachmentSupport = (" << Gui::Command::getObjectCmd(obj) << ",[''])");
FCMD_OBJ_CMD(sketch, "MapReversed = " << (reverseSketch ? "True" : "False"));
FCMD_OBJ_CMD(
sketch,
"MapMode = '" << Attacher::AttachEngine::getModeName(Attacher::mmFlatFace) << "'"
);
}
}
bool isPartDesignAwareObjecta (App::DocumentObject *obj, bool respectGroups = false ) {
return (obj->isDerivedFrom( PartDesign::Feature::getClassTypeId () ) ||
PartDesign::Body::isAllowed ( obj ) ||
obj->isDerivedFrom ( PartDesign::Body::getClassTypeId () ) ||
( respectGroups && (
obj->hasExtension (App::GeoFeatureGroupExtension::getExtensionClassTypeId () ) ||
obj->hasExtension (App::GroupExtension::getExtensionClassTypeId () )
) ) );
bool isPartDesignAwareObjecta(App::DocumentObject* obj, bool respectGroups = false)
{
return (
obj->isDerivedFrom(PartDesign::Feature::getClassTypeId())
|| PartDesign::Body::isAllowed(obj) || obj->isDerivedFrom(PartDesign::Body::getClassTypeId())
|| (respectGroups
&& (obj->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())
|| obj->hasExtension(App::GroupExtension::getExtensionClassTypeId())))
);
}
bool isAnyNonPartDesignLinksTo ( PartDesign::Feature *feature, bool respectGroups ) {
App::Document *doc = feature->getDocument();
bool isAnyNonPartDesignLinksTo(PartDesign::Feature* feature, bool respectGroups)
{
App::Document* doc = feature->getDocument();
for ( const auto & obj: doc->getObjects () ) {
if ( !isPartDesignAwareObjecta ( obj, respectGroups ) ) {
std::vector <App::Property *> properties;
obj->getPropertyList ( properties );
for (auto prop: properties ) {
if ( prop->isDerivedFrom ( App::PropertyLink::getClassTypeId() ) ) {
if ( static_cast <App::PropertyLink *> ( prop )->getValue () == feature ) {
return true;
}
} else if ( prop->isDerivedFrom ( App::PropertyLinkSub::getClassTypeId() ) ) {
if ( static_cast <App::PropertyLinkSub *> ( prop )->getValue () == feature ) {
return true;
}
} else if ( prop->isDerivedFrom ( App::PropertyLinkList::getClassTypeId() ) ) {
auto values = static_cast <App::PropertyLinkList *> ( prop )->getValues ();
if ( std::find ( values.begin (), values.end (), feature ) != values.end() ) {
return true;
}
} else if ( prop->isDerivedFrom ( App::PropertyLinkSubList::getClassTypeId() ) ) {
auto values = static_cast <App::PropertyLinkSubList *> ( prop )->getValues ();
if ( std::find ( values.begin (), values.end (), feature ) != values.end() ) {
for (const auto& obj : doc->getObjects()) {
if (!isPartDesignAwareObjecta(obj, respectGroups)) {
std::vector<App::Property*> properties;
obj->getPropertyList(properties);
for (auto prop : properties) {
if (prop->isDerivedFrom(App::PropertyLink::getClassTypeId())) {
if (static_cast<App::PropertyLink*>(prop)->getValue() == feature) {
return true;
}
}
}
}
else if (prop->isDerivedFrom(App::PropertyLinkSub::getClassTypeId())) {
if (static_cast<App::PropertyLinkSub*>(prop)->getValue() == feature) {
return true;
}
}
else if (prop->isDerivedFrom(App::PropertyLinkList::getClassTypeId())) {
auto values = static_cast<App::PropertyLinkList*>(prop)->getValues();
if (std::find(values.begin(), values.end(), feature) != values.end()) {
return true;
}
}
else if (prop->isDerivedFrom(App::PropertyLinkSubList::getClassTypeId())) {
auto values = static_cast<App::PropertyLinkSubList*>(prop)->getValues();
if (std::find(values.begin(), values.end(), feature) != values.end()) {
return true;
}
}
}
}
}
return false;
}
void relinkToBody (PartDesign::Feature *feature) {
App::Document *doc = feature->getDocument();
PartDesign::Body *body = PartDesign::Body::findBodyOf ( feature );
void relinkToBody(PartDesign::Feature* feature)
{
App::Document* doc = feature->getDocument();
PartDesign::Body* body = PartDesign::Body::findBodyOf(feature);
if (!body) {
throw Base::RuntimeError ("Could not find a body for the feature");
throw Base::RuntimeError("Could not find a body for the feature");
}
for ( const auto & obj: doc->getObjects () ) {
if ( !isPartDesignAwareObjecta ( obj ) ) {
std::vector <App::Property *> properties;
obj->getPropertyList ( properties );
for (auto prop: properties ) {
for (const auto& obj : doc->getObjects()) {
if (!isPartDesignAwareObjecta(obj)) {
std::vector<App::Property*> properties;
obj->getPropertyList(properties);
for (auto prop : properties) {
std::string valueStr;
if ( prop->isDerivedFrom ( App::PropertyLink::getClassTypeId() ) ) {
App::PropertyLink *propLink = static_cast <App::PropertyLink *> ( prop );
if ( propLink->getValue() != feature ) {
if (prop->isDerivedFrom(App::PropertyLink::getClassTypeId())) {
App::PropertyLink* propLink = static_cast<App::PropertyLink*>(prop);
if (propLink->getValue() != feature) {
continue;
}
valueStr = Gui::Command::getObjectCmd(body);
} else if ( prop->isDerivedFrom ( App::PropertyLinkSub::getClassTypeId() ) ) {
App::PropertyLinkSub *propLink = static_cast <App::PropertyLinkSub *> ( prop );
if ( propLink->getValue() != feature ) {
}
else if (prop->isDerivedFrom(App::PropertyLinkSub::getClassTypeId())) {
App::PropertyLinkSub* propLink = static_cast<App::PropertyLinkSub*>(prop);
if (propLink->getValue() != feature) {
continue;
}
valueStr = buildLinkSubPythonStr ( body, propLink->getSubValues() );
} else if ( prop->isDerivedFrom ( App::PropertyLinkList::getClassTypeId() ) ) {
App::PropertyLinkList *propLink = static_cast <App::PropertyLinkList *> ( prop );
std::vector <App::DocumentObject *> linkList = propLink->getValues ();
bool valueChanged=false;
for (auto & link : linkList ) {
if ( link == feature ) {
valueStr = buildLinkSubPythonStr(body, propLink->getSubValues());
}
else if (prop->isDerivedFrom(App::PropertyLinkList::getClassTypeId())) {
App::PropertyLinkList* propLink = static_cast<App::PropertyLinkList*>(prop);
std::vector<App::DocumentObject*> linkList = propLink->getValues();
bool valueChanged = false;
for (auto& link : linkList) {
if (link == feature) {
link = body;
valueChanged = true;
}
}
if ( valueChanged ) {
valueStr = buildLinkListPythonStr ( linkList );
if (valueChanged) {
valueStr = buildLinkListPythonStr(linkList);
// TODO Issue some message here due to it likely will break something
// (2015-08-13, Fat-Zer)
}
} else if ( prop->isDerivedFrom ( App::PropertyLinkSub::getClassTypeId() ) ) {
App::PropertyLinkSubList *propLink = static_cast <App::PropertyLinkSubList *> ( prop );
std::vector <App::DocumentObject *> linkList = propLink->getValues ();
bool valueChanged=false;
for (auto & link : linkList ) {
if ( link == feature ) {
}
else if (prop->isDerivedFrom(App::PropertyLinkSub::getClassTypeId())) {
App::PropertyLinkSubList* propLink = static_cast<App::PropertyLinkSubList*>(prop);
std::vector<App::DocumentObject*> linkList = propLink->getValues();
bool valueChanged = false;
for (auto& link : linkList) {
if (link == feature) {
link = body;
valueChanged = true;
}
}
if ( valueChanged ) {
valueStr = buildLinkSubListPythonStr ( linkList, propLink->getSubValues() );
if (valueChanged) {
valueStr = buildLinkSubListPythonStr(linkList, propLink->getSubValues());
// TODO Issue some message here due to it likely will break something
// (2015-08-13, Fat-Zer)
}
}
if ( !valueStr.empty () && prop->hasName()) {
FCMD_OBJ_CMD(obj,prop->getName() << '=' << valueStr);
if (!valueStr.empty() && prop->hasName()) {
FCMD_OBJ_CMD(obj, prop->getName() << '=' << valueStr);
}
}
}
@@ -482,17 +564,21 @@ bool isFeatureMovable(App::DocumentObject* const feat)
}
if (auto prop = dynamic_cast<App::PropertyLinkList*>(prim->getPropertyByName("Sections"))) {
if (std::any_of(prop->getValues().begin(), prop->getValues().end(), [](App::DocumentObject* obj) {
return !isFeatureMovable(obj);
})) {
if (std::any_of(
prop->getValues().begin(),
prop->getValues().end(),
[](App::DocumentObject* obj) { return !isFeatureMovable(obj); }
)) {
return false;
}
}
if (auto prop = dynamic_cast<App::PropertyLinkSubList*>(prim->getPropertyByName("Sections"))) {
if (std::any_of(prop->getValues().begin(), prop->getValues().end(), [](App::DocumentObject* obj) {
return !isFeatureMovable(obj);
})) {
if (std::any_of(
prop->getValues().begin(),
prop->getValues().end(),
[](App::DocumentObject* obj) { return !isFeatureMovable(obj); }
)) {
return false;
}
}
@@ -517,7 +603,6 @@ bool isFeatureMovable(App::DocumentObject* const feat)
return false;
}
}
}
if (feat->hasExtension(Part::AttachExtension::getExtensionClassTypeId())) {
@@ -535,7 +620,7 @@ std::vector<App::DocumentObject*> collectMovableDependencies(std::vector<App::Do
{
std::set<App::DocumentObject*> unique_objs;
for (auto const &feat : features) {
for (auto const& feat : features) {
// Get sketches and datums from profile based features
if (auto prim = dynamic_cast<PartDesign::ProfileBased*>(feat)) {
Part::Part2DObject* sk = prim->getVerifiedSketch(true);
@@ -547,26 +632,29 @@ std::vector<App::DocumentObject*> collectMovableDependencies(std::vector<App::Do
unique_objs.insert(obj);
}
}
if (auto prop = dynamic_cast<App::PropertyLinkSubList*>(prim->getPropertyByName("Sections"))) {
if (auto prop
= dynamic_cast<App::PropertyLinkSubList*>(prim->getPropertyByName("Sections"))) {
for (App::DocumentObject* obj : prop->getValues()) {
unique_objs.insert(obj);
}
}
if (auto prop = dynamic_cast<App::PropertyLinkSub*>(prim->getPropertyByName("ReferenceAxis"))) {
if (auto prop
= dynamic_cast<App::PropertyLinkSub*>(prim->getPropertyByName("ReferenceAxis"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->isDerivedFrom<App::DatumElement>()){
if (axis && !axis->isDerivedFrom<App::DatumElement>()) {
unique_objs.insert(axis);
}
}
if (auto prop = dynamic_cast<App::PropertyLinkSub*>(prim->getPropertyByName("Spine"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->isDerivedFrom<App::DatumElement>()){
if (axis && !axis->isDerivedFrom<App::DatumElement>()) {
unique_objs.insert(axis);
}
}
if (auto prop = dynamic_cast<App::PropertyLinkSub*>(prim->getPropertyByName("AuxiliarySpine"))) {
if (auto prop
= dynamic_cast<App::PropertyLinkSub*>(prim->getPropertyByName("AuxiliarySpine"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->isDerivedFrom<App::DatumElement>()){
if (axis && !axis->isDerivedFrom<App::DatumElement>()) {
unique_objs.insert(axis);
}
}
@@ -587,9 +675,14 @@ void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody)
App::DocumentObject* support = attachable->AttachmentSupport.getValue();
if (support && support->isDerivedFrom<App::DatumElement>()) {
auto originfeat = static_cast<App::DatumElement*>(support);
App::DatumElement* targetOriginFeature = targetbody->getOrigin()->getDatumElement(originfeat->Role.getValue());
App::DatumElement* targetOriginFeature = targetbody->getOrigin()->getDatumElement(
originfeat->Role.getValue()
);
if (targetOriginFeature) {
attachable->AttachmentSupport.setValue(static_cast<App::DocumentObject*>(targetOriginFeature), "");
attachable->AttachmentSupport.setValue(
static_cast<App::DocumentObject*>(targetOriginFeature),
""
);
}
}
}
@@ -597,15 +690,20 @@ void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody)
auto prim = static_cast<PartDesign::ProfileBased*>(feat);
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("ReferenceAxis"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && axis->isDerivedFrom<App::DatumElement>()){
if (axis && axis->isDerivedFrom<App::DatumElement>()) {
auto originfeat = static_cast<App::DatumElement*>(axis);
App::DatumElement* targetOriginFeature = targetbody->getOrigin()->getDatumElement(originfeat->Role.getValue());
App::DatumElement* targetOriginFeature = targetbody->getOrigin()->getDatumElement(
originfeat->Role.getValue()
);
if (targetOriginFeature) {
prop->setValue(static_cast<App::DocumentObject*>(targetOriginFeature), std::vector<std::string>(0));
prop->setValue(
static_cast<App::DocumentObject*>(targetOriginFeature),
std::vector<std::string>(0)
);
}
}
}
}
}
} /* PartDesignGui */
} // namespace PartDesignGui