[TD]expose dimension arrow position to Python

This commit is contained in:
wandererfan
2020-03-01 19:29:51 -05:00
committed by WandererFan
parent 27c4246c6e
commit db97daf0e0
6 changed files with 46 additions and 1 deletions

View File

@@ -1093,7 +1093,20 @@ bool DrawViewDimension::leaderIntersectsArc(Base::Vector3d s, Base::Vector3d poi
return result;
}
//are there non-blank references?
void DrawViewDimension::saveArrowPositions(const Base::Vector2d positions[])
{
double scale = getViewPart()->getScale();
m_arrowPositions.first = Base::Vector3d(positions[0].x, positions[0].y, 0.0) / scale;
m_arrowPositions.second = Base::Vector3d(positions[1].x, positions[1].y, 0.0) / scale;
}
//return position within parent view of dimension arrow heads/dimline endpoints
//note positions are in apparent coord (inverted y).
pointPair DrawViewDimension::getArrowPositions(void)
{
return m_arrowPositions;
}
bool DrawViewDimension::has2DReferences(void) const
{
// Base::Console().Message("DVD::has2DReferences() - %s\n",getNameInDocument());

View File

@@ -153,6 +153,9 @@ public:
bool isMultiValueSchema(void) const;
pointPair getArrowPositions(void);
void saveArrowPositions(const Base::Vector2d positions[]);
protected:
virtual void onChanged(const App::Property* prop) override;
virtual void onDocumentRestored() override;
@@ -174,6 +177,7 @@ protected:
pointPair closestPoints(TopoDS_Shape s1,
TopoDS_Shape s2) const;
pointPair m_linearPoints;
pointPair m_arrowPositions;
private:
static const char* TypeEnums[];

View File

@@ -33,6 +33,11 @@
<UserDocu>getAnglePoints() - returns list of points for angle Dimension</UserDocu>
</Documentation>
</Methode>
<Methode Name="getArrowPositions">
<Documentation>
<UserDocu>getArrowPositions() - returns list of locations or Dimension Arrowheads. Locations are in unscaled coordinates of parent View </UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -99,6 +99,16 @@ PyObject* DrawViewDimensionPy::getAnglePoints(PyObject* args)
return ret;
}
PyObject* DrawViewDimensionPy::getArrowPositions(PyObject* args)
{
(void) args;
DrawViewDimension* dvd = getDrawViewDimensionPtr();
pointPair pts = dvd->getArrowPositions();
PyObject* ret = PyList_New(0);
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.first)));
PyList_Append(ret,new Base::VectorPy(new Base::Vector3d(pts.second)));
return ret;
}
PyObject *DrawViewDimensionPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;

View File

@@ -1176,6 +1176,8 @@ void QGIViewDimension::drawArrows(int count, const Base::Vector2d positions[], d
const int arrowCount = 2;
QGIArrow *arrows[arrowCount] = { aHead1, aHead2 };
arrowPositionsToFeature(positions);
for (int i = 0; i < arrowCount; ++i) {
QGIArrow *arrow = arrows[i];
@@ -1198,6 +1200,15 @@ void QGIViewDimension::drawArrows(int count, const Base::Vector2d positions[], d
}
}
void QGIViewDimension::arrowPositionsToFeature(const Base::Vector2d positions[]) const
{
auto dim( dynamic_cast<TechDraw::DrawViewDimension*>(getViewObject()) );
if( dim == nullptr )
return;
dim->saveArrowPositions(positions);
}
void QGIViewDimension::drawSingleLine(QPainterPath &painterPath, const Base::Vector2d &lineOrigin, double lineAngle,
double startPosition, double endPosition) const
{

View File

@@ -260,6 +260,8 @@ protected:
//QGICMark* centerMark
double m_lineWidth;
void arrowPositionsToFeature(const Base::Vector2d positions[]) const;
private:
static inline Base::Vector2d fromQtApp(const Base::Vector3d &v) { return Base::Vector2d(v.x, -v.y); }
static inline Base::BoundBox2d fromQtGui(const QRectF &r)