public Link(ReactableObject _input, ReactableObject _output, Canvas _canvas)
 {
     connection = new Line();
     input      = _input;
     output     = _output;
     canvas     = _canvas;
 }
Beispiel #2
0
 public GeneratorLink(ReactableObject _input, ReactableObject _output, Canvas _canvas) : base(_input, _output, _canvas)
 {
     if (typeof(Filter).IsAssignableFrom(input.GetType()))
     {
         drawingConnectionWithFiltrer();
     }
     else if (typeof(Output).IsAssignableFrom(input.GetType()))
     {
     }
 }
        /// <summary>
        /// Draws a line (a connection) between two objects.
        /// </summary>
        /// <param name="outPut"> The object which will be connected to another object. </param>
        /// <param name="inPut"> The object which receives the connection. </param>
        public void connection(ReactableObject outPut, ReactableObject inPut)
        {
            // Removes the previous connection.
            disconnection(outPut, inPut);

            // Creating the connection between the output and the input.
            linkConnection = new Line();
            if (outPut is Generator)
            {
                linkConnection.Stroke = Brushes.Green;
            }
            else if (outPut is EffectFilter)
            {
                linkConnection.Stroke = Brushes.Orange;
            }
            else if (outPut is Controller)
            {
                linkConnection.Stroke = Brushes.Yellow;
            }
            //listEffectFilter((EffectFilter) outPut, (EffectFilter) inPut);
            linkConnection.StrokeThickness = 2;

            linkConnection.X1 = outPut.getX();
            linkConnection.Y1 = outPut.getY();

            linkConnection.X2 = inPut.getX();
            linkConnection.Y2 = inPut.getY();

            outPut.Canvas.Children.Add(linkConnection);
            outPut.connected = true;

            // If the input is a filter, its input must be store the output.
            if (inPut is EffectFilter && !(outPut is Controller))
            {
                inPut.InputObject[0] = outPut;
            }

            /* if (inPut is EffectFilter && outPut is EffectFilter)
             * {
             *
             *   if ((previousConnectedObject != null && previousConnectedObject!= inPut)&& previousConnectedObject is EffectFilter)
             *   {
             *       deleteInList((EffectFilter)inPut, (EffectFilter)previousConnectedObject);
             *   }
             *   if (previousConnectedObject == null || !inPut.Equals(previousConnectedObject))
             *   {
             *      // deleteInList((EffectFilter)inPut, (EffectFilter)previousConnectedObject);
             *       listEffectFilter((EffectFilter)inPut, (EffectFilter)outPut);
             *   }
             * }*/
        }
        public override void checkingConnection(InputReactableObject controller)
        {
            // Copy and paste the list of object in the radius of the generator in a local list.
            List <ReactableObject> objectList = new List <ReactableObject>();

            controller.ObjectsInRadius.ForEach(objectList.Add);

            //Takes the nearest object of the list of object.
            ReactableObject nearestObject = controller.nearestObject(objectList);

            if (nearestObject is Controller)
            {
                while (nearestObject is Controller && nearestObject == null)
                {
                    // Creates a temporary list which stores the current list of object
                    List <ReactableObject> temp = new List <ReactableObject>();
                    objectList.ForEach(temp.Add);
                    // Clear the old list
                    objectList.Clear();

                    // Updates the list of object which has got the objects in the generator's radius,
                    // without the previous nearest object.
                    foreach (ReactableObject reactableObject in temp)
                    {
                        if (!reactableObject.Equals(nearestObject))
                        {
                            objectList.Add(reactableObject);
                        }
                    }
                    // Gets the new nearest object
                    nearestObject = controller.nearestObject(objectList);
                }
            }

            // Condition: the generator has got an object ,at least one, in its radius.
            if (nearestObject != null)
            {
                //The connection can be established with the given object
                connection(controller, nearestObject);
                previousConnectedObject = nearestObject;
            }
            else
            {
                disconnection(controller, previousConnectedObject);
            }
        }
