Mod: Use new addObject<T>(...) using regex

This commit is contained in:
Benjamin Nauck
2025-01-19 01:49:04 +01:00
parent 6d28a19a3e
commit 265b58c034
57 changed files with 125 additions and 159 deletions

View File

@@ -250,7 +250,7 @@ void ImportOCAF::loadShapes(const TDF_Label& label,
if (!localValue.empty()) {
if (aShapeTool->IsAssembly(label)) {
App::Part* pcPart = nullptr;
pcPart = static_cast<App::Part*>(doc->addObject("App::Part", asm_name.c_str()));
pcPart = doc->addObject<App::Part>(asm_name.c_str());
pcPart->Label.setValue(asm_name);
pcPart->addObjects(localValue);
@@ -326,7 +326,7 @@ void ImportOCAF::createShape(const TDF_Label& label,
// Ok we got a Compound which is computed
// Just need to add it to a Part::Feature and push it to lValue
if (!comp.IsNull() && (ctSolids || ctShells || ctEdges || ctVertices)) {
Part::Feature* part = static_cast<Part::Feature*>(doc->addObject("Part::Feature"));
Part::Feature* part = doc->addObject<Part::Feature>();
// Let's allocate the relative placement of the Compound from the STEP file
tryPlacementFromLoc(part, loc);
if (!loc.IsIdentity()) {
@@ -352,7 +352,7 @@ void ImportOCAF::createShape(const TDF_Label& label,
}
if (!localValue.empty() && !mergeShape) {
pcPart = static_cast<App::Part*>(doc->addObject("App::Part", name.c_str()));
pcPart = doc->addObject<App::Part>(name.c_str());
pcPart->Label.setValue(name);
// localValue contain the objects that must added to the local Part
@@ -376,7 +376,7 @@ void ImportOCAF::createShape(const TopoDS_Shape& aShape,
const std::string& name,
std::vector<App::DocumentObject*>& lvalue)
{
Part::Feature* part = static_cast<Part::Feature*>(doc->addObject("Part::Feature"));
Part::Feature* part = doc->addObject<Part::Feature>();
if (!loc.IsIdentity()) {
part->Shape.setValue(aShape.Moved(loc));
@@ -497,7 +497,7 @@ void ImportXCAF::loadShapes()
void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setname) const
{
Part::Feature* part;
part = static_cast<Part::Feature*>(doc->addObject("Part::Feature", default_name.c_str()));
part = doc->addObject<Part::Feature>(default_name.c_str());
part->Label.setValue(default_name);
part->Shape.setValue(shape);
std::map<Standard_Integer, Quantity_ColorRGBA>::const_iterator jt;

View File

@@ -269,8 +269,7 @@ ImportOCAF2::expandShape(App::Document* doc, TDF_Label label, const TopoDS_Shape
if (objs.empty()) {
return nullptr;
}
auto compound =
static_cast<Part::Compound2*>(doc->addObject("Part::Compound2", "Compound"));
auto compound = doc->addObject<Part::Compound2>("Compound");
compound->Links.setValues(objs);
setPlacement(&compound->Placement, shape);
return compound;
@@ -382,8 +381,7 @@ bool ImportOCAF2::createObject(App::Document* doc,
assert(feature);
}
else {
feature = static_cast<Part::Feature*>(
doc->addObject("Part::Feature", tshape.shapeName().c_str()));
feature = doc->addObject<Part::Feature>(tshape.shapeName().c_str());
feature->Shape.setValue(shape);
}
applyFaceColors(feature, {info.faceColor});
@@ -479,10 +477,10 @@ bool ImportOCAF2::createGroup(App::Document* doc,
myCollapsedObjects.emplace(info.obj, info.propPlacement);
return true;
}
auto group = static_cast<App::LinkGroup*>(doc->addObject("App::LinkGroup", "LinkGroup"));
auto group = doc->addObject<App::LinkGroup>("LinkGroup");
for (auto& child : children) {
if (child->getDocument() != doc) {
auto link = static_cast<App::Link*>(doc->addObject("App::Link", "Link"));
auto link = doc->addObject<App::Link>("Link");
link->Label.setValue(child->Label.getValue());
link->setLink(-1, child);
auto pla = Base::freecad_dynamic_cast<App::PropertyPlacement>(
@@ -566,8 +564,7 @@ App::DocumentObject* ImportOCAF2::loadShapes()
}
if (options.merge && ret && !ret->isDerivedFrom<Part::Feature>()) {
auto shape = Part::Feature::getTopoShape(ret);
auto feature =
static_cast<Part::Feature*>(pDocument->addObject("Part::Feature", "Feature"));
auto feature = pDocument->addObject<Part::Feature>("Feature");
auto name = Tools::labelName(pDoc->Main());
feature->Label.setValue(name.empty() ? default_name.c_str() : name.c_str());
feature->Shape.setValue(shape);
@@ -701,8 +698,7 @@ App::DocumentObject* ImportOCAF2::loadShape(App::Document* doc,
auto name = getLabelName(label);
if (info.faceColor != it->second.faceColor || info.edgeColor != it->second.edgeColor
|| (!name.empty() && !info.baseName.empty() && name != info.baseName)) {
auto compound =
static_cast<Part::Compound2*>(doc->addObject("Part::Compound2", "Compound"));
auto compound = doc->addObject<Part::Compound2>("Compound");
compound->Links.setValue(info.obj);
info.propPlacement = &compound->Placement;
if (info.faceColor != it->second.faceColor) {
@@ -719,7 +715,7 @@ App::DocumentObject* ImportOCAF2::loadShape(App::Document* doc,
return info.obj;
}
auto link = static_cast<App::Link*>(doc->addObject("App::Link", "Link"));
auto link = doc->addObject<App::Link>("Link");
link->setLink(-1, info.obj);
setPlacement(&link->Placement, shape);
info.obj = link;
@@ -826,7 +822,7 @@ bool ImportOCAF2::createAssembly(App::Document* _doc,
visibilities[i] = true;
// Okay, we are creating a link array
auto link = static_cast<App::Link*>(doc->addObject("App::Link", "Link"));
auto link = doc->addObject<App::Link>("Link");
link->setLink(-1, child);
link->ShowElement.setValue(false);
link->ElementCount.setValue(childInfo.plas.size());

View File

@@ -241,7 +241,7 @@ void ImportOCAFAssembly::createShape(const TopoDS_Shape& aShape,
const TopLoc_Location& loc,
const std::string& name)
{
Part::Feature* part = static_cast<Part::Feature*>(doc->addObject("Part::Feature"));
Part::Feature* part = doc->addObject<Part::Feature>();
if (!loc.IsIdentity()) {
part->Shape.setValue(aShape.Moved(loc));
}

View File

@@ -736,8 +736,7 @@ std::string ImpExpDxfRead::Deformat(const char* text)
void ImpExpDxfRead::DrawingEntityCollector::AddObject(const TopoDS_Shape& shape,
const char* nameBase)
{
auto pcFeature =
dynamic_cast<Part::Feature*>(Reader.document->addObject("Part::Feature", nameBase));
auto pcFeature = Reader.document->addObject<Part::Feature>(nameBase);
pcFeature->Shape.setValue(shape);
Reader.MoveToLayer(pcFeature);
Reader.ApplyGuiStyles(pcFeature);