Allow Section based on ViewMulti
This commit is contained in:
committed by
Yorik van Havre
parent
8193455890
commit
ce7f6ed351
@@ -88,13 +88,13 @@ public:
|
||||
boost::signal<void (const DrawView*)> signalGuiPaint;
|
||||
virtual double getScale(void) const;
|
||||
void checkScale(void);
|
||||
void requestPaint(void);
|
||||
|
||||
protected:
|
||||
void onChanged(const App::Property* prop) override;
|
||||
std::string pageFeatName;
|
||||
bool autoPos;
|
||||
bool mouseMove;
|
||||
void requestPaint(void);
|
||||
|
||||
private:
|
||||
static const char* ScaleTypeEnums[];
|
||||
|
||||
@@ -116,6 +116,33 @@ 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())){
|
||||
continue; //not a part
|
||||
}
|
||||
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);
|
||||
}
|
||||
result = comp;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *DrawViewMulti::execute(void)
|
||||
{
|
||||
if (!keepUpdated()) {
|
||||
@@ -128,29 +155,17 @@ App::DocumentObjectExecReturn *DrawViewMulti::execute(void)
|
||||
return DrawViewPart::execute();
|
||||
}
|
||||
|
||||
//Base::Console().Message("TRACE - DVM::execute() - %s/%s\n",getNameInDocument(),Label.getValue());
|
||||
|
||||
BRep_Builder builder;
|
||||
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
|
||||
}
|
||||
BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape());
|
||||
TopoDS_Shape shape = BuilderCopy.Shape();
|
||||
builder.Add(comp, shape);
|
||||
m_compound = TopoDS::Compound(getSourceShape());
|
||||
if (m_compound.IsNull()) {
|
||||
return new App::DocumentObjectExecReturn("DVP - Linked shape object(s) is invalid");
|
||||
}
|
||||
m_compound = comp;
|
||||
TopoDS_Compound comp = m_compound;
|
||||
|
||||
gp_Pnt inputCenter;
|
||||
try {
|
||||
inputCenter = TechDrawGeometry::findCentroid(comp,
|
||||
Direction.getValue());
|
||||
shapeCentroid = Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z());
|
||||
TopoDS_Shape mirroredShape = TechDrawGeometry::mirrorShape(comp,
|
||||
inputCenter,
|
||||
getScale());
|
||||
|
||||
@@ -67,6 +67,8 @@ public:
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
//@}
|
||||
|
||||
virtual TopoDS_Shape getSourceShape(void) const override;
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
return "TechDrawGui::ViewProviderViewPart";
|
||||
|
||||
@@ -152,24 +152,40 @@ DrawViewPart::~DrawViewPart()
|
||||
delete geometryObject;
|
||||
}
|
||||
|
||||
//does this need all the validation logic?
|
||||
//how to
|
||||
TopoDS_Shape DrawViewPart::getSourceShape(void) const
|
||||
{
|
||||
TopoDS_Shape result;
|
||||
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 {
|
||||
result = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *DrawViewPart::execute(void)
|
||||
{
|
||||
if (!keepUpdated()) {
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
App::DocumentObject *link = Source.getValue();
|
||||
if (!link) {
|
||||
return new App::DocumentObjectExecReturn("DVP - No Source object linked");
|
||||
}
|
||||
// App::DocumentObject *link = Source.getValue();
|
||||
// if (!link) {
|
||||
// return new App::DocumentObjectExecReturn("DVP - No Source object linked");
|
||||
// }
|
||||
|
||||
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
return new App::DocumentObjectExecReturn("DVP - Linked object is not a Part object");
|
||||
}
|
||||
// if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
// return new App::DocumentObjectExecReturn("DVP - Linked object is not a Part object");
|
||||
// }
|
||||
|
||||
TopoDS_Shape shape = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();
|
||||
TopoDS_Shape shape = getSourceShape();
|
||||
// TopoDS_Shape shape = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();
|
||||
if (shape.IsNull()) {
|
||||
return new App::DocumentObjectExecReturn("DVP - Linked shape object is empty");
|
||||
return new App::DocumentObjectExecReturn("DVP - Linked shape object is invalid");
|
||||
}
|
||||
|
||||
gp_Pnt inputCenter;
|
||||
@@ -204,6 +220,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
|
||||
|
||||
// Base::Console().Message("TRACE _ DVP::exec - %s/%s u: %s v: %s w: %s\n",getNameInDocument(),Label.getValue(),
|
||||
// DrawUtil::formatVector(getUDir()).c_str(), DrawUtil::formatVector(getVDir()).c_str(),DrawUtil::formatVector(getWDir()).c_str());
|
||||
Base::Console().Message("TRACE - DVP::execute - requesting paint\n");
|
||||
requestPaint();
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
@@ -234,6 +251,7 @@ void DrawViewPart::onChanged(const App::Property* prop)
|
||||
//note: slightly different than routine with same name in DrawProjectSplit
|
||||
TechDrawGeometry::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape, gp_Ax2 viewAxis)
|
||||
{
|
||||
Base::Console().Message("TRACE - DVP::buildGO - shape.IsNull: %d\n",shape.IsNull());
|
||||
TechDrawGeometry::GeometryObject* go = new TechDrawGeometry::GeometryObject(getNameInDocument(), this);
|
||||
go->setIsoCount(IsoCount.getValue());
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class gp_Ax2;
|
||||
//class TopoDS_Edge;
|
||||
//class TopoDS_Vertex;
|
||||
//class TopoDS_Wire;
|
||||
//class TopoDS_Shape;
|
||||
class TopoDS_Shape;
|
||||
|
||||
namespace TechDrawGeometry
|
||||
{
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
const Base::Vector3d& getUDir(void) const {return uDir;} //paperspace X
|
||||
const Base::Vector3d& getVDir(void) const {return vDir;} //paperspace Y
|
||||
const Base::Vector3d& getWDir(void) const {return wDir;} //paperspace Z
|
||||
const Base::Vector3d& getCentroid(void) const {return shapeCentroid;}
|
||||
virtual const Base::Vector3d& getCentroid(void) const {return shapeCentroid;}
|
||||
Base::Vector3d projectPoint(const Base::Vector3d& pt) const;
|
||||
virtual gp_Ax2 getViewAxis(const Base::Vector3d& pt,
|
||||
const Base::Vector3d& direction,
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
|
||||
gp_Pln getProjPlane(void) const;
|
||||
virtual std::vector<TopoDS_Wire> getWireForFace(int idx) const;
|
||||
|
||||
virtual TopoDS_Shape getSourceShape(void) const;
|
||||
|
||||
protected:
|
||||
TechDrawGeometry::GeometryObject *geometryObject;
|
||||
|
||||
@@ -154,7 +154,6 @@ short DrawViewSection::mustExecute() const
|
||||
void DrawViewSection::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (!isRestoring()) {
|
||||
//Base::Console().Message("TRACE - DVS::onChanged(%s) - %s\n",prop->getName(),Label.getValue());
|
||||
if (prop == &SectionSymbol) {
|
||||
std::string lblText = "Section " +
|
||||
std::string(SectionSymbol.getValue()) +
|
||||
@@ -164,8 +163,9 @@ void DrawViewSection::onChanged(const App::Property* prop)
|
||||
}
|
||||
if (prop == &SectionOrigin) {
|
||||
App::DocumentObject* base = BaseView.getValue();
|
||||
if (base != nullptr) {
|
||||
base->touch();
|
||||
TechDraw::DrawView* dv = dynamic_cast<TechDraw::DrawView*>(base);
|
||||
if (dv != nullptr) {
|
||||
dv->requestPaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,60 +195,60 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
App::DocumentObject* link = Source.getValue();
|
||||
App::DocumentObject* base = BaseView.getValue();
|
||||
if (!link || !base) {
|
||||
Base::Console().Log("INFO - DVS::execute - No Source or Link - creation?\n");
|
||||
return DrawView::execute();
|
||||
}
|
||||
|
||||
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
return new App::DocumentObjectExecReturn("Source object is not a Part object");
|
||||
if (!base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()))
|
||||
return new App::DocumentObjectExecReturn("BaseView object is not a DrawViewPart object");
|
||||
|
||||
//Base::Console().Message("TRACE - DVS::execute() - %s/%s\n",getNameInDocument(),Label.getValue());
|
||||
TopoDS_Shape baseShape = static_cast<TechDraw::DrawViewPart*>(base)->getSourceShape();
|
||||
if (baseShape.IsNull()) {
|
||||
Base::Console().Log("DVS::execute - baseShape is Null\n");
|
||||
}
|
||||
|
||||
const Part::TopoShape &partTopo = static_cast<Part::Feature*>(link)->Shape.getShape();
|
||||
|
||||
if (partTopo.getShape().IsNull())
|
||||
return new App::DocumentObjectExecReturn("Linked shape object is empty");
|
||||
//is SectionOrigin valid?
|
||||
Bnd_Box centerBox;
|
||||
BRepBndLib::Add(baseShape, centerBox);
|
||||
centerBox.SetGap(0.0);
|
||||
|
||||
gp_Pln pln = getSectionPlane();
|
||||
gp_Dir gpNormal = pln.Axis().Direction();
|
||||
Base::Vector3d orgPnt = SectionOrigin.getValue();
|
||||
|
||||
Base::BoundBox3d bb = partTopo.getBoundBox();
|
||||
if(!isReallyInBox(orgPnt, bb)) {
|
||||
Base::Console().Warning("DVS: Section Plane doesn't intersect part in %s\n",getNameInDocument());
|
||||
if(!isReallyInBox(gp_Pnt(orgPnt.x,orgPnt.y,orgPnt.z), centerBox)) {
|
||||
Base::Console().Warning("DVS: SectionOrigin doesn't intersect part in %s\n",getNameInDocument());
|
||||
Base::Console().Warning("DVS: Using center of bounding box.\n");
|
||||
orgPnt = bb.GetCenter();
|
||||
double Xmin,Ymin,Zmin,Xmax,Ymax,Zmax;
|
||||
centerBox.Get(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
|
||||
orgPnt = Base::Vector3d((Xmax + Xmin)/2.0,
|
||||
(Ymax + Ymin)/2.0,
|
||||
(Zmax + Zmin)/2.0);
|
||||
SectionOrigin.setValue(orgPnt);
|
||||
}
|
||||
|
||||
// Make the extrusion face
|
||||
double dMax = bb.CalcDiagonalLength();
|
||||
double dMax = sqrt(centerBox.SquareExtent());
|
||||
BRepBuilderAPI_MakeFace mkFace(pln, -dMax,dMax,-dMax,dMax);
|
||||
TopoDS_Face aProjFace = mkFace.Face();
|
||||
if(aProjFace.IsNull())
|
||||
if(aProjFace.IsNull()) {
|
||||
return new App::DocumentObjectExecReturn("DrawViewSection - Projected face is NULL");
|
||||
}
|
||||
gp_Vec extrudeDir = dMax * gp_Vec(gpNormal);
|
||||
TopoDS_Shape prism = BRepPrimAPI_MakePrism(aProjFace, extrudeDir, false, true).Shape();
|
||||
|
||||
// We need to copy the shape to not modify the BRepstructure
|
||||
BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape());
|
||||
BRepBuilderAPI_Copy BuilderCopy(baseShape);
|
||||
TopoDS_Shape myShape = BuilderCopy.Shape();
|
||||
|
||||
BRepAlgoAPI_Cut mkCut(myShape, prism);
|
||||
if (!mkCut.IsDone())
|
||||
if (!mkCut.IsDone()) {
|
||||
return new App::DocumentObjectExecReturn("Section cut has failed");
|
||||
}
|
||||
|
||||
TopoDS_Shape rawShape = mkCut.Shape();
|
||||
Bnd_Box testBox;
|
||||
BRepBndLib::Add(rawShape, testBox);
|
||||
testBox.SetGap(0.0);
|
||||
if (testBox.IsVoid()) { //prism & input don't intersect. rawShape is garbage, don't bother.
|
||||
Base::Console().Log("INFO - DVS::execute - prism & input don't intersect\n");
|
||||
Base::Console().Message("INFO - DVS::execute - prism & input don't intersect\n");
|
||||
return DrawView::execute();
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shap
|
||||
{
|
||||
TopoDS_Compound result;
|
||||
if(shape.IsNull()){
|
||||
Base::Console().Log("DrawViewSection::getSectionSurface - Sectional View shape is Empty\n");
|
||||
Base::Console().Warning("DrawViewSection::getSectionSurface - Sectional View shape is Empty\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -473,6 +473,8 @@ TopoDS_Face DrawViewSection::projectFace(const TopoDS_Shape &face,
|
||||
}
|
||||
|
||||
//this should really be in BoundBox.h
|
||||
//!check if point is in box or on boundary of box
|
||||
//!compare to isInBox which doesn't allow on boundary
|
||||
bool DrawViewSection::isReallyInBox (const Base::Vector3d v, const Base::BoundBox3d bb) const
|
||||
{
|
||||
if (v.x <= bb.MinX || v.x >= bb.MaxX)
|
||||
@@ -484,6 +486,11 @@ bool DrawViewSection::isReallyInBox (const Base::Vector3d v, const Base::BoundBo
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DrawViewSection::isReallyInBox (const gp_Pnt p, const Bnd_Box& bb) const
|
||||
{
|
||||
return !bb.IsOut(p);
|
||||
}
|
||||
|
||||
//! calculate the section Normal/Projection Direction given baseView projection direction and section name
|
||||
Base::Vector3d DrawViewSection::getSectionVector (const std::string sectionName)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
|
||||
#include "DrawViewPart.h"
|
||||
|
||||
class Bnd_Box;
|
||||
class gp_Pln;
|
||||
class gp_Pnt;
|
||||
class TopoDS_Face;
|
||||
|
||||
namespace TechDrawGeometry
|
||||
@@ -68,7 +70,9 @@ public:
|
||||
App::PropertyString SectionSymbol;
|
||||
|
||||
virtual short mustExecute() const;
|
||||
|
||||
bool isReallyInBox (const Base::Vector3d v, const Base::BoundBox3d bb) const;
|
||||
bool isReallyInBox (const gp_Pnt p, const Bnd_Box& bb) const;
|
||||
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
|
||||
@@ -163,7 +163,6 @@ void TaskSectionView::updateValues()
|
||||
m_section->SectionOrigin.setValue(origin);
|
||||
m_section->SectionSymbol.setValue(ui->leSymbol->text().toUtf8().constData());
|
||||
|
||||
m_base->touch();
|
||||
m_base->getDocument()->recompute();
|
||||
}
|
||||
|
||||
@@ -302,8 +301,7 @@ bool TaskSectionView::reject()
|
||||
PageName.c_str(),SectionName.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().removeObject('%s')",SectionName.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
||||
m_base->touch();
|
||||
m_base->getDocument()->recompute();
|
||||
m_base->findParentPage()->requestPaint();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user