private bool load_Labels() { string fn = pviewer.ProjectManager.CurrentProject.FolderPath + "/Data/Labels.xml"; if (!System.IO.File.Exists(fn)) { return(false); } XPathDocument doc = new XPathDocument(fn); XPathNavigator nav = doc.CreateNavigator(); var xml = nav.Select("Labels/Label"); while (xml.MoveNext()) { string xpos = xml.Current.GetAttribute("x", ""); string ypos = xml.Current.GetAttribute("y", ""); string zpos = xml.Current.GetAttribute("z", ""); string name = xml.Current.GetAttribute("name", ""); double x = double.Parse(xpos, System.Globalization.CultureInfo.InvariantCulture); double y = double.Parse(ypos, System.Globalization.CultureInfo.InvariantCulture); double z = double.Parse(zpos, System.Globalization.CultureInfo.InvariantCulture); VRVector3D pos = new VRVector3D(x, y, z); IVRLabel label = m_LabelGroup.Add(name, pos); } return(true); }
void m_ItemCreate_Click(object sender, EventArgs e) { // Get the click information from the Tag property as a VRRaycastResult type. VRRayCastResult res = SDKViewer.UI.ContextMenu3D.Tag as VRRayCastResult; // Create the label at the location the user clicked, and set the text of the label to "New Label" and a next line with the position. IVRLabel label = m_LabelGroup.Add("New Label\n" + res.Position.ToString("f2"), res.Position); // Add it to the dictionary, for later reference (see m_ItemDestroy_Click) m_Labels.Add(label.ID, label); // Dump in the window text area the ID of the label created. m_RichTextBox.Text += "Created a new Label of ID : " + label.ID.ToString() + "\r\n"; }
IVRLabelGroup m_LabelGroup = null; // The label group owned by this plugin. void m_ItemDestroy_Click(object sender, EventArgs e) { // Get the click information from the Tag property as a VRRaycastResult type. VRRayCastResult res = SDKViewer.UI.ContextMenu3D.Tag as VRRayCastResult; IVRLabel label = null; // Try to get the label instance matching the ID. If not found, probably user clicked on a walkinside redline, or a label from other plugin. if (m_Labels.TryGetValue(res.TagID, out label)) { // Remove the tag from the dictionary. m_Labels.Remove(res.TagID); // Remove the label from the 3D engine. m_LabelGroup.Remove(label); label = null; // Dump in the window text area the ID of the label destroyed. m_RichTextBox.Text += "Destroyed Label with ID : " + res.TagID.ToString() + "\r\n"; } else { // Dump in the window text area the ID of the label clicked but not owned by this plugin. m_RichTextBox.Text += "Destroyed Label with ID : " + res.TagID.ToString() + "\r\n"; } }