private bool hasFittingsInSystem()
        {
            PressureLossReportHelper helper = PressureLossReportHelper.instance;

            if (helper == null)
            {
                return(false);
            }
            //find the first fitting
            List <MEPSystem> systems = helper.getSortedSystems();

            if (systems == null || systems.Count < 1)
            {
                return(false);
            }
            foreach (MEPSystem system in systems)
            {
                List <MEPSection> sections = new List <MEPSection>();
                MEPSystemInfo.getSectionsFromSystem(system, sections);
                foreach (MEPSection section in sections)
                {
                    //find one section which contains both segment and fitting
                    List <FamilyInstance> fittings = new List <FamilyInstance>();

                    SectionsInfo.getSectionElements(section, null, fittings, null, null);

                    if (fittings.Count > 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public string getTotalPressureLossByType(MEPSection section, SectionMemberType eType)
        {
            string strVal = "";

            if (section != null)
            {
                double dVal = 0.0;
                if (eType == SectionMemberType.Segment)
                {
                    List <MEPCurve> curves = new List <MEPCurve>();
                    SectionsInfo.getSectionElements(section, curves, null, null, null);
                    foreach (MEPCurve crv in curves)
                    {
                        dVal += section.GetPressureDrop(crv.Id);
                    }
                }
                else if (eType == SectionMemberType.Fitting)
                {
                    List <FamilyInstance> fittings = new List <FamilyInstance>();
                    SectionsInfo.getSectionElements(section, null, fittings, null, null);
                    foreach (FamilyInstance famInst in fittings)
                    {
                        dVal += section.GetPressureDrop(famInst.Id);
                    }
                }
                else if (eType == SectionMemberType.AirTerminal)
                {
                    List <FamilyInstance> airTerminals = new List <FamilyInstance>();
                    SectionsInfo.getSectionElements(section, null, null, airTerminals, null);
                    foreach (FamilyInstance famInst in airTerminals)
                    {
                        dVal += section.GetPressureDrop(famInst.Id);
                    }
                }
                else if (eType == SectionMemberType.Equipment)
                {
                    List <FamilyInstance> equipments = new List <FamilyInstance>();
                    SectionsInfo.getSectionElements(section, null, null, null, equipments);
                    foreach (FamilyInstance famInst in equipments)
                    {
                        dVal += section.GetPressureDrop(famInst.Id);
                    }
                }

                if (eType == SectionMemberType.Section)
                {
                    dVal = section.TotalPressureLoss;
                }

                if (domain == ReportResource.pipeDomain)
                {
                    strVal = FormatUtils.Format(doc, UnitType.UT_Piping_Pressure, dVal);
                }
                else
                {
                    strVal = FormatUtils.Format(doc, UnitType.UT_HVAC_Pressure, dVal);
                }
            }
            return(strVal);
        }
        static public string getSectionInfoByParamName(MEPSection section, string paramName, int nGetFrom, ElementId id)
        {
            string paramVal = "";

            if (section == null || paramName == null || (nGetFrom & (int)SectionMemberType.Section) == 0)
            {
                return(paramVal);
            }

            PressureLossReportHelper helper = PressureLossReportHelper.instance;

            if (helper == null)
            {
                return(paramVal);
            }

            if (paramName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_PRESSURE_DROP) ||
                paramName == ReportResource.pressureLoss)
            {
                double dVal = section.GetPressureDrop(id);

                if (helper.Domain == ReportResource.pipeDomain)
                {
                    paramVal = FormatUtils.Format(helper.Doc, UnitType.UT_Piping_Pressure, dVal);
                }
                else
                {
                    paramVal = FormatUtils.Format(helper.Doc, UnitType.UT_HVAC_Pressure, dVal);
                }
                return(paramVal);
            }
            else if (paramName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_LOSS_COEFFICIENT) ||
                     paramName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_FITTING_LOSS_KFACTOR_PARAM))
            {
                double dVal = section.GetCoefficient(id);
                paramVal = FormatUtils.Format(helper.Doc, UnitType.UT_Number, dVal);
                return(paramVal);
            }

            else if (paramName == LabelUtils.GetLabelFor(BuiltInParameter.CURVE_ELEM_LENGTH))
            {
                double dVal = section.GetSegmentLength(id);
                paramVal = FormatUtils.Format(helper.Doc, UnitType.UT_Length, dVal);
                return(paramVal);
            }

            Dictionary <string, string> fieldAndValue = new Dictionary <string, string>();

            SectionsInfo.getSectionCommonInfo(section, fieldAndValue);

            if (fieldAndValue.ContainsKey(paramName))
            {
                return(fieldAndValue[paramName]);
            }

            return(paramVal);
        }
Exemplo n.º 4
0
        public void generateAviliableFields(PressureLossReportData reportData)
        {
            if (doc == null)
            {
                return;
            }

            SectionsInfo.generateSectionFields(reportData);
            SegmentsInfo.generateSegmentFields(reportData);
            FittingsInfo.generateFittingFields(reportData);
        }
        static public double getFittingsLossCoefficient(MEPSection section)
        {
            double dVal = 0.0;
            List <FamilyInstance> fittings = new List <FamilyInstance>();

            SectionsInfo.getSectionElements(section, null, fittings, null, null);
            foreach (FamilyInstance famInst in fittings)
            {
                dVal += section.GetCoefficient(famInst.Id);
            }

            return(dVal);
        }
        private void resetSettings()
        {
            if (settings == null)
            {
                settings = new PressureLossReportData();
            }

            if (settings.AvailableFields == null || settings.AvailableFields.Count < 1)
            {
                SectionsInfo.generateSectionFields(settings);
            }

            if (settings.StraightSegFields == null || settings.StraightSegFields.Count < 1)
            {
                SegmentsInfo.generateSegmentFields(settings);
            }

            if (settings.FittingFields == null || settings.FittingFields.Count < 1)
            {
                FittingsInfo.generateFittingFields(settings);
            }
        }
Exemplo n.º 7
0
        // TODO
        public override bool save(string fileName, PressureLossReportData reportData)
        {
            try
             {
            PressureLossReportHelper helper = PressureLossReportHelper.instance;
            CsvStreamWriter writer = new CsvStreamWriter();

            //title
            string strTitle = ReportResource.reportName;
            if (helper.Domain == ReportResource.pipeDomain)
               strTitle = ReportResource.pipeReportName;
            else
               strTitle = ReportResource.ductReportName;

            DataTable titleTB = new DataTable();
            titleTB.Columns.Add();
            titleTB.Rows.Add(strTitle);
            writer.AddData(titleTB, 1);
            writer.addOneEmptyRow();

            DataTable tbTitle = new DataTable();
            DataTable tb = new DataTable();

            //Project info
            ReportProjectInfo proInfo = new ReportProjectInfo();
            proInfo.writeToCsv(writer);

            writer.addOneEmptyRow();

            //each system
            List<MEPSystem> systems = helper.getSortedSystems();
            if (systems == null || systems.Count < 1)
               return false;
            foreach (MEPSystem sysElem in systems)
            {
               if (sysElem == null)
                  continue;

               //system name and info
               MEPSystemInfo systemInfo = new MEPSystemInfo(sysElem);
               systemInfo.writeToCsv(writer);

               if (systemInfo.needToWrite())
                  writer.addOneEmptyRow();

               List<MEPSection> sections = new List<MEPSection>();
               MEPSystemInfo.getSectionsFromSystem(sysElem, sections);

               //sections: title and info
               SectionsInfo sectionInfo = new SectionsInfo(sections);
               sectionInfo.writeToCsv(writer);

               if (reportData.DisplayCriticalPath)
               {
                  string criticalInfo = ReportResource.criticalPath + " : " + MEPSystemInfo.getCriticalPath(sysElem);
                  criticalInfo += " ; " + ReportResource.totalPressureLoss + " : " + MEPSystemInfo.getCriticalPathPressureLoss(sysElem);

                  writer.addTitleRow(criticalInfo);
               }

               writer.addOneEmptyRow();

               //segments: title and info
               SegmentsInfo segmentsInfo = new SegmentsInfo(sections);
               segmentsInfo.writeToCsv(writer);
               if (segmentsInfo.needToWrite())
                  writer.addOneEmptyRow();

               //fittings: title and info
               FittingsInfo fittingsInfo = new FittingsInfo(sections);
               fittingsInfo.writeToCsv(writer);
               if (fittingsInfo.needToWrite())
                  writer.addOneEmptyRow();
            }

            writer.Save(fileName);
            return true;
             }
             catch(Exception e)
             {
            if (e.Message == ReportConstants.failed_to_delete)
            {
               string subMsg = ReportResource.csvSubMsg.Replace("%FULLPATH%", fileName);
               UIHelperFunctions.postWarning(ReportResource.csvGenerateTitle, ReportResource.csvMsg, subMsg);
            }
            else
               UIHelperFunctions.postWarning(ReportResource.csvGenerateTitle, ReportResource.csvMsg);
            return false;
             }
        }
Exemplo n.º 8
0
        public override bool save(string fileName, PressureLossReportData reportData)
        {
            HtmlStreamWriter writer = new HtmlStreamWriter();
             try
             {
              // Check if the xslt file exists

              if (!File.Exists(writer.XsltFileName))
              {
              string subMsg = ReportResource.xsltFileSubMsg
            .Replace("%FULLPATH%", writer.XsltFileName );

              UIHelperFunctions.postWarning(
            ReportResource.htmlGenerateTitle,
            ReportResource.xsltFileMsg, subMsg );

              return false;
              }

            PressureLossReportHelper helper = PressureLossReportHelper.instance;
            if (helper == null)
               return false;

            //xml head
            writer.WriteStartDocument(false);

            //root node
            string transXML = "UserPressureLossReport";
            writer.WriteStartElement(transXML);

            //title
            writer.WriteElementString("Title", ReportResource.reportName);

            //domain
            if (helper.Domain == ReportResource.pipeDomain)
               writer.WriteElementString("DomainName", ReportResource.pipeReportName);
            else
               writer.WriteElementString("DomainName", ReportResource.ductReportName);

            //write project info
            ReportProjectInfo proInfo = new ReportProjectInfo();
            proInfo.writeToHTML(writer);

            //each system
            List<MEPSystem> systems = helper.getSortedSystems();
            if (systems == null || systems.Count < 1)
               return false;

            foreach (MEPSystem sysElem in systems)
            {
               if (sysElem == null)
                  continue;

               //system node
               string xmlString = "System";
               writer.WriteStartElement(xmlString);

               //system info: name and info
               MEPSystemInfo systemInfo = new MEPSystemInfo(sysElem);
               systemInfo.writeToHTML(writer);

               //critical path
               if (helper.ReportData.DisplayCriticalPath)
               {
                  string criticalInfo =ReportResource.criticalPath + " : " + MEPSystemInfo.getCriticalPath(sysElem);
                  criticalInfo +=  " ; "+ ReportResource.totalPressureLoss + " : " + MEPSystemInfo.getCriticalPathPressureLoss(sysElem);
                  writer.WriteElementString("CriticalPath", criticalInfo);
               }

               List<MEPSection> sections = new List<MEPSection>();
               MEPSystemInfo.getSectionsFromSystem(sysElem, sections);

               //sections: title and info
               SectionsInfo sectionInfo = new SectionsInfo(sections);
               sectionInfo.writeToHTML(writer);

               //segments: title and info
               SegmentsInfo segmentsInfo = new SegmentsInfo(sections);
               segmentsInfo.writeToHTML(writer);

               //fittings: title and info
               FittingsInfo fittingsInfo = new FittingsInfo(sections);
               fittingsInfo.writeToHTML(writer);

               writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();

            writer.Save(fileName);
            return true;
             }
             catch
             {
            writer.Close();
            //delete xml
            File.Delete(writer.XmlFileName);
            UIHelperFunctions.postWarning(ReportResource.htmlGenerateTitle, ReportResource.htmlMsg);
            return false;
             }
        }
        static public void generateFittingFields(PressureLossReportData reportData)
        {
            if (reportData == null)
            {
                return;
            }

            PressureLossReportHelper helper = PressureLossReportHelper.instance;

            if (helper == null)
            {
                return;
            }

            List <PressureLossParameter> fittingParameters = new List <PressureLossParameter>();

            //default fitting selected fields
            //SectionMemberType means where the value is from: section or fitting
            int nOrder = 1;

            fittingParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.ALL_MODEL_MARK), false, -1, (int)SectionMemberType.Fitting));
            fittingParameters.Add(new PressureLossParameter(ReportResource.elementId, true, nOrder++, (int)SectionMemberType.Fitting));

            if (helper.Domain == ReportResource.pipeDomain)
            {
                fittingParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_FITTING_LOSS_METHOD_SERVER_PARAM), true, nOrder++, (int)SectionMemberType.Fitting));
            }
            else
            {
                fittingParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_DUCT_FITTING_LOSS_METHOD_SERVER_PARAM), true, nOrder++, (int)SectionMemberType.Fitting));
            }

            //pressure loss fields is not visible in settings dialog, the order 100 is to make sure it always is the last one field
            fittingParameters.Add(new PressureLossParameter(ReportResource.pressureLoss, true, 100, (int)SectionMemberType.Section, false));

            //find the first fitting
            List <MEPSystem> systems = helper.getSortedSystems();

            if (systems == null || systems.Count < 1)
            {
                return;
            }
            foreach (MEPSystem system in systems)
            {
                List <MEPSection> sections = new List <MEPSection>();
                MEPSystemInfo.getSectionsFromSystem(system, sections);
                foreach (MEPSection section in sections)
                {
                    //find one section which contains both segment and fitting
                    List <FamilyInstance> fittings = new List <FamilyInstance>();

                    SectionsInfo.getSectionElements(section, null, fittings, null, null);

                    if (fittings.Count < 1)
                    {
                        continue;
                    }

                    //fitting's instance parameters

                    PressureLossParameter PLParam1 = new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.ELEM_FAMILY_PARAM), false, -1, (int)SectionMemberType.Type);
                    if (!fittingParameters.Contains(PLParam1))
                    {
                        fittingParameters.Add(PLParam1);
                    }

                    PressureLossParameter PLParam2 = new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM), false, -1, (int)SectionMemberType.Type);
                    if (!fittingParameters.Contains(PLParam2))
                    {
                        fittingParameters.Add(PLParam2);
                    }

                    PressureLossParameter PLParam3 = new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_SIZE_FORMATTED_PARAM), false, -1, (int)SectionMemberType.Fitting);
                    if (!fittingParameters.Contains(PLParam3))
                    {
                        fittingParameters.Add(PLParam3);
                    }

                    foreach (Parameter param in fittings[0].Parameters)
                    {
                        //exclude the parameters under constrains/Graphics/Geometry and other groups
                        if (param.Definition.ParameterGroup == BuiltInParameterGroup.PG_CONSTRAINTS ||
                            param.Definition.ParameterGroup == BuiltInParameterGroup.PG_GRAPHICS ||
                            param.Definition.ParameterGroup == BuiltInParameterGroup.PG_GEOMETRY ||
                            LabelUtils.GetLabelFor(param.Definition.ParameterGroup) == ReportResource.other ||
                            param.Definition.Name == LabelUtils.GetLabelFor(BuiltInParameter.RBS_DUCT_PRESSURE_DROP))
                        {
                            continue;
                        }

                        PressureLossParameter PLParam = new PressureLossParameter(param.Definition.Name, false, -1, (int)SectionMemberType.Fitting);
                        if (!fittingParameters.Contains(PLParam))
                        {
                            fittingParameters.Add(PLParam);
                        }
                    }

                    //Fitting symbol parameters

                    FamilySymbol famSym = fittings[0].Symbol;
                    if (famSym != null)
                    {
                        foreach (Parameter param in famSym.Parameters)
                        {
                            //exclude the parameters under construction and other groups
                            if (param.Definition.ParameterGroup == BuiltInParameterGroup.PG_CONSTRUCTION ||
                                LabelUtils.GetLabelFor(param.Definition.ParameterGroup) == ReportResource.other)
                            {
                                continue;
                            }

                            PressureLossParameter PLParam = new PressureLossParameter(param.Definition.Name, false, -1, (int)SectionMemberType.Type);
                            if (!fittingParameters.Contains(PLParam))
                            {
                                fittingParameters.Add(PLParam);
                            }
                        }
                    }

                    reportData.FittingFields = fittingParameters;

                    return;
                }
            }
        }
