[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
@@ -22,21 +22,21 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <BRepAdaptor_Curve.hxx>
|
||||
# include <BRepAdaptor_Surface.hxx>
|
||||
# include <BRepExtrema_DistShapeShape.hxx>
|
||||
# include <BRepGProp.hxx>
|
||||
# include <GCPnts_AbscissaPoint.hxx>
|
||||
# include <gp_Pln.hxx>
|
||||
# include <gp_Circ.hxx>
|
||||
# include <gp_Torus.hxx>
|
||||
# include <gp_Cylinder.hxx>
|
||||
# include <gp_Sphere.hxx>
|
||||
# include <gp_Lin.hxx>
|
||||
# include <GProp_GProps.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
# include <TopoDS_Shape.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <BRepExtrema_DistShapeShape.hxx>
|
||||
#include <BRepGProp.hxx>
|
||||
#include <GCPnts_AbscissaPoint.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <gp_Circ.hxx>
|
||||
#include <gp_Torus.hxx>
|
||||
#include <gp_Cylinder.hxx>
|
||||
#include <gp_Sphere.hxx>
|
||||
#include <gp_Lin.hxx>
|
||||
#include <GProp_GProps.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
using namespace Measure;
|
||||
@@ -80,31 +80,31 @@ bool Measurement::has3DReferences()
|
||||
return (References3D.getSize() > 0);
|
||||
}
|
||||
|
||||
//add a 3D reference (obj+sub) to end of list
|
||||
int Measurement::addReference3D(App::DocumentObject *obj, const std::string& subName)
|
||||
// add a 3D reference (obj+sub) to end of list
|
||||
int Measurement::addReference3D(App::DocumentObject* obj, const std::string& subName)
|
||||
{
|
||||
return addReference3D(obj,subName.c_str());
|
||||
return addReference3D(obj, subName.c_str());
|
||||
}
|
||||
|
||||
///add a 3D reference (obj+sub) to end of list
|
||||
int Measurement::addReference3D(App::DocumentObject *obj, const char* subName)
|
||||
/// add a 3D reference (obj+sub) to end of list
|
||||
int Measurement::addReference3D(App::DocumentObject* obj, const char* subName)
|
||||
{
|
||||
std::vector<App::DocumentObject*> objects = References3D.getValues();
|
||||
std::vector<std::string> subElements = References3D.getSubValues();
|
||||
std::vector<App::DocumentObject*> objects = References3D.getValues();
|
||||
std::vector<std::string> subElements = References3D.getSubValues();
|
||||
|
||||
objects.push_back(obj);
|
||||
subElements.emplace_back(subName);
|
||||
objects.push_back(obj);
|
||||
subElements.emplace_back(subName);
|
||||
|
||||
References3D.setValues(objects, subElements);
|
||||
References3D.setValues(objects, subElements);
|
||||
|
||||
measureType = findType();
|
||||
return References3D.getSize();
|
||||
measureType = findType();
|
||||
return References3D.getSize();
|
||||
}
|
||||
|
||||
MeasureType Measurement::findType()
|
||||
{
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
|
||||
std::vector<App::DocumentObject*>::const_iterator obj = objects.begin();
|
||||
std::vector<std::string>::const_iterator subEl = subElements.begin();
|
||||
@@ -123,18 +123,18 @@ MeasureType Measurement::findType()
|
||||
int spheres = 0;
|
||||
int vols = 0;
|
||||
|
||||
for (;obj != objects.end(); ++obj, ++subEl) {
|
||||
for (; obj != objects.end(); ++obj, ++subEl) {
|
||||
|
||||
// Check if solid object
|
||||
if(strcmp((*subEl).c_str(), "") == 0) {
|
||||
if (strcmp((*subEl).c_str(), "") == 0) {
|
||||
vols++;
|
||||
}
|
||||
else {
|
||||
|
||||
TopoDS_Shape refSubShape;
|
||||
try {
|
||||
refSubShape = Part::Feature::getShape(*obj,(*subEl).c_str(),true);
|
||||
if(refSubShape.IsNull()){
|
||||
refSubShape = Part::Feature::getShape(*obj, (*subEl).c_str(), true);
|
||||
if (refSubShape.IsNull()) {
|
||||
return MeasureType::Invalid;
|
||||
}
|
||||
}
|
||||
@@ -146,13 +146,10 @@ MeasureType Measurement::findType()
|
||||
}
|
||||
|
||||
switch (refSubShape.ShapeType()) {
|
||||
case TopAbs_VERTEX:
|
||||
{
|
||||
case TopAbs_VERTEX: {
|
||||
verts++;
|
||||
}
|
||||
break;
|
||||
case TopAbs_EDGE:
|
||||
{
|
||||
} break;
|
||||
case TopAbs_EDGE: {
|
||||
edges++;
|
||||
TopoDS_Edge edge = TopoDS::Edge(refSubShape);
|
||||
BRepAdaptor_Curve sf(edge);
|
||||
@@ -163,10 +160,8 @@ MeasureType Measurement::findType()
|
||||
else if (sf.GetType() == GeomAbs_Circle) {
|
||||
circles++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TopAbs_FACE:
|
||||
{
|
||||
} break;
|
||||
case TopAbs_FACE: {
|
||||
faces++;
|
||||
TopoDS_Face face = TopoDS::Face(refSubShape);
|
||||
BRepAdaptor_Surface sf(face);
|
||||
@@ -186,24 +181,23 @@ MeasureType Measurement::findType()
|
||||
else if (sf.GetType() == GeomAbs_Torus) {
|
||||
torus++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(vols > 0) {
|
||||
if(verts > 0 || edges > 0 || faces > 0) {
|
||||
if (vols > 0) {
|
||||
if (verts > 0 || edges > 0 || faces > 0) {
|
||||
mode = MeasureType::Invalid;
|
||||
}
|
||||
else {
|
||||
mode = MeasureType::Volumes;
|
||||
}
|
||||
}
|
||||
else if(faces > 0) {
|
||||
if(verts > 0 || edges > 0) {
|
||||
else if (faces > 0) {
|
||||
if (verts > 0 || edges > 0) {
|
||||
if (faces == 1 && verts == 1) {
|
||||
mode = MeasureType::PointToSurface;
|
||||
}
|
||||
@@ -240,9 +234,9 @@ MeasureType Measurement::findType()
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(edges > 0) {
|
||||
if(verts > 0) {
|
||||
if(verts > 1 && edges > 0) {
|
||||
else if (edges > 0) {
|
||||
if (verts > 0) {
|
||||
if (verts > 1 && edges > 0) {
|
||||
mode = MeasureType::Invalid;
|
||||
}
|
||||
else {
|
||||
@@ -287,11 +281,11 @@ MeasureType Measurement::getType()
|
||||
return measureType;
|
||||
}
|
||||
|
||||
TopoDS_Shape Measurement::getShape(App::DocumentObject *obj , const char *subName) const
|
||||
TopoDS_Shape Measurement::getShape(App::DocumentObject* obj, const char* subName) const
|
||||
{
|
||||
//temporary fix to get "Vertex7" from "Body003.Pocket020.Vertex7"
|
||||
//when selected, Body features are provided as featureName and subNameAndIndex
|
||||
//other sources provide the full extended name with index
|
||||
// temporary fix to get "Vertex7" from "Body003.Pocket020.Vertex7"
|
||||
// when selected, Body features are provided as featureName and subNameAndIndex
|
||||
// other sources provide the full extended name with index
|
||||
if (strcmp(subName, "") == 0) {
|
||||
return Part::Feature::getShape(obj);
|
||||
}
|
||||
@@ -303,12 +297,12 @@ TopoDS_Shape Measurement::getShape(App::DocumentObject *obj , const char *subNam
|
||||
|
||||
try {
|
||||
Part::TopoShape partShape = Part::Feature::getTopoShape(obj);
|
||||
App::GeoFeature* geoFeat = dynamic_cast<App::GeoFeature*>(obj);
|
||||
App::GeoFeature* geoFeat = dynamic_cast<App::GeoFeature*>(obj);
|
||||
if (geoFeat) {
|
||||
partShape.setPlacement(geoFeat->globalPlacement());
|
||||
}
|
||||
TopoDS_Shape shape = partShape.getSubShape(workingSubName.c_str());
|
||||
if(shape.IsNull()) {
|
||||
if (shape.IsNull()) {
|
||||
throw Part::NullShapeException("null shape in measurement");
|
||||
}
|
||||
return shape;
|
||||
@@ -323,64 +317,63 @@ TopoDS_Shape Measurement::getShape(App::DocumentObject *obj , const char *subNam
|
||||
catch (...) {
|
||||
throw Base::RuntimeError("Measurement: Unknown error retrieving shape");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//TODO:: add lengthX, lengthY (and lengthZ??) support
|
||||
// Methods for distances (edge length, two points, edge and a point
|
||||
// TODO:: add lengthX, lengthY (and lengthZ??) support
|
||||
// Methods for distances (edge length, two points, edge and a point
|
||||
double Measurement::length() const
|
||||
{
|
||||
double result = 0.0;
|
||||
int numRefs = References3D.getSize();
|
||||
if(numRefs == 0) {
|
||||
if (numRefs == 0) {
|
||||
Base::Console().Error("Measurement::length - No 3D references available\n");
|
||||
}
|
||||
else if (measureType == MeasureType::Invalid) {
|
||||
Base::Console().Error("Measurement::length - measureType is Invalid\n");
|
||||
}
|
||||
else {
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
|
||||
if(measureType == MeasureType::Points ||
|
||||
measureType == MeasureType::PointToPoint ||
|
||||
measureType == MeasureType::PointToEdge ||
|
||||
measureType == MeasureType::PointToSurface) {
|
||||
if (measureType == MeasureType::Points || measureType == MeasureType::PointToPoint
|
||||
|| measureType == MeasureType::PointToEdge
|
||||
|| measureType == MeasureType::PointToSurface) {
|
||||
|
||||
Base::Vector3d diff = this->delta();
|
||||
result = diff.Length();
|
||||
}
|
||||
else if(measureType == MeasureType::Edges || measureType == MeasureType::Line
|
||||
|| measureType == MeasureType::TwoLines || measureType == MeasureType::Circle) {
|
||||
else if (measureType == MeasureType::Edges || measureType == MeasureType::Line
|
||||
|| measureType == MeasureType::TwoLines || measureType == MeasureType::Circle) {
|
||||
|
||||
// Iterate through edges and calculate each length
|
||||
std::vector<App::DocumentObject*>::const_iterator obj = objects.begin();
|
||||
std::vector<std::string>::const_iterator subEl = subElements.begin();
|
||||
|
||||
for (;obj != objects.end(); ++obj, ++subEl) {
|
||||
//const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
|
||||
//const Part::TopoShape& refShape = refObj->Shape.getShape();
|
||||
// Get the length of one edge
|
||||
for (; obj != objects.end(); ++obj, ++subEl) {
|
||||
// const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
|
||||
// const Part::TopoShape& refShape = refObj->Shape.getShape();
|
||||
// Get the length of one edge
|
||||
TopoDS_Shape shape = getShape(*obj, (*subEl).c_str());
|
||||
const TopoDS_Edge& edge = TopoDS::Edge(shape);
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
|
||||
switch(curve.GetType()) {
|
||||
case GeomAbs_Line : {
|
||||
switch (curve.GetType()) {
|
||||
case GeomAbs_Line: {
|
||||
gp_Pnt P1 = curve.Value(curve.FirstParameter());
|
||||
gp_Pnt P2 = curve.Value(curve.LastParameter());
|
||||
gp_XYZ diff = P2.XYZ() - P1.XYZ();
|
||||
result += diff.Modulus();
|
||||
break;
|
||||
}
|
||||
case GeomAbs_Circle : {
|
||||
case GeomAbs_Circle: {
|
||||
double u = curve.FirstParameter();
|
||||
double v = curve.LastParameter();
|
||||
double radius = curve.Circle().Radius();
|
||||
if (u > v) // if arc is reversed
|
||||
if (u > v) { // if arc is reversed
|
||||
std::swap(u, v);
|
||||
}
|
||||
|
||||
double range = v-u;
|
||||
double range = v - u;
|
||||
result += radius * range;
|
||||
break;
|
||||
}
|
||||
@@ -392,10 +385,11 @@ double Measurement::length() const
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw Base::RuntimeError("Measurement - length - Curve type not currently handled");
|
||||
throw Base::RuntimeError(
|
||||
"Measurement - length - Curve type not currently handled");
|
||||
}
|
||||
} //end switch
|
||||
} //end for
|
||||
} // end switch
|
||||
} // end for
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -403,8 +397,8 @@ double Measurement::length() const
|
||||
|
||||
double Measurement::lineLineDistance() const
|
||||
{
|
||||
// We don't use delta() because BRepExtrema_DistShapeShape return minimum length between line segment.
|
||||
// Here we get the nominal distance between the infinite lines.
|
||||
// We don't use delta() because BRepExtrema_DistShapeShape return minimum length between line
|
||||
// segment. Here we get the nominal distance between the infinite lines.
|
||||
double distance = 0.0;
|
||||
|
||||
if (measureType != MeasureType::TwoParallelLines || References3D.getSize() != 2) {
|
||||
@@ -452,7 +446,8 @@ double Measurement::lineLineDistance() const
|
||||
return distance;
|
||||
}
|
||||
|
||||
double Measurement::planePlaneDistance() const {
|
||||
double Measurement::planePlaneDistance() const
|
||||
{
|
||||
if (measureType != MeasureType::TwoPlanes || References3D.getSize() != 2) {
|
||||
return 0.0;
|
||||
}
|
||||
@@ -489,45 +484,44 @@ double Measurement::planePlaneDistance() const {
|
||||
return distance;
|
||||
}
|
||||
|
||||
double Measurement::angle(const Base::Vector3d & /*param*/) const
|
||||
double Measurement::angle(const Base::Vector3d& /*param*/) const
|
||||
{
|
||||
//TODO: do these references arrive as obj+sub pairs or as a struct of obj + [subs]?
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
// TODO: do these references arrive as obj+sub pairs or as a struct of obj + [subs]?
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
int numRefs = objects.size();
|
||||
if(numRefs == 0) {
|
||||
if (numRefs == 0) {
|
||||
throw Base::RuntimeError("No references available for angle measurement");
|
||||
}
|
||||
else if (measureType == MeasureType::Invalid) {
|
||||
throw Base::RuntimeError("MeasureType is Invalid for angle measurement");
|
||||
}
|
||||
else if(measureType == MeasureType::TwoLines) {
|
||||
//Only case that is supported is edge to edge
|
||||
//The angle between two skew lines is measured by the angle between one line (A)
|
||||
//and a line (B) with the direction of the second through a point on the first line.
|
||||
//Since we don't know if the directions of the lines point in the same general direction
|
||||
//we could get the angle we want or the supplementary angle.
|
||||
if(numRefs == 2) {
|
||||
else if (measureType == MeasureType::TwoLines) {
|
||||
// Only case that is supported is edge to edge
|
||||
// The angle between two skew lines is measured by the angle between one line (A)
|
||||
// and a line (B) with the direction of the second through a point on the first line.
|
||||
// Since we don't know if the directions of the lines point in the same general direction
|
||||
// we could get the angle we want or the supplementary angle.
|
||||
if (numRefs == 2) {
|
||||
TopoDS_Shape shape1 = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(1).c_str());
|
||||
|
||||
BRepAdaptor_Curve curve1(TopoDS::Edge(shape1));
|
||||
BRepAdaptor_Curve curve2(TopoDS::Edge(shape2));
|
||||
|
||||
if(curve1.GetType() == GeomAbs_Line &&
|
||||
curve2.GetType() == GeomAbs_Line) {
|
||||
if (curve1.GetType() == GeomAbs_Line && curve2.GetType() == GeomAbs_Line) {
|
||||
|
||||
gp_Pnt pnt1First = curve1.Value(curve1.FirstParameter());
|
||||
gp_Dir dir1 = curve1.Line().Direction();
|
||||
gp_Dir dir2 = curve2.Line().Direction();
|
||||
gp_Dir dir2r = curve2.Line().Direction().Reversed();
|
||||
|
||||
gp_Lin l1 = gp_Lin(pnt1First, dir1); // (A)
|
||||
gp_Lin l2 = gp_Lin(pnt1First, dir2); // (B)
|
||||
gp_Lin l1 = gp_Lin(pnt1First, dir1); // (A)
|
||||
gp_Lin l2 = gp_Lin(pnt1First, dir2); // (B)
|
||||
gp_Lin l2r = gp_Lin(pnt1First, dir2r); // (B')
|
||||
Standard_Real aRad = l1.Angle(l2);
|
||||
double aRadr = l1.Angle(l2r);
|
||||
return std::min(aRad, aRadr) * 180 / M_PI;
|
||||
return std::min(aRad, aRadr) * 180 / M_PI;
|
||||
}
|
||||
else {
|
||||
throw Base::RuntimeError("Measurement references must both be lines");
|
||||
@@ -538,15 +532,14 @@ double Measurement::angle(const Base::Vector3d & /*param*/) const
|
||||
}
|
||||
}
|
||||
else if (measureType == MeasureType::Points) {
|
||||
//NOTE: we are calculating the 3d angle here, not the projected angle
|
||||
//ASSUMPTION: the references are in end-apex-end order
|
||||
if(numRefs == 3) {
|
||||
// NOTE: we are calculating the 3d angle here, not the projected angle
|
||||
// ASSUMPTION: the references are in end-apex-end order
|
||||
if (numRefs == 3) {
|
||||
TopoDS_Shape shape0 = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Shape shape1 = getShape(objects.at(1), subElements.at(1).c_str());
|
||||
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(2).c_str());
|
||||
if (shape0.ShapeType() != TopAbs_VERTEX ||
|
||||
shape1.ShapeType() != TopAbs_VERTEX ||
|
||||
shape2.ShapeType() != TopAbs_VERTEX) {
|
||||
if (shape0.ShapeType() != TopAbs_VERTEX || shape1.ShapeType() != TopAbs_VERTEX
|
||||
|| shape2.ShapeType() != TopAbs_VERTEX) {
|
||||
throw Base::RuntimeError("Measurement references for 3 point angle are not Vertex");
|
||||
}
|
||||
gp_Pnt gEnd0 = BRep_Tool::Pnt(TopoDS::Vertex(shape0));
|
||||
@@ -557,7 +550,7 @@ double Measurement::angle(const Base::Vector3d & /*param*/) const
|
||||
gp_Lin line0 = gp_Lin(gEnd0, gDir0);
|
||||
gp_Lin line1 = gp_Lin(gEnd1, gDir1);
|
||||
double radians = line0.Angle(line1);
|
||||
return radians * 180 / M_PI;
|
||||
return radians * 180 / M_PI;
|
||||
}
|
||||
}
|
||||
throw Base::RuntimeError("Unexpected error for angle measurement");
|
||||
@@ -569,7 +562,7 @@ double Measurement::radius() const
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
|
||||
int numRefs = References3D.getSize();
|
||||
if(numRefs == 0) {
|
||||
if (numRefs == 0) {
|
||||
Base::Console().Error("Measurement::radius - No 3D references available\n");
|
||||
}
|
||||
else if (measureType == MeasureType::Circle) {
|
||||
@@ -577,11 +570,12 @@ double Measurement::radius() const
|
||||
const TopoDS_Edge& edge = TopoDS::Edge(shape);
|
||||
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
if(curve.GetType() == GeomAbs_Circle) {
|
||||
return (double) curve.Circle().Radius();
|
||||
if (curve.GetType() == GeomAbs_Circle) {
|
||||
return (double)curve.Circle().Radius();
|
||||
}
|
||||
}
|
||||
else if (measureType == MeasureType::Cylinder || measureType == MeasureType::Sphere || measureType == MeasureType::Torus) {
|
||||
else if (measureType == MeasureType::Cylinder || measureType == MeasureType::Sphere
|
||||
|| measureType == MeasureType::Torus) {
|
||||
TopoDS_Shape shape = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Face face = TopoDS::Face(shape);
|
||||
|
||||
@@ -603,7 +597,7 @@ double Measurement::radius() const
|
||||
Base::Vector3d Measurement::delta() const
|
||||
{
|
||||
Base::Vector3d result;
|
||||
int numRefs = References3D.getSize();
|
||||
int numRefs = References3D.getSize();
|
||||
if (numRefs == 0) {
|
||||
Base::Console().Error("Measurement::delta - No 3D references available\n");
|
||||
}
|
||||
@@ -611,11 +605,11 @@ Base::Vector3d Measurement::delta() const
|
||||
Base::Console().Error("Measurement::delta - measureType is Invalid\n");
|
||||
}
|
||||
else {
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
|
||||
if(measureType == MeasureType::PointToPoint) {
|
||||
if(numRefs == 2) {
|
||||
if (measureType == MeasureType::PointToPoint) {
|
||||
if (numRefs == 2) {
|
||||
// Keep separate case for two points to reduce need for complex algorithm
|
||||
TopoDS_Shape shape1 = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(1).c_str());
|
||||
@@ -629,17 +623,19 @@ Base::Vector3d Measurement::delta() const
|
||||
return Base::Vector3d(diff.X(), diff.Y(), diff.Z());
|
||||
}
|
||||
}
|
||||
else if(measureType == MeasureType::PointToEdge || measureType == MeasureType::PointToSurface) {
|
||||
else if (measureType == MeasureType::PointToEdge
|
||||
|| measureType == MeasureType::PointToSurface) {
|
||||
// BrepExtema can calculate minimum distance between any set of topology sets.
|
||||
if(numRefs == 2) {
|
||||
if (numRefs == 2) {
|
||||
TopoDS_Shape shape1 = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(1).c_str());
|
||||
|
||||
BRepExtrema_DistShapeShape extrema(shape1, shape2);
|
||||
|
||||
if(extrema.IsDone()) {
|
||||
if (extrema.IsDone()) {
|
||||
// Found the nearest point between point and curve
|
||||
// NOTE we will assume there is only 1 solution (cyclic topology will create multiple solutions.
|
||||
// NOTE we will assume there is only 1 solution (cyclic topology will create
|
||||
// multiple solutions.
|
||||
gp_Pnt P1 = extrema.PointOnShape1(1);
|
||||
gp_Pnt P2 = extrema.PointOnShape2(1);
|
||||
gp_XYZ diff = P2.XYZ() - P1.XYZ();
|
||||
@@ -647,21 +643,21 @@ Base::Vector3d Measurement::delta() const
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(measureType == MeasureType::Edges) {
|
||||
else if (measureType == MeasureType::Edges) {
|
||||
// Only case that is supported is straight line edge
|
||||
if(numRefs == 1) {
|
||||
if (numRefs == 1) {
|
||||
TopoDS_Shape shape = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
const TopoDS_Edge& edge = TopoDS::Edge(shape);
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
|
||||
if(curve.GetType() == GeomAbs_Line) {
|
||||
gp_Pnt P1 = curve.Value(curve.FirstParameter());
|
||||
gp_Pnt P2 = curve.Value(curve.LastParameter());
|
||||
gp_XYZ diff = P2.XYZ() - P1.XYZ();
|
||||
result = Base::Vector3d(diff.X(), diff.Y(), diff.Z());
|
||||
if (curve.GetType() == GeomAbs_Line) {
|
||||
gp_Pnt P1 = curve.Value(curve.FirstParameter());
|
||||
gp_Pnt P2 = curve.Value(curve.LastParameter());
|
||||
gp_XYZ diff = P2.XYZ() - P1.XYZ();
|
||||
result = Base::Vector3d(diff.X(), diff.Y(), diff.Z());
|
||||
}
|
||||
}
|
||||
else if(numRefs == 2) {
|
||||
else if (numRefs == 2) {
|
||||
TopoDS_Shape shape1 = getShape(objects.at(0), subElements.at(0).c_str());
|
||||
TopoDS_Shape shape2 = getShape(objects.at(1), subElements.at(1).c_str());
|
||||
|
||||
@@ -669,13 +665,13 @@ Base::Vector3d Measurement::delta() const
|
||||
BRepAdaptor_Curve curve2(TopoDS::Edge(shape2));
|
||||
|
||||
// Only permit line to line distance
|
||||
if(curve1.GetType() == GeomAbs_Line &&
|
||||
curve2.GetType() == GeomAbs_Line) {
|
||||
if (curve1.GetType() == GeomAbs_Line && curve2.GetType() == GeomAbs_Line) {
|
||||
BRepExtrema_DistShapeShape extrema(shape1, shape2);
|
||||
|
||||
if(extrema.IsDone()) {
|
||||
if (extrema.IsDone()) {
|
||||
// Found the nearest point between point and curve
|
||||
// NOTE we will assume there is only 1 solution (cyclic topology will create multiple solutions.
|
||||
// NOTE we will assume there is only 1 solution (cyclic topology will create
|
||||
// multiple solutions.
|
||||
gp_Pnt P1 = extrema.PointOnShape1(1);
|
||||
gp_Pnt P2 = extrema.PointOnShape2(1);
|
||||
gp_XYZ diff = P2.XYZ() - P1.XYZ();
|
||||
@@ -720,9 +716,9 @@ double Measurement::area() const
|
||||
Base::Console().Error("Measurement::area - No 3D references available\n");
|
||||
}
|
||||
else if (measureType == MeasureType::Volumes || measureType == MeasureType::Surfaces
|
||||
|| measureType == MeasureType::Cylinder || measureType == MeasureType::Cone
|
||||
|| measureType == MeasureType::Sphere || measureType == MeasureType::Torus
|
||||
|| measureType == MeasureType::Plane) {
|
||||
|| measureType == MeasureType::Cylinder || measureType == MeasureType::Cone
|
||||
|| measureType == MeasureType::Sphere || measureType == MeasureType::Torus
|
||||
|| measureType == MeasureType::Plane) {
|
||||
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
@@ -742,7 +738,7 @@ double Measurement::area() const
|
||||
Base::Vector3d Measurement::massCenter() const
|
||||
{
|
||||
Base::Vector3d result;
|
||||
int numRefs = References3D.getSize();
|
||||
int numRefs = References3D.getSize();
|
||||
if (numRefs == 0) {
|
||||
Base::Console().Error("Measurement::massCenter - No 3D references available\n");
|
||||
}
|
||||
@@ -750,18 +746,18 @@ Base::Vector3d Measurement::massCenter() const
|
||||
Base::Console().Error("Measurement::massCenter - measureType is Invalid\n");
|
||||
}
|
||||
else {
|
||||
const std::vector<App::DocumentObject*> &objects = References3D.getValues();
|
||||
const std::vector<std::string> &subElements = References3D.getSubValues();
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
GProp_GProps gprops = GProp_GProps();
|
||||
|
||||
if(measureType == MeasureType::Volumes) {
|
||||
if (measureType == MeasureType::Volumes) {
|
||||
// Iterate through edges and calculate each length
|
||||
std::vector<App::DocumentObject*>::const_iterator obj = objects.begin();
|
||||
std::vector<std::string>::const_iterator subEl = subElements.begin();
|
||||
|
||||
for (;obj != objects.end(); ++obj, ++subEl) {
|
||||
//const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
|
||||
//const Part::TopoShape& refShape = refObj->Shape.getShape();
|
||||
for (; obj != objects.end(); ++obj, ++subEl) {
|
||||
// const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
|
||||
// const Part::TopoShape& refShape = refObj->Shape.getShape();
|
||||
|
||||
// Compute inertia properties
|
||||
|
||||
@@ -771,20 +767,22 @@ Base::Vector3d Measurement::massCenter() const
|
||||
// Get inertia properties
|
||||
}
|
||||
|
||||
//double mass = gprops.Mass();
|
||||
// double mass = gprops.Mass();
|
||||
gp_Pnt cog = gprops.CentreOfMass();
|
||||
|
||||
return Base::Vector3d(cog.X(), cog.Y(), cog.Z());
|
||||
}
|
||||
else {
|
||||
Base::Console().Error("Measurement::massCenter - measureType is not recognized\n");
|
||||
// throw Base::ValueError("Measurement - massCenter - Invalid References3D Provided");
|
||||
// throw Base::ValueError("Measurement - massCenter - Invalid References3D
|
||||
// Provided");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Measurement::planesAreParallel() const {
|
||||
bool Measurement::planesAreParallel() const
|
||||
{
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
|
||||
@@ -827,7 +825,8 @@ bool Measurement::planesAreParallel() const {
|
||||
return normal1.IsParallel(normal2, Precision::Angular());
|
||||
}
|
||||
|
||||
bool Measurement::linesAreParallel() const {
|
||||
bool Measurement::linesAreParallel() const
|
||||
{
|
||||
const std::vector<App::DocumentObject*>& objects = References3D.getValues();
|
||||
const std::vector<std::string>& subElements = References3D.getSubValues();
|
||||
|
||||
@@ -866,11 +865,11 @@ unsigned int Measurement::getMemSize() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *Measurement::getPyObject()
|
||||
PyObject* Measurement::getPyObject()
|
||||
{
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
PythonObject = Py::Object(new MeasurementPy(this),true);
|
||||
PythonObject = Py::Object(new MeasurementPy(this), true);
|
||||
}
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user