You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

566 lines
12 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "StdAfx.h"
#include ".\itemdelete.h"
#include "SigmaDoc.h"
#include "SigmaView.h"
#include "ActionDeleteItem.h"
CItemDelete::CItemDelete(CSigmaDoc * ppDoc)
: CItemFocusRect(ppDoc)
, strLayer(_T("Layer:\\Condition"))
, m_bIsRegionSelected(false)
{
SetUpdatePropertyGridState(FALSE);
m_idea=DELETE_DEFAULT;
this->SetType(ITEM_DELETE);
condition = 0;
m_pSelectCurve=new CItemSelectCurve(GetDoc());
m_pSelectCurve->SetNumber(-1);
m_pSelectCurve->EnableSelectOtherType(TRUE);
m_pSelectCurve->AddOtherType(DOUBLEFOX_ELLIPSE);
m_pSelectCurve->AddOtherType(DOUBLEFOX_ARC);
m_pSelectCurve->AddOtherType(DOUBLEFOX_CIRCLE);
m_pSelectCurve->AddOtherType(DOUBLEFOX_CRECT);
value=0.2001;
sel=0;
mode=0;
}
CItemDelete::~CItemDelete(void)
{
if(m_pSelectCurve)
delete m_pSelectCurve;
m_pSelectCurve=NULL;
}
void CItemDelete::DoLButtonUp(CDC *pDC)
{
switch(m_idea)
{
default:
case DELETE_DEFAULT:
Delete();
break;
case DELETE_IN:
if (m_pSelectCurve->GetSelectCount() > 0) {
//c = DeleteIn();
DeleteIn();
}
break;
case DELETE_OUT:
if (m_pSelectCurve->GetSelectCount() > 0) {
//c = DeleteOut();
DeleteOut();
}
break;
case DELETE_CONDITION:
//c=DeleteCondition();
DeleteCondition(NULL);
break;
}
}
void CItemDelete::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk)
{
GetDC()->Create(pDC); //Đ޸´CItemSelectCurve::DrawSelectItemĘąąŔŔŁľÄÎĘĚ⥣
CPoint2D dp = GetDC()->GetReal(point);
c_down = dp;
c_last = dp;
switch(m_idea)
{
default:
case DELETE_DEFAULT:
case DELETE_CONDITION:
CItemFocusRect::OnLButtonDown(pDC, nFlags,point, vk);
break;
case DELETE_IN:
case DELETE_OUT:
m_pSelectCurve->OnLButtonDown(pDC, nFlags,point, vk);
if(m_pSelectCurve->GetSelectCount()>0)
DoLButtonUp(pDC);
break;
}
}
int CItemDelete::OnMouseMove(CDC *pDC, UINT nFlags, CPoint point)
{
switch(m_idea)
{
default:
case DELETE_DEFAULT:
case DELETE_CONDITION:
CItemFocusRect::OnMouseMove(pDC, nFlags,point);
break;
case DELETE_IN:
case DELETE_OUT:
m_pSelectCurve->OnMouseMove(pDC, nFlags, point);
break;
}
return 1;
}
int CItemDelete::SetProcessIdea(int nIdea)
{
if (nIdea < 0 || nIdea > 3)
return -1;
m_idea = nIdea;
return 1;
}
bool CItemDelete::IsRegionSelected()
{
return m_bIsRegionSelected;
}
//Đ޸Ä:Ô­Ŕ´ĘÇÔÚŐâ¸öşŻĘýŁŹŃĄÖĐÁËÍźÔŞžÍÉžłýĄŁĎÖÔڸijÉŃĄÖĐÁËÍźÔŞąŁ´ćĆđŔ´
//ŐâŃů×öľÄÄżľÄĘÇÖ§łÖŐâŃů˛Ů×÷ŁşĂťŃĄÖĐÍźÔŞŁŹ˛ťË˘ĐÂÁËÍźĐÎĄŁŐâ¸ö˛Ů×÷ŁŹÓÉÉϲăľ÷ÓĂŐßĘľĎÖĄŁ
int CItemDelete::Delete(void)
{
m_bIsRegionSelected = false;
CRect8 rect=GetRect();
m_selectionSet.RemoveAll();
GetDoc()->GetDraw()->IsInRange(rect, m_selectionSet);
if(m_selectionSet.GetSize() == 0)
return 0;
//Ö§łÖUndo Redo
CActionDeleteItem * pAction = new CActionDeleteItem(GetDoc(), IDS_STRING_ACTION_DELETE, m_selectionSet);
GetDoc()->SetActionItem(pAction);
return 1;
}
int CItemDelete::GetSubMenu()
{
//if(m_idea==DELETE_IN)
// return 14;
return CItem::GetSubMenu();
}
void CItemDelete::DeleteIn(void)
{
ASSERT(m_pSelectCurve);
m_bIsRegionSelected = false;
POSITION pos=m_pSelectCurve->GetSelectItem(0);
if(pos==NULL)
return ;
//CList<POSITION,POSITION> list;
m_selectionSet.RemoveAll();
GetSelectWidthRegion(m_selectionSet,pos,0);
GetDoc()->SetActionItem(new CActionDeleteItem(GetDoc(), IDS_STRING_ACTION_DELETE, m_selectionSet));
m_bIsRegionSelected = true;
m_pSelectCurve->RemoveAllSelect();
}
void CItemDelete::DeleteOut(void)
{
ASSERT(m_pSelectCurve);
m_bIsRegionSelected = false;
POSITION pos=m_pSelectCurve->GetSelectItem(0);
if(pos==NULL)
return ;
m_selectionSet.RemoveAll();
GetSelectWidthRegion(m_selectionSet,pos,1);
GetDoc()->SetActionItem(new CActionDeleteItem(GetDoc(), IDS_STRING_ACTION_DELETE, m_selectionSet));
m_bIsRegionSelected = true;
m_pSelectCurve->RemoveAllSelect();
}
//nOutSelect=0ÎŞÔÚÇřÓňÄÚŁŹ=1ÎŞ˛ťÔÚÇřÓňÄÚŁŹ=2ÎŞ˛żˇÖÔÚ˛żˇÖ˛ťÔÚŁŹ=3ÎŞČŤ˛żÔÚťňŐ߲żˇÖÔÚľÄÔŞËŘ
int CItemDelete::GetSelectWidthRegion(CPositionList& SelectList, POSITION curvePostion, int nOutSelect)
{
COne* pOne;
pOne=GetDoc()->GetDraw()->GetAt(curvePostion);
CRect8 range=pOne->GetRect();
BOOL bDeleteCurve=FALSE;
CCurveEx* pRgn=m_pSelectCurve->GetRangeCurve(curvePostion, bDeleteCurve);
if(pRgn==NULL) return 0;
int bInRgn;
POSITION p,pos;
CPtrList* pl=GetDoc()->GetDraw()->GetValueList();
pos = pl->GetHeadPosition();
while(pos)
{
p=pos;
pOne=(COne*)pl->GetNext(pos);
if(p==curvePostion)continue;
if(!pOne->IsCanEdit() || !pOne->IsView()) continue;
bInRgn=IsInside(pRgn, range, pOne);
switch(nOutSelect)
{
case 0://ÇřÓňÄÚ
if(bInRgn==1) SelectList.AddTail(p);
break;
case 1://ÇřÓňÍâ
if(bInRgn==0) SelectList.AddTail(p);
break;
case 2:
if(bInRgn==2) SelectList.AddTail(p);
break;
case 3:
if(bInRgn>0) SelectList.AddTail(p);
break;
}
}
if(bDeleteCurve) delete pRgn;
return (int)SelectList.GetCount();
}
int NItem::CItemDelete::IsInside(CCurveEx* pRgn, CRect8& rgnRange, COne* pOne)
{
int bInRgn=0;
switch(pOne->GetType())
{
case DOUBLEFOX_TEXT:
{
CText* pText=(CText*)pOne->GetValue();
if(rgnRange.PtInRect(pText->x0,pText->y0))
bInRgn=pRgn->IsInside(pText->x0,pText->y0);
}
case DOUBLEFOX_XYZ:
case DOUBLEFOX_POINT:
{
CPointNameBase* pPoint=(CPointNameBase*)pOne->GetValue();
if(rgnRange.PtInRect(pPoint->x0,pPoint->y0))
bInRgn=pRgn->IsInside(pPoint->x0,pPoint->y0);
}
break;
case DOUBLEFOX_CURVE:
{
CCurveEx* pCurve=(CCurveEx*)pOne->GetValue();
//0ÎŞČŤ˛ťÔÚˇśÎ§ÄÚ,1ÎŞČŤÔÚˇśÎ§ÄÚ,2ÎŞ˛żˇÖÔÚ˛żˇÖ˛ťÔÚˇśÎ§ÄÚ
bInRgn=CurveInRegion(pCurve,pRgn);
}
break;
case DOUBLEFOX_ARC:
{
CArc* pc=(CArc*)pOne->GetValue();
CCurveEx* pCurve=pc->GetCurve();
bInRgn=CurveInRegion(pCurve,pRgn);
}
break;
case DOUBLEFOX_CIRCLE:
case DOUBLEFOX_ELLIPSE:
{
CEllipse* pc=(CEllipse*)pOne->GetValue();
CCurveEx* pCurve=pc->ToCurve(1.0);
bInRgn=CurveInRegion(pCurve,pRgn);
delete pCurve;
}
break;
default:
{
CRect8 rt=pOne->GetRect();
CCurveEx* pCurve=new CCurveEx;
pCurve->CreateCurveFromRect(&rt);
bInRgn=CurveInRegion(pCurve,pRgn);
delete pCurve;
}
break;
}
return bInRgn;
}
BOOL CItemDelete::ElementInRegion(COne* pOne, CPositionList& rgnList) //ÔŞËŘĘǡńÔÚÖ¸ś¨ľÄÇúĎßÄÚ,֝ҪÓĐŇť¸öÔڞ͡ľťŘTRUE
{
CCurveEx curve;
CCurveEx* pCurve;
if(pOne->GetType()!=DOUBLEFOX_CURVE)
{
CRect8 range=pOne->GetRect();
curve.CreateCurveFromRect(&range);
curve.m_type=PLINE_SOLID;
pCurve=&curve;
}
else
pCurve=(CCurveEx*)pOne->GetValue();
BOOL bInRgn=FALSE;
COne* pRgnOne;
CCurveEx* pRgnCurve;
POSITION pos, pt;
pos=rgnList.GetHeadPosition();
while(pos)
{
pt=rgnList.GetNext(pos);
pRgnOne=GetDoc()->GetDraw()->GetAt(pt);
pRgnCurve=(CCurveEx*)pRgnOne->GetValue();
if(CurveInRegion(pCurve, pRgnCurve)!=0)
{
bInRgn=TRUE;
break;
}
}
return bInRgn;
}
int CItemDelete::GetCountSelected()
{
return m_selectionSet.GetSize();
}
BOOL CItemDelete::CurveInRegion(CCurveEx* pCurve, CPositionList& rgnList) //ÇúĎßĘǡńÔÚÖ¸ś¨ľÄÔŞËŘÄÚ,֝ҪÓĐŇť¸öÔڞ͡ľťŘTRUE
{
BOOL br=FALSE;
COne* pRgnOne;
CCurveEx* pRgnCurve;
POSITION pos, pt;
pos=rgnList.GetHeadPosition();
while(pos)
{
pt=rgnList.GetNext(pos);
pRgnOne=GetDoc()->GetDraw()->GetAt(pt);
if(pRgnOne->GetType()!=DOUBLEFOX_CURVE) continue;
pRgnCurve=(CCurveEx*)pRgnOne->GetValue();
if(CurveInRegion(pCurve, pRgnCurve)==1)//ÍęČŤÔÚÇúĎߡśÎ§ÄÚ˛ż
{
br=TRUE;
break;
}
}
return br;
}
//0ÎŞČŤ˛ťÔÚˇśÎ§ÄÚ,1ÎŞČŤÔÚˇśÎ§ÄÚ,2ÎŞ˛żˇÖÔÚ˛żˇÖ˛ťÔÚˇśÎ§ÄÚ
int CItemDelete::CurveInRegion(CCurveEx* pCurve, CCurveEx* pRgn)
{
ASSERT(pCurve);
ASSERT(pRgn);
CCrossList cross;
pCurve->Cross(*(CCurve*)pRgn,cross);
CPoint3D point(pCurve->x[0], pCurve->y[0], 0);
if(cross.GetCount()==1) //ÎŞÁËÉžłý´ňśĎşóľÄÇúĎß,ČçšűąťÉžłýľÄÇúĎ߾Ĝ˾ăŐýşĂÂäÔÚˇśÎ§ĎßÉĎĘą
{
CCrossPoint pt=cross.GetHead();
if(pCurve->l[0]<pCurve->l[pCurve->num-1])
{
if( fabs(pt.x[0]-pCurve->l[0])<1e-10 ||
fabs(pCurve->l[pCurve->num-1]-pt.x[0])<1e-10 )
cross.RemoveAll();
}
else
{
if( fabs(pCurve->l[0]-pt.x[0])<1e-10 ||
fabs(pt.x[0]-pCurve->l[pCurve->num-1])<1e-10 )
cross.RemoveAll();
}
if(cross.IsEmpty())
pCurve->GetCoordinate((pCurve->l[0]+pCurve->l[pCurve->num-1])*0.5, point.x0, point.y0, point.z0); //źĆËăÇúĎßÖĐľă
}
else if(cross.GetCount()==2)
{
CCrossPoint head=cross.GetHead();
CCrossPoint tail=cross.GetTail();
if(pCurve->l[0]<pCurve->l[pCurve->num-1])
{
if( fabs((pCurve->l[pCurve->num-1]-pCurve->l[0]) - (tail.x[0]-head.x[0]))<1e-10)
cross.RemoveAll();
}
else
{
if( fabs((pCurve->l[0]-pCurve->l[pCurve->num-1]) - (tail.x[0]-head.x[0]))<1e-10)
cross.RemoveAll();
}
if(cross.IsEmpty())
pCurve->GetCoordinate((pCurve->l[0]+pCurve->l[pCurve->num-1])*0.5, point.x0, point.y0, point.z0); //źĆËăÇúĎßÖĐľă
}
if(cross.IsEmpty())
{
if(pRgn->IsInside(point.x0, point.y0))
return 1;
else
return 0;
}
return 2;
}
int CItemDelete::DeleteCondition(DeletionCondition * delCondition)
{
if (delCondition == NULL)
{
return 0;
}
//CPropertiesSheet sheet(IDS_GI_DELETE_CONDITION,GetView(),0,FALSE);
//sheet.SetItem(this);
//if(sheet.DoModal()!=IDOK) return 0;
CRect8 rect=GetRect();
CList<POSITION,POSITION> list;
GetDoc()->GetDraw()->IsInRange(rect,list);
if(list.IsEmpty()) return 0;
sel = delCondition->kind;
value = delCondition->threshold;
condition = delCondition->ConditionDeletion;
mode = delCondition->method;
switch(sel)
{
default:
case 0:
DeleteSelectWidthLength(list, value, condition);
break;
case 1:
case 2:
DeleteSelectWidthName(list, value, condition, sel);
break;
}
if(list.IsEmpty())
return 0;
CLayer *pLayer=NULL;
if(mode==1)//ŇĆľ˝šćś¨ľÄ˛ă
{
pLayer=GetDoc()->GetDraw()->FindAddLayer(strLayer);
//¸üĐ²ăĘ÷Ó뚤žßĚőÁĐąí
//CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame();
//if(pmf)
// pmf->AddLayer(strLayer, pLayer);
POSITION pos,pt;
pos=list.GetHeadPosition();
while(pos)
{
pt=list.GetNext(pos);
GetDoc()->GetDraw()->SetElementLayer(pt,pLayer);
}
}
else
{
//GetDoc()->InvalidateDelete(list);
if (list.IsEmpty())
return 0;
CActionDeleteItem * pAction = new CActionDeleteItem(GetDoc(), IDS_STRING_ACTION_DELETE, list);
GetDoc()->SetActionItem(pAction);
list.RemoveAll();
//m_pSelectCurve->RemoveAllSelect();
}
return 1;
}
void CItemDelete::DeleteSelectWidthName(CList<POSITION,POSITION> &list, double value, int flag, int type)
{
CString name;
int et;
CCurveEx* pCurve;
CPointNameEx* pPoint;
POSITION p,pos,pt;
p=list.GetHeadPosition();
while(p)
{
pos=p;
pt=list.GetNext(p);
name.Empty();
et=GetDoc()->GetDraw()->GetElementType(pt);
switch(type)
{
case 1:
if(et!=DOUBLEFOX_CURVE)
list.RemoveAt(pos);
else
{
pCurve=(CCurveEx*)GetDoc()->GetDraw()->GetAtValue(pt);
name=pCurve->GetName();
}
break;
case 2:
if(et!=DOUBLEFOX_POINT && et != DOUBLEFOX_XYZ)
list.RemoveAt(pos);
else
{
pPoint=(CPointNameEx*)GetDoc()->GetDraw()->GetAtValue(pt);
name=pPoint->GetName();
}
break;
}
if(name.IsEmpty())continue;
if(!DeleteQualification(atof(name),value,flag))
list.RemoveAt(pos);
}
}
void CItemDelete::DeleteSelectWidthLength(CList<POSITION,POSITION> &list, double value, int flag)
{
CCurveEx* pCurve;
POSITION p,pos,pt;
p=list.GetHeadPosition();
while(p)
{
pos=p;
pt=list.GetNext(p);
if(GetDoc()->GetDraw()->GetElementType(pt)!=DOUBLEFOX_CURVE)
list.RemoveAt(pos);
else
{
pCurve=(CCurveEx*)GetDoc()->GetDraw()->GetAtValue(pt);
//if(DeleteQualification(pCurve->Length(),value,flag))
if (!DeleteQualification(pCurve->Length(), value, flag))
list.RemoveAt(pos);
}
}
}
BOOL CItemDelete::DeleteQualification(double length, double value, int flag)
{
BOOL bDelete=FALSE;
switch(flag)
{
case 0: //<
if(length<value)bDelete=TRUE;
break;
case 1: //<=
if(length<=value)bDelete=TRUE;
break;
case 2: //=
if(length==value)bDelete=TRUE;
break;
case 3: //>=
if(length>=value)bDelete=TRUE;
break;
case 4: //>
if(length>value)bDelete=TRUE;
break;
}
return bDelete;
}
int CItemDelete::GetProcessIdea(void)
{
return m_idea;
}
void CItemDelete::OnRButtonDown(UINT nFlags, CPoint point)
{
if(m_idea==DELETE_DEFAULT || m_idea==DELETE_IN)
GetDoc()->DeleteItem();
//GetDoc()->EnableDefaultTool();
}
void CItemDelete::DeleteSelection(CList<POSITION, POSITION> * pList)
{
if (pList->IsEmpty())
return ;
CActionDeleteItem deleteItem(GetDoc(), IDS_STRING_ACTION_DELETE, *pList);
deleteItem.Do();
pList->RemoveAll();
}