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:
2026-02-14 19:12:59 -07:00
parent f46590219a
commit a1cfbc2e3f
6 changed files with 159 additions and 0 deletions

View File

@@ -1,10 +1,19 @@
#include "SketchFeature.h"
#include "SketchObject.h"
#include "SketchLine.h"
#include <QJsonArray>
SketchFeature::SketchFeature(const QString& name)
: Feature(name)
{
}
SketchFeature::~SketchFeature()
{
qDeleteAll(m_objects);
}
QString SketchFeature::type() const
{
return "Sketch";
@@ -25,6 +34,16 @@ const TopoDS_Shape& SketchFeature::shape() const
return m_shape;
}
void SketchFeature::addObject(SketchObject* object)
{
m_objects.append(object);
}
const QList<SketchObject*>& SketchFeature::objects() const
{
return m_objects;
}
void SketchFeature::read(const QJsonObject& json)
{
Feature::read(json);
@@ -34,6 +53,23 @@ void SketchFeature::read(const QJsonObject& json)
else if (planeStr == "XZ") m_plane = SketchPlane::XZ;
else if (planeStr == "YZ") m_plane = SketchPlane::YZ;
}
if (json.contains("objects") && json["objects"].isArray()) {
QJsonArray objectsArray = json["objects"].toArray();
qDeleteAll(m_objects);
m_objects.clear();
for (const QJsonValue& value : objectsArray) {
QJsonObject objectJson = value.toObject();
if (objectJson.contains("type") && objectJson["type"].isString()) {
QString type = objectJson["type"].toString();
if (type == "Line") {
auto line = new SketchLine();
line->read(objectJson);
m_objects.append(line);
}
}
}
}
}
void SketchFeature::write(QJsonObject& json) const
@@ -46,4 +82,12 @@ void SketchFeature::write(QJsonObject& json) const
case SketchPlane::YZ: planeStr = "YZ"; break;
}
json["plane"] = planeStr;
QJsonArray objectsArray;
for (const auto& object : m_objects) {
QJsonObject objectJson;
object->write(objectJson);
objectsArray.append(objectJson);
}
json["objects"] = objectsArray;
}