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.

380 lines
9.9 KiB
C++

#include "StdAfx.h"
#include "itemmathfind.h"
#include "SigmaDoc.h"
#include "SigmaView.h"
#include "TinyXml\tinyxml.h"
CItemMathFind::CItemMathFind(CSigmaDoc* ppDoc)
: CItem(ppDoc)
, m_selType(0)
, step(100)
, remains(0)
, m_index(0)
, m_bCompareLayer(TRUE)
, m_bCompareName(TRUE)
, m_dCompareError(1e-4)
, m_nMode(FIND_MATH)
, maxAngle(1.0)
{
this->SetType(ITEM_MATH_FIND);
}
CItemMathFind::~CItemMathFind(void)
{
}
/*
BOOL CItemMathFind::InitPropertyGrid(CXTPPropertyGrid& grid)
{
CPropertyGridItemAdd ItemAdd(NULL);
CString strFormat=GetFloatFormatString();
CXTPPropertyGridItem* pItem;
switch(m_nMode)
{
case FIND_REPEAT:
pItem=grid.AddCategory(IDS_STRING_COMPARE_CURVE);
ItemAdd.SetItem(pItem); pItem->Expand();
ItemAdd.AddItemCombo(IDS_STRING_TYPE,IDS_GI_MATHFIND_TYPE_COMBO,m_selType,&m_selType);
ItemAdd.AddItemDouble(IDS_STRING_COMPARE_ERROR, m_dCompareError, strFormat, &m_dCompareError);
ItemAdd.AddItemBool(IDS_STRING_COMPARE_LAYER, m_bCompareLayer,&m_bCompareLayer);
ItemAdd.AddItemBool(IDS_STRING_COMPARE_NAME, m_bCompareName,&m_bCompareName);
break;
case FIND_MATH:
pItem=grid.AddCategory(IDS_GI_MATHFIND);
ItemAdd.SetItem(pItem); pItem->Expand();
ItemAdd.AddItemCombo(IDS_STRING_TYPE,IDS_GI_MATHFIND_TYPE_COMBO,m_selType,&m_selType);
ItemAdd.AddItemDouble(IDS_GI_STEP, step, strFormat, &step);
ItemAdd.AddItemDouble(IDS_GI_MATHFIND_REMAINS,remains, strFormat, &remains);
ItemAdd.AddItemLong(IDS_GI_MATHFIND_INDEX, m_index,&m_index);
break;
case FIND_DEVIED_CURVE:
pItem=grid.AddCategory(ID_PROCESS_CURVE_SPLIT);
ItemAdd.SetItem(pItem); pItem->Expand();
ItemAdd.AddItemDouble(IDS_STRING_MAX_ANGLE,maxAngle,strFormat,&maxAngle);
break;
}
return TRUE;
}
*/
void CItemMathFind::DevidedCurve(void)
{
CString str;
str.LoadString(ID_PROCESS_CURVE_SPLIT);
int i=str.Find("\n");
if(i>0) str=str.Left(i);
//CPropertiesSheet sheet(str,GetView(),0,FALSE);
//sheet.SetItem(this);
//if(sheet.DoModal()!=IDOK) return;
//CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame();
//if(pmf==NULL) return;
//pmf->ShowPane(COMMAND_BAR_RESULT_LIST);
//pmf->m_pPaneResultList->InitList();
//GetDoc()->BeginWaitCursor();
bool bStart = false;
COne* pOne;
CCurveEx* pc;
double a0,a1;
CPtrList* pl=GetDoc()->GetDraw()->GetValueList();
POSITION pos,pt;
pos=pl->GetHeadPosition();
while(pos)
{
pt=pos;
pOne=(COne*)pl->GetNext(pos);
if(!pOne->IsCanEdit() || !pOne->IsView()) continue;
if(pOne->GetType()!=DOUBLEFOX_CURVE)continue;
pc=(CCurveEx*)pOne->GetValue();
if(!bStart)
{
a0=AfxGetBaseFunction()->GetAngle(pc->x[0], pc->y[0], pc->x[pc->num-1], pc->y[pc->num-1]);
bStart = true;
}
a1=AfxGetBaseFunction()->GetAngle(pc->x[0], pc->y[0], pc->x[pc->num-1], pc->y[pc->num-1])-a0;
while(a1<0) a1+= 360;
while(a1>180) a1 -= 180;
//if(a1<maxAngle||180-a1<maxAngle)
//pmf->m_pPaneResultList->Elements_InsertItem(pt);
}
//pmf->m_pPaneResultList->InsertStatItem(STAT_MODE_ELEMENTS);
}
//BOOL CItemMathFind::OnGridItemChangeValue(CXTPPropertyGridItem* pItem)
//{
// return FALSE;
//}
void CItemMathFind::MathFind(int kind, double step, double remainder, int start, TiXmlElement * rootElement)
{
m_selType = kind;
this->step = step;
remains = remainder;
m_index = start;
MathFind(rootElement);
}
void CItemMathFind::MathFind(TiXmlElement * rootElement)
{
//CPropertiesSheet sheet(IDS_GI_MATHFIND,GetView(),0,FALSE);
//sheet.SetItem(this);
//if(sheet.DoModal()!=IDOK) return;
//CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame();
//if(pmf==NULL) return;
//pmf->ShowPane(COMMAND_BAR_RESULT_LIST);
//CListCtrl* pList=pmf->GetResultListCtrl();
//if(pList==NULL) return;
//pmf->m_pPaneResultList->InitList();
//GetDoc()->BeginWaitCursor();
double value;
//int sel;
int count=0;
CString name,type,idStr,str,txt;
COne* pOne;
CPtrList* pl=GetDoc()->GetDraw()->GetValueList();
double length=pl->GetCount();
long i=0;
POSITION pos=pl->GetHeadPosition();
while(pos)
{
i++;
AfxGetPublicFunction()->SetProgressPos(AfxGetPublicFunction()->FloatToLong(i/length*100));
pOne=(COne*)pl->GetNext(pos);
if(!pOne->IsCanEdit() || !pOne->IsView()) continue;
switch(pOne->GetType())
{
case DOUBLEFOX_CURVE:
if(m_selType == 1) continue;
name=((CCurveEx*)pOne->GetValue())->GetName();
//type.LoadString(IDS_STRING_CURVE);
type = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
break;
case DOUBLEFOX_XYZ:
if (m_selType == 0)continue;
name = ((CPointNameEx*)pOne->GetValue())->GetName();
type = "ɢ<EFBFBD><EFBFBD>";
break;
case DOUBLEFOX_POINT:
if(m_selType == 0)continue;
name=((CPointNameEx*)pOne->GetValue())->GetName();
//type.LoadString(IDS_STRING_Point);
type = "<EFBFBD><EFBFBD>";
break;
default:
continue;
}
int nLength = name.GetLength()-m_index-1;
str = name.Right(nLength);
if(str.IsEmpty()) //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
continue ;
value=atof(str);
if (fabs(value-0.000001)<1e-6)
{
BOOL bIsNumber = FALSE;
CString strTemp;
for (int i=0;i<str.GetLength();i++)
{
if (str.Find('.') != -1)
{
strTemp = str;
strTemp.Delete(i);
if (strTemp.GetAt(i) < '0' || strTemp.GetAt(i) >= '9')
{
bIsNumber = TRUE;
break;
}
}
else
{
if (str.GetAt(i) < '0' || str.GetAt(i) >= '9')
{
bIsNumber = TRUE;
break;
}
}
}
if (bIsNumber)
continue;
}
value=fmod(value,step);
value=fabs(value);
if(fabs(value-remains)>1e-6)
continue;
count++;
//txt.Format("%ld",count+1);
//sel=pList->InsertItem(count,txt);
//pList->SetItemText(sel,1,name);
//pList->SetItemText(sel,2,type);
//pList->SetItemText(sel,3,pOne->GetLayer()->GetPathName());
//pList->SetItemData(sel,(DWORD)pOne);
idStr.Format("%d", count);
TiXmlElement *itemElement = new TiXmlElement("Item");
rootElement->LinkEndChild(itemElement);
TiXmlElement * idElement = new TiXmlElement("ID");
itemElement->LinkEndChild(idElement);
TiXmlElement * nameElement = new TiXmlElement("Name");
itemElement->LinkEndChild(nameElement);
TiXmlElement * typeElement = new TiXmlElement("Type");
itemElement->LinkEndChild(typeElement);
TiXmlElement * layerNameElement = new TiXmlElement("Layer");
itemElement->LinkEndChild(layerNameElement);
TiXmlElement *positionElement = new TiXmlElement("Position");
itemElement->LinkEndChild(positionElement);
TiXmlText *idValue = new TiXmlText(idStr);
idElement->LinkEndChild(idValue);
TiXmlText * nameValue = new TiXmlText(name);
nameElement->LinkEndChild(nameValue);
TiXmlText * typeValue = new TiXmlText(type);
typeElement->LinkEndChild(typeValue);
TiXmlText * layerNameValue = new TiXmlText(pOne->GetLayer()->GetPathName());
layerNameElement->LinkEndChild(layerNameValue);
uintptr_t number = (uintptr_t)pos;
char buffer[65];
_ui64toa(number, buffer, 10);
txt.Format("%s", buffer);
TiXmlText *posValue = new TiXmlText(txt);
positionElement->LinkEndChild(posValue);
}
}
void NItem::CItemMathFind::FindRepeatElements(void)
{
//CPropertiesSheet sheet(IDS_STRING_COMPARE_CURVE,GetView(),0,FALSE);
//sheet.SetItem(this);
//if(sheet.DoModal()!=IDOK) return;
//CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame();
//ASSERT(pmf);
//pmf->ShowPane(COMMAND_BAR_RESULT_LIST);
//CListCtrl* pList=pmf->GetResultListCtrl();
//ASSERT(pList);
//pmf->m_pPaneResultList->m_wndListCtrl.LockWindowUpdate();
//pmf->m_pPaneResultList->InitList();
CPositionList list;
switch(m_selType)
{
case 0:
FindRepeat(DOUBLEFOX_CURVE, list);
break;
case 1:
FindRepeat(DOUBLEFOX_POINT, list);
FindRepeat(DOUBLEFOX_XYZ, list);
break;
case 2:
FindRepeat(DOUBLEFOX_CURVE, list);
FindRepeat(DOUBLEFOX_POINT, list);
FindRepeat(DOUBLEFOX_XYZ, list);
break;
default:
return;
}
if(list.GetCount()>0)
{
POSITION pos, pt;
pos=list.GetHeadPosition();
while(pos)
{
pt=list.GetNext(pos);
//pmf->m_pPaneResultList->Elements_InsertItem(pt);
}
//pmf->m_pPaneResultList->InsertStatItem(STAT_MODE_ELEMENTS);
}
//pmf->m_pPaneResultList->m_wndListCtrl.UnlockWindowUpdate();
}
int NItem::CItemMathFind::FindRepeat(int nType, CPositionList &repeatList)
{
//GetDoc()->BeginProgress(IDS_STRING_COMPARE_CURVE);
COne* pOneNext;
COne* pOnePrev=NULL;
POSITION pos,pt,ptBak;
CPtrList* pl=GetDoc()->GetDraw()->GetValueList();
double length=pl->GetCount();
long i=0;
pos=pl->GetHeadPosition();
while(pos)
{
i++;
AfxGetPublicFunction()->SetProgressPos(AfxGetPublicFunction()->FloatToLong(i/length*100));
pOnePrev=(COne*)pl->GetNext(pos);
if(pOnePrev->GetType()!=nType) continue;
if(!pOnePrev->IsCanEdit() || !pOnePrev->IsView()) continue;
pt=pos;
while(pt)
{
ptBak=pt;
pOneNext=(COne*)pl->GetNext(pt);
if(pOneNext->GetType()!=nType) continue;
if(!pOneNext->IsCanEdit() || !pOneNext->IsView()) continue;
if(repeatList.Find(ptBak)) continue; //<2F>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>
if(CompareElement(pOnePrev, pOneNext, m_dCompareError, m_bCompareLayer, m_bCompareName))
{
repeatList.AddTail(ptBak);
}
}
}
//GetDoc()->EndProgress();
return (int)repeatList.GetCount();
}
//<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><EFBFBD>
bool NItem::CItemMathFind::CompareElement(COne* pOnePrev, COne* pOneNext, double error, BOOL bCompareLayer, BOOL bCompareName)
{
if(bCompareLayer)
{
if(pOnePrev->GetLayer() != pOneNext->GetLayer()) return false;
}
if(bCompareName)
{
CString strPrev=pOnePrev->GetName();
if(strPrev.CompareNoCase(pOneNext->GetName())!=0) return false;
}
switch(pOnePrev->GetType())
{
case DOUBLEFOX_CURVE:
{
CCurveEx* pcPrev=(CCurveEx*)pOnePrev->GetValue();
CCurveEx* pcNext=(CCurveEx*)pOneNext->GetValue();
if(pcPrev->CompareCurve(*(CCurve*)pcNext, error)>error) return false;
}
break;
case DOUBLEFOX_XYZ:
case DOUBLEFOX_POINT:
case DOUBLEFOX_TEXT:
{
CPointNameBase* pnPrev=(CPointNameBase*)pOnePrev->GetValue();
CPointNameBase* pnNext=(CPointNameBase*)pOneNext->GetValue();
if(AfxGetPublicFunction()->Distance(pnPrev->x0,pnPrev->y0,pnNext->x0,pnNext->y0)>error) return false;
}
break;
default:
return false;
}
return true;
}
void NItem::CItemMathFind::SetFindMode(int nMode)
{
m_nMode=nMode;
}