diff --git a/src/Mod/TechDraw/App/DrawViewMulti.cpp b/src/Mod/TechDraw/App/DrawViewMulti.cpp index 07c9504019..8bc5c68355 100644 --- a/src/Mod/TechDraw/App/DrawViewMulti.cpp +++ b/src/Mod/TechDraw/App/DrawViewMulti.cpp @@ -119,40 +119,6 @@ void DrawViewMulti::onChanged(const App::Property* prop) DrawViewPart::onChanged(prop); } -TopoDS_Shape DrawViewMulti::getSourceShape(void) const -{ - TopoDS_Shape result; - const std::vector& links = Sources.getValues(); - if (links.empty()) { - Base::Console().Log("DVM::execute - No Sources - creation? - %s\n",getNameInDocument()); - } else { - BRep_Builder builder; - TopoDS_Compound comp; - builder.MakeCompound(comp); - for (auto& l:links) { - 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); - } - } - result = comp; - } - return result; -} - App::DocumentObjectExecReturn *DrawViewMulti::execute(void) { if (!keepUpdated()) { diff --git a/src/Mod/TechDraw/App/DrawViewMulti.h b/src/Mod/TechDraw/App/DrawViewMulti.h index 8c12da42a8..1c333257cf 100644 --- a/src/Mod/TechDraw/App/DrawViewMulti.h +++ b/src/Mod/TechDraw/App/DrawViewMulti.h @@ -67,8 +67,6 @@ public: virtual void onChanged(const App::Property* prop) override; //@} - virtual TopoDS_Shape getSourceShape(void) const override; - /// returns the type name of the ViewProvider virtual const char* getViewProviderName(void) const override { return "TechDrawGui::ViewProviderViewPart"; diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index c1aafa492b..fab07e9056 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -78,6 +78,7 @@ #include #include +#include #include #include #include @@ -184,54 +185,44 @@ TopoDS_Shape DrawViewPart::getSourceShape(void) const if (links.empty()) { Base::Console().Log("DVP::getSourceShape - No Sources - creation? - %s\n",getNameInDocument()); } else { + std::vector sourceShapes; + for (auto& l:links) { + std::vector shapeList = getShapesFromObject(l); + sourceShapes.insert(sourceShapes.end(),shapeList.begin(),shapeList.end()); + } + BRep_Builder builder; TopoDS_Compound comp; builder.MakeCompound(comp); - for (auto& l:links) { - 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); + for (auto& s:sourceShapes) { + if (s.IsNull()) { + continue; //has no shape } + BRepBuilderAPI_Copy BuilderCopy(s); + TopoDS_Shape shape = BuilderCopy.Shape(); + builder.Add(comp, shape); } result = comp; } return result; } -TopoDS_Shape DrawViewPart::getShapeFromPart(App::Part* ap) const +std::vector DrawViewPart::getShapesFromObject(App::DocumentObject* docObj) 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()); + std::vector result; + App::GroupExtension* gex = dynamic_cast(docObj); + if (docObj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + result.push_back(static_cast(docObj)->Shape.getShape().getShape()); + } else if (gex != nullptr) { + std::vector objs = gex->Group.getValues(); + std::vector shapes; + for (auto& d: objs) { + shapes = getShapesFromObject(d); + if (!shapes.empty()) { + result.insert(result.end(),shapes.begin(),shapes.end()); + } } } - 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; } diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 2ce0b48160..10ca8daebf 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -165,7 +165,7 @@ 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; + virtual std::vector getShapesFromObject(App::DocumentObject* docObj) const; virtual TopoDS_Shape getSourceShapeFused(void) const; protected: diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 4ea1ae2a15..d702ecd9e0 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -254,25 +253,16 @@ void CmdTechDrawNewView::activated(int iMsg) return; } - std::vector shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); - std::vector parts = getSelection().getObjectsOfType(App::Part::getClassTypeId()); - if ((shapes.empty()) && - (parts.empty())) { + std::vector shapes = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); + if (shapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least 1 object with a Shape.")); + QObject::tr("Can not make a View from this selection")); return; } - if (!parts.empty()) { - shapes.insert(shapes.end(),parts.begin(),parts.end()); - } - std::string PageName = page->getNameInDocument(); Gui::WaitCursor wc; - const auto selectedProjections( getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()) ); - - openCommand("Create view"); std::string FeatName = getUniqueObjectName("View"); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewPart','%s')",FeatName.c_str()); @@ -457,35 +447,21 @@ void CmdTechDrawProjGroup::activated(int iMsg) } 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::vector parts = getSelection().getObjectsOfType(App::Part::getClassTypeId()); - if ((shapes.empty()) && - (parts.empty())) { + if (shapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least 1 object with a Shape.")); + QObject::tr("Can not make a ProjectionGroup from this selection.")); return; } - if (!parts.empty()) { - shapes.insert(shapes.end(),parts.begin(),parts.end()); - } - 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) ); multiView->Source.setValues(shapes); @@ -534,23 +510,12 @@ void CmdTechDrawNewMulti::activated(int iMsg) 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::vector parts = getSelection().getObjectsOfType(App::Part::getClassTypeId()); - if ((shapes.empty()) && - (parts.empty())) { + std::vector shapes = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); + if (shapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least 1 object with a Shape.")); + QObject::tr("Can not make a MultiView from this selection.")); return; } - - if (!parts.empty()) { - shapes.insert(shapes.end(),parts.begin(),parts.end()); - } std::string PageName = page->getNameInDocument();