发1个带撤回,设置宽度的polyline JIG,
#pragma onceclass PolylineJig : public DrawJig {
private:
inline static double pipeWidth = 100;
AcDbPolyline* m_Polyline = nullptr;
AcGePoint3d m_curPoint, m_basePoint;
AcGePoint2d m_curVerics;
bool m_hasUpdate = false;
int clickCount = 0;
enum JigMode : UInt8 { kInitial, kDrawing } m_Mode = kInitial;
std::vector<AcString> m_Keywords = { L"S",L"S U" };
void updateDispPrompt() {
std::wstring msg;
switch (m_Mode)
{
case PolylineJig::kInitial: {
msg = std::format(L"\n选择起点,当前管径为DN{}:[管径(S)]", pipeWidth).c_str();
setDispPrompt(msg.c_str());
break;
}
case PolylineJig::kDrawing:
msg = std::format(L"\n选择下1个点,当前管径为DN{}:[管径(S)/撤回(U)]", pipeWidth).c_str();
setDispPrompt(msg.c_str());
break;
default:
break;
}
}
void addVertics() {
m_hasUpdate = false;
m_Mode = kDrawing;
auto count = m_Polyline->numVerts();
m_Polyline->getPointAt(count - 1, m_basePoint);
}
void updateJigState() {
m_Mode = clickCount == 0 ? kInitial : kDrawing;
}
void removeLastVertics() {
auto count = m_Polyline->numVerts();
if (m_hasUpdate)
{
m_Polyline->getPointAt(count - 3, m_basePoint);
m_Polyline->removeVertexAt(count - 2);
}
else
{
m_Polyline->getPointAt(count - 2, m_basePoint);
m_Polyline->removeVertexAt(count - 1);
}
double sw, ew;
count = m_Polyline->numVerts();
if (count > 2) {
m_Polyline->getWidthsAt(count - 2, sw, ew);
setWidth(sw);
}
}
void setWidth(double val) {
pipeWidth = val;
auto count = m_Polyline->numVerts();
if (m_hasUpdate)
{
m_Polyline->setWidthsAt(count - 2, pipeWidth, pipeWidth);
m_Polyline->setWidthsAt(count - 1, pipeWidth, pipeWidth);
}
else
{
m_Polyline->setWidthsAt(count - 1, pipeWidth, pipeWidth);
}
}
public:
PolylineJig(AcDbPolyline* poly) :m_Polyline(poly) {
m_Polyline->setDatabaseDefaults();
setUserInputControls(
/* kAccept3dCoordinates |*/
kNullResponseAccepted |
kAnyBlankTerminatesInput);
}
~PolylineJig() {
if (!m_Polyline) {
delete m_Polyline;
m_Polyline = nullptr;
}
}
// 采样点坐标
DragStatus sampler() override {
DragStatus state = kCancel;
switch (m_Mode) {
case PolylineJig::kInitial: {
setKeywordList(m_Keywords);
state = acquirePoint(m_curPoint);
break;
}
case PolylineJig::kDrawing: {
setKeywordList(m_Keywords);
state = acquirePoint(m_curPoint, m_basePoint);
break;
}
default:
break;
}
return state;
}
virtual bool update() {
m_curVerics = m_curPoint.convert2d(AcGePlane::kXYPlane);
autonumCount = m_Polyline->numVerts();
if (!m_hasUpdate) {
m_Polyline->addVertexAt(numCount, m_curVerics, 0, pipeWidth, pipeWidth);
m_hasUpdate = true;
}
else {
m_Polyline->setPointAt(numCount - 1, m_curVerics);
}
return true;
}
virtual bool subWorldDraw(AcGiWorldDraw* pWorldDraw) override {
if (m_Polyline && m_Polyline->numVerts() > 1) {
pWorldDraw->geometry().draw(m_Polyline);
return true;
}
return false;
}
DragStatusrunJig() {
updateDispPrompt();
DragStatus state = drag(AcEdDragStyle(AcEdDragStyle::kDeletedEffect, AcEdDragStyle::kDeletedEffect));
if (m_basePoint.isEqualTo(m_curPoint) && state == kNormal) {
state = kNoChange;
}
switch (state)
{
case AcEdJig::kNormal:
{
clickCount++;
addVertics();
break;
}
case AcEdJig::kKW1:
{
MapleFlash flash;
flash.AddEntity(m_Polyline);
auto res = MapleGetInt(L"设定管径");
if (res.Ok) {
setWidth(std::max(0, res.Value));
}
break;
}
case AcEdJig::kKW2:
{
clickCount--;
removeLastVertics();
break;
}
case AcEdJig::kNoChange: {
break;
}
default:
break;
}
updateJigState();
return state;
}
AcDbPolyline* getEntity() {
if (m_hasUpdate) {
m_Polyline->removeVertexAt(m_Polyline->numVerts() - 1);
}
auto count = m_Polyline->numVerts();
if (count < 2) {
m_Polyline->erase();
m_Polyline = nullptr;
}
return m_Polyline;
}
};
void pipe() {
DbTrans tr;
auto btr = tr.currentSpace();
auto pline = new AcDbPolyline(2);
tr.addEntity(btr, pline);
PolylineJig jig(pline);
// 循环执行绘图交互,直到用户取消
while (jig.runJig() != AcEdJig::kCancel) {
tr.flushScreen();
}
jig.getEntity();
}
你怎么越来越厉害了 你是真的厉害啊 你有种再说一遍 发表于 2026-1-2 19:47
你怎么越来越厉害了
:L 大佬说笑了
页:
[1]