Exemple #1
0
 public void init(string _schemaName)
 {
     schemaName = _schemaName;
     if (string.IsNullOrEmpty(schemaName))
     {
         Msg.F("IFC.init: No schema");
     }
 }
Exemple #2
0
        public List<Elm> Read(string dir = "", string name = "")
        {
            Log.set("TS_OpenAPI.Read");
            List<Elm> elements = new List<Elm>();
            ModInfo = model.GetInfo();
            if (dir != "" && ModInfo.ModelPath != dir
                || name != "" && ModInfo.ModelName != String.Concat(name, ".db1")) Msg.F("Tekla.Read: Another model loaded, not", name);
            ModInfo.ModelName = ModInfo.ModelName.Replace(".db1", "");
 
            dicParts = ReadModObj<TSM.Part>();

            //20/11/17            ArrayList part_string = new ArrayList() { "MATERIAL", "MATERIAL_TYPE", "PROFILE" };
            //20/11/17            ArrayList part_double = new ArrayList() { "LENGTH", "WEIGHT", "VOLUME" };
            //20/11/17            ArrayList part_int = new ArrayList();
            //20/11/17            Hashtable all_val = new Hashtable();

            foreach (var part in dicParts)
            {
                Elm elm = new Elm();
                elm.mat = part.Value.Material.MaterialString;
                elm.prf = part.Value.Profile.ProfileString;
                part.Value.GetReportProperty("LENGTH", ref elm.length);
                part.Value.GetReportProperty("WEIGHT", ref elm.weight);
                part.Value.GetReportProperty("VOLUME", ref elm.volume);
                part.Value.GetReportProperty("MATERIAL_TYPE", ref elm.mat_type);

                //////////////////double lng = 0, weight = 0, vol = 0;
                //////////////////var p = part.Value;
                //////////////////p.GetReportProperty("LENGTH", ref lng);
                //////////////////p.GetReportProperty("WEIGHT", ref weight);
                //////////////////p.GetReportProperty("VOLUME", ref vol);
                //////////////////elm.volume = vol;
                //////////////////elm.weight = weight;
                //////////////////elm.length = lng;
                //20/11/17                part.Value.GetAllReportProperties(part_string, part_double, part_int, ref all_val);
                //20/11/17               elm.mat = (string)all_val[part_string[0]];
                //20/11/17elm.mat_type = (string)all_val[part_string[1]];
                //20/11/17               elm.prf = (string)all_val[part_string[2]];
                //20/11/17  elm.length = (double)all_val[part_double[0]];
                //20/11/17elm.weight = (double)all_val[part_double[1]];
                //20/11/17elm.volume = (double)all_val[part_double[2]];
                elm.guid = part.Key;
                elements.Add(elm);
            }
            Scale(elements);
            elements.Sort();
            Log.exit();
            return elements;
        } // Read
Exemple #3
0
        /// <summary>
        /// CheckGroups - check all groups of elements, put GrType.Warning if group is incorrect
        /// </summary>
        /// <param name="groups"></param>
        public void CheckGroups(ref Model.Model mod)
        {
            if (mod == null || mod.elements == null || mod.elements.Count < 1 ||
                mod.elmGroups == null || mod.elmGroups.Count < 1 ||
                mod.elements.Count != mod.elmGroups.Sum(x => x.guids.Count))
            {
                Msg.F(me + "ChechGroup bad model", mod.name);
            }
            var _dic = mod.elements.ToDictionary(x => x.guid);

            foreach (var gr in mod.elmGroups)
            {
                elmsDic = _dic.Where(x => gr.guids.Contains(x.Value.guid)).ToDictionary(v => v.Key, v => v.Value);
                Mat     = elmsDic.First().Value.mat;
                int  grIndex = mod.elmGroups.IndexOf(gr);
                bool errFlag = false;
                foreach (var elm in elmsDic)
                {
                    if (elm.Value.mat == Mat)
                    {
                        continue;
                    }
                    mod.elmGroups[grIndex].type = GrType.Warning;
                    mod.HighLightElements(elmsDic);
                    if (errFlag)
                    {
                        continue;
                    }
                    Msg.W(me + "CheckGroups various materials in Group"
                          , grIndex, gr.Prf, Mat, elm.Value.mat);
                    errFlag = true;
                }
            }
        }
