Example #1
0
        /// <summary>
        /// Performs custom actions after an attribute in the DOM node subtree changed</summary>
        /// <param name="sender">Sender (root DOM node)</param>
        /// <param name="e">Attribute change event args</param>
        protected override void OnAttributeChanged(object sender, AttributeEventArgs e)
        {
            if (Validating && !m_undoingOrRedoing)
            {
                if (e.DomNode.Parent.Is <Group>() && e.AttributeInfo == ElementLabelAttribute)
                {
                    var subGraph = e.DomNode.Parent.Cast <Group>();
                    if (e.DomNode.Is <Element>())
                    {
                        // the name of a sub-node has changed, needs to update group pin names that are not manually set
                        SyncGroupPinNamesFromModuleName(subGraph, e.DomNode);
                    }
                }
                else if (e.DomNode.Is <GroupPin>() && e.AttributeInfo == PinNameAttributeAttribute)
                {
                    if (e.DomNode.Parent != null)
                    {
                        var subGraph = e.DomNode.Parent.Cast <Group>();
                        // ensure group pin names are unique at local level
                        UniqueNamer uniqueName  = new UniqueNamer();
                        GroupPin    childGrpPin = e.DomNode.Cast <GroupPin>();

                        foreach (var grpPin in subGraph.InputGroupPins)
                        {
                            if (grpPin != childGrpPin)
                            {
                                uniqueName.Name((string)grpPin.Name);
                            }
                        }

                        foreach (var grpPin in subGraph.OutputGroupPins)
                        {
                            if (grpPin != childGrpPin)
                            {
                                uniqueName.Name((string)grpPin.Name);
                            }
                        }

                        string unique = uniqueName.Name((string)childGrpPin.Name);
                        if (unique != childGrpPin.Name)
                        {
                            childGrpPin.Name.SetString(unique);
                        }

                        // Reset IsDefaultName. Ignore the suffix because there are typically multiple
                        //  circuit elements in a group and the child group pin doesn't know about
                        //  our unique namer.
                        var    defaultName = childGrpPin.DefaultName(childGrpPin.IsInputSide);
                        string ourRoot;
                        int    ourSuffix;
                        uniqueName.Parse(unique, out ourRoot, out ourSuffix);
                        childGrpPin.IsDefaultName = defaultName == ourRoot;

                        UpdateParentGroupPinName(childGrpPin.IsInputSide, childGrpPin);
                    }
                }
            }

            base.OnAttributeChanged(sender, e);
        }
Example #2
0
        public void TestSuffixes()
        {
            UniqueNamer testSpace = new UniqueNamer(' ');

            Assert.AreEqual(testSpace.Name("a"), "a");
            Assert.AreEqual(testSpace.Name("a"), "a 1");

            UniqueNamer testDash = new UniqueNamer('-');

            Assert.AreEqual(testDash.Name("a"), "a");
            Assert.AreEqual(testDash.Name("a"), "a-1");

            UniqueNamer testForwardSlash = new UniqueNamer('/');

            Assert.AreEqual(testForwardSlash.Name("a"), "a");
            Assert.AreEqual(testForwardSlash.Name("a"), "a/1");

            UniqueNamer testBackSlash = new UniqueNamer('\\');

            Assert.AreEqual(testBackSlash.Name("a"), "a");
            Assert.AreEqual(testBackSlash.Name("a"), "a\\1");

            UniqueNamer testParens = new UniqueNamer('(');

            Assert.AreEqual(testParens.Name("a"), "a");
            Assert.AreEqual(testParens.Name("a"), "a(1)");

            Assert.Throws <ArgumentException>(delegate { UniqueNamer bad = new UniqueNamer('@'); });
        }
        public void GetAndCreateTest()
        {
            GeneratorSettings generatorSettings = new GeneratorSettings();
            UniqueNamer       uniqueNamer       = new UniqueNamer();
            TemplateContent   templateContent   = new TemplateContent(generatorSettings, uniqueNamer);

            AbpDbContentTemplate abpDbContentTemplate = new AbpDbContentTemplate(templateContent);
            MySQLSchemaProvider  mySqlSchemaProvider  = new MySQLSchemaProvider();
            const string         mysqlConn            = "Server=127.0.0.1;Database=esms;Uid=root;Pwd=123qwe!@#;";
            SchemaSelector       schemaSelector       = new SchemaSelector(mySqlSchemaProvider, mysqlConn);

            foreach (TableSchema tableSchema in schemaSelector.Tables)
            {
                foreach (DataObjectBase columnSchema in tableSchema.Columns)
                {
                    Console.WriteLine(columnSchema.FullName);
                }
            }

            //EntityContext<AbpEntity, AbpEntityProperty> entityContext = abpDbContentTemplate.GetAndCreate(schemaSelector);
            //Entity<AbpEntityProperty> entity = entityContext.Entities.First(t => t.ClassName == "SysUser");

            //foreach (Relationship relationship in entity.Relationships.Where(t=>t.ThisEntity.Contains("SysUser")&&t.ThisPropertyName=="LastRole"))
            //{
            //    Console.WriteLine(relationship.JoinTable);
            //}
        }
