#include "StdAfx.h" #include ".\itemcurveprocess.h" #include "SigmaDoc.h" #include "SigmaView.h" #include ".\itemlinkcurve.h" #include ".\actionembellishitem.h" #include ".\actionmodifieditem.h" #include ".\actionbackupitem.h" #include "ActionListItem.h" #include "ActionComboItem.h" #include ".\actionchangelayeritem.h" #include "TinyXml/tinyxml.h" #include "Util.h" #include "../SSBase/VoronoiMap/PolygonOperation.h" //#define USINGZ #include "keyholing.h" CItemCurveProcess::CItemCurveProcess(CSigmaDoc * ppDoc) : CItemFocusRect(ppDoc) , m_idea(0) , name(_T("")) , m_pColor(NULL) , a(10) , decimal(8) , m_bIsE(FALSE) , m_bIsLog(false) , m_selSmooth(1) , m_bIsDelete(TRUE) , m_processResult(0) { SetUpdatePropertyGridState(FALSE); this->SetType(ITEM_CURVE_PROCESS); cycle=30; swing=10; dnum=20; m_bDeleteSourveCurve=FALSE; m_dCurveOffset=10; m_dStep=200; m_nMode=0; m_error=0; m_bInteger=TRUE; } CItemCurveProcess::~CItemCurveProcess(void) { if(m_pColor)delete m_pColor; m_pColor=NULL; } void CItemCurveProcess::DoLButtonUp(CDC *pDC) { CSigmaDoc * pDoc = GetDoc(); int c=0; BOOL bEnableDefaultTool=TRUE; switch(m_idea) { case CURVE_FITTING: c=FittingCurve(); break; case CURVE_NULL_EMBELLISH: c=SetNullEmbellish(); break; case CURVE_SET_EMBELLISH: c=SetEmbellish(); break; case CURVE_CONTOUR: c=CurveContour(); break; case CURVE_AUTO_LOCATION: c=AutoLocation(); break; case CURVE_REVERSAL: c=Reversal(); bEnableDefaultTool=FALSE; break; case CURVE_SET_NAME: c=SetName(); break; case CURVE_NAME_TO_Z: c=NameToZ(); break; case CURVE_Z_TO_NAME: c=ZToName(); break; case CURVE_LAYER_TO_NAME: c=LayerToName(); break; case CURVE_NAME_LOG: c=NameLog(); break; case CURVE_NAME_EXPONENTIAL: c=NameExponential(); break; case CURVE_NAME_IS_NULL: //c=FindNameIsNull(); break; case CURVE_ANY_NAME: c=AnyName(); if(c==0) pDoc->Invalidate(GetPos()); break; case ARC_TO_CURVE: //c=ArcToCurve(); break; case CURVE_SMOOTH: c=CurveSmooth(); break; case CURVE_TO_WAVE: c=ToWave(); break; case CURVE_OFFSET: c=CurveOffset(); break; case CURVE_NODE_ENCRYPT: c=NodeEncrypt(); break; case CURVE_REDUNDANT: c=ToRedundant(); break; case CURVE_CLOSE: c=CloseCurve(); bEnableDefaultTool=FALSE; break; case CURVE_SURFACE_Z: c = SetZFromSurface(); break; } m_processResult = c; if(c>0) { //pDoc->Modified(); //pDoc->Invalidate(); } //if(bEnableDefaultTool) //pDoc->EnableDefaultTool(); } bool CItemCurveProcess::NodeEncrypt(int mode, double step, bool bRounding, CPositionList & selectionSet) { CRect8 rect = this->GetRect(); if (selectionSet.IsEmpty()) return false; CActionListItem* pAction = new CActionListItem(GetDoc(), ID_PROCESS_CURVE_ENCRYPT); int count = 0; POSITION pos, pt; COne* pOne; CCurveEx* pCurve; pos = selectionSet.GetHeadPosition(); BOOL bR = bRounding ? TRUE : FALSE; while (pos) { pt = selectionSet.GetNext(pos); pOne = m_pDoc->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) continue; pCurve = (CCurveEx*)pOne->GetValue(); CActionModifiedItem* pModifiedItem = new CActionModifiedItem(GetDoc(), IDS_STRING_CURVE); pModifiedItem->BackupOldItem(pt, pOne); pCurve->GetLocation(); pCurve->EncryptNode(mode, step, bR); pModifiedItem->BackupNewItem(); pAction->AddTailItem(pModifiedItem); count++; m_pDoc->Modified(); } if (count > 0) GetDoc()->SetActionItem(pAction); else delete pAction; return count != 0; } int CItemCurveProcess::PolygonConnect(CPositionList& selections, CString& layerName, bool deleteOriginalCurves) { if (selections.IsEmpty()) return false; vector srcVec; int count = 0; POSITION pos, pt; COne* pOne; CCurveEx* pCurve; /// 使用Clippers2解决 Paths64 subjects; int pathCount = selections.GetCount(); subjects.reserve(pathCount); CPositionList removeElements; pos = selections.GetHeadPosition(); while (pos) { pt = selections.GetNext(pos); pOne = m_pDoc->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) continue; pCurve = (CCurveEx*)pOne->GetValue(); if (pCurve->num < 3) { continue; } removeElements.AddTail(pt); Path64 pathTmp; int nNum = pCurve->num; pathTmp.reserve(nNum); for (int i = 0; i < nNum; i++) { Point64 pt64 = toPoint64(pCurve->x[i], pCurve->y[i]); //, pCurve->z[i] pathTmp.push_back(Point64(pt64.x, pt64.y));//, pCurve->z[i] } subjects.push_back(pathTmp); } PolyTree64 polytree; Clipper64 c64; c64.AddSubject(subjects); c64.Execute(ClipType::Union, FillRule::EvenOdd, polytree); // 首先合并相交或包含的多边形 Paths64 solutionMerge; if (!KeyHole(polytree, solutionMerge)) return false; Path64 pathConn64 = ConnectPolygons(solutionMerge); Path64 pathResult64 = TrimCollinear(pathConn64); PathD pathResult = fromPolygon64(pathConn64); PathsD solution; solution.emplace_back(pathResult); CList addList; CLayer* pLayerResult = GetDoc()->GetDraw()->FindAddLayer(layerName); for (size_t i = 0; i < solution.size(); ++i) { int nSize = solution[i].size(); CPointList PointList; for (int j= 0; j < nSize; j++) { dfPoint point; point.x0 = solution[i][j].x; point.y0 = solution[i][j].y; //point.z0 = solution[i][j].z; PointList.AddTail(point); } dfPoint ptTail; ptTail.x0 = solution[i][0].x; ptTail.y0 = solution[i][0].y; PointList.AddTail(ptTail); CCurveEx* pCurveNew = new CCurveEx; pCurveNew->SetName(""); pCurveNew->SetPoints(PointList, 2); // 增加曲线 pos = GetDoc()->GetDraw()->AddElement(pCurveNew, DOUBLEFOX_CURVE); addList.AddTail(pos); } /////////////// //pos = selections.GetHeadPosition(); //while (pos) //{ // pt = selections.GetNext(pos); // pOne = m_pDoc->GetDraw()->GetAt(pt); // if (pOne->GetType() != DOUBLEFOX_CURVE) // continue; // pCurve = (CCurveEx*)pOne->GetValue(); // if (pCurve->num < 3) { // continue; // } // CPolyline* pLineNew = new CPolyline(); // for (int i = 0; i < pCurve->num; i++) // { // pLineNew->AddPoint(pCurve->x[i], pCurve->y[i], pCurve->z[i]); // } // srcVec.push_back(pLineNew); //} //vector dstVec; //CPolygonOperation::DigHoles(srcVec, dstVec); //CLayer* pLayerNew = GetDoc()->GetDraw()->FindAddLayer(layerName); ////pAction->AddAddItem(pNewOne); //for (auto polyLine : dstVec) { // int numPl = polyLine->GetLength(); // CPointList PointList; // for (int i = 0; i < numPl; i++) // { // dfPoint point; // point.x0 = polyLine->GetPoint(i).x0; // point.y0 = polyLine->GetPoint(i).y0; // point.z0 = polyLine->GetPoint(i).z0; // PointList.AddTail(point); // } // CCurveEx* pCurveNew = new CCurveEx; // pCurveNew->SetName(polyLine->GetName()); // pCurveNew->SetPoints(PointList, 2); // //增加曲线 // pos = GetDoc()->GetDraw()->AddElement(pCurveNew, DOUBLEFOX_CURVE); // addList.AddTail(pos); //} int nCount = addList.GetCount(); if (nCount > 0) { CActionListItem* pItem = new CActionListItem(GetDoc(), ID_EDIT_TOOL_CONNECT_CURVE); pItem->AddAddItem(addList); if (deleteOriginalCurves) { pItem->AddDeleteItem(removeElements); } GetDoc()->SetActionItem(pItem); } return nCount; } bool CItemCurveProcess::ToRedundant(double tolerance, CPositionList & selectSet) { if (tolerance < 0) return false; if (selectSet.IsEmpty()) return false; CActionListItem* pAction = new CActionListItem(GetDoc(), ID_PROCESS_CURVE_REDUNDANT); int count = 0; POSITION pos, pt; COne* pOne; CCurveEx* pCurve; pos = selectSet.GetHeadPosition(); while (pos) { pt = selectSet.GetNext(pos); pOne = m_pDoc->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) continue; pCurve = (CCurveEx*)pOne->GetValue(); CActionModifiedItem* pModifiedItem = new CActionModifiedItem(GetDoc(), IDS_STRING_CURVE); pModifiedItem->BackupOldItem(pt, pOne); CCurveEx* pc = new CCurveEx; *pc = *pCurve; CCurveRedundant cr(*pc); cr.Execute(tolerance); cr.GetRedundantCurve(*pCurve); if (pCurve->bAutoLocation) pCurve->GetLocation(); delete pc; pModifiedItem->BackupNewItem(); pAction->AddTailItem(pModifiedItem); count++; m_pDoc->Modified(); } if (count > 0) GetDoc()->SetActionItem(pAction); else delete pAction; return count !=0 ; } //光滑曲线 //mode 0--B样条 1--三次样条 bool CItemCurveProcess::SmoothCurve(int mode, double step, CPositionList & selecctionSet) { if (selecctionSet.IsEmpty()) return false; if (mode != 0 && mode != 1) return false; CActionListItem* pAction = new CActionListItem(GetDoc(), ID_PROCESS_CURVE_SMOOTH); CPointList bp; int count = 0; POSITION pos, pt; COne* pOne; CCurveEx* pCurve; pos = selecctionSet.GetHeadPosition(); while (pos) { pt = selecctionSet.GetNext(pos); pOne = m_pDoc->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) continue; pCurve = (CCurveEx*)pOne->GetValue(); CActionModifiedItem* pModifiedItem = new CActionModifiedItem(GetDoc(), IDS_STRING_CURVE); pModifiedItem->BackupOldItem(pt, pOne); switch (mode) { default: case 1: pCurve->CurveToBezier(bp, step, FALSE); break; case 0: pCurve->CurveToSpline(bp, step, FALSE); break; } pCurve->SetPoints(bp, pCurve->nPoint, pCurve->bAutoLocation); bp.RemoveAll(); count++; pModifiedItem->BackupNewItem(); pAction->AddTailItem(pModifiedItem); } if (count > 0) GetDoc()->SetActionItem(pAction); else delete pAction; return count != 0; } int CItemCurveProcess::SetProcessIdea(int nIdea) { if (nIdea < 1 || nIdea > 23) return -1; m_idea=nIdea; return 1; } int CItemCurveProcess::SetNullEmbellish(void) { CSigmaDoc * pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; int count=0; POSITION pos,pt; COne* pOne; CCurveEx* pCurve; //为了修饰的Redo/Undo CActionComboItem *pAction= new CActionComboItem(pDoc, IDS_GI_EMBELLISH_SELF); pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; //for undo/redo CActionEmbellishItem* pActionItem=new CActionEmbellishItem(pDoc, 0, pOne); pActionItem->SetOldHowToView(pOne); //备份老修饰 if(pOne->HowToViewCurve!=NULL) { delete pOne->HowToViewCurve; pOne->HowToViewCurve=NULL; } //清除原始属性 pOne->color=0; pCurve=(CCurveEx*)pOne->GetValue(); pCurve->width=0; pCurve->m_type=0; pCurve->VirtualType.Clear(); pActionItem->SetNewHowToView(pOne); pAction->AddAction(pActionItem); count++; } if (count > 0) { m_pDoc->Modified(); pDoc->SetActionItem(pAction); } else { delete pAction; } return count; } int CItemCurveProcess::SetEmbellish(void) { /* CXTPResizePropertySheet sheet(IDS_STRING_PANE_PROPERTIES, GetView()); sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW; CDFDrawProDoc* pDoc=GetDoc(); CEmbellishPage page; //page.SetUnit(pDoc->GetDraw()->GetUnit()); page.SetUnitMode(GetUnitMode().m_unit, GetUnitMode().m_dScaleFactor, GetUnitMode().m_nMode); sheet.AddPage(&page); if(sheet.DoModal()!=IDOK) return 0; if(page.GetHowToViewCurve()==NULL) return 0; */ CSigmaDoc * pDoc = GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; int count=0; POSITION pos,pt; COne* pOne; //为了修饰的Redo/Undo CActionComboItem *pAction= new CActionComboItem(pDoc, IDS_GI_EMBELLISH_SELF); pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; ////for undo/redo CActionEmbellishItem* pActionItem=new CActionEmbellishItem(pDoc, 0, pOne); pActionItem->SetOldHowToView(pOne); //备份老修饰 if(pOne->HowToViewCurve) delete pOne->HowToViewCurve; pOne->HowToViewCurve=new CHowToViewCurve(); *pOne->HowToViewCurve=m_CurveStyle; pActionItem->SetNewHowToView(pOne); //备份新修饰 pAction->AddAction(pActionItem); count++; } if (count > 0) { m_pDoc->Modified(); pDoc->SetActionItem(pAction); } else { delete pAction; } return count; } int CItemCurveProcess::AutoLocation(void) { CSigmaDoc * pDoc = GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; //for redo/undo CActionBackupItem* pAction=new CActionBackupItem(pDoc, ID_OPERATION_CURVE_LOCATION); int count=0; POSITION pos,pt; COne* pOne; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); if(pCurve->bAutoLocation) continue; pAction->Backup(pOne); pCurve->bAutoLocation=TRUE; if(pCurve->nPoint>3)pCurve->nPoint=3; pCurve->GetLocation(); count++; } if (count > 0) { pAction->BackupNew(); pDoc->SetActionItem(pAction); } else delete pAction; return count; } int CItemCurveProcess::Reversal(void) { CSigmaDoc * pDoc = GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; //for redo/undo pDoc->SetActionItem(new CActionCurveReversalItem(pDoc, ID_OPERATION_CURVE_REVERSAL, select)); pDoc->Modified(); int count=0; POSITION pos,pt; COne* pOne; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); pCurve->Reversal(); if(pCurve->bAutoLocation) pCurve->GetLocation(); count ++; } return count; } //#include "DrawModelColor\colorsheet.h" int CItemCurveProcess::CurveContour(void) { return 0; /* CSigmaDoc * pDoc = GetDoc(); CColorSheet sheet("Color", GetView()); if(m_pColor==NULL) m_pColor=new CColorBase; sheet.SetColor(m_pColor); sheet.SetWizardMode(); if(sheet.DoModal()!=ID_WIZFINISH) // if(!m_pColor->CreateWizard(GetView(),0)) return 0; CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CActionListItem* pAction=new CActionListItem(pDoc, ID_OPERATION_CURVE_CONTOUR); COLORREF col=0; int count=0; POSITION pos,pt; COne* pOne; double value; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; value=atof(((CCurveEx*)pOne->GetValue())->GetName()); col=m_pColor->GetColor(value); if(col == pOne->color) continue; pAction->AddChangeColorItem(pt, pOne->color, col); //for redo/undo pOne->color=col; count++; } if(count>0) pDoc->SetActionItem(pAction); else delete pAction; return count; */ } int CItemCurveProcess::SetName(void) { return 0; /* CPropertiesSheet sheet(IDS_STRING_CURVE,GetView(),0,FALSE); sheet.SetItem(this); if(sheet.DoModal()!=IDOK) return 0; CDFDrawProDoc* pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CActionListItem* pAction=new CActionListItem(pDoc, ID_OPERATION_CURVE_CONTOUR); CCurveEx* pCurve; int count=0; POSITION pos,pt; COne* pOne; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); pAction->AddChangeNameItem(pt, pCurve->GetName(), name); pCurve->SetName(name); count++; } if(count>0) pDoc->SetActionItem(pAction); else delete pAction; return count; */ } int CItemCurveProcess::NameToZ(void) { CSigmaDoc * pDoc = GetDoc(); CRect8 rect = this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect, select); if (select.IsEmpty()) return 0; //for redo/undo CActionBackupItem* pAction = new CActionBackupItem(pDoc, ID_OPERATION_CURVE_NAMETOZ); int count = 0, i; double z; POSITION pos, pt; COne* pOne; CCurveEx* pCurve; pos = select.GetHeadPosition(); while (pos) { pt = select.GetNext(pos); pOne = pDoc->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE)continue; pCurve = (CCurveEx*)pOne->GetValue(); z = atof(pCurve->GetName()); pAction->Backup(pOne); for (i = 0; i < pCurve->num; i++) pCurve->z[i] = z; if (pCurve->nPoint < 3)pCurve->nPoint = 3; count++; } if (count > 0) { pAction->BackupNew(); pDoc->SetActionItem(pAction); pDoc->Modified(); } else delete pAction; return count; } int CItemCurveProcess::SetZFromSurface(void) { CSigmaDoc * pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; POSITION pos = GetDoc()->GetDraw()->FindFirstElement(DOUBLEFOX_MESH); if (pos == NULL) { return 0; } CMesh* pMesh = (CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); //for redo/undo CActionBackupItem* pAction=new CActionBackupItem(pDoc, ID_PROCESS_SURFACE_LINEVALUE); int count = 0; COne* pOne; POSITION pt; CPointList dp; dfPoint point; double dx, dy; pMesh->GetDelt(dx, dy); CRect8 range = pMesh->GetRect(); CCurveEx *pCurve; pos = select.GetHeadPosition(); while (pos) { pt = select.GetNext(pos); pOne = GetDoc()->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) continue; pCurve = (CCurveEx*)pOne->GetValue(); if (!pCurve->IsInRange(range)) continue; pAction->Backup(pt); //switch (m_nLineValueMode) //{ //case 0://根据源节点 for (int i = 0; i < pCurve->num; i++) { if (!range.PtInRect(pCurve->x[i], pCurve->y[i]))continue; pCurve->z[i] = pMesh->GetValue(pCurve->x[i], pCurve->y[i]); if (pCurve->nPoint < 3) { pCurve->nPoint = 3; } } // break; //case 1://根据步长重新插值 // if (m_dLineValueStep < 1e-10) // m_dLineValueStep = min(dx, dy); // pCurve->GetPoint(0, point); // if (range.PtInRect(point.x0, point.y0)) // point.z0 = pMesh->GetValue(point.x0, point.y0); // dp.AddTail(point); // { // int si = 1; // int i = 0; // double l0 = pCurve->l[0] + m_dLineValueStep; // double lmax = pCurve->l[pCurve->num - 1]; // if (pCurve->l[0] > pCurve->l[pCurve->num - 1]) // { // l0 = pCurve->l[pCurve->num - 1] + m_dLineValueStep; // lmax = pCurve->l[0]; // si = -1; // i = pCurve->num - 2; // } // while (l0 < lmax) // { // if (l0 > pCurve->l[i]) // { // pCurve->GetPoint(i, point); // if (range.PtInRect(point.x0, point.y0)) // point.z0 = pMesh->GetValue(point.x0, point.y0); // dp.AddTail(point); // i += si; // } // point.l = l0; // pCurve->GetCoordinate(point.l, point.x0, point.y0, point.z0); // if (range.PtInRect(point.x0, point.y0)) // point.z0 = pMesh->GetValue(point.x0, point.y0); // dp.AddTail(point); // l0 += m_dLineValueStep; // } // } // pCurve->GetPoint(pCurve->num - 1, point); // if (range.PtInRect(point.x0, point.y0)) // point.z0 = pMesh->GetValue(point.x0, point.y0); // dp.AddTail(point); // if (pCurve->nPoint < 3) pCurve->nPoint = 3; // pCurve->SetPoints(dp, pCurve->nPoint, pCurve->bAutoLocation); // dp.RemoveAll(); // break; //} count++; } if (count > 0) { //GetDoc()->SetModifiedFlag(); pAction->BackupNew(); GetDoc()->SetActionItem(pAction); } else delete pAction; return count; } int CItemCurveProcess::ZToName(void) { CSigmaDoc * pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CActionListItem* pAction=new CActionListItem(pDoc, ID_OPERATION_CURVE_ZTONAME); int count=0; CString name; POSITION pos,pt; COne* pOne; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); std::unique_ptr pModifiedItem = std::make_unique(GetDoc(), 0); pModifiedItem->BackupOldItem(pt, pOne); ::AfxGetPublicFunction()->FloatToString(name,pCurve->z[0]); pCurve->SetName(name); pModifiedItem->BackupNewItem(); pAction->AddTailItem(pModifiedItem.release()); count++; } if (count > 0) { pDoc->SetActionItem(pAction); pDoc->Modified(); } else delete pAction; return count; } int NItem::CItemCurveProcess::LayerToName(void) { CSigmaDoc * pDoc = GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; //for redo/undo //CActionListItem* pAction=new CActionListItem(pDoc, ID_OPERATION_CURVE_LAYER_TO_NAME); // int count=0; CString name; POSITION pos,pt; COne* pOne; CLayerName ln; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); ln.SetPathName(pOne->m_pLayer->GetPathName()); name=ln.GetTailPathName(); //pAction->AddChangeNameItem(pt, pCurve->GetName(), name); pCurve->SetName(name); count++; } //if(count>0) pDoc->SetActionItem(pAction); //else delete pAction; return count; } int CItemCurveProcess::NameLog(void) { return 0; /* CPropertiesSheet sheet(IDS_STRING_CURVE,GetView(),0,FALSE); sheet.SetItem(this); if(sheet.DoModal()!=IDOK) return 0; if(!(a>1e-300 && a!=1.0) && m_bIsE==FALSE) return 0; CDFDrawProDoc* pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; //for redo/undo CActionListItem* pAction=new CActionListItem(pDoc, ID_OPERATION_CURVE_NAME_LOG); CCurveEx* pCurve; int count=0; POSITION pos,pt; COne* pOne; double b; CString name; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); b=atof(pCurve->GetName()); if(fabs(b)<1e-100) continue; if(m_bIsE)//为自然对数 b=log(b); else b=log(b)/log(a); if(decimal==0) name.Format("%.0lf",b); else ::AfxGetPublicFunction()->FloatToString(name,b,decimal); pAction->AddChangeNameItem(pt, pCurve->GetName(), name); pCurve->SetName(name); count++; } if(count>0) pDoc->SetActionItem(pAction); else delete pAction; return count; */ } int CItemCurveProcess::NameExponential(void) { return 0; /* CPropertiesSheet sheet(IDS_STRING_CURVE,GetView(),0,FALSE); sheet.SetItem(this); if(sheet.DoModal()!=IDOK) return 0; if(!(a>1e-300 && a!=1.0) && m_bIsE==FALSE) return 0; CDFDrawProDoc* pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; //for redo/undo CActionListItem* pAction=new CActionListItem(pDoc, ID_OPERATION_CURVE_NAME_EXPONENTIAL); CCurveEx* pCurve; int count=0; POSITION pos,pt; COne* pOne; double b; CString name; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); b=atof(pCurve->GetName()); if(fabs(b)<1e-100) continue; if(m_bIsE)//为自然对数 b=exp(b); else b=pow(a,b); if(decimal==0) name.Format("%.0lf",b); else ::AfxGetPublicFunction()->FloatToString(name,b,decimal); pAction->AddChangeNameItem(pt, pCurve->GetName(), name); pCurve->SetName(name); count++; } if(count>0) pDoc->SetActionItem(pAction); else delete pAction; return count; */ } struct CItemCruveProcessItem { CItemCruveProcessItem() = default; CItemCruveProcessItem(uint64_t id, const CString &name, POSITION position) { this->id = id; this->name = name; this->position = position; } uint64_t id = 0; CString name; POSITION position; }; static std::string ConvertCurvesOfEmptyNameToXML(const std::vector & items); std::string CItemCurveProcess::FindNameIsNull(CPositionList & selectionSet) { if (selectionSet.IsEmpty()) return ""; int count = 0; int sel = 0; POSITION pos, pt; COne* pOne; //CString type, txt; //type.LoadString(IDS_STRING_CURVE); pos = selectionSet.GetHeadPosition(); std::vector curveItemArray; CString numberStr; while (pos) { pt = selectionSet.GetNext(pos); pOne = m_pDoc->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) continue; if (((CCurveEx*)pOne->GetValue())->name != NULL) continue; curveItemArray.emplace_back(count + 1, pOne->GetLayer()->GetPathName(), pt); count++; } return ConvertCurvesOfEmptyNameToXML(curveItemArray); /* CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame(); ASSERT(pmf); pmf->ShowPane(COMMAND_BAR_RESULT_LIST); CListCtrl* pList=pmf->GetResultListCtrl(); ASSERT(pList); pmf->m_pPaneResultList->InitList(); CDFDrawProDoc* pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; int count=0,sel; POSITION pos,pt; COne* pOne; CString type,txt; type.LoadString(IDS_STRING_CURVE); pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; if(((CCurveEx*)pOne->GetValue())->name!=NULL)continue; txt.Format("%ld",count+1); sel=pList->InsertItem(count,txt); pList->SetItemText(sel,2,type); pList->SetItemText(sel,3,pOne->GetLayer()->GetPathName()); pList->SetItemData(sel,(DWORD)pOne); count++; } return count; */ } int CItemCurveProcess::AnyName(void) { return 0; /* CPropertySheet sheet(IDS_STRING_PANE_PROPERTIES, GetView()); sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW; CDFDrawProDoc* pDoc=GetDoc(); CEmbellishPage page; //page.SetUnit(pDoc->GetDraw()->GetUnit()); page.SetUnitMode(GetUnitMode().m_unit, GetUnitMode().m_dScaleFactor, GetUnitMode().m_nMode); sheet.AddPage(&page); CHowToViewCurve* pHowToViewCurve=new CHowToViewCurve; pHowToViewCurve->Add(new CCurveInNameAny()); page.SetHowToViewCurve(pHowToViewCurve); delete pHowToViewCurve; if(sheet.DoModal()!=IDOK) return 0; if(page.GetHowToViewCurve()==NULL) return 0; ASSERT(GetPos()); CRect8 rect=this->GetRect(); CPositionList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CCurveEx* pCurve=(CCurveEx*)pDoc->GetDraw()->GetAtValue(GetPos()); CCurveEx* pcn; CCurveInNameAny* pany; int i,j; for(i=0; iGetCount(); ++i) { if(page.GetHowToViewCurve()->GetAt(i)->GetType()!=CurveInNameAny)continue; j=i; break; } CCrossPoint cp; POSITION ts; CCrossList xy; int count=0; POSITION pos,pt; COne* pOne; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); if(pt==GetPos())continue; pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pcn=(CCurveEx*)pOne->GetValue(); pcn->Cross(*(CCurve*)pCurve,xy); if(xy.IsEmpty()) continue; if(pOne->HowToViewCurve==NULL) pOne->HowToViewCurve=new CHowToViewCurve; *pOne->HowToViewCurve=*page.GetHowToViewCurve(); pany=(CCurveInNameAny*)pOne->HowToViewCurve->GetAt(j); pany->m_nameNum=(int)xy.GetCount(); pany->l0=new double[pany->m_nameNum]; ts=xy.GetHeadPosition(); for(i=0;im_nameNum;i++) { cp=xy.GetNext(ts); pany->l0[i]=cp.x[0]; } xy.RemoveAll(); count++; } return count; */ } POSITION CItemCurveProcess::SelectOneCurve(UINT nFlags, CPoint point) { CSigmaDoc* pDoc=GetDoc(); CPoint2D rp=GetDC()->GetReal(point); POSITION pos=NULL; //if(pDoc->IsMoveSelect() && pDoc->MoveSelect!=NULL) // pos=pDoc->MoveSelect; //else pos=pDoc->GetSelectedItem(rp); if(pos==NULL) { ::AfxMessageBox(IDS_STRING_NOT_ELEMENT); return NULL; } else if(pDoc->GetDraw()->GetElementType(pos)!=DOUBLEFOX_CURVE) { ::AfxMessageBox(IDS_STRING_IS_NOT_CURVE); return NULL; } return pos; } void CItemCurveProcess::OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk) { m_processResult = 0; if(m_idea==CURVE_ANY_NAME && GetPos()==NULL) { position=SelectOneCurve(nFlags,point); if(GetPos())OnDraw(GetDC()); } else CItemFocusRect::OnLButtonDown(pDC, nFlags,point, vk); } void CItemCurveProcess::OnRButtonDown(UINT nFlags, CPoint point) { m_processResult = 0; switch(m_idea) { case CURVE_REVERSAL: case CURVE_CLOSE: //GetDoc()->EnableDefaultTool(); break; default: break; } } BOOL CItemCurveProcess::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { return TRUE; /* if(m_idea==CURVE_ANY_NAME && GetPos()==NULL) { CSigmaDoc * pDoc = GetDoc(); pDoc->GetCursor().SetCursor(CursorSelectItem); return pDoc->GetCursor().SetCursor(); } return CItemFocusRect::OnSetCursor(pWnd,nHitTest,message); */ } void CItemCurveProcess::OnDraw(CXyDC* pDC) { if(GetPos()==NULL) return; CSigmaDoc * pDoc=GetDoc(); CCurveEx* pCurve=(CCurveEx*)pDoc->GetDraw()->GetAtValue(GetPos()); CItemLinkCurve item(pDoc); item.Draw(pDC,pCurve,RGB(255,0,0)); } int CItemCurveProcess::CurveSmooth(void) { return 0; /* CString str; str.LoadString(IDS_GI_CURVE_PROCESS_SMOOTH_HEAD); 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 0; CDFDrawProDoc* pDoc=GetDoc(); CRect8 rect=this->GetRect(); CPositionList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CActionListItem* pAction=new CActionListItem(pDoc, ID_PROCESS_CURVE_SMOOTH); CPointList bp; int count=0; POSITION pos,pt; COne* pOne; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); pAction->AddModifiedItem(pt, pOne); switch(m_selSmooth) { default: case 1: pCurve->CurveToBezier(bp, a, FALSE); break; case 0: pCurve->CurveToSpline(bp, a, FALSE); break; } pCurve->SetPoints(bp, pCurve->nPoint, pCurve->bAutoLocation); bp.RemoveAll(); count++; } if(count>0) pDoc->SetActionItem(pAction); else delete pAction; return count; */ } int NItem::CItemCurveProcess::ToWave(void) { return 0; /* CString str; str.LoadString(ID_PROCESS_CURVE_TO_WAVE); 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 0; CDFDrawProDoc* pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CActionListItem* pAction=new CActionListItem(pDoc, ID_PROCESS_CURVE_TO_WAVE); CPointList bp; int count=0; POSITION pos,pt; COne* pOne; COne* pNewOne; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); if(m_bDeleteSourveCurve) { if(pCurve->CurveToWave(bp, cycle, swing, dnum)>0) { pAction->AddModifiedItem(pt, pOne); pCurve->SetPoints(bp, pCurve->nPoint, pCurve->bAutoLocation); bp.RemoveAll(); count++; } } else { pNewOne=new COne; *pNewOne=*pOne; pCurve=(CCurveEx*)pNewOne->GetValue(); if(pCurve->CurveToWave(bp, cycle, swing, dnum)>0) { pCurve->SetPoints(bp, pCurve->nPoint, pCurve->bAutoLocation); pDoc->AddElement(pNewOne); pAction->AddAddItem(pNewOne); bp.RemoveAll(); count++; } } } if(count>0) pDoc->SetActionItem(pAction); else delete pAction; return count; */ } int NItem::CItemCurveProcess::CurveOffset(void) { return 0; /* CString str; str.LoadString(ID_PROCESS_CURVE_OFFSET); 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 0; CDFDrawProDoc* pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CActionListItem* pAction=new CActionListItem(pDoc, ID_PROCESS_CURVE_OFFSET); CPointList bp; int count=0; POSITION pos,pt; COne* pNewOne; COne* pOne; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); if(m_bDeleteSourveCurve) { pAction->AddModifiedItem(pt, pOne); (*(CCurve*)pCurve) += m_dCurveOffset; } else { pNewOne=new COne; *pNewOne=*pOne; (*(CCurve*)pNewOne->GetValue()) += m_dCurveOffset; pDoc->AddElement(pNewOne); pAction->AddAddItem(pNewOne); } count++; } if(count>0) pDoc->SetActionItem(pAction); else delete pAction; return count; */ } int NItem::CItemCurveProcess::NodeEncrypt(void) { return 0; /* CString str; str.LoadString(ID_PROCESS_CURVE_ENCRYPT); 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 0; CDFDrawProDoc* pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CActionListItem* pAction=new CActionListItem(pDoc, ID_PROCESS_CURVE_ENCRYPT); int count=0; POSITION pos,pt; COne* pOne; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); pAction->AddModifiedItem(pt, pOne); pCurve->EncryptNode(m_nMode, m_dStep, m_bInteger); count++; } if(count>0) pDoc->SetActionItem(pAction); else delete pAction; return count; */ } int NItem::CItemCurveProcess::ToRedundant(void) { return 0; /* CString str; str.LoadString(ID_PROCESS_CURVE_REDUNDANT); 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 0; CDFDrawProDoc* pDoc=GetDoc(); CRect8 rect=this->GetRect(); CList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CActionListItem* pAction=new CActionListItem(pDoc, ID_PROCESS_CURVE_REDUNDANT); int count=0; POSITION pos,pt; COne* pOne; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE)continue; pCurve=(CCurveEx*)pOne->GetValue(); pAction->AddModifiedItem(pt, pOne); CCurveEx* pc=new CCurveEx; *pc=*pCurve; CCurveRedundant cr(*pc); cr.Execute(m_error); cr.GetRedundantCurve(*pCurve); if(pCurve->bAutoLocation) pCurve->GetLocation(); delete pc; count++; } if(count>0) pDoc->SetActionItem(pAction); else delete pAction; return count; */ } void NItem::CItemCurveProcess::SetCurveStyle(CHowToViewCurve& curveStyle) { this->m_CurveStyle = curveStyle; } int CItemCurveProcess::ArcToCurve(CPositionList & select, double step) { CSigmaDoc * pDoc = GetDoc(); CRect8 rect = this->GetRect(); //CPositionList select; //pDoc->GetDraw()->IsInRange(rect,select); //if(select.IsEmpty()) return 0; //for redo/undo CActionBackupItem* pAction = new CActionBackupItem(pDoc, ID_PROCESS_ARC_TO_CURVE); COne* pOne; // COne *pOneOther; CArc* parc; CEllipse* pEll; CCurveEx* pc; int c = 0; POSITION pos, pt; pos = select.GetHeadPosition(); while (pos) { pt = select.GetNext(pos); pOne = pDoc->GetDraw()->GetAt(pt); switch (pOne->GetType()) { default: continue; case DOUBLEFOX_ARC: pAction->Backup(pOne); parc = (CArc*)pOne->GetValue(); pc = new CCurveEx; parc->GetCurve(a); *pc = *parc->GetCurve(); break; case DOUBLEFOX_CIRCLE: case DOUBLEFOX_ELLIPSE: pAction->Backup(pOne); pEll = (CEllipse*)pOne->GetValue(); pc = pEll->ToCurve(a); break; case DOUBLEFOX_CRECT: pAction->Backup(pOne); pc = new CCurveEx; ((CCurveRect*)pOne->GetValue())->GetCurve(*pc); break; } //备份,为了redo undo //pOneOther=new COne; //*pOneOther=*pOne; //类型转换为曲线 pOne->ClearValue(); pOne->SetValue(pc, DOUBLEFOX_CURVE); c++; } if (c > 0) { pAction->BackupNew(); pDoc->SetActionItem(pAction); pDoc->Modified(); } else delete pAction; return c; } void NItem::CItemCurveProcess::SetCurveName(CString curveName, CPositionList & selectionSet) { CSigmaDoc * pDoc = GetDoc(); CActionListItem* pAction = new CActionListItem(pDoc, ID_OPERATION_CURVE_CONTOUR); CCurveEx* pCurve; int count = 0; POSITION pos, pt; COne* pOne; pos = selectionSet.GetHeadPosition(); while (pos) { pt = selectionSet.GetNext(pos); pOne = pDoc->GetDraw()->GetAt(pt); if (pOne->GetType() != DOUBLEFOX_CURVE) continue; pCurve = (CCurveEx*)pOne->GetValue(); pAction->AddChangeNameItem(pt, pCurve->GetName(), curveName); pCurve->SetName(curveName); count++; } if (count > 0) pDoc->SetActionItem(pAction); else delete pAction; //return count; } int NItem::CItemCurveProcess::CloseCurve(void) { CSigmaDoc * pDoc = GetDoc(); CRect8 rect=this->GetRect(); CPositionList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; //for redo/undo CActionBackupItem* pAction=new CActionBackupItem(pDoc, ID_OPERATION_CURVE_CLOSE); int count=0; POSITION pos,pt; COne* pOne; CCurveEx* pCurve; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if(pOne->GetType()!=DOUBLEFOX_CURVE) continue; pAction->Backup(pOne); pCurve=(CCurveEx*)pOne->GetValue(); if(!pCurve->EnableClose(TRUE)) //设置不成功时,删除备份 { pAction->RemoveBackupTail(); } else { if (pCurve->bAutoLocation) { pCurve->GetLocation(); } count++; } } if (count > 0) { pAction->BackupNew(); pDoc->SetActionItem(pAction); pDoc->Modified(); } else delete pAction; return count; } int NItem::CItemCurveProcess::AutoLinkCurve(double maxError /*= 1E-5*/, bool onlySameName) { double dMaxError = maxError == 0 ? 0.0001 : maxError; int count=0; CClassList* pClassList= GetDoc()->GetDraw()->GetClassList(); CLayerList* pLayerList; CLayer* pLayer; CPositionList select; double num=pClassList->GetLayerCount(); CActionListItem* pAction=new CActionListItem(GetDoc(), ID_PROCESS_CURVE_AUTO_LINK); POSITION pos, pt; pos=pClassList->GetHeadPosition(); while(pos) { pLayerList=pClassList->GetNext(pos); pt=pLayerList->GetHeadPosition(); while(pt) { pLayer=pLayerList->GetNext(pt); select.RemoveAll(); CXyElementFilter filter; filter.addLayer(pLayer->GetName(), true) .addType(DOUBLEFOX_CURVE) .setIncludeHidden(false) .setIncludeNotEditable(false); if(GetDoc()->GetDraw()->GetElement(filter, select)<1) continue; //连接曲线,被连接的曲线必须是同一个类别下的曲线 while(1) { if(select.GetCount()<=1) break; int n=GetNextLinkCurve(select, pAction, dMaxError, onlySameName); count+=n; } } } if(count>0) GetDoc()->SetActionItem(pAction); else delete pAction; return count; } int NItem::CItemCurveProcess::GetNextLinkCurve(CPositionList& select, void* pActionList, double maxError, bool onlySameName) { if(select.GetCount()<=1) return 0; CActionListItem* pAction=(CActionListItem*)pActionList; POSITION pos, posBak, posHead, posNext; CPointList bp; dfPoint head, tail; int sel; //1(head,head),2(head,tail),3(tail,head),4(tail,tail) double dis, dis_tail; CCurveEx* pCurve; int total=0; int count=0; //连接曲线的条数 CSigmaDoc* pDoc=GetDoc(); posHead=select.GetHead(); COne* pHeadOne=pDoc->GetDraw()->GetAt(posHead); CCurveEx* pHeadCurve=(CCurveEx*)pHeadOne->GetValue(); select.RemoveHead(); //去除第一条曲线 if(::AfxGetPublicFunction()->IsCurveSolid(pHeadCurve->m_type)) return 0; pHeadCurve->GetPoint(bp); head=bp.GetHead(); tail=bp.GetTail(); CString strCurveName = pHeadCurve->GetName(); while(1) { count=0; pos=select.GetHeadPosition(); while(pos) { posBak=pos; posNext=select.GetNext(pos); pCurve=(CCurveEx*)pDoc->GetDraw()->GetAtValue(posNext); if(::AfxGetPublicFunction()->IsCurveSolid(pCurve->m_type)) continue; if (onlySameName) { CString strCurveNameNext = pCurve->GetName(); if (strCurveNameNext != strCurveName) { continue; } } sel=1; dis=::AfxGetPublicFunction()->Distance2(head.x0, head.y0, pCurve->x[0], pCurve->y[0]); dis_tail=::AfxGetPublicFunction()->Distance2(head.x0, head.y0, pCurve->x[pCurve->num-1], pCurve->y[pCurve->num-1]); if(dis>dis_tail) {sel=2; dis=dis_tail;} dis_tail=::AfxGetPublicFunction()->Distance2(tail.x0, tail.y0, pCurve->x[0], pCurve->y[0]); if(dis>dis_tail) {sel=3; dis=dis_tail;} dis_tail=::AfxGetPublicFunction()->Distance2(tail.x0, tail.y0, pCurve->x[pCurve->num-1], pCurve->y[pCurve->num-1]); if(dis>dis_tail) {sel=4; dis=dis_tail;} dis=sqrt(dis); if(dis> maxError) continue; switch(sel) { case 1://head,head pCurve->GetPoint(bp, FALSE, TRUE); break; case 2://head,tail pCurve->GetPoint(bp, TRUE, TRUE); break; case 3://tail,head pCurve->GetPoint(bp, FALSE, FALSE); break; case 4://tail,tail pCurve->GetPoint(bp, TRUE, FALSE); break; } pAction->AddDeleteItem(posNext); count++; select.RemoveAt(posBak); head=bp.GetHead(); tail=bp.GetTail(); } if(count==0) break; total+=count; } if(total==0) return 0; pAction->AddDeleteItem(posHead); total++; pCurve=new CCurveEx; *pCurve=*pHeadCurve; pCurve->SetPoints(bp, 2); COne* pNewOne=new COne; pNewOne->CloneOtherParameter(*pHeadOne); pNewOne->value=pCurve; pos=pDoc->GetDraw()->InsertElementBefore(posHead, pNewOne); pAction->AddAddItem(pNewOne); total++; return total; } //将给定的散点自动连接形成一条曲线 int NItem::CItemCurveProcess::FittingCurve(void) { CSigmaDoc * pDoc=GetDoc(); CRect8 rect=this->GetRect(); CPositionList select; pDoc->GetDraw()->IsInRange(rect,select); if(select.IsEmpty()) return 0; CPointList bp; dfPoint point; CPointNameEx* pp; POSITION pos,pt; COne* pOne; pos=select.GetHeadPosition(); while(pos) { pt=select.GetNext(pos); pOne=pDoc->GetDraw()->GetAt(pt); if( pOne->GetType()!=DOUBLEFOX_POINT && pOne->GetType() != DOUBLEFOX_XYZ) continue; pp=(CPointNameEx*)pOne->GetValue(); point.x0 = pp->x0; point.y0 = pp->y0; bp.AddTail(point); } if(bp.GetCount()<=1) return 0; CCurveEx* pCurve = new CCurveEx; pCurve->SetPoints(bp, 2); if(pCurve->num>2) { ::AfxGetBaseFunction()->SortCoordinate(pCurve->x, pCurve->y, pCurve->num); pCurve->GetLocation(); } //增加曲线 pos=pDoc->GetDraw()->AddElement(pCurve, DOUBLEFOX_CURVE); if(pos) pDoc->Invalidate(pos); pDoc->Modified(); //Redo/Undo surport pOne=pDoc->GetDraw()->GetAt(pos); GetView()->ActionAdd(pOne, ID_PROCESS_CURVE_FITTING); return 1; } static void AddCurvesElement(TiXmlElement *rootElement, uint64_t id, const CString & pathName, POSITION position) { CString name, txt; TiXmlElement *itemElement = new TiXmlElement("Item"); rootElement->LinkEndChild(itemElement); TiXmlElement *idElement = new TiXmlElement("ID"); TiXmlElement *nameElement = new TiXmlElement("Name"); TiXmlElement *typeElement = new TiXmlElement("Type"); TiXmlElement *layerElement = new TiXmlElement("Layer"); TiXmlElement *symbolElement = new TiXmlElement("Symbol"); TiXmlElement *lengthElement = new TiXmlElement("RealLength"); TiXmlElement *areaElement = new TiXmlElement("Area"); TiXmlElement *azimuthElement = new TiXmlElement("Azimuth"); TiXmlElement *positionElement = new TiXmlElement("Position"); TiXmlElement *xElement = new TiXmlElement("X"); TiXmlElement *yElement = new TiXmlElement("Y"); TiXmlElement *zElement = new TiXmlElement("Z"); itemElement->LinkEndChild(idElement); //TiXmlElement *zElement = new TiXmlElement("Z"); itemElement->LinkEndChild(idElement); itemElement->LinkEndChild(nameElement); itemElement->LinkEndChild(typeElement); itemElement->LinkEndChild(layerElement); itemElement->LinkEndChild(symbolElement); itemElement->LinkEndChild(lengthElement); itemElement->LinkEndChild(areaElement); itemElement->LinkEndChild(azimuthElement); itemElement->LinkEndChild(positionElement); itemElement->LinkEndChild(xElement); itemElement->LinkEndChild(yElement); itemElement->LinkEndChild(zElement); TiXmlText *idValue = new TiXmlText(std::to_string(id).c_str()); idElement->LinkEndChild(idValue); TiXmlText *layerValue = new TiXmlText(pathName); layerElement->LinkEndChild(layerValue); positionElement->LinkEndChild(new TiXmlText(std::to_string((uint64_t)position).c_str())); TiXmlText * typeValue = new TiXmlText("曲线"); typeElement->LinkEndChild(typeValue); } //返回xml字符串 static std::string ConvertCurvesOfEmptyNameToXML(const std::vector & items) { // 创建一个XML的文档对象。 TiXmlDocument *xmlDocument = new TiXmlDocument(); TiXmlDeclaration * decl = new TiXmlDeclaration("1.0", "UTF-8", ""); xmlDocument->LinkEndChild(decl); // 根元素。 TiXmlElement *rootElement = new TiXmlElement("ROOT"); xmlDocument->LinkEndChild(rootElement); size_t count = items.size(); for (const auto &item : items) { AddCurvesElement(rootElement, item.id, item.name, item.position); } TiXmlPrinter printer; string xmlstr; xmlDocument->Accept(&printer); xmlstr = printer.CStr(); return std::string(printer.CStr()); }