Beispiel #1
0
        /// <summary>
        /// Assumes that the tools are non overlapping sheets and that the sheets fully
        /// overlap the target. The target should be cut into N+1 parts of there are N
        /// tools. They
        /// </summary>
        /// <param name="target"></param>
        /// <param name="tools"></param>
        /// <returns></returns>
        public static IEnumerable <IBody2> CutBySheets(this IBody2 target, IEnumerable <IBody2> tools)
        {
            var targets = new List <IBody2>()
            {
                target.CopyTs()
            };

            foreach (var tool in tools)
            {
                targets = targets.SelectMany
                              (tgt =>
                {
                    var result = tgt.Cut(tool);
                    if (result.Error != 0)
                    {
                        return new[] { tgt }
                    }
                    ;
                    //throw new Exception("Tool was unable to cut");
                    return(result.Bodies);
                })
                          .ToList();
            }
            return(targets);
        }
Beispiel #2
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));
        }