diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 3961ef6253..e3f6b9420b 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -720,6 +720,10 @@ void Application::slotDeleteDocument(const App::Document& Doc) return; } + // Inside beforeDelete() a view provider may finish editing mode + // and therefore can alter the selection. + doc->second->beforeDelete(); + // We must clear the selection here to notify all observers. // And because of possible cross document link, better clear all selection // to be safe @@ -727,8 +731,6 @@ void Application::slotDeleteDocument(const App::Document& Doc) doc->second->signalDeleteDocument(*doc->second); signalDeleteDocument(*doc->second); - doc->second->beforeDelete(); - // If the active document gets destructed we must set it to 0. If there are further existing documents then the // view that becomes active sets the active document again. So, we needn't worry about this. if (d->activeDocument == doc->second) diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index afeb128b8a..5bf79c00eb 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1627,6 +1627,13 @@ Gui::MDIView* Document::cloneView(Gui::MDIView* oldview) view3D->setWindowIcon(oldview->windowIcon()); view3D->resize(oldview->size()); + // FIXME: Add parameter to define behaviour by the calling instance + // View provider editing + if (d->_editViewProvider) { + firstView->getViewer()->resetEditingViewProvider(); + view3D->getViewer()->setEditingViewProvider(d->_editViewProvider, d->_editMode); + } + return view3D; } @@ -1787,7 +1794,11 @@ bool Document::canClose (bool checkModify, bool checkLink) if (!Gui::Control().isAllowedAlterDocument()) { std::string name = Gui::Control().activeDialog()->getDocumentName(); if (name == this->getDocument()->getName()) { - if (this->getInEdit()) + // getInEdit() only checks if the currently active MDI view is + // a 3D view and that it is in edit mode. However, when closing a + // document then the edit mode must be reset independent of the + // active view. + if (d->_editViewProvider) this->_resetEdit(); } } diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 5f30e28c47..d52a081b25 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -608,6 +608,14 @@ View3DInventorViewer::~View3DInventorViewer() // to prevent following OpenGL error message: "Texture is not valid in the current context. Texture has not been destroyed" aboutToDestroyGLContext(); + // It can happen that a document has several MDI views and when the about to be + // closed 3D view is in edit mode the corresponding view provider must be restored + // because otherwise it might be left in a broken state + // See https://forum.freecadweb.org/viewtopic.php?f=3&t=39720 + if (restoreEditingRoot) { + resetEditingRoot(false); + } + // cleanup this->backgroundroot->unref(); this->backgroundroot = 0; diff --git a/src/Mod/TechDraw/App/DrawSVGTemplate.cpp b/src/Mod/TechDraw/App/DrawSVGTemplate.cpp index 4466e5d178..71c6498b76 100644 --- a/src/Mod/TechDraw/App/DrawSVGTemplate.cpp +++ b/src/Mod/TechDraw/App/DrawSVGTemplate.cpp @@ -133,128 +133,125 @@ void DrawSVGTemplate::onChanged(const App::Property* prop) App::DocumentObjectExecReturn * DrawSVGTemplate::execute(void) { - std::string templateFilename = Template.getValue(); - if (templateFilename.empty()) - return App::DocumentObject::StdReturn; + std::string templateFilename = Template.getValue(); + if (templateFilename.empty()) + return App::DocumentObject::StdReturn; - Base::FileInfo fi(templateFilename); - if (!fi.isReadable()) { - // non-empty template value, but can't read file - // if there is a old absolute template file set use a redirect - fi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName()); - // try the redirect - if (!fi.isReadable()) { - Base::Console().Log("DrawSVGTemplate::execute() not able to open %s!\n", Template.getValue()); - std::string error = std::string("Cannot open file ") + Template.getValue(); - return new App::DocumentObjectExecReturn(error); - } - } + Base::FileInfo fi(templateFilename); + if (!fi.isReadable()) { + // non-empty template value, but can't read file + // if there is a old absolute template file set use a redirect + fi.setFile(App::Application::getResourceDir() + "Mod/Drawing/Templates/" + fi.fileName()); + // try the redirect + if (!fi.isReadable()) { + Base::Console().Log("DrawSVGTemplate::execute() not able to open %s!\n", Template.getValue()); + std::string error = std::string("Cannot open file ") + Template.getValue(); + return new App::DocumentObjectExecReturn(error); + } + } - if (std::string(PageResult.getValue()).empty()) //first time through? - PageResult.setValue(fi.filePath().c_str()); + if (std::string(PageResult.getValue()).empty()) //first time through? + PageResult.setValue(fi.filePath().c_str()); - QFile templateFile(QString::fromUtf8(fi.filePath().c_str())); - if (!templateFile.open(QIODevice::ReadOnly)) { - Base::Console().Log("DrawSVGTemplate::execute() can't read template %s!\n", Template.getValue()); - std::string error = std::string("Cannot read file ") + Template.getValue(); - return new App::DocumentObjectExecReturn(error); - } + std::string templateFileSpec = fi.filePath(); + QString qSpec = Base::Tools::fromStdString(templateFileSpec); + std::string documentImage; + QString qDocImage; - QDomDocument templateDocument; - if (!templateDocument.setContent(&templateFile)) { - Base::Console().Message("DrawSVGTemplate::execute() - failed to parse file: %s\n", - Template.getValue()); - std::string error = std::string("Cannot parse file ") + Template.getValue(); - return new App::DocumentObjectExecReturn(error); - } + qDocImage = processTemplate(qSpec); - QXmlQuery query(QXmlQuery::XQuery10); - QDomNodeModel model(query.namePool(), templateDocument); - query.setFocus(QXmlItem(model.fromDomNode(templateDocument.documentElement()))); + if (!qDocImage.isEmpty()) { + // make a temp file for FileIncluded Property + string tempName = PageResult.getExchangeTempFile(); + ofstream outfinal(tempName.c_str()); + std::string result = Base::Tools::toStdString(qDocImage); + outfinal << result; + outfinal.close(); + PageResult.setValue(tempName.c_str()); + } + else { + Base::Console().Error("QSVGT::execute - failed to process Template\n"); + } - // XPath query to select all nodes whose parent - // has "freecad:editable" attribute - query.setQuery(QString::fromUtf8( - "declare default element namespace \"" SVG_NS_URI "\"; " - "declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; " - "//text[@freecad:editable]/tspan")); - - QXmlResultItems queryResult; - query.evaluateTo(&queryResult); - - std::map substitutions = EditableTexts.getValues(); - while (!queryResult.next().isNull()) - { - QDomElement tspan = model.toDomNode(queryResult.current().toNodeModelIndex()).toElement(); - - // Replace the editable text spans with new nodes holding actual values - QString editableName = tspan.parentNode().toElement().attribute(QString::fromUtf8("freecad:editable")); - std::map::iterator item = - substitutions.find(std::string(editableName.toUtf8().constData())); - if (item != substitutions.end()) { - // Keep all spaces in the text node - tspan.setAttribute(QString::fromUtf8("xml:space"), QString::fromUtf8("preserve")); - - // Remove all child nodes and append text node with editable replacement as the only descendant - while (!tspan.lastChild().isNull()) { - tspan.removeChild(tspan.lastChild()); - } - tspan.appendChild(templateDocument.createTextNode(QString::fromUtf8(item->second.c_str()))); - } - } - - //re #4085 - - std::string ssExchangeName = PageResult.getExchangeTempFile(); - QString qExchangeName = Base::Tools::fromStdString(ssExchangeName); - bool rc = writeExchangeFile(qExchangeName, templateDocument.toString()); - if (rc) { - PageResult.setValue(ssExchangeName.c_str()); - } else { - Base::Console().Error("DrawSVGTemplate::execute - failed to exchange temp file: %s\n", - ssExchangeName.c_str()); - } - - // Calculate the dimensions of the page and store for retrieval - // Obtain the size of the SVG document by reading the document attributes - QDomElement docElement = templateDocument.documentElement(); - Base::Quantity quantity; - - // Obtain the width - QString str = docElement.attribute(QString::fromLatin1("width")); - quantity = Base::Quantity::parse(str); - quantity.setUnit(Base::Unit::Length); - - Width.setValue(quantity.getValue()); - - str = docElement.attribute(QString::fromLatin1("height")); - quantity = Base::Quantity::parse(str); - quantity.setUnit(Base::Unit::Length); - - Height.setValue(quantity.getValue()); - - bool isLandscape = getWidth() / getHeight() >= 1.; - - Orientation.setValue(isLandscape ? 1 : 0); - - return TechDraw::DrawTemplate::execute(); + return TechDraw::DrawTemplate::execute(); } -bool DrawSVGTemplate::writeExchangeFile(QString exchangeName, QString fileContent) +QString DrawSVGTemplate::processTemplate(QString fileSpec) { -// Base::Console().Message("DSVGT::writeExchangeFile(%s)\n", qPrintable(exchangeName)); - bool rc = true; - QFile newTempFile(exchangeName); - if (newTempFile.open(QIODevice::WriteOnly | QIODevice::Text)) { - QTextStream stream(&newTempFile); - stream << fileContent; - newTempFile.close(); - } - else { - Base::Console().Message("DrawSVGT:writeExchangeFile - failed to open temp file for writing: %s\n", - qPrintable(exchangeName)); - rc = false; - } - return rc; + QFile templateFile(fileSpec); + if (!templateFile.open(QIODevice::ReadOnly)) { + Base::Console().Log("DrawSVGTemplate::execute() can't read template %s!\n", Template.getValue()); + std::string error = std::string("Cannot read file ") + Template.getValue(); + return QString(); + } + + QDomDocument templateDocument; + if (!templateDocument.setContent(&templateFile)) { + Base::Console().Message("DrawSVGTemplate::execute() - failed to parse file: %s\n", + Template.getValue()); + std::string error = std::string("Cannot parse file ") + Template.getValue(); + return QString(); + } + + QXmlQuery query(QXmlQuery::XQuery10); + QDomNodeModel model(query.namePool(), templateDocument); + query.setFocus(QXmlItem(model.fromDomNode(templateDocument.documentElement()))); + + // XPath query to select all nodes whose parent + // has "freecad:editable" attribute + query.setQuery(QString::fromUtf8( + "declare default element namespace \"" SVG_NS_URI "\"; " + "declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; " + "//text[@freecad:editable]/tspan")); + + QXmlResultItems queryResult; + query.evaluateTo(&queryResult); + + std::map substitutions = EditableTexts.getValues(); + while (!queryResult.next().isNull()) + { + QDomElement tspan = model.toDomNode(queryResult.current().toNodeModelIndex()).toElement(); + + // Replace the editable text spans with new nodes holding actual values + QString editableName = tspan.parentNode().toElement().attribute(QString::fromUtf8("freecad:editable")); + std::map::iterator item = + substitutions.find(std::string(editableName.toUtf8().constData())); + if (item != substitutions.end()) { + // Keep all spaces in the text node + tspan.setAttribute(QString::fromUtf8("xml:space"), QString::fromUtf8("preserve")); + + // Remove all child nodes and append text node with editable replacement as the only descendant + while (!tspan.lastChild().isNull()) { + tspan.removeChild(tspan.lastChild()); + } + tspan.appendChild(templateDocument.createTextNode(QString::fromUtf8(item->second.c_str()))); + } + } + + // Calculate the dimensions of the page and store for retrieval + // Obtain the size of the SVG document by reading the document attributes + QDomElement docElement = templateDocument.documentElement(); + Base::Quantity quantity; + + // Obtain the width + QString str = docElement.attribute(QString::fromLatin1("width")); + quantity = Base::Quantity::parse(str); + quantity.setUnit(Base::Unit::Length); + + Width.setValue(quantity.getValue()); + + str = docElement.attribute(QString::fromLatin1("height")); + quantity = Base::Quantity::parse(str); + quantity.setUnit(Base::Unit::Length); + + Height.setValue(quantity.getValue()); + + bool isLandscape = getWidth() / getHeight() >= 1.; + + Orientation.setValue(isLandscape ? 1 : 0); + + //all Qt holds on files should be released on exit #4085 + return templateDocument.toString(); } double DrawSVGTemplate::getWidth() const @@ -308,7 +305,7 @@ std::map DrawSVGTemplate::getEditableTextsFromTemplate // XPath query to select all nodes whose parent // has "freecad:editable" attribute query.setQuery(QString::fromUtf8( - "declare default element namespace \"" SVG_NS_URI "\"; " + "declare default element namespace \"" SVG_NS_URI "\"; " "declare namespace freecad=\"" FREECAD_SVG_NS_URI "\"; " "//text[@freecad:editable]/tspan")); diff --git a/src/Mod/TechDraw/App/DrawSVGTemplate.h b/src/Mod/TechDraw/App/DrawSVGTemplate.h index eaa10dec59..c8a11eb42e 100644 --- a/src/Mod/TechDraw/App/DrawSVGTemplate.h +++ b/src/Mod/TechDraw/App/DrawSVGTemplate.h @@ -73,8 +73,8 @@ protected: * Also populates editableSvgIds */ std::map getEditableTextsFromTemplate(); - - bool writeExchangeFile(QString exchangeName, QString fileContent); + + QString processTemplate(QString fileSpec); }; diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index e00a334d3d..b939df480d 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -1060,4 +1060,17 @@ QString DrawUtil::qbaToDebug(const QByteArray & line) return s; } +void DrawUtil::dumpCS(const char* text, + gp_Ax2 CS) +{ + gp_Dir baseAxis = CS.Direction(); + gp_Dir baseX = CS.XDirection(); + gp_Dir baseY = CS.YDirection(); + Base::Console().Message("DU::dumpCSDVS - %s Axis: %s X: %s Y: %s\n", text, + DrawUtil::formatVector(baseAxis).c_str(), + DrawUtil::formatVector(baseX).c_str(), + DrawUtil::formatVector(baseY).c_str()); +} + + //================================== diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 7ca4347e9d..972816c081 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -158,6 +158,8 @@ class TechDrawExport DrawUtil { static void countEdges(const char* label, const TopoDS_Shape& s); static const char* printBool(bool b); static QString qbaToDebug(const QByteArray& line); + static void dumpCS(const char* text, gp_Ax2 CS); + }; } //end namespace TechDraw diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 23ed8d86bd..1c2bb4a1ad 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -192,11 +192,16 @@ 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; } App::DocumentObject* base = BaseView.getValue(); + if (base == nullptr) { + return new App::DocumentObjectExecReturn("BaseView object not found"); + } + if (!base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) return new App::DocumentObjectExecReturn("BaseView object is not a DrawViewPart object"); @@ -270,13 +275,14 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) m_cutShape = rawShape; gp_Pnt inputCenter; + gp_Ax2 viewAxis; try { inputCenter = TechDraw::findCentroid(rawShape, - Direction.getValue()); + Direction.getValue()); //?? TopoDS_Shape mirroredShape = TechDraw::mirrorShape(rawShape, inputCenter, getScale()); - gp_Ax2 viewAxis = getViewAxis(Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()),Direction.getValue()); + viewAxis = getSectionCS(SectionDirection.getValueAsString()); if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { mirroredShape = TechDraw::rotateShape(mirroredShape, viewAxis, @@ -298,7 +304,7 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) TopoDS_Shape mirroredSection = TechDraw::mirrorShape(sectionCompound, inputCenter, getScale()); - gp_Ax2 viewAxis = getViewAxis(Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()),Direction.getValue()); +// gp_Ax2 viewAxis = getViewAxis(Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()),Direction.getValue()); if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { mirroredSection = TechDraw::rotateShape(mirroredSection, viewAxis, @@ -415,12 +421,13 @@ TopoDS_Face DrawViewSection::projectFace(const TopoDS_Shape &face, gp_Pnt faceCenter, const Base::Vector3d &direction) { + (void) direction; if(face.IsNull()) { throw Base::ValueError("DrawViewSection::projectFace - input Face is NULL"); } Base::Vector3d origin(faceCenter.X(),faceCenter.Y(),faceCenter.Z()); - gp_Ax2 viewAxis = getViewAxis(origin,direction); + gp_Ax2 viewAxis = getSectionCS(SectionDirection.getValueAsString()); HLRBRep_Algo *brep_hlr = new HLRBRep_Algo(); brep_hlr->Add(face); @@ -526,19 +533,24 @@ bool DrawViewSection::isReallyInBox (const gp_Pnt p, const Bnd_Box& bb) const return !bb.IsOut(p); } -//! calculate the section Normal/Projection Direction given baseView projection direction and section name +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) { +// Base::Console().Message("DVS::getSectionVector(%s) - %s\n", sectionName.c_str(), getNameInDocument()); Base::Vector3d result; Base::Vector3d stdX(1.0,0.0,0.0); Base::Vector3d stdY(0.0,1.0,0.0); Base::Vector3d stdZ(0.0,0.0,1.0); - double adjustAngle = 0.0; - if (getBaseDPGI() != nullptr) { - adjustAngle = getBaseDPGI()->getRotateAngle(); - } - Base::Vector3d view = getBaseDVP()->Direction.getValue(); view.Normalize(); Base::Vector3d left = view.Cross(stdZ); @@ -575,8 +587,101 @@ Base::Vector3d DrawViewSection::getSectionVector (const std::string sectionName) Base::Console().Log("Error - DVS::getSectionVector - bad sectionName: %s\n",sectionName.c_str()); result = stdZ; } - Base::Vector3d adjResult = DrawUtil::vecRotate(result,adjustAngle,view); - return adjResult; + return result; +} + +//! calculate the section Projection CS given section direction name +gp_Ax2 DrawViewSection::getSectionCS (const std::string dirName) +{ + Base::Vector3d view = getBaseDVP()->Direction.getValue(); + view.Normalize(); + + Base::Vector3d sectionOrg = SectionOrigin.getValue(); + gp_Ax2 baseCS = getBaseDVP()->getViewAxis(sectionOrg, + view); + + // cardinal: 0 - left, 1 - right, 2 - up, 3 - down + int cardinal = 0; + if (dirName == "Up") { + cardinal = 2; + } else if (dirName == "Down") { + cardinal = 3; + } else if (dirName == "Left") { + cardinal = 0; + } else if (dirName == "Right") { + cardinal = 1; + } + gp_Ax2 newCS = rotateCSCardinal(baseCS, cardinal); + return newCS; +} + + +//TODO: this should be able to handle arbitrary rotation of the CS +//TODO: this is useful beyond DVS. move to GO or DU or ??? +// or at least static in DVS. doesn't depend on DVS object +gp_Ax2 DrawViewSection::rotateCSCardinal(gp_Ax2 oldCS, int cardinal) +{ + // cardinal: 0 - left, 1 - right, 2 - up, 3 - down + // as in DVS::SectionDirection + gp_Pnt oldOrg = oldCS.Location(); + gp_Dir oldMain = oldCS.Direction(); + gp_Dir oldX = oldCS.XDirection(); + + gp_Ax1 rotAxis; + gp_Dir crossed; + gp_Ax2 newCS; + double angle; + + //Note: cardinal refers to the the motion of the viewer's head. When the head turns to + // the left, the "Direction" moves to the right! When the viewer's head moves to look up, + // the "Direction" moves down! + + switch (cardinal) { + case 0: //right + crossed = oldMain.Crossed(oldX); + rotAxis = gp_Ax1(oldOrg, crossed); + angle = 90.0 * M_PI / 180.0; + newCS = oldCS.Rotated(rotAxis, angle); + break; + case 1: //left + crossed = oldMain.Crossed(oldX); + rotAxis = gp_Ax1(oldOrg, crossed); + angle = -90.0 * M_PI / 180.0; + newCS = oldCS.Rotated(rotAxis, angle); + break; + case 2: // head looks up, so Direction(projection normal) points down + rotAxis = gp_Ax1(oldOrg, oldX); + angle = -90.0 * M_PI / 180.0; + newCS = oldCS.Rotated(rotAxis, angle); + break; + case 3: //down + rotAxis = gp_Ax1(oldOrg, oldX); //one of these should be -oldX? + angle = 90.0 * M_PI / 180.0; + newCS = oldCS.Rotated(rotAxis, angle); + break; + default: + newCS = oldCS; + break; + } + + return newCS; +} + +gp_Ax2 DrawViewSection::rotateCSArbitrary(gp_Ax2 oldCS, + Base::Vector3d axis, + double degAngle) +{ + gp_Ax2 newCS; + + gp_Pnt oldOrg = oldCS.Location(); + + gp_Dir gAxis(axis.x, axis.y, axis.z); + gp_Ax1 rotAxis = gp_Ax1(oldOrg, gAxis); + + double radAngle = degAngle * M_PI / 180.0; + + newCS = oldCS.Rotated(rotAxis, radAngle); + return newCS; } std::vector DrawViewSection::getDrawableLines(int i) diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index 4db327ede4..d1a9a91b7b 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -39,6 +39,7 @@ class Bnd_Box; class gp_Pln; class gp_Pnt; class TopoDS_Face; +class gp_Ax2; namespace TechDraw { @@ -84,7 +85,16 @@ public: 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, + double degAngle) ; + gp_Ax2 getSectionCS (const std::string dirName); + TechDraw::DrawViewPart* getBaseDVP(); TechDraw::DrawProjGroupItem* getBaseDPGI(); virtual void unsetupObject(); 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 5450e8f16e..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,226 +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"; - sectionProjDir = m_section->getSectionVector(sectionDir); - } else if (ui->pb_Down->isChecked()) { - sectionDir = "Down"; - sectionProjDir = m_section->getSectionVector(sectionDir); - } else if (ui->pb_Left->isChecked()) { - sectionDir = "Left"; - sectionProjDir = m_section->getSectionVector(sectionDir); - } else if (ui->pb_Right->isChecked()) { - sectionDir = "Right"; - sectionProjDir = m_section->getSectionVector(sectionDir); - } 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; } - - 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; } @@ -312,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() { } @@ -346,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() { @@ -353,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() @@ -362,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; };