feat: Implement sketch object base class and line geometry
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
58
src/SketchLine.cpp
Normal file
58
src/SketchLine.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "SketchLine.h"
|
||||
#include <QJsonObject>
|
||||
|
||||
SketchLine::SketchLine()
|
||||
{
|
||||
}
|
||||
|
||||
SketchLine::SketchLine(const gp_Pnt& start, const gp_Pnt& end)
|
||||
: m_start(start), m_end(end)
|
||||
{
|
||||
}
|
||||
|
||||
SketchObject::ObjectType SketchLine::type() const
|
||||
{
|
||||
return ObjectType::Line;
|
||||
}
|
||||
|
||||
void SketchLine::read(const QJsonObject& json)
|
||||
{
|
||||
if (json.contains("start") && json["start"].isObject() &&
|
||||
json.contains("end") && json["end"].isObject()) {
|
||||
QJsonObject startObj = json["start"].toObject();
|
||||
QJsonObject endObj = json["end"].toObject();
|
||||
m_start.SetX(startObj["x"].toDouble());
|
||||
m_start.SetY(startObj["y"].toDouble());
|
||||
m_start.SetZ(startObj["z"].toDouble());
|
||||
m_end.SetX(endObj["x"].toDouble());
|
||||
m_end.SetY(endObj["y"].toDouble());
|
||||
m_end.SetZ(endObj["z"].toDouble());
|
||||
}
|
||||
}
|
||||
|
||||
void SketchLine::write(QJsonObject& json) const
|
||||
{
|
||||
QJsonObject startObj;
|
||||
startObj["x"] = m_start.X();
|
||||
startObj["y"] = m_start.Y();
|
||||
startObj["z"] = m_start.Z();
|
||||
|
||||
QJsonObject endObj;
|
||||
endObj["x"] = m_end.X();
|
||||
endObj["y"] = m_end.Y();
|
||||
endObj["z"] = m_end.Z();
|
||||
|
||||
json["type"] = "Line";
|
||||
json["start"] = startObj;
|
||||
json["end"] = endObj;
|
||||
}
|
||||
|
||||
const gp_Pnt& SketchLine::startPoint() const
|
||||
{
|
||||
return m_start;
|
||||
}
|
||||
|
||||
const gp_Pnt& SketchLine::endPoint() const
|
||||
{
|
||||
return m_end;
|
||||
}
|
||||
Reference in New Issue
Block a user