1224 lines
28 KiB
C++
1224 lines
28 KiB
C++
// GraphicDlg.cpp : implementation file
|
||
//
|
||
/*解决动态绘制时“闪”的问题分三步完成:
|
||
第一,JIG里只绘制最后一段,但poly数据不变
|
||
第二,JIG每绘制完一段后,将前面段更新到数据库
|
||
第三,JIG里的UNDO修改*/
|
||
|
||
#include "stdafx.h"
|
||
#include "actrans.h"
|
||
|
||
#include "LinePatternDlg.h"
|
||
|
||
#ifdef _DEBUG
|
||
#define new DEBUG_NEW
|
||
#undef THIS_FILE
|
||
static char THIS_FILE[] = __FILE__;
|
||
#endif
|
||
extern GEOAPI int GetBlockExtents(AcDbObjectId idBlock, XPoint &ptLow, XPoint &ptUp);
|
||
// extern GEOAPI BOOL SplitLibraryPath(const TCHAR *totalName, TCHAR *slbFile, TCHAR *sldFile);
|
||
|
||
int CGraphicDlg::g_nCurSel=0;
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CGraphicDlg dialog
|
||
|
||
CString CGraphicDlg::s_strWidth = _T("120");
|
||
int CGraphicDlg::s_iAlign = 0;
|
||
int CGraphicDlg::s_iBase=0;
|
||
BOOL CGraphicDlg::s_bUseRatio=FALSE;
|
||
double CGraphicDlg::s_fRatio=80.0;
|
||
BOOL CGraphicDlg::m_bDynamic=TRUE;
|
||
|
||
IMPLEMENT_DYNAMIC(CGraphicDlg, CModelessDialog)//add by fxj on 070508
|
||
|
||
CGraphicDlg::CGraphicDlg(CWnd* pParent /*=NULL*/)
|
||
: CModelessDialog(CGraphicDlg::IDD, pParent)
|
||
{
|
||
//{{AFX_DATA_INIT(CGraphicDlg)
|
||
//}}AFX_DATA_INIT
|
||
m_bRail=FALSE;
|
||
|
||
CRegProperty regProp(::GetRegLocation(), _T("Settings"));
|
||
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
||
if (!regProp.GetValue(_T("LinePattern"), m_csCurPattern))
|
||
m_csCurPattern=_T("LinePat(45度线)");
|
||
}
|
||
CGraphicDlg::~CGraphicDlg()
|
||
{
|
||
}
|
||
void CGraphicDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CModelessDialog::DoDataExchange(pDX);
|
||
//{{AFX_DATA_MAP(CGraphicDlg)
|
||
DDX_Text(pDX, IDC_WIDTH, s_strWidth);
|
||
DDX_Radio(pDX, IDC_RADIO_UP, s_iAlign);
|
||
DDX_Radio(pDX, IDC_RADIO_ALIGN_MID, s_iBase);
|
||
DDX_Check(pDX, IDC_CHECK_RATIO,s_bUseRatio);
|
||
DDX_Text(pDX,IDC_RATIO,s_fRatio);
|
||
DDX_Slider(pDX,IDC_PATTERN_SLIDE,g_nCurSel);
|
||
//}}AFX_DATA_MAP
|
||
}
|
||
|
||
|
||
BEGIN_MESSAGE_MAP(CGraphicDlg, CModelessDialog)
|
||
//{{AFX_MSG_MAP(CGraphicDlg)
|
||
ON_BN_CLICKED(IDC_GRAPHIC_WIDTH, OnGraphicWidth)
|
||
ON_BN_CLICKED(IDC_BUTTON_PATH, OnButtonPath)
|
||
ON_BN_CLICKED(IDC_BUTTON_DYNAMIC, OnButtonDynamic)
|
||
ON_WM_PAINT()
|
||
ON_WM_SETCURSOR()
|
||
ON_BN_CLICKED(IDC_PATTERN_SLIDE, OnPatternSlide)
|
||
ON_BN_CLICKED(IDC_CHECK_RATIO,OnCheckRatio)
|
||
ON_EN_KILLFOCUS(IDC_WIDTH, OnKillFocusWidth)
|
||
ON_EN_KILLFOCUS(IDC_RATIO,OnKillFocusRatio)
|
||
ON_BN_CLICKED(IDC_RADIO_UP,OnRadioUp)
|
||
ON_BN_CLICKED(IDC_RADIO_MIDDLE,OnRadioMiddle)
|
||
ON_BN_CLICKED(IDC_RADIO_DOWN,OnRadioDown)
|
||
ON_BN_CLICKED(IDC_RADIO_ALIGN_MID,OnRadioAlignMid)
|
||
ON_BN_CLICKED(IDC_RADIO_ALIGN_LEFT,OnRadioAlignLeft)
|
||
ON_BN_CLICKED(IDC_RADIO_ALIGN_RIGHT,OnRadioAlignRight)
|
||
ON_WM_CLOSE()
|
||
//}}AFX_MSG_MAP
|
||
END_MESSAGE_MAP()
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CGraphicDlg message handlers
|
||
|
||
BOOL CGraphicDlg::OnInitDialog()
|
||
{
|
||
CModelessDialog::OnInitDialog();
|
||
//CRect rect;
|
||
//GetWindowRect(rect);
|
||
// SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), 0);
|
||
m_nOperCode=0;
|
||
ShowSlide(g_nCurSel);
|
||
|
||
// TODO: Add extra initialization here
|
||
|
||
GetDlgItem(IDC_RATIO)->EnableWindow(s_bUseRatio);
|
||
if (m_bDynamic)
|
||
((CButton*)GetDlgItem(IDC_BUTTON_DYNAMIC))->SetCheck(1);
|
||
else
|
||
((CButton*)GetDlgItem(IDC_BUTTON_PATH))->SetCheck(1);
|
||
UpdateData(FALSE);
|
||
|
||
return TRUE; // return TRUE unless you set the focus to a control
|
||
// EXCEPTION: OCX Property Pages should return FALSE
|
||
}
|
||
|
||
void CGraphicDlg::OnClose()
|
||
{
|
||
m_bUserEsc=TRUE;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
|
||
void CGraphicDlg::OnKillFocusWidth()
|
||
{
|
||
UpdateData(TRUE);
|
||
|
||
if (GetFocus()==acedGetAcadFrame())
|
||
{
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
}
|
||
void CGraphicDlg::OnGraphicWidth()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
m_nOperCode = 1;
|
||
m_bUserEsc=FALSE;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
void CGraphicDlg::SetGraphicWidth()
|
||
{
|
||
UpdateData(TRUE);
|
||
ShowWindow(SW_HIDE);
|
||
double nWidth=_tstof(s_strWidth);
|
||
if (GetDist(_T("\n图案宽度<退出>:"), nWidth, RSG_NOZERO|RSG_NONEG)!=RTNORM)
|
||
{
|
||
ShowWindow(SW_SHOW);
|
||
return;
|
||
}
|
||
s_strWidth = (const TCHAR *)Dist2Str(nWidth);
|
||
m_nOperCode=0;
|
||
|
||
UpdateData(FALSE);
|
||
ShowWindow(SW_SHOW);
|
||
if (m_pickSet!=NULL)
|
||
UpdatePickSet();
|
||
}
|
||
void CGraphicDlg::OnButtonPath()
|
||
{
|
||
((CButton*)GetDlgItem(IDC_BUTTON_DYNAMIC))->SetCheck(0);
|
||
((CButton*)GetDlgItem(IDC_BUTTON_PATH))->SetCheck(1);
|
||
m_bDynamic = FALSE;
|
||
m_bUserEsc=FALSE;
|
||
acedPostCommand(_T("\33"));
|
||
|
||
}
|
||
void CGraphicDlg::OnButtonDynamic()
|
||
{
|
||
((CButton*)GetDlgItem(IDC_BUTTON_PATH))->SetCheck(0);
|
||
((CButton*)GetDlgItem(IDC_BUTTON_DYNAMIC))->SetCheck(1);
|
||
m_bDynamic=TRUE;
|
||
m_bUserEsc=FALSE;
|
||
acedPostCommand(_T("\33"));
|
||
|
||
}
|
||
void CGraphicDlg::DoDrawing(int nCurSel)
|
||
{
|
||
if (!m_polyPath)
|
||
return;
|
||
|
||
XString sBlockName, sFile;
|
||
sFile << g_sDwbPath << m_csCurPattern;
|
||
if (LoadDwbBlock(sFile, sBlockName)!=RTNORM)
|
||
return;
|
||
AcDbObjectId idBlock=InitBlock(sBlockName);
|
||
TDbPolyPathArray *pRail=new TDbPolyPathArray;
|
||
if (s_iAlign==0)
|
||
pRail->SetEqualScale(FALSE);
|
||
else if (s_iAlign==1)
|
||
{
|
||
pRail->SetEqualScale(TRUE);
|
||
pRail->SetAutoExpand(TRUE);
|
||
}
|
||
else
|
||
{
|
||
pRail->SetEqualScale(TRUE);
|
||
pRail->SetAutoExpand(FALSE);
|
||
}
|
||
if (s_iBase==0)
|
||
pRail->SetBaseType(2);
|
||
else if (s_iBase==1)
|
||
pRail->SetBaseType(0);
|
||
else
|
||
pRail->SetBaseType(1);
|
||
|
||
if (s_bUseRatio)
|
||
pRail->SetRatio(s_fRatio/100);
|
||
else
|
||
pRail->SetRatio(1);
|
||
pRail->SetUnitId(idBlock);
|
||
pRail->SetUnitHeight(_tstof(s_strWidth));
|
||
pRail->SetPathPoly(m_polyPath,pRail->GetNormal());
|
||
m_pickSet += AddToCurrentSpace(pRail,Adesk::kTrue);
|
||
m_bRail=TRUE;
|
||
}
|
||
|
||
extern BOOL InvokeTkwMan(const TCHAR *pszLib, BOOL bSelOnly, XString &sBlockName);
|
||
|
||
void CGraphicDlg::ShowSlide(int idx)
|
||
{
|
||
XString sSlideName;
|
||
sSlideName << g_sDwbPath << (const TCHAR *)m_csCurPattern; //_T("LinePat(") << slide << _T(")");
|
||
CWnd *pWnd=GetDlgItem(IDC_PATTERN_SLIDE);
|
||
CClientDC dc(pWnd);
|
||
CRect cR;
|
||
pWnd->GetClientRect(&cR);
|
||
m_image.InitDC(&dc, cR, GetAcadBackColor());
|
||
m_image.PaintSlide(sSlideName);
|
||
m_image.SetDC(NULL);
|
||
}
|
||
|
||
void CGraphicDlg::OnPaint()
|
||
{
|
||
CModelessDialog::OnPaint();
|
||
CWnd *pWnd=GetDlgItem(IDC_PATTERN_SLIDE);
|
||
CClientDC dc(pWnd);
|
||
CRect cR;
|
||
pWnd->GetClientRect(&cR);
|
||
m_image.InitDC(&dc, cR, GetAcadBackColor());
|
||
m_image.Redraw();
|
||
m_image.SetDC(NULL);
|
||
// Do not call CAcUiDialog::OnPaint() for painting messages
|
||
}
|
||
|
||
BOOL CGraphicDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
||
{
|
||
CWnd *pSlideWnd=GetDlgItem(IDC_PATTERN_SLIDE);
|
||
if (pWnd && pWnd->m_hWnd==pSlideWnd->m_hWnd)
|
||
{
|
||
CAcModuleResourceOverride vTemp;
|
||
HCURSOR hIcon = AfxGetApp()->LoadCursor( IDC_CUR_PICK );
|
||
SetCursor( hIcon );
|
||
return TRUE;
|
||
}
|
||
return CModelessDialog::OnSetCursor(pWnd, nHitTest, message);
|
||
}
|
||
|
||
void CGraphicDlg::OnCheckRatio()
|
||
{
|
||
CDataExchange dx(this,TRUE);
|
||
DDX_Check(&dx,IDC_CHECK_RATIO,s_bUseRatio);
|
||
BOOL b=GetDlgItem(IDC_RATIO)->EnableWindow(s_bUseRatio);
|
||
if (m_pickSet.Length()>=1)
|
||
{
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
|
||
}
|
||
void CGraphicDlg::OnPatternSlide()
|
||
{
|
||
XString sLibFile, sBlockName;
|
||
sBlockName << (const TCHAR *)m_csCurPattern;
|
||
sLibFile << g_sDwbPath << _T("LinePat.TKW");
|
||
if (!InvokeTkwMan(sLibFile, TRUE, sBlockName)) return;
|
||
XString sLib, sItem;
|
||
if (SplitLibraryPath(sBlockName, sLib, sItem))
|
||
{
|
||
m_csCurPattern = (const TCHAR *)sBlockName;
|
||
XString sSlideName;
|
||
sSlideName << g_sDwbPath << sBlockName;
|
||
CWnd *pWnd=GetDlgItem(IDC_PATTERN_SLIDE);
|
||
CClientDC dc(pWnd);
|
||
CRect cR;
|
||
pWnd->GetClientRect(&cR);
|
||
m_image.InitDC(&dc, cR, GetAcadBackColor());
|
||
m_image.PaintSlide(sSlideName);
|
||
m_image.SetDC(NULL);
|
||
UpdateData(FALSE);
|
||
CRegProperty regProp(::GetRegLocation(), _T("Settings"));
|
||
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
||
regProp.SetValue(_T("LinePattern"), m_csCurPattern);
|
||
}
|
||
UpdateData(FALSE);
|
||
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
void CGraphicDlg::OnRadioUp()
|
||
{
|
||
s_iAlign = 0;
|
||
UpdateData(FALSE);
|
||
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
void CGraphicDlg::OnRadioMiddle()
|
||
{
|
||
s_iAlign=1;
|
||
UpdateData(FALSE);
|
||
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
void CGraphicDlg::OnRadioDown()
|
||
{
|
||
s_iAlign=2;
|
||
UpdateData(FALSE);
|
||
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
void CGraphicDlg::OnRadioAlignMid()
|
||
{
|
||
s_iBase=0;
|
||
UpdateData(FALSE);
|
||
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
void CGraphicDlg::OnRadioAlignLeft()
|
||
{
|
||
s_iBase=1;
|
||
UpdateData(FALSE);
|
||
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
|
||
}
|
||
|
||
void CGraphicDlg::OnRadioAlignRight()
|
||
{
|
||
s_iBase=2;
|
||
UpdateData(FALSE);
|
||
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
|
||
}
|
||
void CGraphicDlg::OnKillFocusRatio()
|
||
{
|
||
UpdateData(TRUE);//add by fxj 2007-6-5
|
||
if (GetFocus()==acedGetAcadFrame())
|
||
{
|
||
m_bUserEsc=FALSE;
|
||
m_nOperCode = 2;
|
||
acedPostCommand(_T("\33"));
|
||
}
|
||
}
|
||
void CGraphicDlg::UpdatePickSet()
|
||
{
|
||
|
||
m_nOperCode = 0;
|
||
m_bUserEsc=TRUE;
|
||
TDocLock lock;
|
||
UpdateData(TRUE);
|
||
|
||
int pickLen=m_pickSet.Length();
|
||
|
||
for(long i=0;i<pickLen;i++)
|
||
{
|
||
Entity ent=m_pickSet[i];
|
||
OPENOBJ_BEGIN(ent,AcDb::kForWrite,TDbPolyPathArray,pRail)
|
||
if (pRail!=NULL)
|
||
{
|
||
g_nCurSel=m_combNameList.GetCurSel();
|
||
|
||
XString sBlockName, sFile;
|
||
sFile << g_sDwbPath <<m_csCurPattern;
|
||
if (LoadDwbBlock(sFile, sBlockName)!=RTNORM)
|
||
return;
|
||
AcDbObjectId idBlock=InitBlock(sBlockName);
|
||
if (s_iAlign==0)
|
||
pRail->SetEqualScale(FALSE);
|
||
else if (s_iAlign==1)
|
||
{
|
||
pRail->SetEqualScale(TRUE);
|
||
pRail->SetAutoExpand(TRUE);
|
||
}
|
||
else
|
||
{
|
||
pRail->SetEqualScale(TRUE);
|
||
pRail->SetAutoExpand(FALSE);
|
||
}
|
||
if (s_iBase==0)
|
||
pRail->SetBaseType(2);
|
||
else if (s_iBase==1)
|
||
pRail->SetBaseType(0);
|
||
else
|
||
pRail->SetBaseType(1);
|
||
|
||
if (s_bUseRatio)
|
||
pRail->SetRatio(s_fRatio/100);
|
||
else
|
||
pRail->SetRatio(1);
|
||
pRail->SetUnitId(idBlock);
|
||
pRail->SetUnitHeight(_tstof(s_strWidth));
|
||
pRail->SetPathPoly(m_polyPath,pRail->GetNormal());
|
||
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
|
||
}
|
||
// [3/19/2008 nsh]
|
||
static BOOL bStart=TRUE;//用于控制消息的循环iStatus的 0→3 | 3→0
|
||
static int iStatus=0;//iStatus为控制状态字,控制线图案显示的外观,iStatus的取值有四个{0,1,2,3}
|
||
static BOOL bFirst=TRUE;//表示第一种状态的初始化态,即iStatus=0,没有发生翻转的情况下
|
||
static BOOL bChange=FALSE;//判断Jig是否有触发【F(翻转)】的热键
|
||
//------------------------------
|
||
class TGraphicEdJig : public TSymbEdJig
|
||
{
|
||
public:
|
||
enum TGraphicOper {kNone=0, kLinePoint=1, kArcPoint=2, kArcMidPoint=3, kArcRadius=4};
|
||
TDbPolyPathArray *m_pRail,m_railLast;//m_railLast为 *m_pRail的最后一段
|
||
protected:
|
||
TGraphicOper m_nOperCode;
|
||
CGraphicDlg *m_pGraphicDlg;
|
||
BOOL m_bFirst;
|
||
BOOL m_bBlockNull;//add by fxj 070606
|
||
public:
|
||
TGraphicEdJig(TDbPolyPathArray*,CGraphicDlg*);
|
||
virtual int DoIt(int *pKeyIndex=NULL);
|
||
virtual DragStatus GetPoint(XPoint &pt);
|
||
protected:
|
||
virtual Adesk::Boolean update();
|
||
virtual AcDbEntity* entity() const;
|
||
public:
|
||
void SetOperCode(TGraphicEdJig::TGraphicOper opCode) {m_nOperCode=opCode;}
|
||
TGraphicOper GetOperCode() {return m_nOperCode;}
|
||
};
|
||
|
||
TGraphicEdJig::TGraphicEdJig(TDbPolyPathArray *pElev,CGraphicDlg *pDlg)
|
||
{
|
||
m_pRail=pElev;
|
||
m_pGraphicDlg=pDlg;
|
||
m_bFirst = TRUE;
|
||
m_bBlockNull = FALSE;
|
||
}
|
||
AcEdJig::DragStatus
|
||
TGraphicEdJig::GetPoint(XPoint &pt)
|
||
{
|
||
DragStatus stat;
|
||
XPoly2D polyPath;
|
||
|
||
AcGeVector3d normal;
|
||
m_pRail->GetPathPoly(polyPath,normal);
|
||
int nLen=polyPath.Length();
|
||
if (nLen>0)
|
||
{
|
||
if (m_bFirst)
|
||
{
|
||
XPoint ptBase = *polyPath[nLen-1];
|
||
stat=acquirePoint(pt, ptBase);
|
||
return stat;
|
||
}
|
||
else
|
||
{
|
||
XPoint ptBase = *polyPath[nLen-2];
|
||
stat=acquirePoint(pt, ptBase);
|
||
return stat;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
stat=acquirePoint(pt);
|
||
return stat;
|
||
}
|
||
}
|
||
|
||
// 开始执行拖动
|
||
int TGraphicEdJig::DoIt(int *keyIndex)
|
||
{
|
||
m_bFirst = TRUE;
|
||
XPoly2D poly2d;
|
||
AcGeVector3d normal;
|
||
m_pRail->GetPathPoly(poly2d,normal);
|
||
if (m_nOperCode==kLinePoint || m_nOperCode==kArcPoint)
|
||
{
|
||
m_ptResult=*poly2d.Tail();
|
||
}
|
||
else if (m_nOperCode==kArcMidPoint)
|
||
{ // MidPoint
|
||
XCurveSegment cv;
|
||
|
||
int nSeg=poly2d.TotalSegments();
|
||
int nRet=poly2d.Nth(nSeg-1,cv);
|
||
m_ptResult=cv.MidPoint();
|
||
}
|
||
int nRet = TSymbEdJig::DoIt(keyIndex);
|
||
|
||
if (m_bBlockNull == TRUE)//add by fxj 070606
|
||
{
|
||
adsout << _T("\n请选择图案样式:");
|
||
}
|
||
|
||
return nRet;
|
||
}
|
||
|
||
|
||
// 更新实体数据
|
||
Adesk::Boolean TGraphicEdJig::update()
|
||
{
|
||
m_pGraphicDlg->UpdateData(TRUE);
|
||
Adesk::Boolean bRet=Adesk::kTrue;
|
||
|
||
//以下是对原有的插入模型控件的图案进行实时修改的操作-----------m_pRail对象操作开始------------------------
|
||
XPoly2D poly2d;
|
||
AcGeVector3d normal;
|
||
m_pRail->GetPathPoly(poly2d,normal);
|
||
int nLen=poly2d.Length();
|
||
if (m_nOperCode==kLinePoint || m_nOperCode==kArcPoint)
|
||
{
|
||
if (m_bFirst)
|
||
{
|
||
m_bFirst = FALSE;
|
||
|
||
poly2d.AppendNode(m_ptResult);
|
||
}
|
||
else
|
||
*poly2d.Tail()=m_ptResult;
|
||
}
|
||
else if (m_nOperCode==kArcMidPoint)
|
||
{
|
||
XDirectionCurve cv;
|
||
int nSeg=poly2d.TotalSegments();
|
||
poly2d.Nth(nSeg-1,cv);
|
||
|
||
XCurveSegment seg;
|
||
seg = XArc(cv.StartPoint(), m_ptResult, cv.EndPoint());
|
||
if (!!seg)
|
||
{
|
||
if (seg.StartPoint().Distance(cv.StartPoint())>_DIST_SNAP)
|
||
{
|
||
// 2010-3-15 17:26 wubo
|
||
// 移植Geo
|
||
seg.SetBulge(-seg.GetBulge());
|
||
}
|
||
poly2d.SetBulge(nLen-2, seg.GetBulge());
|
||
}
|
||
}
|
||
else if (m_nOperCode==kArcRadius)
|
||
{
|
||
XPoint ptBase, ptPrev;
|
||
|
||
ptBase=*poly2d[nLen-1];
|
||
ptPrev=*poly2d[nLen-2];
|
||
|
||
double nChordLen=ptBase.Distance2d(ptPrev);
|
||
double nRadius=ptBase.Distance2d(m_ptResult);
|
||
if (nChordLen<2.0*nRadius+1.0E-6)
|
||
{
|
||
double bulge=2.0*asin(nChordLen/2.0/nRadius);
|
||
if (XLine(ptBase, ptPrev).OnWhichSide(m_ptResult)==OFFSET_LEFT)
|
||
bulge = -bulge;
|
||
poly2d.SetBulge(nLen-1, bulge);
|
||
}
|
||
}
|
||
XString sBlockName, sFile;
|
||
sFile << g_sDwbPath << m_pGraphicDlg->m_csCurPattern;
|
||
|
||
//add by fxj 070606
|
||
if (LoadDwbBlock(sFile, sBlockName)!=RTNORM)
|
||
{
|
||
bRet=Adesk::kFalse;
|
||
m_bFirst=TRUE;
|
||
m_bBlockNull=TRUE;
|
||
return bRet;
|
||
}
|
||
m_bBlockNull=FALSE;
|
||
|
||
m_pRail->SetUnitId(InitBlock(sBlockName));
|
||
m_pRail->SetPathPoly(poly2d,normal);
|
||
if (m_pGraphicDlg->s_iBase==0)
|
||
m_pRail->SetBaseType(2);
|
||
else if (m_pGraphicDlg->s_iBase==1)
|
||
m_pRail->SetBaseType(0);
|
||
else
|
||
m_pRail->SetBaseType(1);//0,左,1,右,2,中
|
||
|
||
if (m_pGraphicDlg->s_iAlign==0)
|
||
m_pRail->SetEqualScale(FALSE);
|
||
else if (m_pGraphicDlg->s_iAlign==1)
|
||
{
|
||
m_pRail->SetEqualScale(TRUE);
|
||
m_pRail->SetAutoExpand(TRUE);
|
||
}
|
||
else
|
||
{
|
||
m_pRail->SetEqualScale(TRUE);
|
||
m_pRail->SetAutoExpand(FALSE);
|
||
}
|
||
|
||
m_pRail->SetUnitHeight(_tstof(m_pGraphicDlg->s_strWidth));
|
||
if (m_pGraphicDlg->s_bUseRatio)
|
||
m_pRail->SetRatio((m_pGraphicDlg->s_fRatio)/100);
|
||
else
|
||
m_pRail->SetRatio(1);
|
||
//-------------------------------------------------m_pRail对象操作结束--------------------------------
|
||
|
||
//以下的代码为Jig拖动时的效果----------------------m_railLast对象的开始-------------------------------
|
||
XPoly2D poly;
|
||
XCurveSegment cv;
|
||
poly2d.Nth(poly2d.TotalSegments()-1,cv);
|
||
cv.AsPoly2D(poly);
|
||
m_railLast.SetUnitId(InitBlock(sBlockName));
|
||
if (m_pGraphicDlg->s_iBase==0)
|
||
m_railLast.SetBaseType(2);
|
||
else if (m_pGraphicDlg->s_iBase==1)
|
||
m_railLast.SetBaseType(0);
|
||
else
|
||
m_railLast.SetBaseType(1);//0,左,1,右,2,中
|
||
|
||
if (m_pGraphicDlg->s_iAlign==0)
|
||
m_railLast.SetEqualScale(FALSE);
|
||
else if (m_pGraphicDlg->s_iAlign==1)
|
||
{
|
||
m_railLast.SetEqualScale(TRUE);
|
||
m_railLast.SetAutoExpand(TRUE);
|
||
}
|
||
else
|
||
{
|
||
m_railLast.SetEqualScale(TRUE);
|
||
m_railLast.SetAutoExpand(FALSE);
|
||
}
|
||
m_railLast.SetUnitHeight(_tstof(m_pGraphicDlg->s_strWidth));
|
||
if (m_pGraphicDlg->s_bUseRatio)
|
||
m_railLast.SetRatio((m_pGraphicDlg->s_fRatio)/100);
|
||
else
|
||
m_railLast.SetRatio(1);
|
||
// [3/18/2008 nsh]
|
||
//-------------begin-------------
|
||
if (bChange)
|
||
{
|
||
switch(iStatus)
|
||
{
|
||
case 0:
|
||
{
|
||
if (!bFirst)
|
||
{
|
||
poly.Reverse();
|
||
m_railLast.Reverse();
|
||
}
|
||
}
|
||
break;
|
||
case 1:
|
||
case 2:
|
||
case 3:
|
||
{
|
||
m_railLast.Reverse();
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
bChange=FALSE;
|
||
}
|
||
if (iStatus==2 || iStatus==3)
|
||
poly.Reverse();
|
||
m_railLast.SetPathPoly(poly,AcGeVector3d(0,0,1));
|
||
//-----------end-----------------
|
||
//-----------------------------------------m_railLast对象操作结束---------------------------
|
||
return bRet;
|
||
}
|
||
|
||
AcDbEntity* TGraphicEdJig::entity() const
|
||
{
|
||
return (AcDbEntity*)&m_railLast;//以JIG只显示最后一段
|
||
}
|
||
|
||
void myGraphic()
|
||
{
|
||
|
||
CAcModuleResourceOverride vTemp;
|
||
CGraphicDlg dlg;
|
||
if (!dlg.Create(dlg.IDD, NULL))
|
||
return;
|
||
dlg.ShowWindow(SW_SHOW);
|
||
acedGetAcadFrame()->SetFocus();
|
||
// [3/19/2008 nsh]
|
||
//回到初始化态
|
||
bStart=TRUE;
|
||
bChange=FALSE;
|
||
//------------------
|
||
while(1)
|
||
{ //第一个循环
|
||
Nstat: dlg.m_bUserEsc=TRUE;
|
||
if (dlg.m_bDynamic)
|
||
{
|
||
int nRet;
|
||
XPoint ptStart;
|
||
XPoly2D poly2d;
|
||
AcGeVector3d normal(0,0,1);
|
||
|
||
dlg.m_pickSet.Free();
|
||
|
||
nRet = ads_getpoint(NULL, _T("\n起点<退出>: "), ptStart);
|
||
|
||
if (nRet==RTCAN)
|
||
{
|
||
if (!dlg.m_bUserEsc)
|
||
{
|
||
if (dlg.m_nOperCode==1)
|
||
dlg.SetGraphicWidth();
|
||
|
||
continue;
|
||
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
else if (nRet == RTNORM)
|
||
{
|
||
|
||
ptStart = Ucs2Wcs(ptStart);
|
||
poly2d.InsertNodeAt(0, ptStart);
|
||
|
||
}
|
||
else
|
||
break;
|
||
TDbPolyPathArray ent;
|
||
ent.SetPathPoly(poly2d,ent.GetNormal());
|
||
dlg.m_polyPath.InsertNodeAt(0,ptStart);
|
||
TGraphicEdJig jig(&ent,&dlg);
|
||
|
||
//add by xlc on 090505 06以下平台资源冲突
|
||
CAcModuleResourceOverride resOverride(acedGetAcadResourceInstance());
|
||
|
||
jig.SetKeyword(_T("A U F"));
|
||
jig.SetOperCode(TGraphicEdJig::kLinePoint);
|
||
jig.SetPrompt(_T("\n直段下一点或 [弧段(A)/回退(U)/翻转(F)]<结束>:"));
|
||
|
||
while(1)
|
||
{//第二个循环 Jig的拖动循环
|
||
int nKeyIndex;
|
||
|
||
BOOL bBreak=FALSE;
|
||
int nRet = jig.DoIt(&nKeyIndex);
|
||
if (nRet == RTNORM)
|
||
{//nRet==RTNORM开始
|
||
ent.GetPathPoly(poly2d,normal);
|
||
if (jig.GetOperCode()==TGraphicEdJig::kArcPoint) //弧段begin
|
||
{
|
||
TGraphicEdJig jig1(&ent,&dlg);
|
||
jig1.SetOperCode(TGraphicEdJig::kArcMidPoint);
|
||
jig1.SetPrompt(_T("\n点取弧上一点或 [输入半径(R)]:"));
|
||
jig1.SetKeyword(_T("R"));
|
||
while(1)
|
||
{//第三个循环
|
||
int nRetCode1=jig1.DoIt();
|
||
if (nRetCode1 == RTNORM)
|
||
{
|
||
ent.GetPathPoly(poly2d,normal);
|
||
break;
|
||
}
|
||
else if (nRetCode1==RTKWORD)
|
||
{
|
||
TGraphicEdJig jig2(&ent,&dlg);
|
||
jig2.SetOperCode(TGraphicEdJig::kArcRadius);
|
||
jig2.SetPrompt(_T("\n输入半径(光标位置确定弧的方向):"));
|
||
while(1)
|
||
{
|
||
int nRetCode2 = jig2.DoIt();
|
||
if (nRetCode2 == RTNORM)
|
||
{
|
||
ent.GetPathPoly(poly2d,normal);
|
||
bBreak=TRUE;
|
||
break;
|
||
}
|
||
else if (nRetCode2==RTCAN)
|
||
{
|
||
if (!dlg.m_bUserEsc)
|
||
{
|
||
if (dlg.m_nOperCode==1)
|
||
{
|
||
dlg.SetGraphicWidth();
|
||
|
||
jig.m_pRail->GetPathPoly(poly2d,normal);
|
||
int nLen=poly2d.Length();
|
||
if (nLen>1)
|
||
{
|
||
poly2d.Remove(nLen-1);
|
||
poly2d.RemoveBugle(nLen-1);
|
||
jig.m_pRail->SetPathPoly(poly2d,normal);
|
||
}
|
||
continue;
|
||
}
|
||
else if (dlg.m_nOperCode==2)
|
||
{
|
||
if (dlg.m_pickSet.Length()>=1)
|
||
dlg.UpdatePickSet();
|
||
jig.m_pRail->GetPathPoly(poly2d,normal);
|
||
int nLen=poly2d.Length();
|
||
if (nLen>1)
|
||
{
|
||
poly2d.Remove(nLen-1);
|
||
poly2d.RemoveBugle(nLen-1);
|
||
jig.m_pRail->SetPathPoly(poly2d,normal);
|
||
}
|
||
|
||
|
||
continue;
|
||
}
|
||
else
|
||
goto Nstat;
|
||
|
||
}
|
||
else
|
||
{
|
||
if (::IsWindow(dlg.m_hWnd))
|
||
dlg.DestroyWindow();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (::IsWindow(dlg.m_hWnd))
|
||
dlg.DestroyWindow();
|
||
return;
|
||
}
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
if (!dlg.m_bUserEsc)
|
||
{
|
||
if (dlg.m_nOperCode==1)
|
||
{
|
||
dlg.SetGraphicWidth();
|
||
|
||
jig.m_pRail->GetPathPoly(poly2d,normal);
|
||
int nLen=poly2d.Length();
|
||
if (nLen>1)
|
||
{
|
||
poly2d.Remove(nLen-1);
|
||
poly2d.RemoveBugle(nLen-1);
|
||
jig.m_pRail->SetPathPoly(poly2d,normal);
|
||
}
|
||
continue;
|
||
}
|
||
else if (dlg.m_nOperCode==2)
|
||
{
|
||
if (dlg.m_pickSet.Length()>=1)
|
||
dlg.UpdatePickSet();
|
||
jig.m_pRail->GetPathPoly(poly2d,normal);
|
||
int nLen=poly2d.Length();
|
||
if (nLen>1)
|
||
{
|
||
poly2d.Remove(nLen-1);
|
||
poly2d.RemoveBugle(nLen-1);
|
||
jig.m_pRail->SetPathPoly(poly2d,normal);
|
||
}
|
||
continue;
|
||
}
|
||
else
|
||
goto Nstat;
|
||
}
|
||
else
|
||
{
|
||
if (::IsWindow(dlg.m_hWnd))
|
||
dlg.DestroyWindow();
|
||
return;
|
||
}
|
||
}
|
||
if (bBreak==TRUE)
|
||
break;
|
||
}//第三个循环结束
|
||
}//弧段end
|
||
jig.m_pRail->GetPathPoly(poly2d,normal);
|
||
dlg.m_polyPath=poly2d;
|
||
if (poly2d.Length()<=2)
|
||
{
|
||
dlg.m_pickSet.Free();
|
||
dlg.m_pickSet+=AddToCurrentSpace((TDbEntity *)ent.clone(),Adesk::kTrue);
|
||
// [12/11/2007 nsh]
|
||
//---------------begin------------
|
||
Entity ent1=dlg.m_pickSet[0L];
|
||
OPENOBJ_BEGIN(ent1,AcDb::kForWrite,TDbPolyPathArray,pRail)
|
||
XPoly2D poly;
|
||
AcGeVector3d vt(0,0,1);
|
||
pRail->GetPathPoly(poly,vt);
|
||
switch(iStatus)
|
||
{
|
||
case 0:
|
||
{
|
||
if (bFirst)
|
||
{
|
||
bFirst=FALSE;
|
||
}
|
||
else
|
||
{
|
||
poly.Reverse();
|
||
pRail->Reverse();
|
||
}
|
||
}
|
||
break;
|
||
case 1:
|
||
{
|
||
pRail->Reverse();
|
||
}
|
||
break;
|
||
case 2:
|
||
{
|
||
poly.Reverse();
|
||
}
|
||
break;
|
||
case 3:
|
||
{
|
||
pRail->Reverse();
|
||
poly.Reverse();
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
pRail->SetPathPoly(poly,vt);
|
||
OPENOBJ_END()
|
||
bStart =FALSE;
|
||
//-------------end---------------
|
||
|
||
int pickLen=dlg.m_pickSet.Length();
|
||
}
|
||
else//实体修改
|
||
{
|
||
if (dlg.m_pickSet.Length()>=1)
|
||
{
|
||
int setLen=dlg.m_pickSet.Length();
|
||
Entity ent1=dlg.m_pickSet[0L];
|
||
OPENOBJ_BEGIN(ent1,AcDb::kForWrite,TDbPolyPathArray,pRail)
|
||
if (pRail!=NULL)
|
||
{
|
||
XPoly2D polypre(poly2d);
|
||
// [12/6/2007 nsh]
|
||
AcGeVector3d vt(0,0,1);
|
||
if (iStatus ==2 || iStatus ==3)
|
||
{
|
||
polypre.Reverse();
|
||
}
|
||
pRail->SetPathPoly(polypre,AcGeVector3d(0,0,1));
|
||
//-----------------------------
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
}
|
||
jig.SetPrompt(_T("\n直段下一点或 [弧段(A)/回退(U)/翻转(F)]<结束>: "));
|
||
jig.SetOperCode(TGraphicEdJig::kLinePoint);
|
||
jig.SetKeyword(_T("A U F"));
|
||
}//end RTNORM
|
||
else if (nRet == RTKWORD)
|
||
{
|
||
if (jig.GetOperCode()==TGraphicEdJig::kLinePoint)
|
||
{
|
||
// [11/27/2007 nsh]
|
||
//-----------------begin--------------
|
||
if (nKeyIndex ==2)
|
||
{
|
||
bChange=TRUE;//让Jig中拖动效果只改变一次
|
||
if (bStart)
|
||
{
|
||
if (iStatus >=3)
|
||
{
|
||
iStatus =0;
|
||
}
|
||
else
|
||
iStatus +=1;
|
||
}
|
||
else
|
||
{
|
||
if (iStatus >=3)
|
||
{
|
||
iStatus=0;
|
||
}
|
||
else
|
||
iStatus+=1;
|
||
Entity ent1=dlg.m_pickSet[0L];
|
||
OPENOBJ_BEGIN(ent1,AcDb::kForWrite,TDbPolyPathArray,pRail)
|
||
XPoly2D poly;
|
||
AcGeVector3d vt(0,0,1);
|
||
pRail->GetPathPoly(poly,vt);
|
||
switch(iStatus)
|
||
{
|
||
case 0:
|
||
{
|
||
if (bFirst)
|
||
{
|
||
bFirst=FALSE;
|
||
}
|
||
else
|
||
{
|
||
poly.Reverse();
|
||
pRail->Reverse();
|
||
}
|
||
}
|
||
break;
|
||
case 1:
|
||
{
|
||
pRail->Reverse();
|
||
}
|
||
break;
|
||
case 2:
|
||
{
|
||
pRail->Reverse();
|
||
poly.Reverse();
|
||
}
|
||
break;
|
||
case 3:
|
||
{
|
||
poly.Reverse();
|
||
pRail->Reverse();
|
||
poly.Reverse();
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
pRail->SetPathPoly(poly,vt);
|
||
OPENOBJ_END()
|
||
}
|
||
}
|
||
//-------------------end------------
|
||
if (nKeyIndex==0)
|
||
{
|
||
jig.SetOperCode(TGraphicEdJig::kArcPoint);
|
||
jig.SetPrompt(_T("\n弧段下一点或 [直段(L)/回退(U)]<结束>: "));
|
||
jig.SetKeyword(_T("L U"));
|
||
}
|
||
else if (nKeyIndex==1) //回退
|
||
{
|
||
int nLen = poly2d.Length();
|
||
if (nLen<=2)// [3/20/2008 nsh]//使第一种状态回到初始化态
|
||
bFirst=TRUE;
|
||
if (nLen>1)
|
||
{
|
||
XPoly2D polyPre(poly2d);
|
||
poly2d.Remove(nLen-1);
|
||
poly2d.RemoveBugle(nLen-2);
|
||
|
||
Entity ent1=dlg.m_pickSet[0L];
|
||
OPENOBJ_BEGIN(ent1,AcDb::kForWrite,TDbPolyPathArray,pRail)
|
||
if (pRail!=NULL)
|
||
{
|
||
polyPre.RemoveNode(polyPre.Length()-1);
|
||
pRail->SetPathPoly(polyPre,AcGeVector3d(0,0,1));
|
||
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
}
|
||
}
|
||
else if (jig.GetOperCode()==TGraphicEdJig::kArcPoint)
|
||
{
|
||
if (nKeyIndex==0)
|
||
{
|
||
jig.SetOperCode(TGraphicEdJig::kLinePoint);
|
||
jig.SetPrompt(_T("\n直段下一点或 [弧段(A)/回退(U)]<结束>: "));
|
||
jig.SetKeyword(_T("A U F"));
|
||
}
|
||
else if (nKeyIndex==1)
|
||
{
|
||
int nLen = poly2d.Length();
|
||
if (nLen>1)
|
||
{
|
||
poly2d.Remove(nLen-1);
|
||
poly2d.RemoveBugle(nLen-1);
|
||
}
|
||
}
|
||
}
|
||
ent.SetPathPoly(poly2d,normal);
|
||
}
|
||
else if (nRet == RTNONE)
|
||
{
|
||
// [12/11/2007 nsh]
|
||
//回到初始化
|
||
iStatus=0;
|
||
bFirst=TRUE;
|
||
bStart =TRUE;
|
||
//---------------
|
||
ent.SetPathPoly(poly2d,normal);
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
if (!dlg.m_bUserEsc)
|
||
{
|
||
if (dlg.m_nOperCode==1)
|
||
{
|
||
dlg.SetGraphicWidth();
|
||
|
||
jig.m_pRail->GetPathPoly(poly2d,normal);
|
||
int nLen=poly2d.Length();
|
||
if (nLen>1)
|
||
{
|
||
poly2d.Remove(nLen-1);
|
||
poly2d.RemoveBugle(nLen-1);
|
||
jig.m_pRail->SetPathPoly(poly2d,normal);
|
||
}
|
||
continue;
|
||
}
|
||
else if (dlg.m_nOperCode==2)
|
||
{
|
||
if (dlg.m_pickSet.Length()>=1)
|
||
dlg.UpdatePickSet();
|
||
jig.m_pRail->GetPathPoly(poly2d,normal);
|
||
int nLen=poly2d.Length();
|
||
if (nLen>1)
|
||
{
|
||
poly2d.Remove(nLen-1);
|
||
poly2d.RemoveBugle(nLen-1);
|
||
jig.m_pRail->SetPathPoly(poly2d,normal);
|
||
}
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
bChange=TRUE;
|
||
bFirst=TRUE;// [3/20/2008 nsh]//使第一种状态回到初始化
|
||
goto Nstat;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// [12/11/2007 nsh]
|
||
//回到初始化
|
||
iStatus=0;
|
||
bFirst=TRUE;
|
||
bStart =TRUE;
|
||
//---------------
|
||
if (::IsWindow(dlg.m_hWnd))
|
||
dlg.DestroyWindow();
|
||
return;
|
||
}
|
||
}
|
||
}//第二个循环结束
|
||
|
||
// AddToCurrentSpace((TDbEntity *)ent.clone(),Adesk::kTrue);
|
||
}
|
||
else//选择路径
|
||
{
|
||
RBList rbMask(RTDXF0, _T("LINE,ARC,POLYLINE,LWPOLYLINE,CIRCLE"), NULL);
|
||
Entity ent;
|
||
int nRet=SelectEntity(_T("\n请选择作为路径的曲线(线/圆/弧/多段线)<退出>:"),ent,rbMask);
|
||
if (nRet==RTCAN&&!dlg.m_bUserEsc)
|
||
{
|
||
if (dlg.m_nOperCode==1)
|
||
dlg.SetGraphicWidth();
|
||
continue;
|
||
}
|
||
else if (nRet!=RTNORM)
|
||
break;
|
||
dlg.m_bRail=FALSE;
|
||
dlg.UpdateData(TRUE);
|
||
XPoly2D basePoly(ent);
|
||
if (!basePoly)
|
||
{
|
||
XCurveSegment segTemp(ent);
|
||
if (!segTemp)
|
||
return;
|
||
segTemp.AsPoly2D(basePoly);
|
||
}
|
||
dlg.m_polyPath=basePoly;
|
||
dlg.g_nCurSel=dlg.m_combNameList.GetCurSel();
|
||
PickSet ssRail(SS_FREE);
|
||
ssRail.IncludeBegin();
|
||
if (!dlg.m_bRail)
|
||
{
|
||
dlg.DoDrawing(dlg.g_nCurSel);
|
||
}
|
||
ssRail.IncludeEnd();
|
||
dlg.m_pickSet=ssRail;
|
||
Entity ent1=ssRail[0L]; //yes or no
|
||
adsout << _T("\n确定[Y]或 取消[N]:<Y>");
|
||
while(1)//选择路径后的确定
|
||
{
|
||
TCHAR sInput[256]=_T("");
|
||
INITGET_BEG(RSG_NONEG, _T("Y N"));
|
||
int nRet=acedGetKword(_T("\n是否确定?[是(Y)/否(N)]<Y>:"),sInput);
|
||
INITGET_END()
|
||
if (nRet==RTNORM)
|
||
{
|
||
|
||
if (sInput[0]==_T('Y'))
|
||
break;
|
||
else if (sInput[0]==_T('N'))
|
||
{
|
||
ent1.Erase();
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
if (!dlg.m_bUserEsc)
|
||
{
|
||
if (dlg.m_nOperCode==1)
|
||
dlg.SetGraphicWidth();
|
||
else if (dlg.m_nOperCode==2)
|
||
dlg.UpdatePickSet();
|
||
else
|
||
break;
|
||
}
|
||
else
|
||
break;
|
||
|
||
}
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
}
|
||
}//第一个循环结束
|
||
if (::IsWindow(dlg.m_hWnd))
|
||
dlg.DestroyWindow();
|
||
}
|