コード例 #1
0
        public static void AddVarsToTab(
            List <WatchVariableControl> watchVars, WatchVariableFlowLayoutPanel variableAdder, AddToTabTypeEnum?addToTabTypeNullable = null)
        {
            List <List <WatchVariableControl> > newVarListList = new List <List <WatchVariableControl> >();
            AddToTabTypeEnum addToTabType = addToTabTypeNullable ?? GetAddToTabType();

            foreach (WatchVariableControl watchVar in watchVars)
            {
                List <WatchVariableControl> newVarList = new List <WatchVariableControl>();
                List <uint>         addressList        = watchVar.FixedAddressListGetter() ?? watchVar.WatchVarWrapper.GetCurrentAddressesToFix();
                List <List <uint> > addressesLists     =
                    addToTabType == AddToTabTypeEnum.GroupedByVariable ||
                    addToTabType == AddToTabTypeEnum.GroupedByBaseAddress
                        ? addressList.ConvertAll(address => new List <uint>()
                {
                    address
                })
                        : new List <List <uint> >()
                {
                    addressList
                };
                for (int i = 0; i < addressesLists.Count; i++)
                {
                    string name = watchVar.VarName;
                    if (addressesLists.Count > 1)
                    {
                        name += " " + (i + 1);
                    }
                    bool useFixed =
                        addToTabType == AddToTabTypeEnum.Fixed ||
                        addToTabType == AddToTabTypeEnum.GroupedByVariable ||
                        addToTabType == AddToTabTypeEnum.GroupedByBaseAddress;
                    List <uint>          constructorAddressList = useFixed ? addressesLists[i] : null;
                    WatchVariableControl newControl             =
                        watchVar.WatchVarPrecursor.CreateWatchVariableControl(
                            name,
                            watchVar._baseColor,
                            new List <VariableGroup>()
                    {
                        VariableGroup.Custom
                    },
                            constructorAddressList);
                    newVarList.Add(newControl);
                }
                watchVar.FlashColor(ADD_TO_CUSTOM_TAB_COLOR);
                newVarListList.Add(newVarList);
            }

            if (addToTabType == AddToTabTypeEnum.GroupedByBaseAddress)
            {
                int maxListLength = newVarListList.Max(list => list.Count);
                for (int i = 0; i < maxListLength; i++)
                {
                    for (int j = 0; j < newVarListList.Count; j++)
                    {
                        List <WatchVariableControl> newVarList = newVarListList[j];
                        if (i >= newVarList.Count)
                        {
                            continue;
                        }
                        WatchVariableControl newVar = newVarList[i];
                        variableAdder.AddVariable(newVar);
                    }
                }
            }
            else
            {
                foreach (List <WatchVariableControl> newVarList in newVarListList)
                {
                    foreach (WatchVariableControl newVar in newVarList)
                    {
                        variableAdder.AddVariable(newVar);
                    }
                }
            }
        }