Esempio n. 1
0
        /// <summary>
        /// Convert json object to PaintShape
        /// </summary>
        /// <param name="jObject">json object</param>
        /// <param name="baseProps">base properties</param>
        /// <returns>initialized paintshape</returns>
        private PaintShape GetPaintShape(JObject jObject, PaintBaseProperties baseProps)
        {
            if (jObject.GetValue("shapeType").ToString() == CircleShape.Instance.ToString() || jObject.GetValue("shapeType").ToString() == RectangleShape.Instance.ToString())
            {
                // Determine shape
                IShapeBase shape = null;
                if (jObject.GetValue("shapeType").ToString() == CircleShape.Instance.ToString())
                {
                    shape = CircleShape.Instance;
                }
                if (jObject.GetValue("shapeType").ToString() == RectangleShape.Instance.ToString())
                {
                    shape = RectangleShape.Instance;
                }

                // Create and return paintshape
                return(new PaintShape(shape)
                {
                    Height = baseProps.Height,
                    Width = baseProps.Width,
                    X = baseProps.X,
                    Y = baseProps.Y
                });
            }

            return(null);
        }
        private void AutoConnectEvents(ConnectDirections connectDirection, IShapeBase shapeBase, IEBCBase ebcBase, EventInfo[] events, MethodInfo[] methods)
        {
            Dictionary<string, MethodInfo> methodInfoToName = new Dictionary<string, MethodInfo>();

            object eventSource = null;
            object firstDelegateArgument = null;

            // Shape to EBC
            if (connectDirection == ConnectDirections.ShapeToEBC)
            {
                eventSource = shapeBase;
                firstDelegateArgument = ebcBase;
            }
            // EBC to Shape
            else if (connectDirection == ConnectDirections.EBCToShape)
            {
                eventSource = ebcBase;
                firstDelegateArgument = shapeBase;
            }

            // Save all methods in a dictionary with it's name as key.
            foreach (var currentMethod in methods)
            {
                if (currentMethod.Name.StartsWith("In_"))
                    methodInfoToName.Add(currentMethod.Name.Replace("In_", ""), currentMethod);
            }

            // Iterate over all found EBC-events and check if there is a matching EBC-handler.
            foreach (var currentEvent in events)
            {
                if (currentEvent.Name.StartsWith("Out_"))
                {
                    string name = currentEvent.Name.Replace("Out_", "");

                    if (methodInfoToName.ContainsKey(name))
                    {
                        // Connect them.
                        currentEvent.AddEventHandler(eventSource,
                                Delegate.CreateDelegate(currentEvent.EventHandlerType, firstDelegateArgument, methodInfoToName[name]));
                    }
                }
            }
        }
        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;
        }
