Home > Community > Forums > Custom IC SKILL > How to write the code - menuItemCallbacks of hiCreateSimpleMenu ?

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 How to write the code - menuItemCallbacks of hiCreateSimpleMenu ? 

Last post Tue, Aug 27 2013 5:45 PM by Charley Chen. 6 replies.
Started by Charley Chen 06 Aug 2013 10:31 PM. Topic has 6 replies and 674 views
Page 1 of 1 (7 items)
Sort Posts:
  • Tue, Aug 6 2013 10:31 PM

    How to write the code - menuItemCallbacks of hiCreateSimpleMenu ? Reply

     

     Dear All ,

    I want to create a simple menu(hiCreateSimleMenu) ,

    which arg l_menuItems  are fixed  , //A -> B -> C

    each  A -> B -> C has it shape id // db:1111 db:2222 db:3333

    How to let arg l_menuItemCallbacks follows  the l_menuItems correspondence ?

    e.g. 

    if   choose A , it will select  db:1111

    if   choose B , it will select  db:2222

    if   choose C , it will select  db:3333

     

    hiCreateSimpleMenu( 'test  "QQ"  list("A" "B" "C")  ????)

    I don't know how to write ???  code  , How to do it ?

     

    Thank you,

    Charley

    • Post Points: 20
  • Mon, Aug 12 2013 10:15 AM

    • skillUser
    • Top 10 Contributor
    • Joined on Fri, Sep 19 2008
    • Austin, TX
    • Posts 2,603
    • Points 16,160
    Re: How to write the code - menuItemCallbacks of hiCreateSimpleMenu ? Reply

     Hi Charley,

    If I have understood your request correctly, it would be something like the following, assuming that the variables "A", "B" etc. contain the database ids of the appropriate instances:

    
    
    items = list(A B C)
    hiDisplayMenu(
      hiCreateSimpleMenu('CCFinstSelectMenu
        "Select Instances"
        foreach(mapcar item items item~>name)
        foreach(mapcar obj items
          sprintf(nil "geSelectFig(dbFindAnyInstByName(geGetEditCellView() %L))"
            obj~>name)
        )
      )
    )
    
    

    I have attached an image of what this might look like - hopefully this is the sort of thing that you were looking for? (If you want "A", "B" etc. in the menu rather than the instance name, simply put the following as the first list passed to the menu function: list("A" "B" "C"), as in your example.

    Best regards,

    Lawrence.


    • Post Points: 20
  • Mon, Aug 12 2013 6:35 PM

    Re: How to write the code - menuItemCallbacks of hiCreateSimpleMenu ? Reply

     Hi Lawrence ,

    Yes , You totally understanded my request.

    In fact ,  items maybe contains insts & shapes , so the code needs to add something ,

    e.g.  determin  whether is shape , if shape  select the shape , if instance , select the instance.

    But I don't know how to write . Could you help me ?

     foreach(mapcar obj items
          sprintf(nil "geSelectFig(dbFindAnyInstByName(geGetEditCellView() %L))"
            obj~>name)
        )

     

    Thank you,
    Charley 

     

    • Post Points: 20
  • Tue, Aug 13 2013 12:48 PM

    • skillUser
    • Top 10 Contributor
    • Joined on Fri, Sep 19 2008
    • Austin, TX
    • Posts 2,603
    • Points 16,160
    Re: How to write the code - menuItemCallbacks of hiCreateSimpleMenu ? Reply

    Hi Charley,

    Here is an attempt at what you are asking for - it may not work under all circumstances, I've arbitrarily picked the center of the objects' bounding box, but if there is an overlapping object this might pick the wrong object when performing the selection.

    
    hiDisplayMenu(
      hiCreateSimpleMenu(
        'CCFinstSelectMenu
        "Select Instances"
        '("A" "B" "C" "D" "E")
        foreach(mapcar obj items 
          case(obj~>objType
            ("inst"
              sprintf(nil
                "geSelectFig(dbFindAnyInstByName(geGetEditCellView() %L))"
                obj~>name
              )
            )
            (t
              sprintf(nil
                "geSelectFig(gePointToFig(hiGetCurrentWindow() t %g:%g))"
                car(centerBox(obj~>bBox)) cadr(centerBox(obj~>bBox))
              )
            )
          ); case
        ); foreach
      ); hiCreateSimpleMenu
    ); hiDisplayMenu
    

    I tested this very briefly and it seems as though it should work.

    Best regards,

    Lawrence.

    • Post Points: 20
  • Tue, Aug 13 2013 10:51 PM

    Re: How to write the code - menuItemCallbacks of hiCreateSimpleMenu ? Reply

     Hi Lawrence , 

    Thank you , But when has many shapes overlap , it won't work.

    (1)Can I write arg l_menuItemCallbacks as a function call ?

    foreach(mapcar obj items
            sprintf(nil "TEST(obj)") //it wont work
    );foreach 
    procedure( TEST(obj)
    printf("%L" obj) 
    );pro 
     
    (2)
    If select "A" ,  it has its dbId , How to pass its dbId 
    If select "B" ,  it has its dbId , How to pass its dbId  
    ...
     
    Thank you,
    Charley 

    • Post Points: 20
  • Tue, Aug 27 2013 10:56 AM

    Re: How to write the code - menuItemCallbacks of hiCreateSimpleMenu ? Reply

    Fundamentally the limitation is that the callback has to be a string, and you can't represent a db object as a string (well, you can, but you can't then use that to locate the db object again, so that's not terribly helpful). It's not obvious how you are indicating to the user what the menu items are and how that relates to the db object underneath, but one solution would be to do this when you build the simple menu:

    MyGlobalItemTable=makeTable('dbLookup nil)
    foreach(mapcar obj items
        sprintf(itemText "%L" obj)
        MyGlobalItemTable[itemText]=obj
        sprintf(nil "TEST(\"%L\")" obj) ; generate callback
    );foreach

    then in your callback function, you can do:

    procedure(TEST(objString)
      realObj=MyGlobalItemTable[objString]
      ... do whatever you want here
    )

    Whatever you do, however, don't hang onto the contents of the global table for too long -  because the database ids might get invalid or recycled (e.g. if objects are deleted, or the containing cellView is purged). For the duration of a popup menu though, it's probably fine though.

    Regards,

    Andrew.

    • Post Points: 20
  • Tue, Aug 27 2013 5:45 PM

    Re: How to write the code - menuItemCallbacks of hiCreateSimpleMenu ? Reply

     Andrew,

     Thank you for help , I will try it.

    Charley

     

    • Post Points: 5
Page 1 of 1 (7 items)
Sort Posts:
Started by Charley Chen at 06 Aug 2013 10:31 PM. Topic has 6 replies.