Exemplo n.º 1
0
        private static void ExportObjectInDoc(FHXObject obj, DocX doc, int level = 0)
        {
            doc.InsertSection();
            Paragraph p = doc.InsertParagraph(obj.Name).Heading((HeadingType)level).Bold().UnderlineStyle(UnderlineStyle.singleLine);

            p.Alignment = Alignment.left;

            if (obj.Parameters.Count > 0)
            {
                Table t = doc.InsertTable(obj.Parameters.Count, 2);

                int i = 0;
                foreach (FHXParameter par in obj.Parameters)
                {
                    ExportParameterInDoc(par, t, i);
                    i++;
                }
            }


            foreach (FHXObject child in obj.Children)
            {
                ExportObjectInDoc(child, doc, level + 1);
            }
        }
Exemplo n.º 2
0
 public void RemoveChild(FHXObject obj)
 {
     if (Children.Contains(obj))
     {
         Children.Remove(obj);
     }
 }
Exemplo n.º 3
0
 public FHXParameter(string identifier, string value, bool mandatory = false, FHXObject parent = null)
 {
     this.Parent    = parent;
     this.Name      = identifier;
     this.Value     = value;
     this.Mandatory = mandatory;
 }
Exemplo n.º 4
0
        private static void ProcessAttribute(FHXObject attr)
        {
            FHXObject parent = attr.Parent;

            if (parent == null)
            {
                return;
            }
            List <FHXObject> ATTRIBUTE = parent.GetAllChildren();

            ATTRIBUTE = ATTRIBUTE.Where(i => i.Type == "ATTRIBUTE" && i.Name == attr.Name).ToList();

            if (ATTRIBUTE.Count > 1)
            {
                Console.WriteLine("Multiple instances of {0} found", attr.Name);
            }

            foreach (var a in ATTRIBUTE)
            {
                if (a.Parent != null)
                {
                    //Adds the ATTRIBUTE_INSTANCE in the parent of the ATTRIBUTE
                    attr.SetParent(null);
                    a.Parent.AddChild(attr);

                    attr.AddParameter(a.GetParameter("TYPE"));

                    //Removes the ATTRIBUTE from its parent
                    a.Parent.RemoveChild(a);
                    a.SetParent(null);
                }
            }
        }
Exemplo n.º 5
0
 public void SetParent(FHXObject parent)
 {
     if (parent == null && this.Parent != null)
     {
         this.Parent.RemoveChild(this);
     }
     this.Parent = parent;
 }
Exemplo n.º 6
0
        public static void ExportObjectWord(FHXObject obj, string file)
        {
            using (var doc = DocX.Create(file))
            {
                Paragraph p = doc.InsertParagraph(obj.Name);
                p.Alignment = Alignment.center;

                ExportObjectInDoc(obj, doc);
                doc.Save();
            }
        }
Exemplo n.º 7
0
        public void Add(FHXObject parent, FHXParameter param, FHXCompareType type)
        {
            string rpath = param.RelativePath(parent);

            if (!_results.Keys.Contains(rpath))
            {
                _results.Add(rpath, new FHXCompareResult(parent, type, param.Value));
            }
            else
            {
                _results[rpath].NewValue = param.Value;
            }
        }
Exemplo n.º 8
0
        public string RelativePath(FHXObject root)
        {
            FHXObject parent = this.Parent;
            string    path   = "";

            while (parent != null && parent != root)
            {
                path   = "/" + parent.Name + path;
                parent = parent.Parent;
            }

            return(path + "." + this.Name);
        }
Exemplo n.º 9
0
        static public FHXObject FromFile(string file)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            string s = File.ReadAllText(file);

            sw.Stop();
            Console.WriteLine("Reading file took {0} ms", sw.ElapsedMilliseconds);

            FHXObject root = FromString(s);

            root.mName = Path.GetFileNameWithoutExtension(file);
            return(root);
        }
Exemplo n.º 10
0
        public FHXObject GetChildFromPath(string path)
        {
            string[]  hierarchy = path.Split('/');
            FHXObject current   = this;

            foreach (string p in hierarchy)
            {
                current = current.GetChild(p);

                if (current == null)
                {
                    return(null);                 //Child not found
                }
            }

            return(current); // Returns the last child from the search
        }
Exemplo n.º 11
0
 private void BuildModule(FHXObject module, ExcelWorksheet sht, int line)
 {
     foreach (var cond in Conditions)
     {
         try
         {
             FHXParameter p = cond.Value(module);
             if (p != null)
             {
                 int col = Columns.Single(i => i.Key == cond.Key).Value;
                 sht.Cells[line, col].Value = p.Value;
             }
         }
         catch (Exception ex)
         {
             //Console.WriteLine(ex.Message);
         }
     }
 }
