예제 #1
0
 protected override IList<GeometryObject> CreateGeometryInternal(
    IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
 {
     if (BooleanResult != null)
         return BooleanResult.CreateGeometry(shapeEditScope, lcs, scaledLcs, guid);
     return null;
 }
예제 #2
0
 /// <summary>
 /// The constructor.
 /// </summary>
 /// <param name="scope">The associated shape edit scope.</param>
 /// <param name="item">The current styled item.</param>
 public IFCContainingRepresentationSetter(IFCImportShapeEditScope scope, IFCRepresentation containingRepresentation)
 {
     if (scope != null)
     {
         m_Scope                        = scope;
         m_OldRepresentation            = scope.ContainingRepresentation;
         scope.ContainingRepresentation = containingRepresentation;
     }
 }
        /// <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>Zero or more created geometries.</returns>
        public IList<GeometryObject> CreateGeometry(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            if (StyledByItem != null)
                StyledByItem.Create(shapeEditScope);

            using (IFCImportShapeEditScope.IFCMaterialStack stack = new IFCImportShapeEditScope.IFCMaterialStack(shapeEditScope, StyledByItem, null))
            {
                return CreateGeometryInternal(shapeEditScope, lcs, scaledLcs, guid);
            }
        }
예제 #4
0
            /// <summary>
            /// The constructor.
            /// </summary>
            /// <param name="scope">The associated shape edit scope.</param>
            /// <param name="targetGeometry">The current target geometry.</param>
            /// <param name="fallbackGeometry">The current fallback geometry.</param>
            public IFCTargetSetter(IFCImportShapeEditScope scope, TessellatedShapeBuilderTarget targetGeometry, TessellatedShapeBuilderFallback fallbackGeometry)
            {
                if (scope != null)
                {
                    m_Scope = scope;

                    m_TargetGeometry   = m_Scope.TargetGeometry;
                    m_FallbackGeometry = m_Scope.FallbackGeometry;

                    m_Scope.SetTargetAndFallbackGeometry(targetGeometry, fallbackGeometry);
                }
            }
예제 #5
0
        /// <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> csgGeometries = CreateGeometryInternal(shapeEditScope, lcs, scaledLcs, guid);
            if (csgGeometries != null)
            {
                foreach (GeometryObject csgGeometry in csgGeometries)
                {
                    shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, csgGeometry));
                }
            }
        }
예제 #6
0
        /// <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>
        protected override IList<GeometryObject> CreateGeometryInternal(
           IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            shapeEditScope.StartCollectingFaceSet();
            Outer.CreateShape(shapeEditScope, lcs, scaledLcs, guid);
            
            IList<GeometryObject> geomObjs = shapeEditScope.CreateGeometry(guid);
            
            if (geomObjs == null || geomObjs.Count == 0)
               return null;

            return geomObjs;
        }
        /// <summary>
        /// Returns the associated material id, if any.
        /// </summary>
        /// <param name="scope">The containing creation scope.</param>
        /// <returns>The element id of the material, if any.</returns>
        public virtual ElementId GetMaterialElementId(IFCImportShapeEditScope scope)
        {
            ElementId materialId = scope.GetCurrentMaterialId();
            if (materialId != ElementId.InvalidElementId)
                return materialId;

            if (scope.Creator != null)
            {
                IFCMaterial creatorMaterial = scope.Creator.GetTheMaterial();
                if (creatorMaterial != null)
                    return creatorMaterial.GetMaterialElementId();
            }

            return ElementId.InvalidElementId;
        }
예제 #8
0
 public TessellatedShapeBuilderScope(IFCImportShapeEditScope container)
     : base(container)
 {
     IFCImportShapeEditScope.BuildPreferenceType BuildPreference = container.BuildPreference;
     if (BuildPreference == IFCImportShapeEditScope.BuildPreferenceType.ForceSolid)
     {
         SetTargetAndFallbackGeometry(TessellatedShapeBuilderTarget.Solid, TessellatedShapeBuilderFallback.Abort);
     }
     else if (BuildPreference == IFCImportShapeEditScope.BuildPreferenceType.AnyMesh)
     {
         SetTargetAndFallbackGeometry(TessellatedShapeBuilderTarget.Mesh, TessellatedShapeBuilderFallback.Salvage);
     }
     else if (BuildPreference == IFCImportShapeEditScope.BuildPreferenceType.AnyGeometry)
     {
         SetTargetAndFallbackGeometry(TessellatedShapeBuilderTarget.AnyGeometry, TessellatedShapeBuilderFallback.Mesh);
     }
 }
