#include "StdAfx.h" #include ".\itemexpression.h" #include "SigmaDoc.h" #include "SigmaView.h" #include "actionmodifieditem.h" #include "ItemSelect.h" namespace NItem { CItemExpression::CItemExpression(CSigmaDoc* ppDoc) : CItem(ppDoc) { SetType(ITEM_EXPRESSION); } CItemExpression::~CItemExpression(void) { } void CItemExpression::AddVar(CExpression &ce) { ce.InitVariabileMap(); ce.AddVariable("PI",3.1415926535897932384626433832795); ce.AddVariable("x",0); ce.AddVariable("y",0); ce.AddVariable("z",0); ce.AddVariable("l",0); } void CItemExpression::SetVarValue(CExpression &ce,double x,double y,double z/*=0*/,double l/*=0*/) { ce.SetVarValue("x",x); ce.SetVarValue("y",y); ce.SetVarValue("z",z); ce.SetVarValue("l",l); } void CItemExpression::Expression(int operationObjectKind ,CString & xStr, CString & yStr, CString & zStr, CString & lStr) { CExpression cx,cy,cz,cl; AddVar(cx);AddVar(cy);AddVar(cz);AddVar(cl); m_xStr = xStr; m_yStr = yStr; m_zStr = zStr; cx.SetExpression(m_xStr); cy.SetExpression(m_yStr); cz.SetExpression(m_zStr); cl.SetExpression(m_lStr); int count=0; POSITION pos,pb; COne* pOne; //for redo/undo std::unique_ptr pAction = std::make_unique(GetDoc(), ID_PROCESS_COORDINATE); long total=0; //GetDoc()->BeginProgress(ID_PROCESS_COORDINATE); if(operationObjectKind == 0)//对所有可编辑元素 { double len=GetDoc()->GetDraw()->GetCount(); CPtrList* pl=GetDoc()->GetDraw()->GetValueList(); pos=pl->GetHeadPosition(); while(pos) { total++; AfxGetPublicFunction()->SetProgressPos(AfxGetPublicFunction()->FloatToLong(total/len)); pb=pos; pOne=(COne*)pl->GetNext(pos); if(!pOne->IsCanEdit() || !pOne->IsView()) continue; pAction->BackupOldItem(pb, pOne);//for redo/undo Expression(pOne,cx,cy,cz,cl); count++; } } else //对所有选择元素 { CItemSelect* pItem=GetDoc()->GetSelectItem(); if(pItem) { double len=pItem->m_selection.GetCount(); POSITION pt=pItem->m_selection.GetHeadPosition(); while(pt) { total++; //AfxGetPublicFunction()->SetProgressPos(AfxGetPublicFunction()->FloatToLong(count/len)); pos=pItem->m_selection.GetNext(pt); pOne=GetDoc()->GetDraw()->GetAt(pos); pAction->BackupOldItem(pos, pOne);//for redo/undo Expression(pOne,cx,cy,cz,cl); count++; } } } //GetDoc()->EndProgress(); if(count>0) { GetDoc()->Modified(); pAction->BackupNewItem(); GetDoc()->SetActionItem(pAction.release()); } } void CItemExpression::Expression(COne* pOne, CExpression& cx, CExpression& cy, CExpression& cz, CExpression& cl) { if(pOne==NULL) return; double x,y,z,l; switch(pOne->GetType()) { case DOUBLEFOX_CURVE: { CCurveEx* pc=(CCurveEx*)pOne->GetValue(); for(int i=0;inum;i++) { x=pc->x[i]; y=pc->y[i]; z=pc->z[i]; l=pc->l[i]; if(!m_xStr.IsEmpty()) { SetVarValue(cx,x,y,z,l); cx.GetValue(pc->x[i]); } if(!m_yStr.IsEmpty()) { SetVarValue(cy,x,y,z,l); cy.GetValue(pc->y[i]); } if(!m_zStr.IsEmpty()) { SetVarValue(cz,x,y,z,l); cz.GetValue(pc->z[i]); } if(!m_lStr.IsEmpty()) { SetVarValue(cl,x,y,z,l); cl.GetValue(pc->l[i]); } if(pc->bAutoLocation && pc->nPoint<4) pc->GetLocation(); } } break; case DOUBLEFOX_FRAME: case DOUBLEFOX_IMAGE: case DOUBLEFOX_INSERT: case DOUBLEFOX_DRAW: case DOUBLEFOX_SCALERULER: { CPoint2D pt; CPointNameRect* pp=(CPointNameRect*)pOne->GetValue(); CRect8 sr(pp->x0, pp->y0+pp->m_size.cy, pp->x0+pp->m_size.cx, pp->y0); if(!m_xStr.IsEmpty()) { SetVarValue(cx,sr.left,sr.bottom); cx.GetValue(pp->x0); SetVarValue(cx,sr.right,sr.top); cx.GetValue(pp->m_size.cx); pp->m_size.cx-=pp->x0; } if(!m_yStr.IsEmpty()) { SetVarValue(cy,sr.left,sr.bottom); cy.GetValue(pp->y0); SetVarValue(cy,sr.right,sr.top); cy.GetValue(pp->m_size.cy); pp->m_size.cy-=pp->y0; } } break; case DOUBLEFOX_XYZ: case DOUBLEFOX_POINT: { CPointNameEx* pp = (CPointNameEx*)pOne->GetValue(); x=pp->x0; y=pp->y0; if(!m_xStr.IsEmpty()) { SetVarValue(cx,x,y); cx.GetValue(pp->x0); } if(!m_yStr.IsEmpty()) { SetVarValue(cy,x,y); cy.GetValue(pp->y0); } if(pp->IsXYZ()) { CPointXyz* px=(CPointXyz*)pp; if(!m_zStr.IsEmpty() && px->m_pXyzValue) { SetVarValue(cz,x,y,px->z0); cz.GetValue(px->z0); px->SetName(); } } } break; case DOUBLEFOX_ELLIPSE: case DOUBLEFOX_CIRCLE: case DOUBLEFOX_MXN: case DOUBLEFOX_PROPORTION: case DOUBLEFOX_DRAW_RECT: case DOUBLEFOX_ARC: case DOUBLEFOX_OLE: case DOUBLEFOX_TREE: { CPointNameBase* pp=(CPointNameBase*)pOne->GetValue(); x=pp->x0; y=pp->y0; if(!m_xStr.IsEmpty()) { SetVarValue(cx,x,y); cx.GetValue(pp->x0); } if(!m_yStr.IsEmpty()) { SetVarValue(cy,x,y); cy.GetValue(pp->y0); } if(pOne->GetType()==DOUBLEFOX_ARC) ((CArc*)pOne->GetValue())->GetCurve(((CArc*)pOne->GetValue())->step); } break; case DOUBLEFOX_TEXT: { CText* pp=(CText*)pOne->GetValue(); x=pp->x0; y=pp->y0; if(!m_xStr.IsEmpty()) { SetVarValue(cx,x,y); cx.GetValue(pp->x0); } if(!m_yStr.IsEmpty()) { SetVarValue(cy,x,y); cy.GetValue(pp->y0); } } break; case DOUBLEFOX_OTHERDRAW: break; case DOUBLEFOX_SECTION: break; case DOUBLEFOX_GRID: case DOUBLEFOX_NET: { CRect8* rt=(CRect8*)pOne->GetValue(); CRect8 sr=*rt; if(!m_xStr.IsEmpty()) { SetVarValue(cx,sr.left,sr.top); cx.GetValue(rt->left); SetVarValue(cx,sr.right,sr.bottom); cx.GetValue(rt->right); } if(!m_yStr.IsEmpty()) { SetVarValue(cy,sr.left,sr.top); cy.GetValue(rt->top); SetVarValue(cy,sr.right,sr.bottom); cy.GetValue(rt->bottom); } } break; case DOUBLEFOX_MESH: { //hjp修改 CMesh* pm=(CMesh*)pOne->GetValue(); CRect8 *rt = &(pm->GetRect()); //CRect8* rt=(CRect8*)pOne->GetValue(); //CRect8* sr=rt; if(!m_xStr.IsEmpty()) { SetVarValue(cx,rt->left,rt->top); cx.GetValue(rt->left); SetVarValue(cx,rt->right,rt->bottom); cx.GetValue(rt->right); /*SetVarValue(cx,sr.left,sr.top); cx.GetValue(rt->left); SetVarValue(cx,sr.right,sr.bottom); cx.GetValue(rt->right);*/ } if(!m_yStr.IsEmpty()) { SetVarValue(cy,rt->left,rt->top); cy.GetValue(rt->top); SetVarValue(cy,rt->right,rt->bottom); cy.GetValue(rt->bottom); /*SetVarValue(cy,sr.left,sr.top); cy.GetValue(rt->top); SetVarValue(cy,sr.right,sr.bottom); cy.GetValue(rt->bottom);*/ } pm->SetRect(rt->left, rt->top, rt->right, rt->bottom); CGrid* pg = pm->GetMesh(); if(!m_xStr.IsEmpty()) { SetVarValue(cx,pg->P0[0],pg->P0[1]); cx.GetValue(pg->P0[0]); } if(!m_yStr.IsEmpty()) { SetVarValue(cy,pg->P0[0],pg->P0[1]); cy.GetValue(pg->P0[1]); } CFunction2D* pFun=(CFunction2D*)pm->GetMesh(); CDimension3D* pDfg=(CDimension3D*)pm->GetMesh(); switch(pm->GetMeshType()) { case MESH_FUN_2D: if(!m_zStr.IsEmpty()) { Expression(cz, pFun); pm->GetBitmap(); } break; default: if(!m_zStr.IsEmpty()) { Expression(cz, pDfg); pm->GetBitmap(); } break; } CRect8 rg=pm->GetRect(); if(pm->GetImage()) { pm->GetImage()->x0=rg.left; pm->GetImage()->y0=rg.bottom; pm->GetImage()->m_size=rg.GetSize(); } if(pm->m_pRuler)//改正标尺的坐标 { if(!m_xStr.IsEmpty()) { SetVarValue(cx, pm->m_pRuler->x0, pm->m_pRuler->y0); cx.GetValue(pm->m_pRuler->x0); } if(!m_yStr.IsEmpty()) { SetVarValue(cy, pm->m_pRuler->x0, pm->m_pRuler->y0); cx.GetValue(pm->m_pRuler->y0); } } } break; //hjp添加 case DOUBLEFOX_RECTLABEL: { CRectLabel* pR=(CRectLabel*)pOne->GetValue(); CRect8 *rt = &(pR->m_rect); if(!m_xStr.IsEmpty()) { SetVarValue(cx,pR->m_ptAnchor.x0,pR->m_ptAnchor.y0); cx.GetValue(pR->m_ptAnchor.x0); SetVarValue(cx,rt->left,rt->top); cx.GetValue(rt->left); SetVarValue(cx,rt->right,rt->bottom); cx.GetValue(rt->right); } if(!m_yStr.IsEmpty()) { SetVarValue(cx,pR->m_ptAnchor.x0,pR->m_ptAnchor.y0); cx.GetValue(pR->m_ptAnchor.y0); SetVarValue(cy,rt->left,rt->top); cy.GetValue(rt->top); SetVarValue(cy,rt->right,rt->bottom); cy.GetValue(rt->bottom); } pR->CreateCurve(); } break; //hjp添加 case DOUBLEFOX_BLOCK: { CXyBlock* pb=(CXyBlock*)pOne->GetValue(); CXy* pxy = (CXy*)pb->GetXy(); if(pxy==NULL) break; POSITION pt=pxy->GetValueList()->GetHeadPosition(); while(pt) { COne *ppOne=(COne*)pxy->GetValueList()->GetNext(pt); Expression(ppOne, cx, cy, cz, cl); } } break; case DOUBLEFOX_WMF: { CMetaFile* pMetaFile = pOne->GetValueSafe(); if (!m_xStr.IsEmpty()) { SetVarValue(cx, pMetaFile->x0, pMetaFile->y0); cx.GetValue(pMetaFile->x0); } if (!m_yStr.IsEmpty()) { SetVarValue(cy, pMetaFile->x0, pMetaFile->y0); cy.GetValue(pMetaFile->y0); } } break; } } void CItemExpression::Expression(CExpression &ce, CDimension3D* pDfg) { if(pDfg==NULL) return; int i,j; double z0; for(i=0;inum[0];i++) { for(j=0;jnum[1];j++) { z0=pDfg->Value(i, j, 0); SetVarValue(ce, pDfg->x(i), pDfg->y(j), z0); ce.GetValue(z0); pDfg->SetValue(i,j,z0); } } SetVarValue(ce, 0, 0, pDfg->range[0]); ce.GetValue(pDfg->range[0]); SetVarValue(ce, 0, 0, pDfg->range[1]); ce.GetValue(pDfg->range[1]); if(pDfg->range[0]>pDfg->range[1]) AfxGetPublicFunction()->ExchangeXY(pDfg->range[0], pDfg->range[1]); } void CItemExpression::Expression(CExpression &ce, CFunction2D* pFun) { if(pFun==NULL) return; int i,j,k,l,ll; CFunction2D::CLineX *pLine; l=0; for(i=0;ixnum();++i) { k=0; for(ll=0;llpLine[i].nCount;++ll) { pLine=pFun->pLine[i].pX+ll; if(pLine->nCount<1)continue; for(j=0;jnCount;++j) { if(l==pFun->total) return; ++l; SetVarValue(ce, pFun->x(i), pFun->y(j+pLine->j0), pLine->pPoint[j].value); ce.GetValue(pLine->pPoint[j].value); } } } } }//namespace