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

@@ -37,7 +37,7 @@ namespace TechDraw
class TechDrawExport DrawComplexSection: public DrawViewSection
{
PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawComplexSection);
PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawComplexSection);
public:
DrawComplexSection();

View File

@@ -463,43 +463,39 @@ App::DocumentObject* DrawProjGroup::addProjection(const char* viewProjType)
if (checkViewProjType(viewProjType) && !hasProjection(viewProjType)) {
std::string FeatName = getDocument()->getUniqueObjectName("ProjItem");
auto docObj(getDocument()->addObject("TechDraw::DrawProjGroupItem",//add to Document
FeatName.c_str()));
view = dynamic_cast<TechDraw::DrawProjGroupItem*>(docObj);
if (!view && docObj) {
view = getDocument()->addObject<TechDraw::DrawProjGroupItem>(FeatName.c_str());
if (!view) {
//should never happen that we create a DPGI that isn't a DPGI!!
Base::Console().Error("PROBLEM - DPG::addProjection - created a non DPGI! %s / %s\n",
getNameInDocument(), viewProjType);
throw Base::TypeError("Error: new projection is not a DPGI!");
}
if (view) {//coverity CID 151722
// the label must be set before the view is added
view->Label.setValue(viewProjType);
// somewhere deep in DocumentObject, duplicate Labels have a numeric suffix applied,
// so we need to wait until that happens before building the translated label
view->translateLabel("DrawProjGroupItem", viewProjType, view->Label.getValue());
addView(view);//from DrawViewCollection
view->Source.setValues(Source.getValues());
view->XSource.setValues(XSource.getValues());
// the label must be set before the view is added
view->Label.setValue(viewProjType);
// somewhere deep in DocumentObject, duplicate Labels have a numeric suffix applied,
// so we need to wait until that happens before building the translated label
view->translateLabel("DrawProjGroupItem", viewProjType, view->Label.getValue());
addView(view);//from DrawViewCollection
view->Source.setValues(Source.getValues());
view->XSource.setValues(XSource.getValues());
// the Scale is already set by DrawView
view->Type.setValue(viewProjType);
if (strcmp(viewProjType, "Front") != 0) {//not Front!
vecs = getDirsFromFront(view);
view->Direction.setValue(vecs.first);
view->XDirection.setValue(vecs.second);
view->recomputeFeature();
}
else {//Front
Anchor.setValue(view);
Anchor.purgeTouched();
requestPaint();//make sure the group object is on the Gui page
view->LockPosition.setValue(
true);//lock "Front" position within DPG (note not Page!).
view->LockPosition.setStatus(App::Property::ReadOnly,
true);//Front should stay locked.
view->LockPosition.purgeTouched();
}
// the Scale is already set by DrawView
view->Type.setValue(viewProjType);
if (strcmp(viewProjType, "Front") != 0) {//not Front!
vecs = getDirsFromFront(view);
view->Direction.setValue(vecs.first);
view->XDirection.setValue(vecs.second);
view->recomputeFeature();
}
else {//Front
Anchor.setValue(view);
Anchor.purgeTouched();
requestPaint();//make sure the group object is on the Gui page
view->LockPosition.setValue(
true);//lock "Front" position within DPG (note not Page!).
view->LockPosition.setStatus(App::Property::ReadOnly,
true);//Front should stay locked.
view->LockPosition.purgeTouched();
}
}
return view;

View File

@@ -49,7 +49,7 @@ namespace TechDraw
class TechDrawExport DrawViewDetail : public DrawViewPart
{
PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawViewDetail);
PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawViewDetail);
public:
/// Constructor

View File

@@ -51,7 +51,7 @@ namespace TechDraw
*/
class TechDrawExport DrawViewMulti : public DrawViewPart
{
PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawViewMulti);
PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawViewMulti);
public:
/// Constructor

View File

@@ -77,7 +77,7 @@ using ChangePointVector = std::vector<ChangePoint>;
class TechDrawExport DrawViewSection: public DrawViewPart
{
PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawViewSection);
PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawViewSection);
public:
DrawViewSection();

View File

@@ -124,15 +124,13 @@ void CmdTechDrawPageDefault::activated(int iMsg)
Gui::WaitCursor wc;
openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page"));
auto page = dynamic_cast<TechDraw::DrawPage *>
(getDocument()->addObject("TechDraw::DrawPage", "Page"));
auto page = getDocument()->addObject<TechDraw::DrawPage>("Page");
if (!page) {
throw Base::TypeError("CmdTechDrawPageDefault - page not created");
}
page->translateLabel("DrawPage", "Page", page->getNameInDocument());
auto svgTemplate = dynamic_cast<TechDraw::DrawSVGTemplate *>
(getDocument()->addObject("TechDraw::DrawSVGTemplate", "Template"));
auto svgTemplate = getDocument()->addObject<TechDraw::DrawSVGTemplate>("Template");
if (!svgTemplate) {
throw Base::TypeError("CmdTechDrawPageDefault - template not created");
}
@@ -195,15 +193,13 @@ void CmdTechDrawPageTemplate::activated(int iMsg)
Gui::WaitCursor wc;
openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page"));
auto page = dynamic_cast<TechDraw::DrawPage *>
(getDocument()->addObject("TechDraw::DrawPage", "Page"));
auto page = getDocument()->addObject<TechDraw::DrawPage>("Page");
if (!page) {
throw Base::TypeError("CmdTechDrawPageTemplate - page not created");
}
page->translateLabel("DrawPage", "Page", page->getNameInDocument());
auto svgTemplate = dynamic_cast<TechDraw::DrawSVGTemplate *>
(getDocument()->addObject("TechDraw::DrawSVGTemplate", "Template"));
auto svgTemplate = getDocument()->addObject<TechDraw::DrawSVGTemplate>("Template");
if (!svgTemplate) {
throw Base::TypeError("CmdTechDrawPageTemplate - template not created");
}

View File

@@ -397,8 +397,7 @@ bool TaskSurfaceFinishSymbols::accept()
{
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Surface Finish Symbols"));
App::Document *doc = Application::Instance->activeDocument()->getDocument();
App::DocumentObject *docObject = doc->addObject("TechDraw::DrawViewSymbol", "SurfaceSymbol");
TechDraw::DrawViewSymbol *surfaceSymbol = dynamic_cast<TechDraw::DrawViewSymbol*>(docObject);
auto* surfaceSymbol = doc->addObject<TechDraw::DrawViewSymbol>("SurfaceSymbol");
surfaceSymbol->Symbol.setValue(completeSymbol());
surfaceSymbol->Rotation.setValue(ui->leAngle->text().toDouble());

View File

@@ -457,7 +457,7 @@ TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol()
{
// Base::Console().Message("TWS::createWeldingSymbol()\n");
App::Document *doc = Application::Instance->activeDocument()->getDocument();
auto weldSymbol = dynamic_cast<TechDraw::DrawWeldSymbol*>(doc->addObject("TechDraw::DrawWeldSymbol", "WeldSymbol"));
auto weldSymbol = doc->addObject<TechDraw::DrawWeldSymbol>("WeldSymbol");
if (!weldSymbol) {
throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found");
}