Skip to content

Commit

Permalink
fix whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 25, 2016
1 parent c90da8e commit 46adbae
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 311 deletions.
80 changes: 40 additions & 40 deletions src/Mod/PartDesign/Gui/CommandBody.cpp
Expand Up @@ -587,48 +587,48 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
if (features.empty()) return;

// Check if all features are valid to move
if (std::any_of(std::begin(features), std::end(features), [](App::DocumentObject* obj){return !PartDesignGui::isFeatureMovable(obj); }))
{
//show messagebox and cancel
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"),
QObject::tr("Some of the selected features have dependencies in the source body"));
return;
}

// Collect dependenies of the selected features
std::vector<App::DocumentObject*> dependencies = PartDesignGui::collectMovableDependencies(features);
if (!dependencies.empty())
features.insert(std::end(features), std::begin(dependencies), std::end(dependencies));
// Check if all features are valid to move
if (std::any_of(std::begin(features), std::end(features), [](App::DocumentObject* obj){return !PartDesignGui::isFeatureMovable(obj); }))
{
//show messagebox and cancel
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"),
QObject::tr("Some of the selected features have dependencies in the source body"));
return;
}

// Collect dependenies of the selected features
std::vector<App::DocumentObject*> dependencies = PartDesignGui::collectMovableDependencies(features);
if (!dependencies.empty())
features.insert(std::end(features), std::begin(dependencies), std::end(dependencies));

// Create a list of all bodies in this part
std::vector<App::DocumentObject*> bodies = getDocument()->getObjectsOfType(Part::BodyBase::getClassTypeId());
std::set<App::DocumentObject*> source_bodies;
for (auto feat : features) {
PartDesign::Body* source = PartDesign::Body::findBodyOf(feat);
source_bodies.insert(static_cast<App::DocumentObject*>(source));
}

std::vector<App::DocumentObject*> target_bodies;
for (auto body : bodies) {
if (!source_bodies.count(body))
target_bodies.push_back(body);
}

if (target_bodies.empty())
{
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"),
QObject::tr("There are no other bodies to move to"));
return;
}

std::set<App::DocumentObject*> source_bodies;
for (auto feat : features) {
PartDesign::Body* source = PartDesign::Body::findBodyOf(feat);
source_bodies.insert(static_cast<App::DocumentObject*>(source));
}

std::vector<App::DocumentObject*> target_bodies;
for (auto body : bodies) {
if (!source_bodies.count(body))
target_bodies.push_back(body);
}

if (target_bodies.empty())
{
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"),
QObject::tr("There are no other bodies to move to"));
return;
}

// Ask user to select the target body (remove source bodies from list)
bool ok;
QStringList items;
for (auto body : target_bodies) {
items.push_back(QString::fromUtf8(body->Label.getValue()));
}
for (auto body : target_bodies) {
items.push_back(QString::fromUtf8(body->Label.getValue()));
}
QString text = QInputDialog::getItem(Gui::getMainWindow(),
qApp->translate("PartDesign_MoveFeature", "Select body"),
qApp->translate("PartDesign_MoveFeature", "Select a body from the list"),
Expand All @@ -637,7 +637,7 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
int index = items.indexOf(text);
if (index < 0) return;

PartDesign::Body* target = static_cast<PartDesign::Body*>(target_bodies[index]);
PartDesign::Body* target = static_cast<PartDesign::Body*>(target_bodies[index]);

openCommand("Move an object");

Expand Down Expand Up @@ -668,8 +668,8 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
// If we removed the tip of the source body, make the new tip visible
if ( featureWasTip ) {
App::DocumentObject * sourceNewTip = source->Tip.getValue();
if (sourceNewTip)
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", sourceNewTip->getNameInDocument());
if (sourceNewTip)
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", sourceNewTip->getNameInDocument());
}

// Hide old tip and show new tip (the moved feature) of the target body
Expand All @@ -695,8 +695,8 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
}
}

//relink origin for sketches and datums (coordinates)
PartDesignGui::relinkToOrigin(feat, target);
//relink origin for sketches and datums (coordinates)
PartDesignGui::relinkToOrigin(feat, target);
}

