Esempio n. 1
0
        private bool isLinkedToProcess(LinkStroke linkStroke, CustomInkCanvas canvas)
        {
            CustomStroke fromStroke = new Stroke(new StylusPointCollection {
                new StylusPoint(0, 0)
            }) as CustomStroke;
            CustomStroke toStroke = new Stroke(new StylusPointCollection {
                new StylusPoint(0, 0)
            }) as CustomStroke;

            string from = "";
            string to   = "";

            from = linkStroke.from?.formId;
            to   = linkStroke.to?.formId;
            if (from != null)
            {
                canvas.StrokesDictionary.TryGetValue(from, out fromStroke);
            }
            if (to != null)
            {
                canvas.StrokesDictionary.TryGetValue(to, out toStroke);
            }

            return(fromStroke != null && fromStroke.isProccessStroke() || toStroke != null && toStroke.isProccessStroke());
        }
Esempio n. 2
0
        private bool isBetweenTwoClasses(LinkStroke linkStroke, CustomInkCanvas canvas)
        {
            CustomStroke fromStroke = new Stroke(new StylusPointCollection {
                new StylusPoint(0, 0)
            }) as CustomStroke;
            CustomStroke toStroke = new Stroke(new StylusPointCollection {
                new StylusPoint(0, 0)
            }) as CustomStroke;

            string from = "";
            string to   = "";

            from = linkStroke.from?.formId;
            to   = linkStroke.to?.formId;
            if (from != null)
            {
                canvas.StrokesDictionary.TryGetValue(from, out fromStroke);
            }
            if (to != null)
            {
                canvas.StrokesDictionary.TryGetValue(to, out toStroke);
            }

            return(fromStroke is ClassStroke && toStroke is ClassStroke);
        }
        private void CreateLink(Point actualPos, ShapeStroke strokeTo, int number, int linkAnchorNumber, LinkTypes linkType, Point pos)
        {
            LinkStroke linkBeingCreated = new LinkStroke(pos, shapeStroke?.guid.ToString(), linkAnchorNumber, linkType, new StylusPointCollection {
                new StylusPoint(0, 0)
            });

            shapeStroke?.linksFrom.Add(linkBeingCreated.guid.ToString());

            linkBeingCreated.addToPointToLink(actualPos, strokeTo?.guid.ToString(), number);
            strokeTo?.linksTo.Add(linkBeingCreated.guid.ToString());

            canvas.AddStroke(linkBeingCreated);
            DrawingService.CreateLink(linkBeingCreated);

            StrokeCollection shapesToUpdate = new StrokeCollection();

            if (shapeStroke != null)
            {
                shapesToUpdate.Add(shapeStroke);
            }
            if (strokeTo != null && !shapesToUpdate.Contains(strokeTo))
            {
                shapesToUpdate.Add(strokeTo);
            }
            DrawingService.UpdateShapes(shapesToUpdate);

            canvas.Select(new StrokeCollection {
                linkBeingCreated
            });
        }
 public static void CreateLink(LinkStroke linkStroke)
 {
     socket.Emit("createLink", serializer.Serialize(createUpdateLinksData(new StrokeCollection {
         linkStroke
     })));
     localAddedStrokes.Add(linkStroke.guid.ToString());
     if (!saving)
     {
         saving = true;
         Application.Current?.Dispatcher?.Invoke(new Action(() => { SaveCanvas(); }), DispatcherPriority.Render);
     }
 }
        // Be sure to call the base class constructor.
        public DottedPathAdorner(UIElement adornedElement, LinkStroke stroke, CustomInkCanvas canvas)
            : base(adornedElement)
        {
            adornedStroke = stroke;

            linkStroke     = stroke;
            this.canvas    = canvas;
            visualChildren = new VisualCollection(this);
            strokeBounds   = stroke.GetCustomBound();

            linkPath                 = new Path();
            linkPath.Stroke          = (Brush) new BrushConverter().ConvertFromString(stroke.style.color);
            linkPath.StrokeThickness = stroke.DrawingAttributes.Height;
            linkPath.StrokeDashArray = new DoubleCollection {
                1, 0.5
            };
            linkPath.IsHitTestVisible = false;
            linkPath.Fill             = Brushes.Black;

            arrowGeom = new PathGeometry();
            lineGeom  = new LineGeometry();

            for (int i = 1; i < linkStroke.path.Count - 1; i++)
            {
                lineGeom.StartPoint = linkStroke.path[i - 1].ToPoint();
                lineGeom.EndPoint   = linkStroke.path[i].ToPoint();
                arrowGeom.AddGeometry(lineGeom);
            }

            AddRelationArrows1();

            linkPath.Data = arrowGeom;

            arrowGeom = new PathGeometry();

            AddRelationArrows();

            arrow                 = new Path();
            arrow.Data            = arrowGeom;
            arrow.Stroke          = (Brush) new BrushConverter().ConvertFromString(stroke.style.color);
            arrow.StrokeThickness = 2;
            if (linkStroke.linkType == 1 || linkStroke.linkType == 2 && linkStroke.style?.thickness != 0)
            {
                arrow.StrokeThickness = 3;
            }
            arrow.IsHitTestVisible = false;
            arrow.Fill             = Brushes.Black;

            visualChildren.Add(linkPath);
            visualChildren.Add(arrow);
        }
        public LinkRotateAdorner(UIElement adornedElement, LinkStroke strokeToRotate, CustomInkCanvas actualCanvas)
            : base(adornedElement)
        {
            adornedStroke = strokeToRotate;

            linkStroke = strokeToRotate;
            canvas     = actualCanvas;
            // rotation initiale de la stroke (pour dessiner le rectangle)
            // Bug. Cheat, but the geometry, the selection Rectangle (newRect) should be the right one.. geom of the stroke?
            strokeBounds = strokeToRotate.GetCustomBound();
            center       = linkStroke.GetCenter();
            lastAngle    = linkStroke.rotation;

            rotation = new RotateTransform(linkStroke.rotation, center.X, center.Y);

            visualChildren          = new VisualCollection(this);
            rotateHandle            = new Thumb();
            rotateHandle.Cursor     = Cursors.Hand;
            rotateHandle.Width      = 10;
            rotateHandle.Height     = 10;
            rotateHandle.Background = new LinearGradientBrush((Color)ColorConverter.ConvertFromString("#FFc8d4ea"),
                                                              (Color)ColorConverter.ConvertFromString("#FF809dce"), 45);

            rotateHandle.DragDelta     += new DragDeltaEventHandler(rotateHandle_DragDelta);
            rotateHandle.DragCompleted += new DragCompletedEventHandler(rotateHandle_DragCompleted);

            TransformGroup transform = new TransformGroup();

            transform.Children.Add(new RotateTransform(rotation.Angle, rotateHandle.Width / 2, rotateHandle.Height / 2));
            transform.Children.Add(new TranslateTransform(-canvas.ActualWidth / 2 + strokeBounds.X + strokeBounds.Width / 2,
                                                          -canvas.ActualHeight / 2 + strokeBounds.Y - HANDLEMARGIN));

            rotateHandle.RenderTransform = transform;

            line                 = new Path();
            line.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF809dce"));
            line.StrokeThickness = 1;

            line.RenderTransform = rotation;

            visualChildren.Add(line);
            visualChildren.Add(rotateHandle);

            pathPreview.IsClosed          = false;
            rotatePreview                 = new Path();
            rotatePreview.Data            = new PathGeometry();
            rotatePreview.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFBBBBBB"));
            rotatePreview.StrokeThickness = 2;
            visualChildren.Add(rotatePreview);
        }
