/* loops on all items in the model collection tree (from the root to the leaves) and adds the * their string names to the tree view. */ private void itemLoop(ModelItemEnumerableCollection models, TreeNode tnc, int ii) { int j = 0; foreach (ModelItem m in models) { MSTreeView.MSTreeNode r = new MSTreeView.MSTreeNode(); r.Text = m.PropertyCategories.ElementAt(0).Properties[0].Value.ToDisplayString(); tnc.Nodes.Add(r); if (ii == 3 && m.Children.First != null) { r.ImageIndex = ii - 1; r.SelectedImageIndex = ii - 1; itemLoop(m.Children, tnc.Nodes[j], ii); } else if (m.HasGeometry) { r.ImageIndex = 3; r.SelectedImageIndex = 3; } else { r.ImageIndex = ii; r.SelectedImageIndex = ii; itemLoop(m.Children, tnc.Nodes[j], ii + 1); } j++; } }
// sets the items of the document to the selection tree for viewing public void setItems() { int i = 0; foreach (ModelItem m in doc.Models.RootItems) { MSTreeView.MSTreeNode r = new MSTreeView.MSTreeNode(); r.Text = m.DisplayName; msTreeView1.Nodes.Add(r); r.ImageIndex = 0; r.SelectedImageIndex = 0; itemLoop(m.Children, msTreeView1.Nodes[i], 1); i++; } }
private void msTreeView1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { MSTreeView.MSTreeNode node = msTreeView1.GetNodeAt(e.Location) as MSTreeView.MSTreeNode; if (node != null) { if (e.Location.X >= node.Bounds.X - (node.TreeView.ImageList.ImageSize.Width + 5) && e.Location.X <= node.Bounds.Right + 1) { ((mainForm)this.DockPanel.Parent).timeSlider1_Scroll(sender, e); System.Drawing.Color c = System.Drawing.Color.Blue; int[] indexs = new int[10]; int i = 1; indexs[0] = node.Index; System.Windows.Forms.TreeNode n = node; while ((n = n.Parent) != null) { indexs[i] = n.Index; i++; } ModelItem model = doc.Models.RootItems.ElementAt(indexs[i - 1]); for (i = i - 2; i >= 0; i--) { model = model.Children.ElementAt(indexs[i]); } doc.Models.OverridePermanentColor(model.Self, new Autodesk.Navisworks.Api.Color(c.R / 255, c.G / 255, c.B / 255)); if (model.PropertyCategories.ElementAt(model.PropertyCategories.Count() - 1).DisplayName == "Dynamics") { this.i = model.PropertyCategories.ElementAt(model.PropertyCategories.Count() - 1).Properties[4].Value.ToInt32(); j = model.PropertyCategories.ElementAt(model.PropertyCategories.Count() - 1).Properties[5].Value.ToInt32(); contextMenuStrip1.Items.Clear(); contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { changePropertiesToolStripMenuItem }); contextMenuStrip1.Size = new Size(164, 26); contextMenuStrip1.Show(msTreeView1, e.Location); } else { ModelItemCollection modelC = new ModelItemCollection(); ModelItemEnumerableCollection modelItems = model.Descendants; foreach (ModelItem m in modelItems) { if (m.PropertyCategories.ElementAt(m.PropertyCategories.Count() - 1).DisplayName == "Dynamics" && m.Parent.PropertyCategories.ElementAt(m.Parent.PropertyCategories.Count() - 1).DisplayName != "Dynamics") { modelC.Add(m); } } if (modelC.Count > 0) { ai = new int[modelC.Count]; aj = new int[modelC.Count]; for (i = 0; i < modelC.Count; i++) { model = modelC[i]; ai[i] = model.PropertyCategories.ElementAt(model.PropertyCategories.Count() - 1).Properties[4].Value.ToInt32(); aj[i] = model.PropertyCategories.ElementAt(model.PropertyCategories.Count() - 1).Properties[5].Value.ToInt32(); } contextMenuStrip1.Items.Clear(); contextMenuStrip1.Items.Add(changeDesendantsToolStripMenuItem); contextMenuStrip1.Size = new Size(164, 26); contextMenuStrip1.Show(msTreeView1, e.Location); } } } } } }