예제 #9
0
            /// <summary>
            /// The constructor.
            /// </summary>
            /// <param name="scope">The associated shape edit scope.</param>
            /// <param name="item">The current styled item.</param>
            public IFCMaterialStack(IFCImportShapeEditScope scope, IFCStyledItem styledItem, IFCPresentationLayerAssignment layerAssignment)
            {
                m_Scope = scope;
                if (styledItem != null)
                {
                    m_MaterialElementId = styledItem.GetMaterialElementId(scope);
                }
                else if (layerAssignment != null)
                {
                    m_MaterialElementId = layerAssignment.GetMaterialElementId(scope);
                }

                if (m_MaterialElementId != ElementId.InvalidElementId)
                {
                    m_Scope.PushMaterialId(m_MaterialElementId);
                }
            }
예제 #10
0
        /// <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 CreateSolid function.</remarks>
        protected IList<GeometryObject> CreateGeometry(
              IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            if (Shells.Count == 0)
                return null;

            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;
        }
예제 #11
0
        /// <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 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;

            IList<GeometryObject> geomObjs = null;

            using (BuilderScope bs = shapeEditScope.InitializeBuilder(IFCShapeBuilderType.TessellatedShapeBuilder))
            {
                TessellatedShapeBuilderScope tsBuilderScope = bs as TessellatedShapeBuilderScope;
                tsBuilderScope.StartCollectingFaceSet();

                foreach (IFCConnectedFaceSet faceSet in Shells)
                    faceSet.CreateShape(shapeEditScope, lcs, scaledLcs, guid);

                geomObjs = tsBuilderScope.CreateGeometry(guid);
            }
            if (geomObjs == null || geomObjs.Count == 0)
                return null;

            return geomObjs;
        }
예제 #13
0
        /// <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)
        {
            if (shapeEditScope.BuilderType != IFCShapeBuilderType.TessellatedShapeBuilder)
                throw new InvalidOperationException("Currently BrepBuilder is only used to support IFCAdvancedFace");

            base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid);

            // we would only be in this code if we are not processing and IfcAdvancedBrep, since IfcAdvancedBrep must have IfcAdvancedFace
            if (shapeEditScope.BuilderScope == null)
            {
                throw new InvalidOperationException("BuilderScope has not been initialized");
            }
            TessellatedShapeBuilderScope tsBuilderScope = shapeEditScope.BuilderScope as TessellatedShapeBuilderScope;

            tsBuilderScope.StartCollectingFace(GetMaterialElementId(shapeEditScope));
            
            foreach (IFCFaceBound faceBound in Bounds)
            {
                faceBound.CreateShape(shapeEditScope, lcs, scaledLcs, guid);
                
                // If we can't create the outer face boundary, we will abort the creation of this face.  In that case, return.
                if (!tsBuilderScope.HaveActiveFace())
                {
                    tsBuilderScope.AbortCurrentFace();
                    return;
                }
            }
            tsBuilderScope.StopCollectingFace();
        }