Esempio n. 7
0
        public LinkAnchorPointAdorner(UIElement adornedElement, LinkStroke linkStroke, CustomInkCanvas actualCanvas)
            : base(adornedElement)
        {
            adornedStroke = linkStroke;

            visualChildren = new VisualCollection(this);

            linkPreview                 = new Path();
            linkPreview.Stroke          = Brushes.Gray;
            linkPreview.StrokeThickness = 2;
            visualChildren.Add(linkPreview);

            this.linkStroke  = linkStroke;
            canvas           = actualCanvas;
            linkStrokeAnchor = this.linkStroke.path.Count;

            strokeBounds = linkStroke.GetStraightBounds();
            center       = this.linkStroke.GetCenter();

            anchors = new List <Thumb>();
            // Pour une ShapeStroke
            for (int i = 0; i < this.linkStroke.path.Count; i++)
            {
                anchors.Add(new Thumb());
            }
            int index = 0;

            foreach (Thumb anchor in anchors)
            {
                anchor.Cursor = Cursors.ScrollAll;
                anchor.Width  = 10;
                anchor.Height = 10;
                //anchor.Background = (Brush)new BrushConverter().ConvertFromString("#809dce");

                anchor.Background = new LinearGradientBrush((Color)ColorConverter.ConvertFromString("#FFDDDDDD"),
                                                            (Color)ColorConverter.ConvertFromString("#809dce"), 45);

                anchor.DragDelta     += new DragDeltaEventHandler(dragHandle_DragDelta);
                anchor.DragCompleted += new DragCompletedEventHandler(dragHandle_DragCompleted);
                anchor.DragStarted   += new DragStartedEventHandler(dragHandle_DragStarted);

                SetAnchorRenderTransfrom(index, linkStroke.path[index].x, linkStroke.path[index].y);

                visualChildren.Add(anchor);
                index++;
            }
        }