Example #4
0
 public TPTPExprLineariser(TextWriter wr, UniqueNamer namer, TPTPProverOptions opts)
 {
     Contract.Requires(wr != null); Contract.Requires(namer != null);
     this.wr      = wr;
     this.Namer   = namer;
     this.Options = opts;
 }
Example #5
0
        private DomNode CreatePrefab(IEnumerable <IGameObject> gobs)
        {
            UniqueNamer uniqueNamer = new UniqueNamer();

            DomNode[]          temp     = new DomNode[1];
            List <IGameObject> copyList = new List <IGameObject>();
            AABB bound = new AABB();

            foreach (IGameObject gameObject in SelectedGobs)
            {
                IBoundable boundable = gameObject.As <IBoundable>();
                bound.Extend(boundable.BoundingBox);
                Matrix4F world = TransformUtils.ComputeWorldTransform(gameObject);
                temp[0] = gameObject.As <DomNode>();
                DomNode[] copies = DomNode.Copy(temp);
                copies[0].InitializeExtensions();
                IGameObject copy = copies[0].As <IGameObject>();
                copy.Name = uniqueNamer.Name(copy.Name);
                TransformUtils.SetTransform(copy, world);
                copyList.Add(copy);
            }

            DomNode prefab = new DomNode(Schema.prefabType.Type, Schema.prefabRootElement);
            var     list   = prefab.GetChildList(Schema.prefabType.gameObjectChild);
            Vec3F   center = bound.Center;

            foreach (IGameObject gob in copyList)
            {
                gob.Translation = gob.Translation - center;
                gob.UpdateTransform();
                list.Add(gob.As <DomNode>());
            }
            return(prefab);
        }
        public void GetAndCreateTest()
        {
            GeneratorSettings generatorSettings = new GeneratorSettings();
            UniqueNamer uniqueNamer = new UniqueNamer();
            TemplateContent templateContent = new TemplateContent(generatorSettings, uniqueNamer);

            AbpDbContentTemplate abpDbContentTemplate = new AbpDbContentTemplate(templateContent);
            MySQLSchemaProvider mySqlSchemaProvider = new MySQLSchemaProvider();
            const string mysqlConn = "Server=127.0.0.1;Database=esms;Uid=root;Pwd=123qwe!@#;";
            SchemaSelector schemaSelector = new SchemaSelector(mySqlSchemaProvider, mysqlConn);

            foreach (TableSchema tableSchema in schemaSelector.Tables)
            {
                foreach (DataObjectBase columnSchema in tableSchema.Columns)
                {
                    Console.WriteLine(columnSchema.FullName);
                }
            }

            //EntityContext<AbpEntity, AbpEntityProperty> entityContext = abpDbContentTemplate.GetAndCreate(schemaSelector);
            //Entity<AbpEntityProperty> entity = entityContext.Entities.First(t => t.ClassName == "SysUser");

            //foreach (Relationship relationship in entity.Relationships.Where(t=>t.ThisEntity.Contains("SysUser")&&t.ThisPropertyName=="LastRole"))
            //{
            //    Console.WriteLine(relationship.JoinTable);
            //}
        }
Example #7
0
 public TypeDeclCollector(SMTLibProverOptions opts, UniqueNamer namer)
 {
     Contract.Requires(namer != null);
     this.Namer   = namer;
     this.Options = opts;
     InitializeKnownDecls();
 }
Example #8
0
        public void TestName()
        {
            UniqueNamer test = new UniqueNamer();

            Assert.AreEqual(test.Name("a"), "a");
            Assert.AreEqual(test.Name("a1"), "a1");
            Assert.AreEqual(test.Name("a"), "a_1");
            Assert.AreEqual(test.Name("a_1"), "a_2");
        }
