Example #1
0
        /// <summary>
        /// Clear all caches contained in this manager.
        /// </summary>
        public static void Clear()
        {
            if (m_AllocatedGeometryObjectCache != null)
            {
                m_AllocatedGeometryObjectCache.DisposeCache();
            }

            m_AllocatedGeometryObjectCache = null;
            m_AssemblyInstanceCache        = null;
            m_ClassificationCache          = null;
            m_CurveAnnotationCache         = null;
            m_DummyHostCache              = null;
            m_ElementToHandleCache        = null;
            m_ExportOptionsCache          = null;
            m_HandleToElementCache        = null;
            m_HostPartsCache              = null;
            m_LevelInfoCache              = null;
            m_MaterialLayerRelationsCache = null;
            m_MaterialLayerSetCache       = null;
            m_MaterialHandleCache         = null;
            m_MaterialRelationsCache      = null;
            m_MEPCache                                 = null;
            m_RailingCache                             = null;
            m_RailingSubElementCache                   = null;
            m_ParameterCache                           = null;
            m_PartExportedCache                        = null;
            m_PresentationStyleCache                   = null;
            m_SpaceBoundaryCache                       = null;
            m_SpaceOccupantInfoCache                   = null;
            m_SpatialElementHandleCache                = null;
            m_TypeObjectsCache                         = null;
            m_TypeRelationsCache                       = null;
            m_WallConnectionDataCache                  = null;
            m_UnitsCache                               = null;
            m_ZoneInfoCache                            = null;
            m_TypePropertyInfoCache                    = null;
            m_DoublePropertyInfoCache                  = null;
            m_BooleanPropertyInfoCache                 = null;
            m_IntegerPropertyInfoCache                 = null;
            m_StringPropertyInfoCache                  = null;
            m_HandleTypeCache                          = null;
            m_HandleIsSubTypeOfCache                   = null;
            m_GroupElementGeometryCache                = null;
            m_PropertySetsForTypeCache                 = null;
            m_ConditionalPropertySetsForTypeCache      = null;
            m_MaterialIdToStyleHandleCache             = null;
            m_DefaultCartesianTransformationOperator3D = null;
            m_StairRampContainerInfoCache              = null;
        }
        /// <summary>
        /// Clear all caches contained in this manager.
        /// </summary>
        public static void Clear()
        {
            if (m_AllocatedGeometryObjectCache != null)
                m_AllocatedGeometryObjectCache.DisposeCache();
            ParameterUtil.ClearParameterCache();

            m_AllocatedGeometryObjectCache = null;
            m_AreaSchemeCache = null;
            m_AssemblyInstanceCache = null;
            m_BeamSystemCache = null;
            m_CategoryClassNameCache = null;
            m_CategoryTypeCache = null;
            m_CeilingSpaceRelCache = null;
            m_ClassificationCache = null;
            m_ClassificationLocationCache = null;
            m_ConditionalPropertySetsForTypeCache = null;
            m_ContainmentCache = null;
            m_CurveAnnotationCache = null;
            m_DefaultCartesianTransformationOperator3D = null;
            m_DummyHostCache = null;
            m_ElementToHandleCache = null;
            m_ElementsInAssembliesCache = null;
            m_ExportOptionsCache = null;
            m_FabricAreaHandleCache = null;
            m_GridCache = null;
            m_GroupCache = null;
            m_GroupElementGeometryCache = null;
            m_HandleToElementCache = null;
            m_HostPartsCache = null;
            m_IsExternalParameterValueCache = null;
            m_LevelInfoCache = null;
            m_MaterialIdToStyleHandleCache = null;
            m_MaterialLayerRelationsCache = null;
            m_MaterialLayerSetCache = null;
            m_MaterialHandleCache = null;
            m_MaterialRelationsCache = null;
            m_MEPCache = null;
            m_ParameterCache = null;
            m_PartExportedCache = null;
            m_PresentationLayerSetCache = null;
            m_PresentationStyleCache = null;
            m_PropertyInfoCache = null;
            m_PropertyMapCache = null;
            m_PropertySetsForTypeCache = null;
            m_RailingCache = null;
            m_RailingSubElementCache = null;
            m_SpaceBoundaryCache = null;
            m_SpaceOccupantInfoCache = null;
            m_SpatialElementHandleCache = null;
            m_StairRampContainerInfoCache = null;
            m_SystemsCache = null;
            m_TrussCache = null;
            m_TypeObjectsCache = null;
            m_TypePropertyInfoCache = null;
            m_TypeRelationsCache = null;
            m_ViewScheduleElementCache = null;
            m_WallConnectionDataCache = null;
            m_WallTypeCache = null;
            m_UnitsCache = null;
            m_ZoneCache = null;
            m_ZoneInfoCache = null;
        }
        /// <summary>
        /// Exports text note elements.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="textNote">
        /// The text note element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, TextNote textNote, IFCProductWrapper productWrapper, PresentationStyleAssignmentCache cache)
        {
            IFCFile file = exporterIFC.GetFile();
            using (IFCTransaction tr = new IFCTransaction(file))
            {
                string textString = textNote.Text;
                if (String.IsNullOrEmpty(textString))
                    throw new Exception("TextNote does not have test string.");

                ElementId symId = textNote.GetTypeId();
                if (symId == ElementId.InvalidElementId)
                    throw new Exception("TextNote does not have valid type id.");

                IFCAnyHandle presHnd = cache.Find(symId);
                if (!presHnd.HasValue)
                {
                    TextElementType textElemType = textNote.Symbol;
                    CreatePresentationStyleAssignmentForTextElementType(exporterIFC, textElemType, cache);
                    presHnd = cache.Find(symId);
                    if (!presHnd.HasValue)
                        throw new Exception("Failed to create presentation style assignment for TextElementType.");
                }

                IList<IFCAnyHandle> presHndSet = new List<IFCAnyHandle>();
                presHndSet.Add(presHnd);

                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, textNote))
                {
                    double linScale = exporterIFC.LinearScale;
                    const double planScale = 100.0;  // currently hardwired.

                    XYZ orig = textNote.Coord;
                    orig = orig.Multiply(linScale);
                    XYZ yDir = textNote.UpDirection;
                    XYZ xDirection = textNote.BaseDirection;
                    XYZ zDirection = xDirection.CrossProduct(yDir);

                    double sizeX = textNote.LineWidth * linScale * planScale;
                    double sizeY = textNote.Height * linScale * planScale;

                    // When we display text on screen, we "flip" it if the xDirection is negative with relation to
                    // the X-axis.  So if it is, we'll flip x and y.
                    bool flipOrig = false;
                    if (xDirection.X < 0)
                    {
                        xDirection = xDirection.Multiply(-1.0);
                        yDir = yDir.Multiply(-1.0);
                        flipOrig = true;
                    }

                    // xFactor, yFactor only used if flipOrig.
                    double xFactor = 0.0, yFactor = 0.0;
                    IFCLabel boxAlign = ConvertTextNoteAlignToBoxAlign(textNote, out xFactor, out yFactor);

                    // modify the origin to match the alignment.  In Revit, the origin is at the top-left (unless flipped,
                    // then bottom-right).
                    if (flipOrig)
                    {
                        orig = orig.Add(xDirection.Multiply(sizeX * xFactor));
                        orig = orig.Add(yDir.Multiply(sizeY * yFactor));
                    }

                    IFCAnyHandle origin = ExporterUtil.CreateAxis(file, orig, zDirection, xDirection);

                    IFCLabel textStringLabel = IFCLabel.Create(textString);
                    IFCAnyHandle extent = file.CreatePlanarExtent(sizeX, sizeY);
                    IFCAnyHandle repItemHnd = file.CreateTextLiteralWithExtent(textStringLabel, origin, IFCTextPath.Left, extent, boxAlign);
                    IFCAnyHandle annoTextOccHnd = file.CreateStyledItem(repItemHnd, presHndSet, IFCLabel.Create());

                    ElementId catId = textNote.Category != null ? textNote.Category.Id : ElementId.InvalidElementId;
                    IFCLabel identifierOpt = IFCLabel.Create("Annotation");
                    IFCLabel repTypeOpt = IFCLabel.Create("Annotation2D");	// this is by IFC2x3 convention, not temporary
                    HashSet<IFCAnyHandle> bodyItems = new HashSet<IFCAnyHandle>();
                    bodyItems.Add(repItemHnd);
                    IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateShapeRepresentation(exporterIFC, catId, exporterIFC.Get2DContextHandle(), identifierOpt, repTypeOpt, bodyItems);

                    if (!bodyRepHnd.HasValue)
                        throw new Exception("Failed to create shape representation.");

                    IList<IFCAnyHandle> shapeReps = new List<IFCAnyHandle>();
                    shapeReps.Add(bodyRepHnd);

                    IFCAnyHandle prodShapeHnd = file.CreateProductDefinitionShape(IFCLabel.Create(), IFCLabel.Create(), shapeReps);
                    IFCAnyHandle annoHnd = file.CreateAnnotation(IFCLabel.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(),
                        IFCLabel.Create(), IFCLabel.Create(), IFCLabel.Create(), setter.GetPlacement(), prodShapeHnd);

                    productWrapper.AddAnnotation(annoHnd, setter.GetLevelInfo(), true);
                }

                tr.Commit();
            }
        }
        /// <summary>
        /// Creates IfcPresentationStyleAssignment for text element type.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="textElementType">
        /// The text note element type.
        /// </param>
        /// <param name="cache">
        /// The cache of IfcPresentationStyleAssignment.
        /// </param>
        static void CreatePresentationStyleAssignmentForTextElementType(ExporterIFC exporterIFC, TextElementType textElementType, PresentationStyleAssignmentCache cache)
        {
            IFCFile file = exporterIFC.GetFile();

            Parameter fontNameParam = textElementType.get_Parameter(BuiltInParameter.TEXT_FONT);
            string fontName = (fontNameParam != null && fontNameParam.StorageType == StorageType.String) ? fontNameParam.AsString() : null;


            Parameter fontSizeParam = textElementType.get_Parameter(BuiltInParameter.TEXT_SIZE);
            double fontSize = (fontSizeParam != null && fontSizeParam.StorageType == StorageType.Double) ? fontSizeParam.AsDouble() : -1.0;

            double scale = exporterIFC.LinearScale;
            double viewScale = 100.0;  // currently hardwired.
            fontSize *= (scale * viewScale);

            IFCMeasureValue ifcFontSize = IFCMeasureValue.Create(fontSize);
            IFCLabel ifcPreDefinedItemName = IFCLabel.Create("Text Font");
            IFCLabel ifcFontName = IFCLabel.Create(fontName);

            IList<IFCLabel> fontNameList = new List<IFCLabel>();
            fontNameList.Add(ifcFontName);

            IFCAnyHandle textSyleFontModelHnd = file.CreateTextStyleFontModel(ifcPreDefinedItemName, fontNameList, IFCLabel.Create(), IFCLabel.Create(), IFCLabel.Create(), ifcFontSize);

            Parameter fontColorParam = textElementType.get_Parameter(BuiltInParameter.LINE_COLOR);
            int color = (fontColorParam != null && fontColorParam.StorageType == StorageType.Integer) ? fontColorParam.AsInteger() : 0;

            double blueVal = ((double)((color & 0xff0000) >> 16)) / 255.0;
            double greenVal = ((double)((color & 0xff00) >> 8)) / 255.0;
            double redVal = ((double)(color & 0xff)) / 255.0;

            IFCAnyHandle colorHnd = file.CreateColourRgb(IFCLabel.Create(), redVal, greenVal, blueVal);
            IFCAnyHandle fontColorHnd = file.CreateTextStyleForDefinedFont(colorHnd, IFCAnyHandle.Create());

            IFCLabel ifcAttrName = IFCLabel.Create(textElementType.Name);
            IFCAnyHandle textStyleHnd = file.CreateTextStyle(ifcAttrName, fontColorHnd, IFCAnyHandle.Create(), textSyleFontModelHnd);

            if (!textStyleHnd.HasValue)
                return;

            ICollection<IFCAnyHandle> presStyleSet = new System.Collections.ObjectModel.Collection<IFCAnyHandle>();
            presStyleSet.Add(textStyleHnd);

            IFCAnyHandle presStyleHnd = file.CreatePresentationStyleAssignment(presStyleSet);
            if (!presStyleHnd.HasValue)
                return;

            cache.Register(textElementType.Id, presStyleHnd);
        }
        /// <summary>
        /// Creates IfcPresentationStyleAssignment for text element type.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="textElemType">
        /// The text note element type.
        /// </param>
        /// <param name="cache">
        /// The cache of IfcPresentationStyleAssignment.
        /// </param>
        static void CreatePresentationStyleAssignmentForTextElementType(ExporterIFC exporterIFC, TextElementType textElemType, PresentationStyleAssignmentCache cache)
        {
            IFCFile file = exporterIFC.GetFile();

            string fontName;
            if (!ParameterUtil.GetStringValueFromElement(textElemType, BuiltInParameter.TEXT_FONT, out fontName))
                fontName = null;

            double fontSize;
            if (!ParameterUtil.GetDoubleValueFromElement(textElemType, BuiltInParameter.TEXT_SIZE, out fontSize))
                fontSize = -1.0;

            double scale = exporterIFC.LinearScale;
            double viewScale = 100.0;  // currently hardwired.
            fontSize *= (scale * viewScale);

            string ifcPreDefinedItemName = "Text Font";

            IList<string> fontNameList = new List<string>();
            fontNameList.Add(fontName);

            IFCAnyHandle textSyleFontModelHnd = IFCInstanceExporter.CreateTextStyleFontModel(file, ifcPreDefinedItemName, fontNameList, null, null, null, IFCDataUtil.CreateAsPositiveLengthMeasure(fontSize));

            int color;
            ParameterUtil.GetIntValueFromElement(textElemType, BuiltInParameter.LINE_COLOR, out color);

            double blueVal = ((double)((color & 0xff0000) >> 16)) / 255.0;
            double greenVal = ((double)((color & 0xff00) >> 8)) / 255.0;
            double redVal = ((double)(color & 0xff)) / 255.0;

            IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(file, null, redVal, greenVal, blueVal);
            IFCAnyHandle fontColorHnd = IFCInstanceExporter.CreateTextStyleForDefinedFont(file, colorHnd, null);

            string ifcAttrName = textElemType.Name;
            IFCAnyHandle textStyleHnd = IFCInstanceExporter.CreateTextStyle(file, textElemType.Name, fontColorHnd, null, textSyleFontModelHnd);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(textStyleHnd))
                return;

            HashSet<IFCAnyHandle> presStyleSet = new HashSet<IFCAnyHandle>();
            presStyleSet.Add(textStyleHnd);

            IFCAnyHandle presStyleHnd = IFCInstanceExporter.CreatePresentationStyleAssignment(file, presStyleSet);
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(presStyleHnd))
                return;

            cache.Register(textElemType.Id, presStyleHnd);
        }
        /// <summary>
        /// Clear all caches contained in this manager.
        /// </summary>
        public static void Clear()
        {
            if (m_AllocatedGeometryObjectCache != null)
            {
                m_AllocatedGeometryObjectCache.DisposeCache();
            }
            ParameterUtil.ClearParameterCache();

            m_AllocatedGeometryObjectCache = null;
            m_AreaSchemeCache                          = null;
            m_AssemblyInstanceCache                    = null;
            m_BeamSystemCache                          = null;
            m_CategoryClassNameCache                   = null;
            m_CategoryTypeCache                        = null;
            m_CeilingSpaceRelCache                     = null;
            m_ClassificationCache                      = null;
            m_ClassificationLocationCache              = null;
            m_ConditionalPropertySetsForTypeCache      = null;
            m_ContainmentCache                         = null;
            m_CurveAnnotationCache                     = null;
            m_DefaultCartesianTransformationOperator3D = null;
            m_DummyHostCache            = null;
            m_ElementToHandleCache      = null;
            m_ElementsInAssembliesCache = null;
            m_ExportOptionsCache        = null;
            m_FabricAreaHandleCache     = null;
            m_GridCache  = null;
            m_GroupCache = null;
            m_GroupElementGeometryCache     = null;
            m_HandleToElementCache          = null;
            m_HostPartsCache                = null;
            m_IsExternalParameterValueCache = null;
            m_LevelInfoCache                = null;
            m_MaterialIdToStyleHandleCache  = null;
            m_MaterialLayerRelationsCache   = null;
            m_MaterialLayerSetCache         = null;
            m_MaterialHandleCache           = null;
            m_MaterialRelationsCache        = null;
            m_MEPCache                    = null;
            m_ParameterCache              = null;
            m_PartExportedCache           = null;
            m_PresentationLayerSetCache   = null;
            m_PresentationStyleCache      = null;
            m_PropertyInfoCache           = null;
            m_PropertyMapCache            = null;
            m_PropertySetsForTypeCache    = null;
            m_RailingCache                = null;
            m_RailingSubElementCache      = null;
            m_SpaceBoundaryCache          = null;
            m_SpaceOccupantInfoCache      = null;
            m_SpatialElementHandleCache   = null;
            m_StairRampContainerInfoCache = null;
            m_SystemsCache                = null;
            m_TrussCache                  = null;
            m_TypeObjectsCache            = null;
            m_TypePropertyInfoCache       = null;
            m_TypeRelationsCache          = null;
            m_ViewScheduleElementCache    = null;
            m_WallConnectionDataCache     = null;
            m_WallTypeCache               = null;
            m_UnitsCache                  = null;
            m_ZoneCache                   = null;
            m_ZoneInfoCache               = null;
        }
        /// <summary>
        /// Implements the method that Autodesk Revit will invoke to perform an export to IFC.
        /// </summary>
        /// <param name="document">The document to export.</param>
        /// <param name="exporterIFC">The IFC exporter object.</param>
        /// <param name="view">The 3D view that is being exported.</param>
        /// <param name="filterView">The view whose filter visibility settings govern the export.</param>
        public void ExportIFC(Autodesk.Revit.DB.Document document, ExporterIFC exporterIFC, Autodesk.Revit.DB.View view, Autodesk.Revit.DB.View filterView)
        {
            try
            {
                String writeIFCExportedElementsVar = Environment.GetEnvironmentVariable("WriteIFCExportedElements");
                if (writeIFCExportedElementsVar != null && writeIFCExportedElementsVar.Length > 0)
                {
                    m_Writer = new StreamWriter(@"c:\ifc-output-filters.txt");
                }

                //init common properties
                m_ParameterCache = new ParameterCache();
                ExporterInitializer.InitPropertySets(m_ParameterCache, exporterIFC.FileVersion);
                ExporterInitializer.InitQuantities(m_ParameterCache, exporterIFC.FileVersion);

                m_PresentationStyleCache = new PresentationStyleAssignmentCache();

                m_CurveAnnotationCache = new CurveAnnotationCache();

                //export spatial element - none or 1st level room boundaries
                if (exporterIFC.SpaceBoundaryLevel == 0 || exporterIFC.SpaceBoundaryLevel == 1)
                {
                    SpatialElementExporter.InitializeSpatialElementGeometryCalculator(document, exporterIFC);
                    ElementFilter spatialElementFilter = ElementFilteringUtil.GetSpatialElementFilter(document, exporterIFC);
                    FilteredElementCollector collector = (filterView == null) ? new FilteredElementCollector(document) : new FilteredElementCollector(document, filterView.Id);
                    collector.WherePasses(spatialElementFilter);
                    foreach (Element element in collector)
                    {
                        ExportElement(exporterIFC, filterView, element);
                    }
                }
                else if (exporterIFC.SpaceBoundaryLevel == 2)
                {
                    SpatialElementExporter.ExportSpatialElement2ndLevel(this, exporterIFC, document, filterView);
                }

                //export other elements
                ElementFilter nonSpatialElementFilter = ElementFilteringUtil.GetNonSpatialElementFilter(document, exporterIFC);
                FilteredElementCollector collector2 = (filterView == null) ? new FilteredElementCollector(document) : new FilteredElementCollector(document, filterView.Id);
                collector2.WherePasses(nonSpatialElementFilter);
                foreach (Element element in collector2)
                {
                    ExportElement(exporterIFC, filterView, element);
                }


                // These elements are created internally, but we allow custom property sets for them.  Create them here.
                using (IFCProductWrapper productWrapper = IFCProductWrapper.Create(exporterIFC, true))
                {
                    // This allows for custom property sets for buildings. There are currently no custom quantities, 
                    // but the code could be added here at a later date.
                    IFCAnyHandle buildingHnd = ExporterIFCUtils.GetBuilding(exporterIFC);
                    productWrapper.AddBuilding(buildingHnd);
                    ExportElementProperties(exporterIFC, document.ProjectInformation, productWrapper);
                }
            }
            finally
            {
                if (m_Writer != null)
                    m_Writer.Close();
            }

        }
