From a6431ee5cf007e7996bedf8e78b62c121049ca32 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Mon, 6 May 2013 11:39:53 +0430 Subject: [PATCH] Improved bounding box calculation for datum feature display size --- src/App/Plane.cpp | 4 +++ src/App/Plane.h | 3 ++ src/Gui/ViewProviderPlane.cpp | 2 +- src/Mod/PartDesign/App/Body.cpp | 36 +++++++++++++++++++ src/Mod/PartDesign/App/Body.h | 5 ++- .../PartDesign/Gui/ViewProviderDatumLine.cpp | 5 +-- .../PartDesign/Gui/ViewProviderDatumPlane.cpp | 8 ++--- 7 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/App/Plane.cpp b/src/App/Plane.cpp index 4e4ba42b5..c5d495b8b 100644 --- a/src/App/Plane.cpp +++ b/src/App/Plane.cpp @@ -48,6 +48,10 @@ Plane::~Plane(void) { } +Base::BoundBox3d Plane::getBoundBox() +{ + return Base::BoundBox3d(-10, -10, -10, 10, 10, 10); +} diff --git a/src/App/Plane.h b/src/App/Plane.h index 33a1d5e7f..51599054f 100644 --- a/src/App/Plane.h +++ b/src/App/Plane.h @@ -53,6 +53,9 @@ public: virtual const char* getViewProviderName(void) const { return "Gui::ViewProviderPlane"; } + + /// Return the bounding box of the plane (this is always a fixed size) + static Base::BoundBox3d getBoundBox(); }; diff --git a/src/Gui/ViewProviderPlane.cpp b/src/Gui/ViewProviderPlane.cpp index 979469d19..40f5672f3 100644 --- a/src/Gui/ViewProviderPlane.cpp +++ b/src/Gui/ViewProviderPlane.cpp @@ -68,7 +68,7 @@ ViewProviderPlane::ViewProviderPlane() pMat = new SoMaterial(); pMat->ref(); - const float size = 2; + const float size = 10; // Note: If you change this, you need to also adapt App/Plane.cpp getBoundBox() static const SbVec3f verts[4] = { diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index 5ed05e42b..d1a06fc4d 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -25,12 +25,16 @@ #ifndef _PreComp_ #endif +#include #include #include "Feature.h" #include "Body.h" #include "BodyPy.h" #include "FeatureSketchBased.h" +#include "DatumPoint.h" +#include "DatumLine.h" +#include "DatumPlane.h" #include #include @@ -316,6 +320,38 @@ App::DocumentObjectExecReturn *Body::execute(void) return App::DocumentObject::StdReturn; } +Base::BoundBox3d Body::getBoundBox() +{ + Base::BoundBox3d result; + + Part::Feature* tipSolid = static_cast(getPrevSolidFeature()); + if (tipSolid != NULL) { + result = tipSolid->Shape.getShape().getBoundBox(); + } else { + result = App::Plane::getBoundBox(); + } + + std::vector model = Model.getValues(); + // TODO: In DatumLine and DatumPlane, recalculate the Base point to be as near as possible to the origin (0,0,0) + for (std::vector::const_iterator m = model.begin(); m != model.end(); m++) { + if ((*m)->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) { + PartDesign::Point* point = static_cast(*m); + result.Add(point->_Point.getValue()); + } else if ((*m)->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) { + PartDesign::Line* line = static_cast(*m); + result.Add(line->_Base.getValue()); + } else if ((*m)->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { + PartDesign::Plane* plane = static_cast(*m); + result.Add(plane->_Base.getValue()); + } else if ((*m)->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { + // Note: We only take into account the base planes here + result.Add(Base::Vector3d(0,0,0)); + } + } + + return result; +} + PyObject *Body::getPyObject(void) { if (PythonObject.is(Py::_None())){ diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index 909b92808..dd07b0459 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -95,7 +95,10 @@ public: * Return true if the given feature is allowed in a Body. Currently allowed are * all features derived from PartDesign::Feature and Part::Datum and sketches */ - static const bool isAllowed(const App::DocumentObject* f); + static const bool isAllowed(const App::DocumentObject* f); + + /// Return the bounding box of the Tip Shape, taking into account datum features + Base::BoundBox3d getBoundBox(); PyObject *getPyObject(void); diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp index 76b9be4ae..d490c0459 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp @@ -85,10 +85,7 @@ void ViewProviderDatumLine::updateData(const App::Property* prop) PartDesign::Body* body = static_cast(Part::BodyBase::findBodyOf(this->getObject())); if (body == NULL) return; - Part::Feature* tipSolid = static_cast(body->getPrevSolidFeature()); - if (tipSolid == NULL) - return; - Base::BoundBox3d bbox = tipSolid->Shape.getShape().getBoundBox(); + Base::BoundBox3d bbox = body->getBoundBox(); bbox.Enlarge(0.1 * bbox.CalcDiagonalLength()); Base::Vector3d p1, p2; if (bbox.IsInBox(base)) { diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp index 44af8dddf..97ddf1997 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp @@ -85,11 +85,9 @@ void ViewProviderDatumPlane::updateData(const App::Property* prop) PartDesign::Body* body = static_cast(Part::BodyBase::findBodyOf(this->getObject())); if (body == NULL) return; - Part::Feature* tipSolid = static_cast(body->getPrevSolidFeature()); - if (tipSolid == NULL) - return; - Base::BoundBox3d bbox = tipSolid->Shape.getShape().getBoundBox(); - bbox.Enlarge(0.1 * bbox.CalcDiagonalLength()); + Base::BoundBox3d bbox = body->getBoundBox(); + double dlength = bbox.CalcDiagonalLength(); + bbox.Enlarge(0.1 * dlength); // Calculate intersection of plane with bounding box edges // TODO: This can be a lot more efficient if we do the maths ourselves, e.g.