Example #1
0
        private ModelingToolboxItem CreateToolboxItem(Store store, GadgeteerPart moduleDefinition, string description,
                                                      string tabName, ElementGroupPrototype prototype, string itemId)
        {
            //Add a filter attribute for each of the .NETMF versions supported by this module. The DocData adds a corresponding
            //filter depending on the version of the project
            var filters = moduleDefinition.SupportedMicroframeworkVersions.Select(v => new ToolboxItemFilterAttribute(GadgeteerDSLToolboxHelperBase.ToolboxFilterString + v,
                                                                                                                      ToolboxItemFilterType.Require)).ToArray();

            var result = new ModelingToolboxItem(
                itemId,                                                // Unique identifier (non-localized) for the toolbox item.
                2,                                                     // Position relative to other items in the same toolbox tab.
                moduleDefinition.Name,
                moduleToolboxIcon,                                     // Image displayed next to the toolbox item.
                "Microsoft.Gadgeteer.Designer.GadgeteerDSLToolboxTab", // Unique identifier (non-localized) for the toolbox item tab.
                tabName,                                               // Localized display name for the toolbox tab.
                moduleDefinition.Name,                                 // F1 help keyword for the toolbox item.
                description,                                           // Localized tooltip text for the toolbox item.
                prototype,
                filters
                );

            //Imporant to make this transient. Otherwise the toolbox items remain even if modules are uninstalled
            result.IsTransient = true;

            return(result);
        }
        /// <summary>
        /// Create sockets based on the associated definition
        /// </summary>
        internal void CreateSockets()
        {
            GadgeteerPart part = this.GadgeteerPartDefinition;

            if (part == null)
            {
                return;
            }

            var socketsCopy = Sockets.ToArray();

            foreach (Socket s in socketsCopy)
            {
                s.Delete();
            }

            Sockets.Clear();

            var providedSockets = part.ProvidedSockets;

            if (providedSockets.Count == 0)
            {
                return;
            }

            foreach (var providedSocket in providedSockets)
            {
                var s = new Socket(this.Store)
                {
                    Label = providedSocket.Label
                };
                this.Sockets.Add(s);
            }
        }
Example #3
0
        private static string GenerateName(GadgeteerPart part)
        {
            if (string.IsNullOrWhiteSpace(part.Name))
            {
                return(Resources.PackageUI.DefinitionNoName);
            }

            return(part.Name);
        }
Example #4
0
        private static string GenerateDescription(GadgeteerPart part, string error)
        {
            if (!string.IsNullOrWhiteSpace(error))
            {
                return(error + Environment.NewLine + Environment.NewLine + part.Description);
            }

            return(part.Description);
        }
Example #5
0
        private void Initialize(GadgeteerPart part, Store store)
        {
            IsTransient   = true;
            GadgeteerPart = part;

            if (!part.HasErrors)
            {
                MinimumGadgeteerCoreVersion = System.Version.Parse(part.MinimumGadgeteerCoreVersion);
            }
        }
Example #6
0
        private IEnumerable <Assembly> GetAssemblyDefinitions(GadgeteerHardware hw)
        {
            GadgeteerPart definition = hw.GadgeteerPartDefinition;

            if (definition == null || definition.Assemblies == null)
            {
                Log.WriteError("Could not find definition for module {0}", hw);
                return(new Assembly[0]);
            }

            return(definition.Assemblies.Where(assembly => assembly.MFVersion == ProjectMFVersion));
        }
