Grasshopper

algorithmic modeling for Rhino

Dear GH nerds,

I'm creating custom component by VS and I have two questions:

1. Where I can find implementation of this thing:

I'm calling it "blackLable" but I have no idea how it is named inside SDK, and how to call it (setup)...

2. Second think is about ComponentMenuItem.

I'm working with CUDA stuff and I want to give a user oportunity to choose Cuda Device. That's mean the list is not constant (some people have 2 or more GPUs)

I can add positions in Context Menu by:

protected override void AppendAdditionalComponentMenuItems(System.Windows.Forms.ToolStripDropDown menu)
  {
   base.AppendAdditionalComponentMenuItems(menu);
     Menu_AppendItem(menu, "Auto Mode", EventHandler, true, true);
     for (int i = 0; i < CudaContext.GetDeviceCount(); i++)
      {

   Menu_AppendItem(menu,CudaContext.GetDeviceInfo(i).DeviceName,EventHandler, true,false);
     }
  }

Until here everything is working. I've add some "Automode", were CudaContex will choose best GPU but also I want to give a possibility to choose GPU and here is the problem, EventHandler.

I've try to override EventHandler by overriding EventArgs:

public class GpuSwitcher : EventArgs
{
    public int DeviceId { get; set; }
    public GpuSwitcher(int D)
    {
      DeviceId = D;
     }
}

And to replace EventHandler in Menu_AppendItem by EventHandler<GpuSwitcher>(function_to_run)

private void function_to_run(object sender, GpuSwitcher e)
{

e <= Containing my data :)

}

to send some data, but GH is not accepting custom EventHandlers... There is any easy way to use ContextMenuItem by this way: if i click first option I get 0, the second options i will get 1 and so on...?

I hope my questions are clear:)

Best Sebastian.

Views: 523

Replies to This Discussion

Yes, Boolean is easy, but not enough. I cannot predict how many GPUs you have. By forloop I'm detecting all CUDA compatible devices ad add ContexMenuItem:

    for (int i = 0; i < CudaContext.GetDeviceCount(); i++)
      {

   Menu_AppendItem(menu,CudaContext.GetDeviceInfo(i).DeviceName,EventHandler, true,false);
     }

And I can't predict how meny EventHandle functions i need to switch between some GPUs...

Example: I have GTX 970 and Quadro 600. In context menu I should get entries:
AUTO MODE (here code will pick best GPU)

GTX 970

Quadro 600

So how you imagine to switch between Gpu by using only bools.? And how to construct EventHandles function for each particular Menu Item if they are generated in for loop ?  

I didnt thought about Lambda... It is nice:)

I like it, but still switch.Next() doesn't send any data, which allows me to identify GPU id. It is working if you switch between 2 options but if I have 3 it is not working. Or maybe I'm stupid.

I've try this implementation:

//first menu for auto - it is strict and working...

Menu_AppendItem(menu, "Auto Mode", (s, e) => { Switcher.AutoMode(this); }, true, true);

//Here by iterations I'm adding additional menus....
for (int i = 0; i < CudaContext.GetDeviceCount(); i++)
{
Menu_AppendItem(menu, CudaContext.GetDeviceInfo(i).DeviceName, (s, e) => { Switcher.GpuId(this,i); }, true, false);
}

But if i click on ContextMenu the index i is out of bounds. (I know the reason, the for loop ends the work and "i" is bigger them Device amount, that's why...)

So still i dont know how to pass my DeviceId by EventHandler...

I'm just looking for simple feature:

3 or more ContextItem added by forloop, when clicked:

Auto => give me 0

Gpu1 => give me 1

Gpu2 => give me 2 and so on...

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service