Esempio n. 1
0
        public static DrawingTool CreateFromFile(string file)
        {
            DrawingTool result = null;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments = true;
            settings.IgnoreProcessingInstructions = true;
            settings.IgnoreWhitespace             = true;
            settings.CloseInput = true;

            using (XmlReader r = XmlReader.Create(file, settings))
            {
                try
                {
                    result = ParseTool(r);
                }
                catch (Exception)
                {
                    log.Error("An error happened during the parsing of a generic drawing tool file");
                }
            }

            return(result);
        }
        private static void ImportExternalTools()
        {
            if (!Directory.Exists(Software.StandardToolsDirectory))
            {
                return;
            }

            foreach (string file in Directory.GetFiles(Software.StandardToolsDirectory))
            {
                AbstractDrawingTool tool = DrawingTool.CreateFromFile(file);
                if (tool != null && !tools.ContainsKey(tool.Name))
                {
                    tools.Add(tool.Name, tool);
                }
            }
        }
Esempio n. 3
0
        private static DrawingTool ParseTool(XmlReader r)
        {
            r.MoveToContent();
            r.ReadStartElement();

            string version = r.ReadElementContentAsString("FormatVersion", "");

            if (version != "1.0")
            {
                log.ErrorFormat("Unsupported format version ({0}) for tool description.", version);
                return(null);
            }

            Guid         id          = Guid.Empty;
            string       name        = "";
            string       displayName = "";
            Bitmap       icon        = null;
            Type         drawingType = null;
            bool         attached    = true;
            bool         keepToolAfterDrawingCreation = false;
            bool         keepToolAfterFrameChange     = false;
            DrawingStyle style = null;

            while (r.NodeType == XmlNodeType.Element)
            {
                switch (r.Name)
                {
                case "Id":
                    id = new Guid(r.ReadElementContentAsString());
                    break;

                case "Name":
                    name = r.ReadElementContentAsString();
                    break;

                case "DisplayName":
                    displayName = r.ReadElementContentAsString();
                    break;

                case "Icon":
                    string iconReference = r.ReadElementContentAsString();
                    if (!string.IsNullOrEmpty(iconReference))
                    {
                        icon = Properties.Drawings.ResourceManager.GetObject(iconReference) as Bitmap;
                    }
                    break;

                case "DrawingClass":
                    string drawingClass = r.ReadElementContentAsString();
                    drawingType = FindType(drawingClass);
                    break;

                case "Attached":
                    attached = XmlHelper.ParseBoolean(r.ReadElementContentAsString());
                    break;

                case "KeepToolAfterDrawingCreation":
                    keepToolAfterDrawingCreation = XmlHelper.ParseBoolean(r.ReadElementContentAsString());
                    break;

                case "KeepToolAfterFrameChange":
                    keepToolAfterFrameChange = XmlHelper.ParseBoolean(r.ReadElementContentAsString());
                    break;

                case "DefaultStyle":
                    style = new DrawingStyle(r);
                    break;

                default:
                    string unparsed = r.ReadOuterXml();
                    log.DebugFormat("Unparsed content in Drawing Tool XML: {0}", unparsed);
                    break;
                }
            }

            r.ReadEndElement();

            if (icon == null)
            {
                icon = Properties.Drawings.generic_posture;
            }

            DrawingTool tool = new DrawingTool(id, name, displayName, icon, drawingType, attached, keepToolAfterDrawingCreation, keepToolAfterFrameChange, style);

            return(tool);
        }