private void ConnectShapeToEBC(IShapeBase shape, IEBCBase ebc) { Type shapeType = shape.GetType(); Type ebcType = ebc.GetType(); // First, events of shapeBase to matching methods of ebcBase. EventInfo[] shapeBaseEvents = shapeType.GetEvents(); MethodInfo[] ebcBaseMethods = ebcType.GetMethods(BindingFlags.Public | BindingFlags.Instance); this.AutoConnectEvents(ConnectDirections.ShapeToEBC, shape, ebc, shapeBaseEvents, ebcBaseMethods); // Second, events of ebcBase to matching methods of shapeBase. EventInfo[] ebcBaseEvent = ebcType.GetEvents(); MethodInfo[] shapeBaseMethods = shapeType.GetMethods(BindingFlags.Public | BindingFlags.Instance); this.AutoConnectEvents(ConnectDirections.EBCToShape, shape, ebc, ebcBaseEvent, shapeBaseMethods); // Last, set the EBC-Name to the shape. shape.Name = ebc.Name; }
private void AddShape(IShapeBase shape, IEBCBase ebc, Point shapeLocation) { try { if (!(shape is ConnectionShape)) { this.Out_STEAutoConnect(new STEConnectMessage(shape, ebc)); shape.Out_PinClicked += new Action<IEBCPinClickedMessage>(shapeBase_Out_PinClicked); if (!shapeLocation.IsEmpty) shape.SetInitialPosition(shapeLocation); this.EBCs.Add(ebc); this.ShapeToEBC.Add(shape.ID, ebc); this.EBCtoShape.Add(ebc, shape.ID); shape.Out_StartProcess += () => this.Out_ExecuteFirstEBC(new ExecuteFirstEBCMessage(this.ShapeToEBC[shape.ID])); // this.StartProcessEvents[shape]; this.Inner_ChangeShapeStatus += (IChangeShapeStatusMessage changeShapeStatus) => shape.In_ChangeShapeStatus(changeShapeStatus); // this.ChangeShapeStatusEvents[shape]; } Dictionary<string, Action<MouseEventArgs>> mouseEvents = new Dictionary<string, Action<MouseEventArgs>>(); Action<MouseEventArgs> mouseClickEvent = (MouseEventArgs mouseEventArgs) => shape.In_MouseClick(mouseEventArgs); Action<MouseEventArgs> mouseDoubleClickEvent = (MouseEventArgs mouseEventArgs) => shape.In_MouseDoubleClick(mouseEventArgs); Action<MouseEventArgs> mouseMoveEvent = (MouseEventArgs mouseEventArgs) => shape.In_MouseMove(mouseEventArgs); Action<MouseEventArgs> mouseUpEvent = (MouseEventArgs mouseEventArgs) => shape.In_MouseUp(mouseEventArgs); Action<MouseEventArgs> mouseDownEvent = (MouseEventArgs mouseEventArgs) => shape.In_MouseDown(mouseEventArgs); mouseEvents.Add("MouseMove", mouseMoveEvent); mouseEvents.Add("MouseUp", mouseUpEvent); mouseEvents.Add("MouseDown", mouseDownEvent); mouseEvents.Add("MouseClick", mouseClickEvent); mouseEvents.Add("MouseDoubleClick", mouseDoubleClickEvent); this.Out_MouseClick += mouseClickEvent; this.Out_MouseMove += mouseMoveEvent; this.Out_MouseUp += mouseUpEvent; this.Out_MouseDown += mouseDownEvent; this.Out_MouseDoubleClick += mouseDoubleClickEvent; shape.Out_PaintRequest += () => this.Out_PaintRequest(); this.MouseEvents.Add(shape, mouseEvents); this.ShapeLevels.Insert(0, shape.ID); this.Shapes.Add(shape.ID, shape); if (!(shape is ConnectionShape)) { this.Out_EBCAdded(ebc); // use the EBC type for counting. Type ebcType = ebc.GetType(); if (this.ShapeTypeCount.ContainsKey(ebcType)) { this.ShapeTypeCount[ebcType]++; // Only add the type number, if there is a minimum of two EBCs with this type. shape.Name += " " + this.ShapeTypeCount[ebcType]; ebc.Name = shape.Name; } else { this.ShapeTypeCount.Add(ebcType, 1); } } } catch (TargetException targetException) { this.OnOut_ReportError(new STEAutoConnectionException("Die Automatische Verbindung von Shape und EBC ist fehlgeschlagen!", targetException)); } }