[TechDraw] Reimplement Weld Symbol parent linking

This commit is contained in:
pavltom
2024-03-08 14:51:25 +01:00
committed by WandererFan
parent 915de5b4db
commit 6dd2a1d1ec
7 changed files with 71 additions and 127 deletions

View File

@@ -98,6 +98,12 @@ void DrawWeldSymbol::onSettingDocument()
void DrawWeldSymbol::onChanged(const App::Property* prop)
{
DrawView::onChanged(prop);
// If leader was switched, our coordinates were adjusted, but we want to stick to the new leader line
if (prop == &Leader && Leader.getValue()) {
X.setValue(0.0);
Y.setValue(0.0);
}
}
short DrawWeldSymbol::mustExecute() const

View File

@@ -62,6 +62,8 @@ public:
bool isTailRightSide();
std::vector<DrawTileWeld*> getTiles() const;
App::PropertyLink *getOwnerProperty() override { return &Leader; }
protected:
void onChanged(const App::Property* prop) override;

View File

@@ -52,12 +52,9 @@ using namespace TechDrawGui;
//**************************************************************
QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent) :
m_weldFeat(nullptr),
m_leadFeat(nullptr),
QGIWeldSymbol::QGIWeldSymbol() :
m_arrowFeat(nullptr),
m_otherFeat(nullptr),
m_qgLead(myParent),
m_tailText(nullptr),
m_fieldFlag(nullptr),
m_allAround(nullptr),
@@ -67,9 +64,6 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent) :
setFlag(QGraphicsItem::ItemIsMovable, false);
setCacheMode(QGraphicsItem::NoCache);
setParentItem(m_qgLead);
m_leadFeat = m_qgLead->getFeature();
setZValue(ZVALUE::DIMENSION);
m_tailText = new QGCustomText();
@@ -126,15 +120,17 @@ void QGIWeldSymbol::updateView(bool update)
{
// Base::Console().Message("QGIWS::updateView()\n");
Q_UNUSED(update);
auto viewWeld( dynamic_cast<TechDraw::DrawWeldSymbol*>(getViewObject()) );
if (!viewWeld)
return;
if (!getFeature()) {
TechDraw::DrawWeldSymbol *feature = getFeature();
if (!feature) {
Base::Console().Warning("QGIWS::updateView - no feature!\n");
return;
}
if (feature->isRestoring() || !getLeader()) {
return;
}
draw();
}
@@ -171,16 +167,17 @@ void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* tileFeat)
return;
}
const auto sym( dynamic_cast<TechDraw::DrawWeldSymbol *>(getViewObject()) );
const auto sym = getFeature();
if (!sym)
return;
auto vp = static_cast<ViewProviderWeld*>(getViewProvider(getViewObject()));
auto vp = dynamic_cast<ViewProviderWeld *>(getViewProvider(sym));
if (!vp)
return;
std::string fontName = vp->Font.getValue();
int fontSize = QGIView::exactFontSize(vp->Font.getValue(),
vp->TileFontSize.getValue());
double featScale = m_leadFeat->getScale();
double featScale = getLeader()->getScale();
std::string tileTextL = tileFeat->LeftText.getValue();
std::string tileTextR = tileFeat->RightText.getValue();
@@ -202,8 +199,8 @@ void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* tileFeat)
// tile->setSymbolFile(symbolFile);
tile->setZValue(ZVALUE::DIMENSION);
tile->setTileScale(featScale);
tile->setTailRight(m_weldFeat->isTailRightSide());
tile->setAltWeld(m_weldFeat->AlternatingWeld.getValue());
tile->setTailRight(getFeature()->isTailRightSide());
tile->setAltWeld(getFeature()->AlternatingWeld.getValue());
tile->draw();
}
@@ -227,8 +224,11 @@ void QGIWeldSymbol::drawAllAround()
m_allAround->setFill(Qt::NoBrush);
// m_allAround->setRadius(calculateFontPixelSize(getDimFontSize()));
m_allAround->setRadius(PreferencesGui::dimFontSizePX());
double width = m_qgLead->getLineWidth();
m_allAround->setWidth(width);
auto qgiLead = dynamic_cast<QGILeaderLine *>(getQGIVByName(getLeader()->getNameInDocument()));
if (qgiLead) {
m_allAround->setWidth(qgiLead->getLineWidth());
}
m_allAround->setZValue(ZVALUE::DIMENSION);
}
@@ -244,10 +244,10 @@ void QGIWeldSymbol::drawTailText()
} else {
m_tailText->show();
}
const auto sym( dynamic_cast<TechDraw::DrawWeldSymbol *>(getViewObject()) );
const auto sym = getFeature();
if (!sym)
return;
auto vp = static_cast<ViewProviderWeld*>(getViewProvider(getViewObject()));
auto vp = dynamic_cast<ViewProviderWeld *>(getViewProvider(sym));
if (!vp) {
return;
}
@@ -305,8 +305,10 @@ void QGIWeldSymbol::drawFieldFlag()
path.lineTo(flagPoints.at(i) * scale);
}
double width = m_qgLead->getLineWidth();
m_fieldFlag->setWidth(width);
auto qgiLead = dynamic_cast<QGILeaderLine *>(getQGIVByName(getLeader()->getNameInDocument()));
if (qgiLead) {
m_fieldFlag->setWidth(qgiLead->getLineWidth());
}
m_fieldFlag->setZValue(ZVALUE::DIMENSION);
m_fieldFlag->setPath(path);
@@ -449,35 +451,38 @@ void QGIWeldSymbol::setPrettySel()
QPointF QGIWeldSymbol::getTileOrigin()
{
Base::Vector3d org = m_leadFeat->getTileOrigin();
Base::Vector3d org = getLeader()->getTileOrigin();
QPointF result(org.x, org.y);
return result;
}
QPointF QGIWeldSymbol::getKinkPoint()
{
Base::Vector3d org = m_leadFeat->getKinkPoint();
Base::Vector3d org = getLeader()->getKinkPoint();
QPointF result(org.x, org.y);
return result;
}
QPointF QGIWeldSymbol::getTailPoint()
{
Base::Vector3d org = m_leadFeat->getTailPoint();
Base::Vector3d org = getLeader()->getTailPoint();
QPointF result(org.x, org.y);
return result;
}
void QGIWeldSymbol::setFeature(TechDraw::DrawWeldSymbol* feat)
{
// Base::Console().Message("QGIWS::setFeature(%s)\n", feat->getNameInDocument());
m_weldFeat = feat;
m_weldFeatName = feat->getNameInDocument();
}
TechDraw::DrawWeldSymbol* QGIWeldSymbol::getFeature()
{
return m_weldFeat;
return dynamic_cast<TechDraw::DrawWeldSymbol *>(getViewObject());
}
TechDraw::DrawLeaderLine *QGIWeldSymbol::getLeader()
{
DrawWeldSymbol *feature = getFeature();
if (!feature) {
return nullptr;
}
return dynamic_cast<TechDraw::DrawLeaderLine *>(feature->Leader.getValue());
}
//preference

