Allow geometry from other bodies in the same par as external geometry for sketches

This commit is contained in:
jrheinlaender 2013-07-03 11:51:27 +02:00 committed by Stefan Tröger
parent f26ca75e50
commit 9e7b463113
4 changed files with 14 additions and 8 deletions

View File

@ -83,6 +83,8 @@ SketchObject::SketchObject()
ADD_PROPERTY_TYPE(Constraints, (0) ,"Sketch",(App::PropertyType)(App::Prop_None),"Sketch constraints");
ADD_PROPERTY_TYPE(ExternalGeometry,(0,0),"Sketch",(App::PropertyType)(App::Prop_None),"Sketch external geometry");
allowOtherBody = true;
for (std::vector<Part::Geometry *>::iterator it=ExternalGeo.begin(); it != ExternalGeo.end(); ++it)
if (*it) delete *it;
ExternalGeo.clear();
@ -2713,7 +2715,7 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId)
int SketchObject::addExternal(App::DocumentObject *Obj, const char* SubName)
{
// so far only externals to the support of the sketch and datum features
if (Support.getValue() != Obj)
if (!allowOtherBody && (Support.getValue() != Obj))
if (!Obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) &&
!Obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId()))
return -1;

View File

@ -259,6 +259,9 @@ public:
/// gets the solved sketch as a reference
inline Sketch &getSolvedSketch(void) {return solvedSketch;}
// Flag to allow external geometry from other bodies than the one this sketch belongs to
bool allowOtherBody;
protected:
/// get called by the container when a property has changed
virtual void onChanged(const App::Property* /*prop*/);

View File

@ -376,10 +376,11 @@ PyObject* SketchObjectPy::addExternal(PyObject *args)
return 0;
// get the target object for the external link
App::DocumentObject * Obj = this->getSketchObjectPtr()->getDocument()->getObject(ObjectName);
Sketcher::SketchObject* skObj = this->getSketchObjectPtr();
App::DocumentObject * Obj = skObj->getDocument()->getObject(ObjectName);
if (!Obj) {
std::stringstream str;
str << ObjectName << "does not exist in the document";
str << ObjectName << " does not exist in the document";
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return 0;
}
@ -388,21 +389,21 @@ PyObject* SketchObjectPy::addExternal(PyObject *args)
if (Obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) {
// OK
} else if (Obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (this->getSketchObjectPtr()->Support.getValue() != Obj) {
if (!skObj->allowOtherBody && (skObj->Support.getValue() != Obj)) {
std::stringstream str;
str << ObjectName << "is not supported by this sketch";
str << ObjectName << " is not supported by this sketch";
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return 0;
}
} else if (!Obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
std::stringstream str;
str << ObjectName << "must be a Part feature or a datum feature";
str << ObjectName << " must be a Part feature or a datum feature";
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return 0;
}
// add the external
if (this->getSketchObjectPtr()->addExternal(Obj,SubName) < 0) {
if (skObj->addExternal(Obj,SubName) < 0) {
std::stringstream str;
str << "Not able to add external shape element";
PyErr_SetString(PyExc_ValueError, str.str().c_str());

View File

@ -4481,7 +4481,7 @@ namespace SketcherGui {
pObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId()))
return true;
if (pObj != support)
if (!sketch->allowOtherBody && (pObj != support))
return false;
if (!sSubName || sSubName[0] == '\0')
return false;