⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mappershape.cpp

📁 vc 和mapobjects地理信息系统组件开发 很有启发意义和参考价值
💻 CPP
📖 第 1 页 / 共 4 页
字号:

			if (LPDISPATCH(line))
				m_oaLines.InsertAt(m_tSel.index,line);
		}
		break;
	case 3:
		{
			CRectEditDlg red;
			red.m_nType=1;
			red.m_dX=m_oaRects[m_tSel.index]->GetLeft();
			red.m_dY=m_oaRects[m_tSel.index]->GetTop();
			red.m_dWidth=m_oaRects[m_tSel.index]->GetWidth();
			red.m_dHeight=m_oaRects[m_tSel.index]->GetHeight();
			if(red.DoModal()!=IDOK)
				return;

			//删除原来对象,重新建立
			m_oaRects[m_tSel.index]->ReleaseDispatch();
			delete m_oaRects[m_tSel.index];
			m_oaRects.RemoveAt(m_tSel.index);

			//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
			//原位置
			CMoRectangle* rect= new CMoRectangle();
			rect->CreateDispatch(TEXT("MapObjects2.Rectangle"));
			rect->SetLeft(red.m_dX);
			rect->SetTop(red.m_dY);
			rect->SetRight(red.m_dX+red.m_dWidth);
			rect->SetBottom(red.m_dY-red.m_dHeight);	//数据轴向上
			if (LPDISPATCH(rect))
				m_oaRects.InsertAt(m_tSel.index,rect);
		}
		break;
	case 4:
		{
			CRectEditDlg red;
			red.m_nType=2;
			red.m_dX=m_oaCircles[m_tSel.index]->GetLeft();
			red.m_dY=m_oaCircles[m_tSel.index]->GetTop();
			red.m_dWidth=m_oaCircles[m_tSel.index]->GetWidth();
			red.m_dHeight=m_oaCircles[m_tSel.index]->GetHeight();
			if(red.DoModal()!=IDOK)
				return;

			//删除原来对象,重新建立
			m_oaCircles[m_tSel.index]->ReleaseDispatch();
			delete m_oaCircles[m_tSel.index];
			m_oaCircles.RemoveAt(m_tSel.index);

			//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
			//原位置
			CMoEllipse* circle= new CMoEllipse();
			circle->CreateDispatch(TEXT("MapObjects2.Ellipse"));
			circle->SetLeft(red.m_dX);
			circle->SetTop(red.m_dY);
			circle->SetRight(red.m_dX+red.m_dWidth);
			circle->SetBottom(red.m_dY-red.m_dWidth);	//数据轴向上
			if (LPDISPATCH(circle))
				m_oaCircles.InsertAt(m_tSel.index,circle);
		}
		break;
	case 5:
		{
			CRectEditDlg red;
			red.m_nType=1;
			red.m_dX=m_oaEllipses[m_tSel.index]->GetLeft();
			red.m_dY=m_oaEllipses[m_tSel.index]->GetTop();
			red.m_dWidth=m_oaEllipses[m_tSel.index]->GetWidth();
			red.m_dHeight=m_oaEllipses[m_tSel.index]->GetHeight();
			if(red.DoModal()!=IDOK)
				return;

			//删除原来对象,重新建立
			m_oaEllipses[m_tSel.index]->ReleaseDispatch();
			delete m_oaEllipses[m_tSel.index];
			m_oaEllipses.RemoveAt(m_tSel.index);

			//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
			//原位置
			CMoEllipse* ellipse= new CMoEllipse();
			ellipse->CreateDispatch(TEXT("MapObjects2.Ellipse"));
			ellipse->SetLeft(red.m_dX);
			ellipse->SetTop(red.m_dY);
			ellipse->SetRight(red.m_dX+red.m_dWidth);
			ellipse->SetBottom(red.m_dY-red.m_dHeight);	//数据轴向上
			if (LPDISPATCH(ellipse))
				m_oaEllipses.InsertAt(m_tSel.index,ellipse);
		}
		break;
	case 6:
		{
			CLineEditDlg led;
			short i;
			long j;
			SMapperPoint mp;
			led.m_taPoint.RemoveAll();
			for(i=0;i<m_oaPolys[m_tSel.index]->GetParts().GetCount();i++)
			{
				CMoPoints pts=m_oaPolys[m_tSel.index]->GetParts().Item(COleVariant(i));
				for(j=0;j<pts.GetCount();j++)
				{
					mp.x=pts.Item(COleVariant(j)).GetX();
					mp.y=pts.Item(COleVariant(j)).GetY();
					led.m_taPoint.Add(mp);
				}
			}

			led.m_sInfo.Format("周长:%lf\n面积:%lf",m_oaPolys[m_tSel.index]->GetPerimeter(),
				m_oaPolys[m_tSel.index]->GetArea());
			if(led.DoModal()!=IDOK)
				return;

			//删除原来对象,重新建立
			m_oaPolys[m_tSel.index]->ReleaseDispatch();
			delete m_oaPolys[m_tSel.index];
			m_oaPolys.RemoveAt(m_tSel.index);

			//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
			//原位置
			CMoPolygon* poly= new CMoPolygon();
			poly->CreateDispatch(TEXT("MapObjects2.Polygon"));
			CMoPoint pt;
			CMoPoints pts;
			pt.CreateDispatch(TEXT("MapObjects2.Point"));
			pts.CreateDispatch(TEXT("MapObjects2.Points"));
			for(j=0;j<led.m_taPoint.GetSize();j++)
			{
				pt.SetX(led.m_taPoint[j].x);
				pt.SetY(led.m_taPoint[j].y);
				pts.Add(pt);
			}

			poly->GetParts().Add(pts);

			if (LPDISPATCH(poly))
				m_oaPolys.InsertAt(m_tSel.index,poly);
		}
		break;

	case 7:
		{
			CLineEditDlg led;
			SMapperPoint mp;
			led.m_taPoint.RemoveAll();

			CMoPoints pts=m_oaTexts[m_tSel.index]->line->GetParts().Item(COleVariant((short)0));
			mp.x=pts.Item(COleVariant((short)0)).GetX();
			mp.y=pts.Item(COleVariant((short)0)).GetY();
			led.m_taPoint.Add(mp);
			mp.x=pts.Item(COleVariant((short)1)).GetX();
			mp.y=pts.Item(COleVariant((short)1)).GetY();
			led.m_taPoint.Add(mp);

			led.m_sInfo.Format("长度:%lf",m_oaTexts[m_tSel.index]->line->GetLength());
			if(led.DoModal()!=IDOK)
				return;

			//删除原来对象,重新建立
			m_oaTexts[m_tSel.index]->line->ReleaseDispatch();
			delete m_oaTexts[m_tSel.index]->line;

			//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
			//原位置
			m_oaTexts[m_tSel.index]->line= new CMoLine();
			m_oaTexts[m_tSel.index]->line->CreateDispatch(TEXT("MapObjects2.Line"));
			CMoPoint pt;
			pt.CreateDispatch(TEXT("MapObjects2.Point"));
			CMoPoints pts1;
			pts1.CreateDispatch(TEXT("MapObjects2.Points"));

			pt.SetX(led.m_taPoint[0].x);
			pt.SetY(led.m_taPoint[0].y);
			pts1.Add(pt);
			pt.SetX(led.m_taPoint[1].x);
			pt.SetY(led.m_taPoint[1].y);
			pts1.Add(pt);

			m_oaTexts[m_tSel.index]->line->GetParts().Add(pts1);
		}
		break;
	}
}

