[TD]apply translateLabel after all addObject calls

This commit is contained in:
wandererfan
2023-08-16 21:12:59 -04:00
committed by WandererFan
parent 6595ed01d1
commit 414e06d54d
17 changed files with 118 additions and 59 deletions

View File

@@ -82,7 +82,9 @@ void DrawDimHelper::makeExtentDim(DrawViewPart* dvp, std::vector<std::string> ed
std::string dimName = doc->getUniqueObjectName("DimExtent");
Base::Interpreter().runStringArg(
"App.activeDocument().addObject('TechDraw::DrawViewDimExtent', '%s')", dimName.c_str());
Base::Interpreter().runStringArg(
Base::Interpreter().runStringArg(
"App.activeDocument().%s.translateLabel('DrawViewDimExtent', 'DimExtent', '%s')",
dimName.c_str(), dimName.c_str()); Base::Interpreter().runStringArg(
"App.activeDocument().%s.Type = '%s'", dimName.c_str(), dimType.c_str());
Base::Interpreter().runStringArg(
"App.activeDocument().%s.DirExtent = %d", dimName.c_str(), dimNum);
@@ -135,7 +137,9 @@ void DrawDimHelper::makeExtentDim3d(DrawViewPart* dvp, ReferenceVector reference
std::string dimName = doc->getUniqueObjectName("DimExtent");
Base::Interpreter().runStringArg(
"App.activeDocument().addObject('TechDraw::DrawViewDimExtent', '%s')", dimName.c_str());
Base::Interpreter().runStringArg(
Base::Interpreter().runStringArg(
"App.activeDocument().%s.translateLabel('DrawViewDimExtent', 'DimExtent', '%s')",
dimName.c_str(), dimName.c_str()); Base::Interpreter().runStringArg(
"App.activeDocument().%s.Type = '%s'", dimName.c_str(), dimType.c_str());
Base::Interpreter().runStringArg(
"App.activeDocument().%s.DirExtent = %d", dimName.c_str(), dimNum);
@@ -426,11 +430,16 @@ DrawDimHelper::makeDistDim(DrawViewPart* dvp, std::string dimType,
if (extent) {
Base::Interpreter().runStringArg(
"App.activeDocument().addObject('TechDraw::DrawViewDimExtent', '%s')", dimName.c_str());
Base::Interpreter().runStringArg(
"App.activeDocument().%s.translateLabel('DrawViewDimExtent', 'DimExtent', '%s')",
dimName.c_str(), dimName.c_str());
}
else {
Base::Interpreter().runStringArg(
"App.activeDocument().addObject('TechDraw::DrawViewDimension', '%s')", dimName.c_str());
Base::Interpreter().runStringArg(
"App.activeDocument().%s.translateLabel('DrawViewDimimension', 'Dimension', '%s')",
dimName.c_str(), dimName.c_str());
}
Base::Interpreter().runStringArg(

View File

@@ -474,11 +474,11 @@ App::DocumentObject* DrawProjGroup::addProjection(const char* viewProjType)
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());
// std::vector<DocumentObject*> xLinks;
// XSource.getLinks(xLinks);
// view->XSource.setValues(xLinks);
view->XSource.setValues(XSource.getValues());
// the Scale is already set by DrawView

View File

@@ -54,7 +54,7 @@ using namespace TechDraw;
QT_TRANSLATE_NOOP("DrawView", "View");
QT_TRANSLATE_NOOP("DrawViewPart", "View");
QT_TRANSLATE_NOOP("DrawViewSection", "Section");
QT_TRANSLATE_NOOP("DrawComplexSection", "ComplexSection");
QT_TRANSLATE_NOOP("DrawComplexSection", "Section");
QT_TRANSLATE_NOOP("DrawViewDetail", "Detail");
QT_TRANSLATE_NOOP("DrawActiveView", "ActiveView");
QT_TRANSLATE_NOOP("DrawViewAnnotation", "Annotation");
@@ -619,15 +619,23 @@ void DrawView::showProgressMessage(std::string featureName, std::string text)
//! the unique name within the document (ex ActiveView001), and use it to update the Label property.
void DrawView::translateLabel(std::string context, std::string baseName, std::string uniqueName)
{
// Base::Console().Message("DV::getTranslatedLabel - context: %s baseName: %s uniqueName: %s\n",
// Base::Console().Message("DV::translateLabel - context: %s baseName: %s uniqueName: %s\n",
// context.c_str(), baseName.c_str(), uniqueName.c_str());
Label.setValue(translateArbitrary(context, baseName, uniqueName));
// Base::Console().Message("DV::translateLabel - new label: %s\n", Label.getValue());
}
//! static method that provides a translated std::string for objects that are not derived from DrawView
std::string DrawView::translateArbitrary(std::string context, std::string baseName, std::string uniqueName)
{
std::string suffix("");
if (uniqueName.length() > baseName.length()) {
suffix = uniqueName.substr(baseName.length(), uniqueName.length() - baseName.length());
}
QString qTranslated = qApp->translate(context.c_str(), baseName.c_str());
std::string ssTranslated = Base::Tools::toStdString(qTranslated);
Label.setValue(ssTranslated + suffix);
return ssTranslated + suffix;
}
PyObject *DrawView::getPyObject(void)

View File

@@ -113,7 +113,9 @@ public:
void overrideKeepUpdated(bool s) { m_overrideKeepUpdated = s; }
bool overrideKeepUpdated(void) { return m_overrideKeepUpdated; }
void translateLabel(std::string context, std::string objectName, std::string uniqueName);
void translateLabel(std::string context, std::string baseName, std::string uniqueName);
static std::string translateArbitrary(std::string context, std::string baseName, std::string uniqueName);
protected:

View File

@@ -30,6 +30,7 @@
#include "DrawWeldSymbolPy.h" // generated from DrawWeldSymbolPy.xml
#include "DrawLeaderLine.h"
#include "DrawTileWeld.h"
#include "DrawView.h" // for translateArbitrary
using namespace TechDraw;
@@ -79,6 +80,7 @@ void DrawWeldSymbol::onSettingDocument()
auto tile1Obj( doc->addObject( "TechDraw::DrawTileWeld", tileName1.c_str() ) );
DrawTileWeld* tile1 = dynamic_cast<DrawTileWeld*>(tile1Obj);
if (tile1) {
tile1->Label.setValue(DrawView::translateArbitrary("DrawTileWeld", "TileWeld", tileName1));
tile1->TileParent.setValue(this);
}
@@ -86,6 +88,7 @@ void DrawWeldSymbol::onSettingDocument()
auto tile2Obj( doc->addObject( "TechDraw::DrawTileWeld", tileName2.c_str() ) );
DrawTileWeld* tile2 = dynamic_cast<DrawTileWeld*>(tile2Obj);
if (tile2) {
tile2->Label.setValue(DrawView::translateArbitrary("DrawTileWeld", "TileWeld", tileName2));
tile2->TileParent.setValue(this);
tile2->TileRow.setValue(-1); //other side is row -1
}

View File

@@ -384,6 +384,8 @@ void CmdTechDrawView::activated(int iMsg)
std::string FeatName = getUniqueObjectName("View");
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewPart', '%s')",
FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewPart', 'View', '%s')",
FeatName.c_str(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
FeatName.c_str());
@@ -1322,6 +1324,8 @@ void CmdTechDrawSymbol::activated(int iMsg)
doCommand(Doc, "f.close()");
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSymbol', '%s')",
FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewSymbol', 'Symbol', '%s')",
FeatName.c_str(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Symbol = svg", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
FeatName.c_str());
@@ -1380,6 +1384,8 @@ void CmdTechDrawDraftView::activated(int iMsg)
openCommand(QT_TRANSLATE_NOOP("Command", "Create DraftView"));
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewDraft', '%s')",
FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewDraft', 'DraftView', '%s')",
FeatName.c_str(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(),
SourceName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
@@ -1452,6 +1458,8 @@ void CmdTechDrawArchView::activated(int iMsg)
openCommand(QT_TRANSLATE_NOOP("Command", "Create ArchView"));
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewArch', '%s')",
FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewArch', 'ArchView', '%s')",
FeatName.c_str(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(),
SourceName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
@@ -1501,6 +1509,8 @@ void CmdTechDrawSpreadsheetView::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Sheet");
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet', '%s')",
FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewSpreadsheet', 'Sheet', '%s')",
FeatName.c_str(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(),
SpreadName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),

View File

@@ -545,6 +545,9 @@ void CmdTechDrawAnnotation::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Annotation");
openCommand(QT_TRANSLATE_NOOP("Command", "Create Annotation"));
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewAnnotation', '%s')", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewAnnotation', 'Annotation', '%s')",
FeatName.c_str(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
updateActive();
commitCommand();

View File

@@ -1306,6 +1306,9 @@ void CmdTechDrawLandmarkDimension::activated(int iMsg)
doCommand(Doc,
"App.activeDocument().addObject('TechDraw::LandmarkDimension', '%s')",
FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('LandmarkDimension', 'LandmarkDim', '%s')",
FeatName.c_str(), FeatName.c_str());
if (objects.size() == 2) {
//what about distanceX and distanceY??
doCommand(Doc, "App.activeDocument().%s.Type = '%s'", FeatName.c_str(), "Distance");
@@ -1386,6 +1389,9 @@ DrawViewDimension* dimensionMaker(TechDraw::DrawViewPart* dvp, std::string dimTy
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().addObject('TechDraw::DrawViewDimension', '%s')",
dimName.c_str());
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.translateLabel('DrawViewDimension', 'Dimension', '%s')",
dimName.c_str(), dimName.c_str());
Gui::Command::doCommand(
Gui::Command::Doc, "App.activeDocument().%s.Type = '%s'", dimName.c_str(), dimType.c_str());

View File

@@ -191,12 +191,16 @@ void CmdTechDrawGeometricHatch::activated(int iMsg)
std::string PageName = page->getNameInDocument();
std::string FeatName = getUniqueObjectName("GeomHatch");
std::stringstream featLabel;
featLabel << FeatName << "FX" << TechDraw::DrawUtil::getIndexFromName(subNames.at(0));
// TODO: the structured label for GeomHatch (and Hatch) should be retired.
// std::stringstream featLabel;
// featLabel << FeatName << "FX" << TechDraw::DrawUtil::getIndexFromName(subNames.at(0));
openCommand(QT_TRANSLATE_NOOP("Command", "Create GeomHatch"));
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawGeomHatch', '%s')", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Label = '%s'", FeatName.c_str(), featLabel.str().c_str());
// doCommand(Doc, "App.activeDocument().%s.Label = '%s'", FeatName.c_str(), featLabel.str().c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawGeomHatch', 'GeomHatch', '%s')",
FeatName.c_str(), FeatName.c_str());
auto geomhatch( static_cast<TechDraw::DrawGeomHatch *>(getDocument()->getObject(FeatName.c_str())) );
geomhatch->Source.setValue(objFeat, subNames);
@@ -264,6 +268,8 @@ void CmdTechDrawImage::activated(int iMsg)
fileName = Base::Tools::escapeEncodeFilename(fileName);
openCommand(QT_TRANSLATE_NOOP("Command", "Create Image"));
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewImage', '%s')", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewImage', 'Image', '%s')",
FeatName.c_str(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.ImageFile = '%s'", FeatName.c_str(), fileName.toUtf8().constData());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
updateActive();

View File

@@ -457,7 +457,7 @@ void QGIView::drawBorder()
m_font.setPixelSize(fontSize);
m_label->setFont(m_font);
QString labelStr = qApp->translate("DrawProjGroupItem", getViewObject()->Label.getValue());
QString labelStr = QString::fromStdString( getViewObject()->Label.getValue() );
m_label->setPlainText(labelStr);
QRectF labelArea = m_label->boundingRect(); //m_label coords
double labelWidth = m_label->boundingRect().width();

View File

@@ -529,6 +529,9 @@ void QGSPage::createBalloon(QPointF origin, DrawView* parent)
Command::doCommand(Command::Doc,
"App.activeDocument().addObject('TechDraw::DrawViewBalloon', '%s')",
featName.c_str());
Command::doCommand(Command::Doc, "App.activeDocument().%s.translateLabel('DrawViewBalloon', 'Balloon', '%s')",
featName.c_str(), featName.c_str());
TechDraw::DrawViewBalloon* balloon = dynamic_cast<TechDraw::DrawViewBalloon*>(
getDrawPage()->getDocument()->getObject(featName.c_str()));
if (!balloon) {
@@ -537,7 +540,6 @@ void QGSPage::createBalloon(QPointF origin, DrawView* parent)
Command::doCommand(Command::Doc,
"App.activeDocument().%s.SourceView = (App.activeDocument().%s)",
featName.c_str(), parent->getNameInDocument());
QGIView* qgParent = getQGIVByName(parent->getNameInDocument());
//convert from scene coords to qgParent coords and unscale
QPointF parentOrigin = qgParent->mapFromScene(origin) / parent->getScale();

View File

@@ -135,7 +135,8 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
}
//we are sure we have a 3D window!
const std::string objectName{QT_TR_NOOP("ActiveView")};
const std::string objectName{"ActiveView"};
std::string imageName = m_pageFeat->getDocument()->getUniqueObjectName(objectName.c_str());
std::string generatedSuffix {imageName.substr(objectName.length())};
std::string imageType = "TechDraw::DrawViewImage";
@@ -146,6 +147,10 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
//document by name instead of using ActiveDocument
Command::doCommand(Command::Doc, "App.getDocument('%s').addObject('%s','%s')",
documentName.c_str(), imageType.c_str(), imageName.c_str());
Command::doCommand(Command::Doc, "App.activeDocument().%s.translateLabel('DrawActiveView', 'ActiveView', '%s')",
imageName.c_str(), imageName.c_str());
Command::doCommand(Command::Doc, "App.getDocument('%s').%s.addView(App.getDocument('%s').%s)",
documentName.c_str(), pageName.c_str(), documentName.c_str(),
imageName.c_str());
@@ -212,9 +217,6 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
}
}
std::string translatedObjectName{tr("ActiveView").toStdString()};
newObj->Label.setValue(translatedObjectName + generatedSuffix);
return newImg;
}

View File

@@ -557,12 +557,15 @@ void TaskComplexSection::createComplexSection()
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create ComplexSection"));
if (!m_section) {
const std::string objectName{QT_TR_NOOP("ComplexSection")};
std::string imageName = m_page->getDocument()->getUniqueObjectName(objectName.c_str());
std::string generatedSuffix {imageName.substr(objectName.length())};
std::string sectionType = "TechDraw::DrawComplexSection";
m_sectionName = m_page->getDocument()->getUniqueObjectName(objectName.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.addObject('TechDraw::DrawComplexSection', '%s')",
m_sectionName.c_str());
std::string uniqueSuffix{m_sectionName.substr(objectName.length(), std::string::npos)};
std::string uniqueLabel = "Section" + uniqueSuffix;
Command::doCommand(Command::Doc, "App.activeDocument().%s.translateLabel('DrawComplexSection', 'Section', '%s')",
m_sectionName.c_str(), uniqueLabel.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.addObject('%s', '%s')",
sectionType.c_str(), m_sectionName.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.addView(App.ActiveDocument.%s)",
m_page->getNameInDocument(), m_sectionName.c_str());
@@ -570,9 +573,6 @@ void TaskComplexSection::createComplexSection()
std::string temp = Base::Tools::toStdString(qTemp);
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.SectionSymbol = '%s'",
m_sectionName.c_str(), temp.c_str());
std::string lblText = "Section " + temp + " - " + temp;
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Label = '%s'",
m_sectionName.c_str(), lblText.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Scale = %0.6f",
m_sectionName.c_str(), ui->sbScale->value());
@@ -628,8 +628,6 @@ void TaskComplexSection::createComplexSection()
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Rotation = %.6f",
m_sectionName.c_str(), rotation);
std::string translatedObjectName{tr(objectName.c_str()).toStdString()};
newObj->Label.setValue(translatedObjectName + generatedSuffix);
}
Gui::Command::commitCommand();
}
@@ -648,10 +646,11 @@ void TaskComplexSection::updateComplexSection()
std::string temp = Base::Tools::toStdString(qTemp);
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.SectionSymbol = '%s'",
m_sectionName.c_str(), temp.c_str());
std::string lblText = "Section " + temp + " - " + temp;
std::string lblText = std::string(m_section->Label.getValue()) + " " + temp + " - " + temp;
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Label = '%s'",
m_sectionName.c_str(), lblText.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Scale = %0.6f",
m_sectionName.c_str(), ui->sbScale->value());
int scaleType = ui->cmbScaleType->currentIndex();

