Skip to content

Commit

Permalink
+ FEM: Support drag and drop for analysis object
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Apr 22, 2015
1 parent bf2266a commit f460cec
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Mod/Fem/Gui/ViewProviderAnalysis.cpp
Expand Up @@ -34,6 +34,7 @@
#include <Gui/Control.h>

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

#include "TaskDlgAnalysis.h"

Expand Down Expand Up @@ -159,6 +160,39 @@ bool ViewProviderFemAnalysis::onDelete(const std::vector<std::string> &)
return true;
}

bool ViewProviderFemAnalysis::canDragObjects() const
{
return true;
}

void ViewProviderFemAnalysis::dragObject(App::DocumentObject* obj)
{
Fem::FemAnalysis* analyze = static_cast<Fem::FemAnalysis*>(getObject());
std::vector<App::DocumentObject*> fem = analyze->Member.getValues();
for (std::vector<App::DocumentObject*>::iterator it = fem.begin(); it != fem.end(); ++it) {
if (*it == obj) {
fem.erase(it);
analyze->Member.setValues(fem);
break;
}
}
}

bool ViewProviderFemAnalysis::canDropObjects() const
{
return true;
}

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);
analyze->Member.setValues(fem);
}

// Python feature -----------------------------------------------------------------------

namespace Gui {
Expand Down
12 changes: 12 additions & 0 deletions src/Mod/Fem/Gui/ViewProviderAnalysis.h
Expand Up @@ -63,6 +63,18 @@ class FemGuiExport ViewProviderFemAnalysis : public Gui::ViewProviderDocumentObj
// shows solid in the tree
virtual bool isShow(void) const{return true;}

/** @name Drag and drop */
//@{
/// Returns true if the view provider generally supports dragging objects
bool canDragObjects() const;
/// Starts to drag the object
void dragObject(App::DocumentObject*);
/// Returns true if the view provider generally accepts dropping of objects
bool canDropObjects() const;
/// If the dropped object type is accepted the object will be added as child
void dropObject(App::DocumentObject*);
//@}

protected:
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
Expand Down

0 comments on commit f460cec

Please sign in to comment.