Example #9
0
        /// <summary>
        /// Performs custom actions after an attribute in the DOM node subtree changed</summary>
        /// <param name="sender">Sender (root DOM node)</param>
        /// <param name="e">Attribute change event args</param>
        protected override void OnAttributeChanged(object sender, AttributeEventArgs e)
        {
            if (Validating && !m_undoingOrRedoing)
            {
                if (e.DomNode.Parent.Is <Group>() && e.AttributeInfo == ElementLabelAttribute)
                {
                    var subGraph = e.DomNode.Parent.Cast <Group>();
                    if (e.DomNode.Is <Element>())
                    {
                        // the name of a sub-node has changed, needs to update group pin names that are not manually set
                        SyncGroupPinNamesFromModuleName(subGraph, e.DomNode);
                    }
                }
                else if (e.DomNode.Is <GroupPin>() && e.AttributeInfo == PinNameAttributeAttribute)
                {
                    if (e.DomNode.Parent != null)
                    {
                        var subGraph = e.DomNode.Parent.Cast <Group>();
                        // ensure group pin names are unique at local level
                        UniqueNamer uniqueName  = new UniqueNamer();
                        GroupPin    childGrpPin = e.DomNode.Cast <GroupPin>();


                        foreach (var pin in subGraph.Inputs)
                        {
                            var grpPin = pin.Cast <GroupPin>();
                            if (grpPin != childGrpPin)
                            {
                                uniqueName.Name(grpPin.Name);
                            }
                        }

                        foreach (var pin in subGraph.Outputs)
                        {
                            var grpPin = pin.Cast <GroupPin>();
                            if (grpPin != childGrpPin)
                            {
                                uniqueName.Name(grpPin.Name);
                            }
                        }


                        string unique = uniqueName.Name(childGrpPin.Name);
                        if (unique != childGrpPin.Name)
                        {
                            childGrpPin.Name = unique;
                        }

                        // try to reset IsDefaultName
                        childGrpPin.IsDefaultName = childGrpPin.Name == childGrpPin.DefaultName(childGrpPin.IsInputSide);
                        UpdateParentGroupPinName(childGrpPin.IsInputSide, childGrpPin);
                    }
                }
            }

            base.OnAttributeChanged(sender, e);
        }
Example #10
0
        public void TestMinNumDigits()
        {
            UniqueNamer test = new UniqueNamer('_', 5);

            test.Name("a");
            Assert.AreEqual(test.Name("a"), "a_00001");

            Assert.Throws <NotSupportedException>(delegate { UniqueNamer bad = new UniqueNamer('_', 11); });
        }
Example #11
0
 public SMTLibExprLineariser(TextWriter wr, UniqueNamer namer, SMTLibProverOptions opts, ISet <VCExprVar> namedAssumes = null, IList <string> optReqs = null)
 {
     Contract.Requires(wr != null); Contract.Requires(namer != null);
     this.wr                   = wr;
     this.Namer                = namer;
     this.ProverOptions        = opts;
     this.OptimizationRequests = optReqs;
     this.NamedAssumes         = namedAssumes;
 }
Example #12
0
        public void TestChange()
        {
            UniqueNamer test = new UniqueNamer();

            test.Name("a");
            test.Change("a", "b");

            Assert.AreEqual(test.Name("a"), "a");
            Assert.AreEqual(test.Name("b"), "b_1");
        }
Example #13
0
        public void TestRetire()
        {
            UniqueNamer test = new UniqueNamer();

            test.Name("a");
            string a_1 = test.Name("a"); // should be a_1

            test.Retire("a");
            Assert.AreEqual(test.Name("a"), "a");
            Assert.AreEqual(test.Name("a"), "a_2");
        }
Example #14
0
        private DomNode CreatePrefab(IEnumerable <object> gobs)
        {
            UniqueNamer uniqueNamer = new UniqueNamer();

            DomNode[] temp     = new DomNode[1];
            var       copyList = new List <object>();
            AABB      bound    = new AABB();

            foreach (var gameObject in SelectedGobs)
            {
                IBoundable boundable = gameObject.As <IBoundable>();
                bound.Extend(boundable.BoundingBox);

                var trans = gameObject.As <ITransformable>();
                var world = (trans != null) ? TransformUtils.ComputeWorldTransform(trans) : Matrix4F.Identity;

                temp[0] = gameObject.As <DomNode>();
                DomNode[] copies = DomNode.Copy(temp);
                copies[0].InitializeExtensions();

                var nameable = copies[0].As <INameable>();
                if (nameable != null)
                {
                    nameable.Name = uniqueNamer.Name(nameable.Name);
                }

                var copyTrans = copies[0].As <ITransformable>();
                if (copyTrans != null)
                {
                    TransformUtils.SetTransform(copyTrans, world);
                }
                copyList.Add(copies[0]);
            }

            DomNode prefab = new DomNode(Schema.prefabType.Type, Schema.prefabRootElement);
            var     list   = prefab.GetChildList(Schema.prefabType.gameObjectChild);
            Vec3F   center = bound.Center;

            foreach (var gob in copyList)
            {
                var trans = gob.As <ITransformable>();
                if (trans != null)
                {
                    trans.Translation = trans.Translation - center;
                    trans.UpdateTransform();
                }
                var node = gob.As <DomNode>();
                if (node != null)
                {
                    list.Add(node);
                }
            }
            return(prefab);
        }
