Move::Move(Work& work, MoveNode const* move) :KeyNode(work.key) { //M_ASSERT(!move->atLineStart()); if (work.board.whiteToMove()) { if (work.m_level == 0 && (work.m_displayStyle & display::ColumnStyle)) work.pushBreak(); work.needMoveNo = true; } if (!work.isFolded && move->hasComment(move::Ante)) { db::Comment comment(move->comment(move::Ante)); comment.strip(*work.wantedLanguages); if (!comment.isEmpty()) { if (!move->prev()->hasMark() || move->prev()->hasComment(move::Post)) work.pushSpaceOrParagraph(Spacing::Comment); work.pop(m_list); m_list.push_back(new Comment(comment, move::Ante)); work.m_isVirgin = false; work.pushSpaceOrParagraph(Spacing::Comment); work.needMoveNo = true; } } work.pop(m_list); if (!work.isFolded && move->hasAnnotation()) { m_list.push_back(new Annotation( move->annotation(), bool(work.m_displayStyle & display::ShowDiagrams))); } m_ply = work.needMoveNo ? new Ply(move, work.board.moveNumber()) : new Ply(move); m_list.push_back(m_ply); work.incrPlyCount(); work.needMoveNo = false; work.pushSpace(); if (work.isFolded) return; if (move->hasMark()) { m_list.push_back(new Marks(move->marks())); work.pushSpace(); } mstl::string info; getMoveInfo(work, move, info); bool needSpace = false; if (move->hasComment(move::Post)) { db::Comment comment(move->comment(move::Post)); comment.strip(*work.wantedLanguages); if (!comment.isEmpty()) { bool isShort = info.empty() && comment.length() <= work.linebreakMinCommentLength && bool(work.m_displayStyle & display::CompactStyle); if (isShort) work.pushSpace(); else work.pushSpaceOrParagraph(Spacing::Comment); work.pop(m_list); m_list.push_back(new Comment(comment, move::Post)); if (isShort) work.pushSpace(); else needSpace = true; } } if (!info.empty()) { if (needSpace) work.pushSpace(); else work.pushSpaceOrParagraph(Spacing::Comment); work.pop(m_list); m_list.push_back(new Comment(db::Comment(info, false, false), move::Post, Comment::Finally)); needSpace = true; } if (needSpace) { work.pushSpaceOrParagraph(Spacing::Comment); work.needMoveNo = true; } }
void Root::makeList(Work& work, KeyNode::List& result, MoveNode const* node, unsigned varNo, unsigned varCount) { //M_ASSERT(node); //M_ASSERT(node->atLineStart()); bool isFolded = node->isFolded(); work.isFolded = isFolded; result.reserve(2*node->countHalfMoves() + 10); work.key.addPly(work.board.plyNumber()); if (node->prev()) ++work.m_level; result.push_back(new Move(work, node, node->isEmptyLine(), varNo, varCount)); if ( !work.isFolded && (work.m_displayStyle & display::ShowDiagrams) && ( node->annotation().contains(nag::Diagram) || node->annotation().contains(nag::DiagramFromBlack))) { work.pushParagraph(Spacing::Diagram); work.pop(const_cast<Move*>(static_cast<Move const*>(result.back()))->m_list); result.push_back(new Diagram( work, node->annotation().contains(nag::Diagram) ? color::White : color::Black)); work.m_isVirgin = false; work.pushParagraph(Spacing::Diagram); work.needMoveNo = true; } work.key.removePly(); node = node->next(); //M_ASSERT(node); if (work.isFolded) { // too confusing! // if (node->next()->atLineEnd() && !node->hasNote() && !node->prev()->hasNote()) // work.isFolded = false; work.key.addPly(work.board.plyNumber() + 1); result.push_back(new Move(work, node)); work.board.doMove(node->move()); work.key.removePly(); } else { for ( ; !node->atLineEnd(); node = node->next()) { work.key.addPly(work.board.plyNumber() + 1); result.push_back(new Move(work, node)); if ( (work.m_displayStyle & display::ShowDiagrams) && ( node->annotation().contains(nag::Diagram) || node->annotation().contains(nag::DiagramFromBlack))) { work.pushParagraph(Spacing::Diagram); work.pop(const_cast<Move*>(static_cast<Move const*>(result.back()))->m_list); work.board.doMove(node->move()); result.push_back(new Diagram( work, node->annotation().contains(nag::Diagram) ? color::White : color::Black)); work.board.undoMove(node->move()); work.pushParagraph(Spacing::Diagram); work.needMoveNo = true; } if (node->hasVariation()) { work.pushParagraph(Spacing::StartVariation); for (unsigned i = 0; i < node->variationCount(); ++i) { Board board(work.board); Key succKey(work.key); if (i + 1 < node->variationCount()) { succKey.addVariation(i + 1); succKey.addPly(work.board.plyNumber()); } else { succKey.exchangePly(work.board.plyNumber() + 2); } work.key.addVariation(i); work.pushBreak(); work.needMoveNo = true; Variation* var = new Variation(work.key, succKey); result.push_back(var); unsigned linebreakMaxLineLength = work.m_linebreakMaxLineLength; if ( work.m_linebreakMaxLineLength != ::DontSetBreaks && work.linebreakMaxLineLengthVar > 0 && node->variation(i)->countNodes() > work.linebreakMaxLineLengthVar) { work.m_linebreakMaxLineLength = work.linebreakMaxLineLengthVar; } else { work.m_linebreakMaxLineLength = ::DontSetBreaks; } makeList(work, var->m_list, node->variation(i), i + 1, node->variationCount()); work.m_linebreakMaxLineLength = linebreakMaxLineLength; //M_ASSERT(work.m_level > 0); --work.m_level; work.key.removeVariation(); work.board = board; } work.pushParagraph(Spacing::EndVariation); work.needMoveNo = true; } work.isFolded = isFolded; work.board.doMove(node->move()); work.key.removePly(); } } work.key.addPly(work.board.plyNumber() + 1); result.push_back(new Move(work, node->comment(move::Post), varNo, varCount)); work.key.removePly(); }