void CMapperShape::AddFromFile(CMap1 &map)
{
	CShapeDataDlg sdd;
	if(sdd.DoModal()!=IDOK)
		return;

	FILE *fin;
	double x,y;
	switch(sdd.m_nShape)
	{
	case 0:	//point
		{
			fin=fopen(sdd.m_sFile,"rt");
			if(fin!=NULL)
			{
				while(1)
				{
					if(fscanf(fin,"%lf %lf",&x,&y)!=2) break;
					
					// Create a new ellipse object
					CMoPoint* point = new CMoPoint();
					point->CreateDispatch(TEXT("MapObjects2.Point"));
					point->SetX(x);
					point->SetY(y);
					point->SetZ(0.0);

					if(LPDISPATCH(point))
						m_oaPoints.Add(point);
					map.Refresh();
				}
				fclose(fin);
			}
		}
		break;
	case 1: //line
		{
			fin=fopen(sdd.m_sFile,"rt");
			if(fin!=NULL)
			{
				CMoPoint pt;
				CMoPoints pts;
				pt.CreateDispatch(TEXT("MapObjects2.Point"));
				pts.CreateDispatch(TEXT("MapObjects2.Points"));
				while(1)
				{
					if(fscanf(fin,"%lf %lf",&x,&y)!=2) break;
					pt.SetX(x);
					pt.SetY(y);
					pt.SetZ(0.0);

					pts.Add(pt);
				}
				fclose(fin);

				if(pts.GetCount()>1)
				{
					CMoLine* line = new CMoLine();
					line->CreateDispatch(TEXT("MapObjects2.Line"));
					line->GetParts().Add(pts);
					
					if (LPDISPATCH(line))
						m_oaLines.Add(line);

					CMoRectangle r = CMoRectangle(line->GetExtent());
					map.RefreshRect(r.m_lpDispatch);
				}
				else
				{
					AfxMessageBox("少于2个点不能建立线!");
				}

				if(pt.m_lpDispatch!=NULL) pt.ReleaseDispatch();
				if(pts.m_lpDispatch!=NULL) pts.ReleaseDispatch();
			}
		}
	
		break;
	case 2: //poly
		{
			fin=fopen(sdd.m_sFile,"rt");
			if(fin!=NULL)
			{
				CMoPoint pt;
				CMoPoints pts;
				pt.CreateDispatch(TEXT("MapObjects2.Point"));
				pts.CreateDispatch(TEXT("MapObjects2.Points"));
				while(1)
				{
					if(fscanf(fin,"%lf %lf",&x,&y)!=2) break;
					pt.SetX(x);
					pt.SetY(y);
					pt.SetZ(0.0);

					pts.Add(pt);
				}
				fclose(fin);

				if(pts.GetCount()>2)
				{
					CMoPolygon* poly = new CMoPolygon();
					poly->CreateDispatch(TEXT("MapObjects2.Polygon"));
					poly->GetParts().Add(pts);

					if (LPDISPATCH(poly))
						m_oaPolys.Add(poly);
			
					CMoRectangle rect = CMoRectangle(poly->GetExtent());
					map.RefreshRect(rect.m_lpDispatch);
				}
				else
				{
					AfxMessageBox("少于3个点不能建立多边形!");
				}

				if(pt.m_lpDispatch!=NULL) pt.ReleaseDispatch();
				if(pts.m_lpDispatch!=NULL) pts.ReleaseDispatch();
			}
		}
		break;
	}

}

