Improve GeoFeatureGroup claim children algorithm and remove special Body impelmentation

This commit is contained in:
Stefan Tröger
2017-09-18 20:08:34 +02:00
committed by wmayer
parent 84667e46f0
commit 5e079d331b
3 changed files with 23 additions and 104 deletions

View File

@@ -67,35 +67,32 @@ std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensio
std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensionClaimChildren(void) const {
//we must be careful which objects to claim, as there might be stacked relations inside the coordinate system,
//like pad/sketch
auto* ext = getExtendedViewProvider()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
if(ext) {
//filter out all objects with more than one inlink, as they are most likely hold by another
//object in the tree
std::vector<App::DocumentObject*> claim;
auto objs = ext->Group.getValues();
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
const std::vector<App::DocumentObject*> &model = group->Group.getValues ();
std::set<App::DocumentObject*> outSet; //< set of objects not to claim (childrens of childrens)
for(auto obj : objs) {
// search for objects handled (claimed) by the features
for( auto obj: model){
//stuff in annother geofeaturegroup is not in the model anyway
if (!obj || obj->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) { continue; }
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider ( obj );
if (!vp || vp == getExtendedViewProvider()) { continue; }
auto vin = obj->getInList();
//we don't want to count objects that are deleted or part of other geo feature groups.
//Second criteria is actually not possible in normal operation, but only in some error
//condition. But then it is needed to understand the problem for the user
auto grp = getExtendedViewProvider()->getObject();
vin.erase(std::remove_if(vin.begin(), vin.end(), [&](App::DocumentObject* obj)->bool {
return obj->isRemoving() ||
obj == grp ||
App::GeoFeatureGroupExtension::getGroupOfObject(obj)!=grp;
}), vin.end());
if(vin.empty())
claim.push_back(obj);
}
return claim;
auto children = vp->claimChildren();
std::remove_copy ( children.begin (), children.end (), std::inserter (outSet, outSet.begin () ), nullptr);
}
return std::vector<App::DocumentObject*>();
// remove the otherwise handled objects, preserving their order so the order in the TreeWidget is correct
std::vector<App::DocumentObject*> Result;
// claim for rest content not claimed by any other features
std::remove_copy_if (model.begin(), model.end(), std::back_inserter (Result),
[outSet] (App::DocumentObject* obj) {
return outSet.find (obj) != outSet.end();
} );
return Result;
}
void ViewProviderGeoFeatureGroupExtension::extensionAttach(App::DocumentObject* pcObject)

View File

@@ -178,80 +178,6 @@ bool ViewProviderBody::doubleClicked(void)
return true;
}
std::vector<App::DocumentObject*> ViewProviderBody::claimChildren(void)const
{
PartDesign::Body* body= static_cast<PartDesign::Body*> ( getObject () );
const std::vector<App::DocumentObject*> &model = body->Group.getValues ();
std::set<App::DocumentObject*> outSet; //< set of objects not to claim (childrens of childrens)
// search for objects handled (claimed) by the features
for( auto obj: model){
if (!obj) { continue; }
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider ( obj );
if (!vp) { continue; }
auto children = vp->claimChildren();
std::remove_copy ( children.begin (), children.end (), std::inserter (outSet, outSet.begin () ), nullptr);
}
// remove the otherwise handled objects, preserving their order so the order in the TreeWidget is correct
std::vector<App::DocumentObject*> Result;
if (body->Origin.getValue()) { // Clame for the Origin
Result.push_back (body->Origin.getValue());
}
// claim for rest content not claimed by any other features
std::remove_copy_if (model.begin(), model.end(), std::back_inserter (Result),
[outSet] (App::DocumentObject* obj) {
return outSet.find (obj) != outSet.end();
} );
return Result;
}
std::vector<App::DocumentObject*> ViewProviderBody::claimChildren3D(void)const
{
PartDesign::Body* body = static_cast<PartDesign::Body*>(getObject());
const std::vector<App::DocumentObject*> & features = body->Group.getValues();
std::vector<App::DocumentObject*> rv;
if ( body->Origin.getValue() ) { // Add origin
rv.push_back (body->Origin.getValue());
}
if ( body->BaseFeature.getValue() ) { // Add Base Feature
rv.push_back (body->BaseFeature.getValue());
}
// Add all other stuff
std::copy (features.begin(), features.end(), std::back_inserter (rv) );
return rv;
}
// TODO To be deleted (2015-09-08, Fat-Zer)
//void ViewProviderBody::updateTree()

View File

@@ -57,10 +57,6 @@ public:
virtual bool doubleClicked(void);
virtual void setupContextMenu(QMenu* menu, QObject* receiver, const char* member);
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
// returns the root node where the children gets collected(3D)
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
virtual std::vector< std::string > getDisplayModes(void) const;
virtual void setDisplayMode(const char* ModeName);