예제 #1
0
void CDasherModel::HandleOutput(Dasher::VECTOR_SYMBOL_PROB* pAdded, int* pNumDeleted) {
  CDasherNode *pNewNode = Get_node_under_crosshair();
  DASHER_ASSERT(pNewNode != NULL);
  
  //  std::cout << "HandleOutput: " << m_pLastOutput << " => " << pNewNode << std::endl;
  
  CDasherNode *pLastSeen = pNewNode;
  while (pLastSeen && !pLastSeen->GetFlag(NF_SEEN))
    pLastSeen = pLastSeen->Parent();
  
  while (m_pLastOutput != pLastSeen) {
    m_pLastOutput->Undo();
    m_pLastOutput->Leave(); //Should we? I think so, but the old code didn't...?
    m_pLastOutput->SetFlag(NF_SEEN, false);
    // TODO: Is this the right place to trap output?
    if(pNumDeleted != NULL)
      (*pNumDeleted) += m_pLastOutput->m_iNumSymbols;
    
    m_pLastOutput = m_pLastOutput->Parent();
    if (m_pLastOutput) m_pLastOutput->Enter();
  }
  
  if(!pNewNode->GetFlag(NF_SEEN)) {
    RecursiveOutput(pNewNode, pAdded);
  }
}
예제 #2
0
void CDasherModel::Reparent_root(int lower, int upper) {
  DASHER_ASSERT(m_Root != NULL);

  // Change the root node to the parent of the existing node. We need
  // to recalculate the coordinates for the "new" root as the user may
  // have moved around within the current root
  CDasherNode *pNewRoot;

  if(oldroots.size() == 0) {
    pNewRoot = m_Root->RebuildParent();
  }
  else {
    pNewRoot = oldroots.back();
    oldroots.pop_back();
  }

  // Return if there's no existing parent and no way of recreating one
  if(pNewRoot == NULL)
    return;

  pNewRoot->SetFlag(NF_COMMITTED, false);

  CDasherNode *pCurrent = m_Root;

  // Need to iterate through group pseudo-nodes
  while(pCurrent != pNewRoot) {

    lower = pCurrent->Lbnd();
    upper = pCurrent->Hbnd();

    pCurrent = pCurrent->Parent();
        
    myint iWidth = upper - lower;
    myint iRootWidth = m_Rootmax - m_Rootmin;
    
    // Fail and undo root creation if the new root is bigger than allowed by normalisation
    if(((myint((GetLongParameter(LP_NORMALIZATION) - upper)) / static_cast<double>(iWidth)) >
	 (m_Rootmax_max - m_Rootmax)/static_cast<double>(iRootWidth)) || 
	((myint(lower) / static_cast<double>(iWidth)) > 
	 (m_Rootmin - m_Rootmin_min) / static_cast<double>(iRootWidth))) {
      pNewRoot->OrphanChild(m_Root);
      delete pNewRoot;
      return;
    }
    
    //Update the root coordinates to reflect the new root
    m_Root = pNewRoot;
    
    m_Rootmax = m_Rootmax + (myint((GetLongParameter(LP_NORMALIZATION) - upper)) * iRootWidth / iWidth);
    m_Rootmin = m_Rootmin - (myint(lower) * iRootWidth / iWidth);
    
    for(std::deque<SGotoItem>::iterator it(m_deGotoQueue.begin()); it != m_deGotoQueue.end(); ++it) {
      iRootWidth = it->iN2 - it->iN1;
      it->iN2 = it->iN2 + (myint((GetLongParameter(LP_NORMALIZATION) - upper)) * iRootWidth / iWidth);
      it->iN1 = it->iN1 - (myint(lower) * iRootWidth / iWidth);
    }
  }
}