updateActive();
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskPipeParameters.cpp
Expand Up @@ -715,7 +715,7 @@ bool TaskDlgPipeParameters::accept()
//the user has to decide which option we should take if external references are used
PartDesign::Pipe* pcPipe = static_cast<PartDesign::Pipe*>(getPipeView()->getObject());
auto pcActiveBody = PartDesignGui::getBodyFor(pcPipe, false);
auto pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false);
//auto pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false);
std::vector<App::DocumentObject*> copies;

bool ext = false;
Expand Down
258 changes: 129 additions & 129 deletions src/Mod/PartDesign/Gui/Utils.cpp
Expand Up @@ -348,142 +348,142 @@ void relinkToBody (PartDesign::Feature *feature) {

bool isFeatureMovable(App::DocumentObject* const feat)
{
if (feat->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
auto prim = static_cast<PartDesign::Feature*>(feat);
App::DocumentObject* bf = prim->BaseFeature.getValue();
if (bf)
return false;
}

if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) {
auto prim = static_cast<PartDesign::FeaturePrimitive*>(feat);

if (!isFeatureMovable(prim->CoordinateSystem.getValue()))
return false;
}

if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
auto prim = static_cast<PartDesign::ProfileBased*>(feat);
auto sk = prim->getVerifiedSketch(true);

if (!isFeatureMovable(static_cast<App::DocumentObject*>(sk)))
return false;
if (auto prop = static_cast<App::PropertyLinkList*>(prim->getPropertyByName("Sections"))) {
if (std::any_of(prop->getValues().begin(), prop->getValues().end(), [](App::DocumentObject* obj){return !isFeatureMovable(obj); }))
return false;
}

if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("ReferenceAxis"))) {
App::DocumentObject* axis = prop->getValue();
if (!isFeatureMovable(static_cast<App::DocumentObject*>(axis)))
return false;
}

if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("Spine"))) {
App::DocumentObject* axis = prop->getValue();
if (!isFeatureMovable(static_cast<App::DocumentObject*>(axis)))
return false;
}

if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("AuxillerySpine"))) {
App::DocumentObject* axis = prop->getValue();
if (!isFeatureMovable(static_cast<App::DocumentObject*>(axis)))
return false;
}

}

if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) {
auto attachable = static_cast<Part::AttachableObject*>(feat);
App::DocumentObject* support = attachable->Support.getValue();
if (support && !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId()))
return false;
}

return true;
if (feat->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
auto prim = static_cast<PartDesign::Feature*>(feat);
App::DocumentObject* bf = prim->BaseFeature.getValue();
if (bf)
return false;
}

if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) {
auto prim = static_cast<PartDesign::FeaturePrimitive*>(feat);

if (!isFeatureMovable(prim->CoordinateSystem.getValue()))
return false;
}

if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
auto prim = static_cast<PartDesign::ProfileBased*>(feat);
auto sk = prim->getVerifiedSketch(true);

if (!isFeatureMovable(static_cast<App::DocumentObject*>(sk)))
return false;

if (auto prop = static_cast<App::PropertyLinkList*>(prim->getPropertyByName("Sections"))) {
if (std::any_of(prop->getValues().begin(), prop->getValues().end(), [](App::DocumentObject* obj){return !isFeatureMovable(obj); }))
return false;
}

if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("ReferenceAxis"))) {
App::DocumentObject* axis = prop->getValue();
if (!isFeatureMovable(static_cast<App::DocumentObject*>(axis)))
return false;
}

if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("Spine"))) {
App::DocumentObject* axis = prop->getValue();
if (!isFeatureMovable(static_cast<App::DocumentObject*>(axis)))
return false;
}

if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("AuxillerySpine"))) {
App::DocumentObject* axis = prop->getValue();
if (!isFeatureMovable(static_cast<App::DocumentObject*>(axis)))
return false;
}

}

if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) {
auto attachable = static_cast<Part::AttachableObject*>(feat);
App::DocumentObject* support = attachable->Support.getValue();
if (support && !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId()))
return false;
}