예제 #14
0
        /// <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>
 /// The constructor.
 /// </summary>
 /// <param name="scope">The associated shape edit scope.</param>
 /// <param name="item">The current styled item.</param>
 public IFCContainingRepresentationSetter(IFCImportShapeEditScope scope, IFCRepresentation containingRepresentation)
 {
     if (scope != null)
     {
         m_Scope = scope;
         m_OldRepresentation = scope.ContainingRepresentation;
         scope.ContainingRepresentation = containingRepresentation;
     }
 }
      /// <summary>
      /// Check for any occurence where distance of two vertices are too narrow (within the tolerance)
      /// </summary>
      /// <param name="entityId">The integer number representing the current IFC entity Id</param>
      /// <param name="shapeEditScope">the shapeEditScope</param>
      /// <param name="inputVerticesList">Input list of the vertices</param>
      /// <param name="outputVerticesList">Output List of the valid vertices, i.e. not vertices that are too close to each other</param>
      /// <returns></returns>
      public static void CheckAnyDistanceVerticesWithinTolerance(int entityId, IFCImportShapeEditScope shapeEditScope, IList<XYZ> inputVerticesList, out IList<XYZ> outputVerticesList)
      {
         // Check triangle that is too narrow (2 vertices are within the tolerance
         double shortSegmentTolerance = shapeEditScope.TryToCreateSolid() ?
                                         shapeEditScope.Document.Application.ShortCurveTolerance :
                                         shapeEditScope.Document.Application.VertexTolerance;

         int lastVertex = 0;
         IList<XYZ> vertList = new List<XYZ>();
         outputVerticesList = vertList;
         for (int ii = 1; ii <= inputVerticesList.Count; ii++)
         {
            int currIdx = (ii % inputVerticesList.Count);

            double dist = inputVerticesList[lastVertex].DistanceTo(inputVerticesList[currIdx]);
            if (dist >= shortSegmentTolerance)
            {
               vertList.Add(inputVerticesList[lastVertex]);
               lastVertex = currIdx;
            }
            else
            {
               string distAsString = IFCUnitUtil.FormatLengthAsString(dist);
               string shortDistAsString = IFCUnitUtil.FormatLengthAsString(shortSegmentTolerance);
               string warningString = "Distance between vertices " + lastVertex + " and " + currIdx +
                                       " is " + distAsString + ", which is less than the minimum " + (shapeEditScope.TryToCreateSolid() ? "Solid" : "Mesh") +
                                       " distance of " + shortDistAsString + ", removing second point.";

               Importer.TheLog.LogComment(entityId, warningString, false);
            }
         }
      }
예제 #17
0
 public BrepBuilderScope(IFCImportShapeEditScope container)
     : base(container)
 {
 }
        /// <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)
            {
                // This isn't an inherited function; see description for more details.
               IList<GeometryObject> createdGeometries = CreateGeometry(shapeEditScope, lcs, scaledLcs, guid);
               if (createdGeometries != null)
               {
                   foreach (GeometryObject createdGeometry in createdGeometries)
                   {
                       shapeEditScope.AddGeometry(IFCSolidInfo.Create(Id, createdGeometry));
                   }
               }
            }
        }