Example #8
0
        /// <summary>
        /// Clear all caches contained in this manager.
        /// </summary>
        public static void Clear()
        {
            if (m_AllocatedGeometryObjectCache != null)
                m_AllocatedGeometryObjectCache.DisposeCache();

            m_AllocatedGeometryObjectCache = null;
            m_AssemblyInstanceCache = null;
            m_ClassificationCache = null;
            m_CurveAnnotationCache = null;
            m_DummyHostCache = null;
            m_ElementToHandleCache = null;
            m_ExportOptionsCache = null;
            m_HandleToElementCache = null;
            m_HostPartsCache = null;
            m_LevelInfoCache = null;
            m_MaterialLayerRelationsCache = null;
            m_MaterialLayerSetCache = null;
            m_MaterialHandleCache = null;
            m_MaterialRelationsCache = null;
            m_MEPCache = null;
            m_RailingCache = null;
            m_RailingSubElementCache = null;
            m_ParameterCache = null;
            m_PartExportedCache = null;
            m_PresentationStyleCache = null;
            m_SpaceBoundaryCache = null;
            m_SpaceOccupantInfoCache = null;
            m_SpatialElementHandleCache = null;
            m_TypeObjectsCache = null;
            m_TypeRelationsCache = null;
            m_WallConnectionDataCache = null;
            m_UnitsCache = null;
            m_ZoneInfoCache = null;
            m_TypePropertyInfoCache = null;
            m_DoublePropertyInfoCache = null;
            m_BooleanPropertyInfoCache = null;
            m_IntegerPropertyInfoCache = null;
            m_StringPropertyInfoCache = null;
            m_HandleTypeCache = null;
            m_HandleIsSubTypeOfCache = null;
            m_GroupElementGeometryCache = null;
            m_PropertySetsForTypeCache = null;
            m_ConditionalPropertySetsForTypeCache = null;
            m_MaterialIdToStyleHandleCache = null;
            m_DefaultCartesianTransformationOperator3D = null;
            m_StairRampContainerInfoCache = null;
        }