Пример #1
0
bool CGameServer::StartConnectCenterServer(void)
{
	// 游戏和中心在不同进程,  需要连接内网中心服务器
	if ((m_pConfig->GetLoadServers() & CServerConfig::CFG_DEFAULT_CENTER) == 0) {
		if (m_krConnectCenter == nullptr) {
			UShort     usPort = 0;
			CStringKey strAddr;
			m_pConfig->GetServerAddr(CServerConfig::CFG_DEFAULT_GAME, CServerConfig::CFG_DEFAULT_CENTER, strAddr, usPort);
			m_krConnectCenter = m_NetworkPtr->Create(*this, usPort, *strAddr);
		}
		if (m_krConnectCenter != nullptr) {
			LOG_INFO(m_FileLog, TF("[游戏服务器]游戏服务器和中心服务器在不同进程, 创建连接中心服务器对象成功"));
			if (m_bCenterCnnted == false) {
				UShort     usPort = 0;
				CStringKey strAddr;
				m_pConfig->GetServerAddr(CServerConfig::CFG_DEFAULT_CENTER, CServerConfig::CFG_DEFAULT_GAME, strAddr, usPort);
				if (m_NetworkPtr->Connect(m_krConnectCenter, usPort, *strAddr) == false)
				{
					LOGV_ERROR(m_FileLog, TF("[游戏服务器]连接中心服务器[%s]:%d请求失败"), *strAddr, usPort);
					return false;
				}
				LOGV_INFO(m_FileLog, TF("[游戏服务器]连接中心服务器[%s]:%d请求完成"), *strAddr, usPort);
			}
		}
		else {
			LOG_ERROR(m_FileLog, TF("[游戏服务器]游戏服务器和中心服务器在不同进程, 创建连接中心服务器对象失败"));
			return false;
		}
	}
	else if (m_bCenterCnnted == false) {
		assert(m_pShareCenterSvr == nullptr);
		CKeyValue::VALUE xValue = { 0 };
		m_pConfig->GetKeyValue()->GetValue(CServerConfig::CenterServer, xValue);
		if (xValue.pValue == nullptr) {
			LOG_ERROR(m_FileLog, TF("[游戏服务器]从动态变量表获取同进程中心服务器对象指针无效"));
			return false;
		}
		m_pShareCenterSvr = reinterpret_cast<ICommonServer*>(xValue.pValue);
		m_bCenterCnnted   = true;

		LOG_INFO(m_FileLog, TF("[游戏服务器]同进程直接向中心服务器注册"));
		m_ServerInfo.usStatus = STATUSU_LINK;

		CGameLink Link;
		Link.SetServerData(m_ServerInfo);
		Link.AdjustSize();

		CBufReadStream brs((PByte)m_ServerInfo.NetAddr, sizeof(m_ServerInfo.NetAddr));
		Link.SetStream(brs);

		m_bCenterLinked = m_pShareCenterSvr->OnShareRoutine(PAK_EVENT_LINK, Link, reinterpret_cast<uintptr_t>(this));
		m_pUIHandler->OnHandle(PAK_EVENT_LINK, 0, DATA_INDEX_CENTER);
		return m_bCenterLinked;
	}
	return true;
}
Пример #2
0
void CListBoxEx::DrawText(Graphics *pG, CRect rcItem, CString strText, Color clrText)
{
	FontFamily fontptroll(L"Arial");
	Gdiplus::Font font(&fontptroll, m_fSizeText, FontStyleRegular, UnitPixel);

	StringFormat formatAlign;
	formatAlign.SetAlignment((Gdiplus::StringAlignment)m_nTextAlign1);		// Left / Center / Right
	formatAlign.SetLineAlignment((Gdiplus::StringAlignment)m_nTextAlign2);	// Top / Middle / Bottom

	SolidBrush brs(clrText);
	RectF rcfCaption((float)rcItem.left+m_nOffsetTextX, (float)rcItem.top+m_nOffsetTextY, (float)rcItem.Width()-20,(float)rcItem.Height());
	pG->DrawString(strText,strText.GetLength(),&font,rcfCaption,&formatAlign,&brs);
}
Пример #3
0
void CDlgRecordNIBP::f_set_table_style()
{
    int row = displayModel->rowCount();
    for(int i = 0;i<row;i++)
    {
        if(i%2)
        {
            QColor color("gray");
            QBrush brs(color);
            displayModel->item(i,0)->setBackground(brs);
            displayModel->item(i,1)->setBackground(brs);
            displayModel->item(i,2)->setBackground(brs);
            displayModel->item(i,3)->setBackground(brs);
            displayModel->item(i,4)->setBackground(brs);
        }
    }
}
Пример #4
0
void CPopupDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CBrush brs(RGB(255, 255, 255));
	CBrush *pOldBrs = dc.SelectObject(&brs);
	CPen *pOldPen = (CPen *)dc.SelectStockObject(BLACK_PEN);

	CRect rc;
	GetClientRect(&rc);
	dc.Rectangle(&rc);
	dc.SetBkMode(TRANSPARENT);
	dc.SelectStockObject(SYSTEM_FIXED_FONT);
	dc.TextOut(1, 1, m_strText);

    dc.SelectObject(pOldPen);
    dc.SelectObject(pOldBrs);
}
Пример #5
0
void CDlgRecordNIBP::slot_forwd()
{

    displayModel->clear();
    f_set_table_header();
    QString stopdatetime = m_lasttime.toString(Qt::TextDate);
    QString filter = "para_datetime >= '"+stopdatetime +"' ";
    QSqlQuery q("select  * from para_nibp where "+filter +" order by para_datetime asc limit 11 ;");



    int i = 0;
    QString vdate ;
    QString vtime;
    QString vss;
    QString vsz ;
    QString vpj ;
    QDateTime tmpdatetime[11];
    QDate cdate ;
    QTime ctime;
    while (q.next())
    {
        vdate = q.value(NIBP_TABLE_VIEW_Date).toString();
        vtime = q.value(NIBP_TABLE_VIEW_Time).toString();
        vss = q.value(NIBP_TABLE_VIEW_SS).toString();
        vsz = q.value(NIBP_TABLE_VIEW_SZ).toString();
        vpj = q.value(NIBP_TABLE_VIEW_PJ).toString();
        displayModel->setItem(10-i, 0, new QStandardItem(vdate));
        displayModel->setItem(10-i, 1, new QStandardItem(vtime));
        displayModel->setItem(10-i, 2, new QStandardItem(vss));
        displayModel->setItem(10-i, 3, new QStandardItem(vsz));
        displayModel->setItem(10-i, 4, new QStandardItem(vpj));
        bool bss = q.value(NIBP_TABLE_ALM1).toBool();
        bool bsz = q.value(NIBP_TABLE_ALM2).toBool();
        bool bpj = q.value(NIBP_TABLE_ALM3).toBool();
        QColor color("yellow");
        QBrush brs(color);

        if(bss)
        {
            displayModel->item(10-i,2)->setBackground(brs);
        }
        if(bsz)
        {
            displayModel->item(10-i,3)->setBackground(brs);
        }
        if(bpj)
        {
            displayModel->item(10-i,4)->setBackground(brs);
        }
        cdate = QDate::fromString(vdate,("yyyy-MM-dd"));
        ctime = QTime::fromString(vtime,("hh:mm:ss"));
        tmpdatetime[i].setDate(cdate);
        tmpdatetime[i].setTime(ctime);
        i++;
    }
    if(i>0)
    {
         m_querytime= tmpdatetime[i-1];
         m_lasttime = tmpdatetime[0];
    }

    if(i>10)
    {
        displayModel->removeRow(10);
        m_lasttime = tmpdatetime[1];


    }
    else
    {
        displayModel->removeRows(0,11-i);

    }
    int row = displayModel->rowCount();
    f_set_table_rowname(row);
    //f_set_table_style();

}
Пример #6
0
CDlgRecordNIBP::CDlgRecordNIBP(QWidget *parent,QWidget *pMain):QDialog(parent)
{
    setupUi(this);
    iCursor = 0;
    bCursorSta = false;
    pMainForm = pMain;

    //设置光标顺序
    QPushButton *btn[MAX_DLG_NIBP_BTN] = {
        m_btn_back_end,
        m_btn_back_fast,
        m_btn_back,
        m_btn_forwd,
        m_btn_forwd_fast,
        m_btn_forwd_end,
        m_btn_return
    };
    setTabOrder(m_btn_back_end,m_btn_back_fast);
    setTabOrder(m_btn_back_fast,m_btn_back);
    setTabOrder(m_btn_back,m_btn_forwd);
    setTabOrder(m_btn_forwd,m_btn_forwd_fast);
    setTabOrder(m_btn_forwd_fast,m_btn_forwd_end);
    setTabOrder(m_btn_forwd_end,m_btn_return);
    setTabOrder(m_btn_return,m_btn_back_end);
    m_btn_back_end->setFocus();
    for(int i=0;i<MAX_DLG_NIBP_BTN;i++)
    {
        btn[i]->installEventFilter(this);
    }
    tableModel = new QSqlTableModel(this);
    tableModel->setTable("para_nibp");
    tableModel->setSort(NIBP_TABLE_VIEW_Time,Qt::DescendingOrder);
    tableModel->setHeaderData(NIBP_TABLE_VIEW_Date,Qt::Horizontal,("日期"));
    tableModel->setHeaderData(NIBP_TABLE_VIEW_Time,Qt::Horizontal,("时间"));
    tableModel->setHeaderData(NIBP_TABLE_VIEW_SS,Qt::Horizontal,("收缩压"));
    tableModel->setHeaderData(NIBP_TABLE_VIEW_SZ,Qt::Horizontal,("舒张压"));
    tableModel->setHeaderData(NIBP_TABLE_VIEW_PJ,Qt::Horizontal,("平均压"));

    m_querytime = QDateTime::currentDateTime();//.addSecs(-540); //-10min
    QString stopdate = m_querytime.date().toString("yyyy-MM-dd");
    QString stoptime = m_querytime.time().toString("hh:mm::ss");
    QString stopdatetime = m_querytime.toString(Qt::TextDate);
    //QString filter = "para_date >= '" +stopdate + "'" + "and para_time >= '" + stoptime + "'";
    QString filter = "para_datetime <= '"+stopdatetime +"'";
    tableModel->setFilter(filter);
    tableModel->setFilter("limit 10");
    tableModel->select();
    int rowcount =  tableModel->rowCount();

    displayModel = new QStandardItemModel(this);
    f_set_table_header();
    //bool result =displayModel->insertRows(0,10);

    //if(rowcount >10)
    //{

    //    tableModel->removeRows(10,(rowcount-10));

    //}
    QSqlQuery q("select * from para_nibp where "+filter +" order by para_datetime desc limit 10 ;");
    QSqlRecord rec = q.record();

    int querycnt =  rec.count();
    int i = 0;
    QDateTime tmplastdatetime[10];
    QDate cdate ;
    QTime ctime;
    while (q.next())
    {

        QString vdate = q.value(NIBP_TABLE_VIEW_Date).toString();
        QString vtime = q.value(NIBP_TABLE_VIEW_Time).toString();
        QString vss = q.value(NIBP_TABLE_VIEW_SS).toString();
        QString vsz = q.value(NIBP_TABLE_VIEW_SZ).toString();
        QString vpj = q.value(NIBP_TABLE_VIEW_PJ).toString();
        displayModel->setItem(i, 0, new QStandardItem(vdate));
        displayModel->setItem(i, 1, new QStandardItem(vtime));
        displayModel->setItem(i, 2, new QStandardItem(vss));
        displayModel->setItem(i, 3, new QStandardItem(vsz));
        displayModel->setItem(i, 4, new QStandardItem(vpj));
        bool bss = q.value(NIBP_TABLE_ALM1).toBool();
        bool bsz = q.value(NIBP_TABLE_ALM2).toBool();
        bool bpj = q.value(NIBP_TABLE_ALM3).toBool();
        QColor color("yellow");
        QBrush brs(color);

        if(bss)
        {
            displayModel->item(i,2)->setBackground(brs);
        }
        if(bsz)
        {
            displayModel->item(i,3)->setBackground(brs);
        }
        if(bpj)
        {
            displayModel->item(i,4)->setBackground(brs);
        }
        cdate = QDate::fromString(vdate,("yyyy-MM-dd"));
        ctime = QTime::fromString(vtime,("hh:mm:ss"));
        tmplastdatetime[i].setDate(cdate);
        tmplastdatetime[i].setTime(ctime);
        i++;
    }

    if(i>1)
    {
        m_querytime = tmplastdatetime[0];
    }

    m_lasttime = tmplastdatetime[i-1];
/*

    int row = (rowcount>10)?10:rowcount;
    for(int i = 0; i<row;i++)
    {
        QSqlRecord record = tableModel->record(i);
        QString vdate = record.value(NIBP_TABLE_VIEW_Date).toString();
        QString vtime = record.value(NIBP_TABLE_VIEW_Time).toString();
        QString vss = record.value(NIBP_TABLE_VIEW_SS).toString();
        QString vsz = record.value(NIBP_TABLE_VIEW_SZ).toString();
        QString vpj = record.value(NIBP_TABLE_VIEW_PJ).toString();
        displayModel->setItem(i, 0, new QStandardItem(vdate));
        displayModel->setItem(i, 1, new QStandardItem(vtime));
        displayModel->setItem(i, 2, new QStandardItem(vss));
        displayModel->setItem(i, 3, new QStandardItem(vsz));
        displayModel->setItem(i, 4, new QStandardItem(vpj));
    }
*/
/*
    if(rowcount <10)
    {
        QDate cdate ;
        QTime ctime;
        int row = 0;
        QDateTime vdatetime ;
        for(int i = 0;i<10;i++)
        {
            vdatetime = m_querytime.addSecs((9-i)*60);//table list time
            if(row>=rowcount)
            {
                tableModel->insertRow(i);
            }
            QSqlRecord record = tableModel->record(row);
            cdate = QDate::fromString(record.value(NIBP_TABLE_VIEW_Date).toString(),tr("yyyy-MM-dd"));
            ctime = QTime::fromString(record.value(NIBP_TABLE_VIEW_Time).toString(),tr("hh:mm:ss"));
            //= QDateTime::fromString(nowdatetime,tr("yyyy-MM-ddhh:mm:ss"));
            QDateTime nowtime ; //record time
            nowtime.setDate(cdate);
            nowtime.setTime(ctime);
            if(nowtime == vdatetime)
            {
                row++;
            }
            else
            {
                QString vdate = vdatetime.date().toString("yyyy-MM-dd");
                QString vtime = vdatetime.time().toString("hh:mm:ss");
                tableModel->insertRow(i);
                tableModel->setData(tableModel->index(i,NIBP_TABLE_VIEW_Date),vdate);
                tableModel->setData(tableModel->index(i,NIBP_TABLE_VIEW_Time),vtime);
                tableModel->setData(tableModel->index(i,NIBP_TABLE_VIEW_SS),"---");
                tableModel->setData(tableModel->index(i,NIBP_TABLE_VIEW_SZ),"---");
                tableModel->setData(tableModel->index(i,NIBP_TABLE_VIEW_PJ),"---");
            }
        }



    }
*/
    tv_nibp->setModel(displayModel );//tableModel
    tv_nibp->setSelectionMode(QAbstractItemView::SingleSelection);
    tv_nibp->setSelectionBehavior(QAbstractItemView::SelectRows);
    //tv_nibp->setColumnHidden(NIBP_TABLE_VIEW_Id,true); //id
    //tv_nibp->setColumnHidden(NIBP_TABLE_VIEW_PARAID,true); //para_id
    tv_nibp->setColumnHidden(NIBP_TABLE_DATETIME,true);

    //tv_nibp->resizeColumnsToContents();
    tv_nibp->setEditTriggers(QAbstractItemView::NoEditTriggers);
    tv_nibp->setFocusPolicy(Qt::NoFocus);

    mapper = new QDataWidgetMapper(this);
    mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
    mapper->setModel(tableModel);

    //QSqlQueryModel model;
    //model.setQuery("SELECT * FROM para_nibp ");


}
Пример #7
0
int uformat(BW *bw)
{
	long indent;
	unsigned char *indents;
	B *buf;
	P *b;
	long curoff;
	int c;
	P *p, *q;

	p = pdup(bw->cursor, USTR "uformat");
	p_goto_bol(p);

	/* Do nothing if we're not on a paragraph line */
	if (pisnpara(bw, p)) {
		prm(p);
		return 0;
	}

	/* Move p to beginning of paragraph, bw->cursor to end of paragraph and
	 * set curoff to original cursor offset within the paragraph */
	pbop(bw, p);
	curoff = bw->cursor->byte - p->byte;
	pset(bw->cursor, p);
	peop(bw, bw->cursor);

	/* Ensure that paragraph ends on a beginning of a line */
	if (!pisbol(bw->cursor))
		binsc(bw->cursor, '\n'), pgetc(bw->cursor);

	/* Record indentation of second line of paragraph, of first line if there
	 * is only one line */
	q = pdup(p, USTR "uformat");
	pnextl(q);
	if (q->line != bw->cursor->line) {
		P *r = pdup(q, USTR "uformat");

		indent = nindent(bw, q, 0);
		pcol(r, indent);
		indents = brs(q, r->byte - q->byte);
		prm(r);
	} else {
		P *r = pdup(p, USTR "uformat");
		int x, y;
		indent = nindent(bw, p, 1); /* allowing * and - here */
		pcol(r, indent);
		indents = brs(p, r->byte - p->byte);
		prm(r);
		if (!bw->o.autoindent) {
			/* Don't indent second line of single-line paragraphs if autoindent is off */
			int x = zlen(indents);
			while (x && (indents[x - 1] == ' ' || indents[x - 1] == '\t'))
				indents[--x] = 0;
			if (x) {
				indents[x++] = ' ';
				indents[x] = 0;
			}
			indent = txtwidth1(bw->o.charmap, bw->o.tab, indents, x);
		}
		for (x = 0; indents[x] && (indents[x] == ' ' || indents[x] == '\t'); ++x);
		y = zlen(indents);
		while (y && (indents[y - 1] == ' ' || indents[y - 1] == '\t'))
			--y;
		/* Don't duplicate if it looks like a bullet */
/*		if (y && (indents[y - 1] == '*' || indents[y - 1] == '-') &&
		    (y == 1 || indents[y - 2] == ' ' || indents[y - 2] == '\t'))
			indents[y - 1] = ' '; */
		/* Fix C comment */
		if (indents[x] == '/' && indents[x + 1] == '*')
			indents[x] = ' ';
	}
	prm(q);

	/* But if the left margin is greater, we use that instead */
	if (bw->o.lmargin > indent) {
		int x;
		for (x = 0; indents[x] == ' ' || indents[x] == '\t'; ++x);
		if (!indents[x]) {
			joe_free(indents);
			indent = bw->o.lmargin;
			indents = joe_malloc(indent+1);
			for (x = 0; x != indent; ++x)
				indents[x] = ' ';
			indents[x] = 0;
		}
	}

	/* Cut paragraph into new buffer */
	
	/* New buffer needs to inherit UTF-8 and CR-LF options */
	buf = bcpy(p, bw->cursor);
	buf->o.crlf = p->b->o.crlf;
	buf->o.charmap = p->b->o.charmap;
	bdel(p, bw->cursor);

	/* text is in buffer.  insert it at cursor */

	/* Do first line */
	b = pdup(buf->bof, USTR "uformat");

	while (!piseof(b)) {
		/* Set cursor position if we're at original offset */
		if (b->byte == curoff)
			pset(bw->cursor, p);

		/* Get character from buffer */
		c = pgetc(b);

		/* Stop if we found end of line */
		if (c == '\n') {
			prgetc(b);
			break;
		}

		/* Stop if we found white-space followed by end of line */
		if (joe_isblank(b->b->o.charmap, c) && piseolblank(b)) {
			prgetc(b);
			break;
		}

		/* Insert character, advance pointer */
		binsc(p, c);
		pgetc(p);

		/* Do word wrap if we reach right margin */
		if (piscol(p) > bw->o.rmargin && !joe_isblank(p->b->o.charmap,c)) {
			wrapword(bw, p, indent, bw->o.french, 1, indents);
			break;
		}
	}

	/* Do rest */

	while (!piseof(b)) {
		c = brch(b);
		if (joe_isblank(b->b->o.charmap,c) || c == '\n') {
			int f = 0;
			P *d;
			int g;

			/* Set f if there are two spaces after . ? or ! instead of one */
			/* (What is c was '\n'?) */
			d=pdup(b, USTR "uformat");
			g=prgetc(d);
			if (g=='.' || g=='?' || g=='!') {
				f = 1;
/*				pset(d,b);
				pgetc(d);
				if (c == '\n' || piseol(d) || joe_isspace(bw->b->o.charmap,brch(d))) {
					f = 1;
				}
*/
			}
			prm(d);
			
			/* Skip past the whitespace.  Skip over indentations */
		      loop:
			
			c = brch(b);
			if (c == '\n') {
				if (b->byte == curoff)
					pset(bw->cursor, p);

				pgetc(b);
				while (cpara(bw, (c=brch(b)))) {
					if (b->byte == curoff)
						pset(bw->cursor, p);
					pgetc(b);
				}
			}

			if (joe_isblank(b->b->o.charmap,c)) {
				if(b->byte == curoff)
					pset(bw->cursor, p);
				pgetc(b);
				goto loop;
			}

			/* Insert proper amount of whitespace */
			if (!piseof(b)) {
				if (f && !bw->o.french)
					binsc(p, ' '), pgetc(p);
				binsc(p, ' ');
				pgetc(p);
			}
		} else {
			/* Insert characters of word and wrap if necessary */
			if (b->byte == curoff)
				pset(bw->cursor, p);

			binsc(p, pgetc(b));
			pgetc(p);
			if (piscol(p) > bw->o.rmargin)
				wrapword(bw, p, indent, bw->o.french, 1, indents);
		}
	}

	binsc(p, '\n');
	prm(p);
	brm(buf);
	joe_free(indents);
	return 0;
}
Пример #8
0
void wrapword(BW *bw, P *p, long int indent, int french, int no_over, unsigned char *indents)
{
	P *q;
	P *r;
	P *s;
	int rmf = 0;
	int c;
	long to = p->byte;
	int my_indents = 0;
	
	/* autoindent when called by utype */
	if (!indents) {
		/* Get indentation prefix from beginning of line */
		s = pdup(p, USTR "wrapword");
		p_goto_bol(s);
		pbop(bw, s);
		/* Record indentation of second line of paragraph, of first
		 * line if there is only one line */
		q = pdup(s, USTR "wrapword");
		pnextl(q);
		if (q->line < p->line) {
			/* Second line */
			P *r = pdup(q, USTR "wrapword");

			indent = nindent(bw, q, 0);
			pcol(r, indent);
			indents = brs(q, r->byte - q->byte);
			prm(r);
		} else {
			/* First line */
			P *r = pdup(s, USTR "uformat");
			int x, y;

			indent = nindent(bw, s, 1);
			pcol(r, indent);
			indents = brs(s, r->byte - s->byte);
			prm(r);
			if (!bw->o.autoindent) {
				/* Don't indent second line of single-line paragraphs if autoindent is off */
				int x = zlen(indents);
				while (x && (indents[x - 1] == ' ' || indents[x - 1] == '\t'))
					indents[--x] = 0;
				if (x) {
					indents[x++] = ' ';
					indents[x] = 0;
				}
				indent = txtwidth1(bw->o.charmap, bw->o.tab, indents, x);
			}
			for (x = 0; indents[x] && (indents[x] == ' ' || indents[x] == '\t'); ++x);
			y = zlen(indents);
			while (y && (indents[y - 1] == ' ' || indents[y - 1] == '\t'))
				--y;
			/* Don't duplicate bullet */
/*			if (y && (indents[y - 1] == '*' || indents[y - 1] == '-') &&
			    (y == 1 || indents[y - 2] == ' ' || indents[y - 2] == '\t'))
			    	indents[y - 1] = ' '; */
			/* Fix C comment */
			if (indents[x] == '/' && indents[x + 1] == '*')
				indents[x] = ' ';
		}
		if (bw->o.lmargin > indent) {
			int x;
			for (x = 0; indents[x] == ' ' || indents[x] == '\t'; ++x);
			if (!indents[x]) {
				joe_free(indents);
				indent = bw->o.lmargin;
				indents = joe_malloc(indent+1);
				for (x = 0; x != indent; ++x)
					indents[x] = ' ';
				indents[x] = 0;
			}
		}
		my_indents = 1;
		prm(q);
		prm(s);
	}


/*
	if(!indents) {
		int f = 0;
		P *r = pdup(p);

		p_goto_bol(r);
		q = pdup(r);
		while(cpara(c = brc(q))) {
			if(!joe_isblank(c))
				f = 1;
			pgetc(q);
		}
		if(f) {
			indents = brs(r, q->byte-r->byte);
			rmf = 1;
			if(indents[0] == '/' && indents[1] == '*')
				indents[0] = ' ';
		}
		prm(r);
		prm(q);
	}
*/

	/* Get to beginning of word */
	while (!pisbol(p) && piscol(p) > indent && !joe_isblank(p->b->o.charmap, prgetc(p)))
		/* do nothing */;

	/* If we found the beginning of a word... */
	if (!pisbol(p) && piscol(p) > indent) {
		/* Move q to two (or one if 'french' is set) spaces after end of previous
		   word */
		q = pdup(p, USTR "wrapword");
		while (!pisbol(q))
			if (!joe_isblank(p->b->o.charmap, (c = prgetc(q)))) {
				pgetc(q);
				if ((c == '.' || c == '?' || c == '!')
				    && q->byte != p->byte && !french)
					pgetc(q);
				break;
			}
		pgetc(p);

		/* Delete space between start of word and end of previous word */
		to -= p->byte - q->byte;
		bdel(q, p);
		prm(q);

		if (bw->o.flowed) {
			binsc(p, ' ');
			pgetc(p);
			++to;
		}

		/* Move word to beginning of next line */
		binsc(p, '\n');
		
		/* When overtype is on, do not insert lines */
		if (!no_over && p->b->o.overtype){
			/* delete the next line break which is unnecessary */
			r = pdup(p, USTR "wrapword");
			/* p_goto_eol(r); */
			pgetc(r);
			p_goto_eol(r);
			s = pdup(r, USTR "wrapword");
			pgetc(r);
			bdel(s,r);
			binsc(r, ' ');
			
			/* Now we got to take care that all subsequent lines are not longer than the right margin */
			/* Move cursor to right margin */
			pfwrd(r, r->b->o.rmargin - r->col);
			
			/* Make a copy of the cursor and move the copied cursor to the end of the line */
			prm(s);
			s = pdup(r, USTR "wrapword");
			p_goto_eol(s);
			
			/* If s is located behind r then the line goes beyond the right margin and we need to call wordwrap() for that line. */
/*
			if (r->byte < s->byte){
				wrapword(bw, r, indent, french, 1, indents);
			}
*/			
			prm(r);
			prm(s);
		}
		
		++to;
		if (p->b->o.crlf)
			++to;
		pgetc(p);

		/* Indent to left margin */
		if (indents) {
			binss(p, indents);
			to += zlen(indents);
		} else
			while (indent--) {
				binsc(p, ' ');
				++to;
			}

		if (rmf)
			joe_free(indents);
	}

	/* Move cursor back to original position */
	pfwrd(p, to - p->byte);
	if (my_indents)
		joe_free(indents);
}
Пример #9
0
void CListBoxEx::DrawItem(Graphics *pG, CRect rcItem, Color clrItem)
{
	SolidBrush brs(clrItem);

	pG->FillRectangle(&brs,rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height());
}
Пример #10
0
  void Unitigging::makeContigs(BetterOverlapSetPtr& c_overlaps, overlap::ReadSet*& read_set) {
    fprintf(stderr, "Reads: %d, Overlaps: %d\n", read_set->size(), c_overlaps->size());
    uint32_t** degrees = new uint32_t*[reads_->size()];
    for (size_t i = 0; i < reads_->size(); ++i) {
      degrees[i] = new uint32_t[2]();
    }
    auto add_degree =
      [] (uint32_t** degrees,
          uint32_t read,
          layout::BetterOverlap* better_overlap) {
        uint32_t suf = better_overlap->Suf(read);
        degrees[read][suf] += 1;
      };
    for (size_t i = 0; i < c_overlaps->size(); ++i) {
      auto better_overlap = (*c_overlaps)[i];
      auto overlap = better_overlap->overlap();
      add_degree(degrees, overlap->read_one, better_overlap);
      add_degree(degrees, overlap->read_two, better_overlap);
    }

    UnionFind uf(reads_->size());
    // first mark all reads as unusable
    for (size_t i = 0; i < reads_->size(); ++i) {
      (*reads_)[i]->usable(false);
    }
    // mark reads as usable
    for (size_t i = 0; i < read_set->size(); ++i) {
      size_t id = (*read_set)[i]->id();
      (*reads_)[id]->usable(true);
    }
    BetterReadSet brs(reads_, 1);
    // @mculinovic adding overlaps
    for (size_t i = 0; i < c_overlaps->size(); ++i) {
      auto better_overlap = (*c_overlaps)[i];
      auto overlap = better_overlap->overlap();
      brs[overlap->read_one]->AddOverlap(better_overlap);
      brs[overlap->read_two]->AddOverlap(better_overlap);
    }
    brs.Finalize();
    // end adding overlaps

    // create contigs from reads
    contigs_ = ContigSetPtr(new ContigSet(&brs));

    for (size_t i = 0; i < c_overlaps->size(); ++i) {
      auto better_overlap = (*c_overlaps)[i];
      auto overlap = better_overlap->overlap();
      auto read_one = overlap->read_one;
      auto read_two = overlap->read_two;
      if (degrees[read_one][better_overlap->Suf(read_one)] == 1 &&
          degrees[read_two][better_overlap->Suf(read_two)] == 1) {
        auto contig_one = uf.find(read_one);
        auto contig_two = uf.find(read_two);
        if (contig_one == contig_two) {
          fprintf(stderr, "Detected circular contig %d; reads:", contig_one);
          auto& reads = (*contigs_)[contig_one]->getReads();
          for (auto it = reads.begin(); it != reads.end(); ++it) {
            const auto& read = (*it)->read();
            fprintf(stderr, "%d(size: %d) ", read->orig_id(), read->hi() - read->lo());
          }
          fprintf(stderr, "\n");
          continue;
        }

        fprintf(stderr, "Joining contigs %d and %d by reads (%d, %d)\n", contig_one, contig_two, read_one, read_two);
        auto larger = uf.join(read_one, read_two);
        if (larger == contig_one) {
          (*contigs_)[contig_one]->Join(better_overlap, (*contigs_)[contig_two]);
        } else {
          (*contigs_)[contig_two]->Join(better_overlap, (*contigs_)[contig_one]);
        }
      } else {
        fprintf(stderr,
            "(%d, %d) is not a candidate for contig because of degrees d[%d][%d] = %d; d[%d][%d] = %d\n",
            read_one,
            read_two,
            read_one,
            better_overlap->Suf(read_one),
            degrees[read_one][better_overlap->Suf(read_one)],
            read_two,
            better_overlap->Suf(read_two),
            degrees[read_two][better_overlap->Suf(read_two)]
            );
      }
    }
    for (size_t i = 0; i < reads_->size(); ++i) {

      delete [] degrees[i];
    }
    delete [] degrees;
  }