Esempio n. 8
0
        void Move_DragDelta(object sender, DragDeltaEventArgs e)
        {
            Vector dragVect = new Vector(e.HorizontalChange, e.VerticalChange);

            dragVect = rotation.Value.Transform(dragVect);

            if (dragVect.X != 0 || dragVect.Y != 0)
            {
                rotationPreview.CenterX = customStroke.GetCenter().X + dragVect.X;
                rotationPreview.CenterY = customStroke.GetCenter().Y + dragVect.Y;
                Rect rectangle = new Rect(customStroke.GetCustomBound().X + dragVect.X,
                                          customStroke.GetCustomBound().Y + dragVect.Y,
                                          customStroke.GetCustomBound().Width,
                                          customStroke.GetCustomBound().Height);
                if (customStroke is LinkStroke && (customStroke as LinkStroke).isAttached())
                {
                    horizontalChange = e.HorizontalChange;
                    verticalChange   = e.VerticalChange;
                    LinkStroke linkStroke = customStroke.Clone() as LinkStroke;
                    linkStroke.path = new List <Coordinates>();
                    foreach (Coordinates coord in (customStroke as LinkStroke).path)
                    {
                        linkStroke.path.Add(new Coordinates(coord.ToPoint()));
                    }

                    for (int i = 0; i < linkStroke.path.Count; i++)
                    {
                        if (i == 0 && linkStroke.isAttached() && linkStroke.from?.formId != null)
                        {
                            continue;
                        }
                        if (i == linkStroke.path.Count - 1 && linkStroke.isAttached() && linkStroke.to?.formId != null)
                        {
                            continue;
                        }
                        Coordinates coords = linkStroke.path[i];
                        coords.x += e.HorizontalChange;
                        coords.y += e.VerticalChange;
                    }
                    rectangle = linkStroke.GetStraightBounds();
                }
                generatePreview(rectangle);
            }
        }
        private static LinkStroke createLinkStroke(dynamic link)
        {
            for (int i = 0; i < link.path.Count; i++)
            {
                link.path[i].x /= 2.1;
                link.path[i].y /= 2.1;
            }

            LinkStroke linkStroke = new LinkStroke(link.ToObject <Link>(), new StylusPointCollection {
                new StylusPoint(0, 0)
            });

            linkStroke.guid = Guid.Parse((string)link.id);

            linkStroke.to   = linkStroke.to.GetForLourd();
            linkStroke.from = linkStroke.from.GetForLourd();

            return(linkStroke);
        }
        public LinkElbowAdorner(Point mousePosition, int index, UIElement adornedElement, LinkStroke linkStroke, CustomInkCanvas actualCanvas)
            : base(adornedElement)
        {
            adornedStroke = linkStroke;

            initialMousePosition = mousePosition;
            indexInPath          = index;

            this.linkStroke = linkStroke;
            canvas          = actualCanvas;
            // rotation initiale de la stroke (pour dessiner le rectangle)
            // Bug. Cheat, but the geometry, the selection Rectangle (newRect) should be the right one.. geom of the stroke?
            strokeBounds = linkStroke.GetStraightBounds();
            center       = this.linkStroke.GetCenter();

            anchors = new List <Thumb>();
            // The linkstroke must already be selected
            if (!isOnLinkStrokeEnds(initialMousePosition))
            {
                anchors.Add(new Thumb());
            }

            visualChildren = new VisualCollection(this);
            foreach (Thumb anchor in anchors)
            {
                anchor.Cursor     = Cursors.ScrollAll;
                anchor.Width      = 8;
                anchor.Height     = 8;
                anchor.Background = new LinearGradientBrush((Color)ColorConverter.ConvertFromString("#FFDDDDDD"),
                                                            (Color)ColorConverter.ConvertFromString("#FF000000"), 45);

                SetAnchorRenderTransfrom(0, initialMousePosition.X, initialMousePosition.Y);

                anchor.DragDelta     += new DragDeltaEventHandler(dragHandle_DragDelta);
                anchor.DragCompleted += new DragCompletedEventHandler(dragHandle_DragCompleted);
                anchor.DragStarted   += new DragStartedEventHandler(dragHandle_DragStarted);

                visualChildren.Add(anchor);
            }
        }