예제 #19
0
 /// <summary>
 /// Creates or populates Revit elements based on the information contained in this class.
 /// </summary>
 /// <param name="doc">The document.</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 CreateProductRepresentation(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
 {
     // TODO: separate representations.
     foreach (IFCRepresentation representation in Representations)
     {
         representation.CreateShape(shapeEditScope, lcs, scaledLcs, guid);
     }
 }
        /// <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>Zero or more created geometries.</returns>
        protected override IList<GeometryObject> CreateGeometryInternal(
              IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
           Transform sweptDiskPosition = (lcs == null) ? Transform.Identity : lcs;

           CurveLoop baseProfileCurve = Directrix.GetCurveLoop();
           if (baseProfileCurve == null)
              return null;

           CurveLoop trimmedDirectrix = IFCGeometryUtil.TrimCurveLoop(baseProfileCurve, StartParameter, EndParameter);
           if (trimmedDirectrix == null)
              return null;

           CurveLoop trimmedDirectrixInWCS = IFCGeometryUtil.CreateTransformed(trimmedDirectrix, sweptDiskPosition);

           // Create the disk.
           Curve firstCurve = null;
           foreach (Curve curve in trimmedDirectrixInWCS)
           {
              firstCurve = curve;
              break;
           }

           double startParam = 0.0;
           IList<CurveLoop> profileCurveLoops = CreateProfileCurveLoopsForDirectrix(firstCurve, out startParam);
           if (profileCurveLoops == null)
              return null;

           SolidOptions solidOptions = new SolidOptions(GetMaterialElementId(shapeEditScope), shapeEditScope.GraphicsStyleId);
           IList<GeometryObject> myObjs = new List<GeometryObject>();
           
           try
           {
              Solid sweptDiskSolid = GeometryCreationUtilities.CreateSweptGeometry(trimmedDirectrixInWCS, 0, startParam, profileCurveLoops,
                 solidOptions);
              if (sweptDiskSolid != null)
                 myObjs.Add(sweptDiskSolid);
           }
           catch (Exception ex)
           {
              // If we can't create a solid, we will attempt to split the Solid into valid pieces (that will likely have some overlap).
              if (ex.Message.Contains("self-intersections"))
              {
                 Importer.TheLog.LogWarning(Id, "The IfcSweptDiskSolid definition does not define a valid solid, likely due to self-intersections or other such problems; the profile probably extends too far toward the inner curvature of the sweep path. Creating the minimum number of solids possible to represent the geometry.", false);
                 myObjs = SplitSweptDiskIntoValidPieces(trimmedDirectrixInWCS, profileCurveLoops, solidOptions);
              }
              else
                 throw ex;
           }

           return myObjs;
        }
      /// <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))
               {
                  Importer.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.BuildPreferenceSetter setter =
                   new IFCImportShapeEditScope.BuildPreferenceSetter(shapeEditScope, IFCImportShapeEditScope.BuildPreferenceType.ForceSolid))
               {
                  // Before we process the second operand, we are going to see if there is a uniform material set for the first operand 
                  // (corresponding to the solid in the Boolean operation).  We will try to suggest the same material for the voids to avoid arbitrary
                  // setting of material information for the cut faces.
                  IFCStyledItem firstOperandStyledItem = GetStyledItemFromOperand(FirstOperand as IFCRepresentationItem);
                  using (IFCImportShapeEditScope.IFCMaterialStack stack =
                      new IFCImportShapeEditScope.IFCMaterialStack(shapeEditScope, firstOperandStyledItem, null))
                  {
                     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)
                  Importer.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 || BooleanOperator == null)
         {
            if (BooleanOperator == null)
               Importer.TheLog.LogError(Id, "Invalid BooleanOperationsType.", false);
            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:
                  Importer.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;
               XYZ suggestedShiftDirection = (SecondOperand == null) ? null : SecondOperand.GetSuggestedShiftDirection(lcs);
               foreach (GeometryObject secondSolid in secondSolids)
               {
                  resultSolid = IFCGeometryUtil.ExecuteSafeBooleanOperation(Id, secondId, resultSolid, secondSolid as Solid, booleanOperationsType, suggestedShiftDirection);
                  if (resultSolid == null)
                     break;
               }

               if (resultSolid != null)
                  resultSolids.Add(resultSolid);
            }
         }

         return resultSolids;
      }
        /// <summary>
        /// Create the Revit elements associated with this IfcPresentationLayerWithStyle.
        /// </summary>
        /// <param name="shapeEditScope">The shape edit scope.</param>
        override public void Create(IFCImportShapeEditScope shapeEditScope)
        {
            // TODO: support cut pattern id and cut pattern color.
            if (CreatedMaterialElementId != ElementId.InvalidElementId || !IsValidForCreation)
                return;

            base.Create(shapeEditScope);

            try
            {
                // If the styled item or the surface style has a name, use it.
                IFCSurfaceStyle surfaceStyle = GetSurfaceStyle();
                if (surfaceStyle == null)
                {
                    // We only handle surface styles at the moment; log file should already reflect any other unhandled styles.
                    IsValidForCreation = true;
                    return;
                }

                string forcedName = surfaceStyle.Name;
                if (string.IsNullOrWhiteSpace(forcedName))
                    forcedName = Name;

                CreatedMaterialElementId = surfaceStyle.Create(shapeEditScope.Document, forcedName, null, Id);
            }
            catch (Exception ex)
            {
                IsValidForCreation = false;
                IFCImportFile.TheLog.LogCreationError(this, ex.Message, false);
            }
        }
        /// <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>
        protected override IList<GeometryObject> CreateGeometryInternal(
           IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            if (Outer == null || Outer.Faces.Count == 0)
                return null;

            IList<GeometryObject> geomObjs = null;
            bool canRevertToMesh = false;
            
            using (BuilderScope bs = shapeEditScope.InitializeBuilder(IFCShapeBuilderType.TessellatedShapeBuilder))
            {
                TessellatedShapeBuilderScope tsBuilderScope = bs as TessellatedShapeBuilderScope;

                tsBuilderScope.StartCollectingFaceSet();
                Outer.CreateShape(shapeEditScope, lcs, scaledLcs, guid);

                if (tsBuilderScope.CreatedFacesCount == Outer.Faces.Count)
                {
                    geomObjs = tsBuilderScope.CreateGeometry(guid);
                }

                canRevertToMesh = tsBuilderScope.CanRevertToMesh();
            }


            if (geomObjs == null || geomObjs.Count == 0)
            {
                if (canRevertToMesh)
                {
                    using (IFCImportShapeEditScope.BuildPreferenceSetter setter =
                        new IFCImportShapeEditScope.BuildPreferenceSetter(shapeEditScope, IFCImportShapeEditScope.BuildPreferenceType.AnyMesh))
                    {
                        using (BuilderScope newBuilderScope = shapeEditScope.InitializeBuilder(IFCShapeBuilderType.TessellatedShapeBuilder))
                        {
                            TessellatedShapeBuilderScope newTsBuilderScope = newBuilderScope as TessellatedShapeBuilderScope;
                            // Let's see if we can loosen the requirements a bit, and try again.
                            newTsBuilderScope.StartCollectingFaceSet();

                            Outer.CreateShape(shapeEditScope, lcs, scaledLcs, guid);

                            // This needs to be in scope so that we keep the mesh tolerance for vertices.
                            if (newTsBuilderScope.CreatedFacesCount != 0)
                            {
                                if (newTsBuilderScope.CreatedFacesCount != Outer.Faces.Count)
                                    Importer.TheLog.LogWarning
                                        (Outer.Id, "Processing " + newTsBuilderScope.CreatedFacesCount + " valid faces out of " + Outer.Faces.Count + " total.", false);

                                geomObjs = newTsBuilderScope.CreateGeometry(guid);
                            }

                        }
                    }
                }
            }
            
            if (geomObjs == null || geomObjs.Count == 0)
            {
                // Couldn't use fallback, or fallback didn't work.
                Importer.TheLog.LogWarning(Id, "Couldn't create any geometry.", false);
                return null;
            }

            return geomObjs;
        }
        /// <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>
        /// 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.</param>
        /// <param name="guid">The guid of an element for which represntation is being created.</param>
        /// <returns>One or more created Solids.</returns>
        protected override IList<GeometryObject> CreateGeometryInternal(
              IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            Transform origLCS = (lcs == null) ? Transform.Identity : lcs;
            Transform revolvePosition = (Position == null) ? origLCS : origLCS.Multiply(Position);

            ISet<IList<CurveLoop>> disjointLoops = GetTransformedCurveLoops(revolvePosition);
            if (disjointLoops == null || disjointLoops.Count() == 0)
                return null;

            XYZ frameOrigin = revolvePosition.OfPoint(Axis.Origin);
            XYZ frameZVec = revolvePosition.OfVector(Axis.BasisZ);
            SolidOptions solidOptions = new SolidOptions(GetMaterialElementId(shapeEditScope), shapeEditScope.GraphicsStyleId);
            
            IList<GeometryObject> myObjs = new List<GeometryObject>();

            foreach (IList<CurveLoop> loops in disjointLoops)
            {
                XYZ frameXVec = null;

                frameXVec = GetValidXVectorFromLoop(loops[0], frameZVec, frameOrigin);
                if (frameXVec == null)
                {
                    Importer.TheLog.LogError(Id, "Couldn't generate valid frame for IfcRevolvedAreaSolid.", false);
                    return null;
                }
                XYZ frameYVec = frameZVec.CrossProduct(frameXVec);
                Frame coordinateFrame = new Frame(frameOrigin, frameXVec, frameYVec, frameZVec);

                GeometryObject myObj = GeometryCreationUtilities.CreateRevolvedGeometry(coordinateFrame, loops, 0, Angle, solidOptions);
                if (myObj != null)
                    myObjs.Add(myObj);
            }

            return myObjs;
        }
 public BuildPreferenceSetter(IFCImportShapeEditScope scope, BuildPreferenceType buildPreferenceType) 
 {
     m_Scope = scope;
     m_PreferenceType = scope.BuildPreference;
     scope.BuildPreference = buildPreferenceType;
 }
            /// <summary>
            /// The constructor.
            /// </summary>
            /// <param name="scope">The associated shape edit scope.</param>
            /// <param name="item">The current styled item.</param>
            public IFCMaterialStack(IFCImportShapeEditScope scope, IFCStyledItem styledItem, IFCPresentationLayerAssignment layerAssignment)
            {
                m_Scope = scope;
                if (styledItem != null)
                    m_MaterialElementId = styledItem.GetMaterialElementId(scope);
                else if (layerAssignment != null)
                    m_MaterialElementId = layerAssignment.GetMaterialElementId(scope);

                if (m_MaterialElementId != ElementId.InvalidElementId)
                    m_Scope.PushMaterialId(m_MaterialElementId);
            }
 /// <summary>
 /// Returns the main element id of the material associated with this presentation layer assignment.
 /// </summary>
 /// <param name="shapeEditScope">The shape edit scope.</param>
 /// <returns>The element id, or ElementId.invalidElementId if not set.</returns>
 public override ElementId GetMaterialElementId(IFCImportShapeEditScope shapeEditScope)
 {
     return CreatedMaterialElementId;
 }
