feat: Create Open CASCADE shapes for sketch geometry
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -13,6 +13,13 @@
|
|||||||
#include "SketchCircle.h"
|
#include "SketchCircle.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
|
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||||
|
#include <BRepBuilderAPI_MakeWire.hxx>
|
||||||
|
#include <GC_MakeSegment.hxx>
|
||||||
|
#include <gp_Ax2.hxx>
|
||||||
|
#include <gp_Circ.hxx>
|
||||||
|
#include <gp_Dir.hxx>
|
||||||
|
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -146,6 +153,10 @@ void ApplicationController::addLine(const gp_Pnt& start, const gp_Pnt& end)
|
|||||||
{
|
{
|
||||||
if (m_activeSketch) {
|
if (m_activeSketch) {
|
||||||
m_activeSketch->addObject(new SketchLine(start, end));
|
m_activeSketch->addObject(new SketchLine(start, end));
|
||||||
|
|
||||||
|
Handle(Geom_TrimmedCurve) segment = GC_MakeSegment(start, end);
|
||||||
|
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(segment);
|
||||||
|
m_activeSketch->addShape(edge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +164,29 @@ void ApplicationController::addRectangle(const gp_Pnt& corner1, const gp_Pnt& co
|
|||||||
{
|
{
|
||||||
if (m_activeSketch) {
|
if (m_activeSketch) {
|
||||||
m_activeSketch->addObject(new SketchRectangle(corner1, corner2));
|
m_activeSketch->addObject(new SketchRectangle(corner1, corner2));
|
||||||
|
|
||||||
|
gp_Pnt c2, c4;
|
||||||
|
auto plane = m_activeSketch->plane();
|
||||||
|
if (plane == SketchFeature::SketchPlane::XY) {
|
||||||
|
c2.SetX(corner2.X()); c2.SetY(corner1.Y()); c2.SetZ(corner1.Z());
|
||||||
|
c4.SetX(corner1.X()); c4.SetY(corner2.Y()); c4.SetZ(corner1.Z());
|
||||||
|
} else if (plane == SketchFeature::SketchPlane::XZ) {
|
||||||
|
c2.SetX(corner2.X()); c2.SetY(corner1.Y()); c2.SetZ(corner1.Z());
|
||||||
|
c4.SetX(corner1.X()); c4.SetY(corner1.Y()); c4.SetZ(corner2.Z());
|
||||||
|
} else { // YZ
|
||||||
|
c2.SetX(corner1.X()); c2.SetY(corner2.Y()); c2.SetZ(corner1.Z());
|
||||||
|
c4.SetX(corner1.X()); c4.SetY(corner1.Y()); c4.SetZ(corner2.Z());
|
||||||
|
}
|
||||||
|
|
||||||
|
TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(corner1, c2);
|
||||||
|
TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(c2, corner2);
|
||||||
|
TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(corner2, c4);
|
||||||
|
TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(c4, corner1);
|
||||||
|
|
||||||
|
BRepBuilderAPI_MakeWire wireMaker(e1, e2, e3, e4);
|
||||||
|
if (wireMaker.IsDone()) {
|
||||||
|
m_activeSketch->addShape(wireMaker.Wire());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +194,20 @@ void ApplicationController::addCircle(const gp_Pnt& center, double radius)
|
|||||||
{
|
{
|
||||||
if (m_activeSketch) {
|
if (m_activeSketch) {
|
||||||
m_activeSketch->addObject(new SketchCircle(center, radius));
|
m_activeSketch->addObject(new SketchCircle(center, radius));
|
||||||
|
|
||||||
|
gp_Ax2 axis;
|
||||||
|
auto plane = m_activeSketch->plane();
|
||||||
|
if (plane == SketchFeature::SketchPlane::XY) {
|
||||||
|
axis = gp_Ax2(center, gp::DZ());
|
||||||
|
} else if (plane == SketchFeature::SketchPlane::XZ) {
|
||||||
|
axis = gp_Ax2(center, gp::DY());
|
||||||
|
} else { // YZ
|
||||||
|
axis = gp_Ax2(center, gp::DX());
|
||||||
|
}
|
||||||
|
|
||||||
|
gp_Circ circle(axis, radius);
|
||||||
|
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(circle);
|
||||||
|
m_activeSketch->addShape(edge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,18 @@
|
|||||||
#include "SketchLine.h"
|
#include "SketchLine.h"
|
||||||
#include "SketchRectangle.h"
|
#include "SketchRectangle.h"
|
||||||
|
|
||||||
|
#include <BRep_Builder.hxx>
|
||||||
|
#include <TopoDS_Compound.hxx>
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
SketchFeature::SketchFeature(const QString& name)
|
SketchFeature::SketchFeature(const QString& name)
|
||||||
: Feature(name)
|
: Feature(name)
|
||||||
{
|
{
|
||||||
|
BRep_Builder builder;
|
||||||
|
TopoDS_Compound compound;
|
||||||
|
builder.MakeCompound(compound);
|
||||||
|
m_shape = compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
SketchFeature::~SketchFeature()
|
SketchFeature::~SketchFeature()
|
||||||
@@ -42,6 +49,12 @@ const TopoDS_Shape& SketchFeature::shape() const
|
|||||||
return m_shape;
|
return m_shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SketchFeature::addShape(const TopoDS_Shape& shape)
|
||||||
|
{
|
||||||
|
BRep_Builder builder;
|
||||||
|
builder.Add(m_shape, shape);
|
||||||
|
}
|
||||||
|
|
||||||
void SketchFeature::addObject(SketchObject* object)
|
void SketchFeature::addObject(SketchObject* object)
|
||||||
{
|
{
|
||||||
m_objects.append(object);
|
m_objects.append(object);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public:
|
|||||||
SketchPlane plane() const;
|
SketchPlane plane() const;
|
||||||
|
|
||||||
const TopoDS_Shape& shape() const;
|
const TopoDS_Shape& shape() const;
|
||||||
|
void addShape(const TopoDS_Shape& shape);
|
||||||
|
|
||||||
void addObject(SketchObject* object);
|
void addObject(SketchObject* object);
|
||||||
const QList<SketchObject*>& objects() const;
|
const QList<SketchObject*>& objects() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user