Extensions: Handle static/dynamic cast
After the change of the virtual inheritance position in the inheritance chain some formally added dynamic_cast's can be reverted to the old behaviour
This commit is contained in:
parent
b101b11c67
commit
15b14783d1
|
@ -259,26 +259,4 @@ protected: // attributes
|
||||||
|
|
||||||
} //namespace App
|
} //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
|
#endif // APP_DOCUMENTOBJECT_H
|
||||||
|
|
|
@ -270,7 +270,29 @@ template<> void _class_::init(void){\
|
||||||
_class_::propertyData.addParentPropertyData(_parentclass_::getPropertyDataPtr());\
|
_class_::propertyData.addParentPropertyData(_parentclass_::getPropertyDataPtr());\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace App
|
} // namespace App
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overload of freecads base class cast for all cases without any virtual inheritance
|
||||||
|
*/
|
||||||
|
template<typename T> T * freecad_dynamic_cast(App::PropertyContainer* 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::PropertyContainer* t)
|
||||||
|
{
|
||||||
|
if (t && t->isDerivedFrom(T::getClassTypeId()))
|
||||||
|
return static_cast<const T*>(t);
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // APP_PROPERTYCONTAINER_H
|
#endif // APP_PROPERTYCONTAINER_H
|
||||||
|
|
|
@ -130,8 +130,7 @@ void PropertyLink::Restore(Base::XMLReader &reader)
|
||||||
assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId()) );
|
assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId()) );
|
||||||
|
|
||||||
if (name != "") {
|
if (name != "") {
|
||||||
DocumentObject* parent = dynamic_cast<DocumentObject*>(getContainer());
|
DocumentObject* parent = static_cast<DocumentObject*>(getContainer());
|
||||||
if(!parent) throw Base::TypeError("Property container is not document object");
|
|
||||||
App::Document* document = parent->getDocument();
|
App::Document* document = parent->getDocument();
|
||||||
DocumentObject* object = document ? document->getObject(name.c_str()) : 0;
|
DocumentObject* object = document ? document->getObject(name.c_str()) : 0;
|
||||||
if (!object) {
|
if (!object) {
|
||||||
|
@ -289,8 +288,7 @@ void PropertyLinkList::Restore(Base::XMLReader &reader)
|
||||||
// referenced objects in XML which do not exist anymore in the new
|
// referenced objects in XML which do not exist anymore in the new
|
||||||
// document. Thus, we should silently ingore this.
|
// document. Thus, we should silently ingore this.
|
||||||
// Property not in an object!
|
// Property not in an object!
|
||||||
DocumentObject* father = dynamic_cast<DocumentObject*>(getContainer());
|
DocumentObject* father = static_cast<DocumentObject*>(getContainer());
|
||||||
if(!father) throw Base::TypeError("Property container is not document object");
|
|
||||||
App::Document* document = father->getDocument();
|
App::Document* document = father->getDocument();
|
||||||
DocumentObject* child = document ? document->getObject(name.c_str()) : 0;
|
DocumentObject* child = document ? document->getObject(name.c_str()) : 0;
|
||||||
if (child)
|
if (child)
|
||||||
|
@ -482,8 +480,7 @@ void PropertyLinkSub::Restore(Base::XMLReader &reader)
|
||||||
DocumentObject *pcObject;
|
DocumentObject *pcObject;
|
||||||
if (!name.empty()) {
|
if (!name.empty()) {
|
||||||
|
|
||||||
auto* parent = dynamic_cast<DocumentObject*>(getContainer());
|
auto* parent = static_cast<DocumentObject*>(getContainer());
|
||||||
if(!parent) throw Base::TypeError("Property container is not document object");
|
|
||||||
App::Document* document = parent->getDocument();
|
App::Document* document = parent->getDocument();
|
||||||
pcObject = document ? document->getObject(name.c_str()) : 0;
|
pcObject = document ? document->getObject(name.c_str()) : 0;
|
||||||
if (!pcObject) {
|
if (!pcObject) {
|
||||||
|
@ -824,8 +821,7 @@ void PropertyLinkSubList::Restore(Base::XMLReader &reader)
|
||||||
// referenced objects in XML which do not exist anymore in the new
|
// referenced objects in XML which do not exist anymore in the new
|
||||||
// document. Thus, we should silently ignore this.
|
// document. Thus, we should silently ignore this.
|
||||||
// Property not in an object!
|
// Property not in an object!
|
||||||
DocumentObject* father = dynamic_cast<DocumentObject*>(getContainer());
|
DocumentObject* father = static_cast<DocumentObject*>(getContainer());
|
||||||
if(!father) throw Base::TypeError("Property container is not document object");
|
|
||||||
App::Document* document = father->getDocument();
|
App::Document* document = father->getDocument();
|
||||||
DocumentObject* child = document ? document->getObject(name.c_str()) : 0;
|
DocumentObject* child = document ? document->getObject(name.c_str()) : 0;
|
||||||
if (child)
|
if (child)
|
||||||
|
|
|
@ -288,8 +288,8 @@ QString PropertyItem::pythonIdentifier(const App::Property* prop) const
|
||||||
QString propName = QString::fromLatin1(parent->getPropertyName(prop));
|
QString propName = QString::fromLatin1(parent->getPropertyName(prop));
|
||||||
return QString::fromLatin1("FreeCAD.getDocument(\"%1\").%2").arg(docName).arg(propName);
|
return QString::fromLatin1("FreeCAD.getDocument(\"%1\").%2").arg(docName).arg(propName);
|
||||||
}
|
}
|
||||||
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(parent);
|
if (parent->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||||
if (obj) {
|
App::DocumentObject* obj = static_cast<App::DocumentObject*>(parent);
|
||||||
App::Document* doc = obj->getDocument();
|
App::Document* doc = obj->getDocument();
|
||||||
QString docName = QString::fromLatin1(App::GetApplication().getDocumentName(doc));
|
QString docName = QString::fromLatin1(App::GetApplication().getDocumentName(doc));
|
||||||
QString objName = QString::fromLatin1(obj->getNameInDocument());
|
QString objName = QString::fromLatin1(obj->getNameInDocument());
|
||||||
|
@ -3375,9 +3375,10 @@ QVariant PropertyLinkItem::value(const App::Property* prop) const
|
||||||
else {
|
else {
|
||||||
// no object assigned
|
// no object assigned
|
||||||
// the document name
|
// the document name
|
||||||
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(c);
|
if (c->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||||
if (obj)
|
App::DocumentObject* obj = static_cast<App::DocumentObject*>(c);
|
||||||
list << QString::fromLatin1(obj->getDocument()->getName());
|
list << QString::fromLatin1(obj->getDocument()->getName());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
list << QString::fromLatin1("");
|
list << QString::fromLatin1("");
|
||||||
|
|
||||||
|
@ -3388,9 +3389,10 @@ QVariant PropertyLinkItem::value(const App::Property* prop) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// the name of this object
|
// the name of this object
|
||||||
App::DocumentObject* cobj = dynamic_cast<App::DocumentObject*>(c);
|
if (c->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||||
if (cobj)
|
App::DocumentObject* obj = static_cast<App::DocumentObject*>(c);
|
||||||
list << QString::fromLatin1(cobj->getNameInDocument());
|
list << QString::fromLatin1(obj->getNameInDocument());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
list << QString::fromLatin1("Null");
|
list << QString::fromLatin1("Null");
|
||||||
|
|
||||||
|
|
|
@ -263,11 +263,10 @@ void PropertyPostDataObject::SaveDocFile (Base::Writer &writer) const
|
||||||
// We only print an error message but continue writing the next files to the
|
// We only print an error message but continue writing the next files to the
|
||||||
// stream...
|
// stream...
|
||||||
App::PropertyContainer* father = this->getContainer();
|
App::PropertyContainer* father = this->getContainer();
|
||||||
if (father) {
|
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||||
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
|
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
|
||||||
if(obj)
|
Base::Console().Error("Dataset of '%s' cannot be written to vtk file '%s'\n",
|
||||||
Base::Console().Error("Dataset of '%s' cannot be written to vtk file '%s'\n",
|
obj->Label.getValue(),fi.filePath().c_str());
|
||||||
obj->Label.getValue(),fi.filePath().c_str());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Base::Console().Error("Cannot save vtk file '%s'\n", fi.filePath().c_str());
|
Base::Console().Error("Cannot save vtk file '%s'\n", fi.filePath().c_str());
|
||||||
|
@ -332,11 +331,10 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader)
|
||||||
// We only print an error message but continue reading the next files from the
|
// We only print an error message but continue reading the next files from the
|
||||||
// stream...
|
// stream...
|
||||||
App::PropertyContainer* father = this->getContainer();
|
App::PropertyContainer* father = this->getContainer();
|
||||||
if (father) {
|
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||||
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
|
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
|
||||||
if(obj)
|
Base::Console().Error("Dataset file '%s' with data of '%s' seems to be empty\n",
|
||||||
Base::Console().Error("Dataset file '%s' with data of '%s' seems to be empty\n",
|
fi.filePath().c_str(),obj->Label.getValue());
|
||||||
fi.filePath().c_str(),obj->Label.getValue());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Base::Console().Warning("Loaded Dataset file '%s' seems to be empty\n", fi.filePath().c_str());
|
Base::Console().Warning("Loaded Dataset file '%s' seems to be empty\n", fi.filePath().c_str());
|
||||||
|
|
|
@ -296,11 +296,10 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const
|
||||||
// We only print an error message but continue writing the next files to the
|
// We only print an error message but continue writing the next files to the
|
||||||
// stream...
|
// stream...
|
||||||
App::PropertyContainer* father = this->getContainer();
|
App::PropertyContainer* father = this->getContainer();
|
||||||
if (father) {
|
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||||
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
|
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
|
||||||
if(obj)
|
Base::Console().Error("Shape of '%s' cannot be written to BRep file '%s'\n",
|
||||||
Base::Console().Error("Shape of '%s' cannot be written to BRep file '%s'\n",
|
obj->Label.getValue(),fi.filePath().c_str());
|
||||||
obj->Label.getValue(),fi.filePath().c_str());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Base::Console().Error("Cannot save BRep file '%s'\n", fi.filePath().c_str());
|
Base::Console().Error("Cannot save BRep file '%s'\n", fi.filePath().c_str());
|
||||||
|
@ -376,11 +375,10 @@ void PropertyPartShape::RestoreDocFile(Base::Reader &reader)
|
||||||
// We only print an error message but continue reading the next files from the
|
// We only print an error message but continue reading the next files from the
|
||||||
// stream...
|
// stream...
|
||||||
App::PropertyContainer* father = this->getContainer();
|
App::PropertyContainer* father = this->getContainer();
|
||||||
if (father) {
|
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||||
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
|
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
|
||||||
if(obj)
|
Base::Console().Error("BRep file '%s' with shape of '%s' seems to be empty\n",
|
||||||
Base::Console().Error("BRep file '%s' with shape of '%s' seems to be empty\n",
|
fi.filePath().c_str(),obj->Label.getValue());
|
||||||
fi.filePath().c_str(),obj->Label.getValue());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Base::Console().Warning("Loaded BRep file '%s' seems to be empty\n", fi.filePath().c_str());
|
Base::Console().Warning("Loaded BRep file '%s' seems to be empty\n", fi.filePath().c_str());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user