![]() ![]() |
||
Steps: 1. Create new class CMyToolBoxBar for new style of toolbox window. 2. Create a new class CMyDoubleLineShape that use CFOPAdvAnchorShape as base class, this new class has one anchors to change the space between these two lines 3. Create a new class CMyIntersectShape that use CFOPAdvAnchorShape as base class, this new class has three anchors. 4. Create a new class CMyThreeLineShape that use CFOPAdvAnchorShape as base class, this new shape has a anchor to change the space between these three lines. 5. Draw new line, call: void CCircuitView::OnDrawMyline() { // TODO: Add your command handler code here m_drawshape = MY_DOUBLELINE; SetCurrentDrawingCursor(IDC_FO_DRAW_DIMLINE); m_action_state = State_DrawDimLine; m_bUpRightMode = FALSE; } void CCircuitView::OnUpdateDrawMyline(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here BOOL bDesign = GetCurrentModel()->IsDesignMode(); pCmdUI->Enable(bDesign); pCmdUI->SetCheck(m_drawshape == MY_DOUBLELINE); } CPoint CCircuitView::CalcNewAnchorPoint(const CPoint &ptStart,const CPoint &ptEnd,const CPoint &ptCompare,const double &dWidth) const { double slopy , cosy , siny; // Draw first line. slopy = atan2( (double)( ptStart.y - ptEnd.y ),(double)( ptStart.x - ptEnd.x ) ); cosy = cos( slopy ); siny = sin( slopy ); // 下面是相对一个顶点计算的点 CPoint pt = CPoint(CFODrawHelper::RoundValue((double)((double)ptCompare.x + dWidth * siny )), CFODrawHelper::RoundValue((double)((double)ptCompare.y - dWidth * cosy ))); return pt; } // Default dimension line length. const int fo_DefaultDimLen = 40; CPoint CCircuitView::GeneratePoints(const CPoint &ptStart,const CPoint &ptEnd,LPPOINT cCtlPt) const { ///////////////////////////////// // 5 6 // | | // | | | // 0--2----------3--1 // | // | // 4 //////////////////////////////// CPoint ptReturn; cCtlPt[0] = ptStart; cCtlPt[1] = ptEnd; CPoint ptCalc = CPoint((ptStart.x + ptEnd.x)/2,(ptStart.y + ptEnd.y)/2); cCtlPt[6] = ptCalc; CPoint ptCenter = CPoint((ptStart.x + ptCalc.x)/2,(ptStart.y + ptCalc.y)/2); cCtlPt[2] = ptCenter; ptCenter = CPoint((ptEnd.x + ptCalc.x)/2,(ptEnd.y + ptCalc.y)/2); cCtlPt[3] = ptCenter; double Par1 = 10; CPoint m_ptLineStart,m_ptLineEnd; m_ptLineStart = ptStart; m_ptLineEnd = ptEnd; // Draw first line. cCtlPt[6] = CalcNewAnchorPoint(m_ptLineStart,m_ptLineEnd,ptCalc,Par1); ptReturn = cCtlPt[2]; // Draw first line. Par1 = fo_DefaultDimLen; ptCenter = CPoint((ptStart.x + ptCalc.x)/2,(ptStart.y + ptCalc.y)/2); cCtlPt[5] = CalcNewAnchorPoint(m_ptLineStart,m_ptLineEnd,ptCenter,Par1); // Draw first line. Par1 = -fo_DefaultDimLen; ptCenter = CPoint((ptEnd.x + ptCalc.x)/2,(ptEnd.y + ptCalc.y)/2); cCtlPt[4] = CalcNewAnchorPoint(m_ptLineStart,m_ptLineEnd,ptCenter,Par1); return ptReturn; } void CCircuitView::OnDrawTrackDimLine(CPoint ptTrackDev) { if(m_drawshape == MY_DOUBLELINE) { m_ptMouseDown = ptTrackDev; CPoint ptTrack = m_ptMouseDown; FODPtoLP(&ptTrack, 1); LimitDrawShapeTrackPoint(&m_ptCurrentLog, &ptTrack, 1); FOLPtoDP(&ptTrack, 1); POINT pptPoints[4]; pptPoints[0] = m_ptCurrentDevice; pptPoints[1] = ptTrack; long Par1 = fo_DefaultDimLen; // Prepare dc. CFOWndDC dc(this,FALSE); PrepareTrackLineDC(&dc); CPoint m_ptLineStart,m_ptLineEnd; double slopy , cosy , siny; m_ptLineStart = m_ptCurrentDevice; m_ptLineEnd = ptTrack; // Draw first line. slopy = atan2( (double)( m_ptLineStart.y - m_ptLineEnd.y ),(double)( m_ptLineStart.x - m_ptLineEnd.x ) ); cosy = cos( slopy ); siny = sin( slopy ); CPoint pt; pt = CPoint(CFODrawHelper::RoundValue((double)(m_ptLineStart.x + int( Par1 * siny ) )), CFODrawHelper::RoundValue((double)(m_ptLineStart.y - int( Par1 * cosy ) ))); CFODrawHelper::MirrorPointX(pt,m_ptLineStart,m_ptLineEnd); pptPoints[2] = pt; // Draw end line. m_ptLineStart = ptTrack; m_ptLineEnd = m_ptCurrentDevice; slopy = atan2( (double)( m_ptLineStart.y - m_ptLineEnd.y ),(double)( m_ptLineStart.x - m_ptLineEnd.x ) ); cosy = cos( slopy ); siny = sin( slopy ); pt = CPoint(CFODrawHelper::RoundValue((double)(m_ptLineStart.x + int( Par1 * siny ) )), CFODrawHelper::RoundValue((double)(m_ptLineStart.y - int( Par1 * cosy ) ))); pptPoints[3] = pt; dc.MoveTo(pptPoints[0]); dc.LineTo(pptPoints[1]); dc.MoveTo(pptPoints[2]); dc.LineTo(pptPoints[3]); // Clear dc. ClearTrackLineDC(&dc); } else if(m_drawshape == MY_INTERSECTLINE) { m_ptMouseDown = ptTrackDev; CPoint ptTrack = m_ptMouseDown; FODPtoLP(&ptTrack, 1); LimitDrawShapeTrackPoint(&m_ptCurrentLog, &ptTrack, 1); FOLPtoDP(&ptTrack, 1); POINT pptPoints[7]; GeneratePoints(m_ptCurrentDevice,ptTrack,pptPoints); // Prepare dc. CFOWndDC dc(this,FALSE); PrepareTrackLineDC(&dc); dc.MoveTo(pptPoints[0]); dc.LineTo(pptPoints[1]); dc.MoveTo(pptPoints[2]); dc.LineTo(pptPoints[5]); dc.MoveTo(pptPoints[3]); dc.LineTo(pptPoints[4]); CPoint ptCenter = pptPoints[2]; int nWidth = (int)(10 / 2); CRect rc = CRect(ptCenter.x - nWidth,ptCenter.y - nWidth,ptCenter.x + nWidth,ptCenter.y + nWidth); dc.Ellipse(&rc); ptCenter = pptPoints[3]; rc = CRect(ptCenter.x - nWidth,ptCenter.y - nWidth,ptCenter.x + nWidth,ptCenter.y + nWidth); dc.Ellipse(&rc); // Clear dc. ClearTrackLineDC(&dc); } else if(m_drawshape == MY_THREEINE) { m_ptMouseDown = ptTrackDev; CPoint ptTrack = m_ptMouseDown; FODPtoLP(&ptTrack, 1); LimitDrawShapeTrackPoint(&m_ptCurrentLog, &ptTrack, 1); FOLPtoDP(&ptTrack, 1); POINT pptPoints[6]; pptPoints[0] = m_ptCurrentDevice; pptPoints[1] = ptTrack; long Par1 = fo_DefaultDimLen; // Prepare dc. CFOWndDC dc(this,FALSE); PrepareTrackLineDC(&dc); CPoint m_ptLineStart,m_ptLineEnd; double slopy , cosy , siny; m_ptLineStart = m_ptCurrentDevice; m_ptLineEnd = ptTrack; // Draw first line. slopy = atan2( (double)( m_ptLineStart.y - m_ptLineEnd.y ),(double)( m_ptLineStart.x - m_ptLineEnd.x ) ); cosy = cos( slopy ); siny = sin( slopy ); CPoint pt; pt = CPoint(CFODrawHelper::RoundValue((double)(m_ptLineStart.x + int( Par1 * siny ) )), CFODrawHelper::RoundValue((double)(m_ptLineStart.y - int( Par1 * cosy ) ))); CFODrawHelper::MirrorPointX(pt,m_ptLineStart,m_ptLineEnd); pptPoints[2] = pt; CPoint ptTemp = pt; CFODrawHelper::MirrorPointX(ptTemp,m_ptLineStart,m_ptLineEnd); pptPoints[4] = ptTemp; // Draw end line. m_ptLineStart = ptTrack; m_ptLineEnd = m_ptCurrentDevice; slopy = atan2( (double)( m_ptLineStart.y - m_ptLineEnd.y ),(double)( m_ptLineStart.x - m_ptLineEnd.x ) ); cosy = cos( slopy ); siny = sin( slopy ); pt = CPoint(CFODrawHelper::RoundValue((double)(m_ptLineStart.x + int( Par1 * siny ) )), CFODrawHelper::RoundValue((double)(m_ptLineStart.y - int( Par1 * cosy ) ))); pptPoints[3] = pt; ptTemp = pt; CFODrawHelper::MirrorPointX(ptTemp,m_ptLineStart,m_ptLineEnd); pptPoints[5] = ptTemp; dc.MoveTo(pptPoints[0]); dc.LineTo(pptPoints[1]); dc.MoveTo(pptPoints[2]); dc.LineTo(pptPoints[3]); dc.MoveTo(pptPoints[4]); dc.LineTo(pptPoints[5]); // Clear dc. ClearTrackLineDC(&dc); } else { CFOPCanvasCore::OnDrawTrackDimLine(ptTrackDev); } } void CCircuitView::OnDrawMythreeline() { // TODO: Add your command handler code here m_drawshape = MY_THREEINE; SetCurrentDrawingCursor(IDC_FO_DRAW_DIMLINE); m_action_state = State_DrawDimLine; m_bUpRightMode = FALSE; } void CCircuitView::OnUpdateDrawMythreeline(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here BOOL bDesign = GetCurrentModel()->IsDesignMode(); pCmdUI->Enable(bDesign); pCmdUI->SetCheck(m_drawshape == MY_THREEINE); } void CCircuitView::OnDrawMyintersectline() { // TODO: Add your command handler code here m_drawshape = MY_INTERSECTLINE; SetCurrentDrawingCursor(IDC_FO_DRAW_DIMLINE); m_action_state = State_DrawDimLine; m_bUpRightMode = FALSE; } void CCircuitView::OnUpdateDrawMyintersectline(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here BOOL bDesign = GetCurrentModel()->IsDesignMode(); pCmdUI->Enable(bDesign); pCmdUI->SetCheck(m_drawshape == MY_INTERSECTLINE); }
|
Copyright ?1998-2007 UCanCode.Net Software, all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.
Please direct your questions or comments to webmaster@ucancode.com