Exemplo n.º 12
0
        private static void ProcessFB(FHXObject fb, List <FHXObject> FUNCTION_BLOCK_DEFINITION)
        {
            FHXObject parent = fb.Parent;

            fb.Parent.RemoveChild(fb);
            fb.SetParent(null);

            if (FUNCTION_BLOCK_DEFINITION.Any(i => i.Name == fb.GetParameter("DEFINITION").Value))
            {
                foreach (FHXObject newChild in FUNCTION_BLOCK_DEFINITION.Where(i => i.Name == fb.GetParameter("DEFINITION").Value))
                {
                    newChild.mName = fb.Name;
                    newChild.Type  = "FUNCTION_BLOCK";
                    newChild.Parent.RemoveChild(newChild);
                    newChild.SetParent(null);
                    parent.AddChild(newChild);
                }
            }
        }
Exemplo n.º 13
0
        public static FHXCompareResultList CompareObjects(FHXObject a, FHXObject b)
        {
            FHXCompareResultList res = new FHXCompareResultList();

            List <FHXParameter> psa = a.GetAllParameters();
            List <FHXParameter> psb = b.GetAllParameters();

            foreach (var pa in psa)
            {
                string rpath = pa.RelativePath(a);
                //Check if b contains the parameter
                if (psb.Any(i => i.RelativePath(b) == rpath))
                {
                    //If it contains it
                    //FHXParameter pb = psb.Single(i => i.RelativePath(b) == rpath);
                    FHXParameter pb = psb.Where(i => i.RelativePath(b) == rpath).ToArray()[0];
                    if (pa.Value != pb.Value)
                    {
                        res.Add(a, pa, FHXCompareType.DIFFERENT);
                        res.Add(b, pb, FHXCompareType.DIFFERENT);
                    }
                }
                else
                {
                    //If not
                    res.Add(a, pa, FHXCompareType.IN);
                }
            }

            foreach (var pb in psb)
            {
                string rpath = pb.RelativePath(b);
                //Check if b contains the parameter
                if (!psb.Any(i => i.RelativePath(b) == rpath))
                {
                    //If not
                    res.Add(b, pb, FHXCompareType.IN);
                }
            }

            return(res);
        }
Exemplo n.º 14
0
        public static string ExportFHX(FHXObject obj)
        {
            string s = "";

            s += obj.Type + " ";

            foreach (var param in obj.Parameters.Where(i => i.Mandatory))
            {
                string v = param.VariableType == "string" ? string.Format("\"{0}\"", param.Value) : param.Value;
                s += string.Format("{0}={1} ", param.Name, v);
            }

            s += "\n{\n";

            if (obj.Type == "ATTRIBUTE_INSTANCE")
            {
                s += "VALUE\n{\n";
            }

            foreach (var param in obj.Parameters.Where(i => i.Mandatory == false))
            {
                string v = param.VariableType == "string" ? string.Format("\"{0}\"", param.Value) : param.Value;
                if (param.Value != "")
                {
                    s += string.Format("{0}={1}\n", param.Name, v);
                }
            }

            foreach (var child in obj.Children)
            {
                s += ExportFHX(child);
            }

            if (obj.Type == "ATTRIBUTE_INSTANCE")
            {
                s += "}\n";
            }

            s += "}\n";

            return(s);
        }
Exemplo n.º 15
0
        static public FHXObject FromString(string s)
        {
            BuildingPercent = 0;
            State           = Properties.Resources.ParsingParsing;

            Stopwatch sw = new Stopwatch();

            sw.Restart();
            TokenStream ts = new TokenStream(s);

            sw.Restart();
            mParser = new TokenStreamParser(ts);
            FHXObject root = mParser.ParseAll();

            sw.Stop();
            Console.WriteLine("Parsing file took {0} ms", sw.ElapsedMilliseconds);

            mParser.mTokenStream.Input.Clear();

            return(root);
        }
Exemplo n.º 16
0
        public static void ExportParameterList(List <FHXParameter> data, string file)
        {
            using (var pkg = new ExcelPackage())
            {
                var wbk = pkg.Workbook;
                var sht = wbk.Worksheets.Add("Parameters");

                sht.Cells[1, 1].Value = "Path";
                sht.Cells[1, 2].Value = "Area";
                sht.Cells[1, 3].Value = "Module";
                sht.Cells[1, 4].Value = "Parameter";
                sht.Cells[1, 5].Value = "Value";

                int i = 2;

                foreach (var param in data)
                {
                    string    area   = "";
                    string    tag    = "";
                    FHXObject module = param.Module;

                    if (module != null)
                    {
                        area = module.GetParameter("PLANT_AREA").Value;
                        tag  = module.GetParameter("TAG").Value;
                    }

                    sht.Cells[i, 1].Value = param.Path;
                    sht.Cells[i, 2].Value = area;
                    sht.Cells[i, 3].Value = tag;
                    sht.Cells[i, 4].Value = module == null ? param.Parent.Name + "." + param.Name : param.RelativePath(module);
                    sht.Cells[i, 5].Value = param.Value;
                    i++;
                }

                pkg.SaveAs(new FileInfo(file));
            }
        }