예제 #29
0
        /// <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>Zero or more created geometries.</returns>
        protected override IList<GeometryObject> CreateGeometryInternal(
              IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            Transform sweptDiskPosition = (lcs == null) ? Transform.Identity : lcs;

            CurveLoop baseProfileCurve = Directrix.GetCurveLoop();
            if (baseProfileCurve == null)
                return null;

            CurveLoop trimmedDirectrix = IFCGeometryUtil.TrimCurveLoop(baseProfileCurve, StartParameter, EndParameter);
            if (trimmedDirectrix == null)
                return null;

            CurveLoop trimmedDirectrixInLCS = IFCGeometryUtil.CreateTransformed(trimmedDirectrix, sweptDiskPosition);

            // Create the disk.
            Transform originTrf = null;
            double startParam = 0.0; // If the directrix isn't bound, this arbitrary parameter will do.
            foreach (Curve curve in trimmedDirectrixInLCS)
            {
                if (curve.IsBound)
                    startParam = curve.GetEndParameter(0);
                originTrf = curve.ComputeDerivatives(startParam, false);
                break;
            }

            if (originTrf == null)
                return null;

            // The X-dir of the transform of the start of the directrix will form the normal of the disk.
            Plane diskPlane = new Plane(originTrf.BasisX, originTrf.Origin);

            IList<CurveLoop> profileCurveLoops = new List<CurveLoop>();

            CurveLoop diskOuterCurveLoop = new CurveLoop();
            diskOuterCurveLoop.Append(Arc.Create(diskPlane, Radius, 0, Math.PI));
            diskOuterCurveLoop.Append(Arc.Create(diskPlane, Radius, Math.PI, 2.0 * Math.PI));
            profileCurveLoops.Add(diskOuterCurveLoop);
            
            if (InnerRadius.HasValue)
            {
                CurveLoop diskInnerCurveLoop = new CurveLoop();
                diskInnerCurveLoop.Append(Arc.Create(diskPlane, InnerRadius.Value, 0, Math.PI));
                diskInnerCurveLoop.Append(Arc.Create(diskPlane, InnerRadius.Value, Math.PI, 2.0 * Math.PI));
                profileCurveLoops.Add(diskInnerCurveLoop);
            }

            SolidOptions solidOptions = new SolidOptions(GetMaterialElementId(shapeEditScope), shapeEditScope.GraphicsStyleId);
            Solid sweptDiskSolid = GeometryCreationUtilities.CreateSweptGeometry(trimmedDirectrixInLCS, 0, startParam, profileCurveLoops,
                solidOptions);

            IList<GeometryObject> myObjs = new List<GeometryObject>();
            if (sweptDiskSolid != null)
                myObjs.Add(sweptDiskSolid);
            return myObjs;
        }
