size_t WHtreeProcesser::collapseBranch( const dist_t flatGap, const dist_t distLevelLimit, size_t root, const bool keepBaseNodes )
{
    if( flatGap >= 1 )
    {
        std::cerr << "ERROR @ WHtreeProcesser::flattenTree(): flattening interval must be smaller than 1" << std::endl;
        return 0;
    }

    std::vector< size_t > branchNodes( m_tree.getBranchNodes( root ) );

    //put higher hierarchy first:
    std::reverse( branchNodes.begin(), branchNodes.end() );
    // flatten levels
    for( std::vector< size_t >::iterator nodesIter( branchNodes.begin() ); nodesIter != branchNodes.end(); ++nodesIter )
    {
        if( m_tree.getNode( *nodesIter ).getDistLevel() > distLevelLimit )
        {
            collapseNode( *nodesIter, flatGap );
        }
    }

    size_t collapsed( m_tree.debinarize( keepBaseNodes ) );

    return collapsed;
} // end "collapseBranch()" -----------------------------------------------------------------
size_t WHtreeProcesser::collapseTree( const dist_t flatGap, const dist_t distLevelLimit, const bool keepBaseNodes )
{
    if( flatGap >= 1 )
    {
        std::cerr << "ERROR @ WHtreeProcesser::collapseTree(): flattening interval must be smaller than 1" << std::endl;
        return 0;
    }

    if( flatGap == 0 )
    {
        m_tree.forceMonotonicityDown();
    }
    else
    {
        // flatten all levels
        for( int32_t i = m_tree.getRoot().getID(); i >= 0; --i )
        {
            if( m_tree.getNode( i ).getDistLevel() > distLevelLimit )
            {
                collapseNode( i, flatGap );
            }
        }
        m_tree.m_treeName += ( "_flat" + str( boost::format( "%1.3f" ) % flatGap ) );
    }

    size_t collapsed( m_tree.debinarize( keepBaseNodes ) );

    return collapsed;
} // end "collapseTree()" -----------------------------------------------------------------
void RxDev::showContextMenu_availableNodes(const QPoint&point){

    QMenu contextMenu_availableNodes;
    QModelIndex index(ui->treeView_availableNodes->indexAt(point));
    //menuPoint_availableNodes = point;
    //const QModelIndex index = ui->treeView_availableNodes->selectionModel()->currentIndex();
    QModelIndex seekRoot = index;
    if(index.isValid()){

    while(seekRoot.parent() != QModelIndex())
    {
        seekRoot = seekRoot.parent();

    }
    contextMenu_availableNodes.addAction(tr("view/edit Specfile"),this, SLOT(openSpecFile()));
    contextMenu_availableNodes.addAction(tr("expand"),this, SLOT(expandNode()));
    contextMenu_availableNodes.addAction(tr("collapse"),this, SLOT(collapseNode()));
    contextMenu_availableNodes.addSeparator();
    contextMenu_availableNodes.addAction(tr("expand all"),this, SLOT(expandAll()));
    contextMenu_availableNodes.addAction(tr("collapse all"),this, SLOT(collapseAll()));



    contextMenu_availableNodes.exec(ui->treeView_availableNodes->viewport()->mapToGlobal(point));
    }
}
size_t WHtreeProcesser::flattenBranch( size_t root, const bool keepBaseNodes )
{
    collapseNode( root, 1 );

    size_t collapsed( m_tree.debinarize( keepBaseNodes ) );

    return collapsed;
} // end "flattenBranch()" -----------------------------------------------------------------
void WHtreeProcesser::collapseNode( const nodeID_t &thisNodeID, const dist_t coefficient, HTPROC_COLLAPSE collapseMode )
{
    if( !thisNodeID.first )
    {
        return;
    }
    else
    {
        collapseNode( thisNodeID.second, coefficient, collapseMode );
    }
    return;
} // end collapseNode() -------------------------------------------------------------------------------------
size_t WHtreeProcesser::collapseTreeSquare( const dist_t coefficient, const bool keepBaseNodes )
{
    if( coefficient <= 0 || coefficient >= 1 )
    {
        std::cerr << "ERROR @ WHtreeProcesser::collapseTreeLinear(): coefficient must be in the range (0,1 )" << std::endl;
        return 0;
    }

    else
    {
        // flatten all levels
        for( int32_t i = m_tree.getRoot().getID(); i >= 0; --i )
        {
            collapseNode( i, coefficient, HTPR_C_SQ );
        }
        m_tree.m_treeName += ( "_flatSQ" + str( boost::format( "%1.3f" ) % coefficient ) );
    }

    size_t collapsed( m_tree.debinarize( keepBaseNodes ) );

    return collapsed;
} // end "collapseTreeSquare()" -----------------------------------------------------------------