Exemple #4
0
        public static List <Elms> Read(string ifcFileName)
        {
            var manager = new IfcManager.Core.IfcManager();

            if (!FileOp.isFileExist(ifcFileName))
            {
                Message.Message Msg = new Message.Message(); Msg.F("IFC.Read: no file", ifcFileName);
            }

            log.Info("TRACE: Read(\"" + ifcFileName + "\"");

            manager.init(ifcFileName, schemaName);

            List <IfcManager.Core.IfcManager.IfcElement> elements = new List <IfcManager.Core.IfcManager.IfcElement>();

            elements = manager.getElementsByProperty("NetVolume");
            IFC.MergeIfcToElmAttSet(elements);

            elements.Clear();
            elements = manager.getElementsByProperty("Weight");
            IFC.MergeIfcToElmAttSet(elements);

            elements.Clear();
            elements = manager.getElementsByMaterials();
            IFC.MergeIfcToElmAttSet(elements);

            elements.Clear();
            elements = manager.getElementsByProperty("Profile");
            IFC.MergeIfcToElmAttSet(elements);

            List <ElmAttributes.ElmAttSet> result = new List <ElmAttributes.ElmAttSet>();

            result = ElmAttributes.ElmAttSet.Elements.Values.ToList();
            foreach (var elm in result)
            {
                string[] matToSplit = elm.mat.Split('/');
                switch (matToSplit.Count())
                {
                case 2:
                    elm.mat_type = matToSplit[0];
                    elm.mat      = matToSplit[1];
                    break;

                case 1:
                    elm.mat_type = "STEEL";
                    elm.prf      = elm.mat; // А400 - это арматура; почемуто ее марку указывают как материал
                                            //..здесь еще надо разобраться с ГОСТ-5781
                                            //..и присвоить значения элемента mat, prf и др
                    break;

                default:
                    Message.Message Msg = new Message.Message(); Msg.F("IFC error Material Parse", elm.mat);
                    break;
                }
            }
            result.Sort();
            return(result);
        }
Exemple #5
0
 /// <summary>
 /// error() - SavedReport error handler method
 /// </summary>
 protected void error(bool errRep = false)
 {
     const string me = "SavedReport__error_";
     Log.set("SR.error()");
     log.Info("error() model.errRecover = " + model.errRecover.ToString());
     if (model.errRecover)
     {
         Msg.AskFOK(me + "Corrupted saved report TSmatchINFO");
         model.elements = Raw(model);
         dRep = Docs.getDoc(sRep);
         if (dRep == null || errRep) Msg.F(me + "recover impossible");
         GetSavedReport();
         Recover(sINFO, RecoverToDo.ResetRep);
         //21/7           Recover(mod, sRep,  RecoverToDo.ResetRep);
     }
     else model.isChanged = true;  // say, that TSmatchINFO.xlsx should be re-written
     Log.exit();
 }
 public ProfileUpdate(ref List<ElmGr> elmGroups)
 {
     if (PrfTab == null || PrfTab.Count == 0 || elmGroups == null || elmGroups.Count == 0)
         Msg.F("internal errer");
     foreach (var gr in elmGroups)
     {
         foreach (var Mark in PrfTab)
         {
             string[] marks = Mark.Value.Split('|');
             foreach (string mark in marks)
             {
                 if (gr.prf.Length < mark.Length || gr.prf.Substring(0, mark.Length) != mark) continue;
                 Profile = gr.Prf; profile = gr.prf;
                 gr.Prf = PrfNormStr(Mark.Key);
                 gr.prf = Lib.ToLat(gr.Prf.ToLower().Replace(" ", ""));
                 if (gr.Prf != Profile) goto NextGr;
             } // end foreach '|' part
         } // end PrfTab entry
         NextGr:;
     } // end elmGroup
 }
Exemple #7
0
 protected string strExclude(string str, List <string> syns)
 {
     foreach (string s in syns)
     {
         if (!str.Contains(s))
         {
             continue;
         }
         return(str.Substring(s.Length));
     }
     Msg.F("Rule.strExclude error", str, syns);
     return(null);
 }