View File

@@ -63,7 +63,7 @@ class TechDrawGuiExport QGIWeldSymbol : public QGIView
public:
enum {Type = QGraphicsItem::UserType + 340};
explicit QGIWeldSymbol(QGILeaderLine* myParent = nullptr);
explicit QGIWeldSymbol();
~QGIWeldSymbol() override = default;
int type() const override { return Type;}
@@ -78,7 +78,7 @@ public:
void updateView(bool update = false) override;
virtual TechDraw::DrawWeldSymbol* getFeature();
virtual void setFeature(TechDraw::DrawWeldSymbol* feat);
virtual TechDraw::DrawLeaderLine *getLeader();
QPointF getTileOrigin();
QPointF getKinkPoint();
@@ -110,14 +110,11 @@ protected:
double prefArrowSize();
double prefFontSize() const;
TechDraw::DrawWeldSymbol* m_weldFeat;
TechDraw::DrawLeaderLine* m_leadFeat;
TechDraw::DrawTileWeld* m_arrowFeat;
TechDraw::DrawTileWeld* m_otherFeat;
std::string m_arrowName;
std::string m_otherName;
QGILeaderLine* m_qgLead;
QGCustomText* m_tailText;
QGIPrimPath* m_fieldFlag;
QGIVertex* m_allAround;
@@ -126,7 +123,6 @@ protected:
bool m_blockDraw; //prevent redraws while updating.
std::string m_weldFeatName;
virtual QRectF customBoundingRect() const;
};