Exemplo n.º 17
0
        public static void ExportParameters(FHXObject obj, string file, bool recursive = true)
        {
            using (var pkg = new ExcelPackage())
            {
                var wbk = pkg.Workbook;
                var sht = wbk.Worksheets.Add("Parameters");

                sht.Cells[1, 1].Value = "Path";
                sht.Cells[1, 2].Value = "Value";

                List <FHXParameter> parameters = obj.GetAllParameters();
                int i = 2;

                foreach (var p in parameters)
                {
                    sht.Cells[i, 1].Value = p.Path;
                    sht.Cells[i, 2].Value = p.Value;
                    i++;
                }

                pkg.SaveAs(new FileInfo(file));
            }
        }
Exemplo n.º 18
0
 public void SetParent(FHXObject parent = null)
 {
     this.Parent = parent;
 }
Exemplo n.º 19
0
 public FHXCompareResult(FHXObject parent, FHXCompareType type, string value = "")
 {
     this.OldValue = value;
     this.Parent   = parent;
     this._type    = type;
 }
Exemplo n.º 20
0
 public FHXStructureHandler(FHXObject root)
 {
     this.Root = root;
 }
Exemplo n.º 21
0
 public FHXSearchResult(FHXObject source)
 {
     this.Source = source;
 }
Exemplo n.º 22
0
        static public void BuildDeltaVHierarchy(FHXObject obj)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            FHXObject        root        = obj.GetRoot();
            List <FHXObject> AllChildren = root.GetAllChildren();

            //Replace FBs with DEFINITION by their definition
            State           = Properties.Resources.ParsingClasses;
            BuildingPercent = 25;
            List <FHXObject> FUNCTION_BLOCK            = AllChildren.Where(i => i.Type == "FUNCTION_BLOCK" && i.Parameters.Any(j => j.Name == "DEFINITION")).ToList();
            List <FHXObject> FUNCTION_BLOCK_DEFINITION = AllChildren.Where(i => i.Type == "FUNCTION_BLOCK_DEFINITION").ToList();

            foreach (FHXObject fb in FUNCTION_BLOCK)
            {
                ProcessFB(fb, FUNCTION_BLOCK_DEFINITION);
            }

            /*
             * Parallel.ForEach(FUNCTION_BLOCK, fb =>
             * {
             *  ProcessFB(fb, FUNCTION_BLOCK_DEFINITION);
             * });
             */
            sw.Stop();
            Console.WriteLine("{0} took {1}ms", "Loading classes", sw.ElapsedMilliseconds);

            //Removes the VALUE Objects and sets their parameters to their parent.
            State           = Properties.Resources.ParsingValues;
            BuildingPercent = 40;
            sw.Restart();
            List <FHXObject> VALUE = AllChildren.Where(i => i.Type == "VALUE").ToList();

            foreach (FHXObject fb in VALUE)
            {
                FHXObject parent = fb.Parent;

                foreach (FHXParameter p in fb.Parameters)
                {
                    parent.AddParameter(p);
                    fb.SetParent(null);
                }
            }
            sw.Stop();
            Console.WriteLine("{0} took {1}ms", "Removing VALUEs", sw.ElapsedMilliseconds);


            //Replace ATTRIBUTE by ATTRIBUTE_INSTANCE when needed
            State           = Properties.Resources.ParsingAttributes;
            BuildingPercent = 75;
            sw.Restart();
            List <FHXObject> ATTRIBUTE_INSTANCE = AllChildren.Where(i => i.Type == "ATTRIBUTE_INSTANCE").ToList();

            foreach (FHXObject attr in ATTRIBUTE_INSTANCE)
            {
                ProcessAttribute(attr);
            }

            /*
             * Parallel.ForEach(ATTRIBUTE_INSTANCE, attr =>
             * {
             *  ProcessAttribute(attr);
             * });
             */
            sw.Stop();
            Console.WriteLine("{0} took {1}ms", "Replacing ATTRIBUTEs", sw.ElapsedMilliseconds);

            //Removes the useless items by type
            State           = Properties.Resources.ParsingCleaning;
            BuildingPercent = 90;
            sw.Restart();
            List <string> unused_types = new List <string>()
            {
                "WIRE", "GRAPHICS", "FUNCTION_BLOCK_TEMPLATE", "FUNCTION_BLOCK_DEFINITION"
            };
            List <string> unused_names = new List <string>()
            {
                "RECTANGLE", "POSITION", "ORIGIN", "END"
            };
            List <FHXObject> uc = AllChildren.Where(i => unused_types.Contains(i.Type) || unused_names.Contains(i.mName)).ToList();

            foreach (FHXObject fb in uc)
            {
                fb.Parent.RemoveChild(fb);
                fb.SetParent(null);
            }
            sw.Stop();
            Console.WriteLine("{0} took {1}ms", "Clearing hierarchy", sw.ElapsedMilliseconds);
            State           = "Done";
            BuildingPercent = 100;
        }
