Example #1
0
        /// <summary>
        /// Perform Add, Cut, Intersect operations on solid bodies.
        /// </summary>
        /// <param name="body"></param>
        /// <param name="type"></param>
        /// <param name="tool"></param>
        /// <returns></returns>
        public static OperationsResult OperationsTs(this IBody2 body, swBodyOperationType_e type, IBody2 tool)
        {
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }
            if (tool == null)
            {
                throw new ArgumentNullException(nameof(tool));
            }

            tool = tool.CopyTs();
            body = body.CopyTs();

            int error;
            var objects = (object[])body.Operations2((int)type, tool, out error);

            if (objects == null)
            {
                return(new OperationsResult(error, new IBody2[] {}));
            }

            var bodies = error == 0 ?  objects.Cast <IBody2>().ToArray() : new IBody2[] {};

            return(new OperationsResult(error, bodies));
        }
Example #2
0
        /// <summary>
        /// There is no need to make a copy of bodies passed to this method.  Returns the first resulting body only.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="tool"></param>
        /// <param name="operation"></param>
        /// <returns>Return the first body of the result</returns>
        private Body2 BodyOperation(Body2 target, Body2 tool, swBodyOperationType_e operation)
        {
            var intersectBodies = (target.ICopy().Operations2((int)operation, tool.ICopy(), out int intError)) as object[];

            if (intError == 0) // swBodyOperationNoError
            {
                return(intersectBodies[0] as Body2);
            }
            else
            {
                if (intError == -1)
                {
                    throw new Exception("swBodyOperationUnknownError");
                }
                else
                {
                    var error = (swBodyOperationError_e)intError;
                    throw new Exception($"{error}");
                }
            }
        }