protected void RecurseCollection(NodeDef node, dynamic collection, TreeNode tnCurrent) { if (node.Nodes.Count > 0) { // Collection is a Dictionary<string, dynamic> where dynamic is a List<T> // obj is a KeyValuePair<string, dynamic> foreach (var kvp in collection.Collection) { string collectionName = kvp.Key; var collectionItems = kvp.Value; // Doesn't matter what nodeDef we find, this is only to get the TypeName and number of child nodes on recursion. // But it does allow us to separate the serialization order from the tree definition order. List <NodeDef> matchingNodes = node.Nodes.FindAll(t => t.TypeName.Contains(collectionName)); NodeDef nodeDef = node.Nodes.Find(t => t.TypeName.Contains(collectionName)); foreach (var item in collectionItems) { // Do not create new instances for the items, as they have already been created! IXtreeNode controller = (IXtreeNode)Activator.CreateInstance(Type.GetType(nodeDef.TypeName), new object[] { false }); controller.Item = item; TreeNode tn = View.AddNode(controller, tnCurrent); // If the item is a symbol, then we want to also show in the symbol and structure lists the associated symbol and structure! if (item is Symbol) { // TODO: Yuck. Clean this up so the model is king, and drives any controller, and remove the inc/dec from the respective view! ApplicationController.SymbolListController.IfNotNull(ctrl => ctrl.AddSymbol(item.Name)).Else(() => ApplicationModel.IncrementSymbolReference(item.Name)); ApplicationController.StructureListController.IfNotNull(ctrl => ctrl.AddStructure(item.Structure)).Else(() => ApplicationModel.IncrementStructureReference(item.Structure)); } else { if (!String.IsNullOrEmpty(item.Name)) { tn.Text = item.Name; } } // string name = ((IHasCollection)item).Name; // tn.Text = (String.IsNullOrWhiteSpace(name) ? tn.Text : name); RecurseCollection(nodeDef, item, tn); } } } }
public static bool IsScalarConst(NodeDef node_def, int v) { if (node_def.Op != "Const" || node_def.Name != "scalar") { return(false); } bool found_dtype = false; bool found_value = false; foreach (var attr in node_def.Attr) { if (attr.Key == "dtype") { if (attr.Value.Type == DataType.DtInt32) { found_dtype = true; } else { return(false); } } else if (attr.Key == "value") { if (attr.Value.Tensor != null && attr.Value.Tensor.IntVal.Count == 1 && attr.Value.Tensor.IntVal[0] == v) { found_value = true; } else { return(false); } } } return(found_dtype && found_value); }
public static bool IsAddN(NodeDef node_def, int n) { if (node_def.Op != "AddN" || node_def.Name != "add" || node_def.Input.Count != n) { return(false); } bool found_t = false; bool found_n = false; foreach (var attr in node_def.Attr) { if (attr.Key == "T") { if (attr.Value.Type == DataType.DtInt32) { found_t = true; } else { return(false); } } else if (attr.Key == "N") { if (attr.Value.I == n) { found_n = true; } else { return(false); } } } return(found_t && found_n); }
protected void PopulateTree() { // TODO: For some reason, suspending / resuming layout stops the Dock mode "Fill" from working correctly. // To replicate, uncomment the suspend/resume lines, load a schema, then increase the size of the pane. The tree view // control's size will no longer automatically adjust. // View.SuspendLayout(); // Remove all existing (such as required) nodes. View.TreeView.Nodes[0].Nodes.Clear(); NodeDef nodeDef = View.TreeView.RootNode.Nodes[0]; // Get the child of the top level node. RecurseCollection(nodeDef, ApplicationController.Schema, View.TreeView.Nodes[0]); View.TreeView.CollapseAll(); View.TreeView.Nodes[0].Expand(); // View.TreeView.ResumeLayout(); currentNode = View.TreeView.Nodes[0]; ApplicationController.PropertyGridController.IfNotNull(t => { t.ShowObject(((NodeInstance)currentNode.Tag).Instance.Item); }); View.TreeView.SelectedNode = currentNode; }
public static bool IsNeg(NodeDef node_def, string input) { return(node_def.Op == "Neg" && node_def.Name == "neg" && node_def.Input.Count == 1 && node_def.Input[0] == input); }
//Initalize the PhysicsManager public void Start() { /*mesh = GetComponent<MeshFilter>().mesh; * vertexs = mesh.vertices; * tetrahedrons = mesh.tetrahedrons;*/ nodes = new List <NodeDef>(); springs = new List <SpringDef>(); Dictionary <string, int> edges = new Dictionary <string, int>(); /*GameObject[] fixedBoxGO = GameObject.FindGameObjectsWithTag("FixedBox"); * coll = new Collider[fixedBoxGO.Length]; * * //Get al the fixers in the scene * for (int i = 0;i<fixedBoxGO.Length;i++){ * coll[i] = fixedBoxGO[i].GetComponent<Collider>(); * }*/ volumes = new float[vertexs.Length]; calculateVolumes(); //Initialize all the nodes to the vertices porsitions for (int i = 0; i < vertexs.Length; i++) { NodeDef n = new NodeDef(transform.TransformPoint(vertexs[i]), i, windReaction); n.Manager = this; //n.isFixed(); n.Mass = (tetrahedronDensity * volumes[i]) / 4; n.Damping = nodeDamping; n.collisionConstant = collisionConstant; nodes.Add(n); } //Inialize all the springs related to the tetrahedrons of the mesh for (int i = 0; i < tetrahedrons.Length; i += 4) { int[] tetrahedron = new int[4]; for (int z = 0; z < 4; z++) { tetrahedron[z] = tetrahedrons[i + z]; } int a, b, c, d; a = tetrahedron[0]; b = tetrahedron[1]; c = tetrahedron[2]; d = tetrahedron[3]; string key = createkey(d, b); if (!edges.ContainsKey(key)) { edges.Add(key, c); SpringDef auxSpringDef = new SpringDef(nodes[d], nodes[b]); auxSpringDef.Stiffness = stiffnes; springs.Add(auxSpringDef); } key = createkey(d, c); if (!edges.ContainsKey(key)) { edges.Add(key, c); SpringDef auxSpringDef = new SpringDef(nodes[d], nodes[c]); auxSpringDef.Stiffness = stiffnes; springs.Add(auxSpringDef); } for (int w = 0; w < 4; w++) { a = tetrahedron[w]; b = tetrahedron[(w + 1) % 4]; c = tetrahedron[(w + 2) % 4]; d = tetrahedron[(w + 3) % 4]; key = createkey(a, b); if (!edges.ContainsKey(key)) { edges.Add(key, c); SpringDef auxSpringDef = new SpringDef(nodes[a], nodes[b]); auxSpringDef.Stiffness = stiffnes; springs.Add(auxSpringDef); }/*else{ * int aux = -1; * edges.TryGetValue(key,out aux); * SpringDef auxSpringDef = new SpringDef(nodes[c],nodes[aux]); * auxSpringDef.Stiffness = flexionStiffnes; * auxSpringDef.isFlexion = true; * springs.Add(auxSpringDef); * }*/ } } }