/// <summary> /// 生成组模型标注 /// </summary> private void genGroupLabel() { if (LstGroupLabel.Count > 0) { int idx = 0; foreach (KeyValuePair <string, ModelBase> item in (model as GroupModelBase).models) { double distance; Point pb1, pb3, po1, po2; GeneralTransform3DTo2D gtransform = owner.modelMain.TransformToAncestor(owner.grdMain); Model3D lModel = item.Value.model; Point3D pinner; pinner = new Point3D(lModel.Bounds.X + lModel.Bounds.SizeX / 2, lModel.Bounds.Y + lModel.Bounds.SizeY / 2, lModel.Bounds.Z + lModel.Bounds.SizeZ); pb1 = gtransform.Transform((model.model.Transform as MatrixTransform3D).Transform(pinner)); pinner = new Point3D(lModel.Bounds.X + lModel.Bounds.SizeX, lModel.Bounds.Y + lModel.Bounds.SizeY / 2, lModel.Bounds.Z + lModel.Bounds.SizeZ); pb3 = gtransform.Transform((model.model.Transform as MatrixTransform3D).Transform(pinner)); distance = pb3.X - pb1.X; po1 = pb1; po1.Offset(distance + 5, 0); po2 = po1; po2.Offset(10, -10); Path path; path = new Path() { StrokeThickness = 1, Stroke = Brushes.White }; PathGeometry geo = new PathGeometry(); PathFigure fig = new PathFigure(); fig.StartPoint = pb1; fig.Segments.Add(new LineSegment(po1, true)); fig.Segments.Add(new LineSegment(po2, true)); geo.Figures.Add(fig); path.Data = geo; owner.grdFlag.Children.Add(path); path = new Path() { StrokeThickness = 1, Fill = Brushes.Blue }; path.Data = new EllipseGeometry(pb1, 5, 5); owner.grdFlag.Children.Add(path); TextBlock txt = new TextBlock() { Foreground = new SolidColorBrush(Color.FromRgb(0x66, 0xFF, 0xCC)), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; //txt.Text = LstGroupLabel[idx].Lname; txt.Text = item.Key; txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); txt.Margin = new Thickness(po2.X + 10, po2.Y - txt.DesiredSize.Height / 2, 0, 0); owner.grdFlag.Children.Add(txt); idx++; } } }
private void genSizeZLabel() { if (SizeZName != null) { double distance; Point pb1, pb2, pb3, po1, po2, pomid, pomid2, pend; GeneralTransform3DTo2D gtransform = owner.modelMain.TransformToAncestor(owner.grdMain); Model3D lModel = model.model; pb1 = gtransform.Transform(new Point3D(lModel.Bounds.X + lModel.Bounds.SizeX / 2, lModel.Bounds.Y + lModel.Bounds.SizeY, lModel.Bounds.Z)); pb2 = gtransform.Transform(new Point3D(lModel.Bounds.X + lModel.Bounds.SizeX / 2, lModel.Bounds.Y + lModel.Bounds.SizeY, lModel.Bounds.Z + lModel.Bounds.SizeZ)); pb3 = gtransform.Transform(new Point3D(lModel.Bounds.X + lModel.Bounds.SizeX, lModel.Bounds.Y + lModel.Bounds.SizeY, lModel.Bounds.Z + lModel.Bounds.SizeZ / 2)); distance = pb3.X - pb1.X; po1 = pb1; po1.Offset(distance + 10, 0); po2 = pb2; po2.Offset(distance + 10, 0); pomid = new Point((po1.X + po2.X) / 2, (po1.Y + po2.Y) / 2); pomid2 = pomid; pomid2.Offset(20, 0); pend = pomid2; pend.Offset(10, -10); Path path; path = new Path() { StrokeThickness = 1, Stroke = Brushes.White }; path.Data = getPathGeo(pb1, pb2, po1, po2, pomid, pomid2, pend); owner.grdFlag.Children.Add(path); path = new Path() { StrokeThickness = 1, Fill = Brushes.Blue }; path.Data = new EllipseGeometry(pend, 5, 5); owner.grdFlag.Children.Add(path); TextBlock txt = new TextBlock() { Foreground = new SolidColorBrush(Color.FromRgb(0x66, 0xFF, 0xCC)), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; txt.Text = SizeZName; txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); txt.Margin = new Thickness(pend.X - txt.DesiredSize.Width / 2, pend.Y - txt.DesiredSize.Height - 5, 0, 0); owner.grdFlag.Children.Add(txt); } }
public static Point?From3Dto2D(Visual3D space, Visual surface, Camera perspectiveCamera, Point3D target) { PerspectiveCamera cmr = perspectiveCamera as PerspectiveCamera; Point? rlt = new Point(); Vector3D look = cmr.Transform.Transform(cmr.LookDirection); Vector3D d = target - cmr.Transform.Transform(cmr.Position); double angle = AngleBetween(d, look); GeneralTransform3DTo2D gt = space.TransformToAncestor(surface); rlt = gt.Transform(target); if (Math.Abs(angle) < cmr.FieldOfView / 2) { return(rlt); } return(null); }
private void ResetBtnLocation(Point3D point) { Model3D m = (Model3D)(((Model3DGroup)grpMain.Children[0]).Children[0]); Transform3DGroup tgp = new Transform3DGroup(); tgp.Children.Add(grpMain.Transform); tgp.Children.Add(m.Transform); GeneralTransform3DTo2D gt = lvMain.TransformToAncestor(vpMain); //vpmain.TransformToDescendant(...); Point p = gt.Transform(tgp.Transform(point)); Canvas.SetLeft(btnTest, p.X); Canvas.SetTop(btnTest, p.Y); btnTest.Content = p.X + "," + p.Y; }
internal void showNodeDetail(SettleNode node, Vector vec_translate) { vectranslate = vec_translate; ScaleTransform3D mscale;//,scale; //TranslateTransform3D translate; title.Text = node.nodename; if (mgLeft.Children.Count == 0) { addCube(node); } //主体 mscale = (((mgLeft as Model3DGroup).Children[0] as GeometryModel3D).Transform as Transform3DGroup).Children[0] as ScaleTransform3D; mscale.ScaleX = node.scaleVec.X / node.layerScale * 3; mscale.ScaleY = node.scaleVec.Y / node.layerScale; mscale.ScaleZ = node.scaleVec.Z / node.layerScale * 3; ////顶 //scale = (((mgLeft as Model3DGroup).Children[1] as GeometryModel3D).Transform as Transform3DGroup).Children[0] as ScaleTransform3D; //scale.ScaleZ = node.scaleVec.Z / node.layerScale * 3; //translate = (((mgLeft as Model3DGroup).Children[1] as GeometryModel3D).Transform as Transform3DGroup).Children[1] as TranslateTransform3D; //translate.OffsetY = mscale.ScaleY*2-1.001; ////底 //scale = (((mgLeft as Model3DGroup).Children[0] as GeometryModel3D).Transform as Transform3DGroup).Children[0] as ScaleTransform3D; //scale.ScaleZ = node.scaleVec.Z / node.layerScale * 3; //电量标志 grdFlag.Children.Clear(); Point ptop, pbottom, pcenter, pfronttop, pfrontbottom; GeneralTransform3DTo2D gtransform = modelMain.TransformToAncestor(grdmain); ptop = gtransform.Transform(new Point3D(mgLeft.Bounds.X, mgLeft.Bounds.Y + mgLeft.Bounds.SizeY, 0)); pbottom = gtransform.Transform(new Point3D(mgLeft.Bounds.X, mgLeft.Bounds.Y, 0)); pcenter = gtransform.Transform(new Point3D(mgLeft.Bounds.X + mgLeft.Bounds.SizeX / 2, mgLeft.Bounds.Y, 0)); pfronttop = gtransform.Transform(new Point3D(mgLeft.Bounds.X + mgLeft.Bounds.SizeX / 2, mgLeft.Bounds.Y + mgLeft.Bounds.SizeY, mgLeft.Bounds.Z + mgLeft.Bounds.SizeZ)); pfrontbottom = gtransform.Transform(new Point3D(mgLeft.Bounds.X + mgLeft.Bounds.SizeX / 2, mgLeft.Bounds.Y, mgLeft.Bounds.Z + mgLeft.Bounds.SizeZ)); Path path; path = new Path() { StrokeThickness = 1, Stroke = Brushes.White }; PathGeometry geo = new PathGeometry(); PathFigure fig = new PathFigure(); fig.StartPoint = ptop; fig.Segments.Add(new LineSegment(new Point(ptop.X - 10, ptop.Y), true)); fig.Segments.Add(new LineSegment(new Point(ptop.X - 10, pbottom.Y), true)); fig.Segments.Add(new LineSegment(new Point(pbottom.X, pbottom.Y), true)); geo.Figures.Add(fig); fig = new PathFigure(); fig.StartPoint = new Point(ptop.X - 10, (ptop.Y + pbottom.Y) / 2); fig.Segments.Add(new LineSegment(new Point(ptop.X - 45, (ptop.Y + pbottom.Y) / 2), true)); fig.Segments.Add(new LineSegment(new Point(ptop.X - 65, (ptop.Y + pbottom.Y) / 2 - 10), true)); geo.Figures.Add(fig); path.Data = geo; grdFlag.Children.Add(path); path = new Path() { StrokeThickness = 1, Fill = Brushes.Blue }; path.Data = new EllipseGeometry(new Point(ptop.X - 65, (ptop.Y + pbottom.Y) / 2 - 10), 5, 5); grdFlag.Children.Add(path); TextBlock txt = new TextBlock() { Foreground = Brushes.Yellow, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; txt.Text = heightTitle + ":" + node.energy.ToString("f0"); txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); txt.Margin = new Thickness(ptop.X - 65 - txt.DesiredSize.Width / 2, (ptop.Y + pbottom.Y) / 2 - 10 - txt.DesiredSize.Height - 5, 0, 0); grdFlag.Children.Add(txt); //电价标志 path = new Path() { StrokeThickness = 1, Stroke = Brushes.White }; geo = new PathGeometry(); fig = new PathFigure(); fig.StartPoint = new Point(pcenter.X, ptop.Y); fig.Segments.Add(new LineSegment(new Point(pcenter.X, ptop.Y - 20), true)); fig.Segments.Add(new LineSegment(new Point(pcenter.X - 50, ptop.Y - 40), true)); geo.Figures.Add(fig); path.Data = geo; grdFlag.Children.Add(path); path = new Path() { StrokeThickness = 1, Fill = Brushes.Blue }; path.Data = new EllipseGeometry(new Point(pcenter.X - 50, ptop.Y - 40), 5, 5); grdFlag.Children.Add(path); txt = new TextBlock() { Foreground = Brushes.Yellow, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; txt.Text = sectionTitle + ":" + node.price.ToString("f4"); txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); txt.Margin = new Thickness(pcenter.X - 50 - txt.DesiredSize.Width / 2, ptop.Y - 40 - txt.DesiredSize.Height - 5, 0, 0); grdFlag.Children.Add(txt); //费用标志 path = new Path() { StrokeThickness = 1, Stroke = Brushes.White }; geo = new PathGeometry(); fig = new PathFigure(); fig.StartPoint = new Point(pcenter.X, pfronttop.Y + (pfrontbottom.Y - pfronttop.Y) * 0.25); fig.Segments.Add(new LineSegment(new Point(pcenter.X + 60, pfronttop.Y + (pfrontbottom.Y - pfronttop.Y) * 0.25), true)); fig.Segments.Add(new LineSegment(new Point(pcenter.X + 80, pfronttop.Y + (pfrontbottom.Y - pfronttop.Y) * 0.25 - 20), true)); geo.Figures.Add(fig); path.Data = geo; grdFlag.Children.Add(path); path = new Path() { StrokeThickness = 1, Fill = Brushes.Blue }; path.Data = new EllipseGeometry(new Point(pcenter.X + 80, pfronttop.Y + (pfrontbottom.Y - pfronttop.Y) * 0.25 - 20), 5, 5); grdFlag.Children.Add(path); txt = new TextBlock() { Foreground = Brushes.Yellow, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; txt.Text = volumeTitle + ":" + node.fee.ToString("f0"); txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); txt.Margin = new Thickness(pcenter.X + 60, pfronttop.Y + (pfrontbottom.Y - pfronttop.Y) * 0.25 - 20 - txt.DesiredSize.Height - 5, 0, 0); grdFlag.Children.Add(txt); mgRight.Children.Clear(); createPie(node); //动画放大 this.Visibility = Visibility.Visible; thisScale.BeginAnimation(ScaleTransform.ScaleXProperty, daOpen); thisScale.BeginAnimation(ScaleTransform.ScaleYProperty, daOpen); DoubleAnimation tax = new DoubleAnimation(vectranslate.X, 0, TimeSpan.FromSeconds(0.3), FillBehavior.HoldEnd); DoubleAnimation tay = new DoubleAnimation(vectranslate.Y, 0, TimeSpan.FromSeconds(0.3), FillBehavior.HoldEnd); thisTranslate.BeginAnimation(TranslateTransform.XProperty, tax); thisTranslate.BeginAnimation(TranslateTransform.YProperty, tay); }
/// <summary> /// 生成颜色标注 /// </summary> private void genColorLabel() { if (ColorName != null) { double distance; Point pb1, pb3, po1, po2, ptop, pbuttom; GeneralTransform3DTo2D gtransform = owner.modelMain.TransformToAncestor(owner.grdMain); Model3D lModel = model.model; pb1 = gtransform.Transform(new Point3D(lModel.Bounds.X + lModel.Bounds.SizeX / 2, lModel.Bounds.Y + lModel.Bounds.SizeY / 2, lModel.Bounds.Z + lModel.Bounds.SizeZ)); pb3 = gtransform.Transform(new Point3D(lModel.Bounds.X + lModel.Bounds.SizeX, lModel.Bounds.Y + lModel.Bounds.SizeY / 2, lModel.Bounds.Z + lModel.Bounds.SizeZ)); ptop = gtransform.Transform(new Point3D(lModel.Bounds.X + lModel.Bounds.SizeX, lModel.Bounds.Y + lModel.Bounds.SizeY, lModel.Bounds.Z + lModel.Bounds.SizeZ / 2)); pbuttom = gtransform.Transform(new Point3D(lModel.Bounds.X + lModel.Bounds.SizeX, lModel.Bounds.Y, lModel.Bounds.Z + lModel.Bounds.SizeZ / 2)); distance = pb3.X - pb1.X; po1 = pb1; po1.Offset(distance + 5, 0); po2 = po1; po2.Offset(10, -10); Path path; path = new Path() { StrokeThickness = 1, Stroke = Brushes.White }; PathGeometry geo = new PathGeometry(); PathFigure fig = new PathFigure(); fig.StartPoint = pb1; fig.Segments.Add(new LineSegment(po1, true)); fig.Segments.Add(new LineSegment(po2, true)); geo.Figures.Add(fig); path.Data = geo; owner.grdFlag.Children.Add(path); path = new Path() { StrokeThickness = 1, Fill = Brushes.Blue }; path.Data = new EllipseGeometry(pb1, 5, 5); owner.grdFlag.Children.Add(path); TextBlock txt = new TextBlock() { Foreground = Brushes.Yellow, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; txt.Text = ColorName; txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); txt.Margin = new Thickness(po2.X + 10, po2.Y - txt.DesiredSize.Height / 2, 0, 0); owner.grdFlag.Children.Add(txt); //色谱 Rectangle rec = new Rectangle() { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; rec.StrokeThickness = 0.3; rec.Stroke = new SolidColorBrush(Colors.White); rec.Width = 6; rec.Height = pbuttom.Y - ptop.Y; LinearGradientBrush brush = new LinearGradientBrush(); brush.StartPoint = new Point(0, 0); brush.EndPoint = new Point(0, 1); brush.GradientStops.Add(new GradientStop(colorStart, 1)); brush.GradientStops.Add(new GradientStop(colorEnd, 0)); rec.Fill = brush; rec.Margin = new Thickness(po2.X, ptop.Y, 0, 0); owner.grdFlag.Children.Add(rec); txt = new TextBlock() { Foreground = new SolidColorBrush(Color.FromRgb(0x99, 0xFF, 0xFF)), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; txt.Text = colorStartValue; txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); txt.Margin = new Thickness(po2.X + 10, pbuttom.Y - txt.DesiredSize.Height / 2, 0, 0); owner.grdFlag.Children.Add(txt); txt = new TextBlock() { Foreground = new SolidColorBrush(Color.FromRgb(0x99, 0xFF, 0xFF)), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; txt.Text = colorEndValue; txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); txt.Margin = new Thickness(po2.X + 10, ptop.Y - txt.DesiredSize.Height / 2, 0, 0); owner.grdFlag.Children.Add(txt); } }