Пример #11
0
  inline void Unitigging::removeTransitiveEdges() {
    layout::BetterReadSet brs(reads_, 1);
    for (size_t i = 0; i < no_contains_->size(); ++i) {
      auto better_overlap = (*no_contains_)[i];
      auto overlap = better_overlap->overlap();
      brs[overlap->read_one]->AddOverlap(better_overlap);
      brs[overlap->read_two]->AddOverlap(better_overlap);
    }
    brs.Finalize();

    // for o1(x, y) and o2(x, a), o3(y, a)
    std::vector< size_t > erased;
    erased.reserve(no_contains_->size());
    for (size_t i = 0; i < no_contains_->size(); ++i) {
      auto better_overlap = (*no_contains_)[i];
      auto overlap = better_overlap->overlap();
      // TODO(brahle): izdvoji ovo u zasebnu klasu iterator
      auto v1 = brs[overlap->read_one]->overlaps();
      auto v2 = brs[overlap->read_two]->overlaps();
      auto it1 = v1.begin();
      auto it2 = v2.begin();
      bool done = false;

      while (!done && it1 != v1.end() && it2 != v2.end()) {
        if (it1->first == overlap->read_one || it1->first == overlap->read_two) {
          ++it1;
          continue;
        }
        if (it2->first == overlap->read_one || it2->first == overlap->read_two) {
          ++it2;
          continue;
        }
        if (it1->first == it2->first) {
          if (isTransitive(better_overlap, it1->second, it2->second)) {
            (*reads_)[overlap->read_one]->addCoverage(
                static_cast<double> (better_overlap->Length()) /
                (*reads_)[overlap->read_one]->size());
            (*reads_)[it1->first]->addCoverage(
                static_cast<double> (better_overlap->Length()) /
                (*reads_)[it1->first]->size());
            erased.emplace_back(i);

            const auto& o = better_overlap->overlap();
            const auto& o1 = it1->second->overlap();
            const auto& o2 = it2->second->overlap();
            fprintf(stderr,
                "Removing overlap (%d, %d) as transitive of (%d, %d), (%d, %d)\n",
                (*reads_)[o->read_one]->orig_id(),
                (*reads_)[o->read_two]->orig_id(),
                (*reads_)[o1->read_one]->orig_id(),
                (*reads_)[o1->read_two]->orig_id(),
                (*reads_)[o2->read_one]->orig_id(),
                (*reads_)[o2->read_two]->orig_id()
                );
            done = true;
          }
          ++it1;
          ++it2;
        } else if (it1->first < it2->first) {
          ++it1;
        } else {
          ++it2;
        }
      }
    }

    no_transitives_ = BetterOverlapSetPtr(new BetterOverlapSet(reads_));
    size_t idx = 0;
    for (size_t i = 0; i < no_contains_->size(); ++i) {
      if (idx < erased.size() && i == erased[idx]) {
        ++idx;
        continue;
      }
      auto better_overlap = (*no_contains_)[i];
      no_transitives_->Add(new BetterOverlap(better_overlap));
    }
    int transitive_edge_count = no_contains_->size() - no_transitives_->size();
    fprintf(
        stderr,
        "Transitive edges = %d (%.2lf%%)\n",
        transitive_edge_count,
        (transitive_edge_count * 100.0) / no_contains_->size());
  }