[TD]dialog fixes from user testing

- fix jumping direction field in dialogs

- apply default rotation to simple sections

- fix rounding error in vector widget

- remove "enter" button on CompassWidget

- add lost focus trap in event filter.

[TD]prevent recompute on cancel without change
This commit is contained in:
wandererfan
2022-12-06 22:13:32 -05:00
committed by WandererFan
parent 5f3c61762c
commit e059e32d40
8 changed files with 382 additions and 378 deletions

View File

@@ -22,9 +22,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QMessageBox>
# include <gp_Pnt.hxx>
#endif // #ifndef _PreComp_
#include <QMessageBox>
#include <gp_Pnt.hxx>
#endif// #ifndef _PreComp_
#include <App/Document.h>
#include <App/Link.h>
@@ -37,26 +37,26 @@
#include <Gui/Selection.h>
#include <Gui/WaitCursor.h>
#include "Widgets/CompassWidget.h"
#include "Widgets/VectorEditWidget.h"
#include <Mod/TechDraw/App/DrawComplexSection.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include <Mod/TechDraw/App/Preferences.h>
#include "Widgets/CompassWidget.h"
#include "Widgets/VectorEditWidget.h"
#include "DrawGuiUtil.h"
#include "TaskComplexSection.h"
#include "ui_TaskComplexSection.h"
#include "DrawGuiUtil.h"
using namespace Gui;
using namespace TechDraw;
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<App::DocumentObject*> shapes,
std::vector<App::DocumentObject*> xShapes,
App::DocumentObject* profileObject,
@@ -73,7 +73,8 @@ TaskComplexSection::TaskComplexSection(TechDraw::DrawPage* page,
m_createMode(true),
m_applyDeferred(0),
m_angle(0.0),
m_directionIsSet(false)
m_directionIsSet(false),
m_modelIsDirty(false)
{
m_sectionName = std::string();
if (m_page) {
@@ -88,8 +89,8 @@ 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
@@ -103,14 +104,15 @@ TaskComplexSection::TaskComplexSection(TechDraw::DrawComplexSection* complexSect
m_createMode(false),
m_applyDeferred(0),
m_angle(0.0),
m_directionIsSet(true)
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<TechDraw::DrawViewPart*> (m_section->BaseView.getValue());
m_baseView = dynamic_cast<TechDraw::DrawViewPart*>(m_section->BaseView.getValue());
if (m_baseView) {
m_saveBaseName = m_baseView->getNameInDocument();
}
@@ -124,8 +126,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());
}
@@ -135,7 +137,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());
}
@@ -149,24 +152,25 @@ void TaskComplexSection::setUiPrimary()
//one is picked in the dialog
Base::Vector3d defaultNormal(-1.0, 0.0, 0.0);
m_saveNormal = defaultNormal;
m_localUnit = 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<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
m_saveNormal = dirs.first;
m_localUnit = 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);
}
@@ -188,11 +192,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->setValue(projectedViewDirection * -1.0);
} else {
m_viewDirectionWidget->setValueNoNotify(projectedViewDirection * -1.0);
}
else {
//no local angle makes sense if there is no baseView?
m_viewDirectionWidget->setValue(sectionNormalVec * -1.0);
}
@@ -201,9 +205,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;
@@ -211,9 +215,11 @@ void TaskComplexSection::setUiCommon()
m_viewDirectionWidget = new VectorEditWidget(this);
m_viewDirectionWidget->setLabel(QObject::tr("Current View Direction"));
m_viewDirectionWidget->setToolTip(QObject::tr("The view direction in BaseView coordinates"));
auto editLayout = ui->viewDirectionLayout;
editLayout->addWidget(m_viewDirectionWidget);
connect(m_compass, SIGNAL(angleChanged(double)), this, SLOT(slotChangeAngle(double)));
connect(ui->pbUp, SIGNAL(clicked(bool)), this, SLOT(onUpClicked()));
@@ -224,28 +230,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_localUnit = m_saveNormal;
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) {
@@ -257,7 +264,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;
@@ -277,11 +284,12 @@ void TaskComplexSection::onSectionObjectsUseSelectionClicked()
std::vector<App::DocumentObject*> newSelection;
std::vector<App::DocumentObject*> 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());
}
}
@@ -293,68 +301,67 @@ 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(projectedViewDirection);
applyAligned();
}
//the CompassWidget reports the view direction. This is the reverse of the
//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);
Base::Vector3d localUnit(unitX, unitY, 0.0);
m_viewDirectionWidget->setValue(localUnit);
m_viewDirectionWidget->setValueNoNotify(localUnit);
checkAll(false);
applyAligned(localUnit);
applyAligned();
}
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));
applyAligned(Base::Vector3d(0.0, 1.0, 0.0));
applyAligned();
}
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));
applyAligned(Base::Vector3d(0.0, -1.0, 0.0));
applyAligned();
}
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));
applyAligned(Base::Vector3d(-1.0, 0.0, 0.0));
applyAligned();
}
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));
applyAligned(Base::Vector3d(1.0, 0.0, 0.0));
applyAligned();
}
void TaskComplexSection::onIdentifierChanged()
@@ -375,9 +382,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)
@@ -389,21 +397,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;
}
}
@@ -423,22 +435,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()
{
@@ -447,32 +454,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;
@@ -481,27 +481,34 @@ 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;
}
Base::Vector3d localUnit = m_viewDirectionWidget->value();
if (m_baseView) {
if (!DrawComplexSection::canBuild(m_baseView->localVectorToCS(m_localUnit), m_profileObject)) {
Base::Console().Error("Can not build Complex Section with this profile and direction\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\n");
Base::Console().Error(
"Can not build Complex Section with this profile and direction (2)\n");
return false;
}
}
@@ -513,7 +520,8 @@ bool TaskComplexSection::apply(bool forceUpdate)
if (isSectionValid()) {
updateComplexSection();
} else {
}
else {
failNoObject();
}
@@ -531,12 +539,10 @@ bool TaskComplexSection::apply(bool forceUpdate)
return true;
}
void TaskComplexSection::applyAligned(Base::Vector3d localUnit)
void TaskComplexSection::applyAligned()
{
// Base::Console().Message("TCS::applyAligned(%s)\n",
// DrawUtil::formatVector(localUnit).c_str());
// Base::Console().Message("TCS::applyAligned()\n");
m_dirName = "Aligned";
m_localUnit = localUnit;
enableAll(true);
m_directionIsSet = true;
ui->pbUpdateNow->setEnabled(true);
@@ -549,7 +555,7 @@ void TaskComplexSection::applyAligned(Base::Vector3d localUnit)
//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) {
@@ -561,22 +567,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);
@@ -584,31 +584,36 @@ 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<TechDraw::DrawComplexSection*>(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(m_localUnit * -1.0);
m_section->setCSFromBase(localUnit * -1.0);
m_section->Source.setValues(m_baseView->Source.getValues());
m_section->XSource.setValues(m_baseView->XSource.getValues());
} else {
//if we have not changed the direction, we should use the 3d directions saved in the
//constructor
if (m_localUnit.IsEqual(m_saveNormal, EWTOLERANCE)) {
}
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 {
//if we have not changed the direction, we should use the 3d directions saved in the
//constructor
m_section->SectionNormal.setValue(m_saveNormal);
m_section->XDirection.setValue(m_saveXDir);
} else {
//if we have changed the direction, use the local unit to create a CS
m_section->setCSFromLocalUnit(m_localUnit * -1.0);
}
m_section->Source.setValues(m_shapes);
m_section->XSource.setValues(m_xShapes);
@@ -623,7 +628,7 @@ void TaskComplexSection::createComplexSection()
void TaskComplexSection::updateComplexSection()
{
// Base::Console().Message("TCS:;updateComplexSection()\n");
// Base::Console().Message("TCS:;updateComplexSection()\n");
if (!isSectionValid()) {
failNoObject();
return;
@@ -631,22 +636,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);
@@ -654,14 +653,16 @@ 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");
m_section->setCSFromBase(m_localUnit * -1.0);
Base::Vector3d localUnit = m_viewDirectionWidget->value();
m_section->setCSFromBase(localUnit * -1.0);
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);
@@ -705,20 +706,20 @@ bool TaskComplexSection::isSectionValid()
//******************************************************************************
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();
}
@@ -731,13 +732,14 @@ 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 {
restoreSectionState();
m_section->recomputeFeature();
m_section->requestPaint();
if (m_modelIsDirty) {
restoreSectionState();
m_section->recomputeFeature();
m_section->requestPaint();
}
}
if (isBaseValid()) {
@@ -758,16 +760,17 @@ void TaskComplexSection::changeEvent(QEvent* event)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TaskDlgComplexSection::TaskDlgComplexSection(TechDraw::DrawPage* page,
TechDraw::DrawViewPart *baseView,
TechDraw::DrawViewPart* baseView,
std::vector<App::DocumentObject*> shapes,
std::vector<App::DocumentObject*> xShapes,
App::DocumentObject* profileObject,
std::vector<std::string> 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);
}
@@ -775,26 +778,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()
{

View File

@@ -75,7 +75,7 @@ protected:
bool apply(bool forceUpdate = false);
void applyQuick(std::string dir);
void applyAligned(Base::Vector3d localUnit);
void applyAligned();
void setUiPrimary();
void setUiEdit();
@@ -137,11 +137,11 @@ private:
Base::Vector3d m_normal;
int m_applyDeferred;
Base::Vector3d m_localUnit;
CompassWidget* m_compass;
double m_angle;
VectorEditWidget* m_viewDirectionWidget;
bool m_directionIsSet;
bool m_modelIsDirty;
};

