diff --git a/DRAWer_2_0.ui b/DRAWer_2_0.ui index 1cf3121..3e9eec9 100644 --- a/DRAWer_2_0.ui +++ b/DRAWer_2_0.ui @@ -35,7 +35,7 @@ - Click me + Line @@ -48,7 +48,7 @@ - PushButton + Parallel @@ -61,7 +61,7 @@ - PushButton + P2P @@ -71,7 +71,7 @@ - 100 + 1000 100 @@ -97,6 +97,9 @@ 16777215 + + Canvas + @@ -107,7 +110,7 @@ 0 0 700 - 22 + 21 diff --git a/GCS/Geo.cpp b/GCS/Geo.cpp index cbb4e30..852191b 100644 --- a/GCS/Geo.cpp +++ b/GCS/Geo.cpp @@ -33,6 +33,13 @@ namespace GCS { //----------------Point + +Point::Point(double* px, double* py, int _tag) { + x = px; + y = py; + tag = _tag; +} + int Point::PushOwnParams(VEC_pD& pvec) { int cnt = 0; @@ -130,6 +137,12 @@ DeriVector2 Curve::Value(double /*u*/, double /*du*/, const double* /*derivparam //----------------Line +Line::Line(Point _p1, Point _p2, int _tag) { + p1 = _p1; + p2 = _p2; + tag = _tag; +} + DeriVector2 Line::CalculateNormal(const Point& p, const double* derivparam) const { (void)p; @@ -178,6 +191,16 @@ Line* Line::Copy() return crv; } +void Line::draw(QPainter& p, bool highlight){ + QPen pen = highlight ? QPen(Qt::red, 4) : QPen(Qt::black, 2); + p.setPen(pen); + p.drawLine(QPointF(p1.get_X(), p1.get_Y()), QPointF(p2.get_X(), p2.get_Y())); + + p.setBrush(highlight ? Qt::red : Qt::blue); + p.drawEllipse(QPointF(p1.get_X(), p1.get_Y()), 4, 4); + p.drawEllipse(QPointF(p2.get_X(), p2.get_Y()), 4, 4); +} + //---------------circle diff --git a/GCS/Geo.h b/GCS/Geo.h index 33c09f0..ce9ac0f 100644 --- a/GCS/Geo.h +++ b/GCS/Geo.h @@ -1,4 +1,4 @@ -/*************************************************************************** +/*************************************************************************** * Copyright (c) 2011 Konstantinos Poulios * * * * This file is part of the FreeCAD CAx development system. * @@ -24,16 +24,20 @@ #define PLANEGCS_GEO_H #include "Util.h" +#include #include #ifdef _MSC_VER #pragma warning(disable : 4251) #endif +#include namespace GCS { class Point { +private: + int tag; public: Point() { @@ -41,24 +45,12 @@ public: y = nullptr; } - Point(double* px, double* py) - { - x = px; - y = py; - } - - Point(double* px, double* py, int _tag) - { - x = px; - y = py; - tag = _tag; - } + Point(double* px, double* py, int _tag = 0); double* x; double* y; int PushOwnParams(VEC_pD& pvec); - void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt); double get_X() const { @@ -69,8 +61,9 @@ public: return *(this->y); } -private: - int tag; + void set_tag(int _tag) { + tag = _tag; + } }; using VEC_P = std::vector; @@ -215,13 +208,14 @@ public: class Line: public Curve { +private: + int tag; public: Line() {} - Line(Point _p1, Point _p2) { - p1 = _p1; - p2 = _p2; - } + + Line(Point _p1, Point _p2, int _tag = 0); + ~Line() override {} Point p1; @@ -231,6 +225,13 @@ public: int PushOwnParams(VEC_pD& pvec) override; void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt) override; Line* Copy() override; + + void draw(QPainter& p, bool highlight = false); + void set_tag(int _tag) { + tag = _tag; + p1.set_tag(_tag); + p2.set_tag(_tag); + } }; class Circle: public Curve @@ -253,6 +254,8 @@ public: class Arc: public Circle { +private: + int tag; public: Arc() { @@ -260,6 +263,20 @@ public: endAngle = nullptr; rad = nullptr; } + + Arc(Point _center, Point _st, Point _end, double* a, double* b, double *radius, int _tag = 0) { + center = _center; + start = _st; + end = _end; + + startAngle = a; + endAngle = b; + rad = radius; + + tag = _tag; + calculate_arc_points(); + } + ~Arc() override {} double* startAngle; @@ -272,6 +289,15 @@ public: int PushOwnParams(VEC_pD& pvec) override; void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt) override; Arc* Copy() override; + +private: + // Find positions of startpoint and endpoint of arc + void calculate_arc_points() { + *start.x = *center.x + *rad * cos(*startAngle); + *start.y = *center.x + *rad * sin(*startAngle); + *end.x = *center.x + *rad * cos(*endAngle); + *end.y = *center.x + *rad * sin(*endAngle); + } }; class MajorRadiusConic: public Curve