BOOL CMapperShape::Setup()
{
	if((m_tSel.type==-1)||(m_tSel.index==-1))
		return FALSE;

	switch(m_tSel.type)
	{
	case 1:
		{
			CPointSetupDlg psd;
			psd.m_nOutline=m_tPointInfo.bOutline;
			psd.m_nPointList=m_tPointInfo.style;
			psd.m_nPointSize=m_tPointInfo.size;
			psd.m_oOutlineColor.SetColor(m_tPointInfo.outlineColor);
			psd.m_oPointColor.SetColor(m_tPointInfo.color);
			if(psd.DoModal()!=IDOK)
				return FALSE;
			m_tPointInfo.bOutline=psd.m_nOutline;
			m_tPointInfo.style=psd.m_nPointList;
			m_tPointInfo.size=psd.m_nPointSize;
			m_tPointInfo.outlineColor=psd.m_oOutlineColor.GetColor();
			m_tPointInfo.color=psd.m_oPointColor.GetColor();
		}
		break;
	case 2:
		{
			CLineSetupDlg lsd;
			lsd.m_nLineStyle=m_tLineInfo.style;
			lsd.m_nLineWidth=m_tLineInfo.size;
			lsd.m_oLineColor.SetColor(m_tLineInfo.color);
			if(lsd.DoModal()!=IDOK)
				return FALSE;
			m_tLineInfo.style=lsd.m_nLineStyle;
			m_tLineInfo.size=lsd.m_nLineWidth;
			m_tLineInfo.color=lsd.m_oLineColor.GetColor();
		}
		break;
	case 3:
		{
			CPolySetupDlg psd;
			psd.m_nFillList=m_tRectInfo.style;
			psd.m_nOutline=m_tRectInfo.bOutline;
			psd.m_nOutlineWidth=m_tRectInfo.size;
			psd.m_oFillColor.SetColor(m_tRectInfo.color);
			psd.m_oOutlineColor.SetColor(m_tRectInfo.outlineColor);
			if(psd.DoModal()!=IDOK)
				return FALSE;
			m_tRectInfo.style=psd.m_nFillList;
			m_tRectInfo.bOutline=psd.m_nOutline;
			m_tRectInfo.size=psd.m_nOutlineWidth;
			m_tRectInfo.color=psd.m_oFillColor.GetColor();
			m_tRectInfo.outlineColor=psd.m_oOutlineColor.GetColor();
		}
		break;
	case 4:
		{
			CPolySetupDlg psd;
			psd.m_nFillList=m_tCircleInfo.style;
			psd.m_nOutline=m_tCircleInfo.bOutline;
			psd.m_nOutlineWidth=m_tCircleInfo.size;
			psd.m_oFillColor.SetColor(m_tCircleInfo.color);
			psd.m_oOutlineColor.SetColor(m_tCircleInfo.outlineColor);
			if(psd.DoModal()!=IDOK)
				return FALSE;
			m_tCircleInfo.style=psd.m_nFillList;
			m_tCircleInfo.bOutline=psd.m_nOutline;
			m_tCircleInfo.size=psd.m_nOutlineWidth;
			m_tCircleInfo.color=psd.m_oFillColor.GetColor();
			m_tCircleInfo.outlineColor=psd.m_oOutlineColor.GetColor();
		}
		break;
	case 5:
		{
			CPolySetupDlg psd;
			psd.m_nFillList=m_tEllipseInfo.style;
			psd.m_nOutline=m_tEllipseInfo.bOutline;
			psd.m_nOutlineWidth=m_tEllipseInfo.size;
			psd.m_oFillColor.SetColor(m_tEllipseInfo.color);
			psd.m_oOutlineColor.SetColor(m_tEllipseInfo.outlineColor);
			if(psd.DoModal()!=IDOK)
				return FALSE;
			m_tEllipseInfo.style=psd.m_nFillList;
			m_tEllipseInfo.bOutline=psd.m_nOutline;
			m_tEllipseInfo.size=psd.m_nOutlineWidth;
			m_tEllipseInfo.color=psd.m_oFillColor.GetColor();
			m_tEllipseInfo.outlineColor=psd.m_oOutlineColor.GetColor();
		}
		break;
	case 6:
		{
			CPolySetupDlg psd;
			psd.m_nFillList=m_tPolyInfo.style;
			psd.m_nOutline=m_tPolyInfo.bOutline;
			psd.m_nOutlineWidth=m_tPolyInfo.size;
			psd.m_oFillColor.SetColor(m_tPolyInfo.color);
			psd.m_oOutlineColor.SetColor(m_tPolyInfo.outlineColor);
			if(psd.DoModal()!=IDOK)
				return FALSE;
			m_tPolyInfo.style=psd.m_nFillList;
			m_tPolyInfo.bOutline=psd.m_nOutline;
			m_tPolyInfo.size=psd.m_nOutlineWidth;
			m_tPolyInfo.color=psd.m_oFillColor.GetColor();
			m_tPolyInfo.outlineColor=psd.m_oOutlineColor.GetColor();
		}
		break;
	case 7:
		{
			CShapeTextDlg std;
			std.m_dHeight=m_oaTexts[m_tSel.index]->height;
			std.m_sText=m_oaTexts[m_tSel.index]->text;
			std.m_oColor.SetColor(m_oaTexts[m_tSel.index]->color);
			if(std.DoModal()!=IDOK)
				return FALSE;
			m_oaTexts[m_tSel.index]->height=std.m_dHeight;
			strcpy(m_oaTexts[m_tSel.index]->text,std.m_sText);
			m_oaTexts[m_tSel.index]->color=std.m_oColor.GetColor();
		}
		break;
	default:
		return FALSE;
		break;
	}

	return TRUE;
}

