Personal tools
You are here: Home Forum Extension of the platform Popup managers and Qtx?

Popup managers and Qtx?

Up to Extension of the platform

Popup managers and Qtx?

Posted by Timo Siltala at March 18. 2017

Hello,

how does QtxPopupMgr relate to LightApp_Selection popup manager? The first one has been used in ATOMSOLV example, the second one has been recommended in ATOMIC example.

Further, what are the Qtx... classes anyway, Qt documentation does not know about them, neither Google except few hits all pointing to Salome. Are they something inherited from Qt classes and tailored to Salome or what?

Timo

Re: Popup managers and Qtx?

Posted by Timo Siltala at March 20. 2017

In case I just want to add few popup menu items to the standard popup menus, is it then necessary to add my own LightApp_Selection popup manager at all or can I use the default one? How is that done?

Timo

Re: Popup managers and Qtx?

Posted by Vadim SANDLER at March 20. 2017

In your module's class, you have to override the createSelection() method in which you must create and return an instance of your own popup selection class. Look how this is done in ATOMIC module:

LightApp_Selection* ATOMICGUI::createSelection() const
{
  return new ATOMICGUI_Selection();
}

Your popup selection class (a successor of LightApp_Selection) can then introduce own parameters for the popup manager. 

All this works together as follows:

1) In your module's initialize() method you create and register all necessary actions (QAction).

2) In the initialize() method you create menus, toolbars and fill them with the actions. Also, you may say to the popup manager which actions to show in context menus. Here you may also specify the rules which control the visibility and enable/disable state of these actions in the context menus. You can either use existing parameters (supplied with LightApp_Selection) or introduce any additional parameters.

3) If you introduce your own parameters you have to implement a successor of LightApp_Selection class and return its insteance in createSelection() method of your module class. In this class you have to compute values of the parameters by analyzing the current selection made by the user (selection manager).

4) The popup manager automatically computes the rules for each popup menu action basing on the parameters' values computed by popup selection classes. Note that popup manager embeds quite powerful syntax parser so you may use very complex expressions in your popup rules.

See Geometry or Mesh modules as an example of this approach.

Previously Timo Siltala wrote:

Hello,

how does QtxPopupMgr relate to LightApp_Selection popup manager? The first one has been used in ATOMSOLV example, the second one has been recommended in ATOMIC example.

Further, what are the Qtx... classes anyway, Qt documentation does not know about them, neither Google except few hits all pointing to Salome. Are they something inherited from Qt classes and tailored to Salome or what?

Timo

 

Re: Popup managers and Qtx?

Posted by Timo Siltala at March 22. 2017

Thanks Vadim,

you certainly have earned a good cup of coffee. Some problems were solved, however I can't get popup menus to pop up when right clicking in Object Manager selection. Selection works, color changes and it goes to corresponding method but attempt to right click goes straight to the only Module::Function I have added. Not showing my popup menu but the default having Refresh, Expand all and Find. In fact I would like to add to this default popup menu if it is possible but can't understand the logic for it. I have tried  createMenu("Popup menu name",-1,-1) and adding submenus to it, no help, also using popupMgr()->insert(separator(),-1,0), no difference. Both methods seem to be used variably in ATOMIC and ATOMSOLV. What am I missing here?

Timo

Re: Popup managers and Qtx?

Posted by Vadim SANDLER at March 23. 2017

Hello Timo,

The procedure is as follows:

1) Create QAction in initialize() method of your module and register it in the menu manager:

createAction( actionId, tooltip, icon, text, statustip, shortcut, parent, toogled, receiver, slot);

Note that 'actionId' here is an unique (within your module) identifier of your action.

2) Create menus and/or toolbars, and put your action there:

int menuId = createMenu("MyMenu");
createMenu(actionId, menuId);
...
int toolId = createTool("MyToolbar");
createTool(actionId, toolId);

This steps is optional.

3) Register action in the popup manager, so it will be shown in context popup menus:

popupMgr()->insert(actionId);

Now, you should be able to see your action in context menu. Invoking it in context menu will call the slot for your action.

