示例#1
0
 public PortConstraint CreatePortConstraint(IEdge key, PortConstraintType type, bool atSource, bool strong)
 {
     if (type == PortConstraintType.FromSketch)
     {
         return(CreatePortConstraintFromSketch(key, atSource, strong));
     }
     return(PortConstraint.Create((PortSide)type, strong));
 }
示例#2
0
        protected override Task RunModule()
        {
            IMapperRegistry registry      = CurrentIGraph.MapperRegistry;
            OptionGroup     toplevelGroup = Handler.GetGroupByName(TOP_LEVEL);

            if ((bool)toplevelGroup[ClearAllConstraints].Value)
            {
                //deregistriere den Mapper, d.h. port constraints werden nicht mehr vorgegeben.
                registry.RemoveMapper(PortConstraintKeys.TargetPortConstraintDpKey);
                registry.RemoveMapper(PortConstraintKeys.SourcePortConstraintDpKey);
                sourcePCMapper = null;
                targetPCMapper = null;
            }
            else
            {
                registry.RemoveMapper(PortConstraintKeys.TargetPortConstraintDpKey);
                registry.RemoveMapper(PortConstraintKeys.SourcePortConstraintDpKey);

                if (sourcePCMapper == null)
                {
                    sourcePCMapper = new DictionaryMapper <IEdge, PortConstraint>();
                }
                if (targetPCMapper == null)
                {
                    targetPCMapper = new DictionaryMapper <IEdge, PortConstraint>();
                }

                string             scope      = (string)toplevelGroup[Scope].Value;
                OptionGroup        spcg       = (OptionGroup)toplevelGroup.GetGroupByName(SourcePortConstraints);
                OptionGroup        tpcg       = (OptionGroup)toplevelGroup.GetGroupByName(TargetPortConstraints);
                PortConstraintType sourceType = (PortConstraintType)spcg[PortConstraintStr].Value;
                bool strongSource             = (bool)spcg[StrongPortConstraint].Value;
                PortConstraintType targetType = (PortConstraintType)tpcg[PortConstraintStr].Value;
                bool strongTarget             = (bool)spcg[StrongPortConstraint].Value;

                foreach (IEdge edge in CurrentIGraph.Edges)
                {
                    bool isSelected = false;
                    switch (scope)
                    {
                    case ScopeAllEdges:
                        isSelected = true;
                        break;

                    case ScopeSelectedEdges:
                        isSelected = IsSelected(Context, edge);
                        break;

                    case ScopeEdgesAtSelectedNodes:
                        IPort sourcePort = edge.SourcePort;
                        IPort targetPort = edge.TargetPort;
                        isSelected = IsSelected(Context, sourcePort) ||
                                     IsSelected(Context, targetPort) ||
                                     IsSelected(Context, sourcePort.Owner) ||
                                     IsSelected(Context, targetPort.Owner);
                        break;
                    }
                    if (isSelected)
                    {
                        sourcePCMapper[edge] = CreatePortConstraint(edge, sourceType, true, strongSource);
                        targetPCMapper[edge] = CreatePortConstraint(edge, targetType, false, strongTarget);
                    }
                }

                registry.AddMapper(PortConstraintKeys.SourcePortConstraintDpKey,
                                   sourcePCMapper);
                registry.AddMapper(PortConstraintKeys.TargetPortConstraintDpKey,
                                   targetPCMapper);
            }
            return(Task.FromResult <object>(null));
        }