From ce7f6ed35198d5810126ab54dd5fa066072e7563 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Sat, 16 Sep 2017 09:57:37 -0400 Subject: [PATCH] Allow Section based on ViewMulti --- src/Mod/TechDraw/App/DrawView.h | 2 +- src/Mod/TechDraw/App/DrawViewMulti.cpp | 49 +++++++++++++------- src/Mod/TechDraw/App/DrawViewMulti.h | 2 + src/Mod/TechDraw/App/DrawViewPart.cpp | 36 +++++++++++---- src/Mod/TechDraw/App/DrawViewPart.h | 6 +-- src/Mod/TechDraw/App/DrawViewSection.cpp | 59 +++++++++++++----------- src/Mod/TechDraw/App/DrawViewSection.h | 4 ++ src/Mod/TechDraw/Gui/TaskSectionView.cpp | 4 +- 8 files changed, 103 insertions(+), 59 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawView.h b/src/Mod/TechDraw/App/DrawView.h index 6f56ca8657..7b32ab8cd1 100644 --- a/src/Mod/TechDraw/App/DrawView.h +++ b/src/Mod/TechDraw/App/DrawView.h @@ -88,13 +88,13 @@ public: boost::signal 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[]; diff --git a/src/Mod/TechDraw/App/DrawViewMulti.cpp b/src/Mod/TechDraw/App/DrawViewMulti.cpp index 13375ecd51..09ce493b41 100644 --- a/src/Mod/TechDraw/App/DrawViewMulti.cpp +++ b/src/Mod/TechDraw/App/DrawViewMulti.cpp @@ -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& 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(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(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()); diff --git a/src/Mod/TechDraw/App/DrawViewMulti.h b/src/Mod/TechDraw/App/DrawViewMulti.h index 481026af63..b8c549dab0 100644 --- a/src/Mod/TechDraw/App/DrawViewMulti.h +++ b/src/Mod/TechDraw/App/DrawViewMulti.h @@ -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"; diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 0adbaf30a4..432167e60b 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -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(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(link)->Shape.getShape().getShape(); + TopoDS_Shape shape = getSourceShape(); +// TopoDS_Shape shape = static_cast(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()); diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index cb974abab3..356837ea1a 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -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 getWireForFace(int idx) const; - + virtual TopoDS_Shape getSourceShape(void) const; protected: TechDrawGeometry::GeometryObject *geometryObject; diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 3ff987726a..dddf990f1b 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -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(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(base)->getSourceShape(); + if (baseShape.IsNull()) { + Base::Console().Log("DVS::execute - baseShape is Null\n"); + } - const Part::TopoShape &partTopo = static_cast(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) { diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index 288a868658..66efda6a81 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -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); diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index 61d84f813a..5450e8f16e 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -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; }