Base: Rename Base::freecad_dynamic_cast into freecad_cast

This is to make it shorter and easier to use. QT does the same thing
with their qobject_cast.
This commit is contained in:
Kacper Donat
2025-03-28 23:15:04 +01:00
committed by Chris Hennes
parent 307a4661af
commit 35a9673a75
73 changed files with 302 additions and 315 deletions

View File

@@ -344,18 +344,16 @@ bool Sheet::exportToFile(const std::string& filename,
std::stringstream field;
using Base::freecad_dynamic_cast;
if (auto p = freecad_dynamic_cast<PropertyQuantity>(prop)) {
if (auto p = freecad_cast<PropertyQuantity>(prop)) {
field << p->getValue();
}
else if (auto p = freecad_dynamic_cast<PropertyFloat>(prop)) {
else if (auto p = freecad_cast<PropertyFloat>(prop)) {
field << p->getValue();
}
else if (auto p = freecad_dynamic_cast<PropertyInteger>(prop)) {
else if (auto p = freecad_cast<PropertyInteger>(prop)) {
field << p->getValue();
}
else if (auto p = freecad_dynamic_cast<PropertyString>(prop)) {
else if (auto p = freecad_cast<PropertyString>(prop)) {
field << p->getValue();
}
else {
@@ -595,7 +593,7 @@ Property* Sheet::setFloatProperty(CellAddress key, double value)
this->removeDynamicProperty(name.c_str());
propAddress.erase(prop);
}
floatProp = freecad_dynamic_cast<PropertyFloat>(
floatProp = freecad_cast<PropertyFloat>(
addDynamicProperty("App::PropertyFloat",
name.c_str(),
nullptr,
@@ -623,7 +621,7 @@ Property* Sheet::setIntegerProperty(CellAddress key, long value)
this->removeDynamicProperty(name.c_str());
propAddress.erase(prop);
}
intProp = freecad_dynamic_cast<PropertyInteger>(
intProp = freecad_cast<PropertyInteger>(
addDynamicProperty("App::PropertyInteger",
name.c_str(),
nullptr,
@@ -668,7 +666,7 @@ Property* Sheet::setQuantityProperty(CellAddress key, double value, const Base::
nullptr,
nullptr,
Prop_ReadOnly | Prop_Hidden | Prop_NoPersist);
quantityProp = freecad_dynamic_cast<PropertySpreadsheetQuantity>(p);
quantityProp = freecad_cast<PropertySpreadsheetQuantity>(p);
}
else {
quantityProp = static_cast<PropertySpreadsheetQuantity*>(prop);
@@ -697,14 +695,14 @@ Property* Sheet::setStringProperty(CellAddress key, const std::string& value)
{
std::string name = key.toString(CellAddress::Cell::ShowRowColumn);
Property* prop = props.getDynamicPropertyByName(name.c_str());
PropertyString* stringProp = freecad_dynamic_cast<PropertyString>(prop);
PropertyString* stringProp = freecad_cast<PropertyString>(prop);
if (!stringProp) {
if (prop) {
this->removeDynamicProperty(name.c_str());
propAddress.erase(prop);
}
stringProp = freecad_dynamic_cast<PropertyString>(
stringProp = freecad_cast<PropertyString>(
addDynamicProperty("App::PropertyString",
name.c_str(),
nullptr,
@@ -722,14 +720,14 @@ Property* Sheet::setObjectProperty(CellAddress key, Py::Object object)
{
std::string name = key.toString(CellAddress::Cell::ShowRowColumn);
Property* prop = props.getDynamicPropertyByName(name.c_str());
PropertyPythonObject* pyProp = freecad_dynamic_cast<PropertyPythonObject>(prop);
PropertyPythonObject* pyProp = freecad_cast<PropertyPythonObject>(prop);
if (!pyProp) {
if (prop) {
this->removeDynamicProperty(name.c_str());
propAddress.erase(prop);
}
pyProp = freecad_dynamic_cast<PropertyPythonObject>(
pyProp = freecad_cast<PropertyPythonObject>(
addDynamicProperty("App::PropertyPythonObject",
name.c_str(),
nullptr,
@@ -796,10 +794,10 @@ void Sheet::updateProperty(CellAddress key)
/* Eval returns either NumberExpression or StringExpression, or
* PyObjectExpression objects */
auto number = freecad_dynamic_cast<NumberExpression>(output.get());
auto number = freecad_cast<NumberExpression>(output.get());
if (number) {
long l;
auto constant = freecad_dynamic_cast<ConstantExpression>(output.get());
auto constant = freecad_cast<ConstantExpression>(output.get());
if (constant && !constant->isNumber()) {
Base::PyGILStateLocker lock;
setObjectProperty(key, constant->getPyValue());
@@ -815,13 +813,13 @@ void Sheet::updateProperty(CellAddress key)
}
}
else {
auto str_expr = freecad_dynamic_cast<StringExpression>(output.get());
auto str_expr = freecad_cast<StringExpression>(output.get());
if (str_expr) {
setStringProperty(key, str_expr->getText().c_str());
}
else {
Base::PyGILStateLocker lock;
auto py_expr = freecad_dynamic_cast<PyObjectExpression>(output.get());
auto py_expr = freecad_cast<PyObjectExpression>(output.get());
if (py_expr) {
setObjectProperty(key, py_expr->getPyValue());
}