Example #15
0
        private void NameNode(DomNode node, UniqueNamer namer)
        {
            // if the name isn't unique, make it so
            string id     = node.GetId();
            string unique = namer.Name(id);

            if (id != unique)
            {
                node.SetAttribute(node.Type.IdAttribute, unique);
            }
        }
Example #16
0
        public static string ToString(VCExpr e, UniqueNamer namer, TPTPProverOptions opts)
        {
            Contract.Requires(e != null);
            Contract.Requires(namer != null);
            Contract.Ensures(Contract.Result <string>() != null);

            StringWriter       sw  = new StringWriter();
            TPTPExprLineariser lin = new TPTPExprLineariser(sw, namer, opts);

            Contract.Assert(lin != null);
            lin.Linearise(e, LineariserOptions.Default);
            return(cce.NonNull(sw.ToString()));
        }
Example #17
0
        public static string ToString(VCExpr e, UniqueNamer namer, SMTLibProverOptions opts, ISet <VCExprVar> namedAssumes = null, IList <string> optReqs = null, ISet <VCExprVar> tryAssumes = null)
        {
            Contract.Requires(e != null);
            Contract.Requires(namer != null);
            Contract.Ensures(Contract.Result <string>() != null);

            StringWriter         sw  = new StringWriter();
            SMTLibExprLineariser lin = new SMTLibExprLineariser(sw, namer, opts, namedAssumes, optReqs);

            Contract.Assert(lin != null);
            lin.Linearise(e, LineariserOptions.Default);
            return(cce.NonNull(sw.ToString()));
        }
Example #18
0
        public Z3apiProverContext(Context ctx, VCExpressionGenerator gen)
            : base(gen, new VCGenerationOptions(new List <string>()))
        {
            z3 = ctx;

            this.z3log = null;
            this.tm    = new Z3TypeCachedBuilder(this);
            this.namer = new UniqueNamer();

            // For external

            constants_inv = new BacktrackDictionary <Term, VCExpr>();
            functions_inv = new BacktrackDictionary <FuncDecl, Function>();
        }
Example #19
0
    /// <summary>
    /// The Initializer for the <seealso cref="ClickableElement"/>
    /// </summary>
    /// <param name="id"></param>
    protected void InitClickableElement(string id = null)
    {
        var foo = editor;

        elementNamer = CreateInstance <UniqueNamer>();
        if (id == null)
        {
            identificator = UniqueID();
        }
        else
        {
            identificator = id;
        }
    }
