p align="left">e.Graphics.DrawLine(myP,oldX,oldY,curX,oldY); e.Graphics.DrawLine(myP,curX,oldY,curX,curY); e.Graphics.DrawLine(myP,oldX,curY,curX,curY); } base.OnPaint (e); } #region Component Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { // // CntrIm // this.BackColor = System.Drawing.SystemColors.Control; this.Name = "CntrIm"; this.Size = new System.Drawing.Size(496, 384); this.Load += new System.EventHandler(this.CntrIm_Load); this.SizeChanged += new System.EventHandler(this.CntrIm_SizeChanged); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.CntrIm_MouseUp); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.CntrIm_MouseMove); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.CntrIm_MouseDown); } #endregion private void CntrIm_Load(object sender, System.EventArgs e) { } public void FileOpen(string Pth) { mapD = new MyMap(); mapD.Scale=1; mapD.SetAxes(1,-1); //mapD.SetXYtoView(); this.Path = Pth; StreamReader StrmR = new StreamReader(Path); bool flag = false; string str; int dss=0; PathD pthD=null; while (((str = StrmR.ReadLine())!=null)) { //this.richTextBox1.Text+=str; dss++; if(str=="/$fm 0 def") { pthD = new PathD(); flag=true; str= StrmR.ReadLine(); dss++; //this.richTextBox1.Text+=str+"\n"; } if(flag) { int i=0; string rtt=""; double [] xy=new double [2]; int nm=0; while (i<str.Length&&str[i]!='C'&&str[i]!='m'&&str[i]!='L') { if(str[i]==' ') { try { xy[nm]=Convert.ToDouble(rtt); } catch(System.FormatException e) { } nm++; if(nm==2) { PointD tm = new PointD(xy[0],xy[1]); pthD.AddPoint(tm); nm=0; } rtt=""; } else if (str[i]=='.') { rtt+=','; } else rtt+=str[i]; i++; } } if((str=="@c"||str=="S")&&flag==true) { mapD.AddPath(pthD); flag=false; //this.richTextBox1.Text+=str+"\n"; } } StrmR.Close(); mapD.SetScaleToView(this.Height,this.Width); mapD.SetXYtoView(); /* AutoColor AClr = new AutoColor(mapD.AllPaths); Color [] msc = AClr.GetMsClr; for (int i=0;i<mapD.Length;i++) { this.SetClrPath(i,msc[i]); }*/ if(MapLoadEnd!=null) MapLoadEnd(); } private void CntrIm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { flag = true; oldX=e.X; oldY=e.Y; oldDx=mapD.DX; oldDy=mapD.DY; } private void CntrIm_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { flag=false; } private void CntrIm_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { curX=e.X; curY=e.Y; if(flRec==true) this.Refresh(); } public void ScaleToPoint(int crX,int crY,double sclN) { double x,y; double oldSc=mapD.Scale; double oldKx=mapD.KX; double oldKy=mapD.KY; mapD.Scale=mapD.Scale*sclN; x=oldDx-Convert.ToDouble(this.Width)/2/(mapD.Scale*mapD.KX)+Convert.ToDouble(crX)/(oldSc*oldKx); y=oldDy-Convert.ToDouble(this.Height)/2/(mapD.Scale*mapD.KY)+Convert.ToDouble(crY)/(oldSc*oldKy); mapD.SetXYAxes(x,y); this.Refresh(); } public void MovePoint(int oldx,int oldy, int crx,int cry) { double x,y; x=oldDx-Convert.ToDouble(crx-oldx)/(mapD.Scale*mapD.KX); y=oldDy-Convert.ToDouble(cry-oldy)/(mapD.Scale*mapD.KY); mapD.SetXYAxes(x,y); this.Refresh(); } public void ScaleToRctangle(int oldx,int oldy,int crX,int crY) { double scl=0.0; double x,y; oldX=oldx; oldY=oldy; double oldKx=mapD.KX; double oldKy=mapD.KY; double oldSc=mapD.Scale; int cX,cY; if(Math.Abs(oldx-crX)>Math.Abs(oldy-crY)) { scl=Convert.ToDouble(this.Width)/Math.Abs(oldx-crX); } else { scl=this.Height/Math.Abs(oldy-crY); } if(oldx<crX) { cX=oldx; } else { cX=crX; } if(oldy<crY) { cY=oldy; } else { cY=crY; } mapD.Scale=mapD.Scale*scl; x=oldDx+Convert.ToDouble(cX)/(oldSc*oldKx); y=oldDy+Convert.ToDouble(cY)/(oldSc*oldKy); mapD.SetXYAxes(x,y); this.Refresh(); } public void VeiwInWindow() { mapD.SetScaleToView(this.Height,this.Width); mapD.SetXYtoView(); this.Refresh(); } public void RealScale() { mapD.Scale=1; mapD.SetXYtoView(); this.Refresh(); } public bool VeiwRect { set { flRec=value; } get { return flRec; } public int GetNamberPath (int crX, int crY) { double x,y; int pth=-1; x=oldDx+Convert.ToDouble(crX)/(this.mapD.Scale*this.mapD.KX); y=oldDy+Convert.ToDouble(crY)/(this.mapD.Scale*this.mapD.KY); double x1,y1,x2,y2; double p; double nx; double ny=y; int per=0; for (int k=0;k<mapD.Length;k++) { per=0; for(int j=0;j<mapD.AllPaths[k].Length-1;j++) { x1 = mapD.AllPaths[k].PathPoints[j].X; y1 = mapD.AllPaths[k].PathPoints[j].Y; x2 = mapD.AllPaths[k].PathPoints[j+1].X; y2 = mapD.AllPaths[k].PathPoints[j+1].Y; if(y1!=y2) { //this.listBox1.Items.Add("xx"); p=(ny-y2)/(y1-y2); nx=p*x1+(1-p)*x2; if((p>0)&&(p<1)&&(x<nx)) { //if(nx!=x1&&ny!=y1) per++; if(nx==x1&&ny==y1) { double xp = mapD.AllPaths[k].PathPoints[j-1].X; double yp = mapD.AllPaths[k].PathPoints[j-1].Y; if(yp<y1&&y1<y2) { per++; } else if(y1>y2&&y1>yp) { else if(y1==y2&&y1==y) { // per++; //не входит } } //listBox1.Items.Add("per_"+per.ToString()); if((per%2)==1) { pth=k; //listBox1.Items.Add("per_"+per.ToString()); //listBox1.Items.Add(k.ToString()); } } return pth; } public void Allocate(int nPth,int type) { mapD.Allocate(nPth,type); this.Refresh(); } public void SetClrPath (int NPth,Color Clr) { mapD.SetClrPth(NPth,Clr); } public Color GetClrPath(int NPth) { return mapD.AllPaths[NPth].ColorP; } public int[,] GetMsGr() { int [,] ms = new int [mapD.Length,mapD.Length]; for (int i=0;i<mapD.Length;i++) { for(int j=0;j<mapD.Length;j++) { ms[i,j]=0; } } double x1,y1; double _x1,_y1; for (int i=0;i<mapD.Length;i++) { for(int j=0;j<mapD.AllPaths[i].Length;j++) { x1 = mapD.AllPaths[i].PathPoints[j].X; y1 = mapD.AllPaths[i].PathPoints[j].Y; for (int k=0;k<mapD.Length;k++) { for(int l=0;l<mapD.AllPaths[k].Length;l++) { if(i!=k) { _x1 = mapD.AllPaths[k].PathPoints[l].X; _y1 = mapD.AllPaths[k].PathPoints[l].Y; if(x1==_x1&&y1==_y1) { ms[i,k]=1; } return ms; } //getmsgr public void Run(int curPth, ref int [,] ms) { if(ms[curPth,curPth]==0) { int j=1; bool flag = false; while (j<256&&!flag) { flag=true; for(int i=0;i<ms.GetLength(1);i++) { if(curPth!=i&&ms[curPth,i]>0&&ms[i,i]==j) { flag=false; } } j++; } ms[curPth,curPth]=j-1; for(int i=0;i<ms.GetLength(1);i++) { if(ms[curPth,i]==1&&curPth!=i) { ms[curPth,i]=2; ms[i,curPth]=2; Run(i,ref ms); } private void CntrIm_SizeChanged(object sender, System.EventArgs e) { mapD.SetScaleToView(this.Height,this.Width); mapD.SetXYtoView(); this.Refresh(); } public MyMap GetMap { get { return mapD; } } } } Приложение Б Текст файла MyMap.cs using System; using System.Drawing; using System.Drawing.Drawing2D; namespace CmpView { /// <summary> /// Summary description for MyMap. /// </summary> public class MyMap { private double scale; private int length; private int space; private double kx; private double ky; private double dx; private double dy; private PathD [] msPthd; private Pen [] msPn; // private GraphicsPath[] GrphPth; public MyMap() { space=20; scale =1; msPthd=null; msPn=null; kx=1; ky=1; dx=0; dy=0; //GrphPth=null; } public void AddPath(PathD pathD) { PathD[] tmpPathD = new PathD[length+1]; msPn = new Pen[length+1]; for(int i=0;i<length+1;i++) { msPn[i]= null; } if (length>0) { msPthd.CopyTo(tmpPathD,0); } tmpPathD[length]=pathD; msPthd=tmpPathD; tmpPathD=null; length++; /* Point[] tmP = new Point [pathD.Length]; for (int i=0;i<pathD.Length;i++) { tmP[i].X=Convert.ToInt32(pathD.PathPoints[i].X*this.scale+this.x*this.scale); tmP[i].Y=Convert.ToInt32(pathD.PathPoints[i].Y*this.scale+this.y*this.scale); } */ } public PathD[] AllPaths { get { return msPthd; } } public Pen[] AllPen { get { return msPn; } } public int Length { get { return length; } } public double Scale { get { return this.scale; } set { if(value<10000&&value>0) { scale=value; } public void SetAxes(double kX,double kY) { kx=kX; ky=kY; } public void SetXYAxes(double dX, double dY) { dx=dX; dy=dY; } public double KX { get { return kx; } } public double KY { get { return ky; } } public double DX { get { return dx; } } public double DY { get { return dy; } } public void SetXYtoView() { if(length>0) { double minX,minY; minX = kx*(this.msPthd[0].PathPoints[0].X); minY = ky*(this.msPthd[0].PathPoints[0].Y); for (int k=0;k<length;k++) { for(int j=0;j<msPthd[k].Length;j++) { if((kx*msPthd[k].PathPoints[j].X)<minX) { minX=kx*msPthd[k].PathPoints[j].X; } if((ky*msPthd[k].PathPoints[j].Y)<minY) { minY=ky*msPthd[k].PathPoints[j].Y; } this.dx=minX/kx-space/(scale*(kx/Math.Abs(kx))); this.dy=minY/ky-space/(scale*(ky/Math.Abs(ky))); } } public void SetScaleToView(int height,int width) { if(length>0) { double minX,minY,maxX,maxY; minX = (kx*this.msPthd[0].PathPoints[0].X); minY = (ky*this.msPthd[0].PathPoints[0].Y); maxX = (kx*this.msPthd[0].PathPoints[0].X); maxY = (ky*this.msPthd[0].PathPoints[0].Y); for (int k=0;k<length;k++) { for(int j=0;j<msPthd[k].Length;j++) { if((kx*msPthd[k].PathPoints[j].X)<minX) { minX=kx*msPthd[k].PathPoints[j].X; } if((ky*msPthd[k].PathPoints[j].Y)<minY) { minY=ky*msPthd[k].PathPoints[j].Y; } ///// if((kx*msPthd[k].PathPoints[j].X)>maxX) { maxX=kx*msPthd[k].PathPoints[j].X; } if((ky*msPthd[k].PathPoints[j].Y)>maxY) { maxY=ky*msPthd[k].PathPoints[j].Y; } double h,l; l=Math.Abs(maxX-minX); h=Math.Abs(maxY-minY); if(h>l) { scale = (height-space*2)/h; } else { scale = (width-space*2)/l; } } } public void Allocate(int nPth,int type) { if(type ==0) { if(msPn[nPth]!=new Pen(Color.Black,4)) { for(int i=0;i<length;i++) { msPn[i]= null; } msPn[nPth] = new Pen(Color.Black,4); } public void SetClrPth(int NPth, Color Clr) { msPthd[NPth].ColorP=Clr; }
Страницы: 1, 2, 3, 4, 5
|