Make PartDesign::Boolean work with new Link structure
This is the first feature that used GeoFeatureGroupExtension and required links to the groups inside as well as to things on the same level. Hence a few modifications to link scopes have been nesseccary.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "OriginFeature.h"
|
||||
#include "Origin.h"
|
||||
#include "OriginGroupExtension.h"
|
||||
#include <Base/Console.h>
|
||||
//#include "GeoFeatureGroupPy.h"
|
||||
//#include "FeaturePythonPyImp.h"
|
||||
|
||||
@@ -49,6 +50,7 @@ EXTENSION_PROPERTY_SOURCE(App::GeoFeatureGroupExtension, App::GroupExtension)
|
||||
GeoFeatureGroupExtension::GeoFeatureGroupExtension(void)
|
||||
{
|
||||
initExtensionType(GeoFeatureGroupExtension::getExtensionClassTypeId());
|
||||
Group.setScope(LinkScope::Child);
|
||||
}
|
||||
|
||||
GeoFeatureGroupExtension::~GeoFeatureGroupExtension(void)
|
||||
@@ -367,11 +369,14 @@ void GeoFeatureGroupExtension::getCSRelevantLinks(const DocumentObject* obj, std
|
||||
bool GeoFeatureGroupExtension::areLinksValid(const DocumentObject* obj) {
|
||||
|
||||
//no cross CS link for local links.
|
||||
//Base::Console().Message("Check object links: %s\n", obj->getNameInDocument());
|
||||
std::vector<App::Property*> list;
|
||||
obj->getPropertyList(list);
|
||||
for(App::Property* prop : list) {
|
||||
if(!isLinkValid(prop))
|
||||
if(!isLinkValid(prop)) {
|
||||
//Base::Console().Message("Invalid link: %s\n", prop->getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -386,16 +391,16 @@ bool GeoFeatureGroupExtension::isLinkValid(App::Property* prop) {
|
||||
|
||||
//no cross CS link for local links.
|
||||
auto result = getScopedObjectsFromLink(prop, LinkScope::Local);
|
||||
auto group = obj->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId()) ? obj : getGroupOfObject(obj);
|
||||
auto group = getGroupOfObject(obj);
|
||||
for(auto link : result) {
|
||||
if(getGroupOfObject(link) != group)
|
||||
return false;
|
||||
}
|
||||
|
||||
//for links with scope SubGroup we need to check if all features are part of subgroups
|
||||
if(group) {
|
||||
if(obj->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) {
|
||||
result = getScopedObjectsFromLink(prop, LinkScope::Child);
|
||||
auto groupExt = group->getExtensionByType<App::GeoFeatureGroupExtension>();
|
||||
auto groupExt = obj->getExtensionByType<App::GeoFeatureGroupExtension>();
|
||||
for(auto link : result) {
|
||||
if(!groupExt->hasObject(link, true))
|
||||
return false;
|
||||
|
||||
@@ -104,6 +104,12 @@ std::vector< DocumentObject* > GroupExtension::addObjects(std::vector< DocumentO
|
||||
return added;
|
||||
}
|
||||
|
||||
std::vector< DocumentObject* > GroupExtension::setObjects(std::vector< DocumentObject* > obj) {
|
||||
|
||||
Group.setValues(std::vector< DocumentObject* > ());
|
||||
return addObjects(obj);
|
||||
}
|
||||
|
||||
std::vector<DocumentObject*> GroupExtension::removeObject(DocumentObject* obj)
|
||||
{
|
||||
std::vector<DocumentObject*> vec = {obj};
|
||||
|
||||
@@ -56,6 +56,11 @@ public:
|
||||
/* Adds the objects \a objs to this group. Returns all objects that have been added.
|
||||
*/
|
||||
virtual std::vector<DocumentObject*> addObjects(std::vector<DocumentObject*> obj);
|
||||
|
||||
/* Sets the objects in this group. Everything contained already will be removed first
|
||||
*/
|
||||
virtual std::vector< DocumentObject* > setObjects(std::vector< DocumentObject* > obj);
|
||||
|
||||
/*override this function if you want only special objects
|
||||
*/
|
||||
virtual bool allowObject(DocumentObject* ) {return true;}
|
||||
|
||||
@@ -20,22 +20,27 @@
|
||||
</Methode>
|
||||
<Methode Name="addObject">
|
||||
<Documentation>
|
||||
<UserDocu>Add an object to the group</UserDocu>
|
||||
<UserDocu>Add an object to the group. Returns all objects that have been added.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="addObjects">
|
||||
<Documentation>
|
||||
<UserDocu>Adds multiple objects to the group. Expects a list.</UserDocu>
|
||||
<UserDocu>Adds multiple objects to the group. Expects a list and returns all objects that have been added.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="setObjects">
|
||||
<Documentation>
|
||||
<UserDocu>Sets the objects of the group. Expects a list and returns all objects that are now in the group.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="removeObject">
|
||||
<Documentation>
|
||||
<UserDocu>Remove an object from the group</UserDocu>
|
||||
<UserDocu>Remove an object from the group and returns all objects that have been removed.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="removeObjects">
|
||||
<Documentation>
|
||||
<UserDocu>Remove multiple objects from the group. Expects a list.</UserDocu>
|
||||
<UserDocu>Remove multiple objects from the group. Expects a list and returns all objects that have been removed.</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="removeObjectsFromDocument">
|
||||
|
||||
@@ -131,6 +131,44 @@ PyObject* GroupExtensionPy::addObjects(PyObject *args) {
|
||||
throw Base::TypeError(error);
|
||||
};
|
||||
|
||||
|
||||
PyObject* GroupExtensionPy::setObjects(PyObject *args) {
|
||||
|
||||
PyObject *object;
|
||||
if (!PyArg_ParseTuple(args, "O", &object)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
|
||||
if (PyTuple_Check(object) || PyList_Check(object)) {
|
||||
Py::Sequence list(object);
|
||||
Py::Sequence::size_type size = list.size();
|
||||
std::vector<DocumentObject*> values;
|
||||
values.resize(size);
|
||||
|
||||
for (Py::Sequence::size_type i = 0; i < size; i++) {
|
||||
Py::Object item = list[i];
|
||||
if (!PyObject_TypeCheck(*item, &(DocumentObjectPy::Type))) {
|
||||
std::string error = std::string("type in list must be 'DocumentObject', not ");
|
||||
error += (*item)->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
}
|
||||
|
||||
values[i] = static_cast<DocumentObjectPy*>(*item)->getDocumentObjectPtr();
|
||||
}
|
||||
|
||||
GroupExtension* grp = getGroupExtensionPtr();
|
||||
auto vec = grp->setObjects(values);
|
||||
Py::List result;
|
||||
for (App::DocumentObject* obj : vec)
|
||||
result.append(Py::asObject(obj->getPyObject()));
|
||||
|
||||
return Py::new_reference_to(result);
|
||||
}
|
||||
|
||||
std::string error = std::string("type must be list of 'DocumentObject', not ");
|
||||
error += object->ob_type->tp_name;
|
||||
throw Base::TypeError(error);
|
||||
};
|
||||
|
||||
PyObject* GroupExtensionPy::removeObject(PyObject *args)
|
||||
{
|
||||
PyObject *object;
|
||||
|
||||
@@ -42,6 +42,7 @@ OriginGroupExtension::OriginGroupExtension () {
|
||||
initExtensionType(OriginGroupExtension::getExtensionClassTypeId());
|
||||
|
||||
EXTENSION_ADD_PROPERTY_TYPE ( Origin, (0), 0, App::Prop_Hidden, "Origin linked to the group" );
|
||||
Origin.setScope(LinkScope::Global);
|
||||
}
|
||||
|
||||
OriginGroupExtension::~OriginGroupExtension ()
|
||||
|
||||
Reference in New Issue
Block a user