View File

@@ -22,10 +22,12 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cmath>
# include <QMessageBox>
#endif // #ifndef _PreComp_
#include <QMessageBox>
#include <cmath>
#endif// #ifndef _PreComp_
#include "Widgets/CompassWidget.h"
#include "Widgets/VectorEditWidget.h"
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Base/Console.h>
@@ -40,11 +42,11 @@
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include <Mod/TechDraw/App/DrawViewSection.h>
#include "Widgets/CompassWidget.h"
#include "Widgets/VectorEditWidget.h"
// clang-format off
#include "ui_TaskSectionView.h"
#include "TaskSectionView.h"
// clang-format on
using namespace Gui;
@@ -62,12 +64,13 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base) :
m_createMode(true),
m_saved(false),
m_applyDeferred(0),
m_directionIsSet(false)
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();
@@ -75,8 +78,8 @@ 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
@@ -89,7 +92,8 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewSection* section) :
m_createMode(false),
m_saved(false),
m_applyDeferred(0),
m_directionIsSet(true)
m_directionIsSet(true),
m_modelIsDirty(false)
{
//existence of section is guaranteed by ViewProviderViewSection.setEdit
@@ -110,21 +114,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 {
@@ -134,18 +138,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);
@@ -154,7 +160,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 {
@@ -166,17 +172,18 @@ void TaskSectionView::setUiEdit()
// convert section normal to view angle
Base::Vector3d sectionNormalVec = m_section->SectionNormal.getValue();
sectionNormalVec.Normalize();
Base::Vector3d projectedViewDirection = m_base->projectPoint(sectionNormalVec, false);
double viewAngle = atan2(-projectedViewDirection.y,
-projectedViewDirection.x);
projectedViewDirection.Normalize();
double viewAngle = atan2(-projectedViewDirection.y, -projectedViewDirection.x);
m_compass->setDialAngle(viewAngle * 180.0 / M_PI);
m_viewDirectionWidget->setValue(sectionNormalVec * -1.0);
m_viewDirectionWidget->setValueNoNotify(sectionNormalVec * -1.0);
}
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);
@@ -217,25 +224,26 @@ void TaskSectionView::setUiCommon(Base::Vector3d origin)
m_viewDirectionWidget = new VectorEditWidget(this);
m_viewDirectionWidget->setLabel(QObject::tr("Current View Direction"));
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;
}
}
@@ -243,7 +251,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;
@@ -259,64 +267,64 @@ 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(projectedViewDirection);
applyAligned();
}
//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);
Base::Vector3d localUnit(unitX, unitY, 0.0);
m_viewDirectionWidget->setValueNoNotify(localUnit);
checkAll(false);
applyAligned(localUnit);
applyAligned();
}
//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));
applyAligned(Base::Vector3d(0.0, 1.0, 0.0));}
applyAligned();
}
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));
applyAligned(Base::Vector3d(0.0, -1.0, 0.0));
applyAligned();
}
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));
applyAligned(Base::Vector3d(-1.0, 0.0, 0.0));
applyAligned();
}
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));
applyAligned(Base::Vector3d(1.0, 0.0, 0.0));
applyAligned();
}
void TaskSectionView::onIdentifierChanged()
@@ -357,21 +365,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;
}
}
@@ -394,7 +406,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 {
@@ -402,30 +414,28 @@ 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;
}
Gui::WaitCursor wc;
m_modelIsDirty = true;
if (m_dirName.empty()) {
//this should never happen
std::string msg =
@@ -439,7 +449,8 @@ bool TaskSectionView::apply(bool forceUpdate)
if (isSectionValid()) {
updateSectionView();
} else {
}
else {
failNoObject();
}
@@ -459,17 +470,16 @@ 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();
}
void TaskSectionView::applyAligned(Base::Vector3d localUnit)
void TaskSectionView::applyAligned()
{
// Base::Console().Message("TSV::applyAligned()\n");
// Base::Console().Message("TSV::applyAligned()\n");
m_dirName = "Aligned";
m_localUnit = localUnit;
enableAll(true);
m_directionIsSet = true;
ui->pbUpdateNow->setEnabled(true);
@@ -481,7 +491,7 @@ void TaskSectionView::applyAligned(Base::Vector3d localUnit)
TechDraw::DrawViewSection* TaskSectionView::createSectionView(void)
{
// Base::Console().Message("TSV::createSectionView()\n");
// Base::Console().Message("TSV::createSectionView()\n");
if (!isBaseValid()) {
failNoObject();
return nullptr;
@@ -501,17 +511,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);
@@ -523,14 +531,22 @@ TechDraw::DrawViewSection* TaskSectionView::createSectionView(void)
if (!newObj || !m_section) {
throw Base::RuntimeError("TaskSectionView - new section object not found");
}
Base::Vector3d localUnit = m_viewDirectionWidget->value();
localUnit.Normalize();
if (m_dirName == "Aligned") {
//m_localUnit is a view direction so we need to reverse it to make a
//localUnit is a view direction so we need to reverse it to make a
//section normal
m_section->setCSFromBase(m_localUnit * -1.0);
} else {
m_section->setCSFromBase(localUnit * -1.0);
}
else {
//Note: DirectionName is to be deprecated in the future
m_section->setCSFromBase(m_dirName.c_str());
}
//auto orientation of view relative to base view
double viewDirectionAngle = m_compass->positiveValue();
double rotation = requiredRotation(viewDirectionAngle);
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Rotation = %.6f",
m_sectionName.c_str(), rotation);
}
Gui::Command::commitCommand();
return m_section;
@@ -538,7 +554,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;
@@ -550,39 +566,38 @@ 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);
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.SectionDirection = '%s'",
m_sectionName.c_str(), m_dirName.c_str());
Base::Vector3d localUnit = m_viewDirectionWidget->value();
localUnit.Normalize();
if (m_dirName == "Aligned") {
//m_localUnit is a view direction so we need to reverse it to make a
//localUnit is a view direction so we need to reverse it to make a
//section normal
m_section->setCSFromBase(m_localUnit * -1.0);
} else {
m_section->setCSFromBase(localUnit * -1.0);
}
else {
//Note: DirectionName is to be deprecated in the future
m_section->setCSFromBase(m_dirName.c_str());
}
//auto orientation of view relative to base view
double viewDirectionAngle = m_compass->positiveValue();
double rotation = requiredRotation(viewDirectionAngle);
Command::doCommand(Command::Doc, "App.ActiveDocument.%s.Rotation = %.6f",
m_sectionName.c_str(), rotation);
}
Gui::Command::commitCommand();
}
@@ -620,25 +635,37 @@ bool TaskSectionView::isSectionValid()
return true;
}
//get required rotation from input angle in [0, 360]
double TaskSectionView::requiredRotation(double inputAngle)
{
double rotation = inputAngle - 90.0;
if (rotation == 180.0) {
//if the view direction is 90/270, then the section is drawn properly and no
//rotation is needed. 90.0 becomes 0.0, but 270.0 needs special handling.
rotation = 0.0;
}
return rotation;
}
//******************************************************************************
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();
}
@@ -651,13 +678,15 @@ 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 {
restoreSectionState();
m_section->recomputeFeature();
m_section->requestPaint();
if (m_modelIsDirty) {
restoreSectionState();
m_section->recomputeFeature();
m_section->requestPaint();
}
}
if (isBaseValid()) {
@@ -669,7 +698,7 @@ bool TaskSectionView::reject()
return false;
}
void TaskSectionView::changeEvent(QEvent *event)
void TaskSectionView::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
@@ -677,29 +706,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()
{
@@ -707,9 +734,7 @@ void TaskDlgSectionView::update()
}
//==== calls from the TaskView ===============================================================
void TaskDlgSectionView::open()
{
}
void TaskDlgSectionView::open() {}
bool TaskDlgSectionView::accept()
{

View File

@@ -60,7 +60,7 @@ protected:
bool apply(bool forceUpdate = false);
void applyQuick(std::string dir);
void applyAligned(Base::Vector3d localUnit);
void applyAligned();
TechDraw::DrawViewSection* createSectionView();
void updateSectionView();
@@ -93,6 +93,8 @@ protected Q_SLOTS:
void slotViewDirectionChanged(Base::Vector3d newDirection);
private:
double requiredRotation(double inputAngle);
std::unique_ptr<Ui_TaskSectionView> ui;
TechDraw::DrawViewPart* m_base;
TechDraw::DrawViewSection* m_section;
@@ -121,10 +123,10 @@ private:
std::string m_savePageName;
int m_applyDeferred;
Base::Vector3d m_localUnit;
CompassWidget* m_compass;
VectorEditWidget* m_viewDirectionWidget;
bool m_directionIsSet;
bool m_modelIsDirty;
};
class TaskDlgSectionView : public Gui::TaskView::TaskDialog

