PD: add SelectionFilterGate to filter dependents, fix mirror taskview

This commit is contained in:
Sergo 2016-10-11 20:58:27 -04:00 committed by wmayer
parent cdf437445c
commit be249f902d
5 changed files with 35 additions and 22 deletions

View File

@ -175,12 +175,18 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
bool NoDependentsSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) bool NoDependentsSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName)
{ {
if (support && !support->testIfLinkDAGCompatible(pObj)) { if (support && support->testIfLinkDAGCompatible(pObj)) {
return true;
}
else {
this->notAllowedReason = QT_TR_NOOP("Selecting this will cause circular dependency."); this->notAllowedReason = QT_TR_NOOP("Selecting this will cause circular dependency.");
return false; return false;
} }
}
return refSelection.allow(pDoc, pObj, sSubName); bool CombineSelectionFilterGates::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName)
{
return filter1->allow(pDoc, pObj, sSubName) && filter2->allow(pDoc, pObj, sSubName);
} }

View File

@ -56,21 +56,31 @@ public:
class NoDependentsSelection : public Gui::SelectionFilterGate class NoDependentsSelection : public Gui::SelectionFilterGate
{ {
ReferenceSelection refSelection;
const App::DocumentObject* support; const App::DocumentObject* support;
public: public:
NoDependentsSelection(const App::DocumentObject* support_, NoDependentsSelection(const App::DocumentObject* support_)
const bool edge_, const bool plane_, const bool planar_, const bool point_ = false) : Gui::SelectionFilterGate((Gui::SelectionFilter*)0), support(support_)
: Gui::SelectionFilterGate((Gui::SelectionFilter*)0), refSelection(support_, edge_, plane_, planar_, point_), support(support_)
{ {
} }
/** /**
* Allow the user to pick only objects wich are not in objs getDependencyList * Allow the user to pick only objects wich are not in objs getDependencyList
*/ */
bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName); bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) override;
}; };
class CombineSelectionFilterGates: public Gui::SelectionFilterGate
{
std::unique_ptr<Gui::SelectionFilterGate> filter1;
std::unique_ptr<Gui::SelectionFilterGate> filter2;
public:
CombineSelectionFilterGates(std::unique_ptr<Gui::SelectionFilterGate> &filter1_, std::unique_ptr<Gui::SelectionFilterGate> &filter2_)
: Gui::SelectionFilterGate((Gui::SelectionFilter*)0), filter1(std::move(filter1_)), filter2(std::move(filter2_))
{
}
bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) override;
};
// Convenience methods // Convenience methods
/// Extract reference from Selection /// Extract reference from Selection
void getReferencedSelection(const App::DocumentObject* thisObj, const Gui::SelectionChanges& msg, void getReferencedSelection(const App::DocumentObject* thisObj, const Gui::SelectionChanges& msg,

View File

@ -223,7 +223,7 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p
DatumView->setPickable(false); DatumView->setPickable(false);
Gui::Selection().addSelectionGate(new NoDependentsSelection(DatumView->getObject(), true, true, true, true)); Gui::Selection().addSelectionGate(new NoDependentsSelection(DatumView->getObject()));
// connect object deletion with slot // connect object deletion with slot
auto bnd = boost::bind(&TaskDatumParameters::objectDeleted, this, _1); auto bnd = boost::bind(&TaskDatumParameters::objectDeleted, this, _1);

View File

@ -184,23 +184,18 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName); removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode(); exitSelectionMode();
} else { } else {
// TODO checkme (2015-09-01, Fat-Zer) if ( selectionMode == reference) {
exitSelectionMode();
std::vector<std::string> mirrorPlanes; std::vector<std::string> mirrorPlanes;
App::DocumentObject* selObj; App::DocumentObject* selObj;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject()); PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes); getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes);
if(!selObj) if (!selObj)
return; return;
// Note: ReferenceSelection has already checked the selection for validity
if ( selectionMode == reference ||
selObj->isDerivedFrom ( App::Plane::getClassTypeId () ) ||
selObj->isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes); pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes);
recomputeFeature(); recomputeFeature();
updateUI(); updateUI();
} }
exitSelectionMode();
} }
} }
} }

View File

@ -338,7 +338,9 @@ void TaskTransformedParameters::exitSelectionMode()
void TaskTransformedParameters::addReferenceSelectionGate(bool edge, bool face) void TaskTransformedParameters::addReferenceSelectionGate(bool edge, bool face)
{ {
Gui::Selection().addSelectionGate(new ReferenceSelection(getBaseObject(), edge, face, /*point =*/ true)); std::unique_ptr<Gui::SelectionFilterGate> gateRefPtr = std::make_unique<ReferenceSelection>(getBaseObject(), edge, face, /*point =*/ true);
std::unique_ptr<Gui::SelectionFilterGate> gateDepPtr = std::make_unique<NoDependentsSelection>(getTopTransformedObject());
Gui::Selection().addSelectionGate(new CombineSelectionFilterGates(gateRefPtr, gateDepPtr));
} }
//************************************************************************** //**************************************************************************