void CMapperShape::SetSelNone()
{
	m_tSel.index=-1;
	m_tSel.type=-1;
}

BOOL CMapperShape::Save(CString sPathFile)
{
	CFile f;
	if(f.Open(sPathFile,CFile::modeWrite|CFile::modeCreate)!=IDOK)
		return FALSE;

	short i,j;
	SMapperPoint	mp;
	SMsfHeadInfo	mhi;
	mhi.mapper=20030701;
	f.Write(&mhi,sizeof(SMsfHeadInfo));

	//point
	mhi.iPoints=m_oaPoints.GetSize();
	for(i=0;i<mhi.iPoints;i++)
	{
		m_tPointInfo.shape=1;
		m_tPointInfo.pts=1;
		f.Write(&m_tPointInfo,sizeof(SMsfShapeInfo));
		mp.x=m_oaPoints[i]->GetX();
		mp.y=m_oaPoints[i]->GetY();
		f.Write(&mp,sizeof(SMapperPoint));
	}

	//line
	mhi.iLines=m_oaLines.GetSize();
	for(i=0;i<mhi.iLines;i++)
	{
		m_tLineInfo.shape=2;
		CMoPoints pts=m_oaLines[i]->GetParts().Item(COleVariant((short)0));
		m_tLineInfo.pts=pts.GetCount();
		f.Write(&m_tLineInfo,sizeof(SMsfShapeInfo));
		for(j=0;j<m_tLineInfo.pts;j++)
		{
			CMoPoint pt=pts.Item(COleVariant(j));
			mp.x=pt.GetX();
			mp.y=pt.GetY();
			f.Write(&mp,sizeof(SMapperPoint));
		}
	}

	//rect 
	mhi.iRects=m_oaRects.GetSize();
	for(i=0;i<mhi.iRects;i++)
	{
		m_tRectInfo.shape=3;
		m_tRectInfo.pts=4;
		f.Write(&m_tRectInfo,sizeof(SMsfShapeInfo));
		mp.x=m_oaRects[i]->GetLeft();
		mp.y=m_oaRects[i]->GetTop();
		f.Write(&mp,sizeof(SMapperPoint));
		mp.x=m_oaRects[i]->GetRight();
		mp.y=m_oaRects[i]->GetBottom();
		f.Write(&mp,sizeof(SMapperPoint));
	}

	//Circle
	mhi.iCircles=m_oaCircles.GetSize();
	for(i=0;i<mhi.iCircles;i++)
	{
		m_tCircleInfo.shape=4;
		m_tCircleInfo.pts=4;
		f.Write(&m_tCircleInfo,sizeof(SMsfShapeInfo));
		mp.x=m_oaCircles[i]->GetLeft();
		mp.y=m_oaCircles[i]->GetTop();
		f.Write(&mp,sizeof(SMapperPoint));
		mp.x=m_oaCircles[i]->GetRight();
		mp.y=m_oaCircles[i]->GetBottom();
		f.Write(&mp,sizeof(SMapperPoint));
	}

	//Ellipse
	mhi.iEllipses=m_oaEllipses.GetSize();
	for(i=0;i<mhi.iEllipses;i++)
	{
		m_tEllipseInfo.shape=5;
		m_tEllipseInfo.pts=4;
		f.Write(&m_tEllipseInfo,sizeof(SMsfShapeInfo));
		mp.x=m_oaEllipses[i]->GetLeft();
		mp.y=m_oaEllipses[i]->GetTop();
		f.Write(&mp,sizeof(SMapperPoint));
		mp.x=m_oaEllipses[i]->GetRight();
		mp.y=m_oaEllipses[i]->GetBottom();
		f.Write(&mp,sizeof(SMapperPoint));
	}

	//poly
	mhi.iPolys=m_oaPolys.GetSize();
	for(i=0;i<mhi.iPolys;i++)
	{
		m_tPolyInfo.shape=6;
		CMoPoints pts=m_oaPolys[i]->GetParts().Item(COleVariant((short)0));
		m_tPolyInfo.pts=pts.GetCount();
		f.Write(&m_tPolyInfo,sizeof(SMsfShapeInfo));
		for(j=0;j<m_tPolyInfo.pts;j++)
		{
			CMoPoint pt=pts.Item(COleVariant(j));
			mp.x=pt.GetX();
			mp.y=pt.GetY();
			f.Write(&mp,sizeof(SMapperPoint));
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -