[Hoops Visualize iOS] How to do it: Find the nodeId when the user taps an item on the model

I’m using the Hoops Visualize app on iOS for picking

I have a modal tree (containing a list of model node items).

When I tap a line/face on the model, they are highlighted. When I tap again, the highlight should be canceled.

Furthermore, when I tap a line/face, I want to get the nodeId of the tapped line/face to link it to the node item in the modal tree.

I followed How to obtain edges for Communicator.Selection.FaceEntity ?. However, it only supports the web platform.

How to obtain on a mobile platform?

@phu_bn this is related to HOOPS Visualize for Desktop & Mobile.

Please consult Selection — HOOPS Visualize Desktop Documentation and look at obtaining selection results.

Mike

I researched the Selection Desktop documentation ( Selection — HOOPS Visualize Desktop Documentation ), but I haven’t obtained the nodeID yet. I used HPS::SelectionResults to get the selected item, but I couldn’t find it.
Could you please support me @simon @mike
Here is my code.


class SandboxHighlightOperator : public HPS::SelectOperator {
public:
//    SandboxHighlightOperator(HPSWidget* widget);
//    virtual ~SandboxHighlightOperator();
    
    explicit SandboxHighlightOperator(HPS::Canvas const& in_canvas);

    virtual ~SandboxHighlightOperator() = default;
    

    virtual HPS::UTF8 GetName() const { return "Qt_SandboxHighlightOperator"; }

    bool OnTouchDown(HPS::TouchState const& in_state) override;
    bool OnTouchUp(HPS::TouchState const& in_state) override;

    bool OnTouchMove(const HPS::TouchState& in_state) override;

    static ::HPS::Selection::Level SelectionLevel;

    void Unhighlight();

private:
    void HighlightCommon();
//    bool SelectCommon(HPS::Point const& in_loc, HPS::WindowKey& in_window, HPS::ModifierKeys in_modifiers);

private:
//    HPSWidget* mainWidget;
    HPS::Canvas canvas;

    bool m_isMove = false;
    HPS::TouchState m_mouseUpState;

    std::vector<HPS::SelectionItem> m_selectItems; // edge face
};
#endif /* SandboxHighlightOperator_h */

SandboxHighlightOperator::SandboxHighlightOperator(HPS::Canvas const& in_canvas)
    : HPS::SelectOperator(HPS::MouseButtons::ButtonLeft(), HPS::ModifierKeys())
    , canvas(in_canvas)
{
}


bool SandboxHighlightOperator::OnTouchDown(HPS::TouchState const& in_state)
{
    m_isMove = false;
    m_mouseUpState = in_state;
    return false;
}

bool SandboxHighlightOperator::OnTouchMove(const HPS::TouchState& in_state)
{
    m_isMove = true;
    return Operator::OnTouchMove(in_state);
}

bool SandboxHighlightOperator::OnTouchUp(const HPS::TouchState& in_state)
{
    HighlightCommon();
    return Operator::OnTouchUp(in_state);
}

void SandboxHighlightOperator::HighlightCommon()
{
    HPS::SelectionResults selection_results = GetActiveSelection();
    size_t selected_count = selection_results.GetCount();
    
    HPS::SelectionResultsIterator iter = selection_results.GetIterator();
    while (iter.IsValid()) {
        HPS::SelectionItem selectionItem = iter.GetItem();
        HPS::Key key;
        selectionItem.ShowSelectedItem(key); // 'key' is the HPS::Key of the selected item

        if (key.Type() == HPS::Type::ShellKey) {
            // do something with this key
            printf("found note");
        }

        iter.Next();
    }
    
    if (selected_count > 0) {
        HPS::HighlightOptionsKit highlight_options(HPS::HighlightOptionsKit::GetDefault());
        highlight_options.SetStyleName("highlight_style");
        highlight_options.SetSubentityHighlighting(false);
        highlight_options.SetOverlay(HPS::Drawing::Overlay::InPlace);
        
        HPS::SelectionResultsIterator it = selection_results.GetIterator();
        HPS::SelectionItem item = it.GetItem();
        intptr_t nodeId = item.GetClassID();
    }

    canvas.Update();
}

Hi @simon

Could you please support me in this case? I’ve researched about HPS::SelectionResults, but have not completed it yet

@phu_bn it’s not clear what part isn’t working.

Is a selection made (i.e. a touch down event occurs)?

Is selected_count > 0 in HighlightCommon()?

What are you trying to achieve with the nodeId? You are assigning the return value of GetClassID() which is not unique to a specific node.

Mike

Thank you for your support @mike

I applied HPS::HighlightOperator to the highlight operator custom instead HPS::SelectOperator

I obtained the NodeID from key.owner().