Allow GroupExtension as Source for Views
- DrawViewPart had special case logic for App::Part. It now handles DocumentObjectGroup and any other GroupExtensions as Source.
This commit is contained in:
@@ -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<App::DocumentObject*>& 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<Part::Feature*>(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<App::Part*>(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()) {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/GroupExtension.h>
|
||||
#include <App/Part.h>
|
||||
#include <Base/BoundBox.h>
|
||||
#include <Base/Console.h>
|
||||
@@ -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<TopoDS_Shape> sourceShapes;
|
||||
for (auto& l:links) {
|
||||
std::vector<TopoDS_Shape> 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<Part::Feature*>(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<App::Part*>(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<TopoDS_Shape> DrawViewPart::getShapesFromObject(App::DocumentObject* docObj) const
|
||||
{
|
||||
TopoDS_Shape result;
|
||||
std::vector<App::DocumentObject*> objs = ap->Group.getValues();
|
||||
std::vector<TopoDS_Shape> shapes;
|
||||
for (auto& d: objs) {
|
||||
if (d->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
shapes.push_back(static_cast<Part::Feature*>(d)->Shape.getShape().getShape());
|
||||
std::vector<TopoDS_Shape> result;
|
||||
App::GroupExtension* gex = dynamic_cast<App::GroupExtension*>(docObj);
|
||||
if (docObj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
result.push_back(static_cast<Part::Feature*>(docObj)->Shape.getShape().getShape());
|
||||
} else if (gex != nullptr) {
|
||||
std::vector<App::DocumentObject*> objs = gex->Group.getValues();
|
||||
std::vector<TopoDS_Shape> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
gp_Pln getProjPlane(void) const;
|
||||
virtual std::vector<TopoDS_Wire> getWireForFace(int idx) const;
|
||||
virtual TopoDS_Shape getSourceShape(void) const;
|
||||
virtual TopoDS_Shape getShapeFromPart(App::Part* ap) const;
|
||||
virtual std::vector<TopoDS_Shape> getShapesFromObject(App::DocumentObject* docObj) const;
|
||||
virtual TopoDS_Shape getSourceShapeFused(void) const;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/FeaturePython.h>
|
||||
#include <App/Part.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
@@ -254,25 +253,16 @@ void CmdTechDrawNewView::activated(int iMsg)
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
|
||||
std::vector<App::DocumentObject*> parts = getSelection().getObjectsOfType(App::Part::getClassTypeId());
|
||||
if ((shapes.empty()) &&
|
||||
(parts.empty())) {
|
||||
std::vector<App::DocumentObject*> 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<App::DocumentObject*> 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<App::DocumentObject*> 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<TechDraw::DrawProjGroup *>(docObj) );
|
||||
multiView->Source.setValues(shapes);
|
||||
@@ -534,23 +510,12 @@ void CmdTechDrawNewMulti::activated(int iMsg)
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> 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<App::DocumentObject*> parts = getSelection().getObjectsOfType(App::Part::getClassTypeId());
|
||||
if ((shapes.empty()) &&
|
||||
(parts.empty())) {
|
||||
std::vector<App::DocumentObject*> 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user