Merge pull request #19142 from hyarion/refactor/add-template-addobject

Add new addObject<T>() function
This commit is contained in:
Chris Hennes
2025-02-11 09:42:47 -06:00
committed by GitHub
95 changed files with 335 additions and 340 deletions

View File

@@ -295,8 +295,7 @@ private:
pcFeature->purgeTouched();
}
else {
Points::Feature* pcFeature = static_cast<Points::Feature*>(
pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
auto* pcFeature = pcDoc->addObject<Points::Feature>(file.fileNamePure().c_str());
pcFeature->Points.setValue(reader->getPoints());
pcDoc->recomputeFeature(pcFeature);
pcFeature->purgeTouched();
@@ -413,9 +412,8 @@ private:
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument();
}
PointsPy* pPoints = static_cast<PointsPy*>(pcObj);
Points::Feature* pcFeature =
static_cast<Points::Feature*>(pcDoc->addObject("Points::Feature", name));
auto* pPoints = static_cast<PointsPy*>(pcObj);
auto* pcFeature = pcDoc->addObject<Points::Feature>(name);
// copy the data
pcFeature->Points.setValue(*(pPoints->getPointKernelPtr()));
return Py::asObject(pcFeature->getPyObject());

View File

@@ -386,8 +386,7 @@ void CmdPointsMerge::activated(int iMsg)
App::Document* doc = App::GetApplication().getActiveDocument();
doc->openTransaction("Merge point clouds");
Points::Feature* pts =
static_cast<Points::Feature*>(doc->addObject("Points::Feature", "Merged Points"));
Points::Feature* pts = doc->addObject<Points::Feature>("Merged Points");
Points::PointKernel* kernel = pts->Points.startEditing();
std::vector<App::DocumentObject*> docObj =
@@ -455,8 +454,7 @@ void CmdPointsStructure::activated(int iMsg)
for (auto it : docObj) {
std::string name = it->Label.getValue();
name += " (Structured)";
Points::Structured* output =
static_cast<Points::Structured*>(doc->addObject("Points::Structured", name.c_str()));
Points::Structured* output = doc->addObject<Points::Structured>(name.c_str());
output->Label.setValue(name);
// Already sorted, so just make a copy