implement drag and drop for body view provider

This commit is contained in:
wmayer
2017-09-22 13:12:20 +02:00
parent 75b2e858a2
commit 9cc8c722cb
2 changed files with 47 additions and 0 deletions

View File

@@ -416,3 +416,43 @@ std::vector< std::string > ViewProviderBody::getDisplayModes(void) const {
modes.erase(modes.begin());
return modes;
}
bool ViewProviderBody::canDropObjects() const
{
// if the BaseFeature property is marked as hidden or read-only then
// it's not allowed to modify it.
PartDesign::Body* body = static_cast<PartDesign::Body*>(getObject());
if (body->BaseFeature.testStatus(App::Property::Status::Hidden))
return false;
if (body->BaseFeature.testStatus(App::Property::Status::ReadOnly))
return false;
return true;
}
bool ViewProviderBody::canDropObject(App::DocumentObject* obj) const
{
if (!obj->isDerivedFrom(Part::Feature::getClassTypeId())) {
return false;
}
else if (PartDesign::Body::findBodyOf(obj)) {
return false;
}
else if (obj->isDerivedFrom (Part::BodyBase::getClassTypeId())) {
return false;
}
App::Part *actPart = PartDesignGui::getActivePart();
App::Part* partOfBaseFeature = App::Part::getPartOfObject(obj);
if (partOfBaseFeature != 0 && partOfBaseFeature != actPart)
return false;
return true;
}
void ViewProviderBody::dropObject(App::DocumentObject* obj)
{
PartDesign::Body* body = static_cast<PartDesign::Body*>(getObject());
body->BaseFeature.setValue(obj);
App::Document* doc = body->getDocument();
doc->recompute();
}

View File

@@ -78,6 +78,13 @@ public:
*/
SbBox3f getBoundBox ();
/** Check whether objects can be added to the view provider by drag and drop */
virtual bool canDropObjects() const;
/** Check whether the object can be dropped to the view provider by drag and drop */
virtual bool canDropObject(App::DocumentObject*) const;
/** Add an object to the view provider by drag and drop */
virtual void dropObject(App::DocumentObject*);
protected:
void slotChangedObjectApp ( const App::DocumentObject& obj, const App::Property& prop );
void slotChangedObjectGui ( const Gui::ViewProviderDocumentObject& obj, const App::Property& prop );