/* * private static Tuple<FaceStatus, FaceStatus, FaceStatus> GetFaceStatusesFromOperationType( * CsgOperationType opType) * { * switch (opType) * { * case CsgOperationType.Union: * return new Tuple<FaceStatus, FaceStatus, FaceStatus>(FaceStatus.Outside, FaceStatus.Same, * FaceStatus.Outside); * case CsgOperationType.Negate: * return new Tuple<FaceStatus, FaceStatus, FaceStatus>(FaceStatus.Outside, FaceStatus.Opposite, * FaceStatus.Inside); * case CsgOperationType.Intersection: * return new Tuple<FaceStatus, FaceStatus, FaceStatus>(FaceStatus.Inside, FaceStatus.Same, * FaceStatus.Inside); * default: * throw new ArgumentOutOfRangeException(); * } * } */ /* * private static void PrepareOperation(Part a, Part b, out Solid lhs, out Solid rhs, out CsgOperationType opType) * { * lhs = null; * rhs = null; * opType = 0; * * if (a is NegateOperation || b is NegateOperation) * { * if (a is NegateOperation && b is NegateOperation) // two subtractions make a union * { * opType = CsgOperationType.Union; * } * else * { * opType = CsgOperationType.Negate; * if (a is NegateOperation) // subtraction is always on right hand side. * { * lhs = Test(b); * rhs = Test(a); * } * else * { * lhs = Test(a); * rhs = Test(b); * } * } * } * else if (a is IntersectOperation || b is IntersectOperation) * { * if (a is IntersectOperation && b is IntersectOperation) // two intersections make a union * { * opType = CsgOperationType.Union; * } * else * { * opType = CsgOperationType.Intersection; * if (a is IntersectOperation) // intersection is always on right hand side. * { * lhs = Test(b); * rhs = Test(a); * } * else * { * lhs = Test(a); * rhs = Test(b); * } * } * } * else // both a and b are either regular Parts or UnionOperations. * { * opType = CsgOperationType.Union; * lhs = Test(b); * rhs = Test(a); * } * } */ /// <summary> /// Seperates a fused object. /// </summary> internal static IEnumerable <Part> Seperate(PartOperation fused) { /* * using (var stream = new MemoryStream(fused.OperationData)) * { * var pair = dAsset.Deserialize<CSGPair>(stream, null); * * var a = pair.A; * a.Parent = fused.Parent; * * var b = pair.B; * if (b != null) b.Parent = fused.Parent; * * fused.Destroy(); * * return new[] {a, b}; * } */ throw new NotImplementedException(); }
//We do the close or the flush operation per part private void DoOperationOnEachPart(PartOperation operation) { //foreach (PackagePart p in _partList.Values) // p.Close(); - this throws // Make local copy of part names to prevent exception during enumeration when // a new relationship part gets created (flushing relationships can cause part creation). // This code throws in such a case: // // foreach (PackagePart p in _partList.Values) // p.Flush(); // if (_partList.Count > 0) { int partCount = 0; PackUriHelper.ValidatedPartUri[] partKeys = new PackUriHelper.ValidatedPartUri[_partList.Keys.Count]; foreach (PackUriHelper.ValidatedPartUri uri in _partList.Keys) { partKeys[partCount++] = uri; } // this throws an exception in certain cases (when a part has been deleted) // // _partList.Keys.CopyTo(keys, 0); for (int i = 0; i < _partList.Keys.Count; i++) { // Some of these may disappear during above close because the list contains "relationship parts" // and these are removed if their parts' relationship collection is empty // This fails: // _partList[keys[i]].Flush(); PackagePart p; if (_partList.TryGetValue(partKeys[i], out p)) { if (!operation(p)) break; } } } }