예제 #30
0
        /// <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>
        /// <remarks>This currently assumes that we are creating plan view curves.</remarks>
        protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid);

            foreach (IFCCurve curve in Curves)
            {
                curve.CreateShape(shapeEditScope, lcs, scaledLcs, guid);
            }
        }
예제 #31
0
        /// <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>
        /// <remarks>This currently assumes that we are create plan view curves.</remarks>
        protected override void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid);

            // TODO: set graphics style.
            if (Curve != null)
            {
                Curve transformedCurve = Curve.CreateTransformed(lcs);
                shapeEditScope.AddFootprintCurve(transformedCurve);
            }
            else if (CurveLoop != null)
            {
                foreach (Curve curve in CurveLoop)
                {
                    Curve transformedCurve = curve.CreateTransformed(lcs);
                    shapeEditScope.AddFootprintCurve(transformedCurve);
                }
            }
        }
예제 #32
0
 public BuilderScope(IFCImportShapeEditScope container)
 {
     this.Container = container;
 }
예제 #33
0
        /// <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)
        {
            // Reject Axis curves - not yet supported.
            IFCRepresentation parentRep = shapeEditScope.ContainingRepresentation;

            IFCRepresentationIdentifier repId = (parentRep == null) ? IFCRepresentationIdentifier.Unhandled : parentRep.Identifier;
            bool createModelGeometry = (repId == IFCRepresentationIdentifier.Axis);
            if (createModelGeometry)
            {
                Importer.TheLog.LogWarning(Id, "Can't process Axis representation, ignoring.", true);
                return;
            } 
            
            base.CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid);

            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.
            ElementId gstyleId = ElementId.InvalidElementId;
            foreach (Curve curve in transformedCurves)
            {
                // Default: assume a plan view curve.
                shapeEditScope.AddFootprintCurve(curve);
            }
        }