return true;
}

std::vector<App::DocumentObject*> collectMovableDependencies(std::vector<App::DocumentObject*>& features)
{
std::set<App::DocumentObject*> unique_objs;

for (auto const &feat : features)
{
// Get coordinate system object
if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) {
auto prim = static_cast<PartDesign::FeaturePrimitive*>(feat);
App::DocumentObject* cs = prim->CoordinateSystem.getValue();
if (cs && cs->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId())
unique_objs.insert(cs);
}

// Get sketches and datums from profile based features
if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
auto prim = static_cast<PartDesign::ProfileBased*>(feat);
Part::Part2DObject* sk = prim->getVerifiedSketch(true);
if (sk) {
unique_objs.insert(static_cast<App::DocumentObject*>(sk));
}
if (auto prop = static_cast<App::PropertyLinkList*>(prim->getPropertyByName("Sections"))) {
for (App::DocumentObject* obj : prop->getValues()) {
unique_objs.insert(obj);
}
}
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("ReferenceAxis"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
unique_objs.insert(axis);
}
}
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("Spine"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
unique_objs.insert(axis);
}
}
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("AuxillerySpine"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
unique_objs.insert(axis);
}
}
}
}

std::vector<App::DocumentObject*> result;
result.reserve(unique_objs.size());
result.insert(result.begin(), unique_objs.begin(), unique_objs.end());

return result;
std::set<App::DocumentObject*> unique_objs;

for (auto const &feat : features)
{
// Get coordinate system object
if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) {
auto prim = static_cast<PartDesign::FeaturePrimitive*>(feat);
App::DocumentObject* cs = prim->CoordinateSystem.getValue();
if (cs && cs->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId())
unique_objs.insert(cs);
}

// Get sketches and datums from profile based features
if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
auto prim = static_cast<PartDesign::ProfileBased*>(feat);
Part::Part2DObject* sk = prim->getVerifiedSketch(true);
if (sk) {
unique_objs.insert(static_cast<App::DocumentObject*>(sk));
}
if (auto prop = static_cast<App::PropertyLinkList*>(prim->getPropertyByName("Sections"))) {
for (App::DocumentObject* obj : prop->getValues()) {
unique_objs.insert(obj);
}
}
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("ReferenceAxis"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
unique_objs.insert(axis);
}
}
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("Spine"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
unique_objs.insert(axis);
}
}
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("AuxillerySpine"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
unique_objs.insert(axis);
}
}
}
}

std::vector<App::DocumentObject*> result;
result.reserve(unique_objs.size());
result.insert(result.begin(), unique_objs.begin(), unique_objs.end());

return result;
}

void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody)
{
if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) {
auto attachable = static_cast<Part::AttachableObject*>(feat);
App::DocumentObject* support = attachable->Support.getValue();
if (support && support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) {
auto originfeat = static_cast<App::OriginFeature*>(support);
App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue());
if (targetOriginFeature) {
attachable->Support.setValue(static_cast<App::DocumentObject*>(targetOriginFeature), "");
}
}
}
else if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
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->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
auto originfeat = static_cast<App::OriginFeature*>(axis);
App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue());
if (targetOriginFeature) {
prop->setValue(static_cast<App::DocumentObject*>(targetOriginFeature), std::vector<std::string>(0));
}
}
}
}
if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) {
auto attachable = static_cast<Part::AttachableObject*>(feat);
App::DocumentObject* support = attachable->Support.getValue();
if (support && support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) {
auto originfeat = static_cast<App::OriginFeature*>(support);
App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue());
if (targetOriginFeature) {
attachable->Support.setValue(static_cast<App::DocumentObject*>(targetOriginFeature), "");
}
}
}
else if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
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->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
auto originfeat = static_cast<App::OriginFeature*>(axis);
App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue());
if (targetOriginFeature) {
prop->setValue(static_cast<App::DocumentObject*>(targetOriginFeature), std::vector<std::string>(0));
}
}
}
}
}

} /* PartDesignGui */
} /* PartDesignGui */

0 comments on commit 46adbae

Please sign in to comment.