private void CreateBoxShape(IFCImportShapeEditScope shapeEditScope, Transform scaledLcs) { using (IFCImportShapeEditScope.IFCContainingRepresentationSetter repSetter = new IFCImportShapeEditScope.IFCContainingRepresentationSetter(shapeEditScope, this)) { // Get the material and graphics style based in the "Box" sub-category of Generic Models. // We will create the sub-category if this is our first time trying to use it. // Note that all bounding boxes are controlled by a sub-category of Generic Models. We may revisit that decision later. // Note that we hard-wire the identifier to "Box" because older files may have bounding box items in an obsolete representation. SolidOptions solidOptions = null; Category bboxCategory = IFCCategoryUtil.GetSubCategoryForRepresentation(shapeEditScope.Document, Id, IFCRepresentationIdentifier.Box); if (bboxCategory != null) { ElementId materialId = (bboxCategory.Material == null) ? ElementId.InvalidElementId : bboxCategory.Material.Id; GraphicsStyle graphicsStyle = bboxCategory.GetGraphicsStyle(GraphicsStyleType.Projection); ElementId gstyleId = (graphicsStyle == null) ? ElementId.InvalidElementId : graphicsStyle.Id; solidOptions = new SolidOptions(materialId, gstyleId); } Solid bboxSolid = IFCGeometryUtil.CreateSolidFromBoundingBox(scaledLcs, BoundingBox, solidOptions); if (bboxSolid != null) { IFCSolidInfo bboxSolidInfo = IFCSolidInfo.Create(Id, bboxSolid); shapeEditScope.AddGeometry(bboxSolidInfo); } } return; }
/// <summary> /// Create 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> protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { base.CreateShapeInternal(shapeEditScope, scaledLcs, lcs, guid); // Ignoring Inner shells for now. if (Outer != null) { try { IList <GeometryObject> solids = CreateGeometry(shapeEditScope, scaledLcs, lcs, guid); if (solids != null) { foreach (GeometryObject solid in solids) { shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, solid)); } } else { Importer.TheLog.LogError(Outer.Id, "cannot create valid solid, ignoring.", false); } } catch (Exception ex) { Importer.TheLog.LogError(Outer.Id, ex.Message, false); } } }
/// <summary> /// Create geometry for a particular representation item. /// </summary> /// <param name="shapeEditScope">The geometry creation scope.</param> /// <param name="lcs">Local coordinate system for the geometry.</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> override protected void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { if (XYZPoint == null) { return; } XYZ transformedPoint = scaledLcs.OfPoint(XYZPoint); if (transformedPoint == null) { return; } ElementId gstyleId = shapeEditScope.GraphicsStyleId; Category pointCategory = IFCCategoryUtil.GetSubCategoryForRepresentation(shapeEditScope.Document, Id, shapeEditScope.ContainingRepresentation.Identifier); if (pointCategory != null) { GraphicsStyle graphicsStyle = pointCategory.GetGraphicsStyle(GraphicsStyleType.Projection); if (graphicsStyle != null) { gstyleId = graphicsStyle.Id; } } Point point = Point.Create(transformedPoint, gstyleId); if (point == null) { return; } shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, point)); }
/// <summary> /// Create 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> protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid); IList <GeometryObject> extrudedGeometries = CreateGeometryInternal(shapeEditScope, lcs, scaledLcs, guid); if (extrudedGeometries != null) { foreach (GeometryObject extrudedGeometry in extrudedGeometries) { shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, extrudedGeometry)); } } }
/// <summary> /// Create 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> protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid); // Ignoring Inner shells for now. if (Shells.Count != 0) { IList <GeometryObject> createdGeometries = CreateGeometry(shapeEditScope, lcs, scaledLcs, guid); if (createdGeometries != null) { foreach (GeometryObject createdGeometry in createdGeometries) { shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, createdGeometry)); } } } }
/// <summary> /// Create 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> protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid); // Check scale; if it is uniform, create an instance. If not, create a shape directly. // TODO: Instead allow creation of instances based on similar scaling. double scaleX = MappingTarget.Scale; double scaleY = MappingTarget.ScaleY.HasValue ? MappingTarget.ScaleY.Value : scaleX; double scaleZ = MappingTarget.ScaleZ.HasValue ? MappingTarget.ScaleZ.Value : scaleX; bool isUnitScale = (MathUtil.IsAlmostEqual(scaleX, 1.0) && MathUtil.IsAlmostEqual(scaleY, 1.0) && MathUtil.IsAlmostEqual(scaleZ, 1.0)); Transform mappingTransform = MappingTarget.Transform; Transform newLcs = (mappingTransform == null) ? lcs : (lcs?.Multiply(mappingTransform) ?? mappingTransform); Transform newScaledLcs = (mappingTransform == null) ? scaledLcs : (scaledLcs?.Multiply(mappingTransform) ?? mappingTransform); bool isFootprint = (shapeEditScope.ContainingRepresentation.Identifier == IFCRepresentationIdentifier.FootPrint); bool canCreateType = !shapeEditScope.PreventInstances && !isFootprint && isUnitScale && (newLcs?.IsConformal ?? true) && (newScaledLcs?.IsConformal ?? true) && (shapeEditScope.ContainingRepresentation != null); if (canCreateType) { int mappingSourceId = MappingSource.Id; int geometrySourceId = FindAlternateGeometrySource(mappingSourceId); MappingSource.CreateShape(shapeEditScope, null, null, guid); if (shapeEditScope.Creator != null) { Importer.TheProcessor.PostProcessMappedItem(shapeEditScope.Creator.Id, shapeEditScope.Creator.GlobalId, shapeEditScope.Creator.EntityType.ToString(), shapeEditScope.Creator.CategoryId, geometrySourceId, newLcs); } // NAVIS_TODO: Figure out how not to do this. IList <GeometryObject> instances = DirectShape.CreateGeometryInstance( shapeEditScope.Document, mappingSourceId.ToString(), newLcs); foreach (GeometryObject instance in instances) { shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, instance)); } } else { if (!isUnitScale) { XYZ xScale = new XYZ(scaleX, 0.0, 0.0); XYZ yScale = new XYZ(0.0, scaleY, 0.0); XYZ zScale = new XYZ(0.0, 0.0, scaleZ); Transform scaleTransform = Transform.Identity; scaleTransform.set_Basis(0, xScale); scaleTransform.set_Basis(1, yScale); scaleTransform.set_Basis(2, zScale); newScaledLcs = newScaledLcs.Multiply(scaleTransform); } MappingSource.CreateShape(shapeEditScope, newLcs, newScaledLcs, guid); } }
protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { using (BuilderScope bs = shapeEditScope.InitializeBuilder(IFCShapeBuilderType.TessellatedShapeBuilder)) { base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid); TessellatedShapeBuilderScope tsBuilderScope = bs as TessellatedShapeBuilderScope; tsBuilderScope.StartCollectingFaceSet(); // Create triangle face set from CoordIndex. We do not support the Normals yet at this point foreach (List <int> triIndex in CoordIndex) { // This is a defensive check in an unlikely situation that the index is larger than the data if (triIndex[0] > Coordinates.CoordList.Count || triIndex[1] > Coordinates.CoordList.Count || triIndex[2] > Coordinates.CoordList.Count) { continue; } tsBuilderScope.StartCollectingFace(GetMaterialElementId(shapeEditScope)); IList <XYZ> loopVertices = new List <XYZ>(); for (int ii = 0; ii < 3; ++ii) { int actualVIdx = triIndex[ii] - 1; if (PnIndex != null) { actualVIdx = PnIndex[actualVIdx] - 1; } IList <double> v = Coordinates.CoordList[actualVIdx]; loopVertices.Add(new XYZ(v[0], v[1], v[2])); } IList <XYZ> transformedVertices = new List <XYZ>(); foreach (XYZ vertex in loopVertices) { // Need to apply the project unit scaling here XYZ scaledVertex = applyProjectUnitScaleVertex(vertex); transformedVertices.Add(scaledLcs.OfPoint(scaledVertex)); } // Check triangle that is too narrow (2 vertices are within the tolerance IList <XYZ> validVertices; IFCGeometryUtil.CheckAnyDistanceVerticesWithinTolerance(Id, shapeEditScope, transformedVertices, out validVertices); // We are going to catch any exceptions if the loop is invalid. // We are going to hope that we can heal the parent object in the TessellatedShapeBuilder. bool bPotentiallyAbortFace = false; int count = validVertices.Count; if (validVertices.Count < 3) { Importer.TheLog.LogComment(Id, "Too few distinct loop vertices (" + count + "), ignoring.", false); bPotentiallyAbortFace = true; } else { if (!tsBuilderScope.AddLoopVertices(Id, validVertices)) { bPotentiallyAbortFace = true; } } if (bPotentiallyAbortFace) { tsBuilderScope.AbortCurrentFace(); } else { tsBuilderScope.StopCollectingFace(); } } IList <GeometryObject> createdGeometries = tsBuilderScope.CreateGeometry(guid); if (createdGeometries != null) { foreach (GeometryObject createdGeometry in createdGeometries) { shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, createdGeometry)); } } } }
protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { using (BuilderScope bs = shapeEditScope.InitializeBuilder(IFCShapeBuilderType.TessellatedShapeBuilder)) { base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid); TessellatedShapeBuilderScope tsBuilderScope = bs as TessellatedShapeBuilderScope; tsBuilderScope.StartCollectingFaceSet(); // Create the face set from IFCIndexedPolygonalFace foreach (IFCIndexedPolygonalFace face in Faces) { // TODO: Consider adding ability to triangulate here. tsBuilderScope.StartCollectingFace(GetMaterialElementId(shapeEditScope), false); IList <XYZ> loopVertices = new List <XYZ>(); foreach (int vertInd in face.CoordIndex) { int actualVIdx = vertInd - 1; // IFC starts the list position at 1 if (PnIndex != null) { actualVIdx = PnIndex[actualVIdx] - 1; } XYZ vertex = Coordinates.CoordList[actualVIdx]; loopVertices.Add(scaledLcs.OfPoint(vertex)); } List <XYZ> validVertices; IFCGeometryUtil.CheckAnyDistanceVerticesWithinTolerance(Id, shapeEditScope, loopVertices, out validVertices); bool bPotentiallyAbortFace = false; if (!tsBuilderScope.AddLoopVertices(Id, validVertices)) { bPotentiallyAbortFace = true; } // Handle holes if (face.InnerCoordIndices != null) { foreach (IList <int> innerLoop in face.InnerCoordIndices) { IList <XYZ> innerLoopVertices = new List <XYZ>(); foreach (int innerVerIdx in innerLoop) { int actualVIdx = innerVerIdx - 1; if (PnIndex != null) { actualVIdx = PnIndex[actualVIdx] - 1; } XYZ vertex = Coordinates.CoordList[actualVIdx]; // add vertex to the loop innerLoopVertices.Add(scaledLcs.OfPoint(vertex)); } List <XYZ> validInnerV; IFCGeometryUtil.CheckAnyDistanceVerticesWithinTolerance(Id, shapeEditScope, innerLoopVertices, out validInnerV); if (!tsBuilderScope.AddLoopVertices(Id, validInnerV)) { bPotentiallyAbortFace = true; } } } tsBuilderScope.StopCollectingFace(!bPotentiallyAbortFace, false); } IList <GeometryObject> createdGeometries = tsBuilderScope.CreateGeometry(guid); if (createdGeometries != null) { foreach (GeometryObject createdGeometry in createdGeometries) { shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, createdGeometry)); } } } }
/// <summary> /// Create 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> protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid); // Check scale; if it is uniform, create an instance. If not, create a shape directly. // TODO: Instead allow creation of instances based on similar scaling. double scaleX = MappingTarget.Scale; double scaleY = MappingTarget.ScaleY.HasValue ? MappingTarget.ScaleY.Value : scaleX; double scaleZ = MappingTarget.ScaleZ.HasValue ? MappingTarget.ScaleZ.Value : scaleX; bool isUnitScale = (MathUtil.IsAlmostEqual(scaleX, 1.0) && MathUtil.IsAlmostEqual(scaleY, 1.0) && MathUtil.IsAlmostEqual(scaleZ, 1.0)); Transform mappingTransform = MappingTarget.Transform; Transform newLcs = null; if (lcs == null) { newLcs = mappingTransform; } else if (mappingTransform == null) { newLcs = lcs; } else { newLcs = lcs.Multiply(mappingTransform); } Transform newScaledLcs = null; if (scaledLcs == null) { newScaledLcs = mappingTransform; } else if (mappingTransform == null) { newScaledLcs = scaledLcs; } else { newScaledLcs = scaledLcs.Multiply(mappingTransform); } // Pass in newLCS = null, use newLCS for instance. bool isFootprint = (shapeEditScope.ContainingRepresentation.Identifier == IFCRepresentationIdentifier.FootPrint); bool canCreateType = (newLcs != null && newLcs.IsConformal) && (newScaledLcs != null && newScaledLcs.IsConformal) && isUnitScale && (shapeEditScope.ContainingRepresentation != null && !isFootprint); if (canCreateType) { MappingSource.CreateShape(shapeEditScope, null, null, guid); IList <GeometryObject> instances = DirectShape.CreateGeometryInstance(shapeEditScope.Document, MappingSource.Id.ToString(), newLcs); foreach (GeometryObject instance in instances) { shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, instance)); } } else { if (!isUnitScale) { XYZ xScale = new XYZ(scaleX, 0.0, 0.0); XYZ yScale = new XYZ(0.0, scaleY, 0.0); XYZ zScale = new XYZ(0.0, 0.0, scaleZ); Transform scaleTransform = Transform.Identity; scaleTransform.set_Basis(0, xScale); scaleTransform.set_Basis(1, yScale); scaleTransform.set_Basis(2, zScale); newScaledLcs = newScaledLcs.Multiply(scaleTransform); } MappingSource.CreateShape(shapeEditScope, newLcs, newScaledLcs, guid); } }
/// <summary> /// Create geometry for a particular representation item, and add to scope. /// </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> protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid) { base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid); IFCRepresentation parentRep = shapeEditScope.ContainingRepresentation; IList <Curve> transformedCurves = new List <Curve>(); if (Curve != null) { Curve transformedCurve = CreateTransformedCurve(Curve, parentRep, lcs); if (transformedCurve != null) { transformedCurves.Add(transformedCurve); } } else if (CurveLoop != null) { foreach (Curve curve in CurveLoop) { Curve transformedCurve = CreateTransformedCurve(curve, parentRep, lcs); if (transformedCurve != null) { transformedCurves.Add(transformedCurve); } } } // TODO: set graphics style for footprint curves. IFCRepresentationIdentifier repId = (parentRep == null) ? IFCRepresentationIdentifier.Unhandled : parentRep.Identifier; bool createModelGeometry = (repId == IFCRepresentationIdentifier.Body) || (repId == IFCRepresentationIdentifier.Axis) || (repId == IFCRepresentationIdentifier.Unhandled); ElementId gstyleId = ElementId.InvalidElementId; if (createModelGeometry) { Category curveCategory = IFCCategoryUtil.GetSubCategoryForRepresentation(shapeEditScope.Document, Id, parentRep.Identifier); if (curveCategory != null) { GraphicsStyle graphicsStyle = curveCategory.GetGraphicsStyle(GraphicsStyleType.Projection); if (graphicsStyle != null) { gstyleId = graphicsStyle.Id; } } } foreach (Curve curve in transformedCurves) { if (createModelGeometry) { curve.SetGraphicsStyleId(gstyleId); shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, curve)); } else { // Default: assume a plan view curve. shapeEditScope.AddFootprintCurve(curve); } } }