private void removeInterloackable(ScopeGroup rootGroup, IInterlockable interlockable, IEnumerable <ITECObject> parentPath)
        {
            if (!filterPredicate(interlockable))
            {
                return;
            }
            List <ScopeGroup> path = rootGroup.GetPath(interlockable as ITECScope);

            path[path.Count - 2].Remove(path.Last());

            ScopeGroup parentGroup = rootGroup;

            for (int i = 1; i < path.Count; i++)
            {
                if (!containsInterlockable(path[i]))
                {
                    parentGroup.Remove(path[i]);
                    return;
                }
                else
                {
                    parentGroup = path[i];
                }
            }
        }
Beispiel #2
0
 public AddInterlockVM(IInterlockable parent, TECScopeManager scopeManager) : base(scopeManager)
 {
     this.parent   = parent;
     this.Catalogs = scopeManager.Catalogs;
     AddCommand    = new RelayCommand(addExecute, canAdd);
     DeleteConnectionTypeCommand = new RelayCommand <TECElectricalMaterial>(deleteConnectiontypeExecute, canDeleteConnectionType);
 }
        private void addInterlockable(ScopeGroup rootGroup, IInterlockable interlockable, IEnumerable <ITECObject> parentPath)
        {
            if (!filterPredicate(interlockable))
            {
                return;
            }
            IRelatable        rootScope = rootGroup.Scope as IRelatable ?? this.root;
            List <ITECObject> path      = new List <ITECObject>(parentPath);

            if (rootScope != parentPath.First())
            {
                path = rootScope.GetObjectPath(parentPath.First());
                path.Remove(parentPath.First());
                path.AddRange(parentPath);
            }

            if (path.Count == 0)
            {
                logger.Error("New connectable doesn't exist in root object.");
                return;
            }

            ScopeGroup lastGroup = rootGroup;
            int        lastIndex = 0;

            for (int i = path.Count - 1; i > 0; i--)
            {
                if (path[i] is ITECScope scope)
                {
                    ScopeGroup group = rootGroup.GetGroup(scope);

                    if (group != null)
                    {
                        lastGroup = group;
                        lastIndex = i;
                        break;
                    }
                }
                else
                {
                    logger.Error("Object in path to interlockable isn't ITECScope, cannot build group hierarchy.");
                    return;
                }
            }

            ScopeGroup currentGroup = lastGroup;

            for (int i = lastIndex + 1; i < path.Count; i++)
            {
                if (path[i] is ITECScope scope)
                {
                    currentGroup = currentGroup.Add(scope);
                }
                else
                {
                    logger.Error("Object in path to interlockable isn't ITECScope, cannot build group hierarchy.");
                    return;
                }
            }
        }
Beispiel #4
0
 private bool canAddInterlock(IInterlockable arg)
 {
     return(true);
 }
Beispiel #5
0
 private void addInterlockExecute(IInterlockable interlockable)
 {
     SelectedVM = new AddInterlockVM(interlockable, scopeManager);
 }