Exemplo n.º 23
0
 public FHXNode(string label, FHXObject data = null, List <FHXNode> children = null)
 {
     this.Label    = label;
     this.Data     = data;
     this.Children = children == null?new List <FHXNode>():children;
 }
Exemplo n.º 24
0
 public static void ExportFHXToFile(FHXObject obj, string path)
 {
     File.WriteAllText(path, ExportFHX(obj));
 }
Exemplo n.º 25
0
 public static List <FHXSearchResult> CheckAffectation(string affectation, FHXObject root, List <FHXObject> os, List <FHXParameter> ps)
 {
     return(root.SearchSimple("//" + affectation, os, ps));
 }
Exemplo n.º 26
0
        public static void ExportBulkEdit(List <FHXParameter> data, string file)
        {
            using (var pkg = new ExcelPackage())
            {
                var wbk = pkg.Workbook;
                var sht = wbk.Worksheets.Add("Parameters");

                List <string> headers = new List <string>();
                Dictionary <string, Dictionary <string, string> > table = new Dictionary <string, Dictionary <string, string> >();

                int i = 2;

                foreach (var param in data)
                {
                    string    area   = "";
                    string    tag    = "";
                    FHXObject module = param.Module;
                    if (module != null)
                    {
                        area = module.GetParameter("PLANT_AREA").Value;
                        tag  = module.GetParameter("TAG").Value;
                        string id = module == null ? param.Parent.Name + "." + param.Name : param.RelativePath(module);

                        if (!headers.Contains(id))
                        {
                            headers.Add(id);
                        }
                        if (!table.ContainsKey(tag))
                        {
                            table.Add(tag, new Dictionary <string, string>());
                        }

                        if (!table[tag].ContainsKey(id))
                        {
                            table[tag].Add(id, param.Value);
                        }
                        else
                        {
                            table[tag][id] = param.Value;
                        }
                    }
                }

                sht.Cells[1, 1].Value = "Module";

                for (int j = 0; j < headers.Count; j++)
                {
                    sht.Cells[1, j + 2].Value = headers[j];
                }

                foreach (string k in table.Keys) //For each modules
                {
                    sht.Cells[i, 1].Value = k;

                    for (int j = 0; j < headers.Count; j++)
                    {
                        int h = j + 2;
                        if (table[k].ContainsKey(headers[j]))
                        {
                            sht.Cells[i, h].Value = table[k][headers[j]];
                        }
                        else
                        {
                            sht.Cells[i, h].Value = "<NULL>";
                        }
                    }
                    i++;
                }
                pkg.SaveAs(new FileInfo(file));
            }
        }
Exemplo n.º 27
0
 public static List <string> ExtractList(FHXObject root, List <string> path)
 {
     return(ExtractList(root.GetAllParameters(), path));
 }
Exemplo n.º 28
0
 public static string Extract(FHXObject root, string path)
 {
     return(Extract(root.GetAllParameters(), path));
 }
Exemplo n.º 29
0
        public static Dictionary <string, List <FHXSearchResult> > CheckAffectations(string[] affectations, FHXObject root)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            long counter = 0;
            long max     = affectations.Length;
            //max = 26;
            Dictionary <string, List <FHXSearchResult> > results = new Dictionary <string, List <FHXSearchResult> >();
            List <FHXParameter> ps = root.GetAllParameters().Where(p => p.Name == "REF").ToList();


            Parallel.For(0, max, (i) =>
            {
                results[affectations[i]] = CheckAffectation(affectations[i], root, null, ps);
                Interlocked.Increment(ref counter);
                if (counter % 25 == 0)
                {
                    Console.WriteLine("Processed {0}/{1}", counter, affectations.Length);
                }
            });

            /*
             * for (long i=0; i < max; i++){
             *  results[affectations[i]] = CheckAffectation(affectations[i], root, null, ps);
             *  counter++;
             *  if (counter % 25 == 0)
             *  {
             *      Console.WriteLine("Processed {0}/{1}", counter, affectations.Length);
             *  }
             * };
             */
            sw.Stop();
            Console.WriteLine("Looked up affectations in {0} ms", sw.ElapsedMilliseconds);

            return(results);
        }
Exemplo n.º 30
0
 public static List <FHXParameter> ExtractPattern(FHXObject root, dynamic script)
 {
     return(ExtractPattern(root.GetAllParameters(), script));
 }