Exemple #8
0
 protected void SetModDir(Boot boot)
 {
     const string me = "SavedReport__SetModelDir_";
     Msg = boot.Msg;
     if (boot.isTeklaActive)
     {   // if Tekla is active - get Path of TSmatch
         model.name = Path.GetFileNameWithoutExtension(TS.ModInfo.ModelName);
         model.dir = TS.GetTeklaDir(TS.ModelDir.model);
         model.phase = TS.ModInfo.CurrentPhase.ToString();
         //6/4/17                        macroDir = TS.GetTeklaDir(TS.ModelDir.macro);
         model.HighLightClear();
     }
     else
     {   // if Tekla not active - get model attributes from TSmatchINFO.xlsx in ModelDir
         model.dir = boot.ModelDir;
         if (!FileOp.isDirExist(model.dir)) Msg.F(me + "No Model Directory", model.dir);
         if (!Docs.IsDocExist(Decl.TSMATCHINFO_MODELINFO)) Msg.F(me + "No_TSmatchINFO", model.dir);
         dINFO = Docs.getDoc(sINFO, fatal: false);
         if (dINFO == null || dINFO.il < 10 || !FileOp.isDirExist(model.dir)) error();
         model.name = dINFO.Body.Strng(Decl.MODINFO_NAME_R, 2);
         model.phase = dINFO.Body.Strng(Decl.MODINFO_PHASE_R, 2);
     }
 }
Exemple #9
0
 public Mgroup(List<ElmAttSet> elements, string material, List<string> guids)
 {
     this.mat = material;
     this.guids = guids;
     totalWeight = totalVolume = totalPrice = 0.0;
     foreach (string id in guids)
     {
         ElmAttSet elm = elements.Find(x => x.guid == id);
         if (elm == null) Msg.F("ElmAttSet: Mgroup(wrong guid)", id);
         totalWeight += elm.weight;
         totalVolume += elm.volume;
         totalPrice += elm.price;
     }
 }
Exemple #10
0
        /// <summary>
        /// Mtch(gr, _rule) - check if Group gr is in match with rule
        ///    if Mtch.ok.Match - return Mtch.Component chousen from CompSet.Component
        ///    else ok.NoMatch
        /// </summary>
        /// <param name="gr"></param>
        /// <param name="_rule"></param>
        public Mtch(Group.Group gr, Rule.Rule _rule)
        {
            if (gr == null || gr.guids == null || gr.guids.Count < 1)
                Msg.F("Matcher__Mtch Bad arguments");
            ok = OK.NoMatch;
            group = gr;
            foreach (var comp in _rule.CompSet.Components)
            {
                bool found = false;
                try { found = comp.isMatch(gr, _rule); }
                catch { }
                if (!found) continue;
                //-- Component is found - fill Price for all Guids elemets
                ok = OK.Match;
                string priceStr;
                try { priceStr = comp.Str(SType.Price); }
                catch { Msg.F("Match: Bad Price descriptor", _rule.sSupl, _rule.sCS); }
                component = comp;
//29/8                gr.match = this;    //27/3!!
                rule = _rule;
                gr.totalPrice = getPrice(gr, rule.CompSet.csDP, comp.Str(SType.Price));
                break;
            }
        }
Exemple #11
0
 /// <summary>
 /// getDoc(name) - get Document name - when nor read yet - from the file. If necessary - Create new Sheet
 /// </summary>
 /// <param name="name">Document name</param>
 /// <param name="fatal">FATAL if this flag = true; else - return null if Document doesnt exists</param>
 /// <returns>Document or null</returns>
 /// <returns>Document</returns>
 /// <history> 25.12.2013 отлажено
 /// 25.12.2013 - чтение из файла, формирование Range Body
 /// 28.12.13 - теперь doc.Sheet и doc.Wb храним в структуре Документа
 /// 5.4.14  - инициализируем docDic, то есть подготавливаем набор данных для Fetch
 /// 22.12.15 - getDoc для нового документа - в Штампе он помечен N
 /// 6.1.16 - NOP если FiliDirectory содержит # - каталог Документа еще будет разворачиваться позже
 ///  5.3.16 - null if Document not found or exist
 /// 30.3.16 - get #template Path from Bootstrap.Template; try-catch rewritten
 ///  5.4.16 - bug fix - SheetReset for "N" Document
 /// 19.4.16 - use Templ.getPath in getDoc()
 /// 27.4.16 - optional flag load - if false -> don't load contents from the file
 ///  9.4.17 - optional create_if_not_exist argument
 /// 17.4.17 - doc.il = doc.Body.iEOL();
 /// 27.4.17 - move Reset() later in code, error logic changed
 /// 31.7.17 - read XML file in doc.Body -- does't works yet!!
 ///  2.8.18 - bug fix doc.il set re-written
 /// </history>
 public static Document getDoc(string name = Decl.DOC_TOC
     , bool fatal = true, bool load = true, bool create_if_notexist = false, bool reset = false)
 {
     Log.set("getDoc(" + name + ")");
     Document doc = null;
     string err = "Err getDoc: ", ex = "";
     try { doc = Documents[name]; }
     catch (Exception e) { err += "doc not in TOC"; ex = e.Message; doc = null; }
     if (doc != null && !doc.isOpen)
     {
         if (load)
         {
             if (doc.FileDirectory.Contains("#")) // #Template substitute with Path in Dictionary
                 doc.FileDirectory = Templates[doc.FileDirectory];
             //-------- Load Document from the file or create it ------------
             if (doc.type == "XML")
             {
                 string file = Path.Combine(doc.FileDirectory, doc.FileName);
                 throw new NotImplementedException();
                 doc.Body = rwXML.XML.ReadFromXmlFile<Mtr>(file);
             }
             else
             {
                 doc.Wb = FileOp.fileOpen(doc.FileDirectory, doc.FileName, create_if_notexist, fatal);
                 if (reset) doc.Reset();
                 try { doc.Sheet = doc.Wb.Worksheets[doc.SheetN]; }
                 catch (Exception e) { err += "no SheetN"; ex = doc.SheetN; doc = null; }
                 if (doc != null) doc.Body = FileOp.getSheetValue(doc.Sheet);
             }
         }
     } // end if(!doc.isOpen)
     if (doc != null)
     {
         doc.isOpen = true;
         if (doc.type != Decl.TSMATCH) doc.il = doc.Body.iEOL();
     }
     else if (fatal) { Message.Message Msg = new Message.Message(); Msg.F(err, ex, name); }
     Log.exit();
     return doc;
 }
