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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user