Esempio n. 4
0
        /// <summary>
        /// Calcul de la masse et du centre de masse d'un membre de corps humain
        /// </summary>
        private ShapeResult GenerateShapeMass(IShapeBase member)
        {
            // Determinants

            var density = 0.000001;

            var actual = member;

            var defaultDistance = 6;

            // Zero test
            if (actual.Front_Down == 0)
            {
                actual.Front_Down = defaultDistance;
            }
            if (actual.Front_Middle == 0)
            {
                actual.Front_Middle = defaultDistance;
            }
            if (actual.Front_Top == 0)
            {
                actual.Front_Top = defaultDistance;
            }
            if (actual.Side_Down == 0)
            {
                actual.Side_Down = defaultDistance;
            }
            if (actual.Side_Middle == 0)
            {
                actual.Side_Middle = defaultDistance;
            }
            if (actual.Side_Top == 0)
            {
                actual.Side_Top = defaultDistance;
            }

            var p = Math.Pow(actual.Height_Down, 2) * actual.Height_Middle
                    - Math.Pow(actual.Height_Middle, 2) * actual.Height_Down
                    - Math.Pow(actual.Height_Down, 2) * actual.Height_Top
                    + Math.Pow(actual.Height_Top, 2) * actual.Height_Down
                    + Math.Pow(actual.Height_Middle, 2) * actual.Height_Top
                    - Math.Pow(actual.Height_Top, 2) * actual.Height_Middle;

            var a = (Math.Pow(actual.Side_Down, 2) * actual.Height_Middle
                     - Math.Pow(actual.Side_Middle, 2) * actual.Height_Down
                     - Math.Pow(actual.Side_Down, 2) * actual.Height_Top
                     + Math.Pow(actual.Side_Top, 2) * actual.Height_Down
                     + Math.Pow(actual.Side_Middle, 2) * actual.Height_Top
                     - Math.Pow(actual.Side_Top, 2) * actual.Height_Middle)
                    / p;

            var b = (Math.Pow(actual.Height_Down, 2) * Math.Pow(actual.Side_Middle, 2)
                     - Math.Pow(actual.Height_Middle, 2) * Math.Pow(actual.Side_Down, 2)
                     - Math.Pow(actual.Height_Down, 2) * Math.Pow(actual.Side_Top, 2)
                     + Math.Pow(actual.Height_Top, 2) * Math.Pow(actual.Side_Down, 2)
                     + Math.Pow(actual.Height_Middle, 2) * Math.Pow(actual.Side_Top, 2)
                     - Math.Pow(actual.Height_Top, 2) * Math.Pow(actual.Side_Middle, 2))
                    / p;

            var c = (Math.Pow(actual.Side_Top, 2) * Math.Pow(actual.Height_Down, 2) * actual.Height_Middle
                     - Math.Pow(actual.Side_Top, 2) * Math.Pow(actual.Height_Middle, 2) * actual.Height_Down
                     - Math.Pow(actual.Side_Middle, 2) * Math.Pow(actual.Height_Down, 2) * actual.Height_Top
                     + Math.Pow(actual.Side_Middle, 2) * Math.Pow(actual.Height_Top, 2) * actual.Height_Down
                     + Math.Pow(actual.Side_Down, 2) * Math.Pow(actual.Height_Middle, 2) * actual.Height_Top
                     - Math.Pow(actual.Side_Down, 2) * Math.Pow(actual.Height_Top, 2) * actual.Height_Middle)
                    / p;

            var k = (actual.Side_Down / actual.Front_Down + actual.Side_Middle / actual.Front_Middle
                     + actual.Side_Top / actual.Front_Top) / 3;

            // Results

            var mass = density * Math.PI * k * actual.Height_Top
                       * (3 * b * actual.Height_Top + 6 * c + 2 * a * Math.Pow(actual.Height_Top, 2))
                       / 6;

            var masscenter = (3 * a * Math.Pow(actual.Height_Top, 2) + 6 * c + 4 * b * actual.Height_Top)
                             / (6 * c + 3 * b * actual.Height_Top + 2 * a * Math.Pow(actual.Height_Top, 2))
                             / 2;

            // Que deux valeurs après la virgule
            mass       = Math.Round(mass, 2);
            masscenter = Math.Round(masscenter, 2);

            return(new ShapeResult(mass, masscenter));
        }
 public ConnectionShape(IShapeBase inputShape, IShapeBase outputShape)
     : this()
 {
     this.SetInputShape(inputShape);
     this.SetOutputShape(outputShape);
 }
        public void SetOutputShape(IShapeBase outputShape)
        {
            this.OutputShape = outputShape;

            if (this.InputShape == null)
            {
                this.LastLinePen.StartCap = LineCap.Round;
                this.LastLinePen.CustomEndCap = new AdjustableArrowCap(5, 5);

                this.CurrentLineDirection = LineDirection.OutputToInput;

                this.StartPoint = outputShape.OutputPinCenter();
                this.OutputShape.Out_ShapeDragged += (IShapeDraggedMessage shapeDraggedMessage) => { this.StartPoint = shapeDraggedMessage.OutputPinCenter; };
            }
            else
            {
                this.EndPoint = outputShape.OutputPinCenter();
                this.OutputShape.Out_ShapeDragged += (IShapeDraggedMessage shapeDraggedMessage) => { this.EndPoint = shapeDraggedMessage.OutputPinCenter; };
            }

            this.CheckStatus();
        }
        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));
            }
        }
 private void AddShape(IShapeBase shapeBase)
 {
     this.AddShape(shapeBase, null, Point.Empty);
 }
        private void DeleteShape(IShapeBase shape)
        {
            if (this.ShapeToEBC.ContainsKey(shape.ID))
            {
                IEBCBase ebc = this.ShapeToEBC[shape.ID];

                this.Out_DeleteEBC(ebc);

                ebc.RemoveEvents();

                this.EBCtoShape.Remove(ebc);
                this.EBCs.Remove(ebc);
            }

            if (this.ConnectionStartShapes.ContainsKey(shape))
            {
                foreach (var connectionShape in this.ConnectionStartShapes[shape])
                {
                    this.DeleteShape(connectionShape);
                }

                this.ConnectionStartShapes.Remove(shape);
            }

            if (this.ConnectionEndShapes.ContainsKey(shape))
            {
                foreach (var connectionShape in this.ConnectionEndShapes[shape])
                {
                    this.DeleteShape(connectionShape);
                }

                this.ConnectionEndShapes.Remove(shape);
            }

            shape.RemoveEvents();

            if (this.MouseEvents.ContainsKey(shape))
            {
                foreach (var mouseEvent in this.MouseEvents[shape])
                {
                    switch (mouseEvent.Key)
                    {
                        case "MouseMove":
                            this.Out_MouseMove -= mouseEvent.Value;
                            break;
                        case "MouseClick":
                            this.Out_MouseClick -= mouseEvent.Value;
                            break;
                        case "MouseUp":
                            this.Out_MouseUp -= mouseEvent.Value;
                            break;
                        case "MouseDown":
                            this.Out_MouseDown -= mouseEvent.Value;
                            break;
                        case "MouseDoubleClick":
                            this.Out_MouseDoubleClick -= mouseEvent.Value;
                            break;
                    }
                }

                this.MouseEvents.Remove(shape);
            }

            this.Shapes.Remove(shape.ID);
            this.ShapeLevels.Remove(shape.ID);
            this.ShapeToEBC.Remove(shape.ID);
        }
        private void HandlePinClicked(PinTypes pinType, IShapeBase shape)
        {
            if (this.LastClickedShape == null)
            {
                this.OnInner_ChangeShapeStatus(false);

                this.LastClickedShape = shape;

                this.LastConnection = new ConnectionShape();
                this.LastPinType = pinType;

                if (pinType == PinTypes.Input)
                    this.LastConnection.SetInputShape(this.LastClickedShape);
                else if (pinType == PinTypes.Output)
                    this.LastConnection.SetOutputShape(this.LastClickedShape);

                this.AddShape(this.LastConnection);
            }
            else if (this.LastClickedShape != null && this.LastPinType != pinType && this.LastClickedShape != shape)
            {
                if (pinType == PinTypes.Input)
                    this.LastConnection.SetInputShape(shape);
                else if (pinType == PinTypes.Output)
                    this.LastConnection.SetOutputShape(shape);

                if (this.ConnectEBCs(this.LastConnection))
                {
                    this.SetConnectionShapes(this.LastConnection);
                }

                this.CancelConnection(false);

                this.Out_PaintRequest();
            }
        }
 public STEConnectMessage(IShapeBase shape, IEBCBase ebc)
 {
     this.Shape = shape;
     this.EBC = ebc;
 }
 public void In_AddShape(IShapeBase shapeBase, IEBCBase ebcBase, Point shapeLocation)
 {
     this.Out_AddShape(new AddShapeMessage(shapeBase, ebcBase, shapeLocation));
 }
 public EBCPinClickedMessage(PinTypes pinType, IShapeBase shapeBase)
 {
     this.PinType = pinType;
     this.Shape = shapeBase;
 }
Esempio n. 14
0
 public PaintShape(PaintShape shape) : base(shape)
 {
     _shape = shape._shape;
 }
Esempio n. 15
0
 public PaintShape(IShapeBase shape)
 {
     _shape = shape;
 }
 public AddShapeMessage(IShapeBase shape, IEBCBase ebc, Point shapeLocation)
 {
     this.Shape = shape;
     this.EBC = ebc;
     this.ShapeLocation = shapeLocation;
 }