Exemple #12
0
            internal static Form getFormByName(Document doc, string name)
            {

                if (!isFormExist(doc.forms, name)) { Message.Message Msg = new Message.Message(); Msg.F("Document.wrDoc no form", name, doc.name); }
                name = Lang(name);
                return doc.forms.Find(x => x.name == name);
            }
Exemple #13
0
        /// <summary>
        /// saveDoc(doc [,BodySave, string MD5]) - сохраняет Документ в Excel файл, если он изменялся
        /// </summary>
        /// <param name="name">имя документа</param>
        /// <param name="BodySave>true - doc.Body нужно сохранить, false - уже в Excel</param>
        /// <param name="MD5">MD5 документа. Если BodySave = false - обязательно</param>
        /// <history>10.1.2016
        /// 18.1.16 - аккуратная обработка BodySave=false и MD5
        /// 20.1.16 - fix bug: not write EOLinTOC for TSmatch type Documents
        /// 1.04.16 - overlay saveDoc(..)
        /// </history>
        public static void saveDoc(Document doc, bool BodySave = true, string MD5 = "", int EOL = 0)
        {
            Log.set("saveDoc(\"" + doc.name + "\")");
            try
            {
                Document toc = Documents[Decl.DOC_TOC];
                if (doc.type == Decl.DOC_TYPE_N) doc.isChanged = true;
                if (doc.isChanged)
                {
                    int EOLinTOC = EOL;
                    if (BodySave)
                    {
                        FileOp.setRange(doc.Sheet);
                        FileOp.saveRngValue(doc.Body);
//24/4/17                        doc.chkSum = doc.Body.ComputeMD5();
//2/8/17 removed EOLinTOC                       doc.EOLinTOC = doc.Body.iEOL();
                        doc.il = doc.Body.iEOL();
                        FileOp.fileSave(doc.Wb);
                        doc.isChanged = false;
                    }
                    else
                    {
                        if (MD5.Length < 20 || EOL == 0) { Message.Message Msg = new Message.Message(); Msg.F("ERR_05.8_saveDoc_NOMD5"); }
                        //2/8/17 removed EOLinTOC                        else { doc.chkSum = MD5; doc.EOLinTOC = EOLinTOC; }
                        else { doc.chkSum = MD5; doc.il = EOLinTOC; }
                    }
                    Mtr tmp = FileOp.getSheetValue(toc.Sheet);
                    for (int n = toc.i0; n <= toc.il; n++)
                    {   // находим и меняем строку документа doc TOC
                        if ((string)toc.Body[n, Decl.DOC_NAME] != doc.name) continue;
                        tmp[1, 1] = Lib.timeStr();
                        tmp[n, Decl.DOC_TIME] = Lib.timeStr();
                        tmp[n, Decl.DOC_MD5] = doc.chkSum;
                        if (doc.type == "N") tmp[n, Decl.DOC_CREATED] = Lib.timeStr();
//2/8/17 removed EOLinTOC                        if (doc.type != Decl.TSMATCH_TYPE) tmp[n, Decl.DOC_EOL] = doc.EOLinTOC;
                        if (doc.type != Decl.TSMATCH_TYPE) tmp[n, Decl.DOC_EOL] = doc.il;
                        FileOp.setRange(toc.Sheet);
                        FileOp.saveRngValue(tmp, AutoFit: false);  //======= save TОC in TSmatch.xlsx
                        break;
                    }
                }
            }
            catch (Exception e) { Log.FATAL("Ошибка \"" + e.Message + "\" сохранения файла \"" + doc.name + "\""); }
            Log.exit();
        }
