Ejemplo n.º 1
0
        // Does the actual translation from state name to UID - may also return a keyword (Return, Hang Up, etc.) for which no UID exists or
        // null if no change is necessary
        // expectedLabel is used to check connectors - Visio has a habit of changing connector names so we need to ensure
        // we have the right one - it's ignored if the goto is not via a connector
        private static string TranslateGotoToUniqueIdForShapeOrKeyword(Shape shape, string gotoShapeName, Dictionary <string, List <string> > uniqueIdMap, string expectedLabel)
        {
            List <string> list = null;

            // Call SubDialogs don't have underscores in the SubDialog names
            ShapeTypes type = Common.GetShapeType(shape);

            if (type == ShapeTypes.CallSubDialog)
            {
                gotoShapeName = StateShadow.StateIdForStorage(gotoShapeName);
            }

            if (uniqueIdMap.TryGetValue(gotoShapeName, out list))
            {
                // dynamic connectors must be on the same page as the shape
                // visio somtimes renames shapes when copying/pasting so we really want
                // to make sure we get the right connector from the right page
                if (list.Count == 1 && !gotoShapeName.StartsWith(Strings.DynamicConnectorShapeNameStart))
                {
                    return(list.ElementAt(0));
                }
                else
                {
                    // There can be multiple shapes with same name, lovely - need to find one on this page or we're in trouble
                    foreach (string uid in list)
                    {
                        try {
                            Shape s = shape.ContainingPage.Shapes.get_ItemU(uid);
                            if (s != null)
                            {
                                // if it's a connector, make sure it's attached to the shape and matches the expected label
                                if (gotoShapeName.StartsWith(Strings.DynamicConnectorShapeNameStart))
                                {
                                    foreach (Connect c in s.Connects)
                                    {
                                        if (c.FromCell.Name.Equals(Strings.BeginConnectionPointCellName) &&
                                            c.ToSheet == shape &&
                                            Common.MakeLabelName(s.Text).Equals(expectedLabel))
                                        {
                                            return(uid);
                                        }
                                    }
                                    return(NeedsToBeRepairedString);
                                }
                                else
                                {
                                    return(uid);
                                }
                            }
                        }
                        catch {
                            // just ignore for now - when checking for one from a different page, it throws an exception
                        }
                    }
                    // if we get here, it means either we have a bogus connection (unlikely) or the connector we're looking for
                    // has been changed when we output from CID
                    return(NeedsToBeRepairedString);
                }
            }

            // some things are expected
            if (gotoShapeName.Length == 0)
            {
                return(null);
            }

            if (gotoShapeName.Equals(Strings.CurrentStateKeyword))
            {
                return(null);
            }

            // these will just be treated as terminals - let's do our best to convert them
            if (gotoShapeName.ToLower().Contains(Strings.ReturnKeyword.ToLower()))
            {
                return(Strings.ReturnKeyword);
            }
            else if (gotoShapeName.ToLower().Contains(Strings.TransferKeyword.ToLower()))
            {
                return(Strings.TransferKeyword);
            }
            else if (gotoShapeName.ToLower().Contains(Strings.HangUpKeywordShortForm.ToLower()))
            {
                return(Strings.HangUpKeywordShortForm);
            }

            return(NeedsToBeRepairedString);
        }