Improved bounding box calculation for datum feature display size
This commit is contained in:
parent
02dfb8551d
commit
a6431ee5cf
|
@ -48,6 +48,10 @@ Plane::~Plane(void)
|
|||
{
|
||||
}
|
||||
|
||||
Base::BoundBox3d Plane::getBoundBox()
|
||||
{
|
||||
return Base::BoundBox3d(-10, -10, -10, 10, 10, 10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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] =
|
||||
{
|
||||
|
|
|
@ -25,12 +25,16 @@
|
|||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
#include <App/Plane.h>
|
||||
#include <Base/Placement.h>
|
||||
|
||||
#include "Feature.h"
|
||||
#include "Body.h"
|
||||
#include "BodyPy.h"
|
||||
#include "FeatureSketchBased.h"
|
||||
#include "DatumPoint.h"
|
||||
#include "DatumLine.h"
|
||||
#include "DatumPlane.h"
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
|
@ -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<Part::Feature*>(getPrevSolidFeature());
|
||||
if (tipSolid != NULL) {
|
||||
result = tipSolid->Shape.getShape().getBoundBox();
|
||||
} else {
|
||||
result = App::Plane::getBoundBox();
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> 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<App::DocumentObject*>::const_iterator m = model.begin(); m != model.end(); m++) {
|
||||
if ((*m)->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) {
|
||||
PartDesign::Point* point = static_cast<PartDesign::Point*>(*m);
|
||||
result.Add(point->_Point.getValue());
|
||||
} else if ((*m)->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
|
||||
PartDesign::Line* line = static_cast<PartDesign::Line*>(*m);
|
||||
result.Add(line->_Base.getValue());
|
||||
} else if ((*m)->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
|
||||
PartDesign::Plane* plane = static_cast<PartDesign::Plane*>(*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())){
|
||||
|
|
|
@ -97,6 +97,9 @@ public:
|
|||
*/
|
||||
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);
|
||||
|
||||
private:
|
||||
|
|
|
@ -85,10 +85,7 @@ void ViewProviderDatumLine::updateData(const App::Property* prop)
|
|||
PartDesign::Body* body = static_cast<PartDesign::Body*>(Part::BodyBase::findBodyOf(this->getObject()));
|
||||
if (body == NULL)
|
||||
return;
|
||||
Part::Feature* tipSolid = static_cast<Part::Feature*>(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)) {
|
||||
|
|
|
@ -85,11 +85,9 @@ void ViewProviderDatumPlane::updateData(const App::Property* prop)
|
|||
PartDesign::Body* body = static_cast<PartDesign::Body*>(Part::BodyBase::findBodyOf(this->getObject()));
|
||||
if (body == NULL)
|
||||
return;
|
||||
Part::Feature* tipSolid = static_cast<Part::Feature*>(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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user