Allow Views of App::Parts
This commit is contained in:
committed by
Yorik van Havre
parent
6d032f1bcf
commit
913e6a7fd8
@@ -51,6 +51,7 @@
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <App/Part.h>
|
||||
#include <Base/BoundBox.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Console.h>
|
||||
@@ -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<Part::Feature*>(l)->Shape.getShape();
|
||||
if (partTopo.isNull()) {
|
||||
continue; //has no shape
|
||||
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);
|
||||
}
|
||||
BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape());
|
||||
TopoDS_Shape shape = BuilderCopy.Shape();
|
||||
builder.Add(comp, shape);
|
||||
}
|
||||
}
|
||||
result = comp;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include <BRepLProp_CurveTool.hxx>
|
||||
#include <BRepLProp_CLProps.hxx>
|
||||
#include <BRepExtrema_DistShapeShape.hxx>
|
||||
# include <BRep_Builder.hxx>
|
||||
#include <BRepBuilderAPI_Copy.hxx>
|
||||
#include <BRepBuilderAPI_MakeFace.hxx>
|
||||
#include <BRepBndLib.hxx>
|
||||
#include <Bnd_Box.hxx>
|
||||
@@ -75,6 +77,7 @@
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/Part.h>
|
||||
#include <Base/BoundBox.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
@@ -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<Part::Feature*>(link)->Shape.getShape().getShape();
|
||||
} else if (link->getTypeId().isDerivedFrom(App::Part::getClassTypeId())) {
|
||||
result = getShapeFromPart(static_cast<App::Part*>(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<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());
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
|
||||
@@ -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<TopoDS_Wire> 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;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#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,11 +255,17 @@ void CmdTechDrawNewView::activated(int iMsg)
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
|
||||
if (shapes.empty()) {
|
||||
std::vector<App::DocumentObject*> 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<TechDraw::DrawViewPart*>(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<App::DocumentObject*> 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<App::DocumentObject*> 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<App::DocumentObject*>& shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
|
||||
if (shapes.empty()) {
|
||||
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())) {
|
||||
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<App::DocumentObject*> 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
|
||||
//===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user