Example #20
0
        public Z3apiProverContext(Z3InstanceOptions opts, VCExpressionGenerator gen)
            : base(gen, new VCGenerationOptions(new List <string>()))
        {
            int timeout = opts.Timeout * 1000;

            config = new Config();
            config.SetParamValue("MODEL", "true");
            config.SetParamValue("MODEL_V2", "true");
            config.SetParamValue("MODEL_COMPLETION", "true");
            config.SetParamValue("MBQI", "false");
            config.SetParamValue("TYPE_CHECK", "true");
            if (0 <= timeout)
            {
                config.SetParamValue("SOFT_TIMEOUT", timeout.ToString());
            }

            if (0 <= CommandLineOptions.Clo.ProverCCLimit)
            {
                this.counterexamples = CommandLineOptions.Clo.ProverCCLimit;
            }
            if (CommandLineOptions.Clo.SimplifyLogFilePath != null)
            {
                logFilename = CommandLineOptions.Clo.SimplifyLogFilePath;
            }
            this.debugTraces = new List <string>();

            z3 = new Context(config);
            z3.SetPrintMode(PrintMode.Smtlib2Compliant);
            if (logFilename != null)
            {
#if true
                z3log = new StreamWriter(logFilename);
                //Z3Log.Open(logFilename);
#else
                z3.OpenLog(logFilename);
#endif
            }
            foreach (string tag in debugTraces)
            {
                z3.EnableDebugTrace(tag);
            }

            //this.z3log = null;
            this.tm    = new Z3TypeCachedBuilder(this);
            this.namer = new UniqueNamer();
        }
        public void UniqueNamerTest()
        {
            var namer = new UniqueNamer();

            Assert.IsNotNull(namer);

            string result;

            result = namer.UniqueName("Tester", "Users");
            Assert.AreEqual("Users", result);

            result = namer.UniqueName("Tester", "Users");
            Assert.AreEqual("Users1", result);

            result = namer.UniqueName("Tester", "Users");
            Assert.AreEqual("Users2", result);
        }
        public IsaUniqueNamer(string spacer)
        {
            this.spacer = spacer;
            uniqueNamer = new UniqueNamer
            {
                Spacer = spacer
            };
            reservedNames = new HashSet <string>();
            reservedNames.Add("A"); //value to abstract value map
            reservedNames.Add("abs");

            illegalChars = new List <char>();
            illegalChars.Add('@');
            illegalChars.Add('.');
            illegalChars.Add('$');
            illegalChars.Add('?');
        }
    public void UniqueNamerTest()
    {
      var namer = new UniqueNamer();
      Assert.IsNotNull(namer);

      string result;

      result = namer.UniqueName("Tester", "Users");
      Assert.AreEqual("Users", result);

      result = namer.UniqueName("Tester", "Users");
      Assert.AreEqual("Users1", result);

      result = namer.UniqueName("Tester", "Users");
      Assert.AreEqual("Users2", result);

    }
 /// <summary>
 /// Checks all DOM nodes in the subtree for validity</summary>
 protected override void ValidateSubtree()
 {
     UniqueNamer uniqueNamer = new UniqueNamer(m_suffixSeparator);
     foreach (DomNode node in DomNode.Subtree)
     {
         foreach (DomNode child in node.Children)
         {
             if (child.Type.IdAttribute != null)
             {
                 string id = child.GetId();
                 string uniqueId = uniqueNamer.Name(id);
                 if (id != uniqueId)
                     OnIdCollision(child, uniqueId);
             }
         }
         uniqueNamer.Clear();
     }
 }
        void ValidateSubtree(DomNode folder)
        {
            var uniqueNamer = new UniqueNamer();

            foreach (DomNode node in folder.Subtree)
            {
                foreach (DomNode child in node.Children)
                {
                    if (child.Type.IdAttribute != null)
                    {
                        string id       = child.GetId();
                        string uniqueId = uniqueNamer.Name(id);
                        if (id != uniqueId)
                        {
                            throw new InvalidTransactionException("id collision");
                        }
                    }
                }
                uniqueNamer.Clear();
            }
        }
Example #26
0
        /// <summary>
        /// Checks all DOM nodes in the subtree for validity</summary>
        protected override void ValidateSubtree()
        {
            UniqueNamer uniqueNamer = new UniqueNamer(m_suffixSeparator);

            foreach (DomNode node in DomNode.Subtree)
            {
                foreach (DomNode child in node.Children)
                {
                    if (child.Type.IdAttribute != null)
                    {
                        string id       = child.GetId();
                        string uniqueId = uniqueNamer.Name(id);
                        if (id != uniqueId)
                        {
                            OnIdCollision(child, uniqueId);
                        }
                    }
                }
                uniqueNamer.Clear();
            }
        }
Example #27
0
        /// <summary>
        /// Performs actions for renamed nodes</summary>
        /// <param name="renamed">Renamed nodes and old ids</param>
        protected override void RenameNodes(Dictionary <DomNode, string> renamed)
        {
            HashSet <DomNode> parents = new HashSet <DomNode>();

            foreach (DomNode node in renamed.Keys)
            {
                if (node.Parent != null)
                {
                    parents.Add(node.Parent);
                }
            }

            UniqueNamer uniqueNamer = new UniqueNamer(m_suffixSeparator);

            foreach (DomNode parent in parents)
            {
                // first, initialize namer with the names of the children whose names haven't changed
                foreach (DomNode child in parent.Children)
                {
                    if (child.Type.IdAttribute != null &&
                        !renamed.ContainsKey(child))
                    {
                        string id = child.GetId();
                        uniqueNamer.Name(id);
                    }
                }

                // now, generate unique ids for the added children
                foreach (DomNode child in parent.Children)
                {
                    if (child.Type.IdAttribute != null &&
                        renamed.ContainsKey(child))
                    {
                        NameNode(child, uniqueNamer);
                    }
                }

                uniqueNamer.Clear();
            }
        }
