Пример #1
0
        private static string EditAnnotationText(AnnotationData annotation)
        {
            var inputBox = new AnnotationInputBox { InputText = annotation.Text };
            inputBox.ShowDialog();

            if (string.IsNullOrWhiteSpace(inputBox.InputText))
            {
                return null;
            }

            return inputBox.InputText;
        }
Пример #2
0
        /// <summary>
        /// Loads the diagram data from file after the subject has already been set by <see cref="AssignDiagramData"/>.
        /// At this stage the diagram has already been loaded and is displayed on screen.  
        /// This method ensures all diagram elements have been positioned where the file specifies their co-ordinates.
        /// Also will provide feedback on any mismatches, ie the type has changed and there are more or less associations.
        /// </summary>
        /// <param name="deserializedDataFile">The deserialised data file.</param>
        public void LoadDiagramDataFromFile(object deserializedDataFile)
        {
            var data = deserializedDataFile as TypeVisualiserLayoutFile;
            if (data == null)
            {
                throw new InvalidOperationException("Code Error: Attempt to load data from a type which is not an instance of Type Visualiser Layout File.");
            }

            var typesNoLongerInDiagram = new List<VisualisableTypeData>();
            foreach (TypeLayoutData layoutData in data.CanvasLayout.Types)
            {
                // Deal with annotations first - these have not been loaded by setting the subject.
                if (layoutData.ContentType == typeof(AnnotationData).FullName)
                {
                    var annotation = new AnnotationData { Id = layoutData.Id, Text = layoutData.Data, };
                    var annotationElement = new DiagramElement(DiagramId, annotation) { Show = layoutData.Visible, TopLeft = layoutData.TopLeft };
                    DiagramElements.Add(annotationElement);
                    continue;
                }

                DiagramElement element = DiagramElements.FirstOrDefault(x => x.DiagramContent.Id == layoutData.Id);
                if (element == null)
                {
                    VisualisableTypeData type = FindTypeInFile(data, layoutData.Id);
                    if (type == null)
                    {
                        throw new InvalidOperationException("Code error: there is a layout data element without a matching association. " + layoutData.Id);
                    }

                    typesNoLongerInDiagram.Add(type);
                    continue;
                }

                element.TopLeft = layoutData.TopLeft;
                element.Show = layoutData.Visible;
            }

            RaiseExpandCanvasRequested();

            if (typesNoLongerInDiagram.Any())
            {
                UserPrompt.Show(Resources.ViewportController_Error_in_diagram_file,
                                Resources.ViewportController_Some_types_are_not_in_assembly_anymore + string.Join(", ", typesNoLongerInDiagram.Select(x => x.Name)));
            }
        }
Пример #3
0
        public DiagramElement DeleteAnnotation(AnnotationData annotation)
        {
            DiagramElement found = DiagramElements.FirstOrDefault(x => x.DiagramContent is AnnotationData && ((AnnotationData)x.DiagramContent).Id == annotation.Id);

            if (found != null)
            {
                DiagramElements.Remove(found);
                return found;
            }

            return null;
        }
Пример #4
0
        public void EditAnnotation(AnnotationData annotation)
        {
            if (annotation == null)
            {
                throw new ArgumentNullResourceException("annotation", Resources.General_Given_Parameter_Cannot_Be_Null);
            }

            annotation.Text = EditAnnotationText(annotation);
            if (string.IsNullOrWhiteSpace(annotation.Text))
            {
                DeleteAnnotation(annotation);
            }
        }
Пример #5
0
        public void AddAnnotation(Point where, AnnotationData annotation = null)
        {
            if (where == default(Point))
            {
                return;
            }

            if (annotation == null)
            {
                annotation = new AnnotationData();
            }

            annotation.Text = EditAnnotationText(annotation);
            if (string.IsNullOrWhiteSpace(annotation.Text))
            {
                return;
            }

            var diagramElement = new DiagramElement(DiagramId, annotation) { TopLeft = where };
            DiagramElements.Add(diagramElement);
        }