View File

@@ -434,12 +434,16 @@ void TaskDetail::createDetail()
// Base::Console().Message("TD::createDetail()\n");
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Detail View"));
const std::string objectName{QT_TR_NOOP("Detail")};
const std::string objectName{"Detail"};
std::string m_detailName = m_doc->getUniqueObjectName(objectName.c_str());
std::string generatedSuffix {m_detailName.substr(objectName.length())};
Gui::Command::doCommand(Command::Doc, "App.activeDocument().addObject('TechDraw::DrawViewDetail', '%s')",
m_detailName.c_str());
Gui::Command::doCommand(Command::Doc, "App.activeDocument().%s.translateLabel('DrawViewDetail', 'Detail', '%s')",
m_detailName.c_str(), m_detailName.c_str());
App::DocumentObject *docObj = m_doc->getObject(m_detailName.c_str());
TechDraw::DrawViewDetail* dvd = dynamic_cast<TechDraw::DrawViewDetail *>(docObj);
if (!dvd) {
@@ -460,9 +464,6 @@ void TaskDetail::createDetail()
Gui::Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)",
m_pageName.c_str(), m_detailName.c_str());
std::string translatedObjectName{tr(objectName.c_str()).toStdString()};
docObj->Label.setValue(translatedObjectName + generatedSuffix);
Gui::Command::updateActive();
Gui::Command::commitCommand();

