fix relinkToOrigin, remove source body from list, etc
This commit is contained in:
parent
3177402141
commit
c90da8e5fb
|
@ -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));
|
||||
}
|
||||
|
||||
// Ask user to select the target body
|
||||
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 (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"),
|
||||
|
@ -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");
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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())) {
|
||||
|
@ -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 */
|
Loading…
Reference in New Issue
Block a user