Example #1
0
        /// <summary>
        /// Instantiate SocketUses based on the xml definition
        /// </summary>
        internal void CreateSocketUses()
        {
            var modDef = this.GadgeteerPartDefinition as ModuleDefinition;

            if (modDef == null)
            {
                return;
            }

            if (modDef.Sockets.Count == 0)
            {
                return;
            }

            SocketUses.Clear();

            foreach (var socketDef in modDef.Sockets)
            {
                var s = new SocketUse(this.Store)
                {
                    Label = socketDef.TypesLabel
                };
                this.SocketUses.Add(s);
            }
        }
        public override string GetToolTipText(DiagramItem item)
        {
            SocketUseShape fromShape = FromShape as SocketUseShape;
            SocketShape    toShape   = ToShape as SocketShape;

            if (fromShape == null || toShape == null)
            {
                return(base.GetToolTipText(item));
            }

            SocketUse fromSocket = fromShape.ModelElement as SocketUse;
            Socket    toSocket   = toShape.ModelElement as Socket;

            if (fromShape == null || toShape == null)
            {
                return(base.GetToolTipText(item));
            }

            string name = null;

            if (toSocket.GadgeteerHardware is Mainboard)
            {
                name = ((Mainboard)toSocket.GadgeteerHardware).Name;
            }

            else if (toSocket.GadgeteerHardware is Module)
            {
                name = ((Module)toSocket.GadgeteerHardware).Name;
            }

            return(string.Format("{0} ({1}) ↔ {2} ({3})", fromSocket.Module.Name, fromSocket.Label, name, toSocket.Label));
        }
Example #3
0
        /// <summary>
        /// Instantiate SocketUses based on the xml definition
        /// </summary>
        internal void CreateSocketUses()
        {
            var modDef = this.GadgeteerPartDefinition as ModuleDefinition;

            if (modDef == null)
            {
                return;
            }

            if (modDef.Sockets.Count == 0)
            {
                return;
            }

            var needsUnique = new Dictionary <string, bool>(modDef.Sockets.Count);

            foreach (var socketDef in modDef.Sockets)
            {
                needsUnique[socketDef.TypesLabel] = needsUnique.ContainsKey(socketDef.TypesLabel);
            }

            SocketUses.Clear();

            foreach (var socketDef in modDef.Sockets)
            {
                var s = new SocketUse(this.Store)
                {
                    Label = needsUnique[socketDef.TypesLabel] ? socketDef.UniqueLabel : socketDef.TypesLabel
                };

                this.SocketUses.Add(s);
            }
        }
Example #4
0
        /// <summary>
        /// Finds unexplored states and push them into the stack
        /// </summary>
        /// <returns>true if any potential connections were found</returns>
        private static bool FindAndPush(Mainboard mainboard, IEnumerable <SocketUse> mSockets, Stack <PossibleConnection> stack)
        {
            SocketUse m = FindUnconnectedSocketUse(mSockets);

            if (m != null)
            {
                PushPosibleConnections(mainboard.Sockets, m, stack);
            }
            return(m != null);
        }
Example #5
0
        private Module CreateModule()
        {
            var m1 = new Module(Store);

            AddSockets(m1, 2);
            var s = new Microsoft.Gadgeteer.Designer.SocketUse(Store);

            m1.SocketUses.Add(s);
            return(m1);
        }
Example #6
0
        /// <summary>
        /// Finds unexplored states and push them into the stack
        /// </summary>
        /// <returns>true if any potential connections were found</returns>
        private static bool FindAndPush(IEnumerable <Socket> providedSockets, IEnumerable <SocketUse> consumedSockets, Stack <PossibleConnection> stack)
        {
            SocketUse m = FindUnconnectedSocketUse(consumedSockets);

            if (m != null)
            {
                PushPosibleConnections(providedSockets, m, stack);
            }
            return(m != null);
        }
        // Called on drop to actually create the new relationship.
        internal static void Connect(ModelElement sourceElement, ModelElement targetElement)
        {
            SocketUse socketUse = sourceElement as SocketUse ?? targetElement as SocketUse;
            Socket    socket    = sourceElement as Socket ?? targetElement as Socket;

            ElementLink newLink = new SocketUseReferencesSocket(socketUse, socket);

            if (DomainClassInfo.HasNameProperty(newLink))
            {
                DomainClassInfo.SetUniqueName(newLink);
            }
        }
        // Called during drag-drop to determine whether the supplied source and target combination is valid.
        internal static bool CanAcceptSourceAndTarget(ModelElement sourceElement, ModelElement targetElement)
        {
            SocketUse socketUse = sourceElement as SocketUse ?? targetElement as SocketUse;
            Socket    socket    = sourceElement as Socket ?? targetElement as Socket;

            if (socket == null || socketUse == null)
            {
                return(false);
            }

            return(socketUse.CanConnectTo(socket));
        }
Example #9
0
        private static void PushPosibleConnections(IEnumerable <Socket> sockets, SocketUse socketUse, Stack <PossibleConnection> stack)
        {
            foreach (var socket in sockets)
            {
                if (socket.SocketUse != null)
                {
                    continue;
                }

                if (socketUse.CanConnectTo(socket))
                {
                    stack.Push(new PossibleConnection()
                    {
                        Socket = socket, SocketUse = socketUse
                    });
                }
            }
        }
