/*************************************************************************** * * * 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 "DrawGuiUtil.h" #include "MDIViewPage.h" #include "TaskProjGroup.h" #include "TaskSectionView.h" #include "ViewProviderPage.h" using namespace TechDrawGui; using namespace std; //=========================================================================== // TechDraw_NewPageDef (default template) //=========================================================================== DEF_STD_CMD_A(CmdTechDrawNewPageDef); CmdTechDrawNewPageDef::CmdTechDrawNewPageDef() : Command("TechDraw_NewPageDef") { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("Insert new default drawing page"); sToolTipText = QT_TR_NOOP("Insert new default drawing page"); sWhatsThis = "TechDraw_NewPageDef"; sStatusTip = sToolTipText; sPixmap = "actions/techdraw-new-default"; } void CmdTechDrawNewPageDef::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::Exception("CmdTechDrawNewPageDef 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 CmdTechDrawNewPageDef::isActive(void) { return hasActiveDocument(); } //=========================================================================== // TechDraw_NewPage (with template choice) //=========================================================================== DEF_STD_CMD_A(CmdTechDrawNewPage); CmdTechDrawNewPage::CmdTechDrawNewPage() : Command("TechDraw_NewPage") { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("Insert new drawing page from template"); sToolTipText = QT_TR_NOOP("Insert new drawing page from template"); sWhatsThis = "TechDraw_NewPage"; sStatusTip = sToolTipText; sPixmap = "actions/techdraw-new-pick"; } void CmdTechDrawNewPage::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 doCommand(Doc,"App.activeDocument().%s.Template = '%s'",TemplateName.c_str(), templateFileName.toStdString().c_str()); // 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::Exception("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 CmdTechDrawNewPage::isActive(void) { return hasActiveDocument(); } //=========================================================================== // TechDraw_NewView //=========================================================================== DEF_STD_CMD_A(CmdTechDrawNewView); CmdTechDrawNewView::CmdTechDrawNewView() : Command("TechDraw_NewView") { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("Insert view in drawing"); sToolTipText = QT_TR_NOOP("Insert a new View of a Part in the active drawing"); sWhatsThis = "TechDraw_NewView"; sStatusTip = sToolTipText; sPixmap = "actions/techdraw-view"; } void CmdTechDrawNewView::activated(int iMsg) { Q_UNUSED(iMsg); TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); if (!page) { return; } std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); if (shapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select at least 1 Part object.")); return; } std::string PageName = page->getNameInDocument(); Gui::WaitCursor wc; const auto selectedProjections( getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()) ); float newScale = 1.0; float newRotation = 0.0; Base::Vector3d newDirection(0.0, 0.0, 1.0); if (!selectedProjections.empty()) { const auto myView( static_cast(selectedProjections.front()) ); newScale = myView->Scale.getValue(); newRotation = myView->Rotation.getValue(); // The "Direction" property does not belong to TechDraw::DrawView, but to one of the // many child classes that are projecting objects into the drawing. Therefore, we get the // property by name. const App::PropertyVector* const propDirection = dynamic_cast(myView->getPropertyByName("Direction")); if (propDirection) { newDirection = propDirection->getValue(); } } openCommand("Create view"); for (std::vector::iterator it = shapes.begin(); it != shapes.end(); ++it) { std::string FeatName = getUniqueObjectName("View"); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewPart','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Direction = (%e,%e,%e)",FeatName.c_str(), newDirection.x, newDirection.y, newDirection.z); doCommand(Doc,"App.activeDocument().%s.Scale = %e",FeatName.c_str(), newScale); doCommand(Doc,"App.activeDocument().%s.Rotation = %e",FeatName.c_str(), newRotation); doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); } updateActive(); commitCommand(); } bool CmdTechDrawNewView::isActive(void) { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_NewViewSection //=========================================================================== DEF_STD_CMD_A(CmdTechDrawNewViewSection); CmdTechDrawNewViewSection::CmdTechDrawNewViewSection() : Command("TechDraw_NewViewSection") { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("Insert section view in drawing"); sToolTipText = QT_TR_NOOP("Insert a new Section View of a Part in the active drawing"); sWhatsThis = "TechDraw_NewViewSecton"; sStatusTip = sToolTipText; sPixmap = "actions/techdraw-viewsection"; } void CmdTechDrawNewViewSection::activated(int iMsg) { Q_UNUSED(iMsg); TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); if (!page) { return; } //std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); std::vector shapes = getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); if (shapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select at least 1 DrawingView object.")); return; } App::DocumentObject* dObj = *(shapes.begin()); TechDraw::DrawViewPart* dvp = static_cast(dObj); // if (dvp->getSectionRef()) { // QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), // QObject::tr("This View already has a related Section. Choose another.")); // return; // } std::string PageName = page->getNameInDocument(); Gui::WaitCursor wc; openCommand("Create view"); std::string FeatName = getUniqueObjectName("Section"); std::string SourceName = dvp->Source.getValue()->getNameInDocument(); std::string BaseName = (dObj)->getNameInDocument(); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSection','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SourceName.c_str()); doCommand(Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s",FeatName.c_str(),BaseName.c_str()); doCommand(Doc,"App.activeDocument().%s.Scale = App.activeDocument().%s.Scale",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()); App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str()); TechDraw::DrawViewSection* dsv = dynamic_cast(docObj); if (!dsv) { throw Base::Exception("CmdTechDrawNewViewSection DSV not found\n"); } Gui::Control().showDialog(new TaskDlgSectionView(dvp,dsv)); updateActive(); commitCommand(); } bool CmdTechDrawNewViewSection::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_NewViewDetail //=========================================================================== DEF_STD_CMD_A(CmdTechDrawNewViewDetail); CmdTechDrawNewViewDetail::CmdTechDrawNewViewDetail() : Command("TechDraw_NewViewDetail") { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("Insert detail view in drawing"); sToolTipText = QT_TR_NOOP("Insert a new Detail View of a Part in the active drawing"); sWhatsThis = "TechDraw_NewViewDetail"; sStatusTip = sToolTipText; sPixmap = "actions/techdraw-viewdetail"; } void CmdTechDrawNewViewDetail::activated(int iMsg) { Q_UNUSED(iMsg); TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); if (!page) { return; } std::vector shapes = getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); if (shapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select at least 1 DrawingView object.")); return; } App::DocumentObject* dObj = *(shapes.begin()); TechDraw::DrawViewPart* dvp = static_cast(dObj); std::string PageName = page->getNameInDocument(); Gui::WaitCursor wc; openCommand("Create view"); std::string FeatName = getUniqueObjectName("Detail"); std::string SourceName = dvp->Source.getValue()->getNameInDocument(); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDetail','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SourceName.c_str()); doCommand(Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s",FeatName.c_str(),(dObj)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Direction = App.activeDocument().%s.Direction",FeatName.c_str(),(dObj)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); updateActive(); commitCommand(); } bool CmdTechDrawNewViewDetail::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_ProjGroup //=========================================================================== DEF_STD_CMD_A(CmdTechDrawProjGroup); CmdTechDrawProjGroup::CmdTechDrawProjGroup() : Command("TechDraw_ProjGroup") { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("Insert Projection Group"); sToolTipText = QT_TR_NOOP("Insert multiple views of a single part into the active drawing"); sWhatsThis = "TechDraw_ProjGroup"; sStatusTip = sToolTipText; sPixmap = "actions/techdraw-projgroup"; } void CmdTechDrawProjGroup::activated(int iMsg) { Q_UNUSED(iMsg); TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); if (!page) { return; } std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); if (shapes.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select exactly 1 Part object.")); return; } std::string PageName = page->getNameInDocument(); Gui::WaitCursor wc; openCommand("Create Projection Group"); std::string multiViewName = getUniqueObjectName("ProjGroup"); std::string SourceName = (*shapes.begin())->getNameInDocument(); 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()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",multiViewName.c_str(),SourceName.c_str()); App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str()); auto multiView( static_cast(docObj) ); // set the anchor // std::string anchor = "Front"; // doCommand(Doc,"App.activeDocument().%s.addProjection('%s')",multiViewName.c_str(),anchor.c_str()); // add the multiView to the page // doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),multiViewName.c_str()); // create the rest of the desired views Gui::Control().showDialog(new TaskDlgProjGroup(multiView,true)); updateActive(); commitCommand(); } bool CmdTechDrawProjGroup::isActive(void) { bool havePage = DrawGuiUtil::needPage(this); bool taskInProgress = false; if (havePage) { taskInProgress = Gui::Control().activeDialog(); } return (havePage && !taskInProgress); } //=========================================================================== // TechDraw_NewMulti //=========================================================================== 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; } const std::vector& shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); if (shapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select at least 1 Part object.")); 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_Annotation //=========================================================================== DEF_STD_CMD_A(CmdTechDrawAnnotation); CmdTechDrawAnnotation::CmdTechDrawAnnotation() : Command("TechDraw_Annotation") { // setting the Gui eye-candy sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("&Annotation"); sToolTipText = QT_TR_NOOP("Inserts an Annotation in the active drawing"); sWhatsThis = "TechDraw_Annotation"; sStatusTip = QT_TR_NOOP("Inserts an Annotation in the active drawing"); sPixmap = "actions/techdraw-annotation"; } void CmdTechDrawAnnotation::activated(int iMsg) { Q_UNUSED(iMsg); TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); if (!page) { return; } std::string PageName = page->getNameInDocument(); std::string FeatName = getUniqueObjectName("Annotation"); openCommand("Create Annotation"); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewAnnotation','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); updateActive(); commitCommand(); } bool CmdTechDrawAnnotation::isActive(void) { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_Clip //=========================================================================== DEF_STD_CMD_A(CmdTechDrawClip); CmdTechDrawClip::CmdTechDrawClip() : Command("TechDraw_Clip") { // seting the sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("&Clip"); sToolTipText = QT_TR_NOOP("Inserts a clip group in the active drawing"); sWhatsThis = "TechDraw_Clip"; sStatusTip = QT_TR_NOOP("Inserts a clip group in the active drawing"); sPixmap = "actions/techdraw-clip"; } void CmdTechDrawClip::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 CmdTechDrawClip::isActive(void) { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_ClipPlus //=========================================================================== DEF_STD_CMD_A(CmdTechDrawClipPlus); CmdTechDrawClipPlus::CmdTechDrawClipPlus() : Command("TechDraw_ClipPlus") { sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("&ClipPlus"); sToolTipText = QT_TR_NOOP("Add a View to a clip group in the active drawing"); sWhatsThis = "TechDraw_ClipPlus"; sStatusTip = QT_TR_NOOP("Adds a View into a clip group in the active drawing"); sPixmap = "actions/techdraw-clipplus"; } void CmdTechDrawClipPlus::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 1 DrawViewClip and 1 DrawView.")); 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 Drawing View object.")); return; } if (!clip) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select exactly one Clip object.")); 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(); double newX = clip->Width.getValue() / 2.0; double newY = clip->Height.getValue() / 2.0; openCommand("ClipPlus"); 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.X = %.3f",ViewName.c_str(),newX); doCommand(Doc,"App.activeDocument().%s.Y = %.3f",ViewName.c_str(),newY); doCommand(Doc,"App.activeDocument().%s.ViewObject.Visibility = True",ViewName.c_str()); updateActive(); commitCommand(); } bool CmdTechDrawClipPlus::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_ClipMinus //=========================================================================== DEF_STD_CMD_A(CmdTechDrawClipMinus); CmdTechDrawClipMinus::CmdTechDrawClipMinus() : Command("TechDraw_ClipMinus") { sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("&ClipMinus"); sToolTipText = QT_TR_NOOP("Remove a View from a clip group in the active drawing"); sWhatsThis = "TechDraw_ClipMinus"; sStatusTip = QT_TR_NOOP("Remove a View from a clip group in the active drawing"); sPixmap = "actions/techdraw-clipminus"; } void CmdTechDrawClipMinus::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 Drawing View object.") ); 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("ClipMinus"); 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 CmdTechDrawClipMinus::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("Inserts a symbol from a svg file in the active drawing"); sWhatsThis = "TechDraw_Symbol"; sStatusTip = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing"); 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"); openCommand("Create Symbol"); doCommand(Doc,"f = open(unicode(\"%s\",'utf-8'),'r')",(const char*)filename.toUtf8()); 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 a DraftView"); sToolTipText = QT_TR_NOOP("Inserts a Draft WB object into the active drawing"); sWhatsThis = "TechDraw_DraftView"; sStatusTip = QT_TR_NOOP("Inserts a Draft WB object into the active drawing"); sPixmap = "actions/techdraw-draft-view"; } void CmdTechDrawDraftView::activated(int iMsg) { Q_UNUSED(iMsg); TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); if (!page) { return; } 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; } std::string PageName = page->getNameInDocument(); for (std::vector::iterator it = objects.begin(); it != objects.end(); ++it) { 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(); } } 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 an ArchView"); sToolTipText = QT_TR_NOOP("Inserts a view of an Arch Section Plane into the active drawing"); sWhatsThis = "TechDraw_ArchView"; sStatusTip = QT_TR_NOOP("Inserts a view of an Arch Section Plane into the active drawing"); sPixmap = "actions/techdraw-arch-view"; } void CmdTechDrawArchView::activated(int iMsg) { Q_UNUSED(iMsg); TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); if (!page) { return; } std::vector objects = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); if (objects.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select exactly one Arch Section Plane object.")); return; } App::Property* prop1 = objects[0]->getPropertyByName("Objects"); App::Property* prop2 = objects[0]->getPropertyByName("OnlySolids"); if ( (!prop1) || (!prop2) ) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("The selected object is not an Arch Section Plane.")); return; } std::string PageName = page->getNameInDocument(); std::string FeatName = getUniqueObjectName("ArchView"); std::string SourceName = objects[0]->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_Spreadheet //=========================================================================== DEF_STD_CMD_A(CmdTechDrawSpreadsheet); CmdTechDrawSpreadsheet::CmdTechDrawSpreadsheet() : Command("TechDraw_Spreadsheet") { // seting the sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("Spreadsheet"); sToolTipText = QT_TR_NOOP("Inserts a view of a selected spreadsheet into a drawing"); sWhatsThis = "TechDraw_Spreadsheet"; sStatusTip = QT_TR_NOOP("Inserts a view of a selected spreadsheet into a drawing"); sPixmap = "actions/techdraw-spreadsheet"; } void CmdTechDrawSpreadsheet::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 CmdTechDrawSpreadsheet::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_ExportPage //=========================================================================== DEF_STD_CMD_A(CmdTechDrawExportPage); CmdTechDrawExportPage::CmdTechDrawExportPage() : Command("TechDraw_ExportPage") { sGroup = QT_TR_NOOP("File"); sMenuText = QT_TR_NOOP("&Export page..."); sToolTipText = QT_TR_NOOP("Export a page to an SVG file"); sWhatsThis = "TechDraw_ExportPage"; sStatusTip = QT_TR_NOOP("Export a page to an SVG file"); sPixmap = "actions/techdraw-saveSVG"; } void CmdTechDrawExportPage::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 CmdTechDrawExportPage::isActive(void) { return DrawGuiUtil::needPage(this); } void CreateTechDrawCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdTechDrawNewPageDef()); rcCmdMgr.addCommand(new CmdTechDrawNewPage()); rcCmdMgr.addCommand(new CmdTechDrawNewView()); rcCmdMgr.addCommand(new CmdTechDrawNewViewSection()); rcCmdMgr.addCommand(new CmdTechDrawNewViewDetail()); rcCmdMgr.addCommand(new CmdTechDrawNewMulti()); rcCmdMgr.addCommand(new CmdTechDrawProjGroup()); rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); rcCmdMgr.addCommand(new CmdTechDrawClip()); rcCmdMgr.addCommand(new CmdTechDrawClipPlus()); rcCmdMgr.addCommand(new CmdTechDrawClipMinus()); rcCmdMgr.addCommand(new CmdTechDrawSymbol()); rcCmdMgr.addCommand(new CmdTechDrawExportPage()); rcCmdMgr.addCommand(new CmdTechDrawDraftView()); rcCmdMgr.addCommand(new CmdTechDrawArchView()); rcCmdMgr.addCommand(new CmdTechDrawSpreadsheet()); }