Edit GCS module and ui

This commit is contained in:
ParkSuMin
2025-12-07 13:08:43 +03:00
parent e613b4f004
commit 94761fecbc
3 changed files with 77 additions and 25 deletions

View File

@@ -35,7 +35,7 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>Click me</string> <string>Line</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -48,7 +48,7 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>PushButton</string> <string>Parallel</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -61,7 +61,7 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>PushButton</string> <string>P2P</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -71,7 +71,7 @@
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>100</width> <width>1000</width>
<height>100</height> <height>100</height>
</size> </size>
</property> </property>
@@ -97,6 +97,9 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="whatsThis">
<string>Canvas</string>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@@ -107,7 +110,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>700</width> <width>700</width>
<height>22</height> <height>21</height>
</rect> </rect>
</property> </property>
</widget> </widget>

View File

@@ -33,6 +33,13 @@ namespace GCS
{ {
//----------------Point //----------------Point
Point::Point(double* px, double* py, int _tag) {
x = px;
y = py;
tag = _tag;
}
int Point::PushOwnParams(VEC_pD& pvec) int Point::PushOwnParams(VEC_pD& pvec)
{ {
int cnt = 0; int cnt = 0;
@@ -130,6 +137,12 @@ DeriVector2 Curve::Value(double /*u*/, double /*du*/, const double* /*derivparam
//----------------Line //----------------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 DeriVector2 Line::CalculateNormal(const Point& p, const double* derivparam) const
{ {
(void)p; (void)p;
@@ -178,6 +191,16 @@ Line* Line::Copy()
return crv; 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 //---------------circle

View File

@@ -1,4 +1,4 @@
/*************************************************************************** /***************************************************************************
* Copyright (c) 2011 Konstantinos Poulios <logari81@gmail.com> * * Copyright (c) 2011 Konstantinos Poulios <logari81@gmail.com> *
* * * *
* This file is part of the FreeCAD CAx development system. * * This file is part of the FreeCAD CAx development system. *
@@ -24,16 +24,20 @@
#define PLANEGCS_GEO_H #define PLANEGCS_GEO_H
#include "Util.h" #include "Util.h"
#include <QPainter>
#include <boost/math/constants/constants.hpp> #include <boost/math/constants/constants.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable : 4251) #pragma warning(disable : 4251)
#endif #endif
#include <numbers>
namespace GCS namespace GCS
{ {
class Point class Point
{ {
private:
int tag;
public: public:
Point() Point()
{ {
@@ -41,24 +45,12 @@ public:
y = nullptr; y = nullptr;
} }
Point(double* px, double* py) Point(double* px, double* py, int _tag = 0);
{
x = px;
y = py;
}
Point(double* px, double* py, int _tag)
{
x = px;
y = py;
tag = _tag;
}
double* x; double* x;
double* y; double* y;
int PushOwnParams(VEC_pD& pvec); int PushOwnParams(VEC_pD& pvec);
void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt); void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt);
double get_X() const { double get_X() const {
@@ -69,8 +61,9 @@ public:
return *(this->y); return *(this->y);
} }
private: void set_tag(int _tag) {
int tag; tag = _tag;
}
}; };
using VEC_P = std::vector<Point>; using VEC_P = std::vector<Point>;
@@ -215,13 +208,14 @@ public:
class Line: public Curve class Line: public Curve
{ {
private:
int tag;
public: public:
Line() Line()
{} {}
Line(Point _p1, Point _p2) {
p1 = _p1; Line(Point _p1, Point _p2, int _tag = 0);
p2 = _p2;
}
~Line() override ~Line() override
{} {}
Point p1; Point p1;
@@ -231,6 +225,13 @@ public:
int PushOwnParams(VEC_pD& pvec) override; int PushOwnParams(VEC_pD& pvec) override;
void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt) override; void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt) override;
Line* Copy() 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 class Circle: public Curve
@@ -253,6 +254,8 @@ public:
class Arc: public Circle class Arc: public Circle
{ {
private:
int tag;
public: public:
Arc() Arc()
{ {
@@ -260,6 +263,20 @@ public:
endAngle = nullptr; endAngle = nullptr;
rad = 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 ~Arc() override
{} {}
double* startAngle; double* startAngle;
@@ -272,6 +289,15 @@ public:
int PushOwnParams(VEC_pD& pvec) override; int PushOwnParams(VEC_pD& pvec) override;
void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt) override; void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt) override;
Arc* Copy() 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 class MajorRadiusConic: public Curve