private static ShapeStroke createShapeStroke(dynamic shape)
        {
            StylusPointCollection points = new StylusPointCollection {
                new StylusPoint((double)shape.shapeStyle.coordinates.x / 2.1, (double)shape.shapeStyle.coordinates.y / 2.1)
            };

            shape.shapeStyle.height        = (double)shape.shapeStyle.height / 2.1;
            shape.shapeStyle.width         = (double)shape.shapeStyle.width / 2.1;
            shape.shapeStyle.coordinates.x = (double)shape.shapeStyle.coordinates.x / 2.1;
            shape.shapeStyle.coordinates.y = (double)shape.shapeStyle.coordinates.y / 2.1;

            ShapeStroke shapeStroke;
            StrokeTypes type = (StrokeTypes)shape.type;

            switch (type)
            {
            case StrokeTypes.CLASS_SHAPE:
                shapeStroke = new ClassStroke(shape.ToObject <ClassShape>(), points);
                break;

            case StrokeTypes.ARTIFACT:
                shapeStroke = new ArtifactStroke(shape.ToObject <BasicShape>(), points);
                break;

            case StrokeTypes.ACTIVITY:
                shapeStroke = new ActivityStroke(shape.ToObject <BasicShape>(), points);
                break;

            case StrokeTypes.ROLE:
                shapeStroke = new ActorStroke(shape.ToObject <BasicShape>(), points);
                break;

            case StrokeTypes.COMMENT:
                shapeStroke = new CommentStroke(shape.ToObject <BasicShape>(), points);
                break;

            case StrokeTypes.PHASE:
                shapeStroke = new PhaseStroke(shape.ToObject <BasicShape>(), points);
                break;

            case StrokeTypes.FLOATINGTEXT:
                shapeStroke = new FloatingTextStroke(shape.ToObject <BasicShape>(), points);
                break;

            default:
                shapeStroke = new ClassStroke(shape.ToObject <ClassShape>(), points);
                break;
            }
            shapeStroke.guid = Guid.Parse((string)shape.id);

            return(shapeStroke);
        }
        private static ShapeStroke ShapeStrokeFromShape(BasicShape shape)
        {
            StrokeTypes type = (StrokeTypes)shape.type;
            ShapeStroke shapeStroke;

            StylusPointCollection points = new StylusPointCollection();
            StylusPoint           point  = new StylusPoint(shape.shapeStyle.coordinates.x, shape.shapeStyle.coordinates.y);

            points.Add(point);

            switch (type)
            {
            case StrokeTypes.CLASS_SHAPE:
                shapeStroke = new ClassStroke((ClassShape)shape, points);
                break;

            case StrokeTypes.ARTIFACT:
                shapeStroke = new ArtifactStroke(shape, points);
                break;

            case StrokeTypes.ACTIVITY:
                shapeStroke = new ActivityStroke(shape, points);
                break;

            case StrokeTypes.ROLE:
                shapeStroke = new ActorStroke(shape, points);
                break;

            case StrokeTypes.COMMENT:
                shapeStroke = new CommentStroke(shape, points);
                break;

            case StrokeTypes.PHASE:
                shapeStroke = new PhaseStroke(shape, points);
                break;

            case StrokeTypes.FLOATINGTEXT:
                shapeStroke = new FloatingTextStroke(shape, points);
                break;

            default:
                shapeStroke = new ActorStroke(shape, points);
                break;
            }

            return(shapeStroke);
        }
        public void DrawClass(string name, List <string> properties, List <string> methods)
        {
            StylusPointCollection stylusPoints = new StylusPointCollection();

            stylusPoints.Add(new StylusPoint(10, 10));
            ClassStroke classStroke = new ClassStroke(stylusPoints);

            classStroke.name       = name;
            classStroke.attributes = properties;
            classStroke.methods    = methods;

            InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(classStroke);

            DrawingService.AddClassFromCode(eventArgs);

            DrawingService.CreateShape(classStroke);
        }
        public void Rename(string className, string attributes, string methods, Color borderColor, Color fillColor, int lineStyle)
        {
            popUpClass.IsOpen = false;
            if (surfaceDessin.GetSelectedStrokes().Count == 1 && surfaceDessin.GetSelectedStrokes()[0] != null)
            {
                ClassStroke stroke = (ClassStroke)surfaceDessin.GetSelectedStrokes()[0];
                stroke.name = className;
                stroke.shapeStyle.borderColor     = borderColor.ToString();
                stroke.shapeStyle.backgroundColor = fillColor.ToString();
                stroke.shapeStyle.borderStyle     = lineStyle;

                stroke.attributes = new List <string>();
                string[] lines = attributes.Split(
                    new[] { Environment.NewLine },
                    StringSplitOptions.None
                    );
                foreach (string line in lines)
                {
                    stroke.attributes.Add(line);
                }

                stroke.methods = new List <string>();
                lines          = methods.Split(
                    new[] { Environment.NewLine },
                    StringSplitOptions.None
                    );
                foreach (string line in lines)
                {
                    stroke.methods.Add(line);
                }

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

                surfaceDessin.RefreshChildren();
                surfaceDessin.RefreshSelectedShape(stroke);
            }
            IsEnabled = true;
        }
        public void setParameters(ClassStroke stroke)
        {
            _className   = stroke.name;
            _attributes  = ListToString(stroke.attributes);
            _methods     = ListToString(stroke.methods);
            _borderColor = (Color)ColorConverter.ConvertFromString(stroke.shapeStyle.borderColor);
            _fillColor   = (Color)ColorConverter.ConvertFromString(stroke.shapeStyle.backgroundColor);
            switch ((stroke as ShapeStroke).shapeStyle.borderStyle)
            {
            case (int)LineStyles.FULL:
                _lineStyle = "Full";
                break;

            case (int)LineStyles.DASHED:
                _lineStyle = "Dashed";
                break;

            case (int)LineStyles.DOTTED:
                _lineStyle = "Dotted";
                break;

            default:
                _lineStyle = "Full";
                break;
            }
            _lineStylesList = new List <string> {
                "Full", "Dashed"
            };
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ClassName"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Attributes"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Methods"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("BorderColor"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("FillColor"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LineStyle"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LineStylesList"));
        }