View File

@@ -623,28 +623,11 @@ QGIView* QGSPage::addRichAnno(TechDraw::DrawRichAnno* richFeat)
QGIView* QGSPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weldFeat)
{
// Base::Console().Message("QGSP::addWeldSymbol()\n");
QGIWeldSymbol* weldGroup = nullptr;
TechDraw::DrawView* parentDV = nullptr;
QGIWeldSymbol *weldView = new QGIWeldSymbol;
weldView->setViewFeature(weldFeat);
App::DocumentObject* parentObj = weldFeat->Leader.getValue();
if (parentObj) {
parentDV = dynamic_cast<TechDraw::DrawView*>(parentObj);
}
else {
// Base::Console().Message("QGSP::addWeldSymbol - no parent doc obj\n");
}
if (parentDV) {
QGIView* parentQV = findQViewForDocObj(parentObj);
QGILeaderLine* leadParent = dynamic_cast<QGILeaderLine*>(parentQV);
if (leadParent) {
weldGroup = new QGIWeldSymbol(leadParent);
weldGroup->setFeature(weldFeat); //for QGIWS
weldGroup->setViewFeature(weldFeat);//for QGIV
weldGroup->updateView(true);
}
}
return weldGroup;
addQView(weldView);
return weldView;
}
void QGSPage::setDimensionGroups(void)

View File

