From 54a8e856cceef5096502ed3cd9c12d916bd54096 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Fri, 28 Oct 2016 14:58:22 -0200 Subject: [PATCH] TechDraw: Arch View --- src/Mod/Arch/ArchSectionPlane.py | 347 ++++++----- src/Mod/TechDraw/App/AppTechDraw.cpp | 2 + src/Mod/TechDraw/App/CMakeLists.txt | 2 + src/Mod/TechDraw/App/DrawViewArch.cpp | 132 ++++ src/Mod/TechDraw/App/DrawViewArch.h | 77 +++ src/Mod/TechDraw/Gui/AppTechDrawGui.cpp | 1 + src/Mod/TechDraw/Gui/Command.cpp | 58 ++ src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 1 + .../icons/actions/techdraw-arch-view.svg | 564 ++++++++++++++++++ src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp | 15 + src/Mod/TechDraw/Gui/ViewProviderSymbol.h | 11 + src/Mod/TechDraw/Gui/Workbench.cpp | 2 + 12 files changed, 1035 insertions(+), 177 deletions(-) create mode 100644 src/Mod/TechDraw/App/DrawViewArch.cpp create mode 100644 src/Mod/TechDraw/App/DrawViewArch.h create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-arch-view.svg diff --git a/src/Mod/Arch/ArchSectionPlane.py b/src/Mod/Arch/ArchSectionPlane.py index 282211589..3a7238603 100644 --- a/src/Mod/Arch/ArchSectionPlane.py +++ b/src/Mod/Arch/ArchSectionPlane.py @@ -35,6 +35,7 @@ else: def QT_TRANSLATE_NOOP(ctxt,txt): return txt + def makeSectionPlane(objectslist=None,name="Section"): """makeSectionPlane([objectslist]) : Creates a Section plane objects including the given objects. If no object is given, the whole document will be considered.""" @@ -53,6 +54,7 @@ def makeSectionPlane(objectslist=None,name="Section"): obj.Objects = g return obj + def makeSectionView(section,name="View"): """makeSectionView(section) : Creates a Drawing view of the given Section Plane in the active Page object (a new page will be created if none exists""" @@ -72,6 +74,156 @@ def makeSectionView(section,name="View"): view.Label = translate("Arch","View of")+" "+section.Name return view + +def getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=False,scale=1,linewidth=1,fontsize=1): + """getSVG(section,[allOn,renderMode,showHidden,showFill,scale,linewidth,fontsize]) : + returns an SVG fragment from an Arch section plane. If + allOn is True, all cut objects are shown, regardless if they are visible or not. + renderMode can be Wireframe (default) or Solid to use the Arch solid renderer. If + showHidden is True, the hidden geometry above the section plane is shown in dashed line. + If showFill is True, the cut areas get filled with a pattern""" + + if not section.Objects: + return + import DraftGeomUtils + p = FreeCAD.Placement(section.Placement) + direction = p.Rotation.multVec(FreeCAD.Vector(0,0,1)) + objs = Draft.getGroupContents(section.Objects,walls=True,addgroups=True) + if not allOn: + objs = Draft.removeHidden(objs) + # separate spaces + spaces = [] + nonspaces = [] + for o in objs: + if Draft.getType(o) == "Space": + spaces.append(o) + else: + nonspaces.append(o) + objs = nonspaces + svg = '' + fillpattern = ' +#endif + +#include + +#include +#include +#include +#include + +#include "DrawViewArch.h" + +using namespace TechDraw; +using namespace std; + + +//=========================================================================== +// DrawViewArch +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawViewArch, TechDraw::DrawViewSymbol) + +const char* DrawViewArch::RenderModeEnums[]= {"Wireframe", + "Solid", + NULL}; + +DrawViewArch::DrawViewArch(void) +{ + static const char *group = "Arch view"; + + ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"Section Plane object for this view"); + ADD_PROPERTY_TYPE(AllOn ,(false),group,App::Prop_None,"If hidden objects must be shown or not"); + RenderMode.setEnums(RenderModeEnums); + ADD_PROPERTY_TYPE(RenderMode, ((long)0),group,App::Prop_None,"The render mode to use"); + ADD_PROPERTY_TYPE(ShowHidden ,(false),group,App::Prop_None,"If the hidden geometry behind the section plane is shown or not"); + ADD_PROPERTY_TYPE(ShowFill ,(false),group,App::Prop_None,"If cut areas must be filled with a hatch pattern or not"); + ADD_PROPERTY_TYPE(LineWidth,(0.35),group,App::Prop_None,"Line width of this view"); + ADD_PROPERTY_TYPE(FontSize,(12.0),group,App::Prop_None,"Text size for this view"); + ScaleType.setValue("Custom"); +} + +DrawViewArch::~DrawViewArch() +{ +} + +void DrawViewArch::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + if (prop == &Source || + prop == &AllOn || + prop == &RenderMode || + prop == &ShowHidden || + prop == &ShowFill || + prop == &LineWidth || + prop == &FontSize) { + try { + App::DocumentObjectExecReturn *ret = recompute(); + delete ret; + } + catch (...) { + } + } + } + TechDraw::DrawViewSymbol::onChanged(prop); +} + +App::DocumentObjectExecReturn *DrawViewArch::execute(void) +{ + App::DocumentObject* sourceObj = Source.getValue(); + if (sourceObj) { + std::string svgFrag; + std::string svgHead = getSVGHead(); + std::string svgTail = getSVGTail(); + std::string FeatName = getNameInDocument(); + std::string SourceName = sourceObj->getNameInDocument(); + // ArchSectionPlane.getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=False,scale=1,linewidth=1,fontsize=1): + + std::stringstream paramStr; + paramStr << ",allOn=" << (AllOn.getValue() ? "True" : "False") + << ",renderMode=\"" << RenderMode.getValue() << "\"" + << ",showHidden=" << (ShowHidden.getValue() ? "True" : "False") + << ",showFill=" << (ShowFill.getValue() ? "True" : "False") + << ",linewidth=" << LineWidth.getValue() + << ",fontsize=" << FontSize.getValue(); + Base::Interpreter().runString("import ArchSectionPlane"); + Base::Interpreter().runStringArg("svgBody = ArchSectionPlane.getSVG(App.activeDocument().%s %s)", + SourceName.c_str(),paramStr.str().c_str()); + Base::Interpreter().runStringArg("App.activeDocument().%s.Symbol = '%s' + svgBody + '%s'", + FeatName.c_str(),svgHead.c_str(),svgTail.c_str()); + } + return DrawView::execute(); +} + +std::string DrawViewArch::getSVGHead(void) +{ + std::string head = std::string("\\n"); + return head; +} + +std::string DrawViewArch::getSVGTail(void) +{ + std::string tail = "\\n"; + return tail; +} diff --git a/src/Mod/TechDraw/App/DrawViewArch.h b/src/Mod/TechDraw/App/DrawViewArch.h new file mode 100644 index 000000000..856bf2447 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawViewArch.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (c) York van Havre 2016 yorik@uncreated.net * + * * + * 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 _DrawViewArch_h_ +#define _DrawViewArch_h_ + +#include +#include +#include +#include + +#include "DrawViewSymbol.h" + +namespace TechDraw +{ + +class TechDrawExport DrawViewArch : public TechDraw::DrawViewSymbol +{ + PROPERTY_HEADER(TechDraw::DrawViewArch); + +public: + /// Constructor + DrawViewArch(void); + virtual ~DrawViewArch(); + + App::PropertyLink Source; + App::PropertyBool AllOn; + App::PropertyEnumeration RenderMode; // "Wireframe","Solid" + App::PropertyBool ShowHidden; + App::PropertyBool ShowFill; + App::PropertyFloat LineWidth; + App::PropertyFloat FontSize; + + /** @name methods overide Feature */ + //@{ + /// recalculate the Feature + virtual App::DocumentObjectExecReturn *execute(void); + //@} + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderArch"; + } + +protected: + virtual void onChanged(const App::Property* prop); + Base::BoundBox3d bbox; + std::string getSVGHead(void); + std::string getSVGTail(void); + +private: + static const char* RenderModeEnums[]; +}; + +} //namespace TechDraw + + +#endif diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp index 327a6d780..dfb5ba097 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -97,6 +97,7 @@ void TechDrawGuiExport initTechDrawGui() TechDrawGui::ViewProviderAnnotation::init(); TechDrawGui::ViewProviderSymbol::init(); TechDrawGui::ViewProviderDraft::init(); + TechDrawGui::ViewProviderArch::init(); TechDrawGui::ViewProviderHatch::init(); TechDrawGui::ViewProviderSpreadsheet::init(); diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index b57734f66..d64253320 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -789,6 +789,63 @@ 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 //=========================================================================== @@ -910,5 +967,6 @@ void CreateTechDrawCommands(void) rcCmdMgr.addCommand(new CmdTechDrawSymbol()); rcCmdMgr.addCommand(new CmdTechDrawExportPage()); rcCmdMgr.addCommand(new CmdTechDrawDraftView()); + rcCmdMgr.addCommand(new CmdTechDrawArchView()); rcCmdMgr.addCommand(new CmdTechDrawSpreadsheet()); } diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index ad141145f..f18104557 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -38,6 +38,7 @@ icons/actions/techdraw-clipminus.svg icons/actions/techdraw-symbol.svg icons/actions/techdraw-draft-view.svg + icons/actions/techdraw-arch-view.svg icons/actions/techdraw-saveSVG.svg icons/actions/techdraw-viewsection.svg icons/actions/techdraw-hatch.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-arch-view.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-arch-view.svg new file mode 100644 index 000000000..f026ad268 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-arch-view.svg @@ -0,0 +1,564 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A + + + + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp b/src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp index 827fb051a..69a469ff5 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderSymbol.cpp @@ -99,3 +99,18 @@ ViewProviderDraft::ViewProviderDraft() ViewProviderDraft::~ViewProviderDraft() { } + +//************************************************************************** +// Arch view + +PROPERTY_SOURCE(TechDrawGui::ViewProviderArch, TechDrawGui::ViewProviderSymbol) + + +ViewProviderArch::ViewProviderArch() +{ + sPixmap = "actions/techdraw-arch-view.svg"; +} + +ViewProviderArch::~ViewProviderArch() +{ +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderSymbol.h b/src/Mod/TechDraw/Gui/ViewProviderSymbol.h index ffc081e4a..8f6eb4d32 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderSymbol.h +++ b/src/Mod/TechDraw/Gui/ViewProviderSymbol.h @@ -65,6 +65,17 @@ public: virtual ~ViewProviderDraft(); }; +class TechDrawGuiExport ViewProviderArch : public ViewProviderSymbol +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderArch); + +public: + /// constructor + ViewProviderArch(); + /// destructor + virtual ~ViewProviderArch(); +}; + } // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 0c38c2443..0e8045500 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -73,6 +73,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_ClipMinus"; *draw << "TechDraw_NewDimension"; *draw << "TechDraw_DraftView"; + *draw << "TechDraw_ArchView"; *draw << "TechDraw_ExportPage"; //*draw << "TechDraw_Open"; //*part << "TechDraw_NewA3Landscape"; @@ -99,6 +100,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *views << "TechDraw_NewViewSection"; *views << "TechDraw_Annotation"; *views << "TechDraw_DraftView"; + *views << "TechDraw_ArchView"; *views << "TechDraw_Spreadsheet"; Gui::ToolBarItem *clips = new Gui::ToolBarItem(root);