From 4eab3248035cbfca3d649621ef42ccaa2218338b Mon Sep 17 00:00:00 2001 From: WandererFan Date: Sat, 29 Oct 2016 08:38:25 -0400 Subject: [PATCH] Basic working multipart View --- src/Mod/TechDraw/App/AppTechDraw.cpp | 3 + src/Mod/TechDraw/App/CMakeLists.txt | 3 +- src/Mod/TechDraw/App/DrawViewMulti.cpp | 177 +++++++ src/Mod/TechDraw/App/DrawViewMulti.h | 85 +++ src/Mod/TechDraw/Gui/Command.cpp | 56 +- src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 2 + .../Resources/icons/TechDraw_Tree_Multi.svg | 57 ++ .../icons/actions/techdraw-multiview.svg | 500 ++++++++++++++++++ .../icons/actions/techdraw-viewsection.svg | 53 +- src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp | 6 + src/Mod/TechDraw/Gui/Workbench.cpp | 3 + 11 files changed, 902 insertions(+), 43 deletions(-) create mode 100644 src/Mod/TechDraw/App/DrawViewMulti.cpp create mode 100644 src/Mod/TechDraw/App/DrawViewMulti.h create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Tree_Multi.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-multiview.svg diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index eb455d8f3a4c..986f8a05b672 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -34,6 +34,7 @@ #include "DrawViewDraft.h" #include "DrawViewArch.h" #include "DrawViewSpreadsheet.h" +#include "DrawViewMulti.h" namespace TechDraw { extern PyObject* initModule(); @@ -68,6 +69,7 @@ PyMODINIT_FUNC initTechDraw() TechDraw::DrawViewSpreadsheet ::init(); TechDraw::DrawViewSection ::init(); + TechDraw::DrawViewMulti ::init(); TechDraw::DrawViewDimension ::init(); TechDraw::DrawProjGroup ::init(); TechDraw::DrawProjGroupItem ::init(); @@ -83,6 +85,7 @@ PyMODINIT_FUNC initTechDraw() // Python Types TechDraw::DrawViewPython ::init(); TechDraw::DrawViewPartPython ::init(); + TechDraw::DrawViewMultiPython ::init(); TechDraw::DrawTemplatePython ::init(); TechDraw::DrawViewSymbolPython::init(); } diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 14f8675ad573..85e16d6778c1 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -79,7 +79,8 @@ SET(Draw_SRCS DrawViewDraft.h DrawViewArch.cpp DrawViewArch.h -) + DrawViewMulti.cpp + DrawViewMulti.h) SET(TechDraw_SRCS AppTechDraw.cpp diff --git a/src/Mod/TechDraw/App/DrawViewMulti.cpp b/src/Mod/TechDraw/App/DrawViewMulti.cpp new file mode 100644 index 000000000000..a999bbd90469 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawViewMulti.cpp @@ -0,0 +1,177 @@ +/*************************************************************************** + * Copyright (c) WandererFan (wandererfan@gmail.com) 2016 * + * * + * 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 +# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif + +#include + +# include +# include + +#include +#include +#include +#include +#include +#include + +#include + +#include "Geometry.h" +#include "GeometryObject.h" +#include "DrawViewMulti.h" + +using namespace TechDraw; +using namespace std; + + +//=========================================================================== +// DrawViewMulti +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawViewMulti, TechDraw::DrawViewPart) + +DrawViewMulti::DrawViewMulti() +{ + static const char *group = "Projection"; + + //properties that affect Geometry + ADD_PROPERTY_TYPE(Sources ,(0),group,App::Prop_None,"3D Shapes to view"); + + //Source is replaced by Sources in Multi + Source.setStatus(App::Property::ReadOnly,true); +} + +DrawViewMulti::~DrawViewMulti() +{ +} + +short DrawViewMulti::mustExecute() const +{ + short result = 0; + if (!isRestoring()) { + result = (Sources.isTouched()); + } + if (result) { + return result; + } + return TechDraw::DrawViewPart::mustExecute(); +} + +void DrawViewMulti::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + //Base::Console().Message("TRACE - DVM::onChanged(%s) - %s\n",prop->getName(),Label.getValue()); + if (prop == &Sources) { + const std::vector& links = Sources.getValues(); + if (!links.empty()) { + Source.setValue(links.front()); + } + } + } + + DrawViewPart::onChanged(prop); +} + +App::DocumentObjectExecReturn *DrawViewMulti::execute(void) +{ + const std::vector& links = Sources.getValues(); + if (links.empty()) { + Base::Console().Log("INFO - DVM::execute - No Sources - creation?\n"); + return DrawViewPart::execute(); + } + + //Base::Console().Message("TRACE - DVM::execute() - %s/%s\n",getNameInDocument(),Label.getValue()); + + (void) DrawView::execute(); //make sure Scale is up to date + + BRep_Builder builder; + TopoDS_Compound comp; + builder.MakeCompound(comp); + for (auto& l:links) { + const Part::TopoShape &partTopo = static_cast(l)->Shape.getShape(); + BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape()); + TopoDS_Shape shape = BuilderCopy.Shape(); + builder.Add(comp, shape); + } + m_compound = comp; + + geometryObject->setTolerance(Tolerance.getValue()); + geometryObject->setScale(Scale.getValue()); + + gp_Pnt inputCenter; + try { + inputCenter = TechDrawGeometry::findCentroid(comp, + Direction.getValue()); + TopoDS_Shape mirroredShape = TechDrawGeometry::mirrorShape(comp, + inputCenter, + Scale.getValue()); + buildGeometryObject(mirroredShape,inputCenter); + +#if MOD_TECHDRAW_HANDLE_FACES + extractFaces(); +#endif //#if MOD_TECHDRAW_HANDLE_FACES + } + catch (Standard_Failure) { + Handle_Standard_Failure e1 = Standard_Failure::Caught(); + Base::Console().Log("LOG - DVM::execute - projection failed for %s - %s **\n",getNameInDocument(),e1->GetMessageString()); + return new App::DocumentObjectExecReturn(e1->GetMessageString()); + } + + return App::DocumentObject::StdReturn; +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewMultiPython, TechDraw::DrawViewMulti) +template<> const char* TechDraw::DrawViewMultiPython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderViewProviderViewPart"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} diff --git a/src/Mod/TechDraw/App/DrawViewMulti.h b/src/Mod/TechDraw/App/DrawViewMulti.h new file mode 100644 index 000000000000..481026af63f2 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawViewMulti.h @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2007 * + * Copyright (c) Luke Parry (l.parry@warwick.ac.uk) 2013 * + * Copyright (c) WandererFan (wandererfan@gmail.com) 2016 * + * 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 _DrawViewMulti_h_ +#define _DrawViewMulti_h_ + +#include +#include +#include +#include +#include + +#include + +#include "DrawViewPart.h" + +class gp_Pln; +class TopoDS_Face; + +namespace TechDrawGeometry +{ +//class Face; +} + +namespace TechDraw +{ + + +/** Base class of all View Features in the drawing module + */ +class TechDrawExport DrawViewMulti : public DrawViewPart +{ + PROPERTY_HEADER(Part::DrawViewMulti); + +public: + /// Constructor + DrawViewMulti(void); + virtual ~DrawViewMulti(); + + App::PropertyLinkList Sources; + + virtual short mustExecute() const; + /** @name methods overide Feature */ + //@{ + /// recalculate the Feature + virtual App::DocumentObjectExecReturn *execute(void); + virtual void onChanged(const App::Property* prop); + //@} + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderViewPart"; + } + +protected: + TopoDS_Compound m_compound; + +// void getParameters(void); +}; + +typedef App::FeaturePythonT DrawViewMultiPython; + +} //namespace TechDraw + +#endif diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index a31f55c47c2a..6ec8a21d8c95 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include "DrawGuiUtil.h" @@ -442,6 +443,58 @@ bool CmdTechDrawProjGroup::isActive(void) 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 @@ -826,7 +879,7 @@ void CmdTechDrawArchView::activated(int iMsg) QObject::tr("The selected object is not an Arch Section Plane.")); return; } - + std::string PageName = page->getNameInDocument(); std::string FeatName = getUniqueObjectName("ArchView"); @@ -957,6 +1010,7 @@ void CreateTechDrawCommands(void) rcCmdMgr.addCommand(new CmdTechDrawNewPage()); rcCmdMgr.addCommand(new CmdTechDrawNewView()); rcCmdMgr.addCommand(new CmdTechDrawNewViewSection()); + rcCmdMgr.addCommand(new CmdTechDrawNewMulti()); rcCmdMgr.addCommand(new CmdTechDrawProjGroup()); rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); rcCmdMgr.addCommand(new CmdTechDrawClip()); diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 1087cc37b214..91745a848d61 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -9,6 +9,7 @@ icons/TechDraw_Tree_Spreadsheet.svg icons/TechDraw_Tree_Symbol.svg icons/TechDraw_Tree_View.svg + icons/TechDraw_Tree_Multi.svg icons/TechDraw_Pages.svg icons/TechDraw_ProjBottom.svg icons/TechDraw_ProjFront.svg @@ -32,6 +33,7 @@ icons/actions/techdraw-new-default.svg icons/actions/techdraw-new-pick.svg icons/actions/techdraw-view.svg + icons/actions/techdraw-multiview.svg icons/actions/techdraw-annotation.svg icons/actions/techdraw-clip.svg icons/actions/techdraw-clipplus.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Tree_Multi.svg b/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Tree_Multi.svg new file mode 100644 index 000000000000..e114a25189eb --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Tree_Multi.svg @@ -0,0 +1,57 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-multiview.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-multiview.svg new file mode 100644 index 000000000000..81dd88f80c86 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-multiview.svg @@ -0,0 +1,500 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-viewsection.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-viewsection.svg index fd32f65cd141..b5fcefd4c46a 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-viewsection.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-viewsection.svg @@ -14,7 +14,7 @@ height="48.000000px" id="svg249" sodipodi:version="0.32" - inkscape:version="0.48.3.1 r9886" + inkscape:version="0.48.4 r9939" sodipodi:docname="techdraw-viewsection.svg" inkscape:export-filename="/home/jimmac/gfx/novell/pdes/trunk/docs/BIGmime-text.png" inkscape:export-xdpi="240.00000" @@ -361,36 +361,6 @@ fx="45.883327" fy="28.869568" r="19.467436" /> - - - image/svg+xml - + Jakub Steiner @@ -594,29 +564,30 @@ id="rect2221" width="31.612995" height="22.113316" - x="7.2478685" - y="15.429372" + x="7.6014218" + y="14.98743" rx="2.0176325" ry="1.7378116" /> + id="g4347" + style="fill:#d3d7cf;stroke:#888a85"> #include +#include #include #include @@ -87,6 +88,11 @@ void ViewProviderViewPart::onChanged(const App::Property* prop) void ViewProviderViewPart::attach(App::DocumentObject *pcFeat) { + TechDraw::DrawViewMulti* dvm = dynamic_cast(pcFeat); + if (dvm != nullptr) { + sPixmap = "TechDraw_Tree_Multi"; + } + // call parent attach method ViewProviderDocumentObject::attach(pcFeat); } diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 0e804550081d..351a94f6c74c 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -63,6 +63,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_NewPageDef"; *draw << "TechDraw_NewPage"; *draw << "TechDraw_NewView"; + *draw << "TechDraw_NewMulti"; *draw << "TechDraw_ProjGroup"; *draw << "TechDraw_NewViewSection"; *draw << "TechDraw_Annotation"; @@ -96,6 +97,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem *views = new Gui::ToolBarItem(root); views->setCommand("TechDraw Views"); *views << "TechDraw_NewView"; + *views << "TechDraw_NewMulti"; *views << "TechDraw_ProjGroup"; *views << "TechDraw_NewViewSection"; *views << "TechDraw_Annotation"; @@ -143,6 +145,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const Gui::ToolBarItem *views = new Gui::ToolBarItem(root); views->setCommand("Views"); *views << "TechDraw_NewView"; + *views << "TechDraw_NewMulti"; *views << "TechDraw_ProjGroup"; *views << "TechDraw_NewViewSection"; *views << "TechDraw_Annotation";