#include "StdAfx.h" #include "ItemMeshProcess.h" #include "SigmaDoc.h" #include "SigmaView.h" #include "itemmeshprocess.h" #include "ActionBackupItem.h" CItemMeshProcess::CItemMeshProcess(CSigmaDoc * ppDoc) : CItemSelectCurve(ppDoc) , m_nIdea(0) { this->SetType(ITEM_MESH_PROCESS); m_pItemFocus=new CItemFocusRect(GetDoc()); num=1; m_dValueZ=0; m_nLineValueMode=0; m_dLineValueStep=0; m_nModeSetZ=0; m_nVolumeMode=0; } CItemMeshProcess::~CItemMeshProcess(void) { if(m_pItemFocus) delete m_pItemFocus; m_pItemFocus=NULL; //RemoveAllSelect(); } BOOL CItemMeshProcess::DoSelectEnd(void) { if(SelectList.GetCount()<1) return FALSE; SELECT_ITEM st; st=SelectList.GetHead(); CCurveEx *pc; pc=(CCurveEx*)GetDoc()->GetDraw()->GetAtValue(st.pos); switch(m_nIdea) { case MESH_GEOLOGICAL_SECTION: GeologicalSection(pc); break; case MESH_VOLUME: if(GetVolumeMode()!=-1) Volume(pc, m_nVolumeMode); break; case MESH_SET_VALUE: if(m_nModeSetZ==0) SetValue(pc, m_dValueZ, FALSE); else SetValue(pc, m_dValueZ, TRUE); break; } CItemSelectCurve::DoSelectEnd(); //GetDoc()->EnableDefaultTool(); return TRUE; } void CItemMeshProcess::DoLButtonUp(CRect8& rect) { CPositionList select; GetDoc()->GetDraw()->IsInRange(rect, select); switch(m_nIdea) { case MESH_CUT: Cut(select); break; case MESH_LINE_VALUE: { //POSITION pos=GetDoc()->FindFirstElement(DOUBLEFOX_MESH); //if(pos==NULL) break; //CMesh* pMesh=(CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); //LineValue(pMesh, select); } break; } //GetDoc()->EnableDefaultTool(); } void CItemMeshProcess::OnLButtonDown(CDC *pCDc, UINT nFlags, CPoint point, int vk) { switch(m_nIdea) { case MESH_LINE_VALUE: case MESH_CUT: //m_pItemFocus->OnLButtonDown(nFlags, point); break; default: //CItemSelectCurve::OnLButtonDown(nFlags, point); break; } } int CItemMeshProcess::OnMouseMove(CDC *pDC, UINT nFlags, CPoint point) { switch(m_nIdea) { case MESH_LINE_VALUE: case MESH_CUT: //m_pItemFocus->OnMouseMove(nFlags, point); break; default: //CItemSelectCurve::OnMouseMove(nFlags, point); break; } return 1; } void CItemMeshProcess::OnLButtonUp(CDC *pDC, UINT nFlags, CPoint point, int vk) { switch(m_nIdea) { case MESH_LINE_VALUE: case MESH_CUT: //m_pItemFocus->OnLButtonUp(nFlags, point); //{ // CRect8 rect=m_pItemFocus->GetRect(); // if(!rect.IsEmpty()) // DoLButtonUp(rect); //} break; default: //CItemSelectCurve::OnLButtonUp(nFlags, point); break; } } BOOL CItemMeshProcess::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { switch(m_nIdea) { case MESH_LINE_VALUE: case MESH_CUT: return m_pItemFocus->OnKeyUp(nChar, nRepCnt, nFlags); break; default: return CItemSelectCurve::OnKeyUp(nChar, nRepCnt, nFlags); break; } return FALSE; } BOOL CItemMeshProcess::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { switch(m_nIdea) { case MESH_LINE_VALUE: case MESH_CUT: return m_pItemFocus->OnSetCursor(pWnd, nHitTest, message); break; default: return CItemSelectCurve::OnSetCursor(pWnd, nHitTest, message); break; } return FALSE; } void CItemMeshProcess::SetProcessIdea(int nIdea) { m_nIdea=nIdea; } void CItemMeshProcess::GeologicalSection(CCurveEx* pSplit) { CMesh* pm; CPtrList list; COne* pOne; CCurveEx* psection; CPtrList* pl=GetDoc()->GetDraw()->GetValueList(); POSITION pos=pl->GetHeadPosition(); while(pos) { if(GetDoc()->GetDraw()->GetElementType(pos)==DOUBLEFOX_MESH) { pm=(CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); if(pm->GetDimension()==3) //三维体时获得一个剖面曲面 { CDimension3D* pdfg=new CDimension3D; if(pm->CutSectionDfg(*pSplit, *(CDimension2D*)pdfg)>0) { CMesh* pp=new CMesh; pp->m_nTimes = pm->m_nTimes; pp->SetMesh(pdfg, MESH_DFG, FALSE); pOne=new COne; pOne->SetValue(pp, DOUBLEFOX_MESH); list.AddTail(pOne); } else delete pdfg; } else //二维曲面时获得曲线 { psection=new CCurveEx; if(pm->GeologicalSection(*pSplit, *psection)>0) { pOne=new COne; pOne->SetValue(psection, DOUBLEFOX_CURVE); list.AddTail(pOne); } else delete psection; } } pl->GetNext(pos); } if(list.GetCount()>0) { //CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame(); //CDFDrawProDoc* pDocEnd = (CDFDrawProDoc*) pmf->GetDrawFrame().NewDocument(); POSITION pos=list.GetHeadPosition(); while(pos) { pOne=(COne*)list.GetNext(pos); //pDocEnd->GetDraw()->AddElement(pOne->GetValue(), pOne->GetType()); m_pDoc->GetDraw()->AddElement(pOne->GetValue(), pOne->GetType()); pOne->value=NULL; delete pOne; m_pDoc->Modified(); m_pDoc->GetItemView()->Extend(EXTEND_MODE_DEFAULT); } } } void CItemMeshProcess::Volume(CCurveEx* pCurveRange, int mode) { CPoint3D point; double v=0; double cz=0; //闭合线 CMesh* pm; CPtrList* pl=GetDoc()->GetDraw()->GetValueList(); POSITION pos=pl->GetHeadPosition(); while(pos) { if(GetDoc()->GetDraw()->GetElementType(pos)==DOUBLEFOX_MESH) { pm=(CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); switch(mode) { case 0: //构造图 if(pm->GetHightPoint(pCurveRange, point)>0) //计算高点 { cz=pm->GetClosedZ(*pCurveRange, point.z0); //计算闭合线 v+=pm->Volume(*pCurveRange, cz); //计算体积 } break; case 1: //等厚图 v+=pm->Volume(*pCurveRange, 0); //计算体积 break; } } pl->GetNext(pos); } CString str; AfxGetPublicFunction()->FloatToString(str, v); CClipboard cp; cp.SetText(str); int i=str.ReverseFind('.'); i-=3; while(i>0) { str.Insert(i,','); i-=3; } CString txt; txt.Format("Close Z: %lf\n%s", cz, str); ::AfxMessageBox(txt); } void NItem::CItemMeshProcess::SetValue(CCurveEx* pCurveRange, double z0, BOOL bInCurve) { CPositionList list; //CActionBackupItem* pAction=new CActionBackupItem(GetDoc(), IDS_STRING_MESH_TITLE); CPtrList curveList; curveList.AddTail(pCurveRange); CWaitCursor wc; int count=0; CMesh* pm; CPtrList* pl=GetDoc()->GetDraw()->GetValueList(); POSITION pos=pl->GetHeadPosition(); while(pos) { if(GetDoc()->GetDraw()->GetElementType(pos)==DOUBLEFOX_MESH) { pm=(CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); //pAction->Backup(pos); pm->SetValue(curveList, z0, bInCurve); pm->GetBitmap(); count++; } pl->GetNext(pos); } if(count>0) { GetDoc()->Invalidate(); //GetDoc()->SetActionItem(pAction); } //else delete pAction; } int NItem::CItemMeshProcess::Cut(CMesh* pMesh, CPositionList& select) { if(pMesh==NULL) return 0; double zmin=0, zmax=0; pMesh->GetM(zmin, zmax); double delt=zmax-zmin; CWaitCursor wc; COne* pOne; CCurveEx* pCurve; POSITION pos, pt; CPtrList solidList, closeList; 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(AfxGetPublicFunction()->IsCurveSolid(pCurve->m_type)) solidList.AddTail(pCurve); else closeList.AddTail(pCurve); } if(solidList.GetCount()>0) pMesh->SetValue(solidList, zmin-delt, FALSE); if(closeList.GetCount()>0) pMesh->SetValue(closeList, zmin-delt, TRUE); if(solidList.GetCount()>0 || closeList.GetCount()>0) pMesh->GetBitmap(); return (int)(solidList.GetCount()+closeList.GetCount()); } void NItem::CItemMeshProcess::Cut(CPositionList& select) { if(select.GetCount()==0) return; CPositionList list; //CActionBackupItem* pAction=new CActionBackupItem(GetDoc(), IDS_STRING_MESH_TITLE); int count=0; CMesh* pm; CPtrList* pl=GetDoc()->GetDraw()->GetValueList(); POSITION pos=pl->GetHeadPosition(); while(pos) { if(GetDoc()->GetDraw()->GetElementType(pos)==DOUBLEFOX_MESH) { pm=(CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); //pAction->Backup(pos); count+=Cut(pm, select); } pl->GetNext(pos); } if(count>0) { GetDoc()->Invalidate(); GetDoc()->Modified(); //GetDoc()->SetActionItem(pAction); } //else // delete pAction; } int NItem::CItemMeshProcess::LineValue(CMesh* pMesh, CPositionList& select) { if(pMesh==NULL) return 0; int count=0; COne* pOne; POSITION pos, pt; //CActionBackupItem* pAction=new CActionBackupItem(GetDoc(), ID_PROCESS_SURFACE_LINEVALUE); 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;inum;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(l0pCurve->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(); //GetDoc()->SetActionItem(pAction); //} //else // delete pAction; return count; } void NItem::CItemMeshProcess::OnOK(void) { } void NItem::CItemMeshProcess::OnCancel(void) { } /* INT_PTR NItem::CItemMeshProcess::DoModal(UINT nID) { CString str; str.LoadString(nID); int i=str.Find("\n"); if(i>0) str=str.Left(i); CPropertiesSheet sheet(str, GetView(), 0, FALSE); sheet.SetItem(this); return sheet.DoModal(); } */ void NItem::CItemMeshProcess::LineValue(void) { //INT_PTR rt=DoModal(MESH_LINE_VALUE); //if(rt!=IDOK) // GetDoc()->EnableDefaultTool(); } bool NItem::CItemMeshProcess::CalculateVolume(CCurveEx* pCurveRange, int mode, double & zOut, double & volumeOut) { zOut = volumeOut = 0; CPoint3D point; double v = 0; double cz = 0; //闭合线 bool bResult = false; CMesh* pm; CPtrList* pl = GetDoc()->GetDraw()->GetValueList(); POSITION pos = pl->GetHeadPosition(); while (pos) { if (GetDoc()->GetDraw()->GetElementType(pos) == DOUBLEFOX_MESH) { pm = (CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); switch (mode) { case 0: //构造图 if (pm->GetHightPoint(pCurveRange, point) > 0) //计算高点 { cz = pm->GetClosedZ(*pCurveRange, point.z0); //计算闭合线 v += pm->Volume(*pCurveRange, cz); //计算体积 bResult = true; } break; case 1: //等厚图 v += pm->Volume(*pCurveRange, 0); //计算体积 bResult = true; break; } } pl->GetNext(pos); } if (bResult) { zOut = cz; volumeOut = v; } return bResult; } bool NItem::CItemMeshProcess::SetZOfSurface(CCurveEx* pCurveRange, int zMode, double zIn) { if (zMode < 0 || zMode >= 7) return false; if (zMode == 0) { if (pCurveRange == 0) return false; return SetZOfSurfaceInMode12(pCurveRange, zIn, FALSE); } else if (zMode == 1) { if (pCurveRange == 0) return false; return SetZOfSurfaceInMode12(pCurveRange, zIn, TRUE); } SetValueZ(zMode, zIn); return true; } bool NItem::CItemMeshProcess::SetZOfSurfaceInMode12(CCurveEx* pCurveRange, double z, BOOL bInCurve) { CPositionList list; CActionBackupItem* pAction = new CActionBackupItem(GetDoc(), IDS_STRING_MESH_TITLE); CPtrList curveList; curveList.AddTail(pCurveRange); int count = 0; CMesh* pm; CPtrList* pl = GetDoc()->GetDraw()->GetValueList(); POSITION pos = pl->GetHeadPosition(); while (pos) { if (GetDoc()->GetDraw()->GetElementType(pos) == DOUBLEFOX_MESH) { pm = (CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); pAction->Backup(pos); pm->SetValue(curveList, z, bInCurve); pm->GetBitmap(); count++; } pl->GetNext(pos); } if (count > 0) { pAction->BackupNew(); GetDoc()->Invalidate(); GetDoc()->SetActionItem(pAction); } else delete pAction; return count != 0; } void NItem::CItemMeshProcess::SetValueZ(void) { //INT_PTR rt=DoModal(IDS_STRING_VALUE_Z); //if(rt!=IDOK) // GetDoc()->EnableDefaultTool(); //else //{ // switch(m_nModeSetZ) // { // case 0: //设置曲线范围内的值为a值 // case 1: //设置曲线范围外的值为a值 // break; // default: // SetValueZ(m_nModeSetZ, m_dValueZ); // GetDoc()->EnableDefaultTool(); // } //} } void NItem::CItemMeshProcess::SetValueZ(int nModeSel, double z) { CPositionList list; //CActionBackupItem* pAction=new CActionBackupItem(GetDoc(), IDS_STRING_VALUE_Z); //CWaitCursor wc; COne* pOne; int count=0; CMesh* pm; CPtrList* pl=GetDoc()->GetDraw()->GetValueList(); POSITION pos=pl->GetHeadPosition(); while(pos) { pOne=GetDoc()->GetDraw()->GetAt(pos); if( pOne->GetType()==DOUBLEFOX_MESH && pOne->GetLayer()->IsViewAndEdit() && pOne->IsView() ) { pm=(CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); //pAction->Backup(pos); pm->SetValueZ(z, nModeSel); pm->GetBitmap(); count++; GetDoc()->Modified(); } pl->GetNext(pos); } //if(count>0) //{ // GetDoc()->SetActionItem(pAction); // GetDoc()->UpdatePropertyGridContent(NULL); // GetDoc()->Invalidate(); //} //else // delete pAction; } void NItem::CItemMeshProcess::ScaleZ(void) { CString str; str.LoadString(ID_PROCESS_SURFACE_SCALE_Z); int i=str.Find("\n"); if(i>0) str=str.Left(i); m_dValueZ=1.0; //CPropertiesSheet sheet(str,GetView(),0,FALSE); //sheet.SetItem(this); //if(sheet.DoModal()!=IDOK) return; CPositionList list; //CActionBackupItem* pAction=new CActionBackupItem(GetDoc(), ID_PROCESS_SURFACE_SCALE_Z); CWaitCursor wc; COne* pOne; int count=0; CMesh* pm; CPtrList* pl=GetDoc()->GetDraw()->GetValueList(); POSITION pos=pl->GetHeadPosition(); while(pos) { pOne=GetDoc()->GetDraw()->GetAt(pos); if( pOne->GetType()==DOUBLEFOX_MESH && pOne->GetLayer()->IsViewAndEdit() && pOne->IsView() ) { pm=(CMesh*)GetDoc()->GetDraw()->GetAtValue(pos); //pAction->Backup(pos); pm->ScaleZ(m_dValueZ); GetDoc()->Modified(); count++; } pl->GetNext(pos); } //if(count>0) //{ // GetDoc()->SetActionItem(pAction); // GetDoc()->UpdatePropertyGridContent(NULL); //} //else // delete pAction; } int NItem::CItemMeshProcess::GetVolumeMode(void) { //int bakMode=m_nIdea; //SetProcessIdea(MESH_VOLUME_MODE_SELECT); //CString str; //str.LoadString(IDS_STRING_VOLUME_MESH); //CPropertiesSheet sheet(str,GetView(),0,FALSE); //sheet.SetItem(this); //if(sheet.DoModal()!=IDOK) //{ // SetProcessIdea(bakMode); // return -1; //} //SetProcessIdea(bakMode); return m_nVolumeMode; } void NItem::CItemMeshProcess::CutSlice(void) { //SetProcessIdea(MESH_CUT_SLICE); //CDFDrawProView* pView = (CDFDrawProView*)GetDoc()->GetActiveView(); //COne* pOne = pView->GetSelectedOne(DOUBLEFOX_MESH); //if(pOne==NULL) return; //CMesh* pm=(CMesh*)pOne->GetValue(); //if(pm->GetDimension()!=3) return; //m_dValueZ=((CDimension3D*)pm->GetMesh())->range[0]; //INT_PTR rt=DoModal(IDS_STRING_VALUE_Z); //if(rt!=IDOK) // return; //CDimension3D* pdfg=new CDimension3D; //if(pm->CutSlice(*(CDimension2D*)pdfg, m_dValueZ)<=0) //{ // delete pdfg; // return; //} //CMesh* pp=new CMesh; //pp->SetMesh(pdfg, MESH_DFG, FALSE); //CMainFrame* pmf = (CMainFrame*)GetDoc()->GetMainFrame(); //CDFDrawProDoc* pDocEnd = (CDFDrawProDoc*) pmf->GetDrawFrame().NewDocument(); //pDocEnd->GetDraw()->AddElement(pp, DOUBLEFOX_MESH); //pDocEnd->SetModifiedFlag(); //pDocEnd->GetItemView().Extend(EXTEND_MODE_DEFAULT); }