Esempio n. 11
0
        // On retire le trait du dessus de la pile de traits retirés et on le place sur la surface de dessin.
        public void Depiler(object o)
        {
            try
            {
                isStackUpToDate = false;
                CustomStroke trait = (CustomStroke)traitsRetires.Last();

                if (trait.isLinkStroke())
                {
                    LinkStroke linkStroke = trait as LinkStroke;

                    linkStroke.from.SetDefaults();
                    linkStroke.to.SetDefaults();
                }
                else
                {
                    ShapeStroke shapeStroke = trait as ShapeStroke;
                    shapeStroke.linksTo   = new List <string> {
                    };
                    shapeStroke.linksFrom = new List <string> {
                    };
                }

                traits.Add(trait);
                if (trait.isLinkStroke())
                {
                    DrawingService.CreateLink(trait as LinkStroke);
                }
                else
                {
                    DrawingService.CreateShape(trait as ShapeStroke);
                }
                traitsRetires.Remove(trait);
            }
            catch { }
        }
        public void EditLink(string linkName, int linkType, int linkStyle, string selectedColor, int linkThickness, string multiplicityFrom, string multiplicityTo)
        {
            popUpLink.IsOpen = false;
            if (surfaceDessin.GetSelectedStrokes().Count == 1 && surfaceDessin.GetSelectedStrokes()[0] != null)
            {
                LinkStroke stroke = (LinkStroke)surfaceDessin.GetSelectedStrokes()[0];
                stroke.name              = linkName;
                stroke.style.type        = linkStyle;
                stroke.style.color       = selectedColor;
                stroke.style.thickness   = linkThickness;
                stroke.from.multiplicity = multiplicityFrom;
                stroke.to.multiplicity   = multiplicityTo;

                stroke.linkType = linkType;
                stroke.addStylusPointsToLink();
                // dotted
                if (stroke.style.type == 1)
                {
                    stroke.DrawingAttributes.Color = Colors.Transparent;
                }
                else // normal line
                {
                    stroke.DrawingAttributes.Color = (Color)ColorConverter.ConvertFromString(selectedColor);
                }

                stroke.DrawingAttributes.Width  = stroke.getThickness();
                stroke.DrawingAttributes.Height = stroke.getThickness();

                StrokeCollection sc = new StrokeCollection();
                sc.Add(stroke);
                DrawingService.UpdateLinks(sc);

                surfaceDessin.RefreshChildren();
            }
            IsEnabled = true;
        }
        public static void Initialize(object o)
        {
            socket.On(Socket.EVENT_RECONNECT, () =>
            {
                if (canvasName != null)
                {
                    // Stocker le mot de passe? ADD
                    JoinCanvas(canvasName, "");
                }
            });

            #region canvas .On
            socket.On("createCanvasResponse", (data) =>
            {
                CreateCanvasResponse response = serializer.Deserialize <CreateCanvasResponse>((string)data);
                if (response.isCreated)
                {
                    canvasName = response.canvasName;
                    RefreshCanvases();
                }
                else
                {
                    Application.Current?.Dispatcher?.Invoke(new Action(() => { CanvasCreationFailed(); }), DispatcherPriority.Render);
                }
            });

            socket.On("canvasCreated", (data) =>
            {
                RefreshCanvases();
            });

            socket.On("updateCanvasPasswordResponse", (data) =>
            {
                UpdateCanvasPasswordResponse response = serializer.Deserialize <UpdateCanvasPasswordResponse>((string)data);
                if (response.isPasswordUpdated)
                {
                    RefreshCanvases();
                }
            });

            socket.On("canvasPasswordUpdated", (data) =>
            {
                LeaveCanvas();
                Application.Current?.Dispatcher?.Invoke(new Action(() => { BackToGallery(); }), DispatcherPriority.Render);
            });

            socket.On("accessCanvasResponse", (data) =>
            {
                AccessCanvasResponse response = serializer.Deserialize <AccessCanvasResponse>((string)data);
                if (response.isPasswordValid)
                {
                    canvasName = response.canvasName;
                }
                Application.Current?.Dispatcher?.Invoke(new Action(() => { JoinCanvasRoom(response); }), DispatcherPriority.Render);
            });

            socket.On("canvasSelected", (data) =>
            {
                EditGalleryData response = serializer.Deserialize <EditGalleryData>((string)data);
                if (!username.Equals((string)response.username) && response.canevasName.Equals(canvasName))
                {
                    isCanvasSizeRemotelyEditing = true;
                }
            });

            socket.On("canvasDeselected", (data) =>
            {
                EditGalleryData response = serializer.Deserialize <EditGalleryData>((string)data);
                if (!username.Equals((string)response.username) && response.canevasName.Equals(canvasName))
                {
                    isCanvasSizeRemotelyEditing = false;
                }
            });

            socket.On("canvasResized", (data) =>
            {
                ResizeCanevasData response = serializer.Deserialize <ResizeCanevasData>((string)data);
                if (username != null && !username.Equals((string)response.username))
                {
                    Application.Current?.Dispatcher?.Invoke(new Action(() => { OnResizeCanvas(response.dimensions); }), DispatcherPriority.Render);
                }
            });

            socket.On("getPublicCanvasResponse", (data) =>
            {
                PublicCanvases canvases = serializer.Deserialize <PublicCanvases>((string)data);

                ExtractCanvasesShapes(canvases.publicCanvas);

                try
                {
                    Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdatePublicCanvases(canvases); }), DispatcherPriority.Render);
                }
                catch { }
            });

            socket.On("getPrivateCanvasResponse", (data) =>
            {
                PrivateCanvases canvases = serializer.Deserialize <PrivateCanvases>((string)data);

                ExtractCanvasesShapes(canvases.privateCanvas);
                Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdatePrivateCanvases(canvases); }), DispatcherPriority.Render);
            });
            #endregion

            #region links .On
            socket.On("linkCreated", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                if (!username.Equals((string)response.username))
                {
                    LinkStroke linkStroke = createLinkStroke(response.links[0]);
                    linkStroke.owner      = response.username;
                    InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(linkStroke);
                    Application.Current?.Dispatcher?.Invoke(new Action(() => { AddStroke(eventArgs); }), DispatcherPriority.ContextIdle);
                }
            });

            socket.On("linksDeleted", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                if (!username.Equals((string)response.username))
                {
                    StrokeCollection strokes = new StrokeCollection();
                    foreach (dynamic link in response.links)
                    {
                        strokes.Add(createLinkStroke(link));
                    }
                    Application.Current?.Dispatcher?.Invoke(new Action(() => { RemoveStrokes(strokes); }), DispatcherPriority.ContextIdle);
                }
            });

            socket.On("linksUpdated", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                if (!username.Equals((string)response.username))
                {
                    foreach (dynamic link in response.links)
                    {
                        InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(createLinkStroke(link));
                        Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateStroke(eventArgs); }), DispatcherPriority.Render);
                    }
                }
            });

            socket.On("linksSelected", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                if (!username.Equals((string)response.username))
                {
                    StrokeCollection strokes = new StrokeCollection();
                    foreach (dynamic link in response.links)
                    {
                        LinkStroke linkStroke = createLinkStroke(link);
                        strokes.Add(linkStroke);
                        if (!remoteSelectedStrokes.Contains(linkStroke.guid.ToString()))
                        {
                            remoteSelectedStrokes.Add(linkStroke.guid.ToString());
                        }
                        Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateSelection(); }), DispatcherPriority.Render);
                    }
                }
            });

            socket.On("linksDeselected", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                if (!username.Equals((string)response.username))
                {
                    StrokeCollection strokes = new StrokeCollection();
                    foreach (dynamic link in response.links)
                    {
                        LinkStroke linkStroke = createLinkStroke(link);
                        strokes.Add(linkStroke);
                        if (remoteSelectedStrokes.Contains(linkStroke.guid.ToString()))
                        {
                            remoteSelectedStrokes.Remove(linkStroke.guid.ToString());
                        }
                        Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateDeselection(); }), DispatcherPriority.Render);
                    }
                }
            });
            #endregion

            #region forms .On
            socket.On("formCreated", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                //Console.WriteLine("FORM CREATED: \n" + "position: " + response.forms[0].shapeStyle.coordinates.x + ", "
                //    + response.forms[0].shapeStyle.coordinates.y + "/n" + "size: " + response.forms[0].shapeStyle.width + ", "
                //    + response.forms[0].shapeStyle.height);
                if (!username.Equals((string)response.username))
                {
                    CustomStroke customStroke = createShapeStroke(response.forms[0]);
                    InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(customStroke);
                    Application.Current?.Dispatcher?.Invoke(new Action(() => { AddStroke(eventArgs); }), DispatcherPriority.ContextIdle);
                }
            });

            socket.On("formsDeleted", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                if (!username.Equals((string)response.username))
                {
                    StrokeCollection strokes = new StrokeCollection();
                    foreach (dynamic shape in response.forms)
                    {
                        ShapeStroke shapeStroke = createShapeStroke(shape);
                        if (remoteSelectedStrokes.Contains(shapeStroke.guid.ToString()))
                        {
                            remoteSelectedStrokes.Remove(shapeStroke.guid.ToString());
                        }
                        strokes.Add(shapeStroke);
                    }
                    Application.Current?.Dispatcher?.Invoke(new Action(() => { RemoveStrokes(strokes); }), DispatcherPriority.ContextIdle);
                }
            });

            socket.On("formsUpdated", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                if (!username.Equals((string)response.username))
                {
                    foreach (dynamic shape in response.forms)
                    {
                        InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(createShapeStroke(shape));
                        Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateStroke(eventArgs); }), DispatcherPriority.Render);
                    }
                }
            });

            socket.On("formsSelected", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                if (!username.Equals((string)response.username))
                {
                    StrokeCollection strokes = new StrokeCollection();
                    foreach (dynamic shape in response.forms)
                    {
                        ShapeStroke stroke = createShapeStroke(shape);
                        strokes.Add(stroke);
                        if (!remoteSelectedStrokes.Contains(stroke.guid.ToString()))
                        {
                            remoteSelectedStrokes.Add(stroke.guid.ToString());
                        }
                        Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateSelection(); }), DispatcherPriority.Render);
                    }
                }
            });

            socket.On("formsDeselected", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                if (!username.Equals((string)response.username))
                {
                    StrokeCollection strokes = new StrokeCollection();
                    foreach (dynamic shape in response.forms)
                    {
                        ShapeStroke stroke = createShapeStroke(shape);
                        strokes.Add(stroke);
                        if (remoteSelectedStrokes.Contains(stroke.guid.ToString()))
                        {
                            remoteSelectedStrokes.Remove(stroke.guid.ToString());
                        }
                        Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateDeselection(); }), DispatcherPriority.Render);
                    }
                }
            });
            #endregion

            socket.On("selectedForms", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                foreach (string id in response.selectedForms)
                {
                    if (!remoteSelectedStrokes.Contains(id))
                    {
                        remoteSelectedStrokes.Add(id);
                    }
                }
                Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateDeselection(); }), DispatcherPriority.Render);
            });

            socket.On("selectedLinks", (data) =>
            {
                dynamic response = JObject.Parse((string)data);
                foreach (string id in response.selectedLinks)
                {
                    if (!remoteSelectedStrokes.Contains(id))
                    {
                        remoteSelectedStrokes.Add(id);
                    }
                }
                Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateDeselection(); }), DispatcherPriority.Render);
            });

            socket.On("canvasSaved", (data) =>
            {
                EditCanevasData response = serializer.Deserialize <EditCanevasData>((string)data);
                RefreshCanvases();
                saving = false;
            });

            socket.On("getCanvasResponse", (data) =>
            {
                Templates.Canvas canvas = serializer.Deserialize <Templates.Canvas>((string)data);
                canvasName    = canvas.name;
                currentCanvas = canvas;
                Application.Current?.Dispatcher?.Invoke(new Action(() => { OnResizeCanvas(canvas.dimensions); }), DispatcherPriority.ContextIdle);
                localSelectedStrokes             = new List <string>();
                localAddedStrokes                = new List <string>();
                EditGalleryData editGallerysData = new EditGalleryData(username, canvasName, "");

                foreach (Link link in canvas.links)
                {
                    LinkStroke linkStroke = LinkStrokeFromLink(link);
                    InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(linkStroke);
                    Application.Current?.Dispatcher?.Invoke(new Action(() => { AddStroke(eventArgs); }), DispatcherPriority.ContextIdle);
                }

                List <BasicShape> basicShapes = ExtractShapesFromCanvas(canvas);
                foreach (BasicShape shape in basicShapes)
                {
                    ShapeStroke shapeStroke = ShapeStrokeFromShape(shape);
                    InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(shapeStroke);
                    Application.Current?.Dispatcher?.Invoke(new Action(() => { AddStroke(eventArgs); }), DispatcherPriority.ContextIdle);
                }

                socket.Emit("getSelectedForms", serializer.Serialize(editGallerysData));
                socket.Emit("getSelectedLinks", serializer.Serialize(editGallerysData));

                Application.Current?.Dispatcher?.Invoke(new Action(() => { RefreshChildren(); }), DispatcherPriority.ContextIdle);
            });

            socket.On("canvasReinitialized", (data) =>
            {
                localAddedStrokes     = new List <string>();
                localSelectedStrokes  = new List <string>();
                remoteSelectedStrokes = new List <string>();
                Application.Current?.Dispatcher?.Invoke(new Action(() => { RemoteReset(); }), DispatcherPriority.Render);
            });

            socket.On("getCanvasLogHistoryResponse", (data) =>
            {
                HistoryData[] historyData = serializer.Deserialize <HistoryData[]>((string)data);
                History history           = new History(historyData);

                Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateHistory(history); }), DispatcherPriority.Render);
            });

            socket.On("disconnect", (data) =>
            {
                // Application.Current?.Dispatcher?.Invoke(new Action(() => { BackToGallery(); }), DispatcherPriority.ContextIdle);
            });

            RefreshCanvases();
        }
