Skip to content

Commit

Permalink
fix relinkToOrigin, remove source body from list, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
usakhelo authored and wwmayer committed Aug 24, 2016
1 parent 3177402 commit c90da8e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
28 changes: 24 additions & 4 deletions src/Mod/PartDesign/Gui/CommandBody.cpp
Expand Up @@ -603,12 +603,32 @@ void CmdPartDesignMoveFeature::activated(int iMsg)

// 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);
}

// Ask user to select the target 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 (std::vector<App::DocumentObject*>::iterator it = bodies.begin(); it != bodies.end(); ++it)
items.push_back(QString::fromUtf8((*it)->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 @@ -617,7 +637,7 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
int index = items.indexOf(text);
if (index < 0) return;

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

openCommand("Move an object");

Expand Down
21 changes: 16 additions & 5 deletions src/Mod/PartDesign/Gui/Utils.cpp
Expand Up @@ -394,11 +394,10 @@ bool isFeatureMovable(App::DocumentObject* const feat)

}

if (feat->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) ||
feat->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) {
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()))
if (support && !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId()))
return false;
}

Expand Down Expand Up @@ -461,8 +460,7 @@ std::vector<App::DocumentObject*> collectMovableDependencies(std::vector<App::Do

void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody)
{
if (feat->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) ||
feat->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) {
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())) {
Expand All @@ -473,6 +471,19 @@ void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody)
}
}
}
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 */

0 comments on commit c90da8e

Please sign in to comment.