/// <summary> /// Return geometry for a particular representation item. /// </summary> /// <param name="shapeEditScope">The shape edit scope.</param> /// <param name="lcs">Local coordinate system for the geometry, without scale.</param> /// <param name="scaledLcs">Local coordinate system for the geometry, including scale, potentially non-uniform.</param> /// <param name="guid">The guid of an element for which represntation is being created.</param> /// <returns>The created geometry.</returns> /// <remarks>As this doesn't inherit from IfcSolidModel, this is a non-virtual CreateGeometry function.</remarks> protected IList<GeometryObject> CreateGeometry(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { if (Shells.Count == 0) return null; using (IFCImportShapeEditScope.IFCTargetSetter setter = new IFCImportShapeEditScope.IFCTargetSetter(shapeEditScope, TessellatedShapeBuilderTarget.AnyGeometry, TessellatedShapeBuilderFallback.Mesh)) { shapeEditScope.StartCollectingFaceSet(); foreach (IFCConnectedFaceSet faceSet in Shells) faceSet.CreateShape(shapeEditScope, lcs, scaledLcs, guid); IList<GeometryObject> geomObjs = shapeEditScope.CreateGeometry(guid); if (geomObjs == null || geomObjs.Count == 0) return null; return geomObjs; } }
/// <summary> /// Return geometry for a particular representation item. /// </summary> /// <param name="shapeEditScope">The geometry creation scope.</param> /// <param name="lcs">Local coordinate system for the geometry, without scale.</param> /// <param name="scaledLcs">Local coordinate system for the geometry, including scale, potentially non-uniform.</param> /// <param name="guid">The guid of an element for which represntation is being created.</param> /// <returns>The created geometry.</returns> public IList<GeometryObject> CreateGeometry( IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { IList<GeometryObject> firstSolids = FirstOperand.CreateGeometry(shapeEditScope, lcs, scaledLcs, guid); if (firstSolids != null) { foreach (GeometryObject potentialSolid in firstSolids) { if (!(potentialSolid is Solid)) { IFCImportFile.TheLog.LogError((FirstOperand as IFCRepresentationItem).Id, "Can't perform Boolean operation on a Mesh.", false); return firstSolids; } } } IList<GeometryObject> secondSolids = null; if (SecondOperand != null) { try { using (IFCImportShapeEditScope.IFCTargetSetter setter = new IFCImportShapeEditScope.IFCTargetSetter(shapeEditScope, TessellatedShapeBuilderTarget.Solid, TessellatedShapeBuilderFallback.Abort)) { secondSolids = SecondOperand.CreateGeometry(shapeEditScope, lcs, scaledLcs, guid); } } catch (Exception ex) { // We will allow something to be imported, in the case where the second operand is invalid. // If the first (base) operand is invalid, we will still fail the import of this solid. if (SecondOperand is IFCRepresentationItem) IFCImportFile.TheLog.LogError((SecondOperand as IFCRepresentationItem).Id, ex.Message, false); else throw ex; secondSolids = null; } } IList<GeometryObject> resultSolids = null; if (firstSolids == null) resultSolids = secondSolids; else if (secondSolids == null) resultSolids = firstSolids; else { BooleanOperationsType booleanOperationsType = BooleanOperationsType.Difference; switch (BooleanOperator) { case IFCBooleanOperator.Difference: booleanOperationsType = BooleanOperationsType.Difference; break; case IFCBooleanOperator.Intersection: booleanOperationsType = BooleanOperationsType.Intersect; break; case IFCBooleanOperator.Union: booleanOperationsType = BooleanOperationsType.Union; break; default: IFCImportFile.TheLog.LogError(Id, "Invalid BooleanOperationsType.", true); break; } resultSolids = new List<GeometryObject>(); foreach (GeometryObject firstSolid in firstSolids) { Solid resultSolid = (firstSolid as Solid); int secondId = (SecondOperand == null) ? -1 : (SecondOperand as IFCRepresentationItem).Id; foreach (GeometryObject secondSolid in secondSolids) { resultSolid = IFCGeometryUtil.ExecuteSafeBooleanOperation(Id, secondId, resultSolid, secondSolid as Solid, booleanOperationsType); if (resultSolid == null) break; } if (resultSolid != null) resultSolids.Add(resultSolid); } } return resultSolids; }
/// <summary> /// Create geometry for a particular representation. /// </summary> /// <param name="shapeEditScope">The geometry creation scope.</param> /// <param name="lcs">Local coordinate system for the geometry, without scale.</param> /// <param name="scaledLcs">Local coordinate system for the geometry, including scale, potentially non-uniform.</param> /// <param name="guid">The guid of an element for which represntation is being created.</param> public void CreateShape(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { // We are not yet displaying Axis information, but do (potentially) need the Axis curve for generating material layer-based extrusions. if (Identifier == IFCRepresentationIdentifier.Axis) return; if (LayerAssignment != null) LayerAssignment.Create(shapeEditScope); // There is an assumption here that Process() weeded out any items that are invalid for this representation. using (IFCImportShapeEditScope.IFCMaterialStack stack = new IFCImportShapeEditScope.IFCMaterialStack(shapeEditScope, null, LayerAssignment)) { using (IFCImportShapeEditScope.IFCContainingRepresentationSetter repSetter = new IFCImportShapeEditScope.IFCContainingRepresentationSetter(shapeEditScope, this)) { foreach (IFCRepresentationItem representationItem in RepresentationItems) { using (IFCImportShapeEditScope.IFCTargetSetter setter = new IFCImportShapeEditScope.IFCTargetSetter(shapeEditScope, TessellatedShapeBuilderTarget.AnyGeometry, TessellatedShapeBuilderFallback.Mesh)) { representationItem.CreateShape(shapeEditScope, lcs, scaledLcs, guid); } } } } }
/// <summary> /// Return geometry for a particular representation item. /// </summary> /// <param name="shapeEditScope">The shape edit scope.</param> /// <param name="lcs">Local coordinate system for the geometry, without scale.</param> /// <param name="scaledLcs">Local coordinate system for the geometry, including scale, potentially non-uniform.</param> /// <param name="guid">The guid of an element for which represntation is being created.</param> /// <returns>The created geometries.</returns> public IList<GeometryObject> CreateGeometry( IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { // A HalfSpaceSolid must always be a Solid, regardless of input. using (IFCImportShapeEditScope.IFCTargetSetter setter = new IFCImportShapeEditScope.IFCTargetSetter(shapeEditScope, TessellatedShapeBuilderTarget.Solid, TessellatedShapeBuilderFallback.Abort)) { return CreateGeometryInternal(shapeEditScope, lcs, scaledLcs, guid); } }