The action will be always shown in context menu, not depending on the selection. If you want to show this action only for some specific selection, you may assign a rule to your action in popup menu manager:

popupMgr()->setRule(actionId, rule);

Here, "rule" is a string which contains an expression. When the expression is "true", action is shown; otherwise it is not shown. You may use variables in the rule, both predefined (like "client", "selcount", etc) and custom ones. But if you use custom variables, you have to implement your own Selection class as written in my previous message - there you must analyze the selection and assign the corresponding values for all your cutom variables.

Regards,
Vadim.

Re: Popup managers and Qtx?

Posted by Timo Siltala at March 23. 2017

Thanks again, Vadim. You have used popupMgr()->insert(actionID), I used popupMgr()->insert(action(ID), parentID,0). I suspect the problem is in the paretID and the trailing zero. I tried to understand their meaning from documentation but there were so many overloads that it was unclear what they should be and are they needed at all. The method I was looking for was QtxActionMenuMgr::insert. I would like to get the popup working in both Object Browser and graphic area, functions limited with rules. Can you see here an explanation for the problem?

Best regards,

Timo

Re: Popup managers and Qtx?

Posted by Timo Siltala at March 23. 2017

Tried your code, popupMgr->insert(actionID) where actionID is enum, is not accepted, parentID is at least required.There is a tiny arrow indicating that a popup exists but I can't get it displayed. The code for is as follows:

    popupMgr()->insert(separator(), parentId, 10);
    popupMgr()->insert(action(MaterialMnu), parentId, 10);
    popupMgr()->insert(action(OpAddToBoundary), parentId, 10);
    popupMgr()->insert(action(OpAddToContacts), parentId, 10);
    popupMgr()->insert(action(OpAddToLoads), parentId, 10);

These show OK. What I would like to get, is my added menu items to the bottom for clarity, I tried several numbers from -1 to 10 but they always remain in the same place. Well, that can be accepted if that is impossible for some reason but the popup doesn't work at all.

    createAction(OpAddToMaterial, "Add to materials", QIcon(), "Lisää materiaaleihin",

    "My materials", 0, dsk, false, this, SLOT(AddToMaterial()) );

    createAction(OpAddToBoundary, "Add to boundary", QIcon(), "Lisää kiinnityksiin",

    "My boundary", 0, dsk, false, this, SLOT(AddToBoundary()) );

    createAction(OpAddToContacts, "Add to materials3", QIcon(), "Lisää kontakteihin",

    "My contacts", 0, dsk, false, this, SLOT(AddToContacts()) );

    createAction(OpAddToLoads, "Add to materials4", QIcon(), "Lisää kuormiin",

    "My loads", 0, dsk, false, this, SLOT(AddToLoads()) );

 

At least the three without popup menu work they enter the slot methods, but "AddToMaterial" not. It however shows both in Object Browser and graphics area which is good, opposite to the others.

int MaterialMnu = createMenu("Lisää materiaaleihin",-1,-1);
    createMenu("AddToMaterial1", MaterialMnu, OpAddToMaterial);

This is how I wrote the create menu

    int parentId = -1;

    popupMgr()->insert(separator(), parentId, 10);
    popupMgr()->insert(action(MaterialMnu), parentId, 10);
    popupMgr()->insert(action(OpAddToBoundary), parentId, 10);
    popupMgr()->insert(action(OpAddToContacts), parentId, 10);
    popupMgr()->insert(action(OpAddToLoads), parentId, 10);

    QString rule = "client='ObjectBrowser' and selcount=1";
//    popupMgr()->setRule(action(OpAddToMaterial), rule); tested and commented out
    popupMgr()->setRule(action(OpAddToBoundary), rule);
    popupMgr()->setRule(action(OpAddToContacts), rule);
    popupMgr()->setRule(action(OpAddToLoads), rule);

Finally the context menu items and rules. As I see it, I have item in context menu which should open a popup and it's only item is linked to operation slot. Still something is missing but what?

Best regards,

Timo

Powered by Ploneboard
Document Actions