Exemplo n.º 10
0
        private bool getFittingInfo(MEPSection section, DataTable fittingTB, bool forHTML = false)
        {
            if (fittingTB == null || section == null)
            {
                return(false);
            }

            PressureLossReportHelper helper = PressureLossReportHelper.instance;

            if (helper == null || helper.ReportData == null)
            {
                return(false);
            }

            List <string> fittingFields = new List <string>();

            if (helper.ReportData.FittingFields != null)
            {
                getFields(fittingFields);
            }

            if (forHTML)
            {
                helper.addColumns(fittingTB, fittingFields.Count);
            }
            else
            {
                helper.addColumns(fittingTB, fittingFields.Count + 2);
            }

            List <FamilyInstance> fittings = new List <FamilyInstance>();

            SectionsInfo.getSectionElements(section, null, fittings, null, null);
            if (fittings.Count < 1)
            {
                return(false);
            }

            int nIndex = 0;

            foreach (FamilyInstance fitting in fittings)
            {
                List <string> paramVals = new List <string>();
                if (!forHTML)
                {
                    if (nIndex == 0)
                    {
                        paramVals.Add(section.Number.ToString());
                    }
                    else
                    {
                        paramVals.Add(" ");
                    }
                }

                foreach (string fieldName in fittingFields)
                {
                    try
                    {
                        PressureLossParameter PLParam = helper.getPressureLossParamByName(helper.ReportData.FittingFields, fieldName);
                        if (PLParam == null)
                        {
                            continue;
                        }

                        string strVal = ReportConstants.emptyValue;
                        if ((PLParam.GetFrom & (int)SectionMemberType.Section) > 0)
                        {
                            strVal = SectionsInfo.getSectionInfoByParamName(section, fieldName, PLParam.GetFrom, fitting.Id);
                        }
                        else if ((PLParam.GetFrom & (int)SectionMemberType.Fitting) > 0)
                        {
                            if (helper.Domain == ReportResource.pipeDomain && fieldName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_FITTING_LOSS_METHOD_SERVER_PARAM))
                            {
                                string strValGUID = fitting.get_Parameter(fieldName).AsString();
                                Guid   serverGUID = new Guid(strValGUID);

                                //convert the GUID to server name
                                //get the service first, and then get the server
                                MultiServerService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipeFittingAndAccessoryPressureDropService) as MultiServerService;
                                if (service != null && serverGUID != null)
                                {
                                    IExternalServer server = service.GetServer(new Guid(strValGUID));
                                    if (server != null)
                                    {
                                        strVal = server.GetName();
                                    }
                                }
                            }
                            else if (helper.Domain == ReportResource.ductDomain && fieldName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_DUCT_FITTING_LOSS_METHOD_SERVER_PARAM))
                            {
                                string strValGUID = fitting.get_Parameter(fieldName).AsString();
                                Guid   serverGUID = new Guid(strValGUID);

                                //convert the GUID to server name
                                //get the service first, and then get the server
                                MultiServerService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DuctFittingAndAccessoryPressureDropService) as MultiServerService;
                                if (service != null && serverGUID != null)
                                {
                                    IExternalServer server = service.GetServer(new Guid(strValGUID));
                                    if (server != null)
                                    {
                                        strVal = server.GetName();
                                    }
                                }
                            }
                            else if (fieldName == ReportResource.elementId)
                            {
                                strVal = fitting.Id.ToString();
                            }
                            else
                            {
                                strVal = helper.getParamValue(fitting.get_Parameter(fieldName));
                            }
                        }
                        else if ((PLParam.GetFrom & (int)SectionMemberType.Type) > 0)
                        {
                            strVal = getFittingSymbolInfoByParamName(fitting, fieldName);
                        }

                        paramVals.Add(strVal);
                    }
                    catch
                    {
                        //...
                    }
                }

                if (!forHTML) //for csv, the last column is section pressure loss report
                {
                    string strVal = ReportConstants.mergeValue;
                    if (nIndex == 0)
                    {
                        strVal = helper.getTotalPressureLossByType(section, SectionMemberType.Fitting);
                    }

                    paramVals.Add(strVal);
                }

                nIndex++;

                helper.addRow(fittingTB, paramVals);
            }

            return(true);
        }