Example #28
0
        public TPTPProcessTheoremProver(ProverOptions options, VCExpressionGenerator gen,
                                        DeclFreeProverContext ctx)
            : base(options, "", "", "", "", gen)
        {
            Contract.Requires(options != null);
            Contract.Requires(gen != null);
            Contract.Requires(ctx != null);

            // No bg predicate at the moment
            // InitializeGlobalInformation("UnivBackPred.tptp");

            this.ctx = ctx;
            this.Gen = gen;

            TypeAxiomBuilder axBuilder;

            switch (CommandLineOptions.Clo.TypeEncodingMethod)
            {
            case CommandLineOptions.TypeEncoding.Arguments:
                axBuilder = new TypeAxiomBuilderArguments(gen);
                axBuilder.Setup();
                break;

            case CommandLineOptions.TypeEncoding.Monomorphic:
                axBuilder = new TypeAxiomBuilderPremisses(gen);
                break;

            default:
                axBuilder = new TypeAxiomBuilderPremisses(gen);
                axBuilder.Setup();
                break;
            }
            AxBuilder = axBuilder;
            UniqueNamer namer = new UniqueNamer();

            Namer              = namer;
            Namer.Spacer       = "__";
            this.DeclCollector = new TypeDeclCollector(namer);
        }
Example #29
0
        /// <summary>
        /// Performs actions for added nodes</summary>
        /// <param name="added">Added nodes</param>
        /// <param name="renamed">Renamed nodes and old ids</param>
        protected override void AddNodes(HashSet <DomNode> added, Dictionary <DomNode, string> renamed)
        {
            HashSet <DomNode> parents = new HashSet <DomNode>();

            foreach (DomNode node in added)
            {
                renamed.Remove(node);
                parents.Add(node.Parent);
            }

            UniqueNamer uniqueNamer = new UniqueNamer(m_suffixSeparator);

            foreach (DomNode parent in parents)
            {
                // first, initialize namer with the names of the pre-existing children
                foreach (DomNode child in parent.Children)
                {
                    if (child.Type.IdAttribute != null &&
                        !added.Contains(child))
                    {
                        string id = child.GetId();
                        uniqueNamer.Name(id);
                    }
                }

                // now, generate unique ids for the added children
                foreach (DomNode child in parent.Children)
                {
                    if (child.Type.IdAttribute != null &&
                        added.Contains(child))
                    {
                        NameNode(child, uniqueNamer);
                    }
                }

                uniqueNamer.Clear();
            }
        }
        /// <summary>
        /// Performs actions for added nodes</summary>
        /// <param name="added">Added nodes</param>
        /// <param name="renamed">Renamed nodes and old ids</param>
        protected override void AddNodes(HashSet<DomNode> added, Dictionary<DomNode, string> renamed)
        {
            HashSet<DomNode> parents = new HashSet<DomNode>();
            foreach (DomNode node in added)
            {
                renamed.Remove(node);
                parents.Add(node.Parent);
            }

            UniqueNamer uniqueNamer = new UniqueNamer(m_suffixSeparator);
            foreach (DomNode parent in parents)
            {
                // first, initialize namer with the names of the pre-existing children
                foreach (DomNode child in parent.Children)
                {
                    if (child.Type.IdAttribute != null &&
                        !added.Contains(child))
                    {
                        string id = child.GetId();
                        uniqueNamer.Name(id);
                    }
                }

                // now, generate unique ids for the added children
                foreach (DomNode child in parent.Children)
                {
                    if (child.Type.IdAttribute != null &&
                        added.Contains(child))
                    {
                        NameNode(child, uniqueNamer);
                    }
                }

                uniqueNamer.Clear();
            }
        }
Example #31
0
 public TypeDeclCollector(UniqueNamer namer)
 {
     Contract.Requires(namer != null);
     this.Namer = namer;
 }