Beispiel #5
0
        //public positionOutput;

        public Output(Canvas _canvas)
        {
            Canvas              = _canvas;
            x                   = 650;
            y                   = 350;
            outputCircle        = new Ellipse();
            outputCircle.Height = height;
            outputCircle.Width  = width;
            outputCircle.Fill   = Brushes.Black;
            Canvas.SetTop(outputCircle, y - height / 2);
            Canvas.SetLeft(outputCircle, x - width / 2);

            InputObject    = new ReactableObject[1];
            InputObject[0] = null;

            Canvas.Children.Add(outputCircle);
        }
        /// <summary>
        /// Deletes the connection.
        /// </summary>
        /// <param name="outPut"> The object which will be connected to another object.</param>
        /// <param name="inPut"> The object which receives the connection. </param>
        public void disconnection(ReactableObject outPut, ReactableObject inPut)
        {
            outPut.connected = false;

            if (linkConnection != null)
            {
                // Removes the previous connection on the canvas.
                outPut.Canvas.Children.Remove(linkConnection);
            }

            if (previousConnectedObject != null && inPut != null &&
                !(outPut is Controller))
            {
                // Only if the input is not already connected with its previous output.
                if (!outPut.Equals(previousConnectedObject))
                {
                    // Sets the filter's input at null.
                    previousConnectedObject.InputObject[0] = null;
                }
            }
        }
        /// <summary>
        /// Constructs an object of type Effect/Filter.
        /// </summary>
        /// <param name="_canvas">canvas where the oscillator is on it</param>
        /// <param name="x">Coordonne x</param>
        /// <param name="y">Coordonne y</param>
        /// <param name="_width">The size of each object's side</param>
        protected EffectFilter(Canvas _canvas, int _x, int _y, double _width)
        {
            Canvas = _canvas;
            x      = _x;
            y      = _y;
            height = _width;
            width  = _width;


            #region Create the main form.

            // The shape is created depending of the input.
            Rect rect = new Rect(new Size(height, width));
            RectangleGeometry rectangleGeometry = new RectangleGeometry(rect, roundBlock, roundBlock);
            geometricShape        = new Path();
            geometricShape.Data   = rectangleGeometry;
            geometricShape.Width  = width;
            geometricShape.Height = height;


            Canvas.SetTop(geometricShape, y - height / 2);
            Canvas.SetLeft(geometricShape, x - width / 2);
            // set Z index for the geometric shape for hidding connection line
            Canvas.SetZIndex(geometricShape, 1);

            #endregion Create the main form.

            // RenderTransform part
            initializationInputStuff();

            // Add the object on the canvas.
            Canvas.Children.Add(geometricShape);
            drawRightArc();
            drawLeftArc();
            drawPointerArcLeft();
            drawPointerArcRight();
            drawingCollisionSurface(300);

            // Initialization of his output.
            outputLink = new EffectFilterLink();

            // Initialization of the list.
            checkRadius(ReactableObject.ReactableObjectList);

            // Adds the output in his list of object in radius.
            ObjectsInRadius.Add(SmartBoard.output);

            // set the opacity of the collision surface, it will be appear when the user click on the object
            collisionSurface.Opacity = 0;

            InputObject      = new ReactableObject[MAX_NUMBER_CONNECTED_OBJECT];
            connectedObjects = null;

            connectionChecker = new DispatcherTimer(new TimeSpan(1000 * 100),  //time interval, timespam( 10^-7/init)
                                                    DispatcherPriority.Normal, //priority
                                                    delegate
            {
                outputLink.checkingConnection(this);
            },
                                                    geometricShape.Dispatcher);
        }
        public override void checkingConnection(InputReactableObject generator)
        {
            // Copy and paste the list of object in the radius of the generator in a local list.
            List <ReactableObject> objectList = new List <ReactableObject>();

            generator.ObjectsInRadius.ForEach(objectList.Add);

            //Takes the nearest object of the list of object.
            ReactableObject nearestObject   = generator.nearestObject(objectList);
            bool            connectionCheck = false;

            // Condition: the generator has got an object ,at least one, in its radius.
            //if (nearestObject != null)
            //{
            // Condition: If the nearest object is an effect filter which is already connected.
            if (nearestObject.InputObject[0] != null && nearestObject is EffectFilter &&
                !generator.Equals(nearestObject.InputObject[0]) ||
                generator.distanceCalculation(SmartBoard.output) < nearestObject.distanceCalculation(SmartBoard.output))
            {
                // To leave: a connection has been established or every objects in the generator's radius are not available to be connected.
                while (!connectionCheck)     //&& nearestObject != null && objectList.Count>0)
                {
                    // If the nearest object is the output the object must to be connected with it.
                    if (!(nearestObject is Output))
                    {
                        // Check if the nearest object is before the generator.
                        if (generator.distanceCalculation(SmartBoard.output) > nearestObject.distanceCalculation(SmartBoard.output))
                        {
                            // If a connection is available with the filter or if the filter is already connected with the generator
                            if (nearestObject.InputObject[0] == null || nearestObject.InputObject[0].Equals(generator))
                            {
                                // Creates or updates the connection
                                connection(generator, nearestObject);
                                connectionCheck = true;
                            }
                            // If the nearest object has already got a connected object, we check if the connected object is more distant of the generator or not
                            if (nearestObject.distanceCalculation(nearestObject.InputObject[0]) > generator.distanceCalculation(nearestObject))
                            {
                                // If the generator is more close, a new connection is established.
                                connection(generator, nearestObject);
                                connectionCheck = true;
                            }
                        }

                        // If a connection is not available with the given nearest object.
                        if (!connectionCheck)
                        {
                            // Creates a temporary list which stores the current list of object
                            List <ReactableObject> temp = new List <ReactableObject>();
                            objectList.ForEach(temp.Add);
                            // Clear the old list
                            objectList.Clear();

                            // Updates the list of object which has got the objects in the generator's radius,
                            // without the previous nearest object.
                            foreach (ReactableObject reactableObject in temp)
                            {
                                if (!reactableObject.Equals(nearestObject))
                                {
                                    objectList.Add(reactableObject);
                                }
                            }
                            // Gets the new nearest object
                            nearestObject = generator.nearestObject(objectList);
                        }
                    }
                    else
                    {
                        connection(generator, nearestObject);
                        connectionCheck = true;
                    }
                }
            }
            // Condition: If the nearest object is not an effect filter.
            else
            {
                //The connection can be established with the given object
                connection(generator, nearestObject);
            }
            // }
            // Saves the previous object which has been connected.
            previousConnectedObject = nearestObject;
        }