@@ -456,78 +456,32 @@ void TaskWeldingSymbol::getTileFeats()
TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol()
{
// Base::Console().Message("TWS::createWeldingSymbol()\n");
const std::string objectName{QT_TR_NOOP("SectionView")};
std::string symbolName = m_leadFeat->getDocument()->getUniqueObjectName(objectName.c_str());
std::string generatedSuffix {symbolName.substr(objectName.length())};
std::string symbolType = "TechDraw::DrawWeldSymbol";
TechDraw::DrawPage* page = m_leadFeat->findParentPage();
std::string pageName = page->getNameInDocument();
Command::doCommand(Command::Doc, "App.activeDocument().addObject('%s', '%s')",
symbolType.c_str(), symbolName.c_str());
Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)",
pageName.c_str(), symbolName.c_str());
Command::doCommand(Command::Doc, "App.activeDocument().%s.Leader = App.activeDocument().%s",
symbolName.c_str(), m_leadFeat->getNameInDocument());
bool allAround = ui->cbAllAround->isChecked();
std::string allAroundText = allAround ? "True" : "False";
Command::doCommand(Command::Doc, "App.activeDocument().%s.AllAround = %s",
symbolName.c_str(), allAroundText.c_str());
bool fieldWeld = ui->cbFieldWeld->isChecked();
std::string fieldWeldText = fieldWeld ? "True" : "False";
Command::doCommand(Command::Doc, "App.activeDocument().%s.FieldWeld = %s",
symbolName.c_str(), fieldWeldText.c_str());
bool altWeld = ui->cbAltWeld->isChecked();
std::string altWeldText = altWeld ? "True" : "False";
Command::doCommand(Command::Doc, "App.activeDocument().%s.AlternatingWeld = %s",
symbolName.c_str(), altWeldText.c_str());
std::string tailText = ui->leTailText->text().toStdString();
tailText = Base::Tools::escapeEncodeString(tailText);
Command::doCommand(Command::Doc, "App.activeDocument().%s.TailText = '%s'",
symbolName.c_str(), tailText.c_str());
App::DocumentObject* newObj = m_leadFeat->getDocument()->getObject(symbolName.c_str());
TechDraw::DrawWeldSymbol* newSym = dynamic_cast<TechDraw::DrawWeldSymbol*>(newObj);
if (!newObj || !newSym)
App::Document *doc = Application::Instance->activeDocument()->getDocument();
auto weldSymbol = dynamic_cast<TechDraw::DrawWeldSymbol*>(doc->addObject("TechDraw::DrawWeldSymbol", "WeldSymbol"));
if (!weldSymbol) {
throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found");
}
std::string translatedObjectName{tr(objectName.c_str()).toStdString()};
newObj->Label.setValue(translatedObjectName + generatedSuffix);
weldSymbol->AllAround.setValue(ui->cbAllAround->isChecked());
weldSymbol->FieldWeld.setValue(ui->cbFieldWeld->isChecked());
weldSymbol->AlternatingWeld.setValue(ui->cbAltWeld->isChecked());
weldSymbol->TailText.setValue(ui->leTailText->text().toStdString());
weldSymbol->Leader.setValue(m_leadFeat);
return newSym;
TechDraw::DrawPage *page = m_leadFeat->findParentPage();
if (page) {
page->addView(weldSymbol);
}
return weldSymbol;
}
void TaskWeldingSymbol::updateWeldingSymbol()
{
// Base::Console().Message("TWS::updateWeldingSymbol()\n");
std::string symbolName = m_weldFeat->getNameInDocument();
bool allAround = ui->cbAllAround->isChecked();
std::string allAroundText = allAround ? "True" : "False";
Command::doCommand(Command::Doc, "App.activeDocument().%s.AllAround = %s",
symbolName.c_str(), allAroundText.c_str());
bool fieldWeld = ui->cbFieldWeld->isChecked();
std::string fieldWeldText = fieldWeld ? "True" : "False";
Command::doCommand(Command::Doc, "App.activeDocument().%s.FieldWeld = %s",
symbolName.c_str(), fieldWeldText.c_str());
bool altWeld = ui->cbAltWeld->isChecked();
std::string altWeldText = altWeld ? "True" : "False";
Command::doCommand(Command::Doc, "App.activeDocument().%s.AlternatingWeld = %s",
symbolName.c_str(), altWeldText.c_str());
std::string tailText = ui->leTailText->text().toStdString();
tailText = Base::Tools::escapeEncodeString(tailText);
Command::doCommand(Command::Doc, "App.activeDocument().%s.TailText = '%s'",
symbolName.c_str(), tailText.c_str());
m_weldFeat->AllAround.setValue(ui->cbAllAround->isChecked());
m_weldFeat->FieldWeld.setValue(ui->cbFieldWeld->isChecked());
m_weldFeat->AlternatingWeld.setValue(ui->cbAltWeld->isChecked());
m_weldFeat->TailText.setValue(ui->leTailText->text().toStdString());
}
void TaskWeldingSymbol::updateTiles()

View File

@@ -393,7 +393,6 @@ std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const
// DrawViewBalloon
// any FeatuerView in a DrawViewClip
// DrawHatch
// DrawWeldSymbol
const std::vector<App::DocumentObject*>& views = getDrawPage()->Views.getValues();
@@ -413,7 +412,6 @@ std::vector<App::DocumentObject*> ViewProviderPage::claimChildren(void) const
|| docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())
|| docObj->isDerivedFrom(TechDraw::DrawHatch::getClassTypeId())
|| docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())
|| docObj->isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId())
|| (featView && featView->isInClip()))
continue;
else