Example #32
0
        /// <summary>
        /// Performs custom actions after an attribute in the DOM node subtree changed</summary>
        /// <param name="sender">Sender (root DOM node)</param>
        /// <param name="e">Attribute change event args</param>
        protected override void OnAttributeChanged(object sender, AttributeEventArgs e)
        {
            if (Validating && !m_undoingOrRedoing)
            {
                if (e.DomNode.Parent.Is<Group>() && e.AttributeInfo == ElementLabelAttribute)
                {
                    var subGraph = e.DomNode.Parent.Cast<Group>();
                    if (e.DomNode.Is<Element>())
                    {
                        // the name of a sub-node has changed, needs to update group pin names that are not manually set
                        SyncGroupPinNamesFromModuleName(subGraph, e.DomNode);
                    }
                }
                else if (e.DomNode.Is<GroupPin>() && e.AttributeInfo == PinNameAttributeAttribute)
                {
                    if (e.DomNode.Parent != null)
                    {
                        var subGraph = e.DomNode.Parent.Cast<Group>();
                        // ensure group pin names are unique at local level
                        UniqueNamer uniqueName = new UniqueNamer();
                        GroupPin childGrpPin = e.DomNode.Cast<GroupPin>();
  
                        foreach (var grpPin in subGraph.InputGroupPins)
                        {
                            if (grpPin != childGrpPin)
                                uniqueName.Name(grpPin.Name);
                        }

                        foreach (var grpPin in subGraph.OutputGroupPins)
                        {
                            if (grpPin != childGrpPin)
                                uniqueName.Name(grpPin.Name);
                        }

                        string unique = uniqueName.Name(childGrpPin.Name);
                        if (unique != childGrpPin.Name)
                            childGrpPin.Name = unique;

                        // Reset IsDefaultName. Ignore the suffix because there are typically multiple
                        //  circuit elements in a group and the child group pin doesn't know about
                        //  our unique namer.
                        string defaultName = childGrpPin.DefaultName(childGrpPin.IsInputSide);
                        string ourRoot;
                        int ourSuffix;
                        uniqueName.Parse(unique, out ourRoot, out ourSuffix);
                        childGrpPin.IsDefaultName = defaultName == ourRoot;

                        UpdateParentGroupPinName(childGrpPin.IsInputSide, childGrpPin);
                    }
                }
            }

            base.OnAttributeChanged(sender,e);
        }
 private void NameNode(DomNode node, UniqueNamer namer)
 {
     // if the name isn't unique, make it so
     string id = node.GetId();
     string unique = namer.Name(id);
     if (id != unique)
     {
         node.SetAttribute(node.Type.IdAttribute, unique);
     }
 }
Example #34
0
        /// <summary>
        /// Performs initialization when the adapter's node is set</summary>
        /// <remarks>Checks ID uniqueness when the adapter's node is set and throws an
        /// InvalidOperationException if a violation is found</remarks>
        protected override void OnNodeSet()
        {
            m_uniqueNamer = new UniqueNamer(m_suffixSeparator);

            base.OnNodeSet();
        }
Example #35
0
        /// <summary>
        /// Performs custom actions after an attribute in the DOM node subtree changed</summary>
        /// <param name="sender">Sender (root DOM node)</param>
        /// <param name="e">Attribute change event args</param>
        protected override void OnAttributeChanged(object sender, AttributeEventArgs e)
        {
            if (Validating && !m_undoingOrRedoing)
            {
                if (e.DomNode.Parent.Is<Group>() && e.AttributeInfo == ElementLabelAttribute)
                {
                    var subGraph = e.DomNode.Parent.Cast<Group>();
                    if (e.DomNode.Is<Element>())
                    {
                        // the name of a sub-node has changed, needs to update group pin names that are not manually set
                        SyncGroupPinNamesFromModuleName(subGraph, e.DomNode);
                    }
                }
                else if (e.DomNode.Is<GroupPin>() && e.AttributeInfo == PinNameAttributeAttribute)
                {

                    if (e.DomNode.Parent != null)
                    {
                        var subGraph = e.DomNode.Parent.Cast<Group>();
                        // ensure group pin names are unique at local level
                        UniqueNamer uniqueName = new UniqueNamer();
                        GroupPin childGrpPin = e.DomNode.Cast<GroupPin>();
                        

                        foreach (var pin in subGraph.Inputs)
                        {
                            var grpPin = pin.Cast<GroupPin>();
                            if (grpPin != childGrpPin)
                                uniqueName.Name(grpPin.Name);
                        }

                        foreach (var pin in subGraph.Outputs)
                        {
                            var grpPin = pin.Cast<GroupPin>();
                            if (grpPin != childGrpPin)
                                uniqueName.Name(grpPin.Name);
                        }


                        string unique = uniqueName.Name(childGrpPin.Name);
                        if (unique != childGrpPin.Name)
                            childGrpPin.Name = unique;

                        // try to reset IsDefaultName
                        childGrpPin.IsDefaultName = childGrpPin.Name == childGrpPin.DefaultName(childGrpPin.IsInputSide);
                        UpdateParentGroupPinName(childGrpPin.IsInputSide, childGrpPin);

                    }
                }
            }

            base.OnAttributeChanged(sender,e);
        }
