/// <summary> /// 执行命令 /// </summary> /// <param name="p_parameter"></param> protected override void DoExecute(object p_parameter) { LineMoveCmdArgs args = p_parameter as LineMoveCmdArgs; SLine line = args.Line; if (args.NewNode == null) { line.UpdateAnThumbPos(args.IsHeadNode); _owner.SelectionClerk.SelectLine(line); _owner.DeleteSelection(); } else { if (args.IsHeadNode) { line.HeaderID = args.NewNode.ID; line.HeaderPort = args.NewPos; } else { line.TailID = args.NewNode.ID; line.TailPort = args.NewPos; } } }
void OnLinkDragCompleted(object sender, DragCompletedEventArgs e) { SNode curNode = _owner.SelectionClerk.Selection[0] as SNode; LinkPortPosition startPos = CaclStart(curNode); Rect thumbRect = new Rect(Canvas.GetLeft(_thumb), Canvas.GetTop(_thumb), _thumb.ActualWidth, _thumb.ActualHeight); if (_owner.IsValidRegion(thumbRect)) { SNode tagNode = _owner.GetFirstIntersect(thumbRect); if (tagNode != null) { //是否存在连接 bool isHas = (from obj in _owner.Container.Children let line = obj as SLine where line != null && line.HeaderID == curNode.ID && line.TailID == tagNode.ID select line).Any(); if (!isHas) { SLine line = new SLine(_owner); line.HeaderID = curNode.ID; line.HeaderPort = startPos; line.TailID = tagNode.ID; line.TailPort = _owner.GetLinkPosition(tagNode, thumbRect); _owner.Insert(line); _owner.SelectionClerk.SelectLine(line); _owner.RefreshLinkLines(tagNode); } } } //还原默认位置 Canvas.SetLeft(_thumb, _thumbX); Canvas.SetTop(_thumb, _thumbY); _line.Visibility = Visibility.Collapsed; _owner.LinkThumbEnd(); }
/// <summary> /// 无指向的线(将被删除)的线移动参数构造函数 /// </summary> /// <param name="p_line"></param> /// <param name="p_isHeadNode"></param> /// <param name="p_oldNode"></param> /// <param name="p_oldPos"></param> public LineMoveCmdArgs(SLine p_line, bool p_isHeadNode, SNode p_oldNode, LinkPortPosition p_oldPos) { _line = p_line; _isHeadNode = p_isHeadNode; _oldNode = p_oldNode; _oldPos = p_oldPos; }
/// <summary> /// 清空连线的选择状态 /// </summary> void ClearLine() { if (_selLine != null) { _selLine.ThumbVisibility = Visibility.Collapsed; } _selLine = null; }
public static SPoint SymmetryPoint(SPoint Point_, SLine Line_) { SPoint PointVector = Point_.Sub(Line_.Point0); var NewTheta = (Mathf.Atan2(PointVector.Y, PointVector.X) - 2.0f * ThetaOfTwoVectors(PointVector, Line_.Point1.Sub(Line_.Point0))); var Radius = Mathf.Sqrt(PointVector.X * PointVector.X + PointVector.Y * PointVector.Y); return(new SPoint(Mathf.Cos(NewTheta) * Radius, Mathf.Sin(NewTheta) * Radius).Add(Line_.Point0)); }
/// <summary> /// 选择连线 /// </summary> /// <param name="p_line"></param> public void SelectLine(SLine p_line) { ClearNode(); ClearLine(); _selLine = p_line; if (_selLine != null) { _selLine.ThumbVisibility = Visibility.Visible; } _owner.OnSelectionChanged(); BringToFront(p_line); }
/// <summary> /// 执行撤消 /// </summary> /// <param name="p_parameter"></param> protected override void DoUndo(object p_parameter) { LineMoveCmdArgs args = p_parameter as LineMoveCmdArgs; SLine line = args.Line; if (args.NewNode == null) { _owner.His.Undo(); } else { if (args.IsHeadNode) { line.HeaderID = args.OldNode.ID; line.HeaderPort = args.OldPos; } else { line.TailID = args.OldNode.ID; line.TailPort = args.OldPos; } } }
static void Main(string[] args) { const int size = 42; var cline = new CLine(size); var sline = new SLine(size); PrintSize(cline, sline); const int newsize = 17; cline.Resize(newsize); sline.Resize(newsize); PrintSize(cline, sline); var isline = (IShape)sline; var icline = (IShape)cline; PrintSize(icline, isline); PrintSize(cline, sline); const int newnewsize = 7; icline.Resize(newnewsize); isline.Resize(newnewsize); // ! PrintSize(icline, isline); PrintSize(cline, sline); var newicline = icline.ResizeImutable(newnewsize); var newisline = isline.ResizeImutable(newnewsize); PrintSize(newicline, newisline); Console.ReadLine(); }
static void Main(String[] args) { var Begin = new SPoint(0, 0); var End = new SPoint(10, 5); while (!CPhysics.MoveTowards(Begin, End, 0.5f)) { Console.WriteLine(Begin.X + " " + Begin.Y); } Console.WriteLine(Begin.X + " " + Begin.Y); return; var MyCenter = new SPoint(0.7059453529691696f, 0.95074967547869216f); var TargetCenter = new SPoint(0.69332838119407825f, 0.78701901149100739f); var Vel0 = new SPoint(0.19000000000000197f, -0.38262210845947314f); var Theta0 = Math.Atan2(Vel0.Y, Vel0.X); // My Scalar var Scalar = Vel0.GetScalar(); // Get Me To Target Vector var LinkVector = TargetCenter.GetSub(MyCenter); // 나의 속도벡터를 나와 대상을 연결한 직선과 나란한 성분A와 A와 수직이 B를 구하고 // A, B의 X,Y 성분을 구하고, B-A 를 구하면 이것이 BalloonFight 의 충돌후의 내 Vector var LinkTheta = CBase.ThetaOfTwoVectors(LinkVector, Vel0); var ScalarA = Mathf.Abs(Mathf.Cos(LinkTheta) * Scalar); var ThetaA = Mathf.Atan2(LinkVector.Y, LinkVector.X); var VecA = new SPoint(Mathf.Cos(ThetaA) * ScalarA, Mathf.Sin(ThetaA) * ScalarA); var ScalarB = Mathf.Abs(Mathf.Sin(LinkTheta) * Scalar); var ThetaB = ThetaA - (Mathf.PI * 0.5f); var VecB = new SPoint(Mathf.Cos(ThetaB) * ScalarB, Mathf.Sin(ThetaB) * ScalarB); var BouncedVec = VecB.GetSub(VecA); Console.WriteLine(VecA.X + " " + VecA.Y); Console.WriteLine(VecB.X + " " + VecB.Y); Console.WriteLine(BouncedVec.X + " " + BouncedVec.Y); return; if (CPhysics.IsOverlappedRectRect(new SRect(0.0f, 1.0f, 0.0f, 1.0f), new SRect(1.0f, 3.0f, 0.0f, 1.0f))) { Console.WriteLine("true"); } else { Console.WriteLine("false"); } return; var CollisionInfo = new SCollisionInfo(); if (CPhysics.IsCollidedRectRect2(new SRect(0.0f, 2.0f, 0.0f, 1.0f), new SRect(1.0f, 3.0f, 0.0f, 1.0f), new SPoint(1.0f, 0.0f), new SPoint(0.0f, 0.0f), CollisionInfo)) { Console.WriteLine("true" + CollisionInfo.Time); } else { Console.WriteLine("false" + CollisionInfo.Time); } SPoint p = new SPoint(0.00000001f, 0.0f); SLine l = new SLine(new SPoint(0.0f, 1.0f), new SPoint(2.0f, 1.0f)); var o = CBase.SymmetryPoint(p, l); Console.WriteLine(o.X + " " + o.Y); }
/// <summary> /// 加载xml字符串 /// </summary> /// <param name="p_xml"></param> public void ReadXml(string p_xml) { _his?.Clear(); _container.Children.Clear(); _selectionClerk.Clear(); if (string.IsNullOrEmpty(p_xml)) { return; } using (StringReader stream = new StringReader(p_xml)) using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings() { IgnoreWhitespace = true, IgnoreComments = true, IgnoreProcessingInstructions = true })) { reader.Read(); Rect totalRect = new Rect(); bool isFirst = true; reader.Read(); while (reader.NodeType != XmlNodeType.None) { if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Sketch") { break; } Rect rc = new Rect(); string name = reader.Name; if (name == "Node") { SNode node = new SNode(this); _container.Children.Add(node); node.ReadXml(reader); rc = new Rect(Canvas.GetLeft(node), Canvas.GetTop(node), node.Width, node.Height); } else if (name == "Line") { SLine line = new SLine(this); _container.Children.Add(line); line.ReadXml(reader); rc = line.Bounds; } else if (name == "Txt") { TextBlock tb = new TextBlock(); _container.Children.Add(tb); for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); switch (reader.Name) { case "text": tb.Text = reader.Value; break; case "fontsize": tb.FontSize = double.Parse(reader.Value); break; // uwp和手机系统weight的操作方式不同 #if UWP case "fontweight": tb.FontWeight = new FontWeight() { Weight = ushort.Parse(reader.Value) }; break; #else case "fontweight": tb.FontWeight = new FontWeight(ushort.Parse(reader.Value)); break; #endif case "foreground": tb.Foreground = new SolidColorBrush(Res.HexStringToColor(reader.Value)); break; case "fontstyle": tb.FontStyle = (FontStyle)int.Parse(reader.Value); break; case "fontfamily": tb.FontFamily = new FontFamily(reader.Value); break; case "left": Canvas.SetLeft(tb, double.Parse(reader.Value)); break; case "top": Canvas.SetTop(tb, double.Parse(reader.Value)); break; case "width": tb.Width = double.Parse(reader.Value); break; case "height": tb.Height = double.Parse(reader.Value); break; } } rc = new Rect(Canvas.GetLeft(tb), Canvas.GetTop(tb), tb.Width, tb.Height); } if (isFirst) { totalRect = rc; isFirst = false; } else { totalRect = Union(totalRect, rc); } reader.Read(); } if (IsReadOnly) { ResizeReadOnlyPage(totalRect); } else { ResizeEditPage(totalRect); } } RefreshAllLines(); }
public static void Process(SLine isoLine) => Messenger.Default.Send(new SLineMessage() { Value = isoLine.Value });
public void Set(SLine Obj_) { Point0.Set(Obj_.Point0); Point1.Set(Obj_.Point1); }
public SLine(SLine Obj_) { Point0 = Obj_.Point0; Point1 = Obj_.Point1; }