Esempio n. 1
0
void wxTreeLayout::DrawBranch(long from, long to, wxDC& dc)
{
    long w, h;
    GetNodeSize(from, &w, &h, dc);
    dc.DrawLine(GetNodeX(from)+w, GetNodeY(from),
        GetNodeX(to), GetNodeY(to));
}
Esempio n. 2
0
static void NodeLineCallBack_first(
	struct Tracker_Windows *window,
	struct WBlocks *wblock,
        struct WTracks *wtrack,
	void *extrainfo,
	int firstlast,
	int realline,
	float y1,float y2,
	float x1,float x2
){
	struct TrackReallineNodeInfo *nodeinfo=(struct TrackReallineNodeInfo *)extrainfo;
	struct Notes *note=(struct Notes *)nodeinfo->pointer;

	InsertTRLElementS(
		nodeinfo->wtrack,
                note,
		realline,
		nodeinfo->type,
		nodeinfo->subtype,
		y1,y2,x1,x2,
		nodeinfo->pointer
	);

	if(firstlast==NODELINE_FIRST || firstlast==NODELINE_FIRSTANDLAST){
	  InsertTRLElementS(
			    nodeinfo->wtrack,
                            note,
			    realline,
			    TRE_VELLINESTART,
			    nodeinfo->subtype,
			    y1,(float)(GetNodeSize(window,wblock,wtrack)*2),x1,(float)GetNodeSize(window,wblock,wtrack),
			    nodeinfo->pointer
			    );
	  InsertTRLElementS(
			    nodeinfo->wtrack,
                            note,
			    realline,
			    TRE_REALSTARTSTOP,
			    nodeinfo->subtype,
			    y1,0.0f,0.0f,0.0f,
			    nodeinfo->pointer
			    );
	}
}
Esempio n. 3
0
void touchmind::layout::LayoutManager::FirstWalk(
    const std::shared_ptr<touchmind::model::node::NodeModel> &tree,
    const std::shared_ptr<touchmind::model::node::NodeModel> &node,
    int level)
{
    std::shared_ptr<touchmind::model::node::NodeModel> pLeftSibling = nullptr;
    node->SetX(0.0f);
    node->SetY(0.0f);
    LayoutWorkData* pTempDataOfNode = _GetLayoutWorkData(node);
    pTempDataOfNode->prelim = 0.0f;
    pTempDataOfNode->modifier = 0.0f;
    pTempDataOfNode->pLeftNeighbor = nullptr;
    pTempDataOfNode->pRightNeighbor = nullptr;
    SetLevelHeight(node, level);
    SetLevelWidth(node, level);
    SetNeighbors(node, level);
    if (node->GetChildrenCount() == 0 || level == m_configuration->GetMaxDepth()) {
        pLeftSibling = node->GetLeftSibling();
        if (pLeftSibling != nullptr) {
            LayoutWorkData* pTempDataOfLeftSibling = _GetLayoutWorkData(pLeftSibling);
            pTempDataOfNode->prelim = pTempDataOfLeftSibling->prelim + GetNodeSize(pLeftSibling) + m_configuration->GetSiblingSeparation();
        } else {
            pTempDataOfNode->prelim = 0.0f;
        }
    } else {
        for (size_t i = 0; i < node->GetChildrenCount(); ++i) {
            std::shared_ptr<touchmind::model::node::NodeModel> pChild = node->GetChild(i);
            FirstWalk(tree, pChild, level + 1);
        }
        FLOAT midPoint = GetChildrenCenter(node);
        midPoint -= GetNodeSize(node) / 2;
        pLeftSibling = node->GetLeftSibling();
        if (pLeftSibling != nullptr) {
            LayoutWorkData* pTempDataOfLeftSibling = _GetLayoutWorkData(pLeftSibling);
            pTempDataOfNode->prelim = pTempDataOfLeftSibling->prelim + GetNodeSize(pLeftSibling) + m_configuration->GetSiblingSeparation();
            pTempDataOfNode->modifier = pTempDataOfNode->prelim - midPoint;
            Apportion(tree, node, level);
        } else {
            pTempDataOfNode->prelim = midPoint;
        }
    }
}
PhraseNode::PhraseNode(UINT64 filePos, OnDiskWrapper &onDiskWrapper)
  :m_counts(onDiskWrapper.GetNumCounts())
{
  // load saved node
  m_filePos = filePos;

  size_t countSize = onDiskWrapper.GetNumCounts();

  std::fstream &file = onDiskWrapper.GetFileSource();
  file.seekg(filePos);
  CHECK(filePos == (UINT64)file.tellg());

  file.read((char*) &m_numChildrenLoad, sizeof(UINT64));
  
  size_t memAlloc = GetNodeSize(m_numChildrenLoad, onDiskWrapper.GetSourceWordSize(), countSize);
  m_memLoad = (char*) malloc(memAlloc);

  // go to start of node again
  file.seekg(filePos);
  CHECK(filePos == (UINT64)file.tellg());

  // read everything into memory
  file.read(m_memLoad, memAlloc);
  CHECK(filePos + memAlloc == (UINT64)file.tellg());

  // get value
  m_value = ((UINT64*)m_memLoad)[1];

  // get counts
  float *memFloat = (float*) (m_memLoad + sizeof(UINT64) * 2);

  CHECK(countSize == 1);
  m_counts[0] = memFloat[0];

  m_memLoadLast = m_memLoad + memAlloc;
}
Esempio n. 5
0
void wxTreeLayout::CalcLayout(long nodeId, int level, wxDC& dc)
{
    wxList children;
    GetChildren(nodeId, children);
    int n = children.GetCount();

    if (m_orientation == false)
    {
        // Left to right
        // X Calculations
        if (level == 0)
            SetNodeX(nodeId, m_leftMargin);
        else
        {
            long x = 0;
            long y = 0;
            long parentId = GetNodeParent(nodeId);
            if (parentId != wxID_ANY)
                GetNodeSize(parentId, &x, &y, dc);
            SetNodeX(nodeId, (long)(GetNodeX(parentId) + m_xSpacing + x));
        }

        wxList::compatibility_iterator node = children.GetFirst();
        while (node)
        {
            CalcLayout((long)node->GetData(), level+1, dc);
            node = node->GetNext();
        }

        // Y Calculations
        long averageY;
        ActivateNode(nodeId, true);

        if (n > 0)
        {
            averageY = 0;
            node = children.GetFirst();
            while (node)
            {
                averageY += GetNodeY((long)node->GetData());
                node = node->GetNext();
            }
            averageY = averageY / n;
            SetNodeY(nodeId, averageY);
        }
        else
        {
            SetNodeY(nodeId, m_lastY);
            long x, y;
            GetNodeSize(nodeId, &x, &y, dc);

            m_lastY = m_lastY + y + m_ySpacing;
        }
    }
    else
    {
        // Top to bottom

        // Y Calculations
        if (level == 0)
            SetNodeY(nodeId, m_topMargin);
        else
        {
            long x = 0;
            long y = 0;
            long parentId = GetNodeParent(nodeId);
            if (parentId != wxID_ANY)
                GetNodeSize(parentId, &x, &y, dc);
            SetNodeY(nodeId, (long)(GetNodeY(parentId) + m_ySpacing + y));
        }

        wxList::compatibility_iterator node = children.GetFirst();
        while (node)
        {
            CalcLayout((long)node->GetData(), level+1, dc);
            node = node->GetNext();
        }

        // X Calculations
        long averageX;
        ActivateNode(nodeId, true);

        if (n > 0)
        {
            averageX = 0;
            node = children.GetFirst();
            while (node)
            {
                averageX += GetNodeX((long)node->GetData());
                node = node->GetNext();
            }
            averageX = averageX / n;
            SetNodeX(nodeId, averageX);
        }
        else
        {
            SetNodeX(nodeId, m_lastX);
            long x, y;
            GetNodeSize(nodeId, &x, &y, dc);

            m_lastX = m_lastX + x + m_xSpacing;
        }
    }
}
void PhraseNode::Save(OnDiskWrapper &onDiskWrapper, size_t pos, size_t tableLimit)
{
  CHECK(!m_saved);

  // save this node
  m_targetPhraseColl.Sort(tableLimit);
  m_targetPhraseColl.Save(onDiskWrapper);
  m_value = m_targetPhraseColl.GetFilePos();

  size_t numCounts = onDiskWrapper.GetNumCounts();

  size_t memAlloc = GetNodeSize(GetSize(), onDiskWrapper.GetSourceWordSize(), numCounts);
  char *mem = (char*) malloc(memAlloc);
  //memset(mem, 0xfe, memAlloc);

  size_t memUsed = 0;
  UINT64 *memArray = (UINT64*) mem;
  memArray[0] = GetSize(); // num of children
  memArray[1] = m_value;   // file pos of corresponding target phrases
  memUsed += 2 * sizeof(UINT64);

  // count info
  float *memFloat = (float*) (mem + memUsed);
  CHECK(numCounts == 1);
  memFloat[0] = (m_counts.size() == 0) ? DEFAULT_COUNT : m_counts[0]; // if count = 0, put in very large num to make sure its still used. HACK
  memUsed += sizeof(float) * numCounts;

  // recursively save chm_countsildren
  ChildColl::iterator iter;
  for (iter = m_children.begin(); iter != m_children.end(); ++iter) {
    const Word &childWord = iter->first;
    PhraseNode &childNode = iter->second;

    // recursive
    if (!childNode.Saved())
      childNode.Save(onDiskWrapper, pos + 1, tableLimit);

    char *currMem = mem + memUsed;
    size_t wordMemUsed = childWord.WriteToMemory(currMem);
    memUsed += wordMemUsed;

    UINT64 *memArray = (UINT64*) (mem + memUsed);
    memArray[0] = childNode.GetFilePos();
    memUsed += sizeof(UINT64);

  }

  // save this node
  //Moses::DebugMem(mem, memAlloc);
  CHECK(memUsed == memAlloc);

  std::fstream &file = onDiskWrapper.GetFileSource();
  m_filePos = file.tellp();
  file.seekp(0, ios::end);
  file.write(mem, memUsed);

  UINT64 endPos = file.tellp();
  CHECK(m_filePos + memUsed == endPos);

  free(mem);

  m_children.clear();
  m_saved = true;
}
Esempio n. 7
0
static void NodeLineCallBack_last(
	struct Tracker_Windows *window,
	struct WBlocks *wblock,
        struct WTracks *wtrack,
	void *extrainfo,
	int firstlast,
	int realline,
	float y1,float y2,
	float x1,float x2
){
	struct TrackReallineNodeInfo *nodeinfo=(struct TrackReallineNodeInfo *)extrainfo;
	struct Notes *note=(struct Notes *)nodeinfo->pointer;

	InsertTRLElementS(
		nodeinfo->wtrack,
                note,
		realline,
		nodeinfo->type,
		nodeinfo->subtype,
		y1,y2,x1,x2,
		nodeinfo->pointer
	);


	if(firstlast==NODELINE_FIRST || firstlast==NODELINE_FIRSTANDLAST){
	  InsertTRLElementS(
			    nodeinfo->wtrack,
                            note,
			    realline,
			    TRE_VELLINENODE,
			    nodeinfo->subtype,
			    y1,y2,x1,x2,
			    nodeinfo->velocity
			    );
	}

	if(
		note->noend==1 &&
		note->end.line==wblock->block->num_lines-1 &&
		note->end.counter==MAX_UINT32-1 &&
		note->end.dividor==MAX_UINT32
	)return;

	if(firstlast==NODELINE_LAST || firstlast==NODELINE_FIRSTANDLAST){
	  InsertTRLElementS(
			    nodeinfo->wtrack,
                            note,
			    realline,
			    TRE_VELLINEEND,
			    nodeinfo->subtype,
			    y2,(float)GetNodeSize(window,wblock,wtrack),x2,(float)GetNodeSize(window,wblock,wtrack),
			    nodeinfo->pointer
			    );
	  InsertTRLElementS(
			    nodeinfo->wtrack,
                            note,
			    realline,
			    TRE_REALSTARTSTOP,
			    nodeinfo->subtype,
			    y2,0.0f,0.0f,0.0f,
			    nodeinfo->pointer
			    );
	}
}
Esempio n. 8
0
void touchmind::layout::LayoutManager::Apportion(
    const std::shared_ptr<touchmind::model::node::NodeModel> &tree,
    const std::shared_ptr<touchmind::model::node::NodeModel> &node,
    int level)
{
    UNREFERENCED_PARAMETER(tree);

    std::shared_ptr<touchmind::model::node::NodeModel> pFirstChild = node->GetFirstChild();
    std::shared_ptr<touchmind::model::node::NodeModel> pFirstChildLeftNeighbor = _GetLayoutWorkData(pFirstChild)->pLeftNeighbor;
    int j = 1;
    for (int k = m_configuration->GetMaxDepth() - level;
            pFirstChild != nullptr && pFirstChildLeftNeighbor != nullptr && j <= k;) {
        FLOAT modifierSumRight = 0.0f;
        FLOAT modifierSumLeft = 0.0f;
        std::shared_ptr<touchmind::model::node::NodeModel> pRightAncestor = pFirstChild;
        std::shared_ptr<touchmind::model::node::NodeModel> pLeftAncestor = pFirstChildLeftNeighbor;
        for (int l = 0; l < j; ++l) {
            pRightAncestor = pRightAncestor->GetParent();
            pLeftAncestor = pLeftAncestor->GetParent();
            modifierSumRight += _GetLayoutWorkData(pRightAncestor)->modifier;
            modifierSumLeft += _GetLayoutWorkData(pLeftAncestor)->modifier;
        }

        FLOAT totalGap = (_GetLayoutWorkData(pFirstChildLeftNeighbor)->prelim + modifierSumLeft + GetNodeSize(pFirstChildLeftNeighbor)
                          + m_configuration->GetSubtreeSeparation()) - (_GetLayoutWorkData(pFirstChild)->prelim + modifierSumRight);
        if (totalGap > 0) {
            std::shared_ptr<touchmind::model::node::NodeModel> subTreeAux = node;
            int numSubtrees = 0;
            for (; subTreeAux != nullptr && subTreeAux != pLeftAncestor; subTreeAux = subTreeAux->GetLeftSibling()) {
                numSubtrees++;
            }
            if (subTreeAux != nullptr) {
                std::shared_ptr<touchmind::model::node::NodeModel> subtreeMoveAux = node;
                FLOAT singleGap = totalGap / numSubtrees;
                for (; subtreeMoveAux != pLeftAncestor; subtreeMoveAux = subtreeMoveAux->GetLeftSibling()) {
                    _GetLayoutWorkData(subtreeMoveAux)->prelim += totalGap;
                    _GetLayoutWorkData(subtreeMoveAux)->modifier += totalGap;
                    totalGap -= singleGap;
                }
            }
        }
        j++;
        if (pFirstChild->GetChildrenCount() == 0) {
            pFirstChild = GetLeftMost(node, 0, j);
        } else {
            pFirstChild = pFirstChild->GetFirstChild();
        }
        if (pFirstChild != nullptr) {
            pFirstChildLeftNeighbor = _GetLayoutWorkData(pFirstChild)->pLeftNeighbor;
        }
    }
}
Esempio n. 9
0
FLOAT touchmind::layout::LayoutManager::GetChildrenCenter(const std::shared_ptr<touchmind::model::node::NodeModel> &node)
{
    auto firstNode = node->GetFirstChild();
    auto lastNode = node->GetLastChild();
    LayoutWorkData* tempDataOfNode = _GetLayoutWorkData(firstNode);
    LayoutWorkData* tempDataOfNode1 = _GetLayoutWorkData(lastNode);
    FLOAT result = tempDataOfNode->prelim + ((tempDataOfNode1->prelim - tempDataOfNode->prelim) + GetNodeSize(lastNode)) / 2;
    return result;
}