/// <summary> /// Limits an arc by a specified list of entities. /// </summary> /// <param name="limitingEntities">The entities with which to perform the limiting operation.</param> /// <param name="limitingMode">The mode in which to carry out the operation.</param> /// <param name="keepOption">Whether to keep one or both sides of the limit.</param> /// <param name="trimOption">Whether to trim one or all of the entities.</param> /// <param name="finishOperation">If true, turns edit selection off.</param> /// <returns>A list of limited entities.</returns> public List <PSEntity> LimitToEntities( List <PSEntity> limitingEntities, LimitingModes limitingMode = LimitingModes.LimitMode, LimitingKeepOptions keepOption = LimitingKeepOptions.KeepOne, LimitingTrimOptions trimOption = LimitingTrimOptions.LimitOne, bool finishOperation = true) { return(PSEntityLimiter.LimitEntity(this, limitingEntities, limitingMode, keepOption, trimOption, finishOperation)); }
/// <summary> /// Limits a single entity using a list of entities. /// </summary> /// <param name="entityToLimit">The entity on which to perform the limiting operation.</param> /// <param name="limitingEntities">The entities with which to perform the limiting operation.</param> /// <param name="limitingMode">The mode in which to carry out the operation.</param> /// <param name="keepOption">Whether to keep one or both sides of the limit.</param> /// <param name="trimOption">Whether to trim one or all of the entities.</param> internal static List <PSEntity> LimitEntity( IPSLimitable entityToLimit, List <PSEntity> limitingEntities, LimitingModes limitingMode = LimitingModes.LimitMode, LimitingKeepOptions keepOption = LimitingKeepOptions.KeepOne, LimitingTrimOptions trimOption = LimitingTrimOptions.LimitOne, bool finishOperation = true) { // Create a list of the single entity List <IPSLimitable> entitiesToLimit = new List <IPSLimitable>(); entitiesToLimit.Add(entityToLimit); // Carry out limit operation return(LimitEntities(entitiesToLimit, limitingEntities, limitingMode, keepOption, trimOption, finishOperation)); }
/// <summary> /// A test for LimitToEntities /// </summary> public void LimitToEntitiesTest( string entityToLimitFile, string entitiesToLimitAgainstFile, LimitingModes limitingMode) { // Get entity var entityToLimit = (IPSLimitable)ImportAndGetEntity(entityToLimitFile); // Import multiple entities _powerSHAPE.ActiveModel.Import(new File(entitiesToLimitAgainstFile)); // Add new entities to list _powerSHAPE.ActiveModel.SelectAll(true); ((PSEntity)entityToLimit).RemoveFromSelection(); var entitiesToLimitAgainst = _powerSHAPE.ActiveModel.SelectedItems.ToList(); // Limit entity entityToLimit.LimitToEntities(entitiesToLimitAgainst, limitingMode); Assert.AreEqual(3, _powerSHAPECollection.Count, "Entity was not limited"); }
/// <summary> /// Limits entities using a list of entities. /// </summary> /// <param name="entitiesToLimit">The entities on which to perform the limiting operation.</param> /// <param name="limitingEntities">The entities with which to perform the limiting operation.</param> /// <param name="limitingMode">The mode in which to carry out the operation.</param> /// <param name="keepOption">Whether to keep one or both sides of the limit.</param> /// <param name="trimOption">Whether to trim one or all of the entities.</param> internal static List <PSEntity> LimitEntities( List <IPSLimitable> entitiesToLimit, List <PSEntity> limitingEntities, LimitingModes limitingMode = LimitingModes.LimitMode, LimitingKeepOptions keepOption = LimitingKeepOptions.KeepOne, LimitingTrimOptions trimOption = LimitingTrimOptions.LimitOne, bool finishOperation = true) { // Get PowerSHAPE instance _powerSHAPE = ((PSEntity)entitiesToLimit[0]).PowerSHAPE; // Clear the selection _powerSHAPE.ActiveModel.ClearSelectedItems(); // Select all the entities with which to do the limit foreach (PSEntity entity in limitingEntities) { entity.AddToSelection(false); } // Do the limit _powerSHAPE.DoCommand("EDIT SELECTION"); _powerSHAPE.DoCommand(keepOption.ToString()); if (trimOption == LimitingTrimOptions.LimitOne) { _powerSHAPE.DoCommand("TRIM ONE"); } else { _powerSHAPE.DoCommand("TRIM BOTH"); } switch (limitingMode) { case LimitingModes.LimitMode: _powerSHAPE.DoCommand("PROFILING LIMIT"); break; case LimitingModes.ProjectMode: _powerSHAPE.DoCommand("PROFILING PROJECT"); break; case LimitingModes.ProjectViewMode: _powerSHAPE.DoCommand("PROFILING PROJECT_VIEW"); break; case LimitingModes.ProjectSurfaceNormalMode: _powerSHAPE.DoCommand("PROFILING MAKEPCU"); break; case LimitingModes.IntersectCurveMode: _powerSHAPE.DoCommand("PROFILING SURFCURVEINT"); break; } // Select all the entities on which to perform the limit foreach (PSEntity entity in entitiesToLimit) { entity.AddToSelection(false); } // Add any new entities to the list of entities List <PSEntity> newEntities = new List <PSEntity>(); if (_powerSHAPE.ActiveModel.CreatedItems.Count == 0) { return(newEntities); } foreach (PSEntity newEntity in _powerSHAPE.ActiveModel.CreatedItems) { newEntity.Id = _powerSHAPE.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID"); _powerSHAPE.ActiveModel.Add(newEntity); newEntities.Add(newEntity); } //Ensure also updated entities are retrieved too when keep both is selected if (keepOption == LimitingKeepOptions.KeepBoth) { foreach (PSEntity itme in _powerSHAPE.ActiveModel.UpdatedItems) { var updatedEntity = itme; updatedEntity.Id = _powerSHAPE.ReadIntValue(updatedEntity.Identifier + "['" + updatedEntity.Name + "'].ID"); if (!newEntities.Exists(x => x.Id == updatedEntity.Id)) { newEntities.Add(updatedEntity); } } } // Finish operation if (finishOperation) { _powerSHAPE.DoCommand("EDIT SELECTION OFF"); } // Doing this changes the ID of the new entities but the names stay the same so get the new IDs foreach (PSEntity limitedEntity in entitiesToLimit) { limitedEntity.Id = _powerSHAPE.ReadIntValue(limitedEntity.Identifier + "['" + limitedEntity.Name + "'].ID"); } return(newEntities); }