diff --git a/src/Mod/TechDraw/App/DrawViewMulti.cpp b/src/Mod/TechDraw/App/DrawViewMulti.cpp index f33a63b735..a5331130c4 100644 --- a/src/Mod/TechDraw/App/DrawViewMulti.cpp +++ b/src/Mod/TechDraw/App/DrawViewMulti.cpp @@ -51,6 +51,7 @@ #include #include +#include #include #include #include @@ -128,17 +129,24 @@ TopoDS_Shape DrawViewMulti::getSourceShape(void) const TopoDS_Compound comp; builder.MakeCompound(comp); for (auto& l:links) { - if (!l->isDerivedFrom(Part::Feature::getClassTypeId())){ - continue; //not a part - } - const Part::TopoShape &partTopo = static_cast(l)->Shape.getShape(); - if (partTopo.isNull()) { - continue; //has no shape + if (l->isDerivedFrom(Part::Feature::getClassTypeId())){ + const Part::TopoShape &partTopo = static_cast(l)->Shape.getShape(); + if (partTopo.isNull()) { + continue; //has no shape + } + BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape()); + TopoDS_Shape shape = BuilderCopy.Shape(); + builder.Add(comp, shape); + } else if (l->getTypeId().isDerivedFrom(App::Part::getClassTypeId())) { + TopoDS_Shape s = getShapeFromPart(static_cast(l)); + if (s.IsNull()) { + continue; + } + BRepBuilderAPI_Copy BuilderCopy(s); + TopoDS_Shape shape = BuilderCopy.Shape(); + builder.Add(comp, shape); } - BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape()); - TopoDS_Shape shape = BuilderCopy.Shape(); - builder.Add(comp, shape); - } + } result = comp; } return result; diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 097b3b2929..5c9c54133b 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -37,6 +37,8 @@ #include #include #include +# include +#include #include #include #include @@ -75,6 +77,7 @@ #include #include +#include #include #include #include @@ -158,14 +161,41 @@ TopoDS_Shape DrawViewPart::getSourceShape(void) const App::DocumentObject *link = Source.getValue(); if (!link) { Base::Console().Error("DVP - No Source object linked - %s\n",getNameInDocument()); - } else if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { - Base::Console().Error("DVP - Linked object is not a Part object - %s\n",getNameInDocument()); - } else { + } else if (link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { result = static_cast(link)->Shape.getShape().getShape(); + } else if (link->getTypeId().isDerivedFrom(App::Part::getClassTypeId())) { + result = getShapeFromPart(static_cast(link)); + } else { Base::Console().Error("DVP - Can't handle this Source - %s\n",getNameInDocument()); } return result; } +TopoDS_Shape DrawViewPart::getShapeFromPart(App::Part* ap) const +{ + TopoDS_Shape result; + std::vector objs = ap->Group.getValues(); + std::vector shapes; + for (auto& d: objs) { + if (d->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + shapes.push_back(static_cast(d)->Shape.getShape().getShape()); + } + } + if (!shapes.empty()) { + BRep_Builder builder; + TopoDS_Compound comp; + builder.MakeCompound(comp); + for (auto& s: shapes) { + BRepBuilderAPI_Copy BuilderCopy(s); + TopoDS_Shape shape = BuilderCopy.Shape(); + builder.Add(comp, shape); + } + result = comp; + } + return result; +} + + + App::DocumentObjectExecReturn *DrawViewPart::execute(void) { if (!keepUpdated()) { diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 0d59d68e82..e11f4eada0 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -46,6 +46,11 @@ class gp_Ax2; //class TopoDS_Wire; class TopoDS_Shape; +namespace App +{ +class Part; +} + namespace TechDrawGeometry { class GeometryObject; @@ -155,7 +160,8 @@ public: gp_Pln getProjPlane(void) const; virtual std::vector getWireForFace(int idx) const; virtual TopoDS_Shape getSourceShape(void) const; - + virtual TopoDS_Shape getShapeFromPart(App::Part* ap) const; + protected: TechDrawGeometry::GeometryObject *geometryObject; Base::BoundBox3d bbox; diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 23679e12a7..b99a4c057b 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -254,11 +255,17 @@ void CmdTechDrawNewView::activated(int iMsg) } std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); - if (shapes.empty()) { + std::vector parts = getSelection().getObjectsOfType(App::Part::getClassTypeId()); + if ((shapes.empty()) && + (parts.empty())) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least 1 Part object.")); + QObject::tr("Select at least 1 object with a Shape.")); return; } + + if (!parts.empty()) { + shapes.insert(shapes.end(),parts.begin(),parts.end()); + } std::string PageName = page->getNameInDocument(); @@ -337,11 +344,6 @@ void CmdTechDrawNewViewSection::activated(int iMsg) } 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(); @@ -471,11 +473,24 @@ void CmdTechDrawProjGroup::activated(int iMsg) } std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); - if (shapes.size() != 1) { +// if (shapes.size() != 1) { +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), +// QObject::tr("Select exactly 1 Part object.")); +// return; +// } + + std::vector parts = getSelection().getObjectsOfType(App::Part::getClassTypeId()); + if ((shapes.empty()) && + (parts.empty())) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly 1 Part object.")); + QObject::tr("Select at least 1 object with a Shape.")); return; } + + if (!parts.empty()) { + shapes.insert(shapes.end(),parts.begin(),parts.end()); + } + std::string PageName = page->getNameInDocument(); Gui::WaitCursor wc; @@ -534,12 +549,23 @@ void CmdTechDrawNewMulti::activated(int iMsg) return; } - const std::vector& shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); - if (shapes.empty()) { + 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::vector parts = getSelection().getObjectsOfType(App::Part::getClassTypeId()); + if ((shapes.empty()) && + (parts.empty())) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least 1 Part object.")); + QObject::tr("Select at least 1 object with a Shape.")); return; } + + if (!parts.empty()) { + shapes.insert(shapes.end(),parts.begin(),parts.end()); + } std::string PageName = page->getNameInDocument(); @@ -880,6 +906,7 @@ void CmdTechDrawDraftView::activated(int iMsg) return; } +//TODO: shouldn't this be checking for a Draft object only? std::vector objects = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); if (objects.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), @@ -905,6 +932,7 @@ bool CmdTechDrawDraftView::isActive(void) return DrawGuiUtil::needPage(this); } +//TODO: shouldn't this be checking for an Arch object only? //=========================================================================== // TechDraw_ArchView //===========================================================================