Skip to content

Commit

Permalink
+ FEM: Improve drag and drop for FEM analysis object
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Apr 23, 2015
1 parent bf32404 commit 13b8d32
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/Gui/Tree.cpp
Expand Up @@ -390,6 +390,9 @@ QMimeData * TreeWidget::mimeData (const QList<QTreeWidgetItem *> items) const
if (!vp->canDragObjects()) {
return 0;
}
else if (!vp->canDragObject(obj)) {
return 0;
}
}
}
}
Expand Down Expand Up @@ -479,6 +482,12 @@ void TreeWidget::dragMoveEvent(QDragMoveEvent *event)
event->ignore();
return;
}

// let the view provider decide to accept the object or ignore it
if (!vp->canDropObject(obj)) {
event->ignore();
return;
}
}
}
else {
Expand Down
19 changes: 18 additions & 1 deletion src/Gui/ViewProvider.h
Expand Up @@ -134,7 +134,7 @@ class GuiExport ViewProvider : public App::PropertyContainer
/** @name Methods used by the Tree
* If you want to take control over the
* appearance of your object in the tree you
* can reimplemnt this methods.
* can reimplemnt these methods.
*/
//@{
/// deliver the icon shown in the tree view
Expand All @@ -148,15 +148,32 @@ class GuiExport ViewProvider : public App::PropertyContainer
*/
virtual std::vector<App::DocumentObject*> claimChildren(void) const
{ return std::vector<App::DocumentObject*>(); }
//@}

/** @name Drag and drop
* To enable drag and drop you have to re-implement \ref canDragObjects() and
* \ref canDropObjects() to return true. For finer control you can also re-implement
* \ref canDragObject() or \ref canDropObject() to filter certain object types, by
* default these methods don't filter any types.
* To take action of drag and drop the method \ref dragObject() and \ref dropObject()
* must be re-implemented, too.
*/
//@{
/** Check whether children can be removed from the view provider by drag and drop */
virtual bool canDragObjects() const
{ return false; }
/** Check whether the object can be removed from the view provider by drag and drop */
virtual bool canDragObject(App::DocumentObject*) const
{ return true; }
/** Remove a child from the view provider by drag and drop */
virtual void dragObject(App::DocumentObject*)
{ }
/** Check whether objects can be added to the view provider by drag and drop */
virtual bool canDropObjects() const
{ return false; }
/** Check whether the object can be dropped to the view provider by drag and drop */
virtual bool canDropObject(App::DocumentObject*) const
{ return true; }
/** Add an object to the view provider by drag and drop */
virtual void dropObject(App::DocumentObject*)
{ }
Expand Down
28 changes: 24 additions & 4 deletions src/Mod/Fem/Gui/ViewProviderAnalysis.cpp
Expand Up @@ -25,7 +25,6 @@

#ifndef _PreComp_
# include <Standard_math.hxx>

#endif

#include "ViewProviderAnalysis.h"
Expand All @@ -35,6 +34,9 @@

#include <Mod/Fem/App/FemAnalysis.h>
#include <Mod/Fem/App/FemMeshObject.h>
#include <Mod/Fem/App/FemSetObject.h>
#include <Mod/Fem/App/FemConstraint.h>
#include <App/MaterialObject.h>

#include "TaskDlgAnalysis.h"

Expand All @@ -52,7 +54,6 @@ PROPERTY_SOURCE(FemGui::ViewProviderFemAnalysis, Gui::ViewProviderDocumentObject
ViewProviderFemAnalysis::ViewProviderFemAnalysis()
{
sPixmap = "Fem_Analysis";

}

ViewProviderFemAnalysis::~ViewProviderFemAnalysis()
Expand Down Expand Up @@ -165,6 +166,22 @@ bool ViewProviderFemAnalysis::canDragObjects() const
return true;
}

bool ViewProviderFemAnalysis::canDragObject(App::DocumentObject* obj) const
{
if (!obj)
return false;
if (obj->getTypeId().isDerivedFrom(Fem::FemMeshObject::getClassTypeId()))
return true;
else if (obj->getTypeId().isDerivedFrom(Fem::Constraint::getClassTypeId()))
return true;
else if (obj->getTypeId().isDerivedFrom(Fem::FemSetObject::getClassTypeId()))
return true;
else if (obj->getTypeId().isDerivedFrom(App::MaterialObject::getClassTypeId()))
return true;
else
return false;
}

void ViewProviderFemAnalysis::dragObject(App::DocumentObject* obj)
{
Fem::FemAnalysis* analyze = static_cast<Fem::FemAnalysis*>(getObject());
Expand All @@ -183,10 +200,13 @@ bool ViewProviderFemAnalysis::canDropObjects() const
return true;
}

bool ViewProviderFemAnalysis::canDropObject(App::DocumentObject* obj) const
{
return canDragObject(obj);
}

void ViewProviderFemAnalysis::dropObject(App::DocumentObject* obj)
{
if (!obj || !obj->getTypeId().isDerivedFrom(Fem::FemMeshObject::getClassTypeId()))
return;
Fem::FemAnalysis* analyze = static_cast<Fem::FemAnalysis*>(getObject());
std::vector<App::DocumentObject*> fem = analyze->Member.getValues();
fem.push_back(obj);
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Fem/Gui/ViewProviderAnalysis.h
Expand Up @@ -67,10 +67,14 @@ class FemGuiExport ViewProviderFemAnalysis : public Gui::ViewProviderDocumentObj
//@{
/// Returns true if the view provider generally supports dragging objects
bool canDragObjects() const;
/// Check whether the object can be removed from the view provider by drag and drop
bool canDragObject(App::DocumentObject*) const;
/// Starts to drag the object
void dragObject(App::DocumentObject*);
/// Returns true if the view provider generally accepts dropping of objects
bool canDropObjects() const;
/// Check whether the object can be dropped to the view provider by drag and drop
bool canDropObject(App::DocumentObject*) const;
/// If the dropped object type is accepted the object will be added as child
void dropObject(App::DocumentObject*);
//@}
Expand Down

0 comments on commit 13b8d32

Please sign in to comment.