From b44044f95b7e47d2dc5af193342c8ae31f81fd78 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Tue, 7 Apr 2020 11:30:57 -0400 Subject: [PATCH] [TD]dialog for Detail #4221 --- src/Mod/TechDraw/App/DrawUtil.cpp | 7 + src/Mod/TechDraw/App/DrawUtil.h | 1 + src/Mod/TechDraw/App/DrawViewDetail.cpp | 2 - src/Mod/TechDraw/Gui/CMakeLists.txt | 9 + src/Mod/TechDraw/Gui/Command.cpp | 2770 ++++++++--------- src/Mod/TechDraw/Gui/QGIGhostHighlight.cpp | 115 + src/Mod/TechDraw/Gui/QGIGhostHighlight.h | 66 + src/Mod/TechDraw/Gui/QGIHighlight.cpp | 59 +- src/Mod/TechDraw/Gui/QGIHighlight.h | 16 +- src/Mod/TechDraw/Gui/QGIUserTypes.h | 46 +- src/Mod/TechDraw/Gui/QGIView.h | 11 +- src/Mod/TechDraw/Gui/Rez.cpp | 6 + src/Mod/TechDraw/Gui/Rez.h | 2 + src/Mod/TechDraw/Gui/TaskDetail.cpp | 585 ++++ src/Mod/TechDraw/Gui/TaskDetail.h | 179 ++ src/Mod/TechDraw/Gui/TaskDetail.ui | 296 ++ src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp | 64 + src/Mod/TechDraw/Gui/ViewProviderViewPart.h | 3 + 18 files changed, 2813 insertions(+), 1424 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/QGIGhostHighlight.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIGhostHighlight.h create mode 100644 src/Mod/TechDraw/Gui/TaskDetail.cpp create mode 100644 src/Mod/TechDraw/Gui/TaskDetail.h create mode 100644 src/Mod/TechDraw/Gui/TaskDetail.ui diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 786daaf79b..27908dbcca 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -570,6 +570,13 @@ Base::Vector3d DrawUtil::invertY(Base::Vector3d v) return result; } +QPointF DrawUtil::invertY(QPointF v) +{ + QPointF result(v.x(), -v.y()); + return result; +} + + //obs? was used in CSV prototype of Cosmetics std::vector DrawUtil::split(std::string csvLine) { diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 8b9f66c92a..aa70753220 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -110,6 +110,7 @@ class TechDrawExport DrawUtil { static std::string shapeToString(TopoDS_Shape s); static TopoDS_Shape shapeFromString(std::string s); static Base::Vector3d invertY(Base::Vector3d v); + static QPointF invertY(QPointF p); static std::vector split(std::string csvLine); static std::vector tokenize(std::string csvLine, std::string delimiter = ",$$$,"); static App::Color pyTupleToColor(PyObject* pColor); diff --git a/src/Mod/TechDraw/App/DrawViewDetail.cpp b/src/Mod/TechDraw/App/DrawViewDetail.cpp index 4e2e3f21ed..53c02f5894 100644 --- a/src/Mod/TechDraw/App/DrawViewDetail.cpp +++ b/src/Mod/TechDraw/App/DrawViewDetail.cpp @@ -100,8 +100,6 @@ using namespace std; PROPERTY_SOURCE(TechDraw::DrawViewDetail, TechDraw::DrawViewPart) DrawViewDetail::DrawViewDetail() -// : -// m_mattingStyle(0) { static const char *dgroup = "Detail"; diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index fb03ba059a..43ab8e5eeb 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -70,6 +70,8 @@ set(TechDrawGui_MOC_HDRS QGIWeldSymbol.h SymbolChooser.h TaskActiveView.h + TaskDetail.h + QGIGhostHighlight.h ) fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) @@ -103,6 +105,7 @@ set(TechDrawGui_UIC_SRCS TaskWeldingSymbol.ui SymbolChooser.ui TaskActiveView.ui + TaskDetail.ui ) if(BUILD_QT5) @@ -203,6 +206,9 @@ SET(TechDrawGui_SRCS TaskActiveView.h Grabber3d.cpp Grabber3d.h + TaskDetail.ui + TaskDetail.cpp + TaskDetail.h ) SET(TechDrawGuiView_SRCS @@ -299,6 +305,8 @@ SET(TechDrawGuiView_SRCS TemplateTextField.cpp TemplateTextField.h ZVALUE.h + QGIGhostHighlight.cpp + QGIGhostHighlight.h ) SET(TechDrawGuiViewProvider_SRCS ViewProviderPage.cpp @@ -366,6 +374,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskWeldingSymbol.ui SymbolChooser.ui TaskActiveView.ui + TaskDetail.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index e28271917e..89b680d198 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -1,1392 +1,1378 @@ -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License as * - * published by the Free Software Foundation; either version 2 of the * - * License, or (at your option) any later version. * - * for detail see the LICENCE text file. * - * Jürgen Riegel 2002 * - * Copyright (c) 2014 Luke Parry * - * * - ***************************************************************************/ - -#include "PreCompiled.h" -#ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -#endif - -#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 -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "DrawGuiUtil.h" -#include "MDIViewPage.h" -#include "TaskProjGroup.h" -#include "TaskSectionView.h" -#include "TaskActiveView.h" -#include "ViewProviderPage.h" - -using namespace TechDrawGui; -using namespace std; - - -//=========================================================================== -// TechDraw_PageDefault -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawPageDefault) - -CmdTechDrawPageDefault::CmdTechDrawPageDefault() - : Command("TechDraw_PageDefault") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Default Page"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_PageDefault"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-PageDefault"; -} - -void CmdTechDrawPageDefault::activated(int iMsg) -{ - Q_UNUSED(iMsg); - Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); - - std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Templates/"; - std::string defaultFileName = defaultDir + "A4_LandscapeTD.svg"; - QString templateFileName = QString::fromStdString(hGrp->GetASCII("TemplateFile",defaultFileName.c_str())); - if (templateFileName.isEmpty()) { - templateFileName = QString::fromStdString(defaultFileName); - } - - std::string PageName = getUniqueObjectName("Page"); - std::string TemplateName = getUniqueObjectName("Template"); - - QFileInfo tfi(templateFileName); - if (tfi.isReadable()) { - Gui::WaitCursor wc; - openCommand("Drawing create page"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",PageName.c_str()); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')",TemplateName.c_str()); - - doCommand(Doc,"App.activeDocument().%s.Template = '%s'",TemplateName.c_str(), templateFileName.toStdString().c_str()); - doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str()); - - commitCommand(); - TechDraw::DrawPage* fp = dynamic_cast(getDocument()->getObject(PageName.c_str())); - if (!fp) { - throw Base::TypeError("CmdTechDrawPageDefault fp not found\n"); - } - - Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); - TechDrawGui::ViewProviderPage* dvp = dynamic_cast(vp); - if (dvp) { - dvp->show(); - } - else { - Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(),TemplateName.c_str()); - } - } else { - QMessageBox::critical(Gui::getMainWindow(), - QLatin1String("No template"), - QLatin1String("No default template found")); - } -} - -bool CmdTechDrawPageDefault::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// TechDraw_PageTemplate -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawPageTemplate) - -CmdTechDrawPageTemplate::CmdTechDrawPageTemplate() - : Command("TechDraw_PageTemplate") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Page using Template"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_PageTemplate"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-PageTemplate"; -} - -void CmdTechDrawPageTemplate::activated(int iMsg) -{ - Q_UNUSED(iMsg); - Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); - - std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Templates"; - QString templateDir = QString::fromStdString(hGrp->GetASCII("TemplateDir", defaultDir.c_str())); - QString templateFileName = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), - QString::fromUtf8(QT_TR_NOOP("Select a Template File")), - templateDir, - QString::fromUtf8(QT_TR_NOOP("Template (*.svg *.dxf)"))); - - if (templateFileName.isEmpty()) { - return; - } - - std::string PageName = getUniqueObjectName("Page"); - std::string TemplateName = getUniqueObjectName("Template"); - - QFileInfo tfi(templateFileName); - if (tfi.isReadable()) { - Gui::WaitCursor wc; - openCommand("Drawing create page"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",PageName.c_str()); - - // Create the Template Object to attach to the page - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')",TemplateName.c_str()); - - //why is "Template" property set twice? -wf - // once to set DrawSVGTemplate.Template to OS template file name - templateFileName = Base::Tools::escapeEncodeFilename(templateFileName); - doCommand(Doc,"App.activeDocument().%s.Template = \"%s\"",TemplateName.c_str(), templateFileName.toUtf8().constData()); - // once to set Page.Template to DrawSVGTemplate.Name - doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str()); - // consider renaming DrawSVGTemplate.Template property? - - commitCommand(); - TechDraw::DrawPage* fp = dynamic_cast(getDocument()->getObject(PageName.c_str())); - if (!fp) { - throw Base::TypeError("CmdTechDrawNewPagePick fp not found\n"); - } - Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); - TechDrawGui::ViewProviderPage* dvp = dynamic_cast(vp); - if (dvp) { - dvp->show(); - } - else { - Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(),TemplateName.c_str()); - } - } - else { - QMessageBox::critical(Gui::getMainWindow(), - QLatin1String("No template"), - QLatin1String("Template file is invalid")); - } -} - -bool CmdTechDrawPageTemplate::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// TechDraw_RedrawPage -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawRedrawPage) - -CmdTechDrawRedrawPage::CmdTechDrawRedrawPage() - : Command("TechDraw_RedrawPage") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Redraw Page"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_RedrawPage"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-RedrawPage"; -} - -void CmdTechDrawRedrawPage::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - Gui::WaitCursor wc; - - page->redrawCommand(); -} - -bool CmdTechDrawRedrawPage::isActive(void) -{ - bool havePage = DrawGuiUtil::needPage(this); - bool haveView = DrawGuiUtil::needView(this,false); - return (havePage && haveView); -} - -//=========================================================================== -// TechDraw_View -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawView) - -CmdTechDrawView::CmdTechDrawView() - : Command("TechDraw_View") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert View"); - sToolTipText = QT_TR_NOOP("Insert a View"); - sWhatsThis = "TechDraw_View"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-View"; -} - -void CmdTechDrawView::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); - - //set projection direction from selected Face - //use first object with a face selected - std::vector shapes; - App::DocumentObject* partObj = nullptr; - std::string faceName; - int resolve = 1; //mystery - bool single = false; //mystery - auto selection = getSelection().getSelectionEx(0, - App::DocumentObject::getClassTypeId(), - resolve, - single); - for (auto& sel: selection) { - auto obj = sel.getObject(); - if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ) { - continue; - } - if (obj != nullptr) { - shapes.push_back(obj); - } - if(partObj != nullptr) { - continue; - } - for(auto& sub : sel.getSubNames()) { - if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") { - faceName = sub; - partObj = obj; - break; - } - } - } - - if ((shapes.empty())) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No Shapes, Groups or Links in this selection")); - return; - } - - Base::Vector3d projDir; - - Gui::WaitCursor wc; - openCommand("Create view"); - std::string FeatName = getUniqueObjectName("View"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewPart','%s')",FeatName.c_str()); - App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str()); - TechDraw::DrawViewPart* dvp = dynamic_cast(docObj); - if (!dvp) { - throw Base::TypeError("CmdTechDrawView DVP not found\n"); - } - dvp->Source.setValues(shapes); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - if (faceName.size()) { - std::pair dirs = DrawGuiUtil::getProjDirFromFace(partObj,faceName); - projDir = dirs.first; - getDocument()->setStatus(App::Document::Status::SkipRecompute, true); - doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", - FeatName.c_str(), projDir.x,projDir.y,projDir.z); - //do something clever with dirs.second; -// dvp->setXDir(dirs.second); - doCommand(Doc,"App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", - FeatName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); - doCommand(Doc,"App.activeDocument().%s.recompute()", FeatName.c_str()); - getDocument()->setStatus(App::Document::Status::SkipRecompute, false); - } else { - std::pair dirs = DrawGuiUtil::get3DDirAndRot(); - projDir = dirs.first; - getDocument()->setStatus(App::Document::Status::SkipRecompute, true); - doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", - FeatName.c_str(), projDir.x,projDir.y,projDir.z); - doCommand(Doc,"App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", - FeatName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); -// dvp->setXDir(dirs.second); - getDocument()->setStatus(App::Document::Status::SkipRecompute, false); - doCommand(Doc,"App.activeDocument().%s.recompute()", FeatName.c_str()); - } - commitCommand(); -} - -bool CmdTechDrawView::isActive(void) -{ - return DrawGuiUtil::needPage(this); -} - -//=========================================================================== -// TechDraw_ActiveView -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawActiveView) - -CmdTechDrawActiveView::CmdTechDrawActiveView() - : Command("TechDraw_ActiveView") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Active View (3D View)"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ActiveView"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-ActiveView"; -} - -void CmdTechDrawActiveView::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); - Gui::Control().showDialog(new TaskDlgActiveView(page)); -} - -bool CmdTechDrawActiveView::isActive(void) -{ - return DrawGuiUtil::needPage(this); -} - -//=========================================================================== -// TechDraw_SectionView -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawSectionView) - -CmdTechDrawSectionView::CmdTechDrawSectionView() - : Command("TechDraw_SectionView") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Section View"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_SectionView"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-SectionView"; -} - -void CmdTechDrawSectionView::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - - std::vector baseObj = getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); - if (baseObj.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least 1 DrawViewPart object as Base.")); - return; - } - TechDraw::DrawViewPart* dvp = static_cast(*baseObj.begin()); -// 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"); - -// 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("CmdTechDrawSectionView 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(); -} - -bool CmdTechDrawSectionView::isActive(void) -{ - bool havePage = DrawGuiUtil::needPage(this); - bool haveView = DrawGuiUtil::needView(this); - bool taskInProgress = false; - if (havePage) { - taskInProgress = Gui::Control().activeDialog(); - } - return (havePage && haveView && !taskInProgress); -} - -//=========================================================================== -// TechDraw_DetailView -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawDetailView) - -CmdTechDrawDetailView::CmdTechDrawDetailView() - : Command("TechDraw_DetailView") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Detail View"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_DetailView"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-DetailView"; -} - -void CmdTechDrawDetailView::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - - std::vector baseObj = getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); - if (baseObj.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least 1 DrawViewPart object as Base.")); - return; - } - TechDraw::DrawViewPart* dvp = static_cast(*(baseObj.begin())); - - std::string PageName = page->getNameInDocument(); - - Gui::WaitCursor wc; - openCommand("Create view"); - - std::string FeatName = getUniqueObjectName("Detail"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDetail','%s')",FeatName.c_str()); - App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str()); - TechDraw::DrawViewDetail* dvd = dynamic_cast(docObj); - if (!dvd) { - throw Base::TypeError("CmdTechDrawDetailView DVD not found\n"); - } - dvd->Source.setValues(dvp->Source.getValues()); - - doCommand(Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s",FeatName.c_str(),dvp->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.Direction = App.activeDocument().%s.Direction",FeatName.c_str(),dvp->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.XDirection = App.activeDocument().%s.XDirection",FeatName.c_str(),dvp->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - - updateActive(); //ok here, no preceding recompute - commitCommand(); -} - -bool CmdTechDrawDetailView::isActive(void) -{ - bool havePage = DrawGuiUtil::needPage(this); - bool haveView = DrawGuiUtil::needView(this); - bool taskInProgress = false; - if (havePage) { - taskInProgress = Gui::Control().activeDialog(); - } - return (havePage && haveView && !taskInProgress); -} - -//=========================================================================== -// TechDraw_ProjectionGroup -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawProjectionGroup) - -CmdTechDrawProjectionGroup::CmdTechDrawProjectionGroup() - : Command("TechDraw_ProjectionGroup") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Projection Group"); - sToolTipText = QT_TR_NOOP("Insert multiple linked views of drawable object(s)"); - sWhatsThis = "TechDraw_ProjectionGroup"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-ProjectionGroup"; -} - -void CmdTechDrawProjectionGroup::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); -// auto inlist = page->getInListEx(true); -// inlist.insert(page); - - //set projection direction from selected Face - //use first object with a face selected - std::vector shapes; - App::DocumentObject* partObj = nullptr; - std::string faceName; - int resolve = 1; //mystery - bool single = false; //mystery - auto selection = getSelection().getSelectionEx(0, - App::DocumentObject::getClassTypeId(), - resolve, - single); - for (auto& sel: selection) { -// for(auto &sel : getSelection().getSelectionEx(0,App::DocumentObject::getClassTypeId(),false)) { - auto obj = sel.getObject(); - if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ) { - continue; - } -// if(!obj || inlist.count(obj)) //?????? -// continue; - if (obj != nullptr) { //can this happen? - shapes.push_back(obj); - } - if(partObj != nullptr) { - continue; - } - for(auto& sub : sel.getSubNames()) { - if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") { - faceName = sub; - partObj = obj; - break; - } - } - } - if (shapes.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No Shapes or Groups in this selection")); - return; - } - - Base::Vector3d projDir; - Gui::WaitCursor wc; - - openCommand("Create Projection Group"); - - std::string multiViewName = getUniqueObjectName("ProjGroup"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawProjGroup','%s')", - multiViewName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", - PageName.c_str(),multiViewName.c_str()); - - App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str()); - auto multiView( static_cast(docObj) ); - multiView->Source.setValues(shapes); - doCommand(Doc,"App.activeDocument().%s.addProjection('Front')",multiViewName.c_str()); - - if (faceName.size()) { - std::pair dirs = DrawGuiUtil::getProjDirFromFace(partObj,faceName); - getDocument()->setStatus(App::Document::Status::SkipRecompute, true); - doCommand(Doc,"App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", - multiViewName.c_str(), dirs.first.x,dirs.first.y,dirs.first.z); - doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)", - multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); - doCommand(Doc,"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", - multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); - getDocument()->setStatus(App::Document::Status::SkipRecompute, false); - } else { - std::pair dirs = DrawGuiUtil::get3DDirAndRot(); - getDocument()->setStatus(App::Document::Status::SkipRecompute, true); - doCommand(Doc,"App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", - multiViewName.c_str(), dirs.first.x,dirs.first.y,dirs.first.z); - doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)", - multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); - doCommand(Doc,"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", - multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); - getDocument()->setStatus(App::Document::Status::SkipRecompute, false); - } - - doCommand(Doc,"App.activeDocument().%s.Anchor.recompute()", multiViewName.c_str()); - commitCommand(); - updateActive(); - - // create the rest of the desired views - Gui::Control().showDialog(new TaskDlgProjGroup(multiView,true)); -} - -bool CmdTechDrawProjectionGroup::isActive(void) -{ - bool havePage = DrawGuiUtil::needPage(this); - bool taskInProgress = false; - if (havePage) { - taskInProgress = Gui::Control().activeDialog(); - } - return (havePage && !taskInProgress); -} - -//=========================================================================== -// TechDraw_NewMulti **deprecated** -//=========================================================================== - -//DEF_STD_CMD_A(CmdTechDrawNewMulti); - -//CmdTechDrawNewMulti::CmdTechDrawNewMulti() -// : Command("TechDraw_NewMulti") -//{ -// sAppModule = "TechDraw"; -// sGroup = QT_TR_NOOP("TechDraw"); -// sMenuText = QT_TR_NOOP("Insert multi-part view in drawing"); -// sToolTipText = QT_TR_NOOP("Insert a new View of a multiple Parts in the active drawing"); -// sWhatsThis = "TechDraw_NewMulti"; -// sStatusTip = sToolTipText; -// sPixmap = "actions/techdraw-multiview"; -//} - -//void CmdTechDrawNewMulti::activated(int iMsg) -//{ -// Q_UNUSED(iMsg); -// TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); -// if (!page) { -// return; -// } - -// std::vector shapes = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); -// if (shapes.empty()) { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), -// QObject::tr("Can not MultiView from this selection.")); -// return; -// } - -// std::string PageName = page->getNameInDocument(); - -// Gui::WaitCursor wc; - -// openCommand("Create view"); -// std::string FeatName = getUniqueObjectName("MultiView"); -// doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewMulti','%s')",FeatName.c_str()); -// App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str()); -// auto multiView( static_cast(docObj) ); -// multiView->Sources.setValues(shapes); -// doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); -// updateActive(); -// commitCommand(); -//} - -//bool CmdTechDrawNewMulti::isActive(void) -//{ -// return DrawGuiUtil::needPage(this); -//} - -//=========================================================================== -// TechDraw_Balloon -//=========================================================================== - -//! common checks of Selection for Dimension commands -//non-empty selection, no more than maxObjs selected and at least 1 DrawingPage exists -bool _checkSelectionBalloon(Gui::Command* cmd, unsigned maxObjs) { - std::vector selection = cmd->getSelection().getSelectionEx(); - if (selection.size() == 0) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), - QObject::tr("Select an object first")); - return false; - } - - const std::vector SubNames = selection[0].getSubNames(); - if (SubNames.size() > maxObjs){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), - QObject::tr("Too many objects selected")); - return false; - } - - std::vector pages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); - if (pages.empty()){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), - QObject::tr("Create a page first.")); - return false; - } - return true; -} - -bool _checkDrawViewPartBalloon(Gui::Command* cmd) { - std::vector selection = cmd->getSelection().getSelectionEx(); - auto objFeat( dynamic_cast(selection[0].getObject()) ); - if( !objFeat ) { - QMessageBox::warning( Gui::getMainWindow(), - QObject::tr("Incorrect selection"), - QObject::tr("No View of a Part in selection.") ); - return false; - } - return true; -} - -DEF_STD_CMD_A(CmdTechDrawBalloon) - -CmdTechDrawBalloon::CmdTechDrawBalloon() - : Command("TechDraw_Balloon") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Balloon Annotation"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_Balloon"; - sStatusTip = sToolTipText; - sPixmap = "TechDraw_Balloon"; -} - -void CmdTechDrawBalloon::activated(int iMsg) -{ - Q_UNUSED(iMsg); - bool result = _checkSelectionBalloon(this,1); - if (!result) - return; - result = _checkDrawViewPartBalloon(this); - if (!result) - return; - - std::vector selection = getSelection().getSelectionEx(); - auto objFeat( dynamic_cast(selection[0].getObject()) ); - if( objFeat == nullptr ) { - return; - } - - TechDraw::DrawPage* page = objFeat->findParentPage(); - std::string PageName = page->getNameInDocument(); - - page->balloonParent = objFeat; - page->balloonPlacing = true; - -} - -bool CmdTechDrawBalloon::isActive(void) -{ - bool havePage = DrawGuiUtil::needPage(this); - bool haveView = DrawGuiUtil::needView(this); - return (havePage && haveView); -} - -//=========================================================================== -// TechDraw_ClipGroup -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawClipGroup) - -CmdTechDrawClipGroup::CmdTechDrawClipGroup() - : Command("TechDraw_ClipGroup") -{ - // setting the - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Clip Group"); - sToolTipText = sToolTipText; - sWhatsThis = "TechDraw_ClipGroup"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-ClipGroup"; -} - -void CmdTechDrawClipGroup::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); - - std::string FeatName = getUniqueObjectName("Clip"); - openCommand("Create Clip"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewClip','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - updateActive(); - commitCommand(); -} - -bool CmdTechDrawClipGroup::isActive(void) -{ - return DrawGuiUtil::needPage(this); -} - -//=========================================================================== -// TechDraw_ClipGroupAdd -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawClipGroupAdd) - -CmdTechDrawClipGroupAdd::CmdTechDrawClipGroupAdd() - : Command("TechDraw_ClipGroupAdd") -{ - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add View to Clip Group"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ClipGroupAdd"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-ClipGroupAdd"; -} - -void CmdTechDrawClipGroupAdd::activated(int iMsg) -{ - Q_UNUSED(iMsg); - std::vector selection = getSelection().getSelectionEx(); - if (selection.size() != 2) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select one Clip group and one View.")); - return; - } - - TechDraw::DrawViewClip* clip = 0; - TechDraw::DrawView* view = 0; - std::vector::iterator itSel = selection.begin(); - for (; itSel != selection.end(); itSel++) { - if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) { - clip = static_cast((*itSel).getObject()); - } else if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { - view = static_cast((*itSel).getObject()); - } - } - if (!view) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one View to add to group.")); - return; - } - if (!clip) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one Clip group.")); - return; - } - - TechDraw::DrawPage* pageClip = clip->findParentPage(); - TechDraw::DrawPage* pageView = view->findParentPage(); - - if (pageClip != pageView) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Clip and View must be from same Page.")); - return; - } - - std::string PageName = pageClip->getNameInDocument(); - std::string ClipName = clip->getNameInDocument(); - std::string ViewName = view->getNameInDocument(); - - openCommand("ClipGroupAdd"); - doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = False",ViewName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",ClipName.c_str(),ViewName.c_str()); - doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = True",ViewName.c_str()); - updateActive(); - commitCommand(); -} - -bool CmdTechDrawClipGroupAdd::isActive(void) -{ - bool havePage = DrawGuiUtil::needPage(this); - bool haveClip = false; - if (havePage) { - auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() ); - auto selClips = getDocument()->getObjectsOfType(drawClipType); - if (!selClips.empty()) { - haveClip = true; - } - } - return (havePage && haveClip); -} - -//=========================================================================== -// TechDraw_ClipGroupRemove -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawClipGroupRemove) - -CmdTechDrawClipGroupRemove::CmdTechDrawClipGroupRemove() - : Command("TechDraw_ClipGroupRemove") -{ - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Remove View from Clip Group"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ClipGroupRemove"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-ClipGroupRemove"; -} - -void CmdTechDrawClipGroupRemove::activated(int iMsg) -{ - Q_UNUSED(iMsg); - auto dObj( getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()) ); - if (dObj.empty()) { - QMessageBox::warning( Gui::getMainWindow(), - QObject::tr("Wrong selection"), - QObject::tr("Select exactly one View to remove from Group.") ); - return; - } - - auto view( static_cast(dObj.front()) ); - - TechDraw::DrawPage* page = view->findParentPage(); - const std::vector pViews = page->Views.getValues(); - TechDraw::DrawViewClip *clip(nullptr); - for (auto &v : pViews) { - clip = dynamic_cast(v); - if (clip && clip->isViewInClip(view)) { - break; - } - clip = nullptr; - } - - if (!clip) { - QMessageBox::warning( Gui::getMainWindow(), - QObject::tr("Wrong selection"), - QObject::tr("View does not belong to a Clip") ); - return; - } - - std::string ClipName = clip->getNameInDocument(); - std::string ViewName = view->getNameInDocument(); - - openCommand("ClipGroupRemove"); - doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = False",ViewName.c_str()); - doCommand(Doc,"App.activeDocument().%s.removeView(App.activeDocument().%s)",ClipName.c_str(),ViewName.c_str()); - doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = True",ViewName.c_str()); - updateActive(); - commitCommand(); -} - -bool CmdTechDrawClipGroupRemove::isActive(void) -{ - bool havePage = DrawGuiUtil::needPage(this); - bool haveClip = false; - if (havePage) { - auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() ); - auto selClips = getDocument()->getObjectsOfType(drawClipType); - if (!selClips.empty()) { - haveClip = true; - } - } - return (havePage && haveClip); -} - - -//=========================================================================== -// TechDraw_Symbol -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawSymbol) - -CmdTechDrawSymbol::CmdTechDrawSymbol() - : Command("TechDraw_Symbol") -{ - // setting the Gui eye-candy - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert SVG Symbol"); - sToolTipText = QT_TR_NOOP("Insert symbol from a SVG file"); - sWhatsThis = "TechDraw_Symbol"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-symbol"; -} - -void CmdTechDrawSymbol::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); - - // Reading an image - QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QObject::tr("Choose an SVG file to open"), QString::null, - QString::fromLatin1("%1 (*.svg *.svgz)").arg(QObject::tr("Scalable Vector Graphic"))); - if (!filename.isEmpty()) - { - std::string FeatName = getUniqueObjectName("Symbol"); - filename = Base::Tools::escapeEncodeFilename(filename); - openCommand("Create Symbol"); -#if PY_MAJOR_VERSION < 3 - doCommand(Doc,"f = open(unicode(\"%s\",'utf-8'),'r')",(const char*)filename.toUtf8()); -#else - doCommand(Doc,"f = open(\"%s\",'r')",(const char*)filename.toUtf8()); -#endif - doCommand(Doc,"svg = f.read()"); - doCommand(Doc,"f.close()"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSymbol','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Symbol = svg",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - updateActive(); - commitCommand(); - } -} - -bool CmdTechDrawSymbol::isActive(void) -{ - return DrawGuiUtil::needPage(this); -} - -//=========================================================================== -// TechDraw_DraftView -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawDraftView) - -CmdTechDrawDraftView::CmdTechDrawDraftView() - : Command("TechDraw_DraftView") -{ - // setting the Gui eye-candy - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Draft Workbench Object"); - sToolTipText = QT_TR_NOOP("Insert a View of a Draft Workbench object"); - sWhatsThis = "TechDraw_NewDraft"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-DraftView"; -} - -void CmdTechDrawDraftView::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); - - std::vector objects = getSelection(). - getObjectsOfType(App::DocumentObject::getClassTypeId()); - - if (objects.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least one object.")); - return; - } - - int draftItemsFound = 0; - for (std::vector::iterator it = objects.begin(); it != objects.end(); ++it) { - if (DrawGuiUtil::isDraftObject((*it))) { - draftItemsFound++; - std::string FeatName = getUniqueObjectName("DraftView"); - std::string SourceName = (*it)->getNameInDocument(); - openCommand("Create DraftView"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDraft','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s", - FeatName.c_str(),SourceName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", - PageName.c_str(),FeatName.c_str()); - updateActive(); - commitCommand(); - } - } - if (draftItemsFound == 0) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("There were no DraftWB objects in the selection.")); - } -} - -bool CmdTechDrawDraftView::isActive(void) -{ - return DrawGuiUtil::needPage(this); -} - -//=========================================================================== -// TechDraw_ArchView -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawArchView) - -CmdTechDrawArchView::CmdTechDrawArchView() - : Command("TechDraw_ArchView") -{ - // setting the Gui eye-candy - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Arch Workbench Object"); - sToolTipText = QT_TR_NOOP("Insert a View of a Section Plane from Arch Workbench"); - sWhatsThis = "TechDraw_NewArch"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-ArchView"; -} - -void CmdTechDrawArchView::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); - - - const std::vector objects = getSelection(). - getObjectsOfType(App::DocumentObject::getClassTypeId()); - App::DocumentObject* archObject = nullptr; - int archCount = 0; - for (auto& obj : objects) { - if (DrawGuiUtil::isArchSection(obj) ) { - archCount++; - archObject = obj; - } - } - if ( archCount > 1 ) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Please select only 1 Arch Section.")); - return; - } - - if (archObject == nullptr) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No Arch Sections in selection.")); - return; - } - - std::string FeatName = getUniqueObjectName("ArchView"); - std::string SourceName = archObject->getNameInDocument(); - openCommand("Create ArchView"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewArch','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SourceName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - updateActive(); - commitCommand(); -} - -bool CmdTechDrawArchView::isActive(void) -{ - return DrawGuiUtil::needPage(this); -} - -//=========================================================================== -// TechDraw_SpreadsheetView -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawSpreadsheetView) - -CmdTechDrawSpreadsheetView::CmdTechDrawSpreadsheetView() - : Command("TechDraw_SpreadsheetView") -{ - // setting the - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Spreadsheet View"); - sToolTipText = QT_TR_NOOP("Insert View to a spreadsheet"); - sWhatsThis = "TechDraw_SpreadsheetView"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-SpreadsheetView"; -} - -void CmdTechDrawSpreadsheetView::activated(int iMsg) -{ - Q_UNUSED(iMsg); - const std::vector spreads = getSelection().getObjectsOfType(Spreadsheet::Sheet::getClassTypeId()); - if (spreads.size() != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one Spreadsheet object.")); - return; - } - std::string SpreadName = spreads.front()->getNameInDocument(); - - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); - - openCommand("Create spreadsheet view"); - std::string FeatName = getUniqueObjectName("Sheet"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SpreadName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - updateActive(); - commitCommand(); -} - -bool CmdTechDrawSpreadsheetView::isActive(void) -{ - //need a Page and a SpreadSheet::Sheet - bool havePage = DrawGuiUtil::needPage(this); - bool haveSheet = false; - if (havePage) { - auto spreadSheetType( Spreadsheet::Sheet::getClassTypeId() ); - auto selSheets = getDocument()->getObjectsOfType(spreadSheetType); - if (!selSheets.empty()) { - haveSheet = true; - } - } - return (havePage && haveSheet); -} - - -//=========================================================================== -// TechDraw_ExportPageSVG -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawExportPageSVG) - -CmdTechDrawExportPageSVG::CmdTechDrawExportPageSVG() - : Command("TechDraw_ExportPageSVG") -{ - sGroup = QT_TR_NOOP("File"); - sMenuText = QT_TR_NOOP("Export Page as SVG"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ExportPageSVG"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-ExportPageSVG"; -} - -void CmdTechDrawExportPageSVG::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); - - Gui::Document* activeGui = Gui::Application::Instance->getDocument(page->getDocument()); - Gui::ViewProvider* vp = activeGui->getViewProvider(page); - ViewProviderPage* dvp = dynamic_cast(vp); - - if (dvp && dvp->getMDIViewPage()) { - dvp->getMDIViewPage()->saveSVG(); - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Drawing View"), - QObject::tr("Open Drawing View before attempting export to SVG.")); - return; - } -} - -bool CmdTechDrawExportPageSVG::isActive(void) -{ - return DrawGuiUtil::needPage(this); -} - -//=========================================================================== -// TechDraw_ExportPageDXF -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawExportPageDXF) - -CmdTechDrawExportPageDXF::CmdTechDrawExportPageDXF() - : Command("TechDraw_ExportPageDXF") -{ - sGroup = QT_TR_NOOP("File"); - sMenuText = QT_TR_NOOP("Export Page as DXF"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ExportPageDXF"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-ExportPageDXF"; -} - -void CmdTechDrawExportPageDXF::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - - std::vector views = page->Views.getValues(); - for (auto& v: views) { - if (v->isDerivedFrom(TechDraw::DrawViewArch::getClassTypeId())) { - QMessageBox::StandardButton rc = - QMessageBox::question(Gui::getMainWindow(), QObject::tr("Can not export selection"), - QObject::tr("Page contains DrawViewArch which will not be exported. Continue?"), - QMessageBox::StandardButtons(QMessageBox::Yes| QMessageBox::No)); - if (rc == QMessageBox::No) { - return; - } else { - break; - } - } - } - -//WF? allow more than one TD Page per Dxf file?? 1 TD page = 1 DXF file = 1 drawing? - QString defaultDir; - QString fileName = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), - QString::fromUtf8(QT_TR_NOOP("Save Dxf File ")), - defaultDir, - QString::fromUtf8(QT_TR_NOOP("Dxf (*.dxf)"))); - - if (fileName.isEmpty()) { - return; - } - - std::string PageName = page->getNameInDocument(); - openCommand("Save page to dxf"); - doCommand(Doc,"import TechDraw"); - fileName = Base::Tools::escapeEncodeFilename(fileName); - doCommand(Doc,"TechDraw.writeDXFPage(App.activeDocument().%s,u\"%s\")",PageName.c_str(),(const char*)fileName.toUtf8()); - commitCommand(); -} - - -bool CmdTechDrawExportPageDXF::isActive(void) -{ - return DrawGuiUtil::needPage(this); -} - -void CreateTechDrawCommands(void) -{ - Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); - - rcCmdMgr.addCommand(new CmdTechDrawPageDefault()); - rcCmdMgr.addCommand(new CmdTechDrawPageTemplate()); - rcCmdMgr.addCommand(new CmdTechDrawRedrawPage()); - rcCmdMgr.addCommand(new CmdTechDrawView()); - rcCmdMgr.addCommand(new CmdTechDrawActiveView()); - rcCmdMgr.addCommand(new CmdTechDrawSectionView()); - rcCmdMgr.addCommand(new CmdTechDrawDetailView()); - rcCmdMgr.addCommand(new CmdTechDrawProjectionGroup()); - rcCmdMgr.addCommand(new CmdTechDrawClipGroup()); - rcCmdMgr.addCommand(new CmdTechDrawClipGroupAdd()); - rcCmdMgr.addCommand(new CmdTechDrawClipGroupRemove()); - rcCmdMgr.addCommand(new CmdTechDrawSymbol()); - rcCmdMgr.addCommand(new CmdTechDrawExportPageSVG()); - rcCmdMgr.addCommand(new CmdTechDrawExportPageDXF()); - rcCmdMgr.addCommand(new CmdTechDrawDraftView()); - rcCmdMgr.addCommand(new CmdTechDrawArchView()); - rcCmdMgr.addCommand(new CmdTechDrawSpreadsheetView()); - rcCmdMgr.addCommand(new CmdTechDrawBalloon()); -} +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * for detail see the LICENCE text file. * + * Jürgen Riegel 2002 * + * Copyright (c) 2014 Luke Parry * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +#endif + +#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 +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DrawGuiUtil.h" +#include "MDIViewPage.h" +#include "TaskProjGroup.h" +#include "TaskSectionView.h" +#include "TaskActiveView.h" +#include "TaskDetail.h" +#include "ViewProviderPage.h" + +using namespace TechDrawGui; +using namespace std; + + +//=========================================================================== +// TechDraw_PageDefault +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawPageDefault) + +CmdTechDrawPageDefault::CmdTechDrawPageDefault() + : Command("TechDraw_PageDefault") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Default Page"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_PageDefault"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-PageDefault"; +} + +void CmdTechDrawPageDefault::activated(int iMsg) +{ + Q_UNUSED(iMsg); + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); + + std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Templates/"; + std::string defaultFileName = defaultDir + "A4_LandscapeTD.svg"; + QString templateFileName = QString::fromStdString(hGrp->GetASCII("TemplateFile",defaultFileName.c_str())); + if (templateFileName.isEmpty()) { + templateFileName = QString::fromStdString(defaultFileName); + } + + std::string PageName = getUniqueObjectName("Page"); + std::string TemplateName = getUniqueObjectName("Template"); + + QFileInfo tfi(templateFileName); + if (tfi.isReadable()) { + Gui::WaitCursor wc; + openCommand("Drawing create page"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",PageName.c_str()); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')",TemplateName.c_str()); + + doCommand(Doc,"App.activeDocument().%s.Template = '%s'",TemplateName.c_str(), templateFileName.toStdString().c_str()); + doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str()); + + commitCommand(); + TechDraw::DrawPage* fp = dynamic_cast(getDocument()->getObject(PageName.c_str())); + if (!fp) { + throw Base::TypeError("CmdTechDrawPageDefault fp not found\n"); + } + + Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); + TechDrawGui::ViewProviderPage* dvp = dynamic_cast(vp); + if (dvp) { + dvp->show(); + } + else { + Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(),TemplateName.c_str()); + } + } else { + QMessageBox::critical(Gui::getMainWindow(), + QLatin1String("No template"), + QLatin1String("No default template found")); + } +} + +bool CmdTechDrawPageDefault::isActive(void) +{ + return hasActiveDocument(); +} + +//=========================================================================== +// TechDraw_PageTemplate +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawPageTemplate) + +CmdTechDrawPageTemplate::CmdTechDrawPageTemplate() + : Command("TechDraw_PageTemplate") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Page using Template"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_PageTemplate"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-PageTemplate"; +} + +void CmdTechDrawPageTemplate::activated(int iMsg) +{ + Q_UNUSED(iMsg); + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); + + std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Templates"; + QString templateDir = QString::fromStdString(hGrp->GetASCII("TemplateDir", defaultDir.c_str())); + QString templateFileName = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), + QString::fromUtf8(QT_TR_NOOP("Select a Template File")), + templateDir, + QString::fromUtf8(QT_TR_NOOP("Template (*.svg *.dxf)"))); + + if (templateFileName.isEmpty()) { + return; + } + + std::string PageName = getUniqueObjectName("Page"); + std::string TemplateName = getUniqueObjectName("Template"); + + QFileInfo tfi(templateFileName); + if (tfi.isReadable()) { + Gui::WaitCursor wc; + openCommand("Drawing create page"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawPage','%s')",PageName.c_str()); + + // Create the Template Object to attach to the page + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawSVGTemplate','%s')",TemplateName.c_str()); + + //why is "Template" property set twice? -wf + // once to set DrawSVGTemplate.Template to OS template file name + templateFileName = Base::Tools::escapeEncodeFilename(templateFileName); + doCommand(Doc,"App.activeDocument().%s.Template = \"%s\"",TemplateName.c_str(), templateFileName.toUtf8().constData()); + // once to set Page.Template to DrawSVGTemplate.Name + doCommand(Doc,"App.activeDocument().%s.Template = App.activeDocument().%s",PageName.c_str(),TemplateName.c_str()); + // consider renaming DrawSVGTemplate.Template property? + + commitCommand(); + TechDraw::DrawPage* fp = dynamic_cast(getDocument()->getObject(PageName.c_str())); + if (!fp) { + throw Base::TypeError("CmdTechDrawNewPagePick fp not found\n"); + } + Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); + TechDrawGui::ViewProviderPage* dvp = dynamic_cast(vp); + if (dvp) { + dvp->show(); + } + else { + Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(),TemplateName.c_str()); + } + } + else { + QMessageBox::critical(Gui::getMainWindow(), + QLatin1String("No template"), + QLatin1String("Template file is invalid")); + } +} + +bool CmdTechDrawPageTemplate::isActive(void) +{ + return hasActiveDocument(); +} + +//=========================================================================== +// TechDraw_RedrawPage +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawRedrawPage) + +CmdTechDrawRedrawPage::CmdTechDrawRedrawPage() + : Command("TechDraw_RedrawPage") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Redraw Page"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_RedrawPage"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-RedrawPage"; +} + +void CmdTechDrawRedrawPage::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + Gui::WaitCursor wc; + + page->redrawCommand(); +} + +bool CmdTechDrawRedrawPage::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this,false); + return (havePage && haveView); +} + +//=========================================================================== +// TechDraw_View +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawView) + +CmdTechDrawView::CmdTechDrawView() + : Command("TechDraw_View") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert View"); + sToolTipText = QT_TR_NOOP("Insert a View"); + sWhatsThis = "TechDraw_View"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-View"; +} + +void CmdTechDrawView::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + //set projection direction from selected Face + //use first object with a face selected + std::vector shapes; + App::DocumentObject* partObj = nullptr; + std::string faceName; + int resolve = 1; //mystery + bool single = false; //mystery + auto selection = getSelection().getSelectionEx(0, + App::DocumentObject::getClassTypeId(), + resolve, + single); + for (auto& sel: selection) { + auto obj = sel.getObject(); + if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ) { + continue; + } + if (obj != nullptr) { + shapes.push_back(obj); + } + if(partObj != nullptr) { + continue; + } + for(auto& sub : sel.getSubNames()) { + if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") { + faceName = sub; + partObj = obj; + break; + } + } + } + + if ((shapes.empty())) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("No Shapes, Groups or Links in this selection")); + return; + } + + Base::Vector3d projDir; + + Gui::WaitCursor wc; + openCommand("Create view"); + std::string FeatName = getUniqueObjectName("View"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewPart','%s')",FeatName.c_str()); + App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str()); + TechDraw::DrawViewPart* dvp = dynamic_cast(docObj); + if (!dvp) { + throw Base::TypeError("CmdTechDrawView DVP not found\n"); + } + dvp->Source.setValues(shapes); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + if (faceName.size()) { + std::pair dirs = DrawGuiUtil::getProjDirFromFace(partObj,faceName); + projDir = dirs.first; + getDocument()->setStatus(App::Document::Status::SkipRecompute, true); + doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", + FeatName.c_str(), projDir.x,projDir.y,projDir.z); + //do something clever with dirs.second; +// dvp->setXDir(dirs.second); + doCommand(Doc,"App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", + FeatName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); + doCommand(Doc,"App.activeDocument().%s.recompute()", FeatName.c_str()); + getDocument()->setStatus(App::Document::Status::SkipRecompute, false); + } else { + std::pair dirs = DrawGuiUtil::get3DDirAndRot(); + projDir = dirs.first; + getDocument()->setStatus(App::Document::Status::SkipRecompute, true); + doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", + FeatName.c_str(), projDir.x,projDir.y,projDir.z); + doCommand(Doc,"App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", + FeatName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); +// dvp->setXDir(dirs.second); + getDocument()->setStatus(App::Document::Status::SkipRecompute, false); + doCommand(Doc,"App.activeDocument().%s.recompute()", FeatName.c_str()); + } + commitCommand(); +} + +bool CmdTechDrawView::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + +//=========================================================================== +// TechDraw_ActiveView +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawActiveView) + +CmdTechDrawActiveView::CmdTechDrawActiveView() + : Command("TechDraw_ActiveView") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Active View (3D View)"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ActiveView"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-ActiveView"; +} + +void CmdTechDrawActiveView::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + Gui::Control().showDialog(new TaskDlgActiveView(page)); +} + +bool CmdTechDrawActiveView::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + +//=========================================================================== +// TechDraw_SectionView +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawSectionView) + +CmdTechDrawSectionView::CmdTechDrawSectionView() + : Command("TechDraw_SectionView") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Section View"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_SectionView"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-SectionView"; +} + +void CmdTechDrawSectionView::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector baseObj = getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); + if (baseObj.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select at least 1 DrawViewPart object as Base.")); + return; + } + TechDraw::DrawViewPart* dvp = static_cast(*baseObj.begin()); +// 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"); + +// 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("CmdTechDrawSectionView 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(); +} + +bool CmdTechDrawSectionView::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this); + bool taskInProgress = false; + if (havePage) { + taskInProgress = Gui::Control().activeDialog(); + } + return (havePage && haveView && !taskInProgress); +} + +//=========================================================================== +// TechDraw_DetailView +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawDetailView) + +CmdTechDrawDetailView::CmdTechDrawDetailView() + : Command("TechDraw_DetailView") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Detail View"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_DetailView"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-DetailView"; +} + +void CmdTechDrawDetailView::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector baseObj = getSelection(). + getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); + if (baseObj.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select at least 1 DrawViewPart object as Base.")); + return; + } + TechDraw::DrawViewPart* dvp = static_cast(*(baseObj.begin())); + + Gui::Control().showDialog(new TaskDlgDetail(dvp)); +} + +bool CmdTechDrawDetailView::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this); + bool taskInProgress = false; + if (havePage) { + taskInProgress = Gui::Control().activeDialog(); + } + return (havePage && haveView && !taskInProgress); +} + +//=========================================================================== +// TechDraw_ProjectionGroup +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawProjectionGroup) + +CmdTechDrawProjectionGroup::CmdTechDrawProjectionGroup() + : Command("TechDraw_ProjectionGroup") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Projection Group"); + sToolTipText = QT_TR_NOOP("Insert multiple linked views of drawable object(s)"); + sWhatsThis = "TechDraw_ProjectionGroup"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-ProjectionGroup"; +} + +void CmdTechDrawProjectionGroup::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); +// auto inlist = page->getInListEx(true); +// inlist.insert(page); + + //set projection direction from selected Face + //use first object with a face selected + std::vector shapes; + App::DocumentObject* partObj = nullptr; + std::string faceName; + int resolve = 1; //mystery + bool single = false; //mystery + auto selection = getSelection().getSelectionEx(0, + App::DocumentObject::getClassTypeId(), + resolve, + single); + for (auto& sel: selection) { +// for(auto &sel : getSelection().getSelectionEx(0,App::DocumentObject::getClassTypeId(),false)) { + auto obj = sel.getObject(); + if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ) { + continue; + } +// if(!obj || inlist.count(obj)) //?????? +// continue; + if (obj != nullptr) { //can this happen? + shapes.push_back(obj); + } + if(partObj != nullptr) { + continue; + } + for(auto& sub : sel.getSubNames()) { + if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") { + faceName = sub; + partObj = obj; + break; + } + } + } + if (shapes.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("No Shapes or Groups in this selection")); + return; + } + + Base::Vector3d projDir; + Gui::WaitCursor wc; + + openCommand("Create Projection Group"); + + std::string multiViewName = getUniqueObjectName("ProjGroup"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawProjGroup','%s')", + multiViewName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", + PageName.c_str(),multiViewName.c_str()); + + App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str()); + auto multiView( static_cast(docObj) ); + multiView->Source.setValues(shapes); + doCommand(Doc,"App.activeDocument().%s.addProjection('Front')",multiViewName.c_str()); + + if (faceName.size()) { + std::pair dirs = DrawGuiUtil::getProjDirFromFace(partObj,faceName); + getDocument()->setStatus(App::Document::Status::SkipRecompute, true); + doCommand(Doc,"App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", + multiViewName.c_str(), dirs.first.x,dirs.first.y,dirs.first.z); + doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)", + multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); + doCommand(Doc,"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", + multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); + getDocument()->setStatus(App::Document::Status::SkipRecompute, false); + } else { + std::pair dirs = DrawGuiUtil::get3DDirAndRot(); + getDocument()->setStatus(App::Document::Status::SkipRecompute, true); + doCommand(Doc,"App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", + multiViewName.c_str(), dirs.first.x,dirs.first.y,dirs.first.z); + doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)", + multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); + doCommand(Doc,"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", + multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); + getDocument()->setStatus(App::Document::Status::SkipRecompute, false); + } + + doCommand(Doc,"App.activeDocument().%s.Anchor.recompute()", multiViewName.c_str()); + commitCommand(); + updateActive(); + + // create the rest of the desired views + Gui::Control().showDialog(new TaskDlgProjGroup(multiView,true)); +} + +bool CmdTechDrawProjectionGroup::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool taskInProgress = false; + if (havePage) { + taskInProgress = Gui::Control().activeDialog(); + } + return (havePage && !taskInProgress); +} + +//=========================================================================== +// TechDraw_NewMulti **deprecated** +//=========================================================================== + +//DEF_STD_CMD_A(CmdTechDrawNewMulti); + +//CmdTechDrawNewMulti::CmdTechDrawNewMulti() +// : Command("TechDraw_NewMulti") +//{ +// sAppModule = "TechDraw"; +// sGroup = QT_TR_NOOP("TechDraw"); +// sMenuText = QT_TR_NOOP("Insert multi-part view in drawing"); +// sToolTipText = QT_TR_NOOP("Insert a new View of a multiple Parts in the active drawing"); +// sWhatsThis = "TechDraw_NewMulti"; +// sStatusTip = sToolTipText; +// sPixmap = "actions/techdraw-multiview"; +//} + +//void CmdTechDrawNewMulti::activated(int iMsg) +//{ +// Q_UNUSED(iMsg); +// TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); +// if (!page) { +// return; +// } + +// std::vector shapes = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); +// if (shapes.empty()) { +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), +// QObject::tr("Can not MultiView from this selection.")); +// return; +// } + +// std::string PageName = page->getNameInDocument(); + +// Gui::WaitCursor wc; + +// openCommand("Create view"); +// std::string FeatName = getUniqueObjectName("MultiView"); +// doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewMulti','%s')",FeatName.c_str()); +// App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str()); +// auto multiView( static_cast(docObj) ); +// multiView->Sources.setValues(shapes); +// doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); +// updateActive(); +// commitCommand(); +//} + +//bool CmdTechDrawNewMulti::isActive(void) +//{ +// return DrawGuiUtil::needPage(this); +//} + +//=========================================================================== +// TechDraw_Balloon +//=========================================================================== + +//! common checks of Selection for Dimension commands +//non-empty selection, no more than maxObjs selected and at least 1 DrawingPage exists +bool _checkSelectionBalloon(Gui::Command* cmd, unsigned maxObjs) { + std::vector selection = cmd->getSelection().getSelectionEx(); + if (selection.size() == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("Select an object first")); + return false; + } + + const std::vector SubNames = selection[0].getSubNames(); + if (SubNames.size() > maxObjs){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("Too many objects selected")); + return false; + } + + std::vector pages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + if (pages.empty()){ + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("Create a page first.")); + return false; + } + return true; +} + +bool _checkDrawViewPartBalloon(Gui::Command* cmd) { + std::vector selection = cmd->getSelection().getSelectionEx(); + auto objFeat( dynamic_cast(selection[0].getObject()) ); + if( !objFeat ) { + QMessageBox::warning( Gui::getMainWindow(), + QObject::tr("Incorrect selection"), + QObject::tr("No View of a Part in selection.") ); + return false; + } + return true; +} + +DEF_STD_CMD_A(CmdTechDrawBalloon) + +CmdTechDrawBalloon::CmdTechDrawBalloon() + : Command("TechDraw_Balloon") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Balloon Annotation"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_Balloon"; + sStatusTip = sToolTipText; + sPixmap = "TechDraw_Balloon"; +} + +void CmdTechDrawBalloon::activated(int iMsg) +{ + Q_UNUSED(iMsg); + bool result = _checkSelectionBalloon(this,1); + if (!result) + return; + result = _checkDrawViewPartBalloon(this); + if (!result) + return; + + std::vector selection = getSelection().getSelectionEx(); + auto objFeat( dynamic_cast(selection[0].getObject()) ); + if( objFeat == nullptr ) { + return; + } + + TechDraw::DrawPage* page = objFeat->findParentPage(); + std::string PageName = page->getNameInDocument(); + + page->balloonParent = objFeat; + page->balloonPlacing = true; + +} + +bool CmdTechDrawBalloon::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this); + return (havePage && haveView); +} + +//=========================================================================== +// TechDraw_ClipGroup +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawClipGroup) + +CmdTechDrawClipGroup::CmdTechDrawClipGroup() + : Command("TechDraw_ClipGroup") +{ + // setting the + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Clip Group"); + sToolTipText = sToolTipText; + sWhatsThis = "TechDraw_ClipGroup"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-ClipGroup"; +} + +void CmdTechDrawClipGroup::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + std::string FeatName = getUniqueObjectName("Clip"); + openCommand("Create Clip"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewClip','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); +} + +bool CmdTechDrawClipGroup::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + +//=========================================================================== +// TechDraw_ClipGroupAdd +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawClipGroupAdd) + +CmdTechDrawClipGroupAdd::CmdTechDrawClipGroupAdd() + : Command("TechDraw_ClipGroupAdd") +{ + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add View to Clip Group"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ClipGroupAdd"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-ClipGroupAdd"; +} + +void CmdTechDrawClipGroupAdd::activated(int iMsg) +{ + Q_UNUSED(iMsg); + std::vector selection = getSelection().getSelectionEx(); + if (selection.size() != 2) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select one Clip group and one View.")); + return; + } + + TechDraw::DrawViewClip* clip = 0; + TechDraw::DrawView* view = 0; + std::vector::iterator itSel = selection.begin(); + for (; itSel != selection.end(); itSel++) { + if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) { + clip = static_cast((*itSel).getObject()); + } else if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { + view = static_cast((*itSel).getObject()); + } + } + if (!view) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one View to add to group.")); + return; + } + if (!clip) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Clip group.")); + return; + } + + TechDraw::DrawPage* pageClip = clip->findParentPage(); + TechDraw::DrawPage* pageView = view->findParentPage(); + + if (pageClip != pageView) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Clip and View must be from same Page.")); + return; + } + + std::string PageName = pageClip->getNameInDocument(); + std::string ClipName = clip->getNameInDocument(); + std::string ViewName = view->getNameInDocument(); + + openCommand("ClipGroupAdd"); + doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = False",ViewName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",ClipName.c_str(),ViewName.c_str()); + doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = True",ViewName.c_str()); + updateActive(); + commitCommand(); +} + +bool CmdTechDrawClipGroupAdd::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveClip = false; + if (havePage) { + auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() ); + auto selClips = getDocument()->getObjectsOfType(drawClipType); + if (!selClips.empty()) { + haveClip = true; + } + } + return (havePage && haveClip); +} + +//=========================================================================== +// TechDraw_ClipGroupRemove +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawClipGroupRemove) + +CmdTechDrawClipGroupRemove::CmdTechDrawClipGroupRemove() + : Command("TechDraw_ClipGroupRemove") +{ + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Remove View from Clip Group"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ClipGroupRemove"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-ClipGroupRemove"; +} + +void CmdTechDrawClipGroupRemove::activated(int iMsg) +{ + Q_UNUSED(iMsg); + auto dObj( getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()) ); + if (dObj.empty()) { + QMessageBox::warning( Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("Select exactly one View to remove from Group.") ); + return; + } + + auto view( static_cast(dObj.front()) ); + + TechDraw::DrawPage* page = view->findParentPage(); + const std::vector pViews = page->Views.getValues(); + TechDraw::DrawViewClip *clip(nullptr); + for (auto &v : pViews) { + clip = dynamic_cast(v); + if (clip && clip->isViewInClip(view)) { + break; + } + clip = nullptr; + } + + if (!clip) { + QMessageBox::warning( Gui::getMainWindow(), + QObject::tr("Wrong selection"), + QObject::tr("View does not belong to a Clip") ); + return; + } + + std::string ClipName = clip->getNameInDocument(); + std::string ViewName = view->getNameInDocument(); + + openCommand("ClipGroupRemove"); + doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = False",ViewName.c_str()); + doCommand(Doc,"App.activeDocument().%s.removeView(App.activeDocument().%s)",ClipName.c_str(),ViewName.c_str()); + doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = True",ViewName.c_str()); + updateActive(); + commitCommand(); +} + +bool CmdTechDrawClipGroupRemove::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveClip = false; + if (havePage) { + auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() ); + auto selClips = getDocument()->getObjectsOfType(drawClipType); + if (!selClips.empty()) { + haveClip = true; + } + } + return (havePage && haveClip); +} + + +//=========================================================================== +// TechDraw_Symbol +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawSymbol) + +CmdTechDrawSymbol::CmdTechDrawSymbol() + : Command("TechDraw_Symbol") +{ + // setting the Gui eye-candy + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert SVG Symbol"); + sToolTipText = QT_TR_NOOP("Insert symbol from a SVG file"); + sWhatsThis = "TechDraw_Symbol"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-symbol"; +} + +void CmdTechDrawSymbol::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + // Reading an image + QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), + QObject::tr("Choose an SVG file to open"), QString::null, + QString::fromLatin1("%1 (*.svg *.svgz);;%2 (*.*)"). + arg(QObject::tr("Scalable Vector Graphic")). + arg(QObject::tr("All Files"))); + + if (!filename.isEmpty()) + { + std::string FeatName = getUniqueObjectName("Symbol"); + filename = Base::Tools::escapeEncodeFilename(filename); + openCommand("Create Symbol"); +#if PY_MAJOR_VERSION < 3 + doCommand(Doc,"f = open(unicode(\"%s\",'utf-8'),'r')",(const char*)filename.toUtf8()); +#else + doCommand(Doc,"f = open(\"%s\",'r')",(const char*)filename.toUtf8()); +#endif + doCommand(Doc,"svg = f.read()"); + doCommand(Doc,"f.close()"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSymbol','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Symbol = svg",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); + } +} + +bool CmdTechDrawSymbol::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + +//=========================================================================== +// TechDraw_DraftView +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawDraftView) + +CmdTechDrawDraftView::CmdTechDrawDraftView() + : Command("TechDraw_DraftView") +{ + // setting the Gui eye-candy + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Draft Workbench Object"); + sToolTipText = QT_TR_NOOP("Insert a View of a Draft Workbench object"); + sWhatsThis = "TechDraw_NewDraft"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-DraftView"; +} + +void CmdTechDrawDraftView::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + std::vector objects = getSelection(). + getObjectsOfType(App::DocumentObject::getClassTypeId()); + + if (objects.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select at least one object.")); + return; + } + + int draftItemsFound = 0; + for (std::vector::iterator it = objects.begin(); it != objects.end(); ++it) { + if (DrawGuiUtil::isDraftObject((*it))) { + draftItemsFound++; + std::string FeatName = getUniqueObjectName("DraftView"); + std::string SourceName = (*it)->getNameInDocument(); + openCommand("Create DraftView"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDraft','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s", + FeatName.c_str(),SourceName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", + PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); + } + } + if (draftItemsFound == 0) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("There were no DraftWB objects in the selection.")); + } +} + +bool CmdTechDrawDraftView::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + +//=========================================================================== +// TechDraw_ArchView +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawArchView) + +CmdTechDrawArchView::CmdTechDrawArchView() + : Command("TechDraw_ArchView") +{ + // setting the Gui eye-candy + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Arch Workbench Object"); + sToolTipText = QT_TR_NOOP("Insert a View of a Section Plane from Arch Workbench"); + sWhatsThis = "TechDraw_NewArch"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-ArchView"; +} + +void CmdTechDrawArchView::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + + const std::vector objects = getSelection(). + getObjectsOfType(App::DocumentObject::getClassTypeId()); + App::DocumentObject* archObject = nullptr; + int archCount = 0; + for (auto& obj : objects) { + if (DrawGuiUtil::isArchSection(obj) ) { + archCount++; + archObject = obj; + } + } + if ( archCount > 1 ) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Please select only 1 Arch Section.")); + return; + } + + if (archObject == nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("No Arch Sections in selection.")); + return; + } + + std::string FeatName = getUniqueObjectName("ArchView"); + std::string SourceName = archObject->getNameInDocument(); + openCommand("Create ArchView"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewArch','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SourceName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); +} + +bool CmdTechDrawArchView::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + +//=========================================================================== +// TechDraw_SpreadsheetView +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawSpreadsheetView) + +CmdTechDrawSpreadsheetView::CmdTechDrawSpreadsheetView() + : Command("TechDraw_SpreadsheetView") +{ + // setting the + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Spreadsheet View"); + sToolTipText = QT_TR_NOOP("Insert View to a spreadsheet"); + sWhatsThis = "TechDraw_SpreadsheetView"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-SpreadsheetView"; +} + +void CmdTechDrawSpreadsheetView::activated(int iMsg) +{ + Q_UNUSED(iMsg); + const std::vector spreads = getSelection().getObjectsOfType(Spreadsheet::Sheet::getClassTypeId()); + if (spreads.size() != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Spreadsheet object.")); + return; + } + std::string SpreadName = spreads.front()->getNameInDocument(); + + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + openCommand("Create spreadsheet view"); + std::string FeatName = getUniqueObjectName("Sheet"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SpreadName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); +} + +bool CmdTechDrawSpreadsheetView::isActive(void) +{ + //need a Page and a SpreadSheet::Sheet + bool havePage = DrawGuiUtil::needPage(this); + bool haveSheet = false; + if (havePage) { + auto spreadSheetType( Spreadsheet::Sheet::getClassTypeId() ); + auto selSheets = getDocument()->getObjectsOfType(spreadSheetType); + if (!selSheets.empty()) { + haveSheet = true; + } + } + return (havePage && haveSheet); +} + + +//=========================================================================== +// TechDraw_ExportPageSVG +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawExportPageSVG) + +CmdTechDrawExportPageSVG::CmdTechDrawExportPageSVG() + : Command("TechDraw_ExportPageSVG") +{ + sGroup = QT_TR_NOOP("File"); + sMenuText = QT_TR_NOOP("Export Page as SVG"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ExportPageSVG"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-ExportPageSVG"; +} + +void CmdTechDrawExportPageSVG::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + Gui::Document* activeGui = Gui::Application::Instance->getDocument(page->getDocument()); + Gui::ViewProvider* vp = activeGui->getViewProvider(page); + ViewProviderPage* dvp = dynamic_cast(vp); + + if (dvp && dvp->getMDIViewPage()) { + dvp->getMDIViewPage()->saveSVG(); + } else { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Drawing View"), + QObject::tr("Open Drawing View before attempting export to SVG.")); + return; + } +} + +bool CmdTechDrawExportPageSVG::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + +//=========================================================================== +// TechDraw_ExportPageDXF +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawExportPageDXF) + +CmdTechDrawExportPageDXF::CmdTechDrawExportPageDXF() + : Command("TechDraw_ExportPageDXF") +{ + sGroup = QT_TR_NOOP("File"); + sMenuText = QT_TR_NOOP("Export Page as DXF"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ExportPageDXF"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-ExportPageDXF"; +} + +void CmdTechDrawExportPageDXF::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector views = page->Views.getValues(); + for (auto& v: views) { + if (v->isDerivedFrom(TechDraw::DrawViewArch::getClassTypeId())) { + QMessageBox::StandardButton rc = + QMessageBox::question(Gui::getMainWindow(), QObject::tr("Can not export selection"), + QObject::tr("Page contains DrawViewArch which will not be exported. Continue?"), + QMessageBox::StandardButtons(QMessageBox::Yes| QMessageBox::No)); + if (rc == QMessageBox::No) { + return; + } else { + break; + } + } + } + +//WF? allow more than one TD Page per Dxf file?? 1 TD page = 1 DXF file = 1 drawing? + QString defaultDir; + QString fileName = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), + QString::fromUtf8(QT_TR_NOOP("Save Dxf File ")), + defaultDir, + QString::fromUtf8(QT_TR_NOOP("Dxf (*.dxf)"))); + + if (fileName.isEmpty()) { + return; + } + + std::string PageName = page->getNameInDocument(); + openCommand("Save page to dxf"); + doCommand(Doc,"import TechDraw"); + fileName = Base::Tools::escapeEncodeFilename(fileName); + doCommand(Doc,"TechDraw.writeDXFPage(App.activeDocument().%s,u\"%s\")",PageName.c_str(),(const char*)fileName.toUtf8()); + commitCommand(); +} + + +bool CmdTechDrawExportPageDXF::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + +void CreateTechDrawCommands(void) +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + + rcCmdMgr.addCommand(new CmdTechDrawPageDefault()); + rcCmdMgr.addCommand(new CmdTechDrawPageTemplate()); + rcCmdMgr.addCommand(new CmdTechDrawRedrawPage()); + rcCmdMgr.addCommand(new CmdTechDrawView()); + rcCmdMgr.addCommand(new CmdTechDrawActiveView()); + rcCmdMgr.addCommand(new CmdTechDrawSectionView()); + rcCmdMgr.addCommand(new CmdTechDrawDetailView()); + rcCmdMgr.addCommand(new CmdTechDrawProjectionGroup()); + rcCmdMgr.addCommand(new CmdTechDrawClipGroup()); + rcCmdMgr.addCommand(new CmdTechDrawClipGroupAdd()); + rcCmdMgr.addCommand(new CmdTechDrawClipGroupRemove()); + rcCmdMgr.addCommand(new CmdTechDrawSymbol()); + rcCmdMgr.addCommand(new CmdTechDrawExportPageSVG()); + rcCmdMgr.addCommand(new CmdTechDrawExportPageDXF()); + rcCmdMgr.addCommand(new CmdTechDrawDraftView()); + rcCmdMgr.addCommand(new CmdTechDrawArchView()); + rcCmdMgr.addCommand(new CmdTechDrawSpreadsheetView()); + rcCmdMgr.addCommand(new CmdTechDrawBalloon()); +} diff --git a/src/Mod/TechDraw/Gui/QGIGhostHighlight.cpp b/src/Mod/TechDraw/Gui/QGIGhostHighlight.cpp new file mode 100644 index 0000000000..c0ac483a4c --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIGhostHighlight.cpp @@ -0,0 +1,115 @@ +/*************************************************************************** + * Copyright (c) 2020 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#include +#include +#endif + +#include +#include +#include +#include + +#include + +#include +#include "Rez.h" +#include "DrawGuiUtil.h" +#include "QGIView.h" +#include "QGIGhostHighlight.h" + +using namespace TechDrawGui; +using namespace TechDraw; + +QGIGhostHighlight::QGIGhostHighlight() +{ + setInteractive(true); + m_dragging = false; + + //make the ghost very visible + QFont f(QGIView::getPrefFont()); + double fontSize = QGIView::getPrefFontSize(); + setFont(f, fontSize); + setReference("drag"); + setStyle(Qt::SolidLine); + setColor(prefSelectColor()); + setWidth(Rez::guiX(1.0)); + setRadius(10.0); //placeholder +} + +QGIGhostHighlight::~QGIGhostHighlight() +{ + +} + +QVariant QGIGhostHighlight::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemPositionHasChanged && scene()) { + // nothing to do here? + } + return QGIHighlight::itemChange(change, value); +} + +void QGIGhostHighlight::mousePressEvent(QGraphicsSceneMouseEvent * event) +{ +// Base::Console().Message("QGIGhostHighlight::mousePress() - %X\n", this); + if ( (event->button() == Qt::LeftButton) && + (flags() && QGraphicsItem::ItemIsMovable) ) { + m_dragging = true; + event->accept(); + } + QGIHighlight::mousePressEvent(event); +} + +void QGIGhostHighlight::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) +{ +// Base::Console().Message("QGIGhostHighlight::mouseRelease() - pos: %s scenePos: %s\n", +// DrawUtil::formatVector(pos()).c_str(), +// DrawUtil::formatVector(mapToScene(pos())).c_str()); + if (m_dragging) { + m_dragging = false; + Q_EMIT positionChange(scenePos()); + event->accept(); + } + QGIHighlight::mouseReleaseEvent(event); +} + +void QGIGhostHighlight::setInteractive(bool state) +{ + setFlag(QGraphicsItem::ItemIsSelectable, state); + setFlag(QGraphicsItem::ItemIsMovable, state); + setFlag(QGraphicsItem::ItemSendsScenePositionChanges, state); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, state); +} + +//radius should scaled, but not Rez::guix() +void QGIGhostHighlight::setRadius(double r) +{ + setBounds(-r, r, r, -r); +} + +#include diff --git a/src/Mod/TechDraw/Gui/QGIGhostHighlight.h b/src/Mod/TechDraw/Gui/QGIGhostHighlight.h new file mode 100644 index 0000000000..0f86095a79 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIGhostHighlight.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (c) 2020 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_QGIGHOSTHIGHLIGHT_H +#define TECHDRAWGUI_QGIGHOSTHIGHLIGHT_H + +#include +#include +#include +#include + +#include "QGIHighlight.h" + +//a movable, selectable surrogate for detail highlights in QGIVPart + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGIGhostHighlight : public QObject, public QGIHighlight +{ + Q_OBJECT +public: + explicit QGIGhostHighlight(); + ~QGIGhostHighlight(); + + enum {Type = QGraphicsItem::UserType + 177}; + int type() const { return Type;} + + void setInteractive(bool state); + void setRadius(double r); + +Q_SIGNALS: + void positionChange(QPointF p); + +protected: + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + + bool m_dragging; + +private: +}; + +} + +#endif // TECHDRAWGUI_QGIGHOSTHIGHLIGHT_H diff --git a/src/Mod/TechDraw/Gui/QGIHighlight.cpp b/src/Mod/TechDraw/Gui/QGIHighlight.cpp index f67212861e..8501a8106e 100644 --- a/src/Mod/TechDraw/Gui/QGIHighlight.cpp +++ b/src/Mod/TechDraw/Gui/QGIHighlight.cpp @@ -46,19 +46,65 @@ QGIHighlight::QGIHighlight() { m_refText = ""; m_refSize = 0.0; + setInteractive(false); + m_circle = new QGraphicsEllipseItem(); addToGroup(m_circle); + m_circle->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_rect = new QGCustomRect(); addToGroup(m_rect); + m_rect->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_reference = new QGCustomText(); addToGroup(m_reference); + m_reference->setFlag(QGraphicsItem::ItemIsSelectable, false); setWidth(Rez::guiX(0.75)); setStyle(getHighlightStyle()); setColor(getHighlightColor()); +} + +QGIHighlight::~QGIHighlight() +{ } +//really only want to emit signal at end of movement +//QVariant QGIHighlight::itemChange(GraphicsItemChange change, const QVariant &value) +//{ +// if (change == ItemPositionHasChanged && scene()) { +// // nothing to do here +// } +// return QGraphicsItem::itemChange(change, value); +//} + +//void QGIHighlight::mousePressEvent(QGraphicsSceneMouseEvent * event) +//{ +// Base::Console().Message("QGIHighlight::mousePress() - %X\n", this); +//// if(scene() && m_reference == scene()->mouseGrabberItem()) { +// if ( (event->button() == Qt::LeftButton) && +// (flags() && QGraphicsItem::ItemIsMovable) ) { +// m_dragging = true; +// } +//// } +// QGIDecoration::mousePressEvent(event); +//} + +//void QGIHighlight::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) +//{ +// Base::Console().Message("QGIHighlight::mouseRelease() - %X grabber: %X\n", this, scene()->mouseGrabberItem()); +//// if(scene() && this == scene()->mouseGrabberItem()) { +// if (m_dragging) { +// m_dragging = false; +//// QString itemName = data(0).toString(); +// Q_EMIT positionChange(pos()); +// return; +// } +//// } +// QGIDecoration::mouseReleaseEvent(event); +//} + void QGIHighlight::draw() { prepareGeometryChange(); @@ -100,6 +146,15 @@ void QGIHighlight::makeReference() } } +void QGIHighlight::setInteractive(bool state) +{ +// setAcceptHoverEvents(state); + setFlag(QGraphicsItem::ItemIsSelectable, state); + setFlag(QGraphicsItem::ItemIsMovable, state); + setFlag(QGraphicsItem::ItemSendsScenePositionChanges, state); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, state); +} + void QGIHighlight::setBounds(double x1,double y1,double x2,double y2) { m_start = QPointF(Rez::guiX(x1),Rez::guiX(-y1)); @@ -142,10 +197,9 @@ int QGIHighlight::getHoleStyle() return style; } - void QGIHighlight::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { QStyleOptionGraphicsItem myOption(*option); - myOption.state &= ~QStyle::State_Selected; +// myOption.state &= ~QStyle::State_Selected; setTools(); // painter->drawRect(boundingRect()); //good for debugging @@ -165,3 +219,4 @@ void QGIHighlight::setTools() m_reference->setDefaultTextColor(m_colCurrent); } + diff --git a/src/Mod/TechDraw/Gui/QGIHighlight.h b/src/Mod/TechDraw/Gui/QGIHighlight.h index 809f9b3fe3..4b3a9f02e5 100644 --- a/src/Mod/TechDraw/Gui/QGIHighlight.h +++ b/src/Mod/TechDraw/Gui/QGIHighlight.h @@ -25,9 +25,12 @@ #include #include +#include #include #include #include +#include +#include #include #include @@ -45,19 +48,25 @@ class TechDrawGuiExport QGIHighlight : public QGIDecoration { public: explicit QGIHighlight(); - ~QGIHighlight() {} + ~QGIHighlight(); - enum {Type = QGraphicsItem::UserType + 172}; + enum {Type = QGraphicsItem::UserType + 176}; int type() const { return Type;} - virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + virtual void paint(QPainter * painter, + const QStyleOptionGraphicsItem * option, + QWidget * widget = 0 ) override; void setBounds(double x1,double y1,double x2,double y2); void setReference(char* sym); void setFont(QFont f, double fsize); virtual void draw(); + void setInteractive(bool state); protected: +/* virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;*/ +/* virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;*/ +/* virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;*/ QColor getHighlightColor(); Qt::PenStyle getHighlightStyle(); void makeHighlight(); @@ -65,6 +74,7 @@ protected: void setTools(); int getHoleStyle(void); +/* bool m_dragging;*/ private: char* m_refText; diff --git a/src/Mod/TechDraw/Gui/QGIUserTypes.h b/src/Mod/TechDraw/Gui/QGIUserTypes.h index 7995cfa785..df54412148 100644 --- a/src/Mod/TechDraw/Gui/QGIUserTypes.h +++ b/src/Mod/TechDraw/Gui/QGIUserTypes.h @@ -1,26 +1,26 @@ /* -Derived QGraphicsItem Classes type() Values +Derived QGI Classes type() Values Qt First UserType>> QGraphicsItem::UserType = 65536 -QGraphicsItemView : 101 -QGraphicsItemViewPart : 102 -QGraphicsItemEdge: 103 -QGraphicsItemFace: 104 -QGraphicsItemVertex: 105 -QGraphicsItemViewDimension : 106 -QGraphicsItemViewBalloon : 140 -QGraphicsItemBalloonLabel : 141 -QGraphicsItemDatumLabel : 107 -QGraphicsItemViewSection : 108 -QGraphicsItemArrow: 109 -QGraphicsItemViewCollection : 110 -QGraphicsItemViewOrthographic : 113 -QGraphicsItemViewAnnotation : 120 -QGraphicsItemViewSymbol : 121 -QGraphicsItemHatch : 122 //obsolete -QGraphicsItemClip : 123 -QGraphicsItemSpreadsheet : 124 +QGIView : 101 +QGIViewPart : 102 +QGIEdge: 103 +QGIFace: 104 +QGIVertex: 105 +QGIViewDimension : 106 +QGIViewBalloon : 140 +QGIBalloonLabel : 141 +QGIDatumLabel : 107 +QGIViewSection : 108 +QGIArrow: 109 +QGIViewCollection : 110 +QGIProjGroup : 113 +QGIViewAnnotation : 120 +QGIViewSymbol : 121 +QGIHatch : 122 //obsolete +QGIClip : 123 +QGISpreadsheet : 124 QGCustomText: 130 QGCustomSvg: 131 QGCustomClip: 132 @@ -28,9 +28,9 @@ QGCustomRect: 133 QGCustomLabel:135 QGCustomBorder: 136 QGDisplayArea: 137 -QGraphicsItemTemplate: 150 -QGraphicsItemDrawingTemplate: 151 -QGraphicsItemSVGTemplate: 153 +QGITemplate: 150 +QGIDrawingTemplate: 151 +QGISVGTemplate: 153 TemplateTextField: 160 QGIPrimPath: 170 QGICMark: 171 @@ -38,6 +38,8 @@ QGISectionLine: 172 QGIDecoration: 173 QGICenterLine: 174 QGIDimLines: 175 +QGIHighlight: 176 +QGIGhostHighlight: 177 QGICaption: 180 QGIViewImage: 200 QGCustomImage: 201 diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index ac8faff4ef..7ba639ee6c 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -121,6 +121,11 @@ public: static int calculateFontPixelWidth(const QFont &font); static const double DefaultFontSizeInMM; + static QString getPrefFont(void); + static double getPrefFontSize(void); + static double getDimFontSize(void); + + MDIViewPage* getMDIViewPage(void) const; virtual void removeChild(QGIView* child); @@ -145,9 +150,9 @@ protected: virtual QRectF customChildrenBoundingRect(void) const; void dumpRect(const char* text, QRectF r); - QString getPrefFont(void); - double getPrefFontSize(void); - double getDimFontSize(void); +/* QString getPrefFont(void);*/ +/* double getPrefFontSize(void);*/ +/* double getDimFontSize(void);*/ Base::Reference getParmGroupCol(void); diff --git a/src/Mod/TechDraw/Gui/Rez.cpp b/src/Mod/TechDraw/Gui/Rez.cpp index e75c0ca02e..21ab1eb63f 100644 --- a/src/Mod/TechDraw/Gui/Rez.cpp +++ b/src/Mod/TechDraw/Gui/Rez.cpp @@ -67,6 +67,11 @@ Base::Vector2d Rez::guiX(Base::Vector3d v, bool planar) return Base::Vector2d(guiX(v.x), guiX(v.y)); } +QPointF Rez::guiX(QPointF p) +{ + return Rez::guiPt(p); +} + //turn Gui side value to App side value double Rez::appX(double x) { @@ -85,6 +90,7 @@ QPointF Rez::appX(QPointF p) } + //Misc conversions QPointF Rez::guiPt(QPointF p) { diff --git a/src/Mod/TechDraw/Gui/Rez.h b/src/Mod/TechDraw/Gui/Rez.h index f35e48a76c..5a03e8551f 100644 --- a/src/Mod/TechDraw/Gui/Rez.h +++ b/src/Mod/TechDraw/Gui/Rez.h @@ -43,6 +43,8 @@ public: static double guiX(double x); static Base::Vector3d guiX(Base::Vector3d v); static Base::Vector2d guiX(Base::Vector3d v, bool planar); + static QPointF guiX(QPointF p); + //turn Gui side value to App side value static double appX(double x); static Base::Vector3d appX(Base::Vector3d v); diff --git a/src/Mod/TechDraw/Gui/TaskDetail.cpp b/src/Mod/TechDraw/Gui/TaskDetail.cpp new file mode 100644 index 0000000000..270b8fb612 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskDetail.cpp @@ -0,0 +1,585 @@ +/*************************************************************************** + * Copyright (c) 2020 Wandererfan +#include +#endif // #ifndef _PreComp_ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "DrawGuiStd.h" +#include "QGVPage.h" +#include "QGIView.h" +#include "QGIPrimPath.h" +#include "QGIGhostHighlight.h" +#include "MDIViewPage.h" +#include "ViewProviderPage.h" +#include "Rez.h" +#include "QGIViewPart.h" + +#include "TaskDetail.h" + +using namespace TechDrawGui; +using namespace TechDraw; +using namespace Gui; + +#define CREATEMODE 0 +#define EDITMODE 1 + +//creation ctor +TaskDetail::TaskDetail(TechDraw::DrawViewPart* baseFeat): + ui(new Ui_TaskDetail), + m_detailFeat(nullptr), + m_baseFeat(baseFeat), + m_basePage(nullptr), + m_inProgressLock(false), + m_saveAnchor(Base::Vector3d(0.0, 0.0, 0.0)), + m_saveRadius(0.0), + m_baseName(std::string()), + m_pageName(std::string()), + m_detailName(std::string()), + m_doc(nullptr), + m_mode(CREATEMODE), + m_created(false) +{ + if (m_baseFeat == nullptr) { + //should be caught in CMD caller + Base::Console().Error("TaskDetail - bad parameters - base feature. Can not proceed.\n"); + return; + } + m_basePage = m_baseFeat->findParentPage(); + if (m_basePage == nullptr) { + Base::Console().Error("TaskDetail - bad parameters - base page. Can not proceed.\n"); + } + + m_baseName = m_baseFeat->getNameInDocument(); + m_doc = m_baseFeat->getDocument(); + m_pageName = m_basePage->getNameInDocument(); + + ui->setupUi(this); + + Gui::Document* activeGui = Gui::Application::Instance->getDocument(m_doc); + Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage); + ViewProviderPage* vpp = static_cast(vp); + m_mdi = vpp->getMDIViewPage(); + m_scene = m_mdi->m_scene; + m_view = m_mdi->getQGVPage(); + + createDetail(); + setUiFromFeat(); + setWindowTitle(QObject::tr("New Detail")); + + connect(ui->pbDragger, SIGNAL(clicked(bool)), + this, SLOT(onDraggerClicked(bool))); + connect(ui->qsbX, SIGNAL(editingFinished()), + this, SLOT(onXEdit())); + connect(ui->qsbY, SIGNAL(editingFinished()), + this, SLOT(onYEdit())); + connect(ui->qsbRadius, SIGNAL(editingFinished()), + this, SLOT(onRadiusEdit())); + + m_ghost = new QGIGhostHighlight(); + m_scene->addItem(m_ghost); + m_ghost->hide(); + connect(m_ghost, SIGNAL(positionChange(QPointF)), + this, SLOT(onHighlightMoved(QPointF))); +} + +//edit ctor +TaskDetail::TaskDetail(TechDraw::DrawViewDetail* detailFeat): + ui(new Ui_TaskDetail), + m_detailFeat(detailFeat), + m_baseFeat(nullptr), + m_basePage(nullptr), + m_inProgressLock(false), + m_saveAnchor(Base::Vector3d(0.0, 0.0, 0.0)), + m_saveRadius(0.0), + m_baseName(std::string()), + m_pageName(std::string()), + m_detailName(std::string()), + m_doc(nullptr), + m_mode(EDITMODE), + m_created(false) +{ + if (m_detailFeat == nullptr) { + //should be caught in CMD caller + Base::Console().Error("TaskDetail - bad parameters. Can not proceed.\n"); + return; + } + + m_doc = m_detailFeat->getDocument(); + m_detailName = m_detailFeat->getNameInDocument(); + + m_basePage = m_detailFeat->findParentPage(); + if (m_basePage != nullptr) { + m_pageName = m_basePage->getNameInDocument(); + } + + App::DocumentObject* baseObj = m_detailFeat->BaseView.getValue(); + m_baseFeat = dynamic_cast(baseObj); + if (m_baseFeat != nullptr) { + m_baseName = m_baseFeat->getNameInDocument(); + } else { + Base::Console().Error("TaskDetail - no BaseView. Can not proceed.\n"); + return; + } + + ui->setupUi(this); + + Gui::Document* activeGui = Gui::Application::Instance->getDocument(m_basePage->getDocument()); + Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage); + ViewProviderPage* vpp = static_cast(vp); + m_mdi = vpp->getMDIViewPage(); + m_scene = m_mdi->m_scene; + m_view = m_mdi->getQGVPage(); + + saveDetailState(); + setUiFromFeat(); + setWindowTitle(QObject::tr("Edit Detail")); + + connect(ui->pbDragger, SIGNAL(clicked(bool)), + this, SLOT(onDraggerClicked(bool))); + connect(ui->qsbX, SIGNAL(editingFinished()), + this, SLOT(onXEdit())); + connect(ui->qsbY, SIGNAL(editingFinished()), + this, SLOT(onYEdit())); + connect(ui->qsbRadius, SIGNAL(editingFinished()), + this, SLOT(onRadiusEdit())); + connect(ui->aeReference, SIGNAL(editingFinished()), + this, SLOT(onReferenceEdit())); + + m_ghost = new QGIGhostHighlight(); + m_scene->addItem(m_ghost); + m_ghost->hide(); + connect(m_ghost, SIGNAL(positionChange(QPointF)), + this, SLOT(onHighlightMoved(QPointF))); +} + +TaskDetail::~TaskDetail() +{ + delete ui; +} + +void TaskDetail::updateTask() +{ +// blockUpdate = true; + +// blockUpdate = false; +} + +void TaskDetail::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +//save the start conditions +void TaskDetail::saveDetailState() +{ +// Base::Console().Message("TD::saveDetailState()\n"); + TechDraw::DrawViewDetail* dvd = getDetailFeat(); + m_saveAnchor = dvd->AnchorPoint.getValue(); + m_saveRadius = dvd->Radius.getValue(); + m_saved = true; +} + +void TaskDetail::restoreDetailState() +{ +// Base::Console().Message("TD::restoreDetailState()\n"); + TechDraw::DrawViewDetail* dvd = getDetailFeat(); + dvd->AnchorPoint.setValue(m_saveAnchor); + dvd->Radius.setValue(m_saveRadius); +} + +//***** ui stuff *************************************************************** + +void TaskDetail::setUiFromFeat() +{ +// Base::Console().Message("TD::setUIFromFeat()\n"); + if (m_baseFeat != nullptr) { + std::string baseName = getBaseFeat()->getNameInDocument(); + ui->leBaseView->setText(Base::Tools::fromStdString(baseName)); + } + + Base::Vector3d anchor; + double radius; + + TechDraw::DrawViewDetail* detailFeat = getDetailFeat(); + QString detailDisplay = QString::fromUtf8(detailFeat->getNameInDocument()) + + QString::fromUtf8(" / ") + + QString::fromUtf8(detailFeat->Label.getValue()); + ui->leDetailView->setText(detailDisplay); + anchor = detailFeat->AnchorPoint.getValue(); + radius = detailFeat->Radius.getValue(); + QString ref = QString::fromUtf8(detailFeat->Reference.getValue()); + + ui->pbDragger->setText(QString::fromUtf8("Drag Highlight")); + ui->pbDragger->setEnabled(true); + int decimals = Base::UnitsApi::getDecimals(); + ui->qsbX->setUnit(Base::Unit::Length); + ui->qsbX->setDecimals(decimals); + ui->qsbY->setUnit(Base::Unit::Length); + ui->qsbY->setDecimals(decimals); + ui->qsbRadius->setDecimals(decimals); + ui->qsbRadius->setUnit(Base::Unit::Length); + ui->qsbX->setValue(anchor.x); + ui->qsbY->setValue(anchor.y); + ui->qsbRadius->setValue(radius); + ui->aeReference->setText(ref); +} + +//update ui point fields after tracker finishes +void TaskDetail::updateUi(QPointF p) +{ + ui->qsbX->setValue(p.x()); + ui->qsbY->setValue(- p.y()); +} + +void TaskDetail::enableInputFields(bool b) +{ + ui->qsbX->setEnabled(b); + ui->qsbY->setEnabled(b); + ui->qsbRadius->setEnabled(b); + ui->aeReference->setEnabled(b); +} + +void TaskDetail::onXEdit() +{ + updateDetail(); +} + +void TaskDetail::onYEdit() +{ + updateDetail(); +} + +void TaskDetail::onRadiusEdit() +{ + updateDetail(); +} + +void TaskDetail::onReferenceEdit() +{ + updateDetail(); +} + +void TaskDetail::onDraggerClicked(bool b) +{ + Q_UNUSED(b); + ui->pbDragger->setEnabled(false); + enableInputFields(false); + editByHighlight(); + return; +} + +void TaskDetail::editByHighlight() +{ +// Base::Console().Message("TD::editByHighlight()\n"); + if (m_ghost == nullptr) { + Base::Console().Error("TaskDetail::editByHighlight - no ghost object\n"); + return; + } + + m_scene->clearSelection(); + m_ghost->setSelected(true); + m_ghost->setPos(getAnchorScene()); + m_ghost->draw(); + m_ghost->show(); +} + +//dragEnd is in scene coords. +void TaskDetail::onHighlightMoved(QPointF dragEnd) +{ +// Base::Console().Message("TD::onHighlightMoved(%s) - highlight: %X\n", +// DrawUtil::formatVector(dragEnd).c_str(), m_ghost); + ui->pbDragger->setEnabled(true); + + double scale = getBaseFeat()->getScale(); + double x = Rez::guiX(getBaseFeat()->X.getValue()) * scale; + double y = Rez::guiX(getBaseFeat()->Y.getValue()) * scale; + QPointF basePosScene(x, -y); //base position in scene coords + + QPointF anchorDisplace = dragEnd - basePosScene; + QPointF newAnchorPos = Rez::appX(anchorDisplace) / scale; + + updateUi(newAnchorPos); + updateDetail(); + enableInputFields(true); + m_ghost->setSelected(false); + m_ghost->hide(); +} + +void TaskDetail::saveButtons(QPushButton* btnOK, + QPushButton* btnCancel) +{ + m_btnOK = btnOK; + m_btnCancel = btnCancel; +} + +void TaskDetail::enableTaskButtons(bool b) +{ + m_btnOK->setEnabled(b); + m_btnCancel->setEnabled(b); +} + +//***** Feature create & edit stuff ******************************************* +void TaskDetail::createDetail() +{ +// Base::Console().Message("TD::createDetail()\n"); + Gui::Command::openCommand("Create Detail"); + + m_detailName = m_doc->getUniqueObjectName("Detail"); + + Gui::Command::doCommand(Command::Doc,"App.activeDocument().addObject('TechDraw::DrawViewDetail','%s')", + m_detailName.c_str()); + App::DocumentObject *docObj = m_doc->getObject(m_detailName.c_str()); + TechDraw::DrawViewDetail* dvd = dynamic_cast(docObj); + if (!dvd) { + throw Base::TypeError("TaskDetail - new detail not found\n"); + } + m_detailFeat = dvd; + + dvd->Source.setValues(getBaseFeat()->Source.getValues()); + + Gui::Command::doCommand(Command::Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s", + m_detailName.c_str(),m_baseName.c_str()); + Gui::Command::doCommand(Command::Doc,"App.activeDocument().%s.Direction = App.activeDocument().%s.Direction", + m_detailName.c_str(),m_baseName.c_str()); + Gui::Command::doCommand(Command::Doc,"App.activeDocument().%s.XDirection = App.activeDocument().%s.XDirection", + m_detailName.c_str(),m_baseName.c_str()); + Gui::Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", + m_pageName.c_str(), m_detailName.c_str()); + + Gui::Command::updateActive(); + Gui::Command::commitCommand(); + + getBaseFeat()->requestPaint(); + m_created = true; +} + +void TaskDetail::updateDetail() +{ +// Base::Console().Message("TD::updateDetail()\n"); + Gui::Command::openCommand("Update Detail"); + double x = ui->qsbX->rawValue(); + double y = ui->qsbY->rawValue(); + Base::Vector3d temp(x, y, 0.0); + TechDraw::DrawViewDetail* detailFeat = getDetailFeat(); + detailFeat->AnchorPoint.setValue(temp); + + double radius = ui->qsbRadius->rawValue(); + detailFeat->Radius.setValue(radius); + QString qRef = ui->aeReference->text(); + std::string ref = Base::Tools::toStdString(qRef); + detailFeat->Reference.setValue(ref); + + detailFeat->recomputeFeature(); + getBaseFeat()->requestPaint(); + Gui::Command::updateActive(); + Gui::Command::commitCommand(); +} + +//***** Getters **************************************************************** + +//get the current Anchor highlight position in scene coords +QPointF TaskDetail::getAnchorScene() +{ + TechDraw::DrawViewPart* dvp = getBaseFeat(); + TechDraw::DrawViewDetail* dvd = getDetailFeat(); + + Base::Vector3d anchorPos = dvd->AnchorPoint.getValue(); + double x = dvp->X.getValue(); + double y = dvp->Y.getValue(); + Base::Vector3d basePos(x, y, 0.0); + Base::Vector3d netPos = basePos + anchorPos; + netPos = Rez::guiX(netPos * dvp->getScale()); + + QPointF qAnchor(netPos.x, - netPos.y); + return qAnchor; +} + +// protects against stale pointers +DrawViewPart* TaskDetail::getBaseFeat() +{ +// Base::Console().Message("TD::getBaseFeat()\n"); + DrawViewPart* result = nullptr; + + if (m_doc != nullptr) { + App::DocumentObject* baseObj = m_doc->getObject(m_baseName.c_str()); + if (baseObj != nullptr) { + result = static_cast(baseObj); + } + } + if (result == nullptr) { + std::string msg = "TaskDetail - base feature " + + m_baseName + + " not found \n"; + throw Base::TypeError(msg); + } + return result; +} + +// protects against stale pointers +DrawViewDetail* TaskDetail::getDetailFeat() +{ +// Base::Console().Message("TD::getDetailFeat()\n"); + DrawViewDetail* result = nullptr; + + if (m_doc != nullptr) { + App::DocumentObject* detailObj = m_doc->getObject(m_detailName.c_str()); + if (detailObj != nullptr) { + result = static_cast(detailObj); + } + } + if (result == nullptr) { + std::string msg = "TaskDetail - detail feature " + + m_detailName + + " not found \n"; +// throw Base::TypeError("TaskDetail - detail feature not found\n"); + throw Base::TypeError(msg); + } + return result; +} + +//****************************************************************************** + +bool TaskDetail::accept() +{ +// Base::Console().Message("TD::accept()\n"); + + Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument()); + if (!doc) return false; + + getDetailFeat()->requestPaint(); + getBaseFeat()->requestPaint(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return true; +} + +bool TaskDetail::reject() +{ +// Base::Console().Message("TD::reject()\n"); + Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument()); + if (!doc) return false; + + if (m_mode == CREATEMODE) { + if (m_created) { + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().removeObject('%s')", + m_detailName.c_str()); + } + } else { + restoreDetailState(); + getDetailFeat()->recomputeFeature(); + getBaseFeat()->requestPaint(); + } + + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return false; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgDetail::TaskDlgDetail(TechDraw::DrawViewPart* baseFeat) + : TaskDialog() +{ + widget = new TaskDetail(baseFeat); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-DetailView"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgDetail::TaskDlgDetail(TechDraw::DrawViewDetail* detailFeat) + : TaskDialog() +{ + widget = new TaskDetail(detailFeat); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-DetailView"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgDetail::~TaskDlgDetail() +{ +} + +void TaskDlgDetail::update() +{ +// widget->updateTask(); +} + +void TaskDlgDetail::modifyStandardButtons(QDialogButtonBox* box) +{ + QPushButton* btnOK = box->button(QDialogButtonBox::Ok); + QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel); + widget->saveButtons(btnOK, btnCancel); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgDetail::open() +{ +} + +void TaskDlgDetail::clicked(int) +{ +} + +bool TaskDlgDetail::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgDetail::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskDetail.h b/src/Mod/TechDraw/Gui/TaskDetail.h new file mode 100644 index 0000000000..588dcaea23 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskDetail.h @@ -0,0 +1,179 @@ +/*************************************************************************** + * Copyright (c) 2020 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_TASKCOSVERTEX_H +#define TECHDRAWGUI_TASKCOSVERTEX_H + +#include +#include +#include +#include + +#include + +//TODO: make this a proper enum +#define TRACKERPICK 0 +#define TRACKEREDIT 1 +#define TRACKERCANCEL 2 +#define TRACKERCANCELEDIT 3 + +class Ui_TaskDetail; + +namespace App { +class DocumentObject; +} + +namespace TechDraw +{ +class DrawPage; +class DrawView; +class DrawDetail; +class DrawViewPart; +} + +namespace TechDrawGui +{ +class QGVPage; +class QGIView; +class QGIPrimPath; +class MDIViewPage; +class QGEPath; +class QGIDetail; +class QGIGhostHighlight; +class ViewProviderLeader; + +class TaskDetail : public QWidget +{ + Q_OBJECT + +public: + TaskDetail(TechDraw::DrawViewPart* baseFeat); + TaskDetail(TechDraw::DrawViewDetail* detailFeat); + ~TaskDetail(); + +public Q_SLOTS: + void onDraggerClicked(bool b); + void onHighlightMoved(QPointF newPos); + void onXEdit(); + void onYEdit(); + void onRadiusEdit(); + void onReferenceEdit(); + +public: + virtual bool accept(); + virtual bool reject(); + void updateTask(); + void saveButtons(QPushButton* btnOK, + QPushButton* btnCancel); + void enableTaskButtons(bool b); + +protected: + void changeEvent(QEvent *e); + void startDragger(void); + + void createDetail(); + void updateDetail(); + + void editByHighlight(); + + void blockButtons(bool b); + void setUiFromFeat(void); + void updateUi(QPointF p); + void enableInputFields(bool b); + + void saveDetailState(); + void restoreDetailState(); + QPointF getAnchorScene(); + + TechDraw::DrawViewPart* getBaseFeat(); + TechDraw::DrawViewDetail* getDetailFeat(); + +private: + Ui_TaskDetail * ui; + bool blockUpdate; + + QGIGhostHighlight* m_ghost; + + MDIViewPage* m_mdi; + QGraphicsScene* m_scene; + QGVPage* m_view; + TechDraw::DrawViewDetail* m_detailFeat; + TechDraw::DrawViewPart* m_baseFeat; + TechDraw::DrawPage* m_basePage; + QGIView* m_qgParent; + std::string m_qgParentName; + + bool m_inProgressLock; + + QPushButton* m_btnOK; + QPushButton* m_btnCancel; + + Base::Vector3d m_saveAnchor; + double m_saveRadius; + bool m_saved; + QPointF m_dragStart; + + std::string m_baseName; + std::string m_pageName; + std::string m_detailName; + App::Document* m_doc; + + bool m_mode; + bool m_created; +}; + +class TaskDlgDetail : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgDetail(TechDraw::DrawViewPart* baseFeat); + TaskDlgDetail(TechDraw::DrawViewDetail* detailFeat); + ~TaskDlgDetail(); + +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + 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; } + void update(); + + void modifyStandardButtons(QDialogButtonBox* box); + +protected: + +private: + TaskDetail * widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef TECHDRAWGUI_TASKCOSVERTEX_H diff --git a/src/Mod/TechDraw/Gui/TaskDetail.ui b/src/Mod/TechDraw/Gui/TaskDetail.ui new file mode 100644 index 0000000000..bf7d9798f3 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskDetail.ui @@ -0,0 +1,296 @@ + + + TechDrawGui::TaskDetail + + + + 0 + 0 + 381 + 405 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Detail Anchor + + + + :/icons/actions/techdraw-DetailView.svg:/icons/actions/techdraw-DetailView.svg + + + + + + + 0 + 0 + + + + + 300 + 300 + + + + + 300 + 300 + + + + QFrame::Box + + + QFrame::Raised + + + + + + + + + + false + + + false + + + Qt::NoFocus + + + false + + + + + + + Base View + + + + + + + Detail View + + + + + + + false + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Click to drag detail highlight to new position + + + Drag Highlight + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + size of detail view + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 10.000000000000000 + + + + + + + X + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Y + + + + + + + + + + + + + + x position of detail highlight within view + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 0.000000000000000 + + + + + + + y position of detail highlight within view + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Radius + + + + + + + Reference + + + + + + + Detail identifier + + + 1 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Gui::AccelLineEdit + QLineEdit +
Gui/Widgets.h
+
+ + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+
+ + + + +
diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp index a1c35d66cf..b8469fc1a2 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp @@ -37,19 +37,29 @@ #include #include #include +#include +#include +#include +#include #include +#include +#include +#include #include #include #include #include #include +#include #include #include #include #include #include +#include "QGIView.h" +#include "TaskDetail.h" #include "ViewProviderViewPart.h" using namespace TechDrawGui; @@ -166,8 +176,11 @@ void ViewProviderViewPart::onChanged(const App::Property* prop) void ViewProviderViewPart::attach(App::DocumentObject *pcFeat) { TechDraw::DrawViewMulti* dvm = dynamic_cast(pcFeat); + TechDraw::DrawViewDetail* dvd = dynamic_cast(pcFeat); if (dvm != nullptr) { sPixmap = "TechDraw_Tree_Multi"; + } else if (dvd != nullptr) { + sPixmap = "actions/techdraw-DetailView"; } ViewProviderDrawingView::attach(pcFeat); @@ -232,6 +245,57 @@ std::vector ViewProviderViewPart::claimChildren(void) cons return tmp; } } +bool ViewProviderViewPart::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default ) { + if (Gui::Control().activeDialog()) { //TaskPanel already open! + return false; + } + TechDraw::DrawViewPart* dvp = getViewObject(); + TechDraw::DrawViewDetail* dvd = dynamic_cast(dvp); + if (dvd != nullptr) { + // clear the selection (convenience) + Gui::Selection().clearSelection(); + Gui::Control().showDialog(new TaskDlgDetail(dvd)); +// Gui::Selection().clearSelection(); +// flush any lingering gui objects + Gui::Selection().addSelection(dvd->getDocument()->getName(), + dvd->getNameInDocument()); + Gui::Selection().clearSelection(); + Gui::Selection().addSelection(dvd->getDocument()->getName(), + dvd->getNameInDocument()); + +//Gui.ActiveDocument.resetEdit() +//>>> # Gui.Selection.addSelection('aaStart121','Detail') +//>>> # Gui.Selection.clearSelection() +//>>> # Gui.Selection.addSelection('aaStart121','Detail') +//>>> # Gui.Selection.addSelection('aaStart121','Detail') +//>>> # Gui.Selection.clearSelection() +//>>> # Gui.Selection.addSelection('aaStart121','Detail') + return true; + } + } else { + return ViewProviderDrawingView::setEdit(ModNum); + } + return true; +} + +void ViewProviderViewPart::unsetEdit(int ModNum) +{ + Q_UNUSED(ModNum); + if (ModNum == ViewProvider::Default) { + Gui::Control().closeDialog(); + } + else { + ViewProviderDrawingView::unsetEdit(ModNum); + } +} + +bool ViewProviderViewPart::doubleClicked(void) +{ + setEdit(ViewProvider::Default); + return true; +} TechDraw::DrawViewPart* ViewProviderViewPart::getViewObject() const { diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.h b/src/Mod/TechDraw/Gui/ViewProviderViewPart.h index 9ab6a4501e..13ff73242c 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewPart.h +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.h @@ -68,6 +68,9 @@ public: virtual std::vector getDisplayModes(void) const; virtual bool onDelete(const std::vector &); virtual bool canDelete(App::DocumentObject* obj) const; + virtual bool setEdit(int ModNum); + virtual void unsetEdit(int ModNum); + virtual bool doubleClicked(void); public: virtual void onChanged(const App::Property *prop);