Example #36
0
        /// <summary>
        /// Open or create new document.
        /// It opens if the file exist otherwise it will creates new document
        /// </summary>
        public static GameDocument OpenOrCreate(Uri uri, SchemaLoader schemaLoader)
        {
            if (!uri.IsAbsoluteUri)
            {
                return(null);
            }

            var docRegistry = Globals.MEFContainer.GetExportedValue <GameDocumentRegistry>();

            GameDocument document = docRegistry.FindDocument(uri) as GameDocument;

            if (document != null)
            {
                return(document);
            }

            string filePath = uri.LocalPath;

            DomNode rootNode = null;

            if (File.Exists(filePath))
            {
                // read existing document using custom dom XML reader
                using (FileStream stream = File.OpenRead(filePath))
                {
                    var reader = new CustomDomXmlReader(Globals.ResourceRoot, schemaLoader);
                    rootNode = reader.Read(stream, uri);
                }
            }
            else
            {
                // create new document by creating a Dom node of the root type defined by the schema
                rootNode = new DomNode(Schema.gameType.Type, Schema.gameRootElement);
                rootNode.SetAttribute(Schema.gameType.nameAttribute, "Game".Localize());
            }


            GameObjectFolder rootFolder = Adapters.As <GameObjectFolder>(rootNode.GetChild(Schema.gameType.gameObjectFolderChild));

            if (rootFolder == null)
            {
                // create the game object folder
                rootFolder      = (GameObjectFolder)GameObjectFolder.Create();
                rootFolder.Name = "GameObjects".Localize("this is the name of a folder in the project lister");
                rootNode.SetChild(Schema.gameType.gameObjectFolderChild, rootFolder.DomNode);
            }


            // create bookmarks
            DomNode bookmarks = rootNode.GetChild(Schema.gameType.bookmarksChild);

            if (bookmarks == null)
            {
                bookmarks = new DomNode(Schema.bookmarksType.Type);
                rootNode.SetChild(Schema.gameType.bookmarksChild, bookmarks);
            }

            DomNode layersNode = rootNode.GetChild(Schema.gameType.layersChild);

            if (layersNode == null)
            {
                layersNode = new DomNode(Schema.layersType.Type);
                rootNode.SetChild(Schema.gameType.layersChild, layersNode);
            }

            // Create the grid
            DomNode gridNode = rootNode.GetChild(Schema.gameType.gridChild);

            if (gridNode == null)
            {
                gridNode = new DomNode(Schema.gridType.Type);
                rootNode.SetChild(Schema.gameType.gridChild, gridNode);
            }

            document     = rootNode.As <GameDocument>();
            document.Uri = uri;

            // Initialize Dom extensions now that the data is complete
            rootNode.InitializeExtensions();

            docRegistry.Add(document);


            UniqueNamer uniqueNamer = new UniqueNamer('_');

            foreach (DomNode node in rootNode.Subtree)
            {
                if (node.Type.IdAttribute != null)
                {
                    uniqueNamer.Name(node.GetId());
                }
            }


            // sync all the prefab instances
            DomNode folderNode = document.RootGameObjectFolder.As <DomNode>();

            foreach (DomNode node in folderNode.Subtree)
            {
                PrefabInstance prefab = node.As <PrefabInstance>();
                if (prefab == null)
                {
                    continue;
                }
                prefab.Resolve(uniqueNamer);
            }

            if (ResolveOnLoad)
            {
                // resovle all the game references.
                foreach (var subGame in document.GetChildList <GameReference>(Schema.gameType.gameReferenceChild))
                {
                    subGame.Resolve();
                }
            }

            document.Dirty = false;
            return(document);
        }
Example #37
0
 public void SetNamer(UniqueNamer namer)
 {
     Namer = namer;
 }
Example #38
0
        /// <summary>
        /// Performs initialization when the adapter's node is set</summary>
        /// <remarks>Checks ID uniqueness when the adapter's node is set and throws an
        /// InvalidOperationException if a violation is found</remarks>
        protected override void OnNodeSet()
        {
            m_uniqueNamer = new UniqueNamer(m_suffixSeparator);

            base.OnNodeSet();
        }
        /// <summary>
        /// Performs actions for renamed nodes</summary>
        /// <param name="renamed">Renamed nodes and old ids</param>
        protected override void RenameNodes(Dictionary<DomNode, string> renamed)
        {
            HashSet<DomNode> parents = new HashSet<DomNode>();
            foreach (DomNode node in renamed.Keys)
                parents.Add(node.Parent);

            UniqueNamer uniqueNamer = new UniqueNamer(m_suffixSeparator);
            foreach (DomNode parent in parents)
            {
                // first, initialize namer with the names of the children whose names haven't changed
                foreach (DomNode child in parent.Children)
                {
                    if (child.Type.IdAttribute != null &&
                        !renamed.ContainsKey(child))
                    {
                        string id = child.GetId();
                        uniqueNamer.Name(id);
                    }
                }

                // now, generate unique ids for the added children
                foreach (DomNode child in parent.Children)
                {
                    if (child.Type.IdAttribute != null &&
                        renamed.ContainsKey(child))
                    {
                        NameNode(child, uniqueNamer);
                    }
                }

                uniqueNamer.Clear();
            }
        }