Exemple #14
0
 public void wrModel(WrMod mode, Mod mod)
 {
     string doc_name = mode.ToString();
     Log.set("Model.wrModel(" + doc_name + ")");
     DateTime t0 = DateTime.Now;
     Docs doc = Docs.getDoc(doc_name, create_if_notexist: true, reset: true);
     doc.Reset();
     switch (mode)
     {
         case WrMod.ModelINFO:   // общая информация о модели: имя, директория, MD5 и др
             doc.wrDocSetForm("HDR_ModelINFO", 1, AutoFit: true);
             string adr = mod.adrCity;
             if (mod.adrStreet != string.Empty) adr += ", " + mod.adrStreet;
             doc.wrDocForm(mod.name, adr, mod.dir, mod.phase
                 , sDat(mod.date), mod.MD5
                 , sInt(mod.elements.Count), sDat(mod.pricingDate), mod.pricingMD5);
             break;
         case WrMod.Materials:   // сводка по материалам, их типам (бетон, сталь и др)
             doc.wrDocSetForm("FORM_Materials", 3, AutoFit: true);
             foreach (var mGr in mod.elmMgroups)
             {
                 doc.wrDocForm(mGr.mat, mGr.totalVolume, mGr.totalWeight, mGr.totalPrice);
             }
             break;
         case WrMod.Suppliers:   // сводка по поставщикам проекта (контакты, URL прайс-листа, закупки)
             doc.wrDocSetForm("FORM_ModSupplierLine", 4, AutoFit: true);
             foreach (var s in mod.Suppliers)
             {
                 doc.wrDocForm(s.Name, s.Url, s.City, s.Index, s.Street, s.Telephone);
             }
             break;
         case WrMod.Rules:       // перечень Правил, используемых для обработки модели
             if (mod.Rules.Count == 0) Msg.F("Can't write TSmatchINFO.xlsx/Rules");
             doc.wrDocSetForm("FORM_RuleLine");
             foreach (var rule in mod.Rules)
             {
                 doc.wrDocForm(sDat(rule.date), rule.sSupl, rule.sCS, rule.text);
             }
             break;
         case WrMod.Report:      // отчет по сопоставлению групп <материал, профиль> c прайс-листами поставщиков
             doc.wrDocSetForm("FORM_Report", AutoFit: true);
             int n = 1;
             foreach (var gr in mod.elmGroups)
             {
                 string compDescription = "", suplName = "", csName = "";
                 if(!string.IsNullOrEmpty(gr.SupplierName))
                 {
                     suplName = gr.SupplierName;
                     csName = gr.CompSetName;
                     compDescription = gr.compDescription;
                 }
                 doc.wrDocForm(n++, gr.Mat, gr.Prf
                     , sDbl00(gr.totalLength), sDbl(gr.totalWeight), sDbl(gr.totalVolume)
                     , compDescription, suplName, csName
                     , sDbl(gr.totalWeight), sDbl(gr.totalPrice));
             }
             doc.isChanged = true;
             doc.saveDoc();
             //--- string - Summary
             double sumWgh = 0, sumPrice = 0;
             int iGr = doc.i0;
             foreach (var gr in mod.elmGroups)
             {
                 double? w = doc.Body.Double(iGr, Decl.REPORT_SUPL_WGT);
                 double? p = doc.Body.Double(iGr++, Decl.REPORT_SUPL_PRICE);
                 sumWgh += (w == null) ? 0 : (double)w;
                 sumPrice += (p == null) ? 0 : (double)p;
             }
             doc.wrDocSetForm("FORM_Report_Sum", AutoFit: true);
             doc.wrDocForm(sumWgh, sumPrice);
             break;
     }
     doc.isChanged = true;
     doc.saveDoc();
     log.Info("Время записи в файл \"" + doc_name + "\"\t t= " + (DateTime.Now - t0).ToString() + " сек");
     Log.exit();
 }
Exemple #15
0
 protected void resxError(ResErr errType, string resName)
 {
     string myName = "Bootstrap__resError_";
     var v = errType.ToString();
     Msg.F(myName + v, resName);
 }