Exemplo n.º 11
0
        public override bool save(string fileName, PressureLossReportData reportData)
        {
            HtmlStreamWriter writer = new HtmlStreamWriter();

            try
            {
                // Check if the xslt file exists

                if (!File.Exists(writer.XsltFileName))
                {
                    string subMsg = ReportResource.xsltFileSubMsg
                                    .Replace("%FULLPATH%", writer.XsltFileName);

                    UIHelperFunctions.postWarning(
                        ReportResource.htmlGenerateTitle,
                        ReportResource.xsltFileMsg, subMsg);

                    return(false);
                }

                PressureLossReportHelper helper = PressureLossReportHelper.instance;
                if (helper == null)
                {
                    return(false);
                }

                //xml head
                writer.WriteStartDocument(false);

                //root node
                string transXML = "UserPressureLossReport";
                writer.WriteStartElement(transXML);

                //title
                writer.WriteElementString("Title", ReportResource.reportName);

                //domain
                if (helper.Domain == ReportResource.pipeDomain)
                {
                    writer.WriteElementString("DomainName", ReportResource.pipeReportName);
                }
                else
                {
                    writer.WriteElementString("DomainName", ReportResource.ductReportName);
                }

                //write project info
                ReportProjectInfo proInfo = new ReportProjectInfo();
                proInfo.writeToHTML(writer);

                //each system
                List <MEPSystem> systems = helper.getSortedSystems();
                if (systems == null || systems.Count < 1)
                {
                    return(false);
                }

                foreach (MEPSystem sysElem in systems)
                {
                    if (sysElem == null)
                    {
                        continue;
                    }

                    //system node
                    string xmlString = "System";
                    writer.WriteStartElement(xmlString);

                    //system info: name and info
                    MEPSystemInfo systemInfo = new MEPSystemInfo(sysElem);
                    systemInfo.writeToHTML(writer);

                    //critical path
                    if (helper.ReportData.DisplayCriticalPath)
                    {
                        string criticalInfo = ReportResource.criticalPath + " : " + MEPSystemInfo.getCriticalPath(sysElem);
                        criticalInfo += " ; " + ReportResource.totalPressureLoss + " : " + MEPSystemInfo.getCriticalPathPressureLoss(sysElem);
                        writer.WriteElementString("CriticalPath", criticalInfo);
                    }

                    List <MEPSection> sections = new List <MEPSection>();
                    MEPSystemInfo.getSectionsFromSystem(sysElem, sections);

                    //sections: title and info
                    SectionsInfo sectionInfo = new SectionsInfo(sections);
                    sectionInfo.writeToHTML(writer);

                    //segments: title and info
                    SegmentsInfo segmentsInfo = new SegmentsInfo(sections);
                    segmentsInfo.writeToHTML(writer);

                    //fittings: title and info
                    FittingsInfo fittingsInfo = new FittingsInfo(sections);
                    fittingsInfo.writeToHTML(writer);

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();

                writer.Save(fileName);
                return(true);
            }
            catch
            {
                writer.Close();
                //delete xml
                File.Delete(writer.XmlFileName);
                UIHelperFunctions.postWarning(ReportResource.htmlGenerateTitle, ReportResource.htmlMsg);
                return(false);
            }
        }
Exemplo n.º 12
0
        // TODO
        public override bool save(string fileName, PressureLossReportData reportData)
        {
            try
            {
                PressureLossReportHelper helper = PressureLossReportHelper.instance;
                CsvStreamWriter          writer = new CsvStreamWriter();

                //title
                string strTitle = ReportResource.reportName;
                if (helper.Domain == ReportResource.pipeDomain)
                {
                    strTitle = ReportResource.pipeReportName;
                }
                else
                {
                    strTitle = ReportResource.ductReportName;
                }

                DataTable titleTB = new DataTable();
                titleTB.Columns.Add();
                titleTB.Rows.Add(strTitle);
                writer.AddData(titleTB, 1);
                writer.addOneEmptyRow();

                DataTable tbTitle = new DataTable();
                DataTable tb      = new DataTable();

                //Project info
                ReportProjectInfo proInfo = new ReportProjectInfo();
                proInfo.writeToCsv(writer);

                writer.addOneEmptyRow();

                //each system
                List <MEPSystem> systems = helper.getSortedSystems();
                if (systems == null || systems.Count < 1)
                {
                    return(false);
                }
                foreach (MEPSystem sysElem in systems)
                {
                    if (sysElem == null)
                    {
                        continue;
                    }

                    //system name and info
                    MEPSystemInfo systemInfo = new MEPSystemInfo(sysElem);
                    systemInfo.writeToCsv(writer);

                    if (systemInfo.needToWrite())
                    {
                        writer.addOneEmptyRow();
                    }

                    List <MEPSection> sections = new List <MEPSection>();
                    MEPSystemInfo.getSectionsFromSystem(sysElem, sections);

                    //sections: title and info
                    SectionsInfo sectionInfo = new SectionsInfo(sections);
                    sectionInfo.writeToCsv(writer);

                    if (reportData.DisplayCriticalPath)
                    {
                        string criticalInfo = ReportResource.criticalPath + " : " + MEPSystemInfo.getCriticalPath(sysElem);
                        criticalInfo += " ; " + ReportResource.totalPressureLoss + " : " + MEPSystemInfo.getCriticalPathPressureLoss(sysElem);

                        writer.addTitleRow(criticalInfo);
                    }

                    writer.addOneEmptyRow();

                    //segments: title and info
                    SegmentsInfo segmentsInfo = new SegmentsInfo(sections);
                    segmentsInfo.writeToCsv(writer);
                    if (segmentsInfo.needToWrite())
                    {
                        writer.addOneEmptyRow();
                    }

                    //fittings: title and info
                    FittingsInfo fittingsInfo = new FittingsInfo(sections);
                    fittingsInfo.writeToCsv(writer);
                    if (fittingsInfo.needToWrite())
                    {
                        writer.addOneEmptyRow();
                    }
                }

                writer.Save(fileName);
                return(true);
            }
            catch (Exception e)
            {
                if (e.Message == ReportConstants.failed_to_delete)
                {
                    string subMsg = ReportResource.csvSubMsg.Replace("%FULLPATH%", fileName);
                    UIHelperFunctions.postWarning(ReportResource.csvGenerateTitle, ReportResource.csvMsg, subMsg);
                }
                else
                {
                    UIHelperFunctions.postWarning(ReportResource.csvGenerateTitle, ReportResource.csvMsg);
                }
                return(false);
            }
        }
Exemplo n.º 13
0
        static public void generateSegmentFields(PressureLossReportData reportData)
        {
            PressureLossReportHelper helper = PressureLossReportHelper.instance;

            if (helper == null)
            {
                return;
            }

            List <PressureLossParameter> segParameters = new List <PressureLossParameter>();

            //default segment selected fields
            //SectionMemberType means where the value is from: segment or section
            int nOrder = 1;

            segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.ALL_MODEL_MARK), false, -1, (int)SectionMemberType.Segment));
            segParameters.Add(new PressureLossParameter(ReportResource.elementId, true, nOrder++, (int)SectionMemberType.Segment));

            if (helper.Domain == ReportResource.pipeDomain)
            {
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_FLOW_PARAM), true, nOrder++, (int)SectionMemberType.Section));
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_SIZE_FORMATTED_PARAM), true, nOrder++, (int)SectionMemberType.Segment));
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_FRICTION_FACTOR_PARAM), false, -1, (int)SectionMemberType.Section));
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_FIXTURE_UNITS_PARAM), false, -1, (int)SectionMemberType.Section));
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_REYNOLDS_NUMBER_PARAM), false, -1, (int)SectionMemberType.Section));
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_FITTING_LOSS_KFACTOR_PARAM), false, -1, (int)SectionMemberType.Section));
            }
            else
            {
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_DUCT_FLOW_PARAM), true, nOrder++, (int)SectionMemberType.Section));
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_DUCT_SIZE_FORMATTED_PARAM), true, nOrder++, (int)SectionMemberType.Segment));
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_REYNOLDSNUMBER_PARAM), false, -1, (int)SectionMemberType.Section));
                segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_LOSS_COEFFICIENT), false, -1, (int)SectionMemberType.Section));
            }

            segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_VELOCITY), true, nOrder++, (int)SectionMemberType.Section));
            segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_VELOCITY_PRESSURE), true, nOrder++, (int)SectionMemberType.Section));
            segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.CURVE_ELEM_LENGTH), true, nOrder++, (int)SectionMemberType.Section));
            segParameters.Add(new PressureLossParameter(ReportResource.pressureLoss, true, 100, (int)SectionMemberType.Section, false));

            segParameters.Add(new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_FRICTION), false, -1, (int)SectionMemberType.Section));

            //find the first curve
            List <MEPSystem> systems = helper.getSortedSystems();

            if (systems == null || systems.Count < 1)
            {
                return;
            }
            foreach (MEPSystem system in systems)
            {
                List <MEPSection> sections = new List <MEPSection>();
                MEPSystemInfo.getSectionsFromSystem(system, sections);
                foreach (MEPSection section in sections)
                {
                    //find one section which contains both segment and fitting
                    List <MEPCurve> curves = new List <MEPCurve>();
                    SectionsInfo.getSectionElements(section, curves, null, null, null);

                    if (curves.Count < 1)
                    {
                        continue;
                    }

                    //segment parameters
                    PressureLossParameter PLParam1 = new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.ELEM_FAMILY_PARAM), false, -1, (int)SectionMemberType.Type);
                    if (!segParameters.Contains(PLParam1))
                    {
                        segParameters.Add(PLParam1);
                    }

                    PressureLossParameter PLParam2 = new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM), false, -1, (int)SectionMemberType.Type);
                    if (!segParameters.Contains(PLParam2))
                    {
                        segParameters.Add(PLParam2);
                    }

                    PressureLossParameter PLParam3 = new PressureLossParameter(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_SIZE_FORMATTED_PARAM), false, -1, (int)SectionMemberType.Segment);
                    if (!segParameters.Contains(PLParam3))
                    {
                        segParameters.Add(PLParam3);
                    }

                    foreach (Parameter param in curves[0].Parameters)
                    {
                        //exclude the parameters under constrain and other groups
                        if (param.Definition.ParameterGroup == BuiltInParameterGroup.PG_CONSTRAINTS ||
                            LabelUtils.GetLabelFor(param.Definition.ParameterGroup) == ReportResource.other ||
                            param.Definition.Name == LabelUtils.GetLabelFor(BuiltInParameter.RBS_SECTION) ||
                            param.Definition.Name == LabelUtils.GetLabelFor(BuiltInParameter.RBS_PRESSURE_DROP))
                        {
                            continue;
                        }

                        PressureLossParameter PLParam = new PressureLossParameter(param.Definition.Name, false, -1, (int)SectionMemberType.Segment);
                        if (!segParameters.Contains(PLParam))
                        {
                            segParameters.Add(PLParam);
                        }
                    }

                    //segmentType parameters
                    MEPCurveType crvType = helper.Doc.GetElement(curves[0].GetTypeId()) as MEPCurveType;
                    if (crvType != null)
                    {
                        foreach (Parameter param in crvType.Parameters)
                        {
                            //exclude the parameters under Fitting/Segments and other groups
                            if (param.Definition.ParameterGroup == BuiltInParameterGroup.PG_FITTING ||
                                param.Definition.ParameterGroup == BuiltInParameterGroup.PG_SEGMENTS_FITTINGS ||
                                LabelUtils.GetLabelFor(param.Definition.ParameterGroup) == ReportResource.other)
                            {
                                continue;
                            }

                            PressureLossParameter PLParam = new PressureLossParameter(param.Definition.Name, false, -1, (int)SectionMemberType.Type);
                            if (!segParameters.Contains(PLParam))
                            {
                                segParameters.Add(PLParam);
                            }
                        }
                    }

                    reportData.StraightSegFields = segParameters;

                    return;
                }
            }
        }
