Improve radius/diameter dims for ellipse,spline
This commit is contained in:
@@ -92,6 +92,7 @@ DrawView::~DrawView()
|
||||
|
||||
App::DocumentObjectExecReturn *DrawView::execute(void)
|
||||
{
|
||||
// Base::Console().Message("DV::execute() - %s\n", getNameInDocument());
|
||||
handleXYLock();
|
||||
requestPaint();
|
||||
return App::DocumentObject::execute();
|
||||
@@ -429,6 +430,7 @@ bool DrawView::keepUpdated(void)
|
||||
|
||||
void DrawView::requestPaint(void)
|
||||
{
|
||||
// Base::Console().Message("DV::requestPaint() - %s\n", getNameInDocument());
|
||||
signalGuiPaint(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,6 +238,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
|
||||
//now we can check if Reference2ds have valid targets.
|
||||
if (!checkReferences2D()) {
|
||||
Base::Console().Warning("%s has invalid 2D References\n", getNameInDocument());
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
@@ -282,6 +283,37 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
pts.onCurve.first = pts.center + Base::Vector3d(1,0,0) * circle->radius; //arbitrary point on edge
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * circle->radius; //arbitrary point on edge
|
||||
}
|
||||
} else if ((base && base->geomType == TechDrawGeometry::GeomType::ELLIPSE) ||
|
||||
(base && base->geomType == TechDrawGeometry::GeomType::ARCOFELLIPSE)) {
|
||||
TechDrawGeometry::Ellipse* ellipse = static_cast<TechDrawGeometry::Ellipse*> (base);
|
||||
if (ellipse->closed()) {
|
||||
double r1 = ellipse->minor;
|
||||
double r2 = ellipse->major;
|
||||
double rAvg = (r1 + r2) / 2.0;
|
||||
pts.center = Base::Vector3d(ellipse->center.x,
|
||||
ellipse->center.y,
|
||||
0.0);
|
||||
pts.radius = rAvg;
|
||||
pts.isArc = false;
|
||||
pts.onCurve.first = pts.center + Base::Vector3d(1,0,0) * rAvg; //arbitrary point on edge
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * rAvg; //arbitrary point on edge
|
||||
} else {
|
||||
TechDrawGeometry::AOE* aoe = static_cast<TechDrawGeometry::AOE*> (base);
|
||||
double r1 = aoe->minor;
|
||||
double r2 = aoe->major;
|
||||
double rAvg = (r1 + r2) / 2.0;
|
||||
pts.isArc = true;
|
||||
pts.center = Base::Vector3d(aoe->center.x,
|
||||
aoe->center.y,
|
||||
0.0);
|
||||
pts.radius = rAvg;
|
||||
pts.arcEnds.first = Base::Vector3d(aoe->startPnt.x,aoe->startPnt.y,0.0);
|
||||
pts.arcEnds.second = Base::Vector3d(aoe->endPnt.x,aoe->endPnt.y,0.0);
|
||||
pts.midArc = Base::Vector3d(aoe->midPnt.x,aoe->midPnt.y,0.0);
|
||||
pts.arcCW = aoe->cw;
|
||||
pts.onCurve.first = Base::Vector3d(aoe->midPnt.x,aoe->midPnt.y,0.0);
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * rAvg; //arbitrary point on edge
|
||||
}
|
||||
} else if (base && base->geomType == TechDrawGeometry::GeomType::BSPLINE) {
|
||||
TechDrawGeometry::BSpline* spline = static_cast<TechDrawGeometry::BSpline*> (base);
|
||||
if (spline->isCircle()) {
|
||||
@@ -303,7 +335,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * rad; //arbitrary point on edge
|
||||
}
|
||||
} else {
|
||||
//fubar - can't have non-circular spline as target of Diameter dimension
|
||||
//fubar - can't have non-circular spline as target of Radius dimension
|
||||
Base::Console().Error("Dimension %s refers to invalid BSpline\n",getNameInDocument());
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
@@ -338,6 +370,37 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
pts.onCurve.first = pts.center + Base::Vector3d(1,0,0) * circle->radius; //arbitrary point on edge
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * circle->radius; //arbitrary point on edge
|
||||
}
|
||||
} else if ( (base && base->geomType == TechDrawGeometry::GeomType::ELLIPSE) ||
|
||||
(base && base->geomType == TechDrawGeometry::GeomType::ARCOFELLIPSE) ) {
|
||||
TechDrawGeometry::Ellipse* ellipse = static_cast<TechDrawGeometry::Ellipse*> (base);
|
||||
if (ellipse->closed()) {
|
||||
double r1 = ellipse->minor;
|
||||
double r2 = ellipse->major;
|
||||
double rAvg = (r1 + r2) / 2.0;
|
||||
pts.center = Base::Vector3d(ellipse->center.x,
|
||||
ellipse->center.y,
|
||||
0.0);
|
||||
pts.radius = rAvg;
|
||||
pts.isArc = false;
|
||||
pts.onCurve.first = pts.center + Base::Vector3d(1,0,0) * rAvg; //arbitrary point on edge
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * rAvg; //arbitrary point on edge
|
||||
} else {
|
||||
TechDrawGeometry::AOE* aoe = static_cast<TechDrawGeometry::AOE*> (base);
|
||||
double r1 = aoe->minor;
|
||||
double r2 = aoe->major;
|
||||
double rAvg = (r1 + r2) / 2.0;
|
||||
pts.isArc = true;
|
||||
pts.center = Base::Vector3d(aoe->center.x,
|
||||
aoe->center.y,
|
||||
0.0);
|
||||
pts.radius = rAvg;
|
||||
pts.arcEnds.first = Base::Vector3d(aoe->startPnt.x,aoe->startPnt.y,0.0);
|
||||
pts.arcEnds.second = Base::Vector3d(aoe->endPnt.x,aoe->endPnt.y,0.0);
|
||||
pts.midArc = Base::Vector3d(aoe->midPnt.x,aoe->midPnt.y,0.0);
|
||||
pts.arcCW = aoe->cw;
|
||||
pts.onCurve.first = Base::Vector3d(aoe->midPnt.x,aoe->midPnt.y,0.0);
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * rAvg; //arbitrary point on edge
|
||||
}
|
||||
} else if (base && base->geomType == TechDrawGeometry::GeomType::BSPLINE) {
|
||||
TechDrawGeometry::BSpline* spline = static_cast<TechDrawGeometry::BSpline*> (base);
|
||||
if (spline->isCircle()) {
|
||||
@@ -360,7 +423,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
}
|
||||
} else {
|
||||
//fubar - can't have non-circular spline as target of Diameter dimension
|
||||
Base::Console().Error("Dimension %s refers to invalid BSpline\n",getNameInDocument());
|
||||
Base::Console().Error("%s: can not make a Circle from this BSpline edge\n",getNameInDocument());
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
} else {
|
||||
@@ -442,7 +505,6 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
}
|
||||
|
||||
//TODO: if MeasureType = Projected and the Projected shape changes, the Dimension may become invalid (see tilted Cube example)
|
||||
|
||||
return DrawView::execute();
|
||||
}
|
||||
|
||||
@@ -627,7 +689,6 @@ double DrawViewDimension::getDimValue()
|
||||
} else if(Type.isValue("Radius")){
|
||||
arcPoints pts = m_arcPoints;
|
||||
result = pts.radius / getViewPart()->getScale(); //Projected BaseGeom is scaled for drawing
|
||||
|
||||
|
||||
} else if(Type.isValue("Diameter")){
|
||||
arcPoints pts = m_arcPoints;
|
||||
|
||||
@@ -197,6 +197,22 @@ std::string BaseGeom::dump()
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool BaseGeom::closed(void)
|
||||
{
|
||||
//return occEdge.Closed(); //based on a flag in occ. may not be correct!
|
||||
bool result = false;
|
||||
Base::Vector3d start(getStartPoint().x,
|
||||
getStartPoint().y,
|
||||
0.0);
|
||||
Base::Vector3d end(getEndPoint().x,
|
||||
getEndPoint().y,
|
||||
0.0);
|
||||
if (start.IsEqual(end, 0.00001)) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//! Convert 1 OCC edge into 1 BaseGeom (static factory method)
|
||||
BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
@@ -252,7 +268,7 @@ BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
delete bspline;
|
||||
bspline = nullptr;
|
||||
} else {
|
||||
TopoDS_Edge circEdge = bspline->isCircle2(isArc);
|
||||
TopoDS_Edge circEdge = bspline->asCircle(isArc);
|
||||
if (!circEdge.IsNull()) {
|
||||
if (isArc) {
|
||||
aoc = new AOC(circEdge);
|
||||
@@ -699,8 +715,8 @@ void BSpline::getCircleParms(bool& isCircle, double& radius, Base::Vector3d& cen
|
||||
}
|
||||
}
|
||||
|
||||
// can this BSpline be a circle?
|
||||
TopoDS_Edge BSpline::isCircle2(bool& arc)
|
||||
// make a circular edge from BSpline
|
||||
TopoDS_Edge BSpline::asCircle(bool& arc)
|
||||
{
|
||||
TopoDS_Edge result;
|
||||
BRepAdaptor_Curve c(occEdge);
|
||||
@@ -743,7 +759,7 @@ TopoDS_Edge BSpline::isCircle2(bool& arc)
|
||||
projm.Perform(pm);
|
||||
}
|
||||
catch(const StdFail_NotDone &e) {
|
||||
Base::Console().Log("Geometry::isCircle2 - init: %s\n",e.GetMessageString());
|
||||
Base::Console().Log("Geometry::asCircle - init: %s\n",e.GetMessageString());
|
||||
return result;
|
||||
}
|
||||
if ( (proj1.NbPoints() == 0) ||
|
||||
@@ -760,7 +776,7 @@ TopoDS_Edge BSpline::isCircle2(bool& arc)
|
||||
pcm = projm.NearestPoint();
|
||||
}
|
||||
catch(const StdFail_NotDone &e) {
|
||||
Base::Console().Log("Geometry::isCircle2 - nearPoint: %s\n",e.GetMessageString());
|
||||
Base::Console().Log("Geometry::asCircle - nearPoint: %s\n",e.GetMessageString());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ class TechDrawExport BaseGeom
|
||||
Base::Vector2d nearPoint(Base::Vector2d p);
|
||||
Base::Vector2d nearPoint(const BaseGeom* p);
|
||||
static BaseGeom* baseFactory(TopoDS_Edge edge);
|
||||
bool closed(void);
|
||||
std::string dump();
|
||||
};
|
||||
|
||||
@@ -192,7 +193,7 @@ class TechDrawExport BSpline: public BaseGeom
|
||||
|
||||
bool isLine(void);
|
||||
bool isCircle(void);
|
||||
TopoDS_Edge isCircle2(bool& isArc);
|
||||
TopoDS_Edge asCircle(bool& isArc);
|
||||
void getCircleParms(bool& isCircle, double& radius, Base::Vector3d& center, bool& isArc);
|
||||
bool intersectsArc(Base::Vector3d p1,Base::Vector3d p2);
|
||||
std::vector<BezierSegment> segments;
|
||||
|
||||
Reference in New Issue
Block a user