GeoFeatureGroup: Handle drag into document
This commit is contained in:
@@ -111,15 +111,16 @@ Base::Placement GeoFeatureGroupExtension::recursiveGroupPlacement(GeoFeatureGrou
|
||||
return group->placement().getValue();
|
||||
}
|
||||
|
||||
void GeoFeatureGroupExtension::addObject(App::DocumentObject* object) {
|
||||
std::vector<DocumentObject*> GeoFeatureGroupExtension::addObject(App::DocumentObject* object) {
|
||||
|
||||
if(!allowObject(object))
|
||||
return;
|
||||
return std::vector<DocumentObject*>();
|
||||
|
||||
//cross CoordinateSystem links are not allowed, so we need to move the whole link group
|
||||
auto links = getCSRelevantLinks(object);
|
||||
links.push_back(object);
|
||||
|
||||
auto ret = links;
|
||||
std::vector<DocumentObject*> grp = Group.getValues();
|
||||
for( auto obj : links) {
|
||||
//only one geofeaturegroup per object.
|
||||
@@ -129,13 +130,16 @@ void GeoFeatureGroupExtension::addObject(App::DocumentObject* object) {
|
||||
|
||||
if (!hasObject(obj))
|
||||
grp.push_back(obj);
|
||||
else
|
||||
ret.erase(std::remove(ret.begin(), ret.end(), obj), ret.end());
|
||||
}
|
||||
|
||||
Group.setValues(grp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void GeoFeatureGroupExtension::removeObject(App::DocumentObject* object) {
|
||||
std::vector<DocumentObject*> GeoFeatureGroupExtension::removeObject(App::DocumentObject* object) {
|
||||
|
||||
//cross CoordinateSystem links are not allowed, so we need to remove the whole link group
|
||||
auto links = getCSRelevantLinks(object);
|
||||
@@ -147,6 +151,7 @@ void GeoFeatureGroupExtension::removeObject(App::DocumentObject* object) {
|
||||
grp.erase(std::remove(grp.begin(), grp.end(), link), grp.end());
|
||||
|
||||
Group.setValues(grp);
|
||||
return links;
|
||||
}
|
||||
|
||||
std::vector< DocumentObject* > GeoFeatureGroupExtension::getObjectsFromLinks(DocumentObject* obj) {
|
||||
|
||||
@@ -96,8 +96,8 @@ public:
|
||||
!obj->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId());
|
||||
}
|
||||
|
||||
virtual void addObject(DocumentObject* obj);
|
||||
virtual void removeObject(DocumentObject* obj);
|
||||
virtual std::vector<DocumentObject*> addObject(DocumentObject* obj) override;
|
||||
virtual std::vector<DocumentObject*> removeObject(DocumentObject* obj) override;
|
||||
|
||||
/// returns GeoFeatureGroup relevant objects that are linked from the given one. That meas all linked objects
|
||||
/// including their linkes (recursively) except GeoFeatureGroups, where the recursion stops. Expressions
|
||||
|
||||
@@ -59,13 +59,13 @@ DocumentObject* GroupExtension::addObject(const char* sType, const char* pObject
|
||||
return obj;
|
||||
}
|
||||
|
||||
void GroupExtension::addObject(DocumentObject* obj)
|
||||
std::vector<DocumentObject*> GroupExtension::addObject(DocumentObject* obj)
|
||||
{
|
||||
if(!allowObject(obj))
|
||||
return;
|
||||
return std::vector<DocumentObject*>();
|
||||
|
||||
if (hasObject(obj))
|
||||
return;
|
||||
return std::vector<DocumentObject*>();
|
||||
|
||||
//only one group per object. Note that it is allowed to be in a group and geofeaturegroup. However,
|
||||
//getGroupOfObject() returns only normal groups, no GeoFeatureGroups. Hence this works.
|
||||
@@ -81,6 +81,9 @@ void GroupExtension::addObject(DocumentObject* obj)
|
||||
std::vector<DocumentObject*> grp = Group.getValues();
|
||||
grp.push_back(obj);
|
||||
Group.setValues(grp);
|
||||
|
||||
std::vector<DocumentObject*> vec = {obj};
|
||||
return vec;
|
||||
}
|
||||
|
||||
void GroupExtension::addObjects(const std::vector<App::DocumentObject*>& objs)
|
||||
@@ -106,7 +109,7 @@ void GroupExtension::addObjects(const std::vector<App::DocumentObject*>& objs)
|
||||
Group.setValues(grp);
|
||||
}
|
||||
|
||||
void GroupExtension::removeObject(DocumentObject* obj)
|
||||
std::vector<DocumentObject*> GroupExtension::removeObject(DocumentObject* obj)
|
||||
{
|
||||
const std::vector<DocumentObject*> & grp = Group.getValues();
|
||||
std::vector<DocumentObject*> newGrp;
|
||||
@@ -115,6 +118,9 @@ void GroupExtension::removeObject(DocumentObject* obj)
|
||||
if (grp.size() != newGrp.size()) {
|
||||
Group.setValues (newGrp);
|
||||
}
|
||||
|
||||
std::vector<DocumentObject*> vec = {obj};
|
||||
return vec;
|
||||
}
|
||||
|
||||
void GroupExtension::removeObjectsFromDocument()
|
||||
|
||||
@@ -50,9 +50,9 @@ public:
|
||||
* append it to this group as well.
|
||||
*/
|
||||
virtual DocumentObject *addObject(const char* sType, const char* pObjectName);
|
||||
/* Adds the object \a obj to this group.
|
||||
/* Adds the object \a obj to this group. Returns all objects that have been added.
|
||||
*/
|
||||
virtual void addObject(DocumentObject* obj);
|
||||
virtual std::vector<DocumentObject*> addObject(DocumentObject* obj);
|
||||
/* Adds an array of object \a objs to this group.
|
||||
*/
|
||||
virtual void addObjects(const std::vector<App::DocumentObject*>& objs);
|
||||
@@ -60,9 +60,9 @@ public:
|
||||
*/
|
||||
virtual bool allowObject(DocumentObject* ) {return true;}
|
||||
|
||||
/** Removes an object from this group.
|
||||
/** Removes an object from this group. Returns all objects that have been removed.
|
||||
*/
|
||||
virtual void removeObject(DocumentObject* obj);
|
||||
virtual std::vector<DocumentObject*> removeObject(DocumentObject* obj);
|
||||
/** Removes all children objects from this group and the document.
|
||||
*/
|
||||
virtual void removeObjectsFromDocument();
|
||||
|
||||
@@ -86,8 +86,12 @@ PyObject* GroupExtensionPy::addObject(PyObject *args)
|
||||
|
||||
GroupExtension* grp = getGroupExtensionPtr();
|
||||
|
||||
grp->addObject(docObj->getDocumentObjectPtr());
|
||||
Py_Return;
|
||||
auto vec = grp->addObject(docObj->getDocumentObjectPtr());
|
||||
Py::List list;
|
||||
for (App::DocumentObject* obj : vec)
|
||||
list.append(Py::asObject(obj->getPyObject()));
|
||||
|
||||
return Py::new_reference_to(list);
|
||||
}
|
||||
|
||||
PyObject* GroupExtensionPy::removeObject(PyObject *args)
|
||||
@@ -108,8 +112,12 @@ PyObject* GroupExtensionPy::removeObject(PyObject *args)
|
||||
|
||||
GroupExtension* grp = getGroupExtensionPtr();
|
||||
|
||||
grp->removeObject(docObj->getDocumentObjectPtr());
|
||||
Py_Return;
|
||||
auto vec = grp->removeObject(docObj->getDocumentObjectPtr());
|
||||
Py::List list;
|
||||
for (App::DocumentObject* obj : vec)
|
||||
list.append(Py::asObject(obj->getPyObject()));
|
||||
|
||||
return Py::new_reference_to(list);
|
||||
}
|
||||
|
||||
PyObject* GroupExtensionPy::removeObjectsFromDocument(PyObject *args)
|
||||
|
||||
@@ -174,9 +174,9 @@ void OriginGroupExtension::relinkToOrigin(App::DocumentObject* obj)
|
||||
}
|
||||
}
|
||||
|
||||
void OriginGroupExtension::addObject(DocumentObject* obj) {
|
||||
std::vector< DocumentObject* > OriginGroupExtension::addObject(DocumentObject* obj) {
|
||||
relinkToOrigin(obj);
|
||||
App::GeoFeatureGroupExtension::addObject(obj);
|
||||
return App::GeoFeatureGroupExtension::addObject(obj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
//changes all links of obj to a origin to point to this groupes origin
|
||||
void relinkToOrigin(App::DocumentObject* obj);
|
||||
|
||||
virtual void addObject(DocumentObject* obj) override;
|
||||
virtual std::vector<DocumentObject*> addObject(DocumentObject* obj) override;
|
||||
|
||||
protected:
|
||||
/// Checks integrity of the Origin
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectGroup.h>
|
||||
#include <App/GeoFeatureGroupExtension.h>
|
||||
|
||||
#include "Tree.h"
|
||||
#include "Command.h"
|
||||
@@ -643,11 +644,26 @@ void TreeWidget::dropEvent(QDropEvent *event)
|
||||
vpp->dragObject(obj);
|
||||
}
|
||||
|
||||
std::list<MDIView*> baseViews = gui->getMDIViews();
|
||||
for (MDIView* view : baseViews) {
|
||||
View3DInventor *activeView = dynamic_cast<View3DInventor *>(view);
|
||||
if (activeView && !activeView->getViewer()->hasViewProvider(vpc)) {
|
||||
activeView->getViewer()->addViewProvider(vpc);
|
||||
//make sure it is not part of a geofeaturegroup anymore. When this has happen we need to handle
|
||||
//all removed objects
|
||||
std::vector<Gui::ViewProvider*> vps = {vpc};
|
||||
auto grp = App::GeoFeatureGroupExtension::getGroupOfObject(obj);
|
||||
if(grp) {
|
||||
auto removed = grp->getExtensionByType<App::GeoFeatureGroupExtension>()->removeObject(obj);
|
||||
for(auto o : removed) {
|
||||
auto remvp = gui->getViewProvider(o);
|
||||
if(remvp)
|
||||
vps.push_back(remvp);
|
||||
}
|
||||
}
|
||||
|
||||
for(auto vp : vps) {
|
||||
std::list<MDIView*> baseViews = gui->getMDIViews();
|
||||
for (MDIView* view : baseViews) {
|
||||
View3DInventor *activeView = dynamic_cast<View3DInventor *>(view);
|
||||
if (activeView && !activeView->getViewer()->hasViewProvider(vp)) {
|
||||
activeView->getViewer()->addViewProvider(vp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,16 +265,19 @@ Body* Body::findBodyOf(const App::DocumentObject* feature)
|
||||
}
|
||||
|
||||
|
||||
void Body::addObject(App::DocumentObject *feature)
|
||||
std::vector<App::DocumentObject*> Body::addObject(App::DocumentObject *feature)
|
||||
{
|
||||
if(!isAllowed(feature))
|
||||
throw Base::Exception("Body: object is not allowed");
|
||||
|
||||
|
||||
//TODO: features should not add all links
|
||||
/*
|
||||
//only one group per object
|
||||
auto *group = App::GroupExtension::getGroupOfObject(feature);
|
||||
if(group && group != getExtendedObject())
|
||||
group->getExtensionByType<App::GroupExtension>()->removeObject(feature);
|
||||
|
||||
*/
|
||||
|
||||
insertObject (feature, getNextSolidFeature (), /*after = */ false);
|
||||
// Move the Tip if we added a solid
|
||||
if (isSolidFeature(feature)) {
|
||||
@@ -345,7 +348,7 @@ void Body::insertObject(App::DocumentObject* feature, App::DocumentObject* targe
|
||||
}
|
||||
|
||||
|
||||
void Body::removeObject(App::DocumentObject* feature)
|
||||
std::vector<App::DocumentObject*> Body::removeObject(App::DocumentObject* feature)
|
||||
{
|
||||
App::DocumentObject* nextSolidFeature = getNextSolidFeature(feature);
|
||||
App::DocumentObject* prevSolidFeature = getPrevSolidFeature(feature);
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
* Add the feature into the body at the current insert point.
|
||||
* The insertion poin is the before next solid after the Tip feature
|
||||
*/
|
||||
virtual void addObject(App::DocumentObject*) override;
|
||||
virtual std::vector<App::DocumentObject*> addObject(App::DocumentObject*) override;
|
||||
|
||||
/**
|
||||
* Insert the feature into the body after the given feature.
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
void insertObject(App::DocumentObject* feature, App::DocumentObject* target, bool after=false);
|
||||
|
||||
/// Remove the feature from the body
|
||||
virtual void removeObject(DocumentObject* obj) override;
|
||||
virtual std::vector<DocumentObject*> removeObject(DocumentObject* obj) override;
|
||||
|
||||
/**
|
||||
* Checks if the given document object lays after the current insert point
|
||||
|
||||
Reference in New Issue
Block a user