diff --git a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp index db56446a1a3b2..b41ace06e3f69 100644 --- a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp +++ b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp @@ -22,9 +22,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -#endif // #ifndef _PreComp_ +#include +#include +#endif// #ifndef _PreComp_ #include #include @@ -37,17 +37,17 @@ #include #include +#include "Widgets/CompassWidget.h" +#include "Widgets/VectorEditWidget.h" #include #include #include #include #include -#include "Widgets/CompassWidget.h" -#include "Widgets/VectorEditWidget.h" +#include "DrawGuiUtil.h" #include "TaskComplexSection.h" #include "ui_TaskComplexSection.h" -#include "DrawGuiUtil.h" using namespace Gui; @@ -56,26 +56,15 @@ using namespace TechDrawGui; using DU = DrawUtil; //ctor for creation -TaskComplexSection::TaskComplexSection(TechDraw::DrawPage* page, - TechDraw::DrawViewPart* baseView, +TaskComplexSection::TaskComplexSection(TechDraw::DrawPage* page, TechDraw::DrawViewPart* baseView, std::vector shapes, std::vector xShapes, App::DocumentObject* profileObject, - std::vector profileSubs) : - ui(new Ui_TaskComplexSection), - m_page(page), - m_baseView(baseView), - m_section(nullptr), - m_shapes(shapes), - m_xShapes(xShapes), - m_profileObject(profileObject), - m_profileSubs(profileSubs), - m_dirName("Aligned"), - m_createMode(true), - m_applyDeferred(0), - m_angle(0.0), - m_directionIsSet(false), - m_modelIsDirty(false) + std::vector profileSubs) + : ui(new Ui_TaskComplexSection), m_page(page), m_baseView(baseView), m_section(nullptr), + m_shapes(shapes), m_xShapes(xShapes), m_profileObject(profileObject), + m_profileSubs(profileSubs), m_dirName("Aligned"), m_createMode(true), m_applyDeferred(0), + m_angle(0.0), m_directionIsSet(false), m_modelIsDirty(false) { m_sectionName = std::string(); if (m_page) { @@ -90,30 +79,23 @@ TaskComplexSection::TaskComplexSection(TechDraw::DrawPage* page, saveSectionState(); setUiPrimary(); - m_applyDeferred = 0; //setting the direction widgets causes an increment of the deferred count, - //so we reset the counter and the message. + m_applyDeferred = 0;//setting the direction widgets causes an increment of the deferred count, + //so we reset the counter and the message. } //ctor for edit -TaskComplexSection::TaskComplexSection(TechDraw::DrawComplexSection* complexSection) : - ui(new Ui_TaskComplexSection), - m_page(nullptr), - m_baseView(nullptr), - m_section(complexSection), - m_profileObject(nullptr), - m_dirName("Aligned"), - m_createMode(false), - m_applyDeferred(0), - m_angle(0.0), - m_directionIsSet(true), - m_modelIsDirty(false) +TaskComplexSection::TaskComplexSection(TechDraw::DrawComplexSection* complexSection) + : ui(new Ui_TaskComplexSection), m_page(nullptr), m_baseView(nullptr), + m_section(complexSection), m_profileObject(nullptr), m_dirName("Aligned"), + m_createMode(false), m_applyDeferred(0), m_angle(0.0), m_directionIsSet(true), + m_modelIsDirty(false) { m_sectionName = m_section->getNameInDocument(); - m_doc = m_section->getDocument(); - m_page = m_section->findParentPage(); + m_doc = m_section->getDocument(); + m_page = m_section->findParentPage(); m_savePageName = m_page->getNameInDocument(); - m_baseView = dynamic_cast (m_section->BaseView.getValue()); + m_baseView = dynamic_cast(m_section->BaseView.getValue()); if (m_baseView) { m_saveBaseName = m_baseView->getNameInDocument(); } @@ -127,8 +109,8 @@ TaskComplexSection::TaskComplexSection(TechDraw::DrawComplexSection* complexSect saveSectionState(); setUiEdit(); - m_applyDeferred = 0; //setting the direction widgets causes an increment of the deferred count, - //so we reset the counter and the message. + m_applyDeferred = 0;//setting the direction widgets causes an increment of the deferred count, + //so we reset the counter and the message. ui->lPendingUpdates->setText(QString()); } @@ -138,7 +120,8 @@ void TaskComplexSection::setUiPrimary() if (m_baseView) { ui->sbScale->setValue(m_baseView->getScale()); ui->cmbScaleType->setCurrentIndex(m_baseView->ScaleType.getValue()); - } else { + } + else { ui->sbScale->setValue(Preferences::scale()); ui->cmbScaleType->setCurrentIndex(Preferences::scaleType()); } @@ -154,20 +137,23 @@ void TaskComplexSection::setUiPrimary() m_saveNormal = defaultNormal; m_saveXDir = Base::Vector3d(0.0, 1.0, 0.0); ui->leBaseView->setText(Base::Tools::fromStdString(m_baseView->getNameInDocument())); - m_viewDirectionWidget->setValue(Base::Vector3d(0.0, 0.0, 0.0)); - } else { + m_compass->setDialAngle(0.0); + m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(1.0, 0.0, 0.0)); + } + else { //if there is no baseView, we use the 3d view to determine the SectionNormal //and XDirection. std::pair dirs = DrawGuiUtil::get3DDirAndRot(); m_saveNormal = dirs.first; m_saveXDir = dirs.second; - m_viewDirectionWidget->setValue(m_saveNormal * -1.0); //this will propagate to m_compass + m_viewDirectionWidget->setValue(m_saveNormal * -1.0);//this will propagate to m_compass } //don't allow updates until a direction is picked ui->pbUpdateNow->setEnabled(false); ui->cbLiveUpdate->setEnabled(false); - QString msgLiteral = QString::fromUtf8(QT_TRANSLATE_NOOP("TaskComplexSection", "No direction set")); + QString msgLiteral = + QString::fromUtf8(QT_TRANSLATE_NOOP("TaskComplexSection", "No direction set")); ui->lPendingUpdates->setText(msgLiteral); } @@ -189,11 +175,11 @@ void TaskComplexSection::setUiEdit() if (m_baseView) { ui->leBaseView->setText(Base::Tools::fromStdString(m_baseView->getNameInDocument())); Base::Vector3d projectedViewDirection = m_baseView->projectPoint(sectionNormalVec, false); - double viewAngle = atan2(-projectedViewDirection.y, - -projectedViewDirection.x); + double viewAngle = atan2(-projectedViewDirection.y, -projectedViewDirection.x); m_compass->setDialAngle(viewAngle * 180.0 / M_PI); m_viewDirectionWidget->setValueNoNotify(projectedViewDirection * -1.0); - } else { + } + else { //no local angle makes sense if there is no baseView? m_viewDirectionWidget->setValue(sectionNormalVec * -1.0); } @@ -202,9 +188,9 @@ void TaskComplexSection::setUiEdit() void TaskComplexSection::setUiCommon() { ui->leSectionObjects->setText(sourcesToString()); - ui->leProfileObject->setText(Base::Tools::fromStdString(m_profileObject->getNameInDocument()) + - QString::fromUtf8(" / ") + - Base::Tools::fromStdString(m_profileObject->Label.getValue())); + ui->leProfileObject->setText(Base::Tools::fromStdString(m_profileObject->getNameInDocument()) + + QString::fromUtf8(" / ") + + Base::Tools::fromStdString(m_profileObject->Label.getValue())); m_compass = new CompassWidget(this); auto layout = ui->compassLayout; @@ -227,27 +213,29 @@ void TaskComplexSection::setUiCommon() connect(ui->pbUpdateNow, SIGNAL(clicked(bool)), this, SLOT(updateNowClicked())); connect(ui->cbLiveUpdate, SIGNAL(clicked(bool)), this, SLOT(liveUpdateClicked())); - connect(ui->pbSectionObjects, SIGNAL(clicked()), this, SLOT(onSectionObjectsUseSelectionClicked())); - connect(ui->pbProfileObject, SIGNAL(clicked()), this, SLOT(onProfileObjectsUseSelectionClicked())); + connect(ui->pbSectionObjects, SIGNAL(clicked()), this, + SLOT(onSectionObjectsUseSelectionClicked())); + connect(ui->pbProfileObject, SIGNAL(clicked()), this, + SLOT(onProfileObjectsUseSelectionClicked())); connect(m_compass, SIGNAL(angleChanged(double)), this, SLOT(slotChangeAngle(double))); - connect(m_viewDirectionWidget, SIGNAL(valueChanged(Base::Vector3d)), - this, SLOT(slotViewDirectionChanged(Base::Vector3d))); + connect(m_viewDirectionWidget, SIGNAL(valueChanged(Base::Vector3d)), this, + SLOT(slotViewDirectionChanged(Base::Vector3d))); } //save the start conditions void TaskComplexSection::saveSectionState() { -// Base::Console().Message("TCS::saveSectionState()\n"); + // Base::Console().Message("TCS::saveSectionState()\n"); if (m_section) { m_saveSymbol = m_section->SectionSymbol.getValue(); - m_saveScale = m_section->getScale(); + m_saveScale = m_section->getScale(); m_saveScaleType = m_section->ScaleType.getValue(); m_saveNormal = m_section->SectionNormal.getValue(); m_saveDirection = m_section->Direction.getValue(); m_saveXDir = m_section->XDirection.getValue(); - m_saveOrigin = m_section->SectionOrigin.getValue(); - m_saveDirName = m_section->SectionDirection.getValueAsString(); + m_saveOrigin = m_section->SectionOrigin.getValue(); + m_saveDirName = m_section->SectionDirection.getValueAsString(); m_saved = true; } if (m_baseView) { @@ -259,7 +247,7 @@ void TaskComplexSection::saveSectionState() //restore the start conditions void TaskComplexSection::restoreSectionState() { -// Base::Console().Message("TCS::restoreSectionState()\n"); + // Base::Console().Message("TCS::restoreSectionState()\n"); if (!m_section) return; @@ -279,11 +267,12 @@ void TaskComplexSection::onSectionObjectsUseSelectionClicked() std::vector newSelection; std::vector newXSelection; for (auto& sel : selection) { - if (sel.getObject()->isDerivedFrom(App::LinkElement::getClassTypeId()) || - sel.getObject()->isDerivedFrom(App::LinkGroup::getClassTypeId()) || - sel.getObject()->isDerivedFrom(App::Link::getClassTypeId()) ) { + if (sel.getObject()->isDerivedFrom(App::LinkElement::getClassTypeId()) + || sel.getObject()->isDerivedFrom(App::LinkGroup::getClassTypeId()) + || sel.getObject()->isDerivedFrom(App::Link::getClassTypeId())) { newXSelection.push_back(sel.getObject()); - } else { + } + else { newSelection.push_back(sel.getObject()); } } @@ -295,15 +284,14 @@ void TaskComplexSection::onSectionObjectsUseSelectionClicked() //the VectorEditWidget reports a change in direction void TaskComplexSection::slotViewDirectionChanged(Base::Vector3d newDirection) { -// Base::Console().Message("TCS::slotViewDirectionChanged(%s)\n", -// DrawUtil::formatVector(newDirection).c_str()); + // Base::Console().Message("TCS::slotViewDirectionChanged(%s)\n", + // DrawUtil::formatVector(newDirection).c_str()); Base::Vector3d projectedViewDirection = newDirection; if (m_baseView) { projectedViewDirection = m_baseView->projectPoint(newDirection, false); } projectedViewDirection.Normalize(); - double viewAngle = atan2(projectedViewDirection.y, - projectedViewDirection.x); + double viewAngle = atan2(projectedViewDirection.y, projectedViewDirection.x); m_compass->setDialAngle(viewAngle * 180.0 / M_PI); checkAll(false); applyAligned(); @@ -313,7 +301,7 @@ void TaskComplexSection::slotViewDirectionChanged(Base::Vector3d newDirection) //SectionNormal void TaskComplexSection::slotChangeAngle(double newAngle) { -// Base::Console().Message("TCS::slotAngleChanged(%.3f)\n", newAngle); + // Base::Console().Message("TCS::slotAngleChanged(%.3f)\n", newAngle); double angleRadians = newAngle * M_PI / 180.0; double unitX = cos(angleRadians); double unitY = sin(angleRadians); @@ -325,7 +313,7 @@ void TaskComplexSection::slotChangeAngle(double newAngle) void TaskComplexSection::onUpClicked() { -// Base::Console().Message("TCS::onUpClicked()\n"); + // Base::Console().Message("TCS::onUpClicked()\n"); checkAll(false); m_compass->setToNorth(); m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(0.0, 1.0, 0.0)); @@ -334,7 +322,7 @@ void TaskComplexSection::onUpClicked() void TaskComplexSection::onDownClicked() { -// Base::Console().Message("TCS::onDownClicked()\n"); + // Base::Console().Message("TCS::onDownClicked()\n"); checkAll(false); m_compass->setToSouth(); m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(0.0, -1.0, 0.0)); @@ -343,7 +331,7 @@ void TaskComplexSection::onDownClicked() void TaskComplexSection::onLeftClicked() { -// Base::Console().Message("TCS::onLeftClicked()\n"); + // Base::Console().Message("TCS::onLeftClicked()\n"); checkAll(false); m_compass->setToWest(); m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(-1.0, 0.0, 0.0)); @@ -352,7 +340,7 @@ void TaskComplexSection::onLeftClicked() void TaskComplexSection::onRightClicked() { -// Base::Console().Message("TCS::onRightClicked()\n"); + // Base::Console().Message("TCS::onRightClicked()\n"); checkAll(false); m_compass->setToEast(); m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(1.0, 0.0, 0.0)); @@ -377,9 +365,10 @@ void TaskComplexSection::onProfileObjectsUseSelectionClicked() //check for single selection and ability to make profile from selected object if (!selection.empty()) { m_profileObject = selection.front().getObject(); - ui->leProfileObject->setText(Base::Tools::fromStdString(m_profileObject->getNameInDocument()) + - QString::fromUtf8(" / ") + - Base::Tools::fromStdString(m_profileObject->Label.getValue())); + ui->leProfileObject->setText( + Base::Tools::fromStdString(m_profileObject->getNameInDocument()) + + QString::fromUtf8(" / ") + + Base::Tools::fromStdString(m_profileObject->Label.getValue())); } } void TaskComplexSection::scaleTypeChanged(int index) @@ -391,21 +380,25 @@ void TaskComplexSection::scaleTypeChanged(int index) ui->sbScale->setValue(m_baseView->findParentPage()->Scale.getValue()); ui->sbScale->setEnabled(false); } - } else if (index == 1) { + } + else if (index == 1) { // Automatic Scale Type ui->sbScale->setEnabled(false); if (m_section) { ui->sbScale->setValue(m_section->autoScale()); } - } else if (index == 2) { + } + else if (index == 2) { // Custom Scale Type ui->sbScale->setEnabled(true); if (m_section) { ui->sbScale->setValue(m_section->Scale.getValue()); ui->sbScale->setEnabled(true); } - } else { - Base::Console().Log("Error - TaskComplexSection::scaleTypeChanged - unknown scale type: %d\n", index); + } + else { + Base::Console().Log( + "Error - TaskComplexSection::scaleTypeChanged - unknown scale type: %d\n", index); return; } } @@ -425,22 +418,17 @@ void TaskComplexSection::enableAll(bool enable) ui->cmbScaleType->setEnabled(enable); QString qScaleType = ui->cmbScaleType->currentText(); //Allow or prevent scale changing initially - if (qScaleType == QString::fromUtf8("Custom")) { + if (qScaleType == QString::fromUtf8("Custom")) { ui->sbScale->setEnabled(true); } else { ui->sbScale->setEnabled(false); } - } -void TaskComplexSection::liveUpdateClicked() { - apply(true); -} +void TaskComplexSection::liveUpdateClicked() { apply(true); } -void TaskComplexSection::updateNowClicked() { - apply(true); -} +void TaskComplexSection::updateNowClicked() { apply(true); } QString TaskComplexSection::sourcesToString() { @@ -449,32 +437,25 @@ QString TaskComplexSection::sourcesToString() QString currentSeparator; if (m_baseView) { for (auto& obj : m_baseView->Source.getValues()) { - result += currentSeparator + - Base::Tools::fromStdString(obj->getNameInDocument()) + - QString::fromUtf8(" / ") + - Base::Tools::fromStdString(obj->Label.getValue()); + result += currentSeparator + Base::Tools::fromStdString(obj->getNameInDocument()) + + QString::fromUtf8(" / ") + Base::Tools::fromStdString(obj->Label.getValue()); currentSeparator = separator; } currentSeparator = QString(); for (auto& obj : m_baseView->XSource.getValues()) { - result += currentSeparator + - Base::Tools::fromStdString(obj->getNameInDocument()) + - QString::fromUtf8(" / ") + - Base::Tools::fromStdString(obj->Label.getValue()); + result += currentSeparator + Base::Tools::fromStdString(obj->getNameInDocument()) + + QString::fromUtf8(" / ") + Base::Tools::fromStdString(obj->Label.getValue()); } - } else { + } + else { for (auto& obj : m_shapes) { - result += currentSeparator + - Base::Tools::fromStdString(obj->getNameInDocument()) + - QString::fromUtf8(" / ") + - Base::Tools::fromStdString(obj->Label.getValue()); + result += currentSeparator + Base::Tools::fromStdString(obj->getNameInDocument()) + + QString::fromUtf8(" / ") + Base::Tools::fromStdString(obj->Label.getValue()); } currentSeparator = QString(); for (auto& obj : m_xShapes) { - result += currentSeparator + - Base::Tools::fromStdString(obj->getNameInDocument()) + - QString::fromUtf8(" / ") + - Base::Tools::fromStdString(obj->Label.getValue()); + result += currentSeparator + Base::Tools::fromStdString(obj->getNameInDocument()) + + QString::fromUtf8(" / ") + Base::Tools::fromStdString(obj->Label.getValue()); } } return result; @@ -483,13 +464,13 @@ QString TaskComplexSection::sourcesToString() //****************************************************************************** bool TaskComplexSection::apply(bool forceUpdate) { -// Base::Console().Message("TCS::apply() - liveUpdate: %d forece: %d\n", -// ui->cbLiveUpdate->isChecked(), forceUpdate); - if(!ui->cbLiveUpdate->isChecked() && - !forceUpdate) { + // Base::Console().Message("TCS::apply() - liveUpdate: %d forece: %d\n", + // ui->cbLiveUpdate->isChecked(), forceUpdate); + if (!ui->cbLiveUpdate->isChecked() && !forceUpdate) { //nothing to do m_applyDeferred++; - QString msgLiteral = QString::fromUtf8(QT_TRANSLATE_NOOP("TaskPojGroup", " updates pending")); + QString msgLiteral = + QString::fromUtf8(QT_TRANSLATE_NOOP("TaskPojGroup", " updates pending")); QString msgNumber = QString::number(m_applyDeferred); ui->lPendingUpdates->setText(msgNumber + msgLiteral); return false; @@ -497,15 +478,20 @@ bool TaskComplexSection::apply(bool forceUpdate) Base::Vector3d localUnit = m_viewDirectionWidget->value(); if (m_baseView) { - if (!DrawComplexSection::canBuild(m_baseView->localVectorToCS(localUnit), m_profileObject)) { - Base::Console().Error("Can not build Complex Section with this profile and direction (1)\n"); + if (!DrawComplexSection::canBuild(m_baseView->localVectorToCS(localUnit), + m_profileObject)) { + Base::Console().Error( + "Can not build Complex Section with this profile and direction (1)\n"); return false; } - } else { + } + else { gp_Pnt stdOrigin(0.0, 0.0, 0.0); - gp_Ax2 sectionCS(stdOrigin, DrawUtil::togp_Dir(m_saveNormal), DrawUtil::togp_Dir(m_saveXDir)); + gp_Ax2 sectionCS(stdOrigin, DrawUtil::togp_Dir(m_saveNormal), + DrawUtil::togp_Dir(m_saveXDir)); if (!DrawComplexSection::canBuild(sectionCS, m_profileObject)) { - Base::Console().Error("Can not build Complex Section with this profile and direction (2)\n"); + Base::Console().Error( + "Can not build Complex Section with this profile and direction (2)\n"); return false; } } @@ -519,7 +505,8 @@ bool TaskComplexSection::apply(bool forceUpdate) if (isSectionValid()) { updateComplexSection(); - } else { + } + else { failNoObject(); } @@ -539,7 +526,7 @@ bool TaskComplexSection::apply(bool forceUpdate) void TaskComplexSection::applyAligned() { -// Base::Console().Message("TCS::applyAligned()\n"); + // Base::Console().Message("TCS::applyAligned()\n"); m_dirName = "Aligned"; enableAll(true); m_directionIsSet = true; @@ -553,7 +540,7 @@ void TaskComplexSection::applyAligned() //pointer to created view is not returned, but stored in m_section void TaskComplexSection::createComplexSection() { -// Base::Console().Message("TCS::createComplexSection()\n"); + // Base::Console().Message("TCS::createComplexSection()\n"); Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create ComplexSection")); if (!m_section) { @@ -565,22 +552,16 @@ void TaskComplexSection::createComplexSection() Command::doCommand(Command::Doc, "App.ActiveDocument.%s.addView(App.ActiveDocument.%s)", m_page->getNameInDocument(), m_sectionName.c_str()); - QString qTemp = ui->leSymbol->text(); + 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; + 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()); + m_sectionName.c_str(), lblText.c_str()); Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Scale = %0.6f", - m_sectionName.c_str(), - ui->sbScale->value()); + m_sectionName.c_str(), ui->sbScale->value()); int scaleType = ui->cmbScaleType->currentIndex(); Command::doCommand(Command::Doc, "App.ActiveDocument.%s.ScaleType = %d", m_sectionName.c_str(), scaleType); @@ -588,28 +569,32 @@ void TaskComplexSection::createComplexSection() Command::doCommand(Command::Doc, "App.ActiveDocument.%s.ProjectionStrategy = %d", m_sectionName.c_str(), projectionStrategy); - Command::doCommand(Command::Doc, "App.activeDocument().%s.SectionOrigin = FreeCAD.Vector(0.0, 0.0, 0.0)", - m_sectionName.c_str()); + Command::doCommand(Command::Doc, + "App.activeDocument().%s.SectionOrigin = FreeCAD.Vector(0.0, 0.0, 0.0)", + m_sectionName.c_str()); Command::doCommand(Command::Doc, "App.activeDocument().%s.SectionDirection = 'Aligned'", - m_sectionName.c_str()); + m_sectionName.c_str()); App::DocumentObject* newObj = m_page->getDocument()->getObject(m_sectionName.c_str()); m_section = dynamic_cast(newObj); - if (!newObj || !m_section) { + if (!newObj || !m_section) { throw Base::RuntimeError("TaskComplexSection - new section object not found"); } Base::Vector3d localUnit = m_viewDirectionWidget->value(); if (m_baseView) { - Command::doCommand(Command::Doc, "App.ActiveDocument.%s.BaseView = App.ActiveDocument.%s", + Command::doCommand(Command::Doc, + "App.ActiveDocument.%s.BaseView = App.ActiveDocument.%s", m_sectionName.c_str(), m_baseView->getNameInDocument()); m_section->setCSFromBase(localUnit * -1.0); m_section->Source.setValues(m_baseView->Source.getValues()); m_section->XSource.setValues(m_baseView->XSource.getValues()); - } else { + } + else { if (m_directionIsSet) { //if we have changed the direction, use the local unit to create a CS m_section->setCSFromLocalUnit(localUnit * -1.0); - } else { + } + else { //if we have not changed the direction, we should use the 3d directions saved in the //constructor m_section->SectionNormal.setValue(m_saveNormal); @@ -634,7 +619,7 @@ void TaskComplexSection::createComplexSection() void TaskComplexSection::updateComplexSection() { -// Base::Console().Message("TCS:;updateComplexSection()\n"); + // Base::Console().Message("TCS:;updateComplexSection()\n"); if (!isSectionValid()) { failNoObject(); return; @@ -642,22 +627,16 @@ void TaskComplexSection::updateComplexSection() Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Edit SectionView")); if (m_section) { - QString qTemp = ui->leSymbol->text(); + 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; + 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()); + m_sectionName.c_str(), lblText.c_str()); Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Scale = %0.6f", - m_sectionName.c_str(), - ui->sbScale->value()); + m_sectionName.c_str(), ui->sbScale->value()); int scaleType = ui->cmbScaleType->currentIndex(); Command::doCommand(Command::Doc, "App.ActiveDocument.%s.ScaleType = %d", m_sectionName.c_str(), scaleType); @@ -665,7 +644,7 @@ void TaskComplexSection::updateComplexSection() Command::doCommand(Command::Doc, "App.ActiveDocument.%s.ProjectionStrategy = %d", m_sectionName.c_str(), projectionStrategy); Command::doCommand(Command::Doc, "App.activeDocument().%s.SectionDirection = 'Aligned'", - m_sectionName.c_str()); + m_sectionName.c_str()); m_section->CuttingToolWireObject.setValue(m_profileObject); m_section->SectionDirection.setValue("Aligned"); Base::Vector3d localUnit = m_viewDirectionWidget->value(); @@ -673,7 +652,8 @@ void TaskComplexSection::updateComplexSection() if (m_baseView) { m_section->Source.setValues(m_baseView->Source.getValues()); m_section->XSource.setValues(m_baseView->XSource.getValues()); - } else { + } + else { //without a baseView, our choice of SectionNormal and XDirection may well be wrong m_section->Source.setValues(m_shapes); m_section->XSource.setValues(m_xShapes); @@ -737,20 +717,20 @@ double TaskComplexSection::requiredRotation(double inputAngle) //****************************************************************************** bool TaskComplexSection::accept() { -// Base::Console().Message("TCS::accept()\n"); + // Base::Console().Message("TCS::accept()\n"); apply(true); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()"); return true; } bool TaskComplexSection::reject() { - if (!m_section) { //no section created, nothing to undo + if (!m_section) {//no section created, nothing to undo Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()"); return false; } - if (!isSectionValid()) { //section !exist. nothing to undo + if (!isSectionValid()) {//section !exist. nothing to undo if (isBaseValid()) { m_baseView->requestPaint(); } @@ -763,10 +743,10 @@ bool TaskComplexSection::reject() Gui::Command::doCommand(Gui::Command::Gui, "App.ActiveDocument.%s.removeView(App.ActiveDocument.%s)", m_savePageName.c_str(), SectionName.c_str()); - Gui::Command::doCommand(Gui::Command::Gui, - "App.ActiveDocument.removeObject('%s')", + Gui::Command::doCommand(Gui::Command::Gui, "App.ActiveDocument.removeObject('%s')", SectionName.c_str()); - } else { + } + else { if (m_modelIsDirty) { restoreSectionState(); m_section->recomputeFeature(); @@ -780,7 +760,8 @@ bool TaskComplexSection::reject() Gui::Command::updateActive(); Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()"); - return false;} + return false; +} void TaskComplexSection::changeEvent(QEvent* event) { @@ -791,16 +772,17 @@ void TaskComplexSection::changeEvent(QEvent* event) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TaskDlgComplexSection::TaskDlgComplexSection(TechDraw::DrawPage* page, - TechDraw::DrawViewPart *baseView, + TechDraw::DrawViewPart* baseView, std::vector shapes, std::vector xShapes, App::DocumentObject* profileObject, std::vector profileSubs) : TaskDialog() { - widget = new TaskComplexSection(page, baseView, shapes, xShapes, profileObject, profileSubs); - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_ComplexSection"), - widget->windowTitle(), true, nullptr); + widget = new TaskComplexSection(page, baseView, shapes, xShapes, profileObject, profileSubs); + taskbox = + new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_ComplexSection"), + widget->windowTitle(), true, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } @@ -808,26 +790,23 @@ TaskDlgComplexSection::TaskDlgComplexSection(TechDraw::DrawPage* page, TaskDlgComplexSection::TaskDlgComplexSection(TechDraw::DrawComplexSection* complexSection) : TaskDialog() { - widget = new TaskComplexSection(complexSection); - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_ComplexSection"), - widget->windowTitle(), true, nullptr); + widget = new TaskComplexSection(complexSection); + taskbox = + new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_ComplexSection"), + widget->windowTitle(), true, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } -TaskDlgComplexSection::~TaskDlgComplexSection() -{ -} +TaskDlgComplexSection::~TaskDlgComplexSection() {} void TaskDlgComplexSection::update() { -// widget->updateTask(); + // widget->updateTask(); } //==== calls from the TaskView =============================================================== -void TaskDlgComplexSection::open() -{ -} +void TaskDlgComplexSection::open() {} bool TaskDlgComplexSection::accept() { diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index 0fe7c3785cdcd..a62b33ce4f416 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -22,10 +22,12 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -#endif // #ifndef _PreComp_ +#include +#include +#endif// #ifndef _PreComp_ +#include "Widgets/CompassWidget.h" +#include "Widgets/VectorEditWidget.h" #include #include #include @@ -40,11 +42,11 @@ #include #include #include -#include "Widgets/CompassWidget.h" -#include "Widgets/VectorEditWidget.h" +// clang-format off #include "ui_TaskSectionView.h" #include "TaskSectionView.h" +// clang-format on using namespace Gui; @@ -52,23 +54,15 @@ using namespace TechDraw; using namespace TechDrawGui; //ctor for create -TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base) : - ui(new Ui_TaskSectionView), - m_base(base), - m_section(nullptr), - m_saveScale(1.0), - m_dirName(""), - m_doc(nullptr), - m_createMode(true), - m_saved(false), - m_applyDeferred(0), - m_directionIsSet(false), - m_modelIsDirty(false) +TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base) + : ui(new Ui_TaskSectionView), m_base(base), m_section(nullptr), m_saveScale(1.0), m_dirName(""), + m_doc(nullptr), m_createMode(true), m_saved(false), m_applyDeferred(0), + m_directionIsSet(false), m_modelIsDirty(false) { //existence of base is guaranteed by CmdTechDrawSectionView (Command.cpp) m_sectionName = std::string(); - m_doc = m_base->getDocument(); + m_doc = m_base->getDocument(); m_saveBaseName = m_base->getNameInDocument(); m_savePageName = m_base->findParentPage()->getNameInDocument(); @@ -76,22 +70,15 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base) : ui->setupUi(this); setUiPrimary(); - m_applyDeferred = 0; //setting the direction widgets causes an increment of the deferred count, - //so we reset the counter and the message. + m_applyDeferred = 0;//setting the direction widgets causes an increment of the deferred count, + //so we reset the counter and the message. } //ctor for edit -TaskSectionView::TaskSectionView(TechDraw::DrawViewSection* section) : - ui(new Ui_TaskSectionView), - m_base(nullptr), - m_section(section), - m_saveScale(1.0), - m_doc(nullptr), - m_createMode(false), - m_saved(false), - m_applyDeferred(0), - m_directionIsSet(true), - m_modelIsDirty(false) +TaskSectionView::TaskSectionView(TechDraw::DrawViewSection* section) + : ui(new Ui_TaskSectionView), m_base(nullptr), m_section(section), m_saveScale(1.0), + m_doc(nullptr), m_createMode(false), m_saved(false), m_applyDeferred(0), + m_directionIsSet(true), m_modelIsDirty(false) { //existence of section is guaranteed by ViewProviderViewSection.setEdit @@ -112,21 +99,21 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewSection* section) : saveSectionState(); setUiEdit(); - m_applyDeferred = 0; //setting the direction widgets causes an increment of the deferred count, - //so we reset the counter and the message. + m_applyDeferred = 0;//setting the direction widgets causes an increment of the deferred count, + //so we reset the counter and the message. ui->lPendingUpdates->setText(QString()); } void TaskSectionView::setUiPrimary() { -// Base::Console().Message("TSV::setUiPrimary()\n"); + // Base::Console().Message("TSV::setUiPrimary()\n"); setWindowTitle(QObject::tr("Create Section View")); ui->sbScale->setValue(m_base->getScale()); ui->cmbScaleType->setCurrentIndex(m_base->ScaleType.getValue()); //Allow or prevent scale changing initially - if (m_base->ScaleType.isValue("Custom")) { + if (m_base->ScaleType.isValue("Custom")) { ui->sbScale->setEnabled(true); } else { @@ -136,18 +123,20 @@ void TaskSectionView::setUiPrimary() Base::Vector3d origin = m_base->getOriginalCentroid(); setUiCommon(origin); - m_viewDirectionWidget->setValue(Base::Vector3d(1.0, 0.0, 0.0)); + m_compass->setDialAngle(0.0); + m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(1.0, 0.0, 0.0)); //don't allow updates until a direction is picked ui->pbUpdateNow->setEnabled(false); ui->cbLiveUpdate->setEnabled(false); - QString msgLiteral = QString::fromUtf8(QT_TRANSLATE_NOOP("TaskSectionView", "No direction set")); + QString msgLiteral = + QString::fromUtf8(QT_TRANSLATE_NOOP("TaskSectionView", "No direction set")); ui->lPendingUpdates->setText(msgLiteral); } void TaskSectionView::setUiEdit() { -// Base::Console().Message("TSV::setUiEdit()\n"); + // Base::Console().Message("TSV::setUiEdit()\n"); setWindowTitle(QObject::tr("Edit Section View")); std::string temp = m_section->SectionSymbol.getValue(); QString qTemp = Base::Tools::fromStdString(temp); @@ -156,7 +145,7 @@ void TaskSectionView::setUiEdit() ui->sbScale->setValue(m_section->getScale()); ui->cmbScaleType->setCurrentIndex(m_section->ScaleType.getValue()); //Allow or prevent scale changing initially - if (m_section->ScaleType.isValue("Custom")) { + if (m_section->ScaleType.isValue("Custom")) { ui->sbScale->setEnabled(true); } else { @@ -171,8 +160,7 @@ void TaskSectionView::setUiEdit() sectionNormalVec.Normalize(); Base::Vector3d projectedViewDirection = m_base->projectPoint(sectionNormalVec, false); projectedViewDirection.Normalize(); - double viewAngle = atan2(-projectedViewDirection.y, - -projectedViewDirection.x); + double viewAngle = atan2(-projectedViewDirection.y, -projectedViewDirection.x); m_compass->setDialAngle(viewAngle * 180.0 / M_PI); m_viewDirectionWidget->setValueNoNotify(sectionNormalVec * -1.0); } @@ -180,7 +168,7 @@ void TaskSectionView::setUiEdit() void TaskSectionView::setUiCommon(Base::Vector3d origin) { std::string temp = m_base->getNameInDocument(); - QString qTemp = Base::Tools::fromStdString(temp); + QString qTemp = Base::Tools::fromStdString(temp); ui->leBaseView->setText(qTemp); ui->sbOrgX->setUnit(Base::Unit::Length); @@ -224,23 +212,23 @@ void TaskSectionView::setUiCommon(Base::Vector3d origin) m_viewDirectionWidget->setToolTip(QObject::tr("The view direction in BaseView coordinates")); auto editLayout = ui->viewDirectionLayout; editLayout->addWidget(m_viewDirectionWidget); - connect(m_viewDirectionWidget, SIGNAL(valueChanged(Base::Vector3d)), - this, SLOT(slotViewDirectionChanged(Base::Vector3d))); + connect(m_viewDirectionWidget, SIGNAL(valueChanged(Base::Vector3d)), this, + SLOT(slotViewDirectionChanged(Base::Vector3d))); } //save the start conditions void TaskSectionView::saveSectionState() { -// Base::Console().Message("TSV::saveSectionState()\n"); + // Base::Console().Message("TSV::saveSectionState()\n"); if (m_section) { m_saveSymbol = m_section->SectionSymbol.getValue(); - m_saveScale = m_section->getScale(); + m_saveScale = m_section->getScale(); m_saveScaleType = m_section->ScaleType.getValue(); m_saveNormal = m_section->SectionNormal.getValue(); m_normal = m_saveNormal; m_saveDirection = m_section->Direction.getValue(); - m_saveOrigin = m_section->SectionOrigin.getValue(); - m_saveDirName = m_section->SectionDirection.getValueAsString(); + m_saveOrigin = m_section->SectionOrigin.getValue(); + m_saveDirName = m_section->SectionDirection.getValueAsString(); m_saved = true; } } @@ -248,7 +236,7 @@ void TaskSectionView::saveSectionState() //restore the start conditions void TaskSectionView::restoreSectionState() { -// Base::Console().Message("TSV::restoreSectionState()\n"); + // Base::Console().Message("TSV::restoreSectionState()\n"); if (!m_section) return; @@ -264,12 +252,11 @@ void TaskSectionView::restoreSectionState() //the VectorEditWidget reports a change in direction void TaskSectionView::slotViewDirectionChanged(Base::Vector3d newDirection) { -// Base::Console().Message("TSV::slotViewDirectionChanged(%s)\n", -// DrawUtil::formatVector(newDirection).c_str()); + // Base::Console().Message("TSV::slotViewDirectionChanged(%s)\n", + // DrawUtil::formatVector(newDirection).c_str()); Base::Vector3d projectedViewDirection = m_base->projectPoint(newDirection, false); projectedViewDirection.Normalize(); - double viewAngle = atan2(projectedViewDirection.y, - projectedViewDirection.x); + double viewAngle = atan2(projectedViewDirection.y, projectedViewDirection.x); m_compass->setDialAngle(viewAngle * 180.0 / M_PI); checkAll(false); applyAligned(); @@ -278,7 +265,7 @@ void TaskSectionView::slotViewDirectionChanged(Base::Vector3d newDirection) //the CompassWidget reports that the view direction angle has changed void TaskSectionView::slotChangeAngle(double newAngle) { -// Base::Console().Message("TSV::slotChangeAngle(%.3f)\n", newAngle); + // Base::Console().Message("TSV::slotChangeAngle(%.3f)\n", newAngle); double angleRadians = newAngle * M_PI / 180.0; double unitX = cos(angleRadians); double unitY = sin(angleRadians); @@ -291,7 +278,7 @@ void TaskSectionView::slotChangeAngle(double newAngle) //preset view directions void TaskSectionView::onUpClicked() { -// Base::Console().Message("TSV::onUpClicked()\n"); + // Base::Console().Message("TSV::onUpClicked()\n"); checkAll(false); m_compass->setToNorth(); m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(0.0, 1.0, 0.0)); @@ -300,7 +287,7 @@ void TaskSectionView::onUpClicked() void TaskSectionView::onDownClicked() { -// Base::Console().Message("TSV::onDownClicked()\n"); + // Base::Console().Message("TSV::onDownClicked()\n"); checkAll(false); m_compass->setToSouth(); m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(0.0, -1.0, 0.0)); @@ -309,7 +296,7 @@ void TaskSectionView::onDownClicked() void TaskSectionView::onLeftClicked() { -// Base::Console().Message("TSV::onLeftClicked()\n"); + // Base::Console().Message("TSV::onLeftClicked()\n"); checkAll(false); m_compass->setToWest(); m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(-1.0, 0.0, 0.0)); @@ -318,7 +305,7 @@ void TaskSectionView::onLeftClicked() void TaskSectionView::onRightClicked() { -// Base::Console().Message("TSV::onRightClicked()\n"); + // Base::Console().Message("TSV::onRightClicked()\n"); checkAll(false); m_compass->setToEast(); m_viewDirectionWidget->setValueNoNotify(Base::Vector3d(1.0, 0.0, 0.0)); @@ -363,21 +350,25 @@ void TaskSectionView::scaleTypeChanged(int index) ui->sbScale->setValue(m_base->findParentPage()->Scale.getValue()); ui->sbScale->setEnabled(false); } - } else if (index == 1) { + } + else if (index == 1) { // Automatic Scale Type ui->sbScale->setEnabled(false); if (m_section) { ui->sbScale->setValue(m_section->autoScale()); } - } else if (index == 2) { + } + else if (index == 2) { // Custom Scale Type ui->sbScale->setEnabled(true); if (m_section) { ui->sbScale->setValue(m_section->Scale.getValue()); ui->sbScale->setEnabled(true); } - } else { - Base::Console().Log("Error - TaskSectionView::scaleTypeChanged - unknown scale type: %d\n", index); + } + else { + Base::Console().Log("Error - TaskSectionView::scaleTypeChanged - unknown scale type: %d\n", + index); return; } } @@ -400,7 +391,7 @@ void TaskSectionView::enableAll(bool enable) ui->cmbScaleType->setEnabled(enable); QString qScaleType = ui->cmbScaleType->currentText(); //Allow or prevent scale changing initially - if (qScaleType == QString::fromUtf8("Custom")) { + if (qScaleType == QString::fromUtf8("Custom")) { ui->sbScale->setEnabled(true); } else { @@ -408,24 +399,20 @@ void TaskSectionView::enableAll(bool enable) } } -void TaskSectionView::liveUpdateClicked() { - apply(true); -} +void TaskSectionView::liveUpdateClicked() { apply(true); } -void TaskSectionView::updateNowClicked() { - apply(true); -} +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); - if(!ui->cbLiveUpdate->isChecked() && - !forceUpdate) { + // 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++; - QString msgLiteral = QString::fromUtf8(QT_TRANSLATE_NOOP("TaskPojGroup", " updates pending")); + QString msgLiteral = + QString::fromUtf8(QT_TRANSLATE_NOOP("TaskPojGroup", " updates pending")); QString msgNumber = QString::number(m_applyDeferred); ui->lPendingUpdates->setText(msgNumber + msgLiteral); return false; @@ -447,7 +434,8 @@ bool TaskSectionView::apply(bool forceUpdate) if (isSectionValid()) { updateSectionView(); - } else { + } + else { failNoObject(); } @@ -467,7 +455,7 @@ bool TaskSectionView::apply(bool forceUpdate) void TaskSectionView::applyQuick(std::string dir) { -// Base::Console().Message("TSV::applyQuick(%s)\n", dir.c_str()); + // Base::Console().Message("TSV::applyQuick(%s)\n", dir.c_str()); m_dirName = dir; enableAll(true); apply(); @@ -475,7 +463,7 @@ void TaskSectionView::applyQuick(std::string dir) void TaskSectionView::applyAligned() { -// Base::Console().Message("TSV::applyAligned()\n"); + // Base::Console().Message("TSV::applyAligned()\n"); m_dirName = "Aligned"; enableAll(true); m_directionIsSet = true; @@ -488,7 +476,7 @@ void TaskSectionView::applyAligned() TechDraw::DrawViewSection* TaskSectionView::createSectionView(void) { -// Base::Console().Message("TSV::createSectionView()\n"); + // Base::Console().Message("TSV::createSectionView()\n"); if (!isBaseValid()) { failNoObject(); return nullptr; @@ -508,17 +496,15 @@ TechDraw::DrawViewSection* TaskSectionView::createSectionView(void) m_savePageName.c_str(), m_sectionName.c_str()); Command::doCommand(Command::Doc, "App.ActiveDocument.%s.BaseView = App.ActiveDocument.%s", m_sectionName.c_str(), baseName.c_str()); - Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Source = App.ActiveDocument.%s.Source", + Command::doCommand(Command::Doc, + "App.ActiveDocument.%s.Source = App.ActiveDocument.%s.Source", m_sectionName.c_str(), baseName.c_str()); Command::doCommand(Command::Doc, "App.ActiveDocument.%s.SectionOrigin = FreeCAD.Vector(%.6f, %.6f, %.6f)", - m_sectionName.c_str(), - ui->sbOrgX->value().getValue(), - ui->sbOrgY->value().getValue(), - ui->sbOrgZ->value().getValue()); + m_sectionName.c_str(), ui->sbOrgX->value().getValue(), + ui->sbOrgY->value().getValue(), ui->sbOrgZ->value().getValue()); Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Scale = %0.6f", - m_sectionName.c_str(), - ui->sbScale->value().getValue()); + m_sectionName.c_str(), ui->sbScale->value().getValue()); int scaleType = ui->cmbScaleType->currentIndex(); Command::doCommand(Command::Doc, "App.ActiveDocument.%s.ScaleType = %d", m_sectionName.c_str(), scaleType); @@ -536,7 +522,8 @@ TechDraw::DrawViewSection* TaskSectionView::createSectionView(void) //localUnit is a view direction so we need to reverse it to make a //section normal m_section->setCSFromBase(localUnit * -1.0); - } else { + } + else { //Note: DirectionName is to be deprecated in the future m_section->setCSFromBase(m_dirName.c_str()); } @@ -552,7 +539,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; @@ -564,25 +551,17 @@ void TaskSectionView::updateSectionView() m_sectionName.c_str(), m_dirName.c_str()); Command::doCommand(Command::Doc, "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(); + 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; + 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()); + 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()); + m_sectionName.c_str(), ui->sbScale->value().getValue()); int scaleType = ui->cmbScaleType->currentIndex(); Command::doCommand(Command::Doc, "App.ActiveDocument.%s.ScaleType = %d", m_sectionName.c_str(), scaleType); @@ -594,7 +573,8 @@ void TaskSectionView::updateSectionView() //localUnit is a view direction so we need to reverse it to make a //section normal m_section->setCSFromBase(localUnit * -1.0); - } else { + } + else { //Note: DirectionName is to be deprecated in the future m_section->setCSFromBase(m_dirName.c_str()); } @@ -656,21 +636,21 @@ double TaskSectionView::requiredRotation(double inputAngle) bool TaskSectionView::accept() { -// Base::Console().Message("TSV::accept()\n"); + // Base::Console().Message("TSV::accept()\n"); apply(true); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()"); return true; } bool TaskSectionView::reject() { -// Base::Console().Message("TSV::reject()\n"); - if (!m_section) { //no section created, nothing to undo + // Base::Console().Message("TSV::reject()\n"); + if (!m_section) {//no section created, nothing to undo Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()"); return false; } - if (!isSectionValid()) { //section !exist. nothing to undo + if (!isSectionValid()) {//section !exist. nothing to undo if (isBaseValid()) { m_base->requestPaint(); } @@ -683,10 +663,10 @@ bool TaskSectionView::reject() Gui::Command::doCommand(Gui::Command::Gui, "App.ActiveDocument.%s.removeView(App.ActiveDocument.%s)", m_savePageName.c_str(), SectionName.c_str()); - Gui::Command::doCommand(Gui::Command::Gui, - "App.ActiveDocument.removeObject('%s')", + Gui::Command::doCommand(Gui::Command::Gui, "App.ActiveDocument.removeObject('%s')", SectionName.c_str()); - } else { + } + else { if (m_modelIsDirty) { restoreSectionState(); m_section->recomputeFeature(); @@ -703,7 +683,7 @@ bool TaskSectionView::reject() return false; } -void TaskSectionView::changeEvent(QEvent *event) +void TaskSectionView::changeEvent(QEvent* event) { if (event->type() == QEvent::LanguageChange) { ui->retranslateUi(this); @@ -711,29 +691,27 @@ void TaskSectionView::changeEvent(QEvent *event) } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -TaskDlgSectionView::TaskDlgSectionView(TechDraw::DrawViewPart* base) : - TaskDialog() +TaskDlgSectionView::TaskDlgSectionView(TechDraw::DrawViewPart* base) : TaskDialog() { - widget = new TaskSectionView(base); - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_SectionView"), - widget->windowTitle(), true, nullptr); + widget = new TaskSectionView(base); + taskbox = + new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_SectionView"), + widget->windowTitle(), true, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } -TaskDlgSectionView::TaskDlgSectionView(TechDraw::DrawViewSection* section) : - TaskDialog() +TaskDlgSectionView::TaskDlgSectionView(TechDraw::DrawViewSection* section) : TaskDialog() { - widget = new TaskSectionView(section); - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_SectionView"), - widget->windowTitle(), true, nullptr); + widget = new TaskSectionView(section); + taskbox = + new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_SectionView"), + widget->windowTitle(), true, nullptr); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } -TaskDlgSectionView::~TaskDlgSectionView() -{ -} +TaskDlgSectionView::~TaskDlgSectionView() {} void TaskDlgSectionView::update() { @@ -741,9 +719,7 @@ void TaskDlgSectionView::update() } //==== calls from the TaskView =============================================================== -void TaskDlgSectionView::open() -{ -} +void TaskDlgSectionView::open() {} bool TaskDlgSectionView::accept() { diff --git a/src/Mod/TechDraw/Gui/Widgets/CompassWidget.cpp b/src/Mod/TechDraw/Gui/Widgets/CompassWidget.cpp index 6c2c768d1486e..0f068ef88cd93 100644 --- a/src/Mod/TechDraw/Gui/Widgets/CompassWidget.cpp +++ b/src/Mod/TechDraw/Gui/Widgets/CompassWidget.cpp @@ -21,8 +21,8 @@ ***************************************************************************/ // The CompassWidget has several children widgets - a CompassDialWidget, a fine -// adjustment QDoubleSpinBox and a QPushButton that acts as an enter key -// for the spin box. +// adjustment QDoubleSpinBox and QPushButtons that increment the spin box by a +// (usually) larger step than the arrows on the spinbox #include "PreCompiled.h" #ifndef _PreComp_ @@ -45,7 +45,7 @@ using namespace TechDrawGui; -CompassWidget::CompassWidget(QWidget *parent) +CompassWidget::CompassWidget(QWidget* parent) : QWidget(parent), m_minimumWidth(200), m_minimumHeight(200), m_defaultMargin(10), m_angle(0.0), m_advanceIncrement(10.0) { @@ -54,7 +54,6 @@ CompassWidget::CompassWidget(QWidget *parent) buildWidget(); compassDial->setSize(m_minimumHeight - 2 * m_defaultMargin); - connect(pbUseCompassSetting, &QPushButton::pressed, this, &CompassWidget::slotUseSpinboxValue); dsbAngle->installEventFilter(this); connect(pbCWAdvance, &QPushButton::pressed, this, &CompassWidget::slotCWAdvance); @@ -62,17 +61,22 @@ CompassWidget::CompassWidget(QWidget *parent) } //trap Enter press in dsbAngle so as not to invoke task accept processing -bool CompassWidget::eventFilter(QObject *target, QEvent *event) +bool CompassWidget::eventFilter(QObject* target, QEvent* event) { if (target == dsbAngle) { if (event->type() == QEvent::KeyPress) { - QKeyEvent *keyEvent = static_cast(event); + QKeyEvent* keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) { dsbAngle->interpretText(); slotSpinBoxEnter(dsbAngle->value()); return true; } } + else if (event->type() == QEvent::FocusOut) { + dsbAngle->interpretText(); + slotSpinBoxEnter(dsbAngle->value()); + return true; + } } return QWidget::eventFilter(target, event); } @@ -140,15 +144,6 @@ void CompassWidget::buildWidget() compassControlLayout->addWidget(dsbAngle); - pbUseCompassSetting = new QPushButton(this); - pbUseCompassSetting->setObjectName(QString::fromUtf8("pbUseCompassSetting")); - QIcon icon; - icon.addFile(QString::fromUtf8(":/icons/edit_OK.svg"), QSize(), QIcon::Normal, QIcon::On); - pbUseCompassSetting->setIcon(icon); - pbUseCompassSetting->setText(QString()); - - compassControlLayout->addWidget(pbUseCompassSetting); - compassControlLayout->setStretch(0, 3); compassControlLayout->setStretch(1, 2); @@ -164,8 +159,6 @@ void CompassWidget::retranslateUi() #ifndef QT_NO_TOOLTIP dsbAngle->setToolTip(QApplication::translate( "CompassWidget", "The view direction angle relative to +X in the BaseView.", nullptr)); - pbUseCompassSetting->setToolTip(QApplication::translate( - "CompassWidget", "Use the current view direction to set the Section Normal.", nullptr)); pbCWAdvance->setToolTip(QApplication::translate( "CompassWidget", "Advance the view direction in clockwise direction.", nullptr)); pbCCWAdvance->setToolTip(QApplication::translate( @@ -180,7 +173,7 @@ QSize CompassWidget::minimumSizeHint() const return QRect(0, 0, m_minimumWidth, m_minimumHeight).size(); } -void CompassWidget::paintEvent(QPaintEvent *event) +void CompassWidget::paintEvent(QPaintEvent* event) { Q_UNUSED(event); QWidget::paintEvent(event); @@ -199,17 +192,6 @@ void CompassWidget::setDialAngle(double newAngle) } } -//slot for updates from spinbox arrows or typing. -void CompassWidget::slotSpinBoxUpdate(double newAngle) -{ - // Base::Console().Message("CW::slotSpinBoxUpdate(%.3f)\n", newAngle); - m_angle = newAngle; - Q_EMIT angleChanged(m_angle); - if (compassDial) { - compassDial->setAngle(m_angle); - } -} - //slot for updates from spinbox on Enter/Return press. void CompassWidget::slotSpinBoxEnter(double newAngle) { @@ -223,20 +205,6 @@ void CompassWidget::slotSpinBoxEnter(double newAngle) } } -//slot for OK button press -void CompassWidget::slotUseSpinboxValue() -{ - // Base::Console().Message("CW::slotUseSpinboxValue()\n"); - if (dsbAngle) { - dsbAngle->interpretText(); - m_angle = dsbAngle->value(); - Q_EMIT angleChanged(m_angle); - } - if (compassDial) { - compassDial->setAngle(m_angle); - } -} - void CompassWidget::slotCWAdvance() { double angle = m_angle - m_advanceIncrement; @@ -259,4 +227,3 @@ void CompassWidget::slotCCWAdvance() } void CompassWidget::setAdvanceIncrement(double newIncrement) { m_advanceIncrement = newIncrement; } - diff --git a/src/Mod/TechDraw/Gui/Widgets/CompassWidget.h b/src/Mod/TechDraw/Gui/Widgets/CompassWidget.h index 25858ac494b60..7a6b1fda82880 100644 --- a/src/Mod/TechDraw/Gui/Widgets/CompassWidget.h +++ b/src/Mod/TechDraw/Gui/Widgets/CompassWidget.h @@ -25,8 +25,8 @@ #include #include -#include #include +#include QT_BEGIN_NAMESPACE class QLabel; @@ -35,14 +35,15 @@ class QPushButton; class QVBoxLayout; QT_END_NAMESPACE -namespace TechDrawGui { +namespace TechDrawGui +{ class CompassDialWidget; -class CompassWidget : public QWidget +class CompassWidget: public QWidget { Q_OBJECT - Q_PROPERTY( double angle READ dialAngle WRITE setDialAngle NOTIFY angleChanged) + Q_PROPERTY(double angle READ dialAngle WRITE setDialAngle NOTIFY angleChanged) public: CompassWidget(QWidget* parent = 0); @@ -50,7 +51,7 @@ class CompassWidget : public QWidget QSize sizeHint() const override; QSize minimumSizeHint() const override; - bool eventFilter(QObject *target, QEvent *event) override; + bool eventFilter(QObject* target, QEvent* event) override; void retranslateUi(); double dialAngle() const { return m_angle; } double value() const { return m_angle; } @@ -65,13 +66,11 @@ class CompassWidget : public QWidget public Q_SLOTS: void slotChangeAngle(double angle) { setDialAngle(angle); } - void slotSpinBoxUpdate(double newAngle); void slotSpinBoxEnter(double newAngle); - void slotUseSpinboxValue(); - void resetAngle() { setDialAngle(0.0); } //conventional angles - void setToEast() { setDialAngle(0.0); } + void resetAngle() { setDialAngle(0.0); }//conventional angles + void setToEast() { setDialAngle(0.0); } void setToNorth() { setDialAngle(90.0); } - void setToWest() { setDialAngle(180.0); } + void setToWest() { setDialAngle(180.0); } void setToSouth() { setDialAngle(270.0); } void slotCWAdvance(); void slotCCWAdvance(); @@ -94,14 +93,12 @@ public Q_SLOTS: QHBoxLayout* compassControlLayout; CompassDialWidget* compassDial; -// DoubleSpinBoxNoEnter* dsbAngle; + // DoubleSpinBoxNoEnter* dsbAngle; QDoubleSpinBox* dsbAngle; QLabel* compassControlLabel; - QPushButton* pbUseCompassSetting; QPushButton* pbCWAdvance; QPushButton* pbCCWAdvance; }; -} //namespace TechDrawGui -#endif // COMPASSWIDGET_H - +}//namespace TechDrawGui +#endif// COMPASSWIDGET_H