#include "stdafx.h" #include "SigmaDoc.h" #include "ItemPointProcess.h" #include "ActionComboItem.h" #include "ActionEmbellishItem.h" NItem::CItemPointProcess::CItemPointProcess(CSigmaDoc * ppDoc) : CItemFocusRect(ppDoc) , angle(0) , m_processCount(0) , m_idea(0) { this->SetType(ITEM_POINT_PROCESS); } NItem::CItemPointProcess::~CItemPointProcess(void) { } void NItem::CItemPointProcess::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk) { m_processCount = 0; if (m_idea != POINT_POLYGON_REL) CItemFocusRect::OnLButtonDown(pDC, nFlags, point, vk); else { position = SelectOneCurve(nFlags, point); if (position) DoLButtonUp(pDC); } } //BOOL NItem::CItemPointProcess::OnSetCursor(CWnd * pWnd, UINT nHitTest, UINT message) //{ // if (m_idea == POINT_POLYGON_REL) // { // GetDoc()->GetCursor().SetCursor(CursorSelectItem); // return GetDoc()->GetCursor().SetCursor(); // } // return CItemFocusRect::OnSetCursor(pWnd, nHitTest, message); //} void NItem::CItemPointProcess::DoLButtonUp(CDC* pDC) { int count = 0; switch (m_idea) { case POINT_NULL_EMBELLISH: count = SetNullEmbellish(); break; case POINT_SET_EMBELLISH: count = SetEmbellish(); break; case POINT_SET_ANGLE: count = SetAngle(); break; case POINT_POLYGON_REL: ReliabilityPolygon(); break; case POINT_RECT_REL: ReliabilityRect(); break; } m_processCount = count; //if (count > 0) //{ // GetDoc()->SetModifiedFlag(); // GetDoc()->Invalidate(); //} //GetDoc()->EnableDefaultTool(); } void NItem::CItemPointProcess::SetProcessIdea(int nIdea) { m_idea = nIdea; } void NItem::CItemPointProcess::SetPointStyle(CHowToViewPoint& ptStyle) { this->ptStyle = ptStyle; } int NItem::CItemPointProcess::SetNullEmbellish(void) { CRect8 rect = this->GetRect(); CList select; m_pDoc->m_pXy->IsInRange(rect, select); if (select.IsEmpty()) return 0; int count = 0; POSITION pos, pt; COne* pOne; //为了修饰的Redo/Undo CActionComboItem *pAction = new CActionComboItem(GetDoc(), IDS_GI_EMBELLISH_SELF); pos = select.GetHeadPosition(); while (pos) { CSigmaDoc* p = m_pDoc; pt = select.GetNext(pos); pOne = m_pDoc->m_pXy->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_POINT && pOne->GetType() != DOUBLEFOX_XYZ && pOne->GetType() != DOUBLEFOX_XPOINT)continue; if (pOne->HowToViewPoint == NULL) continue; ////for undo/redo CActionEmbellishItem* pActionItem = new CActionEmbellishItem(GetDoc(), 0, pOne); pActionItem->SetOldHowToView(pOne); //备份老修饰 pAction->AddAction(pActionItem); delete pOne->HowToViewPoint; pOne->HowToViewPoint = NULL; count++; } if (count > 0) { m_pDoc->Modified(); GetDoc()->SetActionItem(pAction); } else { delete pAction; } return count; } int NItem::CItemPointProcess::SetEmbellish(void) { //CXTPResizePropertySheet sheet(IDS_STRING_PANE_PROPERTIES, GetView()); //sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW; //CEmbellishPage page; ////page.SetUnit(GetDoc()->GetDraw()->GetUnit()); //page.SetUnitMode(GetUnitMode().m_unit, GetUnitMode().m_dScaleFactor, GetUnitMode().m_nMode); //page.m_select = 1; //sheet.AddPage(&page); //if (sheet.DoModal() != IDOK) return 0; //if (page.GetHowToViewPoint() == NULL) return 0; CRect8 rect = this->GetRect(); CList select; GetDoc()->GetDraw()->IsInRange(rect, select); int count = 0; POSITION pos, pt; COne* pOne; ////为了修饰的Redo/Undo CActionComboItem *pAction = new CActionComboItem(GetDoc(), IDS_GI_EMBELLISH_SELF); pos = select.GetHeadPosition(); while (pos) { pt = select.GetNext(pos); pOne = GetDoc()->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_POINT && pOne->GetType() != DOUBLEFOX_XYZ && pOne->GetType() != DOUBLEFOX_XPOINT)continue; ////for undo/redo CActionEmbellishItem* pActionItem = new CActionEmbellishItem(GetDoc(), 0, pOne); pActionItem->SetOldHowToView(pOne); //备份老修饰 if (pOne->HowToViewPoint) delete pOne->HowToViewPoint; pOne->HowToViewPoint = new CHowToViewPoint(); *pOne->HowToViewPoint = this->ptStyle; //*pOne->HowToViewPoint = *page.GetHowToViewPoint(); ////for undo/redo pActionItem->SetNewHowToView(pOne); //备份新修饰 pAction->AddAction(pActionItem); count++; } if (count > 0) { m_pDoc->Modified(); GetDoc()->SetActionItem(pAction); } else { delete pAction; } return count; } int NItem::CItemPointProcess::SetAngle(void) { CRect8 rect = this->GetRect(); CList select; GetDoc()->GetDraw()->IsInRange(rect, select); if (select.IsEmpty()) return 0; int count = 0; POSITION pos, pt; COne* pOne; pos = select.GetHeadPosition(); while (pos) { pt = select.GetNext(pos); pOne = GetDoc()->GetDraw()->GetAt(pt); switch (pOne->GetType()) { case DOUBLEFOX_XYZ: case DOUBLEFOX_POINT: { CPointNameEx* pPoint = (CPointNameEx*)pOne->GetValue(); pPoint->angle = AfxGetPublicFunction()->GetAngleWithBL(GetDoc()->GetDraw()->GetProjection(), pPoint->x0, pPoint->y0); } count++; break; case DOUBLEFOX_TEXT: { CText* pPoint = (CText*)pOne->GetValue(); pPoint->angle = AfxGetPublicFunction()->GetAngleWithBL(GetDoc()->GetDraw()->GetProjection(), pPoint->x0, pPoint->y0); } count++; break; } } return count; } int NItem::CItemPointProcess::ReliabilityPolygon(void) { //CPropertiesSheet sheet(IDS_STRING_Point, GetView(), 0, FALSE); //sheet.SetItem(this); //if (sheet.DoModal() != IDOK) return 0; ASSERT(GetPos()); CCurveEx* pCurve = (CCurveEx*)GetDoc()->GetDraw()->GetAtValue(GetPos()); CPointXyz* pPoint; int count = 0; COne* pOne; CPtrList* pl = GetDoc()->GetDraw()->GetValueList(); POSITION pos = pl->GetHeadPosition(); while (pos) { pOne = (COne*)pl->GetNext(pos); if (pOne->GetType() != DOUBLEFOX_XYZ) continue; // if (!((CPointNameEx*)pOne->GetValue())->IsXYZ()) continue; pPoint = (CPointXyz*)pOne->GetValue(); if (!pCurve->IsInside(pPoint->x0, pPoint->y0))continue; pPoint->SetReliability(angle); count++; } return count; } int NItem::CItemPointProcess::ReliabilityRect(void) { //CPropertiesSheet sheet(IDS_STRING_Point, GetView(), 0, FALSE); //sheet.SetItem(this); //if (sheet.DoModal() != IDOK) return 0; CRect8 rect = this->GetRect(); CList select; GetDoc()->GetDraw()->IsInRange(rect, select); if (select.IsEmpty()) return 0; int count = 0; POSITION pos, pt; COne* pOne; pos = select.GetHeadPosition(); while (pos) { pt = select.GetNext(pos); pOne = GetDoc()->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_XYZ)continue; //if (!((CPointNameEx*)pOne->GetValue())->IsXYZ()) continue; ((CPointXyz*)pOne->GetValue())->SetReliability(angle); count++; } return count; } POSITION NItem::CItemPointProcess::SelectOneCurve(UINT nFlags, CPoint point) { CPoint2D rp = GetDC()->GetReal(point); POSITION pos = NULL; //if (GetDoc()->IsMoveSelect() && GetDoc()->MoveSelect != NULL) // pos = GetDoc()->MoveSelect; //else // pos = GetDoc()->GetSelectedItem(rp); //if (pos == NULL) //{ // ::AfxMessageBox(IDS_STRING_NOT_ELEMENT); // return NULL; //} //else if (GetDoc()->GetDraw()->GetElementType(pos) != DOUBLEFOX_CURVE) //{ // ::AfxMessageBox(IDS_STRING_IS_NOT_CURVE); // return NULL; //} return pos; }