Example #7
0
        public static GadgeteerToolboxItem CreateFor(GadgeteerPart part, Store store, string mfVersion, Version gVersion, int position = 2)
        {
            Bitmap icon         = ToolboxIcon;
            string errorMessage = null;

            if (part.HasErrors)
            {
                errorMessage = string.Format(Resources.PackageUI.DefinitionError, string.Join(Environment.NewLine, part.GetErrors()));

                icon = ToolboxIconError;
            }
            else
            {
                if (gVersion != null && gVersion < System.Version.Parse(part.MinimumGadgeteerCoreVersion))
                {
                    // do not block the designer if Gadgeteer version cannot be found (e.g. referenced as project)
                    // if (gVersion == null)
                    //     errorMessage = string.Format(Resources.PackageUI.WarningNoG, part.MinimumGadgeteerCoreVersion);
                    // else
                    errorMessage = string.Format(Resources.PackageUI.WarningGVersion, part.MinimumGadgeteerCoreVersion, gVersion);

                    icon = ToolboxIconWarning;
                }

                else if (!part.SupportedMicroframeworkVersions.Contains(mfVersion))
                {
                    errorMessage = string.Format(Resources.PackageUI.WarningMFVersion, string.Join(", ", part.SupportedMicroframeworkVersions), mfVersion);

                    icon = ToolboxIconWarning;
                }
            }

            part.ErrorMessage = errorMessage;

            ModuleDefinition module = part as ModuleDefinition;

            if (module != null)
            {
                return(new GadgeteerToolboxItem(module, store, icon, position, errorMessage));
            }

            MainboardDefinition mainboard = part as MainboardDefinition;

            if (mainboard != null)
            {
                return(new GadgeteerToolboxItem(mainboard, store, icon, position, errorMessage));
            }

            throw new NotSupportedException();
        }
        private static void SetFullPaths(string xmlDirectory, GadgeteerPart md)
        {
            if (!string.IsNullOrWhiteSpace(md.Image))
            {
                md.Image = Path.Combine(xmlDirectory, md.Image);
            }

            //Prefix the help url with the path name only if it is not empty and it's not an absolute url
            Uri uri;

            if (!string.IsNullOrWhiteSpace(md.HelpUrl) && !Uri.TryCreate(md.HelpUrl, UriKind.Absolute, out uri))
            {
                md.HelpUrl = Path.Combine(xmlDirectory, md.HelpUrl);
            }
        }
        /// <summary>
        /// Serialize the part definition to save it into the module. This allows us to correctly display diagrams on systems with certain
        /// modules/mainboards missing
        /// </summary>
        internal void CacheDefinition()
        {
            GadgeteerPart part = GadgeteerPartDefinition;

            if (part == null)
            {
                return;
            }

            using (var sw = new StringWriter())
            {
                CachedDefinitionSerializer.Serialize(sw, part);
                this.CachedDefinition = sw.ToString();
            }
        }
        internal Bitmap GetImage()
        {
            if (!imageExists)
            {
                return(null);
            }

            //This can happen if the mouse is over the shape as it is loading. In this case the hit test code tries to figure out
            //the shape bounds, which causes a call to the IconImageField.GetDisplayImage. All of this happens before the first OnPaintShape()
            //so we don't have the dpi yet
            if (dpiX == 0 || dpiY == 0)
            {
                return(null);
            }

            if (image == null)
            {
                var hardware = ModelElement as GadgeteerHardware;
                if (hardware != null)
                {
                    GadgeteerPart part = hardware.GadgeteerPartDefinition;
                    if (part != null)
                    {
                        if (imageExists = IsValidImage(part.Image))
                        {
                            using (var bmp = new Bitmap(part.Image))
                            {
                                try
                                {
                                    image = new Bitmap(bmp, (int)(ToInches(part.BoardWidth) * dpiX), (int)(ToInches(part.BoardHeight) * dpiY));
                                }
                                catch (ArgumentException e)
                                {
                                    //log it and eat it, in case we missed something. otherwise this can crash the designer
                                    Log.WriteError(e);
                                }
                            }
                        }
                    }
                }
            }

            return(image);
        }
 private static bool IsValidPart(GadgeteerPart part)
 {
     return(!string.IsNullOrWhiteSpace(part.Image) &&
            part.Assemblies.Count > 0 &&
            !part.Assemblies.All(asm => string.IsNullOrWhiteSpace(asm.Name) || string.IsNullOrWhiteSpace(asm.MFVersion)));
 }