Esempio n. 1
0
        void generateIDAndElements(string loadID, string loadPat, string nodeName, double value, LoadNode speckleLoadNode)
        {
            speckleLoadNode.value = value;
            Node speckleNode = PointToSpeckle(nodeName);

            speckleLoadNode.loadCase = LoadPatternCaseToSpeckle(loadPat);
            NodeStoring.TryGetValue(loadID, out var nodeList);
            if (nodeList == null)
            {
                nodeList = new List <Node> {
                };
            }
            nodeList.Add(speckleNode);
            NodeStoring[loadID]     = nodeList;
            LoadStoringNode[loadID] = speckleLoadNode;
        }
Esempio n. 2
0
        private RuntimeResult VisitLoadNode(LoadNode node, Context context)
        {
            string fname    = node.Token.Value.ToString();
            string fileName = "";

            if (File.Exists(Program.FileDirectory + fname + Program.LibraryExt))
            {
                fileName = Program.FileDirectory + fname + Program.LibraryExt;
            }
            else if (File.Exists(Program.FileDirectory + "libs\\" + fname + Program.LibraryExt))
            {
                fileName = Program.FileDirectory + "libs\\" + fname + Program.LibraryExt;
            }
            else if (File.Exists(Program.FileDirectory + fname + ".si"))
            {
                fileName = Program.FileDirectory + fname + ".si";
            }
            else if (File.Exists(Program.FileDirectory + "libs\\" + fname + ".si"))
            {
                fileName = Program.FileDirectory + "libs\\" + fname + ".si";
            }
            else if (File.Exists(Program.BaseDirectory + fname + Program.LibraryExt))
            {
                fileName = Program.BaseDirectory + fname + Program.LibraryExt;
            }
            else if (File.Exists(Program.BaseDirectory + "libs\\" + fname + Program.LibraryExt))
            {
                fileName = Program.BaseDirectory + fname + "libs\\" + Program.LibraryExt;
            }
            else if (File.Exists(Program.BaseDirectory + fname + ".si"))
            {
                fileName = Program.BaseDirectory + fname + ".si";
            }
            else if (File.Exists(Program.BaseDirectory + "libs\\" + fname + ".si"))
            {
                fileName = Program.BaseDirectory + "libs\\" + fname + ".si";
            }

            if (fileName.Equals(""))
            {
                return(new RuntimeResult(new RuntimeError(node.Token.Position, "Assembly '" + fname + "' not found!", context)));
            }

            if (fileName.EndsWith(Program.LibraryExt))
            {
                if (node.ClassToken != null)
                {
                    Values.AssemblyValue value = new Values.AssemblyValue();
                    value.SetPositionAndContext(node.Token.Position, context);
                    value.LoadAsm("libs\\" + fname + Program.LibraryExt, fname, node.ClassToken.Value.ToString());
                    context.AddSymbol(node.ClassToken.Value.ToString(), value);
                    return(new RuntimeResult(value));
                }
                else
                {
                    //todo fix this system
                    Assembly asm   = Assembly.LoadFile(fileName);
                    Type[]   types = asm.GetTypes();
                    for (int i = 0; i < types.Length; i++)
                    {
                        Console.WriteLine(types[i].Name);
                    }
                    for (int i = 0; i < types.Length; i++)
                    {
                        Values.AssemblyValue value = new Values.AssemblyValue();
                        value.Assembly = asm;
                        value.AsmType  = types[i];
                        FieldInfo[] fields = types[i].GetFields();
                        for (int j = 0; j < fields.Length; j++)
                        {
                            context.AddSymbol(fields[j].Name, Values.AssemblyValue.ParseValue(fields[j].GetValue(null), node.Token.Position, context));
                        }
                        value.SetPositionAndContext(node.Token.Position, context);
                        context.AddSymbol(types[i].Name, value);
                        if (i == types.Length - 1)
                        {
                            return(new RuntimeResult(value));
                        }
                    }
                }
            }
            else
            {
                string          code            = File.ReadAllText(fileName).Replace("\r\n", "\n");
                Tokenizer       tokenizer       = new Tokenizer(fname, code);
                TokenizerResult tokenizerResult = tokenizer.GenerateTokens();
                if (!tokenizerResult.HasError)
                {
                    Parser       parser       = new Parser(tokenizerResult.Tokens);
                    ParserResult parserResult = parser.Parse();
                    if (!parserResult.HasError)
                    {
                        Interpreter interpreter = new Interpreter();
                        return(interpreter.Visit(parserResult.Node, context));
                    }
                    else
                    {
                        return(new RuntimeResult(parserResult.Error));
                    }
                }
                else
                {
                    return(new RuntimeResult(tokenizerResult.Error));
                }
            }
            return(new RuntimeResult(new RuntimeError(node.Token.Position, "Library " + fname + " not found!", context)));
        }
