Beispiel #1
0
        /// <summary>
        /// Creates a new Workplane relative to an entity and adds it to the collection.
        /// </summary>
        /// <param name="entity">The entity on which to create the new Workplane.</param>
        /// <param name="origin">The intended origin for the workplane.</param>
        /// <returns>The created workplane.</returns>
        public PSWorkplane CreateWorkplaneAlignedToEntity(PSEntity entity, Geometry.Point origin)
        {
            PSWorkplane newWorkplane = new PSWorkplane(_powerSHAPE, entity, origin);

            Add(newWorkplane);
            return(newWorkplane);
        }
        /// <summary>
        /// A test for RemoveToSelection
        /// </summary>
        public virtual void RemoveFromSelectionTest(string multipleEntitiesFile, string singleEntitiesFile)
        {
            // Import multiple entities
            _powerSHAPE.ActiveModel.Import(new FileSystem.File(multipleEntitiesFile));

            // Import single entity
            _powerSHAPE.ActiveModel.Import(new FileSystem.File(singleEntitiesFile));

            // Get single entity
            PSEntity testEntity = _powerSHAPE.ActiveModel.SelectedItems[0];

            // Select everything
            _powerSHAPE.ActiveModel.SelectAll(true);

            // Remove entities from selection
            ((PSEntitiesCollection <T>)_powerSHAPECollection).RemoveFromSelection();

            // Check the selection contains only the single entity
            if (_powerSHAPE.ActiveModel.SelectedItems.Count == 0) // Everything was deselected
            {
                Assert.Fail("Deselected all entities in PowerSHAPE");
            }
            else if (_powerSHAPE.ActiveModel.SelectedItems.Count == 4) // Nothing was deselected
            {
                Assert.Fail("Deselected nothing in PowerSHAPE");
            }
            else if (_powerSHAPE.ActiveModel.SelectedItems.Count != 1) // More than just the single entity is selected
            {
                Assert.Fail("Failed to remove all " + _collectionType.ToLower() + "s from selection");
            }

            Assert.AreEqual(_powerSHAPE.ActiveModel.SelectedItems[0],
                            testEntity,
                            "Removed incorrect entities from the selection");
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new Workplane relative to an entity and adds it to the collection.
        /// </summary>
        /// <param name="entity">The entity on which to create the new Workplane.</param>
        /// <param name="positionAtEntity">The position on the entity at which to create the workplane: Centre, Top, Bottom.</param>
        /// <returns>The created workplane.</returns>
        public PSWorkplane CreateWorkplaneAtEntity(PSEntity entity, NewWorkplaneInEntityPositions positionAtEntity)
        {
            PSWorkplane newWorkplane = new PSWorkplane(_powerSHAPE, entity, positionAtEntity);

            Add(newWorkplane);
            return(newWorkplane);
        }
Beispiel #4
0
        /// <summary>
        /// A test for Equals
        /// </summary>
        public virtual void EqualsTest(string file)
        {
            // Create comparison
            PSEntity comparisonDatabaseEntity = ImportAndGetEntity(file);

            // Compare collections
            Assert.IsTrue(_powerSHAPECollection[0].Equals(comparisonDatabaseEntity),
                          "Incorrectly returned that entities were not equal");
        }
Beispiel #5
0
        /// <summary>
        /// A test for Id
        /// </summary>
        public virtual void IdTest(string file)
        {
            // Import entity
            PSEntity importedEntity = ImportAndGetEntity(file);

            // Check that the id is correct
            Assert.AreEqual(_powerSHAPE.ExecuteEx(IdentifierAccessor(importedEntity) + "[" + importedEntity.Name + "].ID"),
                            importedEntity.Id,
                            "Returned incorrect id");
        }
        /// <summary>
        /// Creates instance objects based on a string identifying an item's type in PowerSHAPE.
        /// </summary>
        /// <param name="powerSHAPE">The base instance to interact with PowerShape.</param>
        /// <param name="type">The identifier PowerSHAPE uses to identify this type of entity.</param>
        /// <param name="id">The identifier of the entity.</param>
        /// <param name="name">The name of the entity.</param>
        /// <returns>The new entity.</returns>
        internal static object CreateEntity(PSAutomation powerSHAPE, string type, int id, string name)
        {
            PSEntity entity = null;

            switch (type.ToUpper())
            {
            case PSAnnotation.ANNOTATION_IDENTIFIER:
                entity = new PSAnnotation(powerSHAPE, id, name);
                break;

            case PSArc.ARC_IDENTIFIER:
                entity = new PSArc(powerSHAPE, id, name);
                break;

            case PSCompCurve.COMPCURVE_IDENTIFIER:
            case "COMPOSITE CURVE":
                entity = new PSCompCurve(powerSHAPE, id, name);
                break;

            case PSCurve.CURVE_IDENTIFIER:
                entity = new PSCurve(powerSHAPE, id, name);
                break;

            case PSElectrode.ELECTRODE_IDENTIFIER:
                entity = new PSElectrode(powerSHAPE, id, name);
                break;

            case PSLine.LINE_IDENTIFIER:
                entity = new PSLine(powerSHAPE, id, name);
                break;

            case PSPoint.POINT_IDENTIFIER:
                entity = new PSPoint(powerSHAPE, id, name);
                break;

            case PSSolid.SOLID_IDENTIFIER:
                entity = (PSEntity)PSSolidFactory.CreateSolid(powerSHAPE, id, name);
                break;

            case PSMesh.MESH_IDENTIFIER:
                entity = new PSMesh(powerSHAPE, id, name);
                break;

            case PSSurface.SURFACE_IDENTIFIER:
                entity = (PSEntity)PSSurfaceFactory.CreateSurface(powerSHAPE, id, name);
                break;

            case PSWorkplane.WORKPLANE_IDENTIFIER:
                entity = new PSWorkplane(powerSHAPE, id, name);
                break;
            }

            return(entity);
        }
        /// <summary>
        /// This test checks that the Entity's Identifier is as expected
        /// </summary>
        public override void IdentifierTest(FileSystem.File fileToImport, string expectedIdentifier)
        {
            // Get entity
            PSEntity importedEntity = ImportAndGetEntity(fileToImport);

            // Check that the collection Identifier matches the entity type
            string actualIdentifier = (string)importedEntity
                                      .GetType().GetProperty("Identifier", BindingFlags.NonPublic | BindingFlags.Instance)
                                      .GetValue(importedEntity, null);

            Assert.AreEqual(expectedIdentifier, actualIdentifier);
        }
Beispiel #8
0
        /// <summary>
        /// A test for Exists
        /// </summary>
        public virtual void ExistsTest(string file)
        {
            // Import entity
            PSEntity entity = ImportAndGetEntity(file);

            // Check that correct value is returned
            Assert.IsTrue(entity.Exists, "Incorrectly stated that entity did not exist");

            // Delete entity and check again
            entity.Delete();
            Assert.IsFalse(entity.Exists, "Incorrectly stated that entity existed");
        }
        public void AddMeshesToSelectionTest()
        {
            // Import three entities to be deleted
            _powerSHAPE.ActiveModel.Import(new FileSystem.File(TestFiles.SINGLE_MESH1));
            _powerSHAPE.ActiveModel.Import(new FileSystem.File(TestFiles.SINGLE_MESH2));
            _powerSHAPE.ActiveModel.Import(new FileSystem.File(TestFiles.SINGLE_MESH3));

            // Import single entity to remain
            _powerSHAPE.ActiveModel.Import(new FileSystem.File(TestFiles.SINGLE_SURFACE));

            // Get single entity
            PSEntity testEntity = _powerSHAPE.ActiveModel.SelectedItems[0];

            // Clear selection
            _powerSHAPE.ActiveModel.ClearSelectedItems();

            // Add multiple entities to selection
            ((PSEntitiesCollection <PSMesh>)_powerSHAPECollection).AddToSelection(true);

            // Check the selection contains all three entities
            if (_powerSHAPE.ActiveModel.SelectedItems.Count == 0) // Nothing was selected
            {
                Assert.Fail("Failed to select anything in PowerSHAPE");
            }
            else if (_powerSHAPE.ActiveModel.SelectedItems.Count == 4) // Everything was selected
            {
                Assert.Fail("Selected everything in PowerSHAPE");
            }

            // Check the test entity is not selected
            foreach (PSEntity selectedEntity in _powerSHAPE.ActiveModel.SelectedItems)
            {
                if (selectedEntity.Equals(testEntity)) // Test entity is in selection
                {
                    Assert.Fail("Added other entities to selection");
                }
            }
            Assert.AreEqual(_powerSHAPE.ActiveModel.SelectedItems.Count,
                            3,
                            "Failed to add all " + _collectionType.ToLower() + " to collection");
        }
Beispiel #10
0
        public void AddElectrodesToSelectionTest()
        {
            _powerSHAPE.Models.CreateModelFromFile(new File(TestFiles.THREE_ELECTRODES_MODEL));

            // Import single entity to remain
            _powerSHAPE.ActiveModel.Import(new File(TestFiles.SINGLE_SURFACE));

            // Get single entity
            PSEntity testEntity = _powerSHAPE.ActiveModel.SelectedItems[0];

            // Clear selection
            _powerSHAPE.ActiveModel.ClearSelectedItems();

            // Add multiple entities to selection
            _powerSHAPE.ActiveModel.Electrodes.AddToSelection(true);

            // Check the selection contains all three entities
            if (_powerSHAPE.ActiveModel.SelectedItems.Count == 0) // Nothing was selected
            {
                Assert.Fail("Failed to select anything in PowerSHAPE");
            }
            else if (_powerSHAPE.ActiveModel.SelectedItems.Count == 4) // Everything was selected
            {
                Assert.Fail("Selected everything in PowerSHAPE");
            }

            // Check the test entity is not selected
            foreach (PSEntity selectedEntity in _powerSHAPE.ActiveModel.SelectedItems)
            {
                if (selectedEntity.Equals(testEntity)) // Test entity is in selection
                {
                    Assert.Fail("Added other entities to selection");
                }
            }
            Assert.AreEqual(_powerSHAPE.ActiveModel.SelectedItems.Count,
                            3,
                            "Failed to add all " + _collectionType.ToLower() + " to collection");
        }
Beispiel #11
0
        public void RemoveElectrodesFromSelectionTest()
        {
            // Import file with three entities
            _powerSHAPE.Models.CreateModelFromFile(new File(TestFiles.THREE_ELECTRODES_MODEL));
            _powerSHAPECollection = _powerSHAPE.ActiveModel.Electrodes;

            // Import single entity
            _powerSHAPE.ActiveModel.Import(new File(TestFiles.SINGLE_SURFACE));

            // Get single entity
            PSEntity testEntity = _powerSHAPE.ActiveModel.SelectedItems[0];

            // Select everything
            _powerSHAPE.ActiveModel.SelectAll(true);

            // Remove entities from selection
            ((PSEntitiesCollection <PSElectrode>)_powerSHAPECollection).RemoveFromSelection();

            // Check the selection contains only the single entity
            if (_powerSHAPE.ActiveModel.SelectedItems.Count == 0) // Everything was deselected
            {
                Assert.Fail("Deselected all entities in PowerSHAPE");
            }
            else if (_powerSHAPE.ActiveModel.SelectedItems.Count == 4) // Nothing was deselected
            {
                Assert.Fail("Deselected nothing in PowerSHAPE");
            }
            else if (_powerSHAPE.ActiveModel.SelectedItems.Count != 1) // More than just the single entity is selected
            {
                Assert.Fail("Failed to remove all " + _collectionType.ToLower() + "s from selection");
            }

            Assert.AreEqual(_powerSHAPE.ActiveModel.SelectedItems[0],
                            testEntity,
                            "Removed incorrect entities from the selection");
        }
        /// <summary>
        /// Creates instance objects based on a string identifying an item's type in PowerSHAPE.
        /// </summary>
        /// <param name="powerSHAPE">The base instance to interact with PowerShape.</param>
        /// <param name="type">The identifier PowerSHAPE uses to identify this type of entity.</param>
        /// <param name="id">The identifier of the entity.</param>
        /// <param name="name">The name of the entity.</param>
        /// <returns>The new entity.</returns>
        internal static object CreateEntity(
            PSAutomation powerSHAPE,
            int type,
            int id,
            string name,
            string description,
            string level)
        {
            PSEntity entity = null;

            switch (type)
            {
            case 61:
                entity = new PSAnnotation(powerSHAPE, id, name);
                break;

            case 52:
                entity = new PSArc(powerSHAPE, id, name);
                break;

            case 59:
                entity = new PSCompCurve(powerSHAPE, id, name);
                break;

            case 53:
                entity = new PSCurve(powerSHAPE, id, name);
                break;

            case 58:
                entity = new PSLine(powerSHAPE, id, name);
                break;

            case 49:
                entity = new PSPoint(powerSHAPE, id, name);
                break;

            case 40:
                entity = (PSEntity)PSSolidFactory.CreateSolid(powerSHAPE, id, name, description);
                break;

            case 60:
                switch (description)
                {
                case "Mesh":
                    entity = new PSMesh(powerSHAPE, id, name);
                    break;

                case "Point":
                    entity = new PSPoint(powerSHAPE, id, name);
                    break;

                case "Electrode":
                    entity = new PSElectrode(powerSHAPE, id, name);
                    break;
                }
                break;

            case 21:
                entity = (PSEntity)PSSurfaceFactory.CreateSurface(powerSHAPE, id, name, description);
                break;

            case 54:
                entity = new PSWorkplane(powerSHAPE, id, name);
                break;
            }

            if (entity != null)
            {
                entity._levelNumber = int.Parse(level);
            }

            return(entity);
        }