View File

@@ -195,18 +195,22 @@ void TaskHatch::createHatch()
{
// Base::Console().Message("TH::createHatch()\n");
App::Document* doc = m_dvp->getDocument();
const std::string objectName{QT_TR_NOOP("Hatch")};
// TODO: the structured label for Hatch (and GeomHatch) should be retired.
const std::string objectName("Hatch");
std::string FeatName = doc->getUniqueObjectName(objectName.c_str());
std::string generatedSuffix {FeatName.substr(objectName.length())};
std::string translatedObjectName{tr(objectName.c_str()).toStdString()};
std::stringstream featLabel;
featLabel << translatedObjectName << generatedSuffix << "F" <<
TechDraw::DrawUtil::getIndexFromName(m_subs.at(0)); //use 1st face# for label
// std::string generatedSuffix {FeatName.substr(objectName.length())};
// std::string translatedObjectName{tr(objectName.c_str()).toStdString()};
// std::stringstream featLabel;
// featLabel << translatedObjectName << generatedSuffix << "F" <<
// TechDraw::DrawUtil::getIndexFromName(m_subs.at(0)); //use 1st face# for label
Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Hatch"));
Command::doCommand(Command::Doc, "App.activeDocument().addObject('TechDraw::DrawHatch', '%s')", FeatName.c_str());
Command::doCommand(Command::Doc, "App.activeDocument().%s.Label = '%s'", FeatName.c_str(), featLabel.str().c_str());
// Command::doCommand(Command::Doc, "App.activeDocument().%s.Label = '%s'", FeatName.c_str(), featLabel.str().c_str());
Command::doCommand(Command::Doc, "App.activeDocument().%s.translateLabel('DrawHatch', 'Hatch', '%s')",
FeatName.c_str(), FeatName.c_str());
m_hatch = static_cast<TechDraw::DrawHatch *>(doc->getObject(FeatName.c_str()));
m_hatch->Source.setValue(m_dvp, m_subs);

View File

@@ -335,9 +335,8 @@ void TaskLeaderLine::onLineStyleChanged()
void TaskLeaderLine::createLeaderFeature(std::vector<Base::Vector3d> converted)
{
// Base::Console().Message("TTL::createLeaderFeature()\n");
const std::string objectName{QT_TR_NOOP("LeaderLine")};
const std::string objectName{"LeaderLine"};
std::string m_leaderName = m_basePage->getDocument()->getUniqueObjectName(objectName.c_str());
std::string generatedSuffix {m_leaderName.substr(objectName.length())};
m_leaderType = "TechDraw::DrawLeaderLine";
std::string PageName = m_basePage->getNameInDocument();
@@ -345,6 +344,9 @@ void TaskLeaderLine::createLeaderFeature(std::vector<Base::Vector3d> converted)
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Leader"));
Command::doCommand(Command::Doc, "App.activeDocument().addObject('%s', '%s')",
m_leaderType.c_str(), m_leaderName.c_str());
Command::doCommand(Command::Doc, "App.activeDocument().%s.translateLabel('DrawLeaderLine', 'LeaderLine', '%s')",
m_leaderName.c_str(), m_leaderName.c_str());
Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)",
PageName.c_str(), m_leaderName.c_str());
if (m_baseFeat) {
@@ -379,9 +381,6 @@ void TaskLeaderLine::createLeaderFeature(std::vector<Base::Vector3d> converted)
}
}
std::string translatedObjectName{tr(objectName.c_str()).toStdString()};
obj->Label.setValue(translatedObjectName + generatedSuffix);
Gui::Command::updateActive();
Gui::Command::commitCommand();

