//=================================================================
void PlanarityTestImpl::calcNewRBCFromTerminalNode(node newCNode,
    node n,
    node n1,
    node n2,
    tlp::BmdList<node>& nodeList) {
  node t = n1;
  node predT = NULL_NODE;
  node parentT = NULL_NODE;

  while (t != n2) {
    parentT = parent.get(t.id);

    //    cout << "Tulip t =  " << t.id << "  : ";
    if (isCNode(t)) {
      //      cout << "Is CNode" << endl;
      t = activeCNodeOf(false, t);
      addOldCNodeRBCToNewRBC(t, newCNode, n, predT, NULL_NODE, nodeList);
      parentT = parent.get(t.id);
      parent.set(t.id, newCNode);

      if (labelB.get(t.id) > labelB.get(newCNode.id)) {
        labelB.set(newCNode.id, labelB.get(t.id));

        if (embed) // needed to calculate obstruction edges;
          nodeLabelB.set(newCNode.id, nodeLabelB.get(t.id));
      }
    }
    else {
      //      cout << "Not Is CNode :" << t << endl;
      parent.set(t.id, newCNode);
      updateLabelB(t);

      if (labelB.get(t.id) > dfsPosNum.get(n.id)) {
        BmdLink<node>* item = nodeList.append(t);
        ptrItem.set(t.id, item) ;//nodeList.append(t));
      }

      if (labelB.get(t.id) > labelB.get(newCNode.id)) {
        labelB.set(newCNode.id, labelB.get(t.id));

        if (embed) // needed to calculate obstruction edges;
          nodeLabelB.set(newCNode.id, nodeLabelB.get(t.id));
      }
    }

    if (!isCNode(t))
      predT = t; // predT is never a c-node;

    t = parentT;
  }
}
/*
 * Embeds all edges in path P' from t1 to t2 and all back-edges with
 * representant in P' (emb_list).
 * emb_back_edges_out_w is false only in case of 2 terminal
 * nodes, for one of the two terminals (see calculate_partial_embedding).
 * Returns an ordered list of all representants to be embedded later
 * (see add_old_cnode_to_embedding).
 * Precondition:
 * - if u is a node in P' and e is a back-edge with representant u then e is in list
 *   b_edges_repres[u].
 */
list<node> PlanarityTestImpl::embedUpwardT(bool embBackEdgesOutW,
    node t1,
    node t2,
    Graph *sG,
    node w,
    map<node , list<edge> > &bEdgesRepres,
    list<node>& traversedNodes,
    tlp::BmdList<edge>& embList) {
  list<node> toEmbedLater;
  node u = t1, predU = NULL_NODE;

  while (predU != t2) {
    if (isCNode(u)) {
      node f = predU,
           oldCNode = activeCNodeOf(false, u);
      addOldCNodeToEmbedding(embBackEdgesOutW, sG, w, oldCNode, f,
                             bEdgesRepres, traversedNodes, toEmbedLater,
                             embList);
      u = parent.get(oldCNode.id);

      if (u == t2)
        return toEmbedLater;
    }
    else {
      if (predU != NULL_NODE) {

        embList.push(edgeReversal( T0EdgeIn.get(predU.id)));

        if (u != w)
          embList.push(T0EdgeIn.get(predU.id));
        else
          embList.append(T0EdgeIn.get(predU.id));
      }
    }

    if (hasBackEdge.get(u.id) && u != t2)
      embedBackEdges(embBackEdgesOutW, sG, u, traversedNodes,
                     bEdgesRepres[u], embList);

    predU = u;
    u = parent.get(u.id);
  }

  return toEmbedLater;
}