Esempio n. 3
0
        //need to figure out how to recombine forces into val6
        //void LoadNodeToNative(LoadNode loadNode)
        //{
        //    foreach(var node in loadNode.nodes)
        //    {
        //        Model.PointObj.SetLoadForce(node.name,loadNode.loadCase,load)
        //    }
        //}
        Base LoadNodeToSpeckle(string name, int pointNumber)
        {
            double[] F1          = null;
            double[] F2          = null;
            double[] F3          = null;
            double[] M1          = null;
            double[] M2          = null;
            double[] M3          = null;
            string[] csys        = null;
            int[]    lcStep      = null;
            string[] pointName   = null;
            string[] loadPat     = null;
            int      numberItems = 0;

            int s = Model.PointObj.GetLoadForce(name, ref numberItems, ref pointName, ref loadPat, ref lcStep, ref csys, ref F1, ref F2, ref F3, ref M1, ref M2, ref M3);

            if (s == 0)
            {
                foreach (int index in Enumerable.Range(0, numberItems))
                {
                    if (F1[index] != 0)
                    {
                        var speckleLoadNode = new LoadNode();
                        speckleLoadNode.direction = LoadDirection.X;
                        var loadID = string.Concat(loadPat[index], F1[index], "F1");
                        generateIDAndElements(loadID, loadPat[index], pointName[index], F1[index], speckleLoadNode);
                    }
                    else if (F2[index] != 0)
                    {
                        var speckleLoadNode = new LoadNode();
                        speckleLoadNode.direction = LoadDirection.Y;
                        var loadID = string.Concat(loadPat[index], F2[index], "F2");
                        generateIDAndElements(loadID, loadPat[index], pointName[index], F2[index], speckleLoadNode);
                    }
                    else if (F3[index] != 0)
                    {
                        var speckleLoadNode = new LoadNode();
                        speckleLoadNode.direction = LoadDirection.Z;
                        var loadID = string.Concat(loadPat[index], F3[index], "F3");
                        generateIDAndElements(loadID, loadPat[index], pointName[index], F3[index], speckleLoadNode);
                    }
                    else if (M1[index] != 0)
                    {
                        var speckleLoadNode = new LoadNode();
                        speckleLoadNode.direction = LoadDirection.XX;
                        var loadID = string.Concat(loadPat[index], M1[index], "M1");
                        generateIDAndElements(loadID, loadPat[index], pointName[index], M1[index], speckleLoadNode);
                    }
                    else if (M2[index] != 0)
                    {
                        var speckleLoadNode = new LoadNode();
                        speckleLoadNode.direction = LoadDirection.YY;
                        var loadID = string.Concat(loadPat[index], M2[index], "M2");
                        generateIDAndElements(loadID, loadPat[index], pointName[index], M2[index], speckleLoadNode);
                    }
                    else if (M3[index] != 0)
                    {
                        var speckleLoadNode = new LoadNode();
                        speckleLoadNode.direction = LoadDirection.ZZ;
                        var loadID = string.Concat(loadPat[index], M3[index], "M3");
                        generateIDAndElements(loadID, loadPat[index], pointName[index], M3[index], speckleLoadNode);
                    }
                    //speckleLoadFace.loadCase = LoadPatternCaseToSpeckle(loadPat[index]);
                }
                counterPoint += 1;

                if (counterPoint == pointNumber)
                {
                    foreach (var entry in NodeStoring.Keys)
                    {
                        NodeStoring.TryGetValue(entry, out var listNode);
                        LoadStoringNode.TryGetValue(entry, out var loadStoringNode);
                        loadStoringNode.nodes = listNode;
                        SpeckleModel.loads.Add(loadStoringNode);
                    }
                }
            }

            var speckleBase = new Base();

            return(speckleBase);
        }
Esempio n. 4
0
 public void AddCustomNode(string name, LoadNode node)
 {
     customTypes.Add(new CustomTypeLoader(node, name));
 }
Esempio n. 5
0
 public CustomTypeLoader(LoadNode func, string name)
 {
     this.name = name;
     Loader    = func;
 }
Esempio n. 6
0
 public void AddCustomNode(string name, LoadNode node)
 {
     customTypes.Add(new CustomTypeLoader(node, name));
 }
Esempio n. 7
0
 public CustomTypeLoader(LoadNode func, string name)
 {
     this.name = name;
     Loader = func;
 }