View File

@@ -419,8 +419,8 @@ void TaskSectionView::updateNowClicked() { apply(true); }
//******************************************************************************
bool TaskSectionView::apply(bool forceUpdate)
{
// Base::Console().Message("TSV::apply() - liveUpdate: %d force: %d deferred: %d\n",
// ui->cbLiveUpdate->isChecked(), forceUpdate, m_applyDeferred);
// Base::Console().Message("TSV::apply() - liveUpdate: %d force: %d deferred: %d\n",
// ui->cbLiveUpdate->isChecked(), forceUpdate, m_applyDeferred);
if (!ui->cbLiveUpdate->isChecked() && !forceUpdate) {
//nothing to do
m_applyDeferred++;
@@ -495,18 +495,23 @@ TechDraw::DrawViewSection* TaskSectionView::createSectionView(void)
return nullptr;
}
std::string sectionName;
std::string baseName = m_base->getNameInDocument();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create SectionView"));
if (!m_section) {
const std::string objectName{QT_TR_NOOP("SectionView")};
std::string m_sectionName = m_base->getDocument()->getUniqueObjectName(objectName.c_str());
std::string generatedSuffix {m_sectionName.substr(objectName.length())};
std::string sectionType = "TechDraw::DrawViewSection";
const std::string objectName("SectionView");
m_sectionName = m_base->getDocument()->getUniqueObjectName(objectName.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.addObject('TechDraw::DrawViewSection', '%s')",
m_sectionName.c_str());
// section labels (Section A-A) are not unique, and are not the same as the object name (SectionView)
// we pluck the generated suffix from the object name and append it to "Section" to generate
// unique Labels
std::string uniqueSuffix{m_sectionName.substr(objectName.length(), std::string::npos)};
std::string uniqueLabel = "Section" + uniqueSuffix;
Command::doCommand(Command::Doc, "App.activeDocument().%s.translateLabel('DrawViewSection', 'Section', '%s')",
m_sectionName.c_str(), uniqueLabel.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.addObject('%s', '%s')",
sectionType.c_str(), m_sectionName.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.addView(App.ActiveDocument.%s)",
m_savePageName.c_str(), m_sectionName.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.BaseView = App.ActiveDocument.%s",
@@ -548,8 +553,6 @@ TechDraw::DrawViewSection* TaskSectionView::createSectionView(void)
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Rotation = %.6f",
m_sectionName.c_str(), rotation);
std::string translatedObjectName{tr(objectName.c_str()).toStdString()};
newObj->Label.setValue(translatedObjectName + generatedSuffix);
}
Gui::Command::commitCommand();
return m_section;
@@ -557,7 +560,7 @@ TechDraw::DrawViewSection* TaskSectionView::createSectionView(void)
void TaskSectionView::updateSectionView()
{
// Base::Console().Message("TSV::updateSectionView() - m_sectionName: %s\n", m_sectionName.c_str());
// Base::Console().Message("TSV::updateSectionView() - m_sectionName: %s\n", m_sectionName.c_str());
if (!isSectionValid()) {
failNoObject();
return;
@@ -571,13 +574,15 @@ void TaskSectionView::updateSectionView()
"App.ActiveDocument.%s.SectionOrigin = FreeCAD.Vector(%.3f, %.3f, %.3f)",
m_sectionName.c_str(), ui->sbOrgX->value().getValue(),
ui->sbOrgY->value().getValue(), ui->sbOrgZ->value().getValue());
QString qTemp = ui->leSymbol->text();
std::string temp = Base::Tools::toStdString(qTemp);
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.SectionSymbol = '%s'",
m_sectionName.c_str(), temp.c_str());
std::string lblText = "Section " + temp + " - " + temp;
std::string lblText = std::string(m_section->Label.getValue()) + " " + temp + " - " + temp;
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Label = '%s'",
m_sectionName.c_str(), lblText.c_str());
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Scale = %0.6f",
m_sectionName.c_str(), ui->sbScale->value().getValue());
int scaleType = ui->cmbScaleType->currentIndex();