From 356faf94da63f9c2c92583bfe347f5616d61c52b Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 14 Nov 2022 16:03:21 -0500 Subject: [PATCH] [TD]prevent Complex Section with no Base View --- src/Mod/TechDraw/App/DrawViewSection.cpp | 12 ++++++----- src/Mod/TechDraw/Gui/Command.cpp | 6 ++++++ src/Mod/TechDraw/Gui/TaskComplexSection.cpp | 22 ++++++++++++++------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index d2224bfd19..8f481fc55a 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -801,11 +801,13 @@ Base::Vector3d DrawViewSection::getXDirection() const //we have an XDirection property if (DrawUtil::fpCompare(XDirection.getValue().Length(), 0.0)) { //but it has no value, so we make a value - gp_Ax2 cs = getCSFromBase(SectionDirection.getValueAsString()); - gp_Dir gXDir = cs.XDirection(); - result = Base::Vector3d(gXDir.X(), - gXDir.Y(), - gXDir.Z()); + if (BaseView.getValue()) { + gp_Ax2 cs = getCSFromBase(SectionDirection.getValueAsString()); + gp_Dir gXDir = cs.XDirection(); + result = Base::Vector3d(gXDir.X(), + gXDir.Y(), + gXDir.Z()); + } } else { //XDirection is good, so we use it result = XDirection.getValue(); diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 52947210ed..3185eb93fc 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -737,6 +737,12 @@ void execComplexSection(Gui::Command* cmd) } } + if (!baseView) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("I do not know what base view to use.")); + return; + } + if (shapes.empty() && xShapes.empty() && !baseView) { diff --git a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp index b241a9d80d..d8cf2f37e8 100644 --- a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp +++ b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp @@ -91,11 +91,13 @@ TaskComplexSection::TaskComplexSection(TechDraw::DrawPage* page, m_directionIsSet(false) { m_sectionName = std::string(); - m_doc = m_baseView->getDocument(); - - m_saveBaseName = m_baseView->getNameInDocument(); - m_savePageName = m_baseView->findParentPage()->getNameInDocument(); - + if (m_page) { + m_doc = m_page->getDocument(); + m_savePageName = m_page->getNameInDocument(); + } + if (m_baseView) { + m_saveBaseName = m_baseView->getNameInDocument(); + } ui->setupUi(this); saveSectionState(); @@ -120,11 +122,14 @@ TaskComplexSection::TaskComplexSection(TechDraw::DrawComplexSection* complexSect { m_sectionName = m_section->getNameInDocument(); m_doc = m_section->getDocument(); + m_page = m_section->findParentPage(); + m_savePageName = m_page->getNameInDocument(); + m_baseView = dynamic_cast (m_section->BaseView.getValue()); if (m_baseView) { m_saveBaseName = m_baseView->getNameInDocument(); - m_savePageName = m_baseView->findParentPage()->getNameInDocument(); } + m_shapes = m_section->Source.getValues(); m_xShapes = m_section->XSource.getValues(); m_profileObject = m_section->CuttingToolWireObject.getValue(); @@ -305,7 +310,10 @@ void TaskComplexSection::slotViewDirectionChanged(Base::Vector3d newDirection) { // Base::Console().Message("TCS::slotViewDirectionChanged(%s)\n", // DrawUtil::formatVector(newDirection).c_str()); - Base::Vector3d projectedViewDirection = m_baseView->projectPoint(newDirection, false); + Base::Vector3d projectedViewDirection = newDirection; + if (m_baseView) { + projectedViewDirection = m_baseView->projectPoint(newDirection, false); + } projectedViewDirection.Normalize(); double viewAngle = atan2(projectedViewDirection.y, projectedViewDirection.x);