Example #10
0
        public void TestSortedModules()
        {
            Mainboard mb = GadgeteerModel.Mainboard;

            DoInTransaction(() =>
            {
                Assert.AreEqual(0, GadgeteerModel.SortModulesInCodeGenerationOrder().Count(),
                                "Empty test failed");


                AddSockets(mb, 3);

                Module m1 = CreateModule();
                Module m2 = CreateModule();
                Module m3 = CreateModule();
                Module m4 = CreateModule();
                Module m5 = CreateModule();

                //Connect m2 with to sockets to the mainboard
                var su = new Microsoft.Gadgeteer.Designer.SocketUse(Store);
                m2.SocketUses.Add(su);
                su.Socket = mb.Sockets[2];

                Connect(mb, m1, 0);
                Connect(mb, m2, 1);
                Connect(m1, m4, 1);
                Connect(m4, m5, 0);
                Connect(m2, m3, 0);

                var expectedOrder = new[] { m1, m4, m5, m2, m3 };
                var result        = GadgeteerModel.SortModulesInCodeGenerationOrder();
                bool equal        = expectedOrder.SequenceEqual(result);

                Assert.IsTrue(equal, "The sequence did not result in the expected order");
            });
        }
Example #11
0
        /// <summary>
        /// Checks whether it's possible to connect the given sockets without incurring shared pin conflicts. This method will consider
        /// all other sockets currently connected to the mainboard when checking for conflicts
        /// </summary>
        internal static bool CanPinsConnect(Socket socket, SocketUse socketUse)
        {
            var providedSocket = socket.Definition as ProvidedSocket;

            if (providedSocket == null)
            {
                return(false);
            }

            if (providedSocket.SharedPinMaps == null || providedSocket.SharedPinMaps.Count == 0)
            {
                return(true);
            }


            foreach (var sharedPinMap in providedSocket.SharedPinMaps)
            {
                //is it used by the connecting socketuse?
                SharedPinMap map           = sharedPinMap;
                Pin          connectingPin = (from pin
                                              in ((SocketUseDefinition)socketUse.Definition).Pins
                                              where pin.Value == map.SocketPin
                                              select pin).FirstOrDefault();

                if (connectingPin == null)
                {
                    continue;
                }

                // if the pin can only be used shared and this use is not compatible with sharing, fail
                if (!connectingPin.Shared && sharedPinMap.SharedOnly)
                {
                    return(false);
                }

                foreach (var s in socket.GadgeteerHardware.Sockets)
                {
                    //We are interested in sockets other than "us"
                    if (s == socket)
                    {
                        continue;
                    }

                    if (!s.IsConnected)
                    {
                        continue;
                    }

                    var ps = s.Definition as ProvidedSocket;

                    //If there are no shared pin maps there's nothing else to check
                    if (ps.SharedPinMaps == null || ps.SharedPinMaps.Count == 0)
                    {
                        continue;
                    }

                    foreach (var spm in ps.SharedPinMaps)
                    {
                        //are the shared pind maps for the same mainboard resource?
                        if (spm.NetId != sharedPinMap.NetId)
                        {
                            continue;
                        }

                        //is it in use or are they both shared?
                        foreach (var pin in ((SocketUseDefinition)s.SocketUse.Definition).Pins)
                        {
                            if (pin.Value == spm.SocketPin && (!pin.Shared || !connectingPin.Shared))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Example #12
0
        /// <summary>
        /// Checks whether it's possible to connect the given sockets without incurring shared pin conflicts. This method will consider
        /// all other sockets currently connected to the mainboard when checking for conflicts
        /// </summary>
        internal static bool CanPinsConnect(Socket socket, SocketUse socketUse)
        {
            var providedSocket = socket.Definition as ProvidedSocket;

            if (providedSocket == null)
            {
                return(false);
            }

            if (providedSocket.SharedPinMaps == null || providedSocket.SharedPinMaps.Count == 0)
            {
                return(true);
            }


            foreach (var sharedPinMap in providedSocket.SharedPinMaps)
            {
                //is it used by the connecting socketuse?
                SharedPinMap map           = sharedPinMap;
                Pin          connectingPin = (from pin
                                              in ((SocketUseDefinition)socketUse.Definition).Pins
                                              where pin.Value == map.SocketPin
                                              select pin).FirstOrDefault();

                if (connectingPin == null)
                {
                    continue;
                }

                // if the pin can only be used shared and this use is not compatible with sharing, fail
//#warning this check may be insufficient - have to follow the chain up to see if any provider says "sharedonly"
                if (!connectingPin.Shared && sharedPinMap.SharedOnly)
                {
                    return(false);
                }

                // iterate over

                foreach (var s in socket.GadgeteerHardware.Sockets)
                {
                    //We are interested in sockets other than "us"
                    if (s == socket)
                    {
                        continue;
                    }

                    if (!s.IsConnected)
                    {
                        continue;
                    }
                    //socket.GadgeteerHardware.
//#warning need to check USED sockets too, and follow the net downstream
                    var otherProvidedSocket = s.Definition as ProvidedSocket;

                    //If there are no shared pin maps there's nothing else to check
                    if (otherProvidedSocket.SharedPinMaps == null || otherProvidedSocket.SharedPinMaps.Count == 0)
                    {
                        continue;
                    }

                    foreach (var spm in otherProvidedSocket.SharedPinMaps)
                    {
                        //are the shared pind maps for the same mainboard resource?
                        if (spm.NetId != sharedPinMap.NetId)
                        {
                            continue;
                        }

                        //is it in use or are they both shared?
                        foreach (var pin in ((SocketUseDefinition)s.SocketUse.Definition).Pins)
                        {
                            if (pin.Value == spm.SocketPin && (!pin.Shared || !connectingPin.Shared))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
 private ModelElement GetParentForSocketUse(SocketUse childElement)
 {
     return(childElement.Module);
 }