View File

@@ -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<QKeyEvent *>(event);
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(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;
@@ -249,7 +217,13 @@ void CompassWidget::slotCWAdvance()
void CompassWidget::slotCCWAdvance()
{
double angle = m_angle + m_advanceIncrement;
setDialAngle(fmod(angle, 360.0));
if (angle > dsbAngle->maximum()) {
angle = angle - dsbAngle->maximum();
}
if (angle < dsbAngle->minimum()) {
angle = angle + dsbAngle->minimum();
}
setDialAngle(angle);
}
void CompassWidget::setAdvanceIncrement(double newIncrement) { m_advanceIncrement = newIncrement; }

View File

@@ -25,8 +25,8 @@
#include <QDoubleSpinBox>
#include <QKeyEvent>
#include <QWidget>
#include <QSize>
#include <QWidget>
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,9 +51,11 @@ public:
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; }
double positiveValue() { return m_angle < 0.0 ? m_angle + 360.0 : m_angle; }
void setDialAngle(double newAngle);
void setAdvanceIncrement(double newIncrement);
double advanceIncrement() const { return m_advanceIncrement; }
@@ -63,13 +66,11 @@ Q_SIGNALS:
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();
@@ -92,14 +93,12 @@ private:
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

View File

@@ -66,9 +66,9 @@ VectorEditWidget::VectorEditWidget(QWidget* parent) : QWidget(parent),
buildWidget();
connect(tbExpand, SIGNAL(toggled(bool)), this, SLOT(slotExpandButtonToggled(bool)));
connect(dsbX, SIGNAL(valueChanged(double)), this, SLOT(xValueChanged(double)));
connect(dsbY, SIGNAL(valueChanged(double)), this, SLOT(yValueChanged(double)));
connect(dsbZ, SIGNAL(valueChanged(double)), this, SLOT(zValueChanged(double)));
connect(dsbX, SIGNAL(valueChanged(double)), this, SLOT(slotXValueChanged(double)));
connect(dsbY, SIGNAL(valueChanged(double)), this, SLOT(slotYValueChanged(double)));
connect(dsbZ, SIGNAL(valueChanged(double)), this, SLOT(slotZValueChanged(double)));
dsbX->installEventFilter(this);
dsbY->installEventFilter(this);
@@ -107,7 +107,7 @@ void VectorEditWidget::setLabel(QString newLabel)
void VectorEditWidget::setValue(Base::Vector3d newValue)
{
// Base::Console().Message("VEW::setValue(%s)\n", DrawUtil::formatVector(newValue).c_str());
// Base::Console().Message("VEW::setValue(%.6f, %.6f, %.6f)\n", newValue.x, newValue.y, newValue.z);
m_value = newValue;
dsbX->setValue(m_value.x);
dsbY->setValue(m_value.y);
@@ -117,7 +117,7 @@ void VectorEditWidget::setValue(Base::Vector3d newValue)
void VectorEditWidget::setValueNoNotify(Base::Vector3d newValue)
{
// Base::Console().Message("VEW::setValue(%s)\n", DrawUtil::formatVector(newValue).c_str());
// Base::Console().Message("VEW::setValueNoNotify(%.6f, %.6f, %.6f)\n", newValue.x, newValue.y, newValue.z);
m_value = newValue;
m_blockNotify = true;
dsbX->setValue(m_value.x);
@@ -142,30 +142,35 @@ void VectorEditWidget::slotExpandButtonToggled(bool checked)
}
}
void VectorEditWidget::xValueChanged(double newValue)
//slotXValueChanged can be triggered by the Ui or programmatically. We only want
//to tell the world about the change if it comes from the Ui.
void VectorEditWidget::slotXValueChanged(double newValue)
{
// Base::Console().Message("VEW::xValueChanged(%.3f)\n", newValue);
m_value.x = newValue;
updateDisplay();
// Base::Console().Message("VEW::xValueChanged(%.6f) - m_value.x: %.6f\n", newValue, m_value.x);
if (!m_blockNotify) {
//this is a change from the dsb
m_value.x = newValue;
updateDisplay();
Q_EMIT valueChanged(m_value);
}
}
void VectorEditWidget::yValueChanged(double newValue)
void VectorEditWidget::slotYValueChanged(double newValue)
{
// Base::Console().Message("VEW::yValueChanged(%.3f)\n", newValue);
m_value.y = newValue;
updateDisplay();
// Base::Console().Message("VEW::yValueChanged(%.6f) - m_value.y: %.6f\n", newValue, m_value.y);
if (!m_blockNotify) {
//this is a change from the dsb
m_value.y = newValue;
updateDisplay();
Q_EMIT valueChanged(m_value);
}
}
void VectorEditWidget::zValueChanged(double newValue)
void VectorEditWidget::slotZValueChanged(double newValue)
{
// Base::Console().Message("VEW::zValueChanged(%.3f)\n", newValue);
m_value.z = newValue;
updateDisplay();
// Base::Console().Message("VEW::zValueChanged(%.6f)\n", newValue);
if (!m_blockNotify) {
//this is a change from the dsb
m_value.z = newValue;
updateDisplay();
Q_EMIT valueChanged(m_value);
}
}
@@ -262,4 +267,3 @@ void VectorEditWidget::buildWidget()
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
}

View File

@@ -72,9 +72,9 @@ protected:
protected Q_SLOTS:
void slotExpandButtonToggled(bool checked);
void xValueChanged(double newValue);
void yValueChanged(double newValue);
void zValueChanged(double newValue);
void slotXValueChanged(double newValue);
void slotYValueChanged(double newValue);
void slotZValueChanged(double newValue);
void updateDisplay();