Closed dkOogway closed 6 years ago
Hi
Believe that example 7 has most of the information you need. https://github.com/walkinside/sdk/tree/master/examples/official/Viewer%20SDK/Ex7.Labels
Basic operation is:
// Create a group of labels in the 3D engine.
IVRLabelGroup m_LabelGroup = SDKViewer.CreateLabelGroup("Example7");
// 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("valve not accessible", position3d);
To get the position to place the label, you could use the bounding box of your equipment. For example
IVRBranch branch = SDKViewer.ProjectManager.CurrentProject.BranchManager.GetBranchesByExactNamesAndKind(new string[]{ "V-500" }, VRBranchKind.Cad).FirstOrDefault();
VRVector3D position3d = branch.AABB.Center;
Happy coding
Thanks griemens,
Hi Griemens, Is possible to click on label as button to show separate form / Graphical form view to show details. Checked in SDK documentation, IVRLabel does not has the control action. Ex.,
I tried with adding button in Walkinside with below code, It is not working. Is this possible? or any other solution is available in Walkinside. Please share,
ToolStripMenuItem m_Item = null;
ToolStripItem m_ItemAdd = null;
public bool CreatePlugin(IVRViewerSdk viewer)
{
m_Item = viewer.UI.Control.ContextMenuStrip.Items.Add("Test") as ToolStripMenuItem;
m_ItemAdd = m_Item.DropDownItems.Add("Add");
m_ItemAdd.Click += new EventHandler(m_ItemAdd_Click);
return true;
}
private void m_ItemAdd_Click(object sender, EventArgs e)
{
VRRayCastResult res = SDKViewer.UI.Control.ContextMenuStrip.Tag as VRRayCastResult;
int x = Convert.ToInt32(res.Position.X);
int y = Convert.ToInt32(res.Position.Y);
Button b = new Button();
b.Location = new Point(x, y);
b.Height = 40;
b.Width = 120;
b.Text = "Test";
Controls.Add(b);
}
-- Thanks
Hi,
Indeed labels do not have event handlers to detect there user clicks. Labels are made to be very fast updated and to have hundreds even thousands of them without impacting framerate. Would really recommend to have a detailed look at example 7 in the SDK.
What I usualy do is adding a menu item to the context menu
// Create a menu item in the 3D Context Menu, called "Example
m_Item = SDKViewer.UI.Control.ContextMenuStrip.Items.Add("Example 7") as ToolStripMenuItem;
// Create sub menu items to create and destroy labels.
m_ItemCreate = m_Item.DropDownItems.Add("Create Label");
m_ItemDestroy = m_Item.DropDownItems.Add("Destroy Label");
Next add to these items an event handler for example ItemDestroy
Now to detect which label to destroy
// Get the click information from the Tag property as a VRRaycastResult type.
VRRayCastResult res = SDKViewer.UI.Control.ContextMenuStrip.Tag as VRRayCastResult;
// Next test if the label belongs to your set of labels. To do this we store all label ids in our own dictionary.
if (m_Labels.TryGetValue(res.TagID, out label))
If want to have the context menu behave differently depenign if clicked on one of your labels, you could hook up to an eventhandler Opening in SDKViewer.UI.Control.ContextMenuStrip
Kind regards
Hi, Thanks for information about labels does not have event handlers. Good to know label works faster, yes i have experienced it. Thanks
I started work on label which am referring from Example 7. As you explained, i could create a context menu to show my form. But these i could achieve by adding new label and then i could access it.
But in my case is different. Is it possible to access the Label group which is created by other context menu 1. Because context menu 1 will be acitivated only in edit mode.
So i have to access the label details which was created by context menu 1. If not possible in current implementation, i will look into other option to access label details. --Thanks
Hi, for my requirement i could not use label. Because i want to access the details of tag information's. Thank you so much for your time and good explanations.
Hi dkOogway,
Not sure if I understand what you mean with tag Information. In case you mean to have access to Branch information where Tag is assigned, you will need to implement your own management type of framework. Sometimes what I do is wrapping IVRLabel in my own class maybe in your case something like.
public class VRMyLabel
{
public IVRLabel Label { get; private set; }
public IVRBranch Branch { get; private set; }
public VRMyLabel(IVRLabelGroup group, IVRBRanch branch)
{
this.Label = group.Add(branch.Name, branch.AABB.Center);
this.Branch = branch;
}
......
}
Good luck
Hi, How to create a separate graphic box on 3D object to show the name of object?
-- Thanks