Пример #1
0
        public void Instance()
        {
            this.Name = "Elements_ElementInstance";

            // <example>
            // Create a test user element.
            var profile  = new Profile(Polygon.Rectangle(1.0, 1.0));
            var material = new Material("yellow", Colors.Yellow);
            var line     = new Line(Vector3.Origin, new Vector3(5, 5, 5));

            // Set the isElementDefinition parameter to true,
            // so the element is considered an instance definition.
            var testUserElement = new TestUserElement(line, profile, material, isElementDefinition: true);

            // Create instances of that element
            // with varied transforms.
            var attractor = new Vector3(30, 20);

            for (var x = 0.0; x < 50; x += 1.5)
            {
                for (var y = 0.0; y < 50; y += 1.5)
                {
                    var loc = new Vector3(x, y);
                    var d   = loc.DistanceTo(attractor);
                    var s   = d == 0 ? 1 : 5 * Math.Sin(1 / d);
                    var t   = new Transform();
                    t.Scale(new Vector3(s, s, s));
                    t.Move(loc);
                    var instance = testUserElement.CreateInstance(t, $"Test User Element {x}:{y}");
                    this.Model.AddElement(instance);
                }
            }
            // </example>
        }
Пример #2
0
        public void CreateCustomElement()
        {
            this.Name = "UserElement";

            var line = new Line(Vector3.Origin, new Vector3(5, 5, 5));
            var m    = new Material("UserElementGreen", Colors.Green);
            var ue   = new TestUserElement(line, new Profile(Polygon.L(1, 2, 0.5)), m);

            var p  = new Profile(Polygon.Rectangle(1, 1));
            var m1 = new Mass(p, 1, BuiltInMaterials.Wood);

            ue.SubElements.Add(m1);

            this.Model.AddElement(ue);

            var json     = this.Model.ToJson();
            var newModel = Model.FromJson(json, out var errors);

            Assert.Empty(errors);
            var newUe = newModel.AllElementsOfType <TestUserElement>().First();

            // Plus one because of the profile that will be added from
            // UpdateRepresentation() call during serialization.
            Assert.Equal(this.Model.Elements.Count + 1, newModel.Elements.Count);

            Assert.Equal(ue.Representation.SolidOperations.Count, newUe.Representation.SolidOperations.Count);
            Assert.Equal(ue.Id, newUe.Id);
            Assert.Equal(ue.Transform, newUe.Transform);

            // Three profiles.
            // 1. The user element
            // 2. The one for the sub-element masses.
            // 3. The one created during UpdateRepresentation
            Assert.Equal(3, newModel.AllElementsOfType <Profile>().Count());
        }
Пример #3
0
        public void CreateCustomElement()
        {
            this.Name = "UserElement";

            var line = new Line(Vector3.Origin, new Vector3(5, 5, 5));
            var m    = new Material("UserElementGreen", Colors.Green);
            var ue   = new TestUserElement(line, new Profile(Polygon.L(1, 2, 0.5)), m);

            var p  = new Profile(Polygon.Rectangle(1, 1));
            var m1 = new Mass(p, 1, BuiltInMaterials.Wood);

            ue.SubElements.Add(m1);

            this.Model.AddElement(ue);

            var json     = this.Model.ToJson();
            var newModel = Model.FromJson(json);
            var newUe    = newModel.AllElementsOfType <TestUserElement>().First();

            Assert.Equal(6, newModel.Elements.Count);
            Assert.Equal(ue.Representation.SolidOperations.Count, newUe.Representation.SolidOperations.Count);
            Assert.Equal(ue.Id, newUe.Id);
            Assert.Equal(ue.Transform, newUe.Transform);

            // Two profiles. The one for the user element
            // and the one for the sub-element masses.
            Assert.Equal(2, newModel.AllElementsOfType <Profile>().Count());
        }
Пример #4
0
        public void ProfilesInRepresentationsAreAddedToModel()
        {
            var model = new Model();
            var line  = new Line(Vector3.Origin, new Vector3(5, 5, 5));
            var ue    = new TestUserElement(line, new Profile(Polygon.L(1, 2, 0.5)));

            ue.UpdateRepresentations();
            model.AddElement(ue);
            Assert.Equal(2, model.AllElementsOfType <Profile>().Count());
        }
Пример #5
0
        public void SubDictionaryOfElementIsAddedToModel()
        {
            var model = new Model();
            var line  = new Line(Vector3.Origin, new Vector3(5, 5, 5));
            var ue    = new TestUserElement(line, new Profile(Polygon.L(1, 2, 0.5)));

            ue.DictionaryElements["foo"] = BuiltInMaterials.XAxis;
            ue.DictionaryElements["bar"] = BuiltInMaterials.YAxis;
            model.AddElement(ue);
            Assert.Equal(3, model.AllElementsOfType <Material>().Count());
        }
Пример #6
0
        public void SubElementIsAddedToModel()
        {
            var model = new Model();
            var line  = new Line(Vector3.Origin, new Vector3(5, 5, 5));
            var ue    = new TestUserElement(line, new Profile(Polygon.L(1, 2, 0.5)));

            model.AddElement(ue);

            // The profile of the user element and the one
            // created inside UpdateRepresentation.
            Assert.Equal(2, model.AllElementsOfType <Profile>().Count());
        }
Пример #7
0
        public void SubListElementIsAddedToModel()
        {
            var model = new Model();
            var line  = new Line(Vector3.Origin, new Vector3(5, 5, 5));
            var ue    = new TestUserElement(line, new Profile(Polygon.L(1, 2, 0.5)));

            ue.SubElements.AddRange(new[] {
                new Mass(Polygon.Rectangle(1, 1)),
                new Mass(Polygon.L(2, 2, 1))
            });
            model.AddElement(ue);

            // The profiles from the user element, the two sub elements
            // and one profile generated in UpdateRepresentations.
            Assert.Equal(4, model.AllElementsOfType <Profile>().Count());
        }
Пример #8
0
        public void CreateCustomElement()
        {
            this.Name = "UserElement";

            var line = new Line(Vector3.Origin, new Vector3(5, 5, 5));
            var m    = new Material("UserElementGreen", Colors.Green);
            var ue   = new TestUserElement(line, new Profile(Polygon.L(1, 2, 0.5)), m);

            var p  = new Profile(Polygon.Rectangle(1, 1));
            var m1 = new Mass(p, 1, BuiltInMaterials.Wood);

            ue.SubElements.Add(m1);

            this.Model.AddElement(ue);

            var json     = this.Model.ToJson();
            var newModel = Model.FromJson(json, out var errors);

            Assert.Empty(errors);
            var newUe = newModel.AllElementsOfType <TestUserElement>().First();

            // Plus one because of the profile that will be added from
            // UpdateRepresentation() call during serialization.
            Assert.Equal(this.Model.Elements.Count + 1, newModel.Elements.Count);

            Assert.Equal(ue.Representation.SolidOperations.Count, newUe.Representation.SolidOperations.Count);
            Assert.Equal(ue.Id, newUe.Id);
            Assert.Equal(ue.Transform, newUe.Transform);

            // Three profiles.
            // 1. The user element
            // 2. The one for the sub-element masses.
            // 3. The one created during UpdateRepresentation
            // 4. The one created when the model is deserialized
            //    and update representation is called while adding elements.
            // TODO: This is not good. This creates a new profile in the model
            // during every subsequent deserialization. As a general rule,
            // update representations should not be used to create new elements.
            Assert.Equal(4, newModel.AllElementsOfType <Profile>().Count());
        }