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.
kev/Drawer/Module/GeoSigmaDraw/InterfaceDelete.cpp

194 lines
3.9 KiB
C++

#include "stdafx.h"
#include "SigmaView.h"
#include "SectionDoc.h"
#include "ItemDelete.h"
#include "ActionDeleteItem.h"
#include "DrawOperator/Util.h"
static CItemDelete * GetItemDeleteFromView(CSigmaView * pView)
{
if (pView == NULL)
return 0;
CItem * item = pView->GetItem();
if (item == NULL)
return 0;
CItemDelete * itemDelete = dynamic_cast<CItemDelete *>(item);
if (itemDelete == NULL)
return 0;
return itemDelete;
}
/*
0==删除矩形范围内元素
1==删除区域内元素
2==删除区域外元素
3==有条件删除元素
*/
//CItemDelete
extern "C" __declspec(dllexport)
int Delete_SetType(CSigmaView* pView, int type)
{
CItemDelete * itemDelete = GetItemDeleteFromView(pView);
if (itemDelete == NULL)
return -1;
return itemDelete->SetProcessIdea(type);
}
extern "C" __declspec(dllexport)
int Delete_GetCountSelected(CSigmaView* pView)
{
CItemDelete * itemDelete = GetItemDeleteFromView(pView);
if (itemDelete == NULL)
return -1;
return itemDelete->GetCountSelected();
}
//1-有选中的区域或图元 0-无选中的区域或图元
extern "C" __declspec(dllexport)
int Delete_IsRegionSelected(CSigmaView* pView)
{
CItemDelete * itemDelete = GetItemDeleteFromView(pView);
if (itemDelete == NULL)
return 0;
return itemDelete->IsRegionSelected()?1:0;
}
static BOOL 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;
}
void DeleteSelectWidthName(CXy& xy, 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=xy.GetElementType(pt);
switch(type)
{
case 1:
if(et!=DOUBLEFOX_CURVE)
list.RemoveAt(pos);
else
{
pCurve=(CCurveEx*)xy.GetAtValue(pt);
name=pCurve->GetName();
}
break;
case 2:
if(et!=DOUBLEFOX_POINT && et != DOUBLEFOX_XYZ)
list.RemoveAt(pos);
else
{
pPoint=(CPointNameEx*)xy.GetAtValue(pt);
name=pPoint->GetName();
}
break;
}
if(name.IsEmpty())continue;
if(!DeleteQualification(atof(name),value,flag))
list.RemoveAt(pos);
}
}
static void DeleteSelectWidthLength(CXy& xy, 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(xy.GetElementType(pt)!=DOUBLEFOX_CURVE)
list.RemoveAt(pos);
else
{
pCurve=(CCurveEx*)xy.GetAtValue(pt);
//if(DeleteQualification(pCurve->Length(),value,flag))
if (!DeleteQualification(pCurve->Length(), value, flag))
list.RemoveAt(pos);
}
}
}
static int DeleteCondition(CSigmaView& view, const DeletionCondition &delCondition)
{
CXy& xy = *(view.m_pDoc->m_pXy);
// 为了复用 CItemDelete 的代码,我们先偷个懒,这里把 position list 构建出来
CList<POSITION,POSITION> list;
xy.GetElement(delCondition.layerName, list, TRUE, FALSE);
// 条件过滤
switch (delCondition.kind)
{
default:
case 0:
DeleteSelectWidthLength(xy, list, delCondition.threshold, delCondition.ConditionDeletion);
break;
case 1:
case 2:
DeleteSelectWidthName(xy, list, delCondition.threshold, delCondition.ConditionDeletion, delCondition.kind);
break;
}
// 删除
if (list.GetCount() > 0)
{
CActionDeleteItem * pAction = new CActionDeleteItem(view.m_pDoc, IDS_STRING_ACTION_DELETE, list);
view.m_pDoc->SetActionItem(pAction);
return list.GetCount();
}
return 0;
}
extern "C" __declspec(dllexport)
int Delete_Condition(CSigmaView * pView, DeletionCondition * condition)
{
if (pView == nullptr || condition == nullptr)
{
return 0;
}
DeleteCondition(*pView, *condition);
return 1;
}