Esempio n. 14
0
        public void setParameters(LinkStroke linkStroke, CustomInkCanvas canvas)
        {
            var parent = Parent;

            while (!(parent is WindowDrawing))
            {
                parent = LogicalTreeHelper.GetParent(parent);
            }

            windowDrawing = (WindowDrawing)parent;
            if (windowDrawing != null)
            {
                LinkStroke stroke = windowDrawing.surfaceDessin.GetSelectedStrokes()[0] as LinkStroke;
                _label            = stroke.name;
                _selectedColor    = stroke.style.color;
                _multiplicityFrom = stroke.from.multiplicity;
                _multiplicityTo   = stroke.to.multiplicity;

                switch (stroke.linkType)
                {
                case (int)LinkTypes.LINE:
                    _linkType = "Line";
                    break;

                case (int)LinkTypes.HERITAGE:
                    _linkType = "Heritage";
                    break;

                case (int)LinkTypes.ONE_WAY_ASSOCIATION:
                    _linkType = "One way association";
                    break;

                case (int)LinkTypes.TWO_WAY_ASSOCIATION:
                    _linkType = "Two way association";
                    break;

                case (int)LinkTypes.COMPOSITION:
                    _linkType = "Composition";
                    break;

                case (int)LinkTypes.AGGREGATION:
                    _linkType = "Aggregation";
                    break;

                default:
                    _linkType = "Line";
                    break;
                }

                switch (stroke.style.type)
                {
                case (int)LinkStyles.FULL:
                    _linkStyle = "Full";
                    break;

                case (int)LinkStyles.DOTTED:
                    _linkStyle = "Dotted";
                    break;

                default:
                    _linkStyle = "Full";
                    break;
                }

                switch (stroke.style.thickness)
                {
                case (int)LinkThicknesses.THIN:
                    _linkThickness = "Thin";
                    break;

                case (int)LinkThicknesses.NORMAL:
                    _linkThickness = "Normal";
                    break;

                case (int)LinkThicknesses.THICK:
                    _linkThickness = "Thick";
                    break;

                default:
                    _linkThickness = "Thin";
                    break;
                }
            }

            if (isBetweenTwoClasses(linkStroke, canvas))
            {
                _linkTypesList = new List <string> {
                    "Line", "One way association", "Two way association", "Heritage", "Aggregation", "Composition"
                };
            }
            else if (isLinkedToOneClass(linkStroke, canvas))
            {
                _linkTypesList = new List <string> {
                    "Line", "One way association", "Two way association"
                };
            }
            else if (isLinkedToProcess(linkStroke, canvas))
            {
                _linkTypesList = new List <string> {
                    "One way association"
                };
            }
            else
            {
                _linkTypesList = new List <string> {
                    "Line", "One way association", "Two way association"
                };
            }
            _linkStylesList = new List <string> {
                "Full", "Dotted"
            };
            _linkThicknessesList = new List <string> {
                "Thin", "Normal", "Thick"
            };

            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Label"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LinkStyle"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LinkType"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SelectedColor"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LinkThickness"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MultiplicityFrom"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MultiplicityTo"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LinkStylesList"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LinkTypesList"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LinkThicknessesList"));
        }