diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 575c21d2b6..1c2bb4a1ad 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -192,6 +192,7 @@ void DrawViewSection::onChanged(const App::Property* prop) App::DocumentObjectExecReturn *DrawViewSection::execute(void) { +// Base::Console().Message("DVS::execute() - %s \n", getNameInDocument()); if (!keepUpdated()) { return App::DocumentObject::StdReturn; } @@ -532,6 +533,14 @@ bool DrawViewSection::isReallyInBox (const gp_Pnt p, const Bnd_Box& bb) const return !bb.IsOut(p); } +void DrawViewSection::setNormalFromBase(const std::string sectionName) +{ +// Base::Console().Message("DVS::setNormalFromBase(%s)\n", sectionName.c_str()); + Base::Vector3d normal = getSectionVector(sectionName); + Direction.setValue(normal); + SectionNormal.setValue(normal); +} + //! calculate the section Normal/Projection Direction given section name //TODO: this should take base view rotation into account. Base::Vector3d DrawViewSection::getSectionVector (const std::string sectionName) diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index 4acac38ac4..d1a9a91b7b 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -87,6 +87,8 @@ public: std::vector getFaceGeometry(); Base::Vector3d getSectionVector (const std::string sectionName); + void setNormalFromBase(const std::string sectionName); + gp_Ax2 rotateCSCardinal(gp_Ax2 oldCS, int cardinal); gp_Ax2 rotateCSArbitrary(gp_Ax2 oldCS, Base::Vector3d axis, diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 208ca310db..e6bf3f8deb 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -393,27 +393,27 @@ void CmdTechDrawNewViewSection::activated(int iMsg) return; } TechDraw::DrawViewPart* dvp = static_cast(*baseObj.begin()); - std::string BaseName = dvp->getNameInDocument(); - std::string PageName = page->getNameInDocument(); - double baseScale = dvp->getScale(); +// std::string BaseName = dvp->getNameInDocument(); +// std::string PageName = page->getNameInDocument(); +// double baseScale = dvp->getScale(); - Gui::WaitCursor wc; - openCommand("Create view"); - std::string FeatName = getUniqueObjectName("Section"); +// Gui::WaitCursor wc; +// openCommand("Create view"); +// std::string FeatName = getUniqueObjectName("Section"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSection','%s')",FeatName.c_str()); +// doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSection','%s')",FeatName.c_str()); - App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str()); - TechDraw::DrawViewSection* dsv = dynamic_cast(docObj); - if (!dsv) { - throw Base::TypeError("CmdTechDrawNewViewSection DVS not found\n"); - } - dsv->Source.setValues(dvp->Source.getValues()); - doCommand(Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s",FeatName.c_str(),BaseName.c_str()); - doCommand(Doc,"App.activeDocument().%s.ScaleType = App.activeDocument().%s.ScaleType",FeatName.c_str(),BaseName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Scale = %0.6f",FeatName.c_str(),baseScale); - Gui::Control().showDialog(new TaskDlgSectionView(dvp,dsv)); +// App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str()); +// TechDraw::DrawViewSection* dsv = dynamic_cast(docObj); +// if (!dsv) { +// throw Base::TypeError("CmdTechDrawNewViewSection DVS not found\n"); +// } +// dsv->Source.setValues(dvp->Source.getValues()); +// doCommand(Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s",FeatName.c_str(),BaseName.c_str()); +// doCommand(Doc,"App.activeDocument().%s.ScaleType = App.activeDocument().%s.ScaleType",FeatName.c_str(),BaseName.c_str()); +// doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); +// doCommand(Doc,"App.activeDocument().%s.Scale = %0.6f",FeatName.c_str(),baseScale); + Gui::Control().showDialog(new TaskDlgSectionView(dvp)); updateActive(); //ok here since dialog doesn't call doc.recompute() commitCommand(); diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/section-down.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/section-down.svg index 7fe7fec52c..a48f0e4de0 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/actions/section-down.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/section-down.svg @@ -1,65 +1,266 @@ - - - + + + + + + + - - - - + + + + + + + + + + - - + + - - + + - - - + + + + + + + + + + + + + + + + + + + + - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + - + image/svg+xml - - + + [WandererFan] - section-down + section-right 2016-10-06 http://www.freecadweb.org/wiki/index.php?title=Artwork @@ -67,7 +268,7 @@ FreeCAD - FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/actions/section-down.svg + FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/actions/section-right.svg FreeCAD LGPL2+ @@ -82,14 +283,56 @@ - - - - - - - - + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/section-left.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/section-left.svg index 136d1bc71c..0f1016e848 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/actions/section-left.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/section-left.svg @@ -1,65 +1,271 @@ - - - + + + + + + + + - - - - + + + + + + + + + + - - + + - - + + - - - + + + + + + + + + + + + + + + + + + + + - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + - + image/svg+xml - - + + [WandererFan] - section-left + section-right 2016-10-06 http://www.freecadweb.org/wiki/index.php?title=Artwork @@ -67,7 +273,7 @@ FreeCAD - FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/actions/section-left.svg + FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/actions/section-right.svg FreeCAD LGPL2+ @@ -82,15 +288,52 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/section-right.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/section-right.svg index 7a1505b644..e99464de4f 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/actions/section-right.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/section-right.svg @@ -1,59 +1,243 @@ - - - + + + + - - - - + + + + + + + + + + - - + + - - + + - - - + + + + + + + + + + + + + + + + + + + + - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + - + image/svg+xml - - + + [WandererFan] @@ -82,15 +266,52 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/section-up.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/section-up.svg index 742ef6e882..e6e64c2c62 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/actions/section-up.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/section-up.svg @@ -1,65 +1,266 @@ - - - + + + + + + + - - - - + + + + + + + + + + - - + + - - + + - - - + + + + + + + + + + + + + + + + + + + + - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + - + image/svg+xml - - + + [WandererFan] - section-up + section-right 2016-10-06 http://www.freecadweb.org/wiki/index.php?title=Artwork @@ -67,7 +268,7 @@ FreeCAD - FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/actions/section-up.svg + FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/actions/section-right.svg FreeCAD LGPL2+ @@ -82,15 +283,52 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index 3f7a7e19bd..dc7a4e449e 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -26,55 +26,121 @@ #include #endif // #ifndef _PreComp_ +#include +#include +#include +#include + #include -#include +#include +#include #include #include #include +#include #include +#include #include #include +#include #include #include #include -#include - #include +#include +#include #include -#include "TaskSectionView.h" +#include "DrawGuiStd.h" +#include "Rez.h" +#include "MDIViewPage.h" +#include "QGVPage.h" +#include "QGIView.h" + +//#include "ViewProviderPage.h" +//#include "ViewProviderViewPart.h" + #include +#include "TaskSectionView.h" + using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; -void _printVect(char* label, Base::Vector3d v); - -TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base, TechDraw::DrawViewSection* section) : +//ctor for create +TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base) : ui(new Ui_TaskSectionView), m_base(base), - m_section(section) + m_section(nullptr), + m_dirName(""), + m_createMode(true), + m_saved(false) { +// Base::Console().Message("TSV::TSV() - create mode\n"); + if (m_base == nullptr) { + //should be caught in CMD caller + std::string msg = Base::Tools::toStdString(tr("TaskSectionView - bad parameters. Can not proceed.")); + Base::Console().Error((msg + "\n").c_str()); + return; + } + + ui->setupUi(this); + + connect(ui->pbUp, SIGNAL(clicked(bool)), + this, SLOT(onUpClicked(bool))); + connect(ui->pbDown, SIGNAL(clicked(bool)), + this, SLOT(onDownClicked(bool))); + connect(ui->pbRight, SIGNAL(clicked(bool)), + this, SLOT(onRightClicked(bool))); + connect(ui->pbLeft, SIGNAL(clicked(bool)), + this, SLOT(onLeftClicked(bool))); + + setUiPrimary(); +} + + +//ctor for edit +TaskSectionView::TaskSectionView(TechDraw::DrawViewSection* section) : + ui(new Ui_TaskSectionView), + m_base(nullptr), + m_section(section), + m_createMode(false), + m_saved(false) +{ +// Base::Console().Message("TS::TS() - edit mode\n"); + + if (m_section == nullptr) { + //should be caught in CMD caller + std::string msg = Base::Tools::toStdString(tr("TaskSectionView - bad parameters. Can not proceed.")); + Base::Console().Error((msg + "\n").c_str()); + return; + } + + App::DocumentObject* newObj = m_section->BaseView.getValue(); + m_base = dynamic_cast(newObj); + if ( (newObj == nullptr) || + (m_base == nullptr) ) { + throw Base::RuntimeError("TaskSectionView - BaseView not found"); + } + ui->setupUi(this); - connect(ui->pb_Up, SIGNAL(clicked(bool)), + connect(ui->pbUp, SIGNAL(clicked(bool)), this, SLOT(onUpClicked(bool))); - connect(ui->pb_Down, SIGNAL(clicked(bool)), + connect(ui->pbDown, SIGNAL(clicked(bool)), this, SLOT(onDownClicked(bool))); - connect(ui->pb_Right, SIGNAL(clicked(bool)), + connect(ui->pbRight, SIGNAL(clicked(bool)), this, SLOT(onRightClicked(bool))); - connect(ui->pb_Left, SIGNAL(clicked(bool)), + connect(ui->pbLeft, SIGNAL(clicked(bool)), this, SLOT(onLeftClicked(bool))); - connect(ui->pbReset, SIGNAL(clicked(bool)), - this, SLOT(onResetClicked(bool))); - sectionDir = "unset"; - saveInitialValues(); - resetValues(); + m_dirName = m_section->SectionDirection.getValue(); + saveSectionState(); + setUiEdit(); } TaskSectionView::~TaskSectionView() @@ -82,223 +148,294 @@ TaskSectionView::~TaskSectionView() delete ui; } - -void TaskSectionView::saveInitialValues() +void TaskSectionView::setUiPrimary() { - saveSym = m_section->SectionSymbol.getValue(); - saveSectionOrigin = m_base->getCentroid(); - saveSectionProjDir = m_section->Direction.getValue(); - saveSectionNormal = m_section->SectionNormal.getValue(); - saveLabel = m_section->Label.getValue(); +// Base::Console().Message("TSV::setUiPrimary()\n"); + setWindowTitle(QObject::tr("Create SectionView")); + std::string temp = m_base->getNameInDocument(); + QString qTemp = Base::Tools::fromStdString(temp); + ui->leBaseView->setText(qTemp); + + //TODO: get next symbol from page +// ui->leSymbol->setText(); + + Base::Vector3d origin = m_base->getCentroid(); + ui->sbOrgX->setValue(origin.x); + ui->sbOrgY->setValue(origin.y); + ui->sbOrgZ->setValue(origin.z); } -//set the screen back to original values -void TaskSectionView::resetValues() +void TaskSectionView::setUiEdit() { - ui->leSymbol->setText(QString::fromUtf8(saveSym.data(), saveSym.size())); +// Base::Console().Message("TSV::setUiEdit()\n"); + setWindowTitle(QObject::tr("Edit SectionView")); - checkAll(false); - enableAll(true); + std::string temp = m_base->getNameInDocument(); + QString qTemp = Base::Tools::fromStdString(temp); + ui->leBaseView->setText(qTemp); - sectionDir = "unset"; - sectionProjDir = saveSectionProjDir; - sectionNormal = saveSectionNormal; - - ui->sb_OrgX->setValue(saveSectionOrigin.x); - ui->sb_OrgY->setValue(saveSectionOrigin.y); - ui->sb_OrgZ->setValue(saveSectionOrigin.z); - - ui->leProjDir->setReadOnly(true); - ui->leProjDir->setText(formatVector(saveSectionProjDir)); - ui->leNormal->setReadOnly(true); - ui->leNormal->setText(formatVector(saveSectionNormal)); - - m_section->Label.setValue(saveLabel.c_str()); - Base::Console().Message(""); + temp = m_section->SectionSymbol.getValue(); + qTemp = Base::Tools::fromStdString(temp); + ui->leSymbol->setText(qTemp); + + Base::Vector3d origin = m_section->SectionOrigin.getValue(); + ui->sbOrgX->setValue(origin.x); + ui->sbOrgY->setValue(origin.y); + ui->sbOrgZ->setValue(origin.z); } -//calculate good starting points from base view and push buttons -bool TaskSectionView::calcValues() +//save the start conditions +void TaskSectionView::saveSectionState() { - bool result = true; - - if (ui->pb_Up->isChecked()) { - sectionDir = "Up"; - } else if (ui->pb_Down->isChecked()) { - sectionDir = "Down"; - } else if (ui->pb_Left->isChecked()) { - sectionDir = "Left"; - } else if (ui->pb_Right->isChecked()) { - sectionDir = "Right"; - } else { - Base::Console().Message("Select a direction\n"); - result = false; +// Base::Console().Message("TSV::saveSectionState()\n"); + if (m_section != nullptr) { + m_saveSymbol = m_section->SectionSymbol.getValue(); + m_saveNormal = m_section->SectionNormal.getValue(); + m_saveDirection = m_section->Direction.getValue(); + m_saveOrigin = m_section->SectionOrigin.getValue(); + m_saveDirName = m_section->SectionDirection.getValue(); + m_saved = true; } - sectionProjDir = m_section->getSectionVector(sectionDir); - - sectionNormal = sectionProjDir; - if (result) { - ui->leNormal->setText(formatVector(sectionNormal)); - ui->leProjDir->setText(formatVector(sectionProjDir)); - - Base::Console().Message("Press Reset, OK or Cancel to continue \n"); - } - return result; } -//move values from screen to DocObjs -void TaskSectionView::updateValues() +//restore the start conditions +void TaskSectionView::restoreSectionState() { - if (strcmp(sectionDir,"unset") != 0) { - m_section->SectionDirection.setValue(sectionDir); +// Base::Console().Message("TSV::restoreSectionState()\n"); + if (m_section != nullptr) { + m_section->SectionSymbol.setValue(m_saveSymbol); + m_section->SectionNormal.setValue(m_saveNormal); + m_section->Direction.setValue(m_saveDirection); + m_section->SectionOrigin.setValue(m_saveOrigin); + m_section->SectionDirection.setValue(m_saveDirName.c_str()); } - m_section->Direction.setValue(sectionProjDir); - m_section->SectionNormal.setValue(sectionNormal); - Base::Vector3d origin(ui->sb_OrgX->value().getValue(), - ui->sb_OrgY->value().getValue(), - ui->sb_OrgZ->value().getValue()); - m_section->SectionOrigin.setValue(origin); - m_section->SectionSymbol.setValue(ui->leSymbol->text().toUtf8().constData()); - - m_base->getDocument()->recompute(); } void TaskSectionView::blockButtons(bool b) { - ui->pb_Up->blockSignals(b); - ui->pb_Down->blockSignals(b); - ui->pb_Left->blockSignals(b); - ui->pb_Right->blockSignals(b); + Q_UNUSED(b); } -void TaskSectionView::turnOnUp() -{ - blockButtons(true); - checkAll(false); - enableAll(false); - ui->pb_Up->setChecked(true); - ui->pb_Up->setEnabled(true); - blockButtons(false); - if (calcValues()) { - updateValues(); - } -} - -void TaskSectionView::turnOnDown() -{ - blockButtons(true); - checkAll(false); - enableAll(false); - ui->pb_Down->setChecked(true); - ui->pb_Down->setEnabled(true); - blockButtons(false); - if (calcValues()) { - updateValues(); - } -} - -void TaskSectionView::turnOnLeft() -{ - blockButtons(true); - checkAll(false); - enableAll(false); - ui->pb_Left->setChecked(true); - ui->pb_Left->setEnabled(true); - blockButtons(false); - if (calcValues()) { - updateValues(); - } -} - -void TaskSectionView::turnOnRight() -{ - blockButtons(true); - checkAll(false); - enableAll(false); - ui->pb_Right->setChecked(true); - ui->pb_Right->setEnabled(true); - blockButtons(false); - if (calcValues()) { - updateValues(); - } -} - -void TaskSectionView::checkAll(bool b) -{ - blockButtons(true); - ui->pb_Up->setChecked(b); - ui->pb_Down->setChecked(b); - ui->pb_Left->setChecked(b); - ui->pb_Right->setChecked(b); - blockButtons(false); -} - -void TaskSectionView::enableAll(bool b) -{ - blockButtons(true); - ui->pb_Up->setEnabled(b); - ui->pb_Down->setEnabled(b); - ui->pb_Left->setEnabled(b); - ui->pb_Right->setEnabled(b); - blockButtons(false); -} - - +// cardinal: 0 - left, 1 - right, 2 - up, 3 - down void TaskSectionView::onUpClicked(bool b) { +// Base::Console().Message("TSV::onUpClicked()\n"); Q_UNUSED(b); - turnOnUp(); + checkAll(false); + ui->pbUp->setChecked(true); + applyQuick("Up"); } void TaskSectionView::onDownClicked(bool b) { +// Base::Console().Message("TSV::onDownClicked()\n"); Q_UNUSED(b); - turnOnDown(); + checkAll(false); + ui->pbDown->setChecked(true); + applyQuick("Down"); } void TaskSectionView::onLeftClicked(bool b) { +// Base::Console().Message("TSV::onLeftClicked()\n"); + checkAll(false); + ui->pbLeft->setChecked(true); Q_UNUSED(b); - turnOnLeft(); + applyQuick("Left"); } void TaskSectionView::onRightClicked(bool b) { +// Base::Console().Message("TSV::onRightClicked()\n"); Q_UNUSED(b); - turnOnRight(); + checkAll(false); + ui->pbRight->setChecked(true); + applyQuick("Right"); } -void TaskSectionView::onResetClicked(bool b) +bool TaskSectionView::apply() { - Q_UNUSED(b); - resetValues(); - updateValues(); - m_section->Label.setValue(saveLabel.c_str()); +// Base::Console().Message("TSV::apply()\n"); + if (m_dirName.empty()) { + std::string msg = Base::Tools::toStdString(tr("TSV::apply - No section direction picked yet")); + Base::Console().Error((msg + "\n").c_str()); + } else { + checkAll(false); + applyQuick(m_dirName); + } + return true; } +void TaskSectionView::checkAll(bool b) +{ + ui->pbUp->setChecked(b); + ui->pbDown->setChecked(b); + ui->pbRight->setChecked(b); + ui->pbLeft->setChecked(b); +} + +//****************************************************************************** +void TaskSectionView::applyQuick(std::string dir) +{ +// Base::Console().Message("TSV::applyQuick(%s)\n", dir.c_str()); + m_dirName = dir; + Gui::Command::openCommand("Apply Quick"); + m_dirName = dir; + if (m_section == nullptr) { + m_section = createSectionView(); + } + updateSectionView(); + m_section->recomputeFeature(); +// m_section->requestPaint(); + m_base->requestPaint(); +} + +void TaskSectionView::applyAligned(void) +{ + Base::Console().Message("TSV::applyAligned() - not implemented yet\n"); + Gui::Command::openCommand("Apply Aligned"); + m_dirName = "Aligned"; + //fiddle with directions here + +// m_section->recomputeFeature(); //???? + m_section->requestPaint(); + m_base->requestPaint(); +} + +TechDraw::DrawViewSection* TaskSectionView::createSectionView(void) +{ +// Base::Console().Message("TSV::createSectionView()\n"); + + std::string sectionName; + std::string baseName = m_base->getNameInDocument(); + + Gui::Command::openCommand("Create SectionView"); + TechDraw::DrawViewSection* newSection = nullptr; + if (m_section == nullptr) { + sectionName = m_base->getDocument()->getUniqueObjectName("DrawViewSection"); + std::string sectionType = "TechDraw::DrawViewSection"; + + TechDraw::DrawPage* page = m_base->findParentPage(); + std::string pageName = page->getNameInDocument(); + + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + sectionType.c_str(),sectionName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", + pageName.c_str(), sectionName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s", + sectionName.c_str(),baseName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.Source = App.activeDocument().%s.Source", + sectionName.c_str(),baseName.c_str()); + App::DocumentObject* newObj = m_base->getDocument()->getObject(sectionName.c_str()); + newSection = dynamic_cast(newObj); + if ( (newObj == nullptr) || + (newSection == nullptr) ) { + throw Base::RuntimeError("TaskSectionView - new section object not found"); + } + } + return newSection; +} + +void TaskSectionView::updateSectionView(void) +{ +// Base::Console().Message("TSV::updateSectionView()\n"); + if (m_section != nullptr) { + std::string sectionName = m_section->getNameInDocument(); + Command::doCommand(Command::Doc,"App.activeDocument().%s.SectionDirection = '%s'", + sectionName.c_str(),m_dirName.c_str()); + Command::doCommand(Command::Doc, + "App.activeDocument().%s.SectionOrigin = FreeCAD.Vector(%.3f,%.3f,%.3f)", + 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'", + sectionName.c_str(), + temp.c_str()); + m_section->setNormalFromBase(m_dirName.c_str()); + } +} + +void TaskSectionView::saveButtons(QPushButton* btnOK, + QPushButton* btnCancel, + QPushButton* btnApply) +{ + m_btnOK = btnOK; + m_btnCancel = btnCancel; + m_btnApply = btnApply; +} + +//std::string TaskSectionView::prefViewSection() +//{ +//// Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> +//// GetGroup("Preferences")->GetGroup("Mod/TechDraw/Section"); +//// +//// std::string prefString = hGrp->GetASCII("SectionPref", "default"); +//// return prefString; +//} + +//****************************************************************************** bool TaskSectionView::accept() { - if (strcmp(sectionDir,"unset") == 0) { - Base::Console().Message("No direction selected!\n"); - return reject(); +// Base::Console().Message("TSV::accept()\n"); + if (m_createMode) { + if (m_section == nullptr) { + apply(); + } + Gui::Command::updateActive(); + Gui::Command::commitCommand(); } else { - updateValues(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); - return true; + Gui::Command::openCommand("Edit SectionView"); + try { + updateSectionView(); + } + catch (...) { + Base::Console().Error("TSV::accept - failed to update section\n"); + } + + Gui::Command::updateActive(); + Gui::Command::commitCommand(); } + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); +// m_section->recomputeFeature(); + if (m_section != nullptr) { + m_section->requestPaint(); + } + if (m_base != nullptr) { + m_base->requestPaint(); + } + return true; } bool TaskSectionView::reject() { - std::string BaseName = m_base->getNameInDocument(); +// Base::Console().Message("TSV::reject()\n"); std::string PageName = m_base->findParentPage()->getNameInDocument(); - std::string SectionName = m_section->getNameInDocument(); - Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.removeView(App.activeDocument().%s)", - PageName.c_str(),SectionName.c_str()); - Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().removeObject('%s')",SectionName.c_str()); + if (m_section != nullptr) { + if (m_createMode) { + std::string SectionName = m_section->getNameInDocument(); + Gui::Command::doCommand(Gui::Command::Gui, + "App.activeDocument().%s.removeView(App.activeDocument().%s)", + PageName.c_str(),SectionName.c_str()); + Gui::Command::doCommand(Gui::Command::Gui, + "App.activeDocument().removeObject('%s')", + SectionName.c_str()); + } else { + Base::Console().Message("TSV::reject() - edit mode\n"); + restoreSectionState(); + //check undo stack? + m_section->requestPaint(); + m_base->requestPaint(); + } + + } + + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()"); Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); - m_base->findParentPage()->requestPaint(); + return false; } @@ -309,31 +446,26 @@ void TaskSectionView::changeEvent(QEvent *e) } } -QString TaskSectionView::formatVector(Base::Vector3d v) -{ - QString data = QString::fromLatin1("[%1 %2 %3]") - .arg(QLocale::system().toString(v.x, 'f', 2)) - .arg(QLocale::system().toString(v.y, 'f', 2)) - .arg(QLocale::system().toString(v.z, 'f', 2)); - return data; -} - -void _printVect(char* label, Base::Vector3d v) -{ - Base::Console().Message("printVect: %s (%3f,%.3f,%.3f)\n",label,v.x,v.y,v.z); -} - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -TaskDlgSectionView::TaskDlgSectionView(TechDraw::DrawViewPart* base, TechDraw::DrawViewSection* section) : +TaskDlgSectionView::TaskDlgSectionView(TechDraw::DrawViewPart* base) : TaskDialog() { - widget = new TaskSectionView(base,section); - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_Tree_View"), + widget = new TaskSectionView(base); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-viewsection"), widget->windowTitle(), true, 0); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } +TaskDlgSectionView::TaskDlgSectionView(TechDraw::DrawViewSection* section) : + TaskDialog() +{ + widget = new TaskSectionView(section); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-viewsection"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} TaskDlgSectionView::~TaskDlgSectionView() { } @@ -343,6 +475,15 @@ void TaskDlgSectionView::update() //widget->updateTask(); } +void TaskDlgSectionView::modifyStandardButtons(QDialogButtonBox* box) +{ + QPushButton* btnOK = box->button(QDialogButtonBox::Ok); + QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel); + QPushButton* btnApply = box->button(QDialogButtonBox::Apply); + widget->saveButtons(btnOK, btnCancel, btnApply); +} + + //==== calls from the TaskView =============================================================== void TaskDlgSectionView::open() { @@ -350,7 +491,11 @@ void TaskDlgSectionView::open() void TaskDlgSectionView::clicked(int i) { - Q_UNUSED(i); +// Q_UNUSED(i); +// Base::Console().Message("TDSV::clicked(%X)\n",i); + if (i == QMessageBox::Apply) { + widget->apply(); + } } bool TaskDlgSectionView::accept() @@ -359,6 +504,13 @@ bool TaskDlgSectionView::accept() return true; } +//bool TaskDlgSectionView::apply() +//{ +// Base::Console().Message("TDSV::apply()\n"); +// widget->apply(); +// return true; +//} + bool TaskDlgSectionView::reject() { widget->reject(); diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.h b/src/Mod/TechDraw/Gui/TaskSectionView.h index 939a18cddd..b9823230b8 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.h +++ b/src/Mod/TechDraw/Gui/TaskSectionView.h @@ -42,52 +42,69 @@ class TaskSectionView : public QWidget Q_OBJECT public: - TaskSectionView(TechDraw::DrawViewPart* base, TechDraw::DrawViewSection* section); + TaskSectionView(TechDraw::DrawViewPart* base); + TaskSectionView(TechDraw::DrawViewSection* section); ~TaskSectionView(); public: virtual bool accept(); + virtual bool apply(); virtual bool reject(); + void modifyStandardButtons(QDialogButtonBox* box); + void saveButtons(QPushButton* btnOK, + QPushButton* btnCancel, + QPushButton* btnApply); + protected Q_SLOTS: void onUpClicked(bool b); void onDownClicked(bool b); void onLeftClicked(bool b); void onRightClicked(bool b); - void onResetClicked(bool b); protected: - void turnOnUp(void); - void turnOnDown(void); - void turnOnLeft(void); - void turnOnRight(void); - void checkAll(bool b); - void enableAll(bool b); void blockButtons(bool b); + void changeEvent(QEvent *e); - void resetValues(); - bool calcValues(); - void saveInitialValues(); - void updateValues(); - QString formatVector(Base::Vector3d v); + void saveSectionState(); + void restoreSectionState(); + + void applyQuick(std::string dir); + void applyAligned(void); + + TechDraw::DrawViewSection* createSectionView(void); + void updateSectionView(void); + + void setUiPrimary(); + void setUiEdit(); + + void checkAll(bool b); + +// std::string prefViewSection(); private: Ui_TaskSectionView * ui; TechDraw::DrawViewPart* m_base; TechDraw::DrawViewSection* m_section; - Base::Vector3d sectionNormal; - Base::Vector3d sectionProjDir; - Base::Vector3d sectionOrigin; - char* sectionDir; - Base::Vector3d arrowDir; + std::string m_symbol; + Base::Vector3d m_normal; + Base::Vector3d m_direction; + Base::Vector3d m_origin; + + std::string m_saveSymbol; + std::string m_saveDirName; + Base::Vector3d m_saveNormal; + Base::Vector3d m_saveDirection; + Base::Vector3d m_saveOrigin; - std::string saveSym; - std::string saveLabel; - //bool saveHorizSectionLine; - //bool saveArrowUpSection; - Base::Vector3d saveSectionProjDir; - Base::Vector3d saveSectionOrigin; - Base::Vector3d saveSectionNormal; + std::string m_dirName; + + QPushButton* m_btnOK; + QPushButton* m_btnCancel; + QPushButton* m_btnApply; + + bool m_createMode; + bool m_saved; }; @@ -96,7 +113,8 @@ class TaskDlgSectionView : public Gui::TaskView::TaskDialog Q_OBJECT public: - TaskDlgSectionView(TechDraw::DrawViewPart* base, TechDraw::DrawViewSection* section); + TaskDlgSectionView(TechDraw::DrawViewPart* base); + TaskDlgSectionView(TechDraw::DrawViewSection* section); ~TaskDlgSectionView(); public: @@ -110,9 +128,14 @@ public: virtual bool reject(); /// is called by the framework if the user presses the help button virtual void helpRequested() { return;} + virtual bool isAllowedAlterDocument(void) const { return false; } + virtual QDialogButtonBox::StandardButtons getStandardButtons() const + { return QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel; } + virtual void modifyStandardButtons(QDialogButtonBox* box); + void update(); protected: diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.ui b/src/Mod/TechDraw/Gui/TaskSectionView.ui index 3e3eacdc6e..0fa2e1758a 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.ui +++ b/src/Mod/TechDraw/Gui/TaskSectionView.ui @@ -6,12 +6,12 @@ 0 0 - 410 - 492 + 434 + 368 - + 0 0 @@ -19,103 +19,109 @@ 250 - 0 + 300 - Quick Section Parameters + Section Parameters - + - + 0 0 - - Define Your Section + + + 350 + 350 + + + + QFrame::StyledPanel + + + QFrame::Raised - - + + + + + BaseView + + + + + + + false + + + + Symbol - + Identifier for this section - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Origin Y - - - - - - - Location of section plane - - - - - - - + - Origin X + Section Origin X - - - - Origin Z - - - - - + + - Location of section plane + <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> - - + + + + Section Origin Y + + + + + - Location of section plane + <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> + + + + + + + + + + Section Origin Z + + + + + + + <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> @@ -125,46 +131,9 @@ - - - - - Looking down - - - - - - - :/icons/actions/section-down.svg - - - - - 48 - 48 - - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + + Looking right @@ -187,32 +156,8 @@ - - - - Looking left - - - - - - - :/icons/actions/section-left.svg - - - - - 48 - 48 - - - - true - - - - - + + Looking up @@ -241,124 +186,85 @@ - - - - Qt::Horizontal + + + + Looking left - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - Qt::Horizontal - - - - - - - Calculated Values - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - Projection Direction + - - - - - + + + :/icons/actions/section-left.svg + + + + + 48 + 48 + + + true - - + + + + Looking down + - Section Normal + + + + + :/icons/actions/section-down.svg + + + + + 48 + 48 + + + + true - - + + + + + 50 + false + + + + Apply + + - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Start over - - - Reset - - - - + + + Qt::Vertical + + + + 20 + 40 + + + - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp index 3f3c014b6d..b974ca13ab 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderViewSection.cpp @@ -37,6 +37,17 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "TaskSectionView.h" + #include "ViewProviderViewSection.h" using namespace TechDrawGui; @@ -124,6 +135,40 @@ void ViewProviderViewSection::updateGraphic(void) } } +bool ViewProviderViewSection::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default ) { + if (Gui::Control().activeDialog()) { //TaskPanel already open! + return false; + } + // clear the selection (convenience) + Gui::Selection().clearSelection(); + Gui::Control().showDialog(new TaskDlgSectionView(getViewObject())); + return true; + } else { + return ViewProviderDrawingView::setEdit(ModNum); + } + return true; +} + +void ViewProviderViewSection::unsetEdit(int ModNum) +{ + Q_UNUSED(ModNum); + if (ModNum == ViewProvider::Default) { + Gui::Control().closeDialog(); + } + else { + ViewProviderDrawingView::unsetEdit(ModNum); + } +} + +bool ViewProviderViewSection::doubleClicked(void) +{ + setEdit(ViewProvider::Default); + return true; +} + + void ViewProviderViewSection::getParameters(void) { Base::Reference hGrp = App::GetApplication().GetUserParameter() diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewSection.h b/src/Mod/TechDraw/Gui/ViewProviderViewSection.h index a9047be9c3..911fdbc923 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewSection.h +++ b/src/Mod/TechDraw/Gui/ViewProviderViewSection.h @@ -57,12 +57,17 @@ public: virtual std::vector getDisplayModes(void) const; virtual void updateData(const App::Property*); virtual void onChanged(const App::Property *prop); + virtual bool setEdit(int ModNum); + virtual void unsetEdit(int ModNum); + virtual bool doubleClicked(void); virtual std::vector claimChildren(void) const; void updateGraphic(void); void getParameters(void); + + virtual TechDraw::DrawViewSection* getViewObject() const; };