|
1. ExFillet.h
#pragma once
/********************************************************************
created: 2019/5/23 15:10
filename: ExFillet.h
author: WangHongFeng
purpose: 增强圆角
*********************************************************************/
class CExFillet
{
public:
CExFillet();
~CExFillet();
//************************************
// Author: WangHongFeng
// Summary: 在封闭轮廓的角落, 自动对所有的内角导圆
// Method: AutoProfileFillet
// Access: public
// Returns: bool
//************************************
bool AutoProfileFillet();
static double dFilletR;
static resbuf* ssCallback(const TCHAR* kword);
private:
//************************************
// Author: WangHongFeng
// Summary: 闭合多段线,内角圆角
// Method: fillerInnerCorner
// Access: public
// Returns: bool
// Parameter: ads_name ssName
// Parameter: AcDbPolyline * pPoly
// Parameter: int Relation -1闭合区域外,1闭合区域内
//************************************
bool fillerInnerCorner(ads_name ssName, AcDbPolyline * pPoly, int Relation);
};
2. ExFillet.cpp
#include "StdAfx.h"
#include "ExFillet.h"
#include "PubFuc.h"
#include "AutoCmdEcho.h"
typedef AcDbObjectPointer<AcDbCurve> AcDbCurvePointer;
CExFillet::CExFillet()
{
}
CExFillet::~CExFillet()
{
}
double CExFillet::dFilletR = 5;
resbuf* CExFillet::ssCallback(const TCHAR* kword)
{
ArxDbgUiPrDistDef prDist(L"input fillet radius", NULL, ArxDbgUiPrDist::kNoNegNoZero, dFilletR);
ReturnfalseNotTrue(prDist.go() == ArxDbgUiPrBase::kOk);
dFilletR = prDist.value();
resbuf *result = NULL;
return result;
}
bool CExFillet::AutoProfileFillet()
{
resbuf *rb;
rb = acutBuildList(-4, L"<OR", RTDXF0, L"LINE",
RTDXF0, L"LWPOLYLINE", RTDXF0, L"ARC", -4, L">OR", RTNONE);
AcDbObjectId startLineId;
ArxDbgSelSet selStartLine;
selStartLine.setAllowSingleOnly(true,false);
selStartLine.setKeywordCallback(L"R", ssCallback);
ReturnfalseNotTrue(selStartLine.userSelect(L"\nselect start Line[fillet radius(R)]:", NULL, rb) == ArxDbgSelSet::kSelected);
acutRelRb(rb);
AcDbObjectIdArray selSet;
selStartLine.asArray(selSet);
startLineId = selSet.at(0);
// bool bRes = ArxDbgUtils::selectEntity(L"select start Line:", startLineId);
// ReturnfalseNotTrue(bRes);
//获取所有直线圆弧
AcDbObjectIdArray idArr;
PubFuc::selectAllLineAndArc(idArr);
//获取边界id
AcDbObjectIdArray boundaryIds;
ReturnfalseNotTrue(PubFuc::getBoundaryIds(startLineId, idArr, boundaryIds));
ArxDbgUiPrPoint prPt(L"select Inner Point", NULL);
ReturnfalseNotTrue(prPt.go() == ArxDbgUiPrBase::kOk);
ads_name ssName;
PubFuc::objIdArrToEname(boundaryIds, ssName);
//合并边界为多段线
CAutoCmdEcho cmdcho(0);
acedCommand(RTSTR, L"JOIN", RTENAME, ssName,RTSTR, L"", RTNONE);
ads_name polyName;
acdbEntLast(polyName);
AcDbObjectId polyId;
ArxDbgUtils::enameToObjId(polyName, polyId);
AcDbPolyline *pPoly = NULL;
auto es = acdbOpenObject(pPoly, polyId, AcDb::kForWrite);
ArxDbgUtils::rxErrorMsg(es);
//点与闭合多段线的关系
int Relation = PubFuc::PtRelationToPoly(pPoly, PubFuc::ToPoint2d(prPt.value()));
PubFuc::unerase(boundaryIds);
//内角倒圆角
ReturnfalseNotTrue(fillerInnerCorner(ssName, pPoly, Relation));
acedSSFree(ssName);
pPoly->erase();
pPoly->close();
return true;
}
bool CExFillet::fillerInnerCorner(ads_name ssName, AcDbPolyline * pPoly, int Relation)
{
long length;
acedSSLength(ssName, &length);
for (int i = 0; i < length; i++)
{
ads_name ent1;
acedSSName(ssName, i, ent1);
ads_name ent2;
acedSSName(ssName, i + 1, ent2);
if (i == length - 1)
{
acedSSName(ssName, 0, ent2);
}
//AcadUtils::UndoM();
ads_name result;
PubFuc::Fillet(ent1, ent2, result, dFilletR);
AcDbObjectId arcId;
ArxDbgUtils::enameToObjId(result, arcId);
AcDbObjectPointer<AcDbArc> pArc(arcId, AcDb::kForWrite);
ReturnfalseNotTrue(pArc.openStatus() == Acad::eOk);
if (PubFuc::PtRelationToPoly(pPoly, PubFuc::ToPoint2d(pArc->center())) != Relation)
{
pArc->erase();
pArc->close();
PubFuc::Fillet(ent1, ent2, result, 0);
//AcadUtils::UndoB();
}
}
return true;
}
3. 调用
static void HFSoft_AutoProfileFillet()
{
CExFillet exFillet;
exFillet.AutoProfileFillet();
}
4. PubFuc::PtRelationToPoly
参考:[url]https://blog.csdn.net/wang161019/article/details/90520450[/url] |
|