private void map_MouseDown(object sender, MouseButtonEventArgs e) { string id = null; //抓取线路 PowerBasicObject pickobj = earth.objManager.pick(e.GetPosition(grdMain)); VECTOR3D? tmpLocation = earth.earthManager.transformScreenToD3D(e.GetPosition(grdMain)); if (pickobj != null && pickobj.busiData.busiSort == "线路") { id = pickobj.id; } else { return; } pPowerLine pline = pickobj as pPowerLine; if (isAdding && id != null) { if (viewmodel.curSection != null) { if (viewmodel.curSection.lines.Count(p => p.id == id) == 0) { line nline = new line() { id = id, section = viewmodel.curSection }; //zhh注:此下应修改为从数据库中读取相应数据 //if (tmpLocation!=null) // nline.d3dLocation =(VECTOR3D)tmpLocation; //else nline.d3dLocation = pline.VecLocation; nline.name = pline.name; nline.maxValue = pline.busiData.busiRatingValue; nline.curValue = pline.busiData.busiCurValue; //--------- viewmodel.curSection.lines.Add(nline); nline.InitVisualControl(); if (viewmodel.curSection.isShow) { viewmodel.grid.Children.Add(nline.vLinkLine); viewmodel.grid.Children.Add(nline.vInfo); } viewmodel.curSection.refreshCollection(); viewmodel.curSection.refreshLocation(); viewmodel.curSection.refreshData(); } } } }
void OnDelLine() { line tmp = curLine; if (root.grid.Children.Contains(tmp.vInfo)) { root.grid.Children.Remove(tmp.vInfo); root.grid.Children.Remove(tmp.vLinkLine); } curLineIdx = -1; lines.Remove(tmp); RaisePropertyChanged(() => curLineIdx); RaisePropertyChanged(() => lines); }
public void refreshLocation() { foreach (line lin in lines) { lin.center = root.map.earthManager.transformD3DToScreen(lin.d3dLocation); isLeft = lin.center.X < root.grid.ActualWidth / 2; //List<DynSceneLibrary.CObjectPosition> ele = root.map.GetElementPositions("ACLineSegment_Layer", lin.id); //if (ele != null) //{ // GeneralTransform3DTo2D gt = root.map.GetTransform3DTo2D(); // Point3D org = new Point3D(ele[0].ObjectPosition.Left, 0, ele[0].ObjectPosition.Top); // lin.center = gt.Transform(org); // isLeft = lin.center.X < root.grid.ActualWidth / 2; //} } _bound = null; double allheight = lines.Count * viewmodel.height2 + (lines.Count - 1) * viewmodel.span; if (lines.Count > 0) { int idx = 0; double top = bound.Top + bound.Height / 2 - allheight / 2; foreach (line lin in lines.OrderBy(p => p.center.Y)) { double left = isLeft ? bound.Left - 50 - lin.len : bound.Right + 50; lin.location = new Thickness(left, top, 0, 0); top += viewmodel.height2 + viewmodel.span; lin.idx = idx; idx++; } // 相交互换 int changecount = 0; line oldlin = null; Point p1, p2; Point p3 = new Point(); int allchangecount = 0; do { allchangecount++; changecount = 0; foreach (line lin in lines.OrderBy(p => p.idx)) { if (lin.idx == 0) { oldlin = lin; continue; } else { p1 = new Point(oldlin.locationX, oldlin.locationY); p2 = new Point(lin.locationX, lin.locationY); if (OperateHelper.GetIntersection(oldlin.center, p1, lin.center, p2, ref p3) == 1) { Thickness tmp = lin.location; lin.location = oldlin.location; oldlin.location = tmp; int tmpi = lin.idx; lin.idx = oldlin.idx; oldlin.idx = tmpi; changecount++; } else { oldlin = lin; } } } }while (changecount > 0 && allchangecount < 20); //======断面名称 double top2 = bound.Top + bound.Height / 2 - allheight / 2 - viewmodel.fontSizeSectionName - 10; double left2 = isLeft ? bound.Left - 50 - viewmodel.len2 : bound.Right + 50 + 10; location = new Thickness(left2, top2, 0, 0); RaisePropertyChanged(() => location); } }