Extensions: Handle new dynamic_cast's
This commit is contained in:
@@ -1894,14 +1894,15 @@ DocumentObject * Document::addObject(const char* sType, const char* pObjectName,
|
||||
string ObjectName;
|
||||
if (!base)
|
||||
return 0;
|
||||
if (!base->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||
|
||||
App::DocumentObject* pcObject = dynamic_cast<App::DocumentObject*>(base);
|
||||
if (!pcObject) {
|
||||
delete base;
|
||||
std::stringstream str;
|
||||
str << "'" << sType << "' is not a document object type";
|
||||
throw Base::TypeError(str.str());
|
||||
}
|
||||
|
||||
App::DocumentObject* pcObject = dynamic_cast<App::DocumentObject*>(base);
|
||||
pcObject->setDocument(this);
|
||||
|
||||
// do no transactions if we do a rollback!
|
||||
|
||||
@@ -259,5 +259,26 @@ protected: // attributes
|
||||
|
||||
} //namespace App
|
||||
|
||||
/**
|
||||
* Overload of freecads base class cast for all cases without any virtual inheritance
|
||||
*/
|
||||
template<typename T> T * freecad_dynamic_cast(App::DocumentObject * t)
|
||||
{
|
||||
if (t && t->isDerivedFrom(T::getClassTypeId()))
|
||||
return static_cast<T*>(t);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* See explaination above
|
||||
*/
|
||||
template<typename T> const T * freecad_dynamic_cast(const App::DocumentObject * t)
|
||||
{
|
||||
if (t && t->isDerivedFrom(T::getClassTypeId()))
|
||||
return static_cast<const T*>(t);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#endif // APP_DOCUMENTOBJECT_H
|
||||
|
||||
@@ -149,7 +149,7 @@ PyObject* ExtensionContainerPy::addExtension(PyObject *args) {
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
|
||||
}
|
||||
|
||||
ext->initExtension(dynamic_cast<App::DocumentObject*>(getExtensionContainerPtr()));
|
||||
ext->initExtension(getExtensionContainerPtr());
|
||||
|
||||
//set the proxy to allow python overrides
|
||||
App::Property* pp = ext->getPropertyByName("Proxy");
|
||||
|
||||
@@ -70,13 +70,15 @@ App::DocumentObject *OriginGroupExtension::getGroupOfObject (const DocumentObjec
|
||||
std::vector<DocumentObject*> grps = doc->getObjectsWithExtension ( OriginGroupExtension::getClassTypeId() );
|
||||
for (auto grpObj: grps) {
|
||||
OriginGroupExtension* grp = dynamic_cast <OriginGroupExtension* >(grpObj->getExtension(OriginGroupExtension::getClassTypeId()));
|
||||
if(!grp) throw Base::TypeError("Wrong type in origin group extenion");
|
||||
|
||||
if ( indirect ) {
|
||||
if ( grp->geoHasObject (obj) ) {
|
||||
return dynamic_cast<App::DocumentObject*>(grp);
|
||||
return grp->getExtendedObject();
|
||||
}
|
||||
} else {
|
||||
if ( grp->hasObject (obj) ) {
|
||||
return dynamic_cast<App::DocumentObject*>(grp);
|
||||
return grp->getExtendedObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ void PropertyLink::Restore(Base::XMLReader &reader)
|
||||
|
||||
if (name != "") {
|
||||
DocumentObject* parent = dynamic_cast<DocumentObject*>(getContainer());
|
||||
if(!parent) throw Base::TypeError("Property container is not document object");
|
||||
App::Document* document = parent->getDocument();
|
||||
DocumentObject* object = document ? document->getObject(name.c_str()) : 0;
|
||||
if (!object) {
|
||||
@@ -289,6 +290,7 @@ void PropertyLinkList::Restore(Base::XMLReader &reader)
|
||||
// document. Thus, we should silently ingore this.
|
||||
// Property not in an object!
|
||||
DocumentObject* father = dynamic_cast<DocumentObject*>(getContainer());
|
||||
if(!father) throw Base::TypeError("Property container is not document object");
|
||||
App::Document* document = father->getDocument();
|
||||
DocumentObject* child = document ? document->getObject(name.c_str()) : 0;
|
||||
if (child)
|
||||
@@ -479,7 +481,10 @@ void PropertyLinkSub::Restore(Base::XMLReader &reader)
|
||||
|
||||
DocumentObject *pcObject;
|
||||
if (!name.empty()) {
|
||||
App::Document* document = dynamic_cast<DocumentObject*>(getContainer())->getDocument();
|
||||
|
||||
auto* parent = dynamic_cast<DocumentObject*>(getContainer());
|
||||
if(!parent) throw Base::TypeError("Property container is not document object");
|
||||
App::Document* document = parent->getDocument();
|
||||
pcObject = document ? document->getObject(name.c_str()) : 0;
|
||||
if (!pcObject) {
|
||||
if (reader.isVerbose()) {
|
||||
@@ -807,7 +812,6 @@ void PropertyLinkSubList::Restore(Base::XMLReader &reader)
|
||||
reader.readElement("LinkSubList");
|
||||
// get the value of my attribute
|
||||
int count = reader.getAttributeAsInteger("count");
|
||||
assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId()) );
|
||||
|
||||
std::vector<DocumentObject*> values;
|
||||
values.reserve(count);
|
||||
@@ -821,6 +825,7 @@ void PropertyLinkSubList::Restore(Base::XMLReader &reader)
|
||||
// document. Thus, we should silently ignore this.
|
||||
// Property not in an object!
|
||||
DocumentObject* father = dynamic_cast<DocumentObject*>(getContainer());
|
||||
if(!father) throw Base::TypeError("Property container is not document object");
|
||||
App::Document* document = father->getDocument();
|
||||
DocumentObject* child = document ? document->getObject(name.c_str()) : 0;
|
||||
if (child)
|
||||
|
||||
Reference in New Issue
Block a user