예제 #34
0
 public BuildPreferenceSetter(IFCImportShapeEditScope scope, BuildPreferenceType buildPreferenceType)
 {
     m_Scope               = scope;
     m_PreferenceType      = scope.BuildPreference;
     scope.BuildPreference = buildPreferenceType;
 }
        /// <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>
        public void CreateShape(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            if (StyledByItem != null)
                StyledByItem.Create(shapeEditScope);

            if (LayerAssignment != null)
                LayerAssignment.Create(shapeEditScope);
            
            using (IFCImportShapeEditScope.IFCMaterialStack stack = new IFCImportShapeEditScope.IFCMaterialStack(shapeEditScope, StyledByItem, LayerAssignment))
            {
                CreateShapeInternal(shapeEditScope, lcs, scaledLcs, guid);
            }
        }
 /// <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="guid">The guid of an element for which represntation is being created.</param>
 virtual protected void CreateShapeInternal(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
 {
 }
        /// <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.</param>
        /// <param name="guid">The guid of an element for which represntation is being created.</param>
        /// <returns>The created geometry.</returns>
        protected override IList<GeometryObject> CreateGeometryInternal(
              IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            Transform objectPosition = (lcs == null) ? Position : lcs.Multiply(Position);

            CurveLoop baseProfileCurve = Directrix.GetCurveLoop();
            if (baseProfileCurve == null)
                return null;

            CurveLoop trimmedDirectrix = IFCGeometryUtil.TrimCurveLoop(baseProfileCurve, StartParameter, EndParameter);
            if (trimmedDirectrix == null)
                return null;

            CurveLoop trimmedDirectrixInLCS = IFCGeometryUtil.CreateTransformed(trimmedDirectrix, objectPosition);

            // Create the sweep.
            double startParam = 0.0; // If the directrix isn't bound, this arbitrary parameter will do.
            Transform originTrf = null;
            Curve firstCurve = trimmedDirectrixInLCS.First();
            if (firstCurve.IsBound)
                startParam = firstCurve.GetEndParameter(0);
            originTrf = firstCurve.ComputeDerivatives(startParam, false);

            if (originTrf == null)
                return null;

            Transform referenceSurfaceLocalTransform = ReferenceSurface.GetTransformAtPoint(originTrf.Origin);
            Transform referenceSurfaceTransform = objectPosition.Multiply(referenceSurfaceLocalTransform);

            Transform profileCurveLoopsTransform = Transform.CreateTranslation(originTrf.Origin);
            profileCurveLoopsTransform.BasisX = referenceSurfaceTransform.BasisZ;
            profileCurveLoopsTransform.BasisZ = originTrf.BasisX.Normalize();
            profileCurveLoopsTransform.BasisY = profileCurveLoopsTransform.BasisZ.CrossProduct(profileCurveLoopsTransform.BasisX);

            ISet<IList<CurveLoop>> profileCurveLoops = GetTransformedCurveLoops(profileCurveLoopsTransform);
            if (profileCurveLoops == null || profileCurveLoops.Count == 0)
                return null;

            SolidOptions solidOptions = new SolidOptions(GetMaterialElementId(shapeEditScope), shapeEditScope.GraphicsStyleId);
            IList<GeometryObject> myObjs = new List<GeometryObject>();
            foreach (IList<CurveLoop> loops in profileCurveLoops)
            {
                GeometryObject myObj = GeometryCreationUtilities.CreateSweptGeometry(trimmedDirectrixInLCS, 0, startParam, loops, solidOptions);
                if (myObj != null)
                    myObjs.Add(myObj);
            }

            return myObjs;
        }