/// <summary> /// 블럭이 끼워질 때의 이벤트 /// 끼워진 블럭이 가지는 구멍들을 이 블럭이 가진 구멍 목록에 추가 /// </summary> /// <param name="hole">블럭이 끼워진 구멍</param> /// <param name="block">구멍에 끼운 블럭</param> private void OnBlockAttached(BaseHole hole, BaseBlock block) { if (block != null) { AllHoleList.AddRange(block.HoleList); block.AllowVariableList.AddRange(AllowVariableList); ParentHole?.ParentBlock?.OnBlockAttached(hole, block); } }
public static void ConnectToHole(BaseHole baseHole, BaseBlock baseBlock) { if (baseHole is BaseObjectHole) { (baseHole as BaseObjectHole).BaseObjectBlock = baseBlock as ObjectBlock; } else if (baseHole is SettableObjectHole) { (baseHole as SettableObjectHole).SettableObjectBlock = baseBlock as SettableObjectBlock; } else if (baseHole is NextConnectHole) { (baseHole as NextConnectHole).StatementBlock = baseBlock as StatementBlock; } }
/// <summary> /// 블럭이 떨어질 때의 이벤트 /// 떨어진 블럭이 가지는 구멍들은 이 블럭이 가진 구멍 목록에서 제거 /// </summary> /// <param name="hole">블럭이 떨어져 나온 구멍</param> /// <param name="block">구멍에서 떨어진 블럭</param> private void OnBlockDetached(BaseHole hole, BaseBlock block) { if (block != null) { foreach (var holeItem in block.HoleList) { AllHoleList.Remove(holeItem); } foreach (var allowVariable in AllowVariableList) { block.AllowVariableList.Remove(allowVariable); } ParentHole?.ParentBlock?.OnBlockDetached(hole, block); } }
// RealNextConnectHole BlockAttached & BlockDetached Event private void RealNextConnectHole_BlockChanged(BaseHole hole, BaseBlock block) { _GFunction.Content.Clear(); List <GBase> content = NextConnectHole.StatementBlock?.ToGObjectList(); if (content == null) { return; } foreach (GBase gbase in content) { if (gbase is GStatement) { _GFunction.Append(gbase as GStatement); } } }
private void UserControl_MouseUp(object sender, MouseButtonEventArgs e) { // 선택한 블럭이 없으면 안됨 if (SelectedBlock == null) { return; } // 마우스를 움직인 경우에만 if (IsSelectedBlockMoved) { // 마우스 좌표로 블럭 이동 Point position = e.GetPosition(Master); SelectedBlock.Position = new Point(position.X - SelectedPosition.X, position.Y - SelectedPosition.Y); if (SelectedBlock.Position.X < 0) { SelectedBlock.Position = new Point(0, SelectedBlock.Position.Y); } if (SelectedBlock.Position.Y < 0) { SelectedBlock.Position = new Point(SelectedBlock.Position.X, 0); } // 연결할 대상이 있다면 연결 if (MargnetTarget != null) { ConnectBlock(SelectedBlock, e); } } Panel.SetZIndex(SelectedBlock, 1); // Selected 해제 SelectedBlock = null; MargnetTarget = null; Highlighter.Visibility = Visibility.Hidden; CanAttachHoleList.Clear(); ReleaseMouseCapture(); }
// 각자 맞는 블럭으로 오버로딩 private void MargnetBlock(BaseBlock block, MouseEventArgs e) { MargnetTarget = null; Highlighter.Visibility = Visibility.Hidden; foreach (var hole in CanAttachHoleList) { if (block.AllHoleList.Contains(hole)) { continue; } var position = hole.TranslatePoint(new Point(0, 0), Master); if (GetDistance(position, block.Position) > 20) { continue; } MargnetTarget = hole; Highlighter.Margin = new Thickness(position.X, position.Y, 0, 0); Highlighter.Visibility = Visibility.Visible; } }
/// <summary> /// 모듈 블럭들에게 필요한 구멍을 자동으로 찾아서 생성하고 위치시킵니다. /// </summary> /// <param name="Command">모듈을 호출하기 위해 필요한 GCommand 객체</param> /// <param name="Content">생성한 구멍과 내용을 추가할 Panel 객체</param> /// <returns>생성한 모든 구멍을 반환</returns> public static List <BaseHole> SetContent(GCommand Command, Panel Content, Brush brush = null) { // 기존 패널에 있는 내용 삭제 Content.Children.Clear(); // 반환을 위한 구멍 목록 생성 var holeList = new List <BaseHole>(); // Command의 FriendlyName에서 구멍 파싱 var start = -1; var last = 0; for (int i = 0; i < Command.FriendlyName.Length; i++) { var chr = Command.FriendlyName[i]; if (chr == '{') { start = i; } else if (chr == '}' && start >= 0) { var text = Command.FriendlyName.Substring(last, start - last); var holeNumber = Command.FriendlyName.Substring(start + 1, i - start - 1); int number; if (int.TryParse(holeNumber, out number) && 0 <= number && number < Command.Optionals.Length) { BaseHole hole = CreateHole(Command.Optionals[number].ObjectType); if (brush == null) { brush = new BrushConverter().ConvertFromString("#086748") as Brush; } hole.Foreground = brush; hole.VerticalAlignment = VerticalAlignment.Center; Content.Children.Add(new TextBlock { Text = text, FontWeight = FontWeights.Bold, Foreground = Brushes.White, VerticalAlignment = VerticalAlignment.Center }); Content.Children.Add(hole); holeList.Add(hole); start = -1; last = i + 1; } } } var lastText = Command.FriendlyName.Substring(last); Content.Children.Add(new TextBlock { Text = lastText, FontWeight = FontWeights.Bold, Foreground = Brushes.White, VerticalAlignment = VerticalAlignment.Center }); // 구멍 목록 반환 return(holeList); }