Ejemplo n.º 1
0
        private string DeterminePartType(PartMetadata metadata, ICollection <PartType> partTypes)
        {
            var possiblePartTypes = GetMatchingPartTypes(metadata, partTypes);

            return(possiblePartTypes
                   .OrderByDescending(x => x.Value)
                   .Select(x => x.Key?.Name)
                   .FirstOrDefault());
        }
Ejemplo n.º 2
0
        private ICollection <string> DetermineKeywords(PartMetadata metadata, ICollection <PartType> partTypes)
        {
            // part type
            // important parts from description
            // alternate series numbers etc
            var keywords          = new List <string>();
            var possiblePartTypes = GetMatchingPartTypes(metadata, partTypes);

            foreach (var possiblePartType in possiblePartTypes)
            {
                if (!keywords.Contains(possiblePartType.Key.Name, StringComparer.InvariantCultureIgnoreCase))
                {
                    keywords.Add(possiblePartType.Key.Name.ToLower());
                }
            }

            if (!keywords.Contains(metadata.ManufacturerPartNumber, StringComparer.InvariantCultureIgnoreCase))
            {
                keywords.Add(metadata.ManufacturerPartNumber.ToLower());
            }
            var desc = metadata.Description.ToLower().Split(new string[] { " ", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            // add the first 4 words of desc
            var wordCount    = 0;
            var ignoredWords = new string[] { "and", "the", "in", "or", "in", "a", };

            foreach (var word in desc)
            {
                if (!ignoredWords.Contains(word, StringComparer.InvariantCultureIgnoreCase) && !keywords.Contains(word, StringComparer.InvariantCultureIgnoreCase))
                {
                    keywords.Add(word.ToLower());
                    wordCount++;
                }
                if (wordCount >= 4)
                {
                    break;
                }
            }
            var basePart = metadata.Integrations?.Digikey?.Parameters.Where(x => x.Parameter.Equals("Base Part Number")).Select(x => x.Value).FirstOrDefault();

            if (basePart != null && !keywords.Contains(basePart, StringComparer.InvariantCultureIgnoreCase))
            {
                keywords.Add(basePart.ToLower());
            }
            var mountingType = metadata.Integrations?.Digikey?.Parameters.Where(x => x.Parameter.Equals("Mounting Type")).Select(x => x.Value).FirstOrDefault();

            if (mountingType != null && !keywords.Contains(mountingType, StringComparer.InvariantCultureIgnoreCase))
            {
                keywords.Add(mountingType.ToLower());
            }

            return(keywords.Distinct().ToList());
        }
Ejemplo n.º 3
0
        private IDictionary <PartType, int> GetMatchingPartTypes(PartMetadata metadata, ICollection <PartType> partTypes)
        {
            // load all part types
            var possiblePartTypes = new Dictionary <PartType, int>();

            foreach (var partType in partTypes)
            {
                if (string.IsNullOrEmpty(partType.Name))
                {
                    continue;
                }
                var addPart = false;
                if (metadata.Description?.IndexOf(partType.Name, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    addPart = true;
                }
                if (metadata.DetailedDescription?.IndexOf(partType.Name, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    addPart = true;
                }
                if (metadata.PartNumber?.IndexOf(partType.Name, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    addPart = true;
                }
                if (metadata.DatasheetUrl?.IndexOf(partType.Name, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    addPart = true;
                }
                if (addPart)
                {
                    if (possiblePartTypes.ContainsKey(partType))
                    {
                        possiblePartTypes[partType]++;
                    }
                    else
                    {
                        possiblePartTypes.Add(partType, 1);
                    }
                }
            }
            return(possiblePartTypes);
        }
Ejemplo n.º 4
0
        private bool CollidesPredictive(ProceduralRoom room, bool testMounts, bool testOptional)
        {
            // Buildable?
            if (m_construction.Intersects(room, testOptional))
            {
                return(true);
            }
            if (!testMounts)
            {
                return(false);
            }

            m_invokers.Clear();
            // Reject if this will block another mount point, or one of our mount points would be blocked.
            // Quick test based on the mounting blocks themselves.
            foreach (var point in room.MountPoints)
            {
                var mount = point.AttachedToIn(m_construction);
                if (mount != null)
                {
                    m_invokers.Add(mount);
                }
                else if (point.MountLocations.Any(m_construction.CubeExists))
                {
                    return(true);
                }
            }
            foreach (var other in m_construction.Rooms)
            {
                if (other != room)
                {
                    foreach (var point in other.MountPoints)
                    {
                        if (point.AttachedToIn(m_construction) == null)
                        {
                            foreach (var block in point.MountPoint.Blocks)
                            {
                                var pos = other.PrefabToGrid(block.MountLocation);
                                if (!room.CubeExists(pos))
                                {
                                    continue;
                                }
                                var mountBlock = room.GetMountPointBlockAt(pos);
                                if (mountBlock == null || !mountBlock.TypeEquals(block) || pos != room.PrefabToGrid(mountBlock.AnchorLocation))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            // Reject if this will block another mount point, or one of our mount points would blocked.  Use expensive test.
            foreach (var point in room.MountPoints)
            {
                if (point.AttachedToIn(m_construction) == null)
                {
                    var oppos = point.MountPoint.SmallestTerminalAttachment;
                    if (oppos.Item1 == null)
                    {
                        continue;
                    }
                    var     pos = Utilities.Multiply(oppos.Item2, room.Transform);
                    MatrixI ipos;
                    MatrixI.Invert(ref pos, out ipos);
                    if (m_construction.Intersects(oppos.Item1, pos, ipos, testOptional, true, room))
                    {
                        return(true);
                    }
                }
            }
            // Compare to all other unused mount points.
            foreach (var other in m_construction.Rooms)
            {
                if (other != room)
                {
                    foreach (var point in other.MountPoints)
                    {
                        if (!m_invokers.Contains(point) && point.AttachedTo == null)
                        {
                            // TODO we actually have this data pre-computed if we wanted to use that.
                            var oppos = point.MountPoint.SmallestTerminalAttachment;
                            if (oppos.Item1 == null)
                            {
                                continue;
                            }
                            var     pos = Utilities.Multiply(oppos.Item2, other.Transform);
                            MatrixI ipos;
                            MatrixI.Invert(ref pos, out ipos);
                            if (PartMetadata.Intersects(room.Part, room.Transform, room.InvTransform,
                                                        other.Part, pos, ipos, testOptional, true))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
 public bool Intersects(ProceduralRoom other, bool testOptional, bool testQuick = false)
 {
     return(other.BoundingBoxBoth.Intersects(BoundingBoxBoth) &&
            (other.BoundingBox.Intersects(BoundingBox) || other.ReservedSpace.Intersects(ReservedSpace)) &&
            PartMetadata.Intersects(ref m_part, ref m_transform, ref m_invTransform, ref other.m_part, ref other.m_transform, ref other.m_invTransform, testOptional, testQuick));
 }
Ejemplo n.º 6
0
 public bool Intersects(PartFromPrefab other, MatrixI otherTransform, MatrixI otherITransform, bool testOptional, bool testQuick = false)
 {
     return(PartMetadata.Intersects(ref m_part, ref m_transform, ref m_invTransform, ref other, ref otherTransform, ref otherITransform, testOptional, testQuick));
 }