Exemplo n.º 14
0
        private bool getSegmentInfo(MEPSection section, DataTable segmentTB, bool forHTML = false)
        {
            if (segmentTB == null || section == null)
            {
                return(false);
            }

            PressureLossReportHelper helper = PressureLossReportHelper.instance;

            if (helper == null || helper.ReportData == null)
            {
                return(false);
            }

            //get fields from reportData
            List <string> segmentFields = new List <string>();

            getFields(segmentFields);

            if (forHTML)
            {
                helper.addColumns(segmentTB, segmentFields.Count);
            }
            else
            {
                helper.addColumns(segmentTB, segmentFields.Count + 2);
            }

            List <MEPCurve> curves = new List <MEPCurve>();

            SectionsInfo.getSectionElements(section, curves, null, null, null);
            if (curves.Count < 1)
            {
                return(false);
            }

            int nIndex = 0;

            foreach (MEPCurve crv in curves)
            {
                List <string> paramVals = new List <string>();
                if (!forHTML)
                {
                    if (nIndex == 0)
                    {
                        paramVals.Add(section.Number.ToString());
                    }
                    else
                    {
                        paramVals.Add(" ");
                    }
                }

                foreach (string fieldName in segmentFields)
                {
                    PressureLossParameter PLParam = helper.getPressureLossParamByName(helper.ReportData.StraightSegFields, fieldName);
                    if (PLParam == null)
                    {
                        continue;
                    }

                    string strVal = ReportConstants.emptyValue;
                    if (((PLParam.GetFrom & (int)SectionMemberType.Section) > 0))
                    {
                        strVal = SectionsInfo.getSectionInfoByParamName(section, fieldName, PLParam.GetFrom, crv.Id);
                    }
                    else if ((PLParam.GetFrom & (int)SectionMemberType.Segment) > 0)
                    {
                        if (helper.Domain == ReportResource.pipeDomain &&
                            fieldName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_FLOW_STATE_PARAM))
                        {
                            int nVal = crv.get_Parameter(fieldName).AsInteger();
                            strVal = LabelUtils.GetLabelFor((Autodesk.Revit.DB.Plumbing.PipeFlowState)nVal, helper.Doc);
                        }
                        else if ((fieldName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_SIZE_FORMATTED_PARAM) ||
                                  fieldName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_DUCT_SIZE_FORMATTED_PARAM)) &&
                                 ((BuiltInCategory)crv.Category.Id.IntegerValue == BuiltInCategory.OST_FlexDuctCurves ||
                                  (BuiltInCategory)crv.Category.Id.IntegerValue == BuiltInCategory.OST_FlexPipeCurves))
                        {
                            //for flex duct/pipe, no size parameter, using diameter?
                            if (helper.Domain == ReportResource.pipeDomain)
                            {
                                strVal = helper.getParamValue(crv.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM));
                            }
                            else
                            {
                                //TBD: need to check round or rect
                                strVal = helper.getParamValue(crv.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM));
                            }
                        }
                        else if (fieldName == ReportResource.elementId)
                        {
                            strVal = crv.Id.ToString();
                        }
                        else
                        {
                            strVal = helper.getParamValue(crv.get_Parameter(fieldName));
                        }
                    }
                    else if ((PLParam.GetFrom & (int)SectionMemberType.Type) > 0)
                    {
                        strVal = getSegmentTypeInfoByParamName(crv, fieldName);
                    }

                    paramVals.Add(strVal);
                }

                if (!forHTML) //for csv, the last column is section pressure loss report
                {
                    string strVal = ReportConstants.mergeValue;
                    if (nIndex == 0)
                    {
                        strVal = helper.getTotalPressureLossByType(section, SectionMemberType.Segment);
                    }

                    paramVals.Add(strVal);
                }

                nIndex++;

                helper.addRow(segmentTB, paramVals);
            }

            return(true);
        }