Example #6
0
        private static void LoadForm(dynamic shape, CustomStrokeCollection strokes)
        {
            StylusPoint topLeft = new StylusPoint((double)(shape["ShapeInfo"]["Center"]["X"] - shape["ShapeInfo"]["Width"] / 2),
                                                  (double)(shape["ShapeInfo"]["Center"]["Y"] - shape["ShapeInfo"]["Height"] / 2));
            StylusPoint bottomRight = new StylusPoint((double)(shape["ShapeInfo"]["Center"]["X"] + shape["ShapeInfo"]["Width"] / 2),
                                                      (double)(shape["ShapeInfo"]["Center"]["Y"] + shape["ShapeInfo"]["Height"] / 2));

            ShapeStroke loadedShape;

            if (shape["ShapeType"] == StrokeType.RECTANGLE.ToString())
            {
                loadedShape = new BaseRectangleStroke(new StylusPointCollection()
                {
                    topLeft, bottomRight
                }, strokes);
            }
            else if (shape["ShapeType"] == StrokeType.ELLIPSE.ToString())
            {
                loadedShape = new BaseElipseStroke(new StylusPointCollection()
                {
                    topLeft, bottomRight
                }, strokes);
            }
            else if (shape["ShapeType"] == StrokeType.TRIANGLE.ToString())
            {
                loadedShape = new BaseTrangleStroke(new StylusPointCollection()
                {
                    topLeft, bottomRight
                }, strokes);
            }
            else if (shape["ShapeType"] == StrokeType.ACTOR.ToString())
            {
                loadedShape = new PersonStroke(new StylusPointCollection()
                {
                    topLeft, bottomRight
                }, strokes);
                ((PersonStroke)loadedShape).Name = "";
                for (int j = 0; j < shape["ShapeInfo"]["Content"].Count; j++)
                {
                    ((PersonStroke)loadedShape).Name += shape["ShapeInfo"]["Content"][j] + " ";
                }
            }
            else if (shape["ShapeType"] == StrokeType.CLASS.ToString())
            {
                loadedShape = new ClassStroke(new StylusPointCollection()
                {
                    topLeft, bottomRight
                }, strokes);
                ((ClassStroke)loadedShape).textContent = new List <string>();
                for (int j = 0; j < shape["ShapeInfo"]["Content"].Count; j++)
                {
                    ((ClassStroke)loadedShape).textContent.Add((string)shape["ShapeInfo"]["Content"][j]);
                }
            }
            else
            {
                loadedShape = new UseCaseStroke(new StylusPointCollection()
                {
                    topLeft, bottomRight
                }, strokes);
                ((UseCaseStroke)loadedShape).textContent = new List <string>();
                for (int j = 0; j < shape["ShapeInfo"]["Content"].Count; j++)
                {
                    ((UseCaseStroke)loadedShape).textContent.Add((string)shape["ShapeInfo"]["Content"][j]);
                }
            }
            loadedShape.Id = shape["Id"];
            loadedShape.DrawingAttributes.Color = (Color)ColorConverter.ConvertFromString((string)shape["ShapeInfo"]["Color"]);
            strokes.Add(loadedShape);
        }