Exemplo n.º 1
0
float GiGraphics::calcPenWidth(float lineWidth, bool useViewScale) const
{
    float w = mgMin(m_impl->minPenWidth, 1.f);

    if (m_impl->maxPenWidth <= 1)
        lineWidth = 0;

    if (lineWidth > 0) {            // 单位:0.01mm
        w = lineWidth / 2540.f * xf().getDpiY();
        if (useViewScale)
            w *= xf().getViewScale();
    }
    else if (lineWidth < 0) {       // 单位:像素
        if (lineWidth < -1e3f)      // 不使用UI放缩系数
            w = 1e3f - lineWidth;
        else
            w = -lineWidth * _penWidthFactor;
        if (useViewScale)
            w *= xf().getViewScale();
    }
    w = mgMin(w, m_impl->maxPenWidth);
    w = mgMax(w, m_impl->minPenWidth);
    //if (lineWidth <= 0 && xf().getDpiY() > getScreenDpi())
    //    w = w * xf().getDpiY() / getScreenDpi();

    return w;
}
Exemplo n.º 2
0
bool GiGraphics::setClipBox(const RECT_2D& rc)
{
    if (m_impl->drawRefcnt < 1)
        return false;

    bool ret = false;
    Box2d rect;

    if (!rect.intersectWith(Box2d(rc), Box2d(m_impl->clipBox0)).isEmpty())
    {
        if (rect != Box2d(m_impl->clipBox))
        {
            rect.get(m_impl->clipBox);
            m_impl->rectDraw.set(Box2d(rc));
            m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
            m_impl->rectDrawM = m_impl->rectDraw * xf().displayToModel();
            m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
            SafeCall(m_impl->canvas, clipRect(m_impl->clipBox.left, m_impl->clipBox.top,
                                              m_impl->clipBox.width(),
                                              m_impl->clipBox.height()));
        }
        ret = true;
    }

    return ret;
}
Exemplo n.º 3
0
float GiGraphics::calcPenWidth(float lineWidth, bool useViewScale) const
{
    float w = 1;
    float px;

    if (m_impl->maxPenWidth <= 1)
        lineWidth = 0;

    if (lineWidth > 0)      // 单位:0.01mm
    {
        px = lineWidth / 2540.f * xf().getDpiY();
        if (useViewScale)
            px *= xf().getViewScale();
        w = mgMin(px, m_impl->maxPenWidth);
    }
    else if (lineWidth < 0) // 单位:像素
    {
        w = mgMin(-lineWidth, m_impl->maxPenWidth);
    }
    
    w = mgMax(w, m_impl->minPenWidth);
    if (lineWidth <= 0 && xf().getDpiY() > getScreenDpi()) {
        w = w * xf().getDpiY() / getScreenDpi();
    }

    return w;
}
Exemplo n.º 4
0
bool GiGraphics::setClipWorld(const Box2d& rectWorld)
{
    bool ret = false;

    if (isDrawing() && !rectWorld.isEmpty())
    {
        Box2d box (rectWorld * xf().worldToDisplay());

        box.intersectWith(Box2d(m_impl->clipBox0));
        if (!box.isEmpty(Tol(1, 0)))
        {
            if (box != Box2d(m_impl->clipBox))
            {
                box.get(m_impl->clipBox);
                m_impl->rectDraw = box;
                m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
                m_impl->rectDrawM = m_impl->rectDraw * xf().displayToModel();
                m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
                SafeCall(m_impl->canvas, _clipBoxChanged(m_impl->clipBox));
            }

            ret = true;
        }
    }

    return ret;
}
Exemplo n.º 5
0
bool GiCanvasGdip::beginPaint(HDC hdc, HDC attribDC, bool buffered, bool overlay)
{
    bool ret = (NULL == m_draw->m_gs)
        && GiCanvasWin::beginPaint(hdc, attribDC, buffered, overlay);
    if (!ret)
        return false;

    buffered = buffered && !gs()->isPrint();
    COLORREF cr = ::GetBkColor(hdc);
    m_draw->m_bkColor.set(GetRValue(cr), GetGValue(cr), GetBValue(cr));

    GdipOverlayBmp oldDrawing;
    if (buffered && overlay)
        oldDrawing.save(m_owner, hdc);

    m_draw->m_gs = new G::Graphics(hdc);
    if (m_draw->m_gs == NULL)
    {
        GiCanvasWin::endPaint(false);
        return false;
    }

    if (buffered)
    {
        m_draw->m_memBitmap = new G::Bitmap(xf().getWidth(), xf().getHeight());
        m_draw->m_memGs = G::Graphics::FromImage(m_draw->m_memBitmap);
        oldDrawing.draw(m_draw->m_memGs);
    }

    _antiAliasModeChanged(gs()->isAntiAliasMode());

    return ret;
}
Exemplo n.º 6
0
bool GiCanvasGdi::drawCachedBitmap2(const GiCanvas* p, float x, float y, bool secondBmp)
{
    if (p && p->getCanvasType() == getCanvasType())
    {
        const GiCanvasGdi* gs = static_cast<const GiCanvasGdi*>(p);
        return gs->xf().getWidth() == xf().getWidth()
            && gs->xf().getHeight() == xf().getHeight()
            && GdiCachedBmp(secondBmp).draw(m_draw, m_draw->getDrawDC(), x, y);
    }
    return false;
}
Exemplo n.º 7
0
bool GiGraphics::drawBeeline(const GiContext* ctx, const Point2d& startPt,
                             const Point2d& endPt, bool modelUnit)
{
    Vector2d vec((endPt - startPt) * RAYMUL);
    Point2d pts[2] = { (startPt - vec) * S2D(xf(), modelUnit),
        (endPt + vec) * S2D(xf(), modelUnit) };
    
    if (!mglnrel::clipLine(pts[0], pts[1], m_impl->rectDraw))
        return false;
    
    return rawLine(ctx, pts[0].x, pts[0].y, pts[1].x, pts[1].y);
}
void
RegularizedHingeIntegration::getSectionWeights(int numSections, double L,
					       double *wt)
{
  beamInt->getSectionWeights(numSections-2, L, wt);

  double oneOverL = 1.0/L;

  double betaI = lpI*oneOverL;
  wt[1] = wt[0]-betaI;
  wt[0] = betaI;

  double betaJ = lpJ*oneOverL;
  wt[2] = wt[numSections-3]-betaJ;
  wt[3] = betaJ;
  
  const int nc = 4;
  int nf = numSections - nc;

  if (nf > 0) {
    
    if (wf == 0)
      wf = new double[nf];
    
    double pt[100];
    this->getSectionLocations(numSections, L, pt);

    Vector wc(wt, nc);
    Vector xc(pt, nc);
    Vector xf(&pt[nc], nf);

    Vector R(nf);
    for (int i = 0; i < nf; i++) {
      double sum = 0.0;
      for (int j = 0; j < nc; j++)
	sum += pow(xc(j),i)*wc(j);
      R(i) = 1.0/(i+1) - sum;
    }
    
    Matrix J(nf,nf);
    for (int i = 0; i < nf; i++)
      for (int j = 0; j < nf; j++)
	J(i,j) = pow(xf(j),i);
    
    Vector wfVec(wf, nf);
    
    J.Solve(R, wfVec);
  }

  for (int i = 0; i < nf; i++)
    wt[i+nc] = wf[i];
}
Exemplo n.º 9
0
bool GiGraphics::drawLine(const GiContext* ctx, const Point2d& startPt,
                          const Point2d& endPt, bool modelUnit)
{
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(Box2d(startPt, endPt)))
        return false;

    Point2d pts[2] = { startPt * S2D(xf(), modelUnit), endPt * S2D(xf(), modelUnit) };

    if (!mglnrel::clipLine(pts[0], pts[1], m_impl->rectDraw))
        return false;

    return rawLine(ctx, pts[0].x, pts[0].y, pts[1].x, pts[1].y);
}
Exemplo n.º 10
0
bool GiGraphics::beginPaint(GiCanvas* canvas, const RECT_2D& clipBox)
{
    if (!canvas || m_impl->canvas || m_impl->drawRefcnt > 0) {
        return false;
    }
    
    m_impl->canvas = canvas;
    m_impl->ctxused = 0;
    m_impl->stopping = 0;
    giInterlockedIncrement(&m_impl->drawRefcnt);
    
    if (m_impl->lastZoomTimes != xf().getZoomTimes()) {
        m_impl->zoomChanged();
        m_impl->lastZoomTimes = xf().getZoomTimes();
    }
    
    m_impl->clipBox0 = clipBox;
    if (Box2d(clipBox).isEmpty()) {
        (xf().getWndRectW() * xf().worldToDisplay()).get(m_impl->clipBox0);
    }
    m_impl->clipBox  = m_impl->clipBox0;
    m_impl->rectDraw = m_impl->clipBox0;
    m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
    m_impl->rectDrawM = Box2d(m_impl->rectDraw) * xf().displayToModel();
    m_impl->rectDrawMaxM = xf().getWndRectM();
    m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
    m_impl->rectDrawMaxW = m_impl->rectDrawMaxM * xf().modelToWorld();
    
    return true;
}
Exemplo n.º 11
0
 void reverse() {
     if (xf() == 0) {
         xf() = 1;
         xi()--;
     } else if (xf() == 1) {
         xf() = 0;
         xi()++;
     } else if (yf() == 0) {
         yf() = 1;
         yi()--;
     } else if (yf() == 1) {
         yf() = 0;
         yi()++;
     }
 }
Exemplo n.º 12
0
bool GiGraphics::drawPath(const GiContext* ctx, int count, 
                          const Point2d* points, const UInt8* types, 
                          bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 2 
        || points == NULL || types == NULL)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    if (count > 0x2000)
        count = 0x2000;

    Matrix2d matD(S2D(xf(), modelUnit));

    const Box2d extent (count, points);                     // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    vector<Point2d> pxpoints;
    pxpoints.resize(count);
    Point2d *pxs = &pxpoints.front();

    for (int i = 0; i < count; i++)
        pxs[i] = points[i] * matD;

    return rawPath(ctx, count, pxs, types);
}
Exemplo n.º 13
0
bool GiGraphics::drawSplines(const GiContext* ctx, int count, 
                             const Point2d* knots, 
                             const Vector2d* knotvs, bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 2 
        || knots == NULL || knotvs == NULL)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    count = mgMin(count, static_cast<int>(1 + (0x2000 - 1) / 3));

    int i;
    Point2d pt;
    Vector2d vec;
    vector<Point2d> pxpoints;
    Matrix2d matD(S2D(xf(), modelUnit));

    // 开辟整形像素坐标数组
    pxpoints.resize(1 + (count - 1) * 3);
    Point2d *pxs = &pxpoints.front();

    pt = knots[0] * matD;                       // 第一个Bezier段的起点
    vec = knotvs[0] * matD / 3.f;               // 第一个Bezier段的起始矢量
    *pxs++ = pt;                                // 产生Bezier段的起点
    for (i = 1; i < count; i++)                 // 计算每一个Bezier段
    {
        *pxs++ = (pt += vec);                   // 产生Bezier段的第二点
        pt = knots[i] * matD;                   // Bezier段的终点
        vec = knotvs[i] * matD / 3.f;           // Bezier段的终止矢量
        *pxs++ = pt - vec;                      // 产生Bezier段的第三点
        *pxs++ = pt;                            // 产生Bezier段的终点
    }

    // 绘图
    return rawBeziers(ctx, &pxpoints.front(), getSize(pxpoints));
}
Exemplo n.º 14
0
int
put_xform(			/* translate and print transform */
	register XF_SPEC	*spec
)
{
	register char	**av;
	register int	n;

	n = xf_ac(spec) - xf_ac(spec->prev);
	if (xf(&spec->xf, n, av=xf_av(spec)) != n)
		return(-1);
	printf("%sMatrixTransform {\n", tabs);
	indent(1);
	printf("%s# xf", tabs);		/* put out original as comment */
	while (n--) {
		putchar(' ');
		fputs(*av++, stdout);
	}
	putchar('\n');			/* put out computed matrix */
	printf("%smatrix %13.9g %13.9g %13.9g %13.9g\n", tabs,
			spec->xf.xfm[0][0], spec->xf.xfm[0][1],
			spec->xf.xfm[0][2], spec->xf.xfm[0][3]);
	for (n = 1; n < 4; n++)
		printf("%s       %13.9g %13.9g %13.9g %13.9g\n", tabs,
				spec->xf.xfm[n][0], spec->xf.xfm[n][1],
				spec->xf.xfm[n][2], spec->xf.xfm[n][3]);
	indent(0);
	printf("%s}\n", tabs);
	return(0);
}
Exemplo n.º 15
0
bool GiGraphics::drawHermiteSplines(const GiContext* ctx, int count, const Point2d* knots,
                                    const Vector2d* knotvs, bool closed, bool modelUnit)
{
    if (count < 2 || !knots || !knotvs || isStopping())
        return false;
    count = mgMin(count, 0x1000);

    int i;
    Point2d pt;
    Vector2d vec;
    vector<Point2d> pxpoints;
    Matrix2d matD(S2D(xf(), modelUnit));
    Matrix2d mat2(matD / 3.f);

    pxpoints.resize(1 + (closed ? count : count - 1) * 3);
    Point2d *pxs = &pxpoints.front();

    pt = knots[0] * matD;                       // 第一个Bezier段的起点
    vec = knotvs[0] * mat2;                     // 第一个Bezier段的起始矢量
    *pxs++ = pt;                                // 产生Bezier段的起点
    for (i = 1; i < count; i++) {               // 计算每一个Bezier段
        *pxs++ = (pt += vec);                   // 产生Bezier段的第二点
        pt = knots[i] * matD;                   // Bezier段的终点
        vec = knotvs[i] * mat2;                 // Bezier段的终止矢量
        *pxs++ = pt - vec;                      // 产生Bezier段的第三点
        *pxs++ = pt;                            // 产生Bezier段的终点
    }
    if (closed) {
        *pxs++ = (pt += vec);                   // 产生Bezier段的第二点
        *pxs++ = 2 * pxpoints[0] - pxpoints[1].asVector();  // 产生Bezier段的第三点
        *pxs++ = pxpoints[0];                   // 产生Bezier段的终点
    }
    
    return rawBeziers(ctx, &pxpoints.front(), getSize(pxpoints), closed);
}
Exemplo n.º 16
0
bool GiGraphics::drawEllipse(const GiContext* ctx, const Point2d& center, 
                             float rx, float ry, bool modelUnit)
{
    if (rx < _MGZERO || isStopping())
        return false;
    
    bool ret = false;
    Matrix2d matD(S2D(xf(), modelUnit));

    if (ry < _MGZERO) {
        ry = (Vector2d(rx, rx) * matD).x;
        ry = fabsf((Vector2d(ry, ry) * matD.inverse()).y);
    }

    const Box2d extent (center, rx*2.f, ry*2.f);            // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    if (mgIsZero(matD.m12) && mgIsZero(matD.m21)) {
        Point2d cen (center * matD);
        rx *= fabsf(matD.m11);
        ry *= fabsf(matD.m22);
        ret = rawEllipse(ctx, cen.x - rx, cen.y - ry, 2 * rx, 2 * ry);
    } else {
        Point2d pxs[13];
        mgcurv::ellipseToBezier(pxs, center, rx, ry);
        matD.transformPoints(13, pxs);

        ret = rawBeziers(ctx, pxs, 13, true);
    }

    return ret;
}
Exemplo n.º 17
0
int
xf_handler(int ac, char **av)		/* handle xf entity */
{
	register XF_SPEC	*spec;
	register int	n;
	int	rv;

	if (ac == 1) {			/* something with existing transform */
		if ((spec = xf_context) == NULL)
			return(MG_ECNTXT);
		n = -1;
		if (spec->xarr != NULL) {	/* check for iteration */
			register struct xf_array	*ap = spec->xarr;

			(void)xf_aname((struct xf_array *)NULL);
			n = ap->ndim;
			while (n--) {
				if (++ap->aarg[n].i < ap->aarg[n].n)
					break;
				(void)strcpy(ap->aarg[n].arg, "0");
				ap->aarg[n].i = 0;
			}
			if (n >= 0) {
				if ((rv = mg_fgoto(&ap->spos)) != MG_OK)
					return(rv);
				sprintf(ap->aarg[n].arg, "%d", ap->aarg[n].i);
				(void)xf_aname(ap);
			}
		}
		if (n < 0) {			/* pop transform */
			xf_context = spec->prev;
			free_xf(spec);
			return(MG_OK);
		}
	} else {			/* else allocate transform */
		if ((spec = new_xf(ac-1, av+1)) == NULL)
			return(MG_EMEM);
		if (spec->xarr != NULL)
			(void)xf_aname(spec->xarr);
		spec->prev = xf_context;	/* push onto stack */
		xf_context = spec;
	}
					/* translate new specification */
	n = xf_ac(spec);
	n -= xf_ac(spec->prev);		/* incremental comp. is more eff. */
	if (xf(&spec->xf, n, xf_av(spec)) != n)
		return(MG_ETYPE);
					/* check for vertex reversal */
	if ((spec->rev = (spec->xf.sca < 0.)))
		spec->xf.sca = -spec->xf.sca;
					/* compute total transformation */
	if (spec->prev != NULL) {
		multmat4(spec->xf.xfm, spec->xf.xfm, spec->prev->xf.xfm);
		spec->xf.sca *= spec->prev->xf.sca;
		spec->rev ^= spec->prev->rev;
	}
	spec->xid = comp_xfid(spec->xf.xfm);	/* compute unique ID */
	return(MG_OK);
}
Exemplo n.º 18
0
bool GiCanvasGdi::drawImage(long hmWidth, long hmHeight, HBITMAP hbitmap, 
                            const Box2d& rectW, bool fast)
{
    BOOL ret = FALSE;
    HDC hdc = m_draw->getDrawDC();

    if (hdc != NULL && hmWidth > 0 && hmHeight > 0 && hbitmap != NULL
        && m_owner->getClipWorld().isIntersect(Box2d(rectW, true)))
    {
        RECT_2D clipBox;
        RECT rc, rcDraw, rcFrom;

        // rc: 整个图像对应的显示坐标区域
        (rectW * xf().worldToDisplay()).get(rc);

        // rcDraw: 图像经剪裁后的可显示部分
        Box2d(gs()->getClipBox(clipBox)).get(rcFrom);
        if (!IntersectRect(&rcDraw, &rc, &rcFrom))
            return false;

        long width, height;       // pixel units
        width = MulDiv(hmWidth, GetDeviceCaps(hdc, LOGPIXELSX), 2540);
        height = MulDiv(hmHeight, GetDeviceCaps(hdc, LOGPIXELSY), 2540);

        // rcFrom: rcDraw在原始图像上对应的图像范围
        rcFrom.left = MulDiv(rcDraw.left - rc.left, width, rc.right - rc.left);
        rcFrom.top = MulDiv(rcDraw.top - rc.top, height, rc.bottom - rc.top);
        rcFrom.right = MulDiv(rcDraw.right - rc.left, width, rc.right - rc.left);
        rcFrom.bottom = MulDiv(rcDraw.bottom - rc.top, height, rc.bottom - rc.top);

        // 根据rectW正负决定是否颠倒显示图像
        if (rectW.xmin > rectW.xmax)
            mgSwap(rcDraw.left, rcDraw.right);
        if (rectW.ymin > rectW.ymax)
            mgSwap(rcDraw.top, rcDraw.bottom);

        GiCompatibleDC memDC (hdc);
        if (memDC == NULL)
            return false;
        KGDIObject bmp (memDC, hbitmap, false);
        KGDIObject brush (hdc, ::GetStockObject(NULL_BRUSH), false);

        int nBltMode = (!fast || m_owner->isPrint()) ? HALFTONE : COLORONCOLOR;
        int nOldMode = ::SetStretchBltMode(hdc, nBltMode);
        ::SetBrushOrgEx(hdc, rcDraw.left % 8, rcDraw.top % 8, NULL);
        ret = ::StretchBlt(hdc, 
            rcDraw.left, rcDraw.top, 
            rcDraw.right - rcDraw.left, 
            rcDraw.bottom - rcDraw.top, 
            memDC, 
            rcFrom.left, rcFrom.top, 
            rcFrom.right - rcFrom.left, 
            rcFrom.bottom - rcFrom.top, 
            SRCCOPY);
        ::SetStretchBltMode(hdc, nOldMode);
    }

    return ret ? true : false;
}
Exemplo n.º 19
0
bool GiGraphics::drawHandle(const Point2d& pnt, int type, float angle, bool modelUnit)
{
    if (m_impl->canvas && type >= 0 && !m_impl->stopping && !pnt.isDegenerate()) {
        Point2d ptd(pnt * S2D(xf(), modelUnit));
        return m_impl->canvas->drawHandle(ptd.x, ptd.y, type, angle);
    }
    return false;
}
Exemplo n.º 20
0
bool GiGraphics::drawPath(const GiContext* ctx, const MgPath& path, bool fill, bool modelUnit)
{
    if (ctx && ctx->hasArrayHead() && path.getSubPathCount() == 1 && !path.isClosed()) {
        MgPath pathw(path);
        GiContext ctx2(*ctx);
        
        pathw.transform(S2D(xf(), modelUnit));
        
        ctx2.setNoFillColor();
        ctx2.setStartArrayHead(0);
        ctx2.setEndArrayHead(0);
        
        return drawPathWithArrayHead(ctx2, pathw, ctx->getStartArrayHead(), ctx->getEndArrayHead());
    }
    
    return drawPath_(ctx, path, fill, S2D(xf(), modelUnit));
}
Exemplo n.º 21
0
bool GiGraphics::drawClosedBSplines(const GiContext* ctx, 
                                    int count, 
                                    const Point2d* ctlpts, 
                                    bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 3 || ctlpts == NULL)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    count = mgMin(count, static_cast<int>((0x2000 - 1) / 3));

    const Box2d extent (count, ctlpts);              // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    int i;
    Point2d pt1, pt2, pt3, pt4;
    float d6 = 1.f / 6.f;
    vector<Point2d> pxpoints;
    Matrix2d matD(S2D(xf(), modelUnit));

    // 开辟整形像素坐标数组
    pxpoints.resize(1 + count * 3);
    Point2d *pxs = &pxpoints.front();

    // 计算第一个曲线段
    pt1 = ctlpts[0] * matD;
    pt2 = ctlpts[1] * matD;
    pt3 = ctlpts[2] * matD;
    pt4 = ctlpts[3 % count] * matD;
    (*pxs++).set((pt1.x + 4 * pt2.x + pt3.x)*d6, (pt1.y + 4 * pt2.y + pt3.y)*d6);
    (*pxs++).set((4 * pt2.x + 2 * pt3.x)    *d6, (4 * pt2.y + 2 * pt3.y)    *d6);
    (*pxs++).set((2 * pt2.x + 4 * pt3.x)    *d6, (2 * pt2.y + 4 * pt3.y)    *d6);
    (*pxs++).set((pt2.x + 4 * pt3.x + pt4.x)*d6, (pt2.y + 4 * pt3.y + pt4.y)*d6);

    // 计算其余曲线段
    for (i = 4; i < count + 3; i++)
    {
        pt1 = pt2;
        pt2 = pt3;
        pt3 = pt4;
        pt4 = ctlpts[i % count] * matD;
        (*pxs++).set((4 * pt2.x + 2 * pt3.x)    *d6, (4 * pt2.y + 2 * pt3.y)    *d6);
        (*pxs++).set((2 * pt2.x + 4 * pt3.x)    *d6, (2 * pt2.y + 4 * pt3.y)    *d6);
        (*pxs++).set((pt2.x + 4 * pt3.x + pt4.x)*d6, (pt2.y + 4 * pt3.y + pt4.y)*d6);
    }

    // 绘图
    bool ret = rawBeginPath();
    if (ret)
    {
        ret = rawMoveTo(pxs[0].x, pxs[0].y);
        ret = rawBezierTo(pxs + 1, getSize(pxpoints) - 1);
        ret = rawClosePath();
        ret = rawEndPath(ctx, true);
    }

    return ret;
}
Exemplo n.º 22
0
bool GiGraphics::beginPaint(GiCanvas* canvas, const RECT_2D& clipBox)
{
    if (!canvas || m_impl->canvas || isStopping()) {
        return false;
    }
    
    m_impl->canvas = canvas;
    m_impl->ctxused = 0;
    m_impl->stopping = 0;
    
    float phase = fabsf(m_impl->phase);
    m_impl->phase = (phase < 1e4f ? phase + 0.5f : 0.5f) * (m_impl->phase > 0 ? 1.f : -1.f);
    
    if (m_impl->lastZoomTimes != xf().getZoomTimes()) {
        m_impl->zoomChanged();
        m_impl->lastZoomTimes = xf().getZoomTimes();
    }
    
    m_impl->clipBox0 = clipBox;
    if (Box2d(clipBox).isEmpty()) {
        xf().getWndRect().get(m_impl->clipBox0);
    }
    m_impl->clipBox  = m_impl->clipBox0;
    m_impl->rectDraw = m_impl->clipBox0;
    m_impl->rectDraw.inflate(GiGraphicsImpl::CLIP_INFLATE);
    m_impl->rectDrawM = Box2d(m_impl->rectDraw) * xf().displayToModel();
    m_impl->rectDrawMaxM = xf().getWndRectM();
    m_impl->rectDrawW = m_impl->rectDrawM * xf().modelToWorld();
    m_impl->rectDrawMaxW = m_impl->rectDrawMaxM * xf().modelToWorld();
    
    return true;
}
Exemplo n.º 23
0
bool GiGraphics::drawHandle(const Point2d& pnt, int type, bool modelUnit)
{
    if (m_impl->canvas && type >= 0 && !m_impl->stopping) {
        Point2d ptd(pnt * S2D(xf(), modelUnit));
        m_impl->canvas->drawHandle(ptd.x, ptd.y, type);
        return true;
    }
    return false;
}
Exemplo n.º 24
0
bool GiGraphics::drawBeziers(const GiContext* ctx, int count, 
                             const Point2d* points, bool closed, bool modelUnit)
{
    if (count < 4 || !points || isStopping())
        return false;
    if (count > 0x2000)
        count = 0x2000;
    count = 1 + (count - 1) / 3 * 3;

    bool ret = false;
    vector<Point2d> pxpoints;
    vector<Point2d> pointBuf;
    int i, j, n, si, ei;
    Point2d * pxs;
    Matrix2d matD(S2D(xf(), modelUnit));

    const Box2d extent (count, points);                 // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;
    
    if (closed) {
        pxpoints.resize(count);
        pxs = &pxpoints.front();
        for (i = 0; i < count; i++)
            pxs[i] = points[i] * matD;
        ret = rawBeziers(ctx, pxs, count, closed);
    }
    else if (DRAW_MAXR(m_impl, modelUnit).contains(extent)) {   // 全部在显示区域内
        pxpoints.resize(count);
        pxs = &pxpoints.front();
        for (i = 0; i < count; i++)
            pxs[i] = points[i] * matD;
        ret = rawBeziers(ctx, pxs, count);
    } else {
        pointBuf.resize(count);
        for (i = 0; i < count; i++)                 // 转换到像素坐标
            pointBuf[i] = points[i] * matD;
        Point2d* pts = &pointBuf.front();

        for (i = 0; i + 3 < count;) {
            for (; i + 3 < count && !m_impl->rectDraw.isIntersect(Box2d(4, &pts[i])); i += 3) ;
            si = ei = i;
            for (; i + 3 < count && m_impl->rectDraw.isIntersect(Box2d(4, &pts[i])); i += 3)
                ei = i + 3;
            if (ei > si) {
                n = ei - si + 1;
                pxpoints.resize(n);
                pxs = &pxpoints.front();
                for (j=0; j<n; j++)
                    pxs[j] = pts[si + j];
                ret = rawBeziers(ctx, pxs, n);
            }
        }
    }
    return ret;
}
Exemplo n.º 25
0
bool GiGraphics::drawBeziers(const GiContext* ctx, int count, 
                             const Point2d* points, bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 4 || points == NULL)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    if (count > 0x2000)
        count = 0x2000;
    count = 1 + (count - 1) / 3 * 3;

    bool ret = false;
    vector<Point2d> pxpoints;
    vector<Point2d> pointBuf;
    int i, j, n, si, ei;
    Point2d * pxs;
    Matrix2d matD(S2D(xf(), modelUnit));

    const Box2d extent (count, points);                 // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    if (DRAW_MAXR(m_impl, modelUnit).contains(extent))  // 全部在显示区域内
    {
        pxpoints.resize(count);
        pxs = &pxpoints.front();
        for (i = 0; i < count; i++)
            pxs[i] = points[i] * matD;
        ret = rawBeziers(ctx, pxs, count);
    }
    else
    {        
        pointBuf.resize(count);
        for (i = 0; i < count; i++)                 // 转换到像素坐标
            pointBuf[i] = points[i] * matD;
        Point2d* pts = &pointBuf.front();

        si = ei = 0;
        for (i = 3; i < count; i += 3)
        {
            for ( ; i < count
                && m_impl->rectDraw.isIntersect(Box2d(4, &pts[ei])); i += 3)
                ei = i;
            n = ei - si + 1;
            if (n > 1)
            {
                pxpoints.resize(n);
                pxs = &pxpoints.front();
                for (j=0; j<n; j++)
                    pxs[j] = pts[si + j];
                ret = rawBeziers(ctx, pxs, n);
            }
            si = ei = i;
        }
    }
    return ret;
}
Exemplo n.º 26
0
/*static*/
GfMatrix4d
UsdImagingCubeAdapter::GetMeshTransform(UsdPrim const& prim, 
                                        UsdTimeCode time)
{
    double size = 2.0;
    UsdGeomCube cube(prim);
    TF_VERIFY(cube.GetSizeAttr().Get(&size, time));
    GfMatrix4d xf(GfVec4d(size, size, size, 1.0));
    return xf;
}
Exemplo n.º 27
0
/*static*/
GfMatrix4d
UsdImagingSphereAdapter::GetMeshTransform(UsdPrim const& prim, 
                                          UsdTimeCode time)
{
    double radius = 1.0;
    UsdGeomSphere sphere(prim);
    TF_VERIFY(sphere.GetRadiusAttr().Get(&radius, time));
    GfMatrix4d xf(GfVec4d(radius, radius, radius, 1.0));   
    return xf;
}
Exemplo n.º 28
0
bool GiGraphics::drawLines(const GiContext* ctx, int count, 
                           const Point2d* points, bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 2 || points == NULL)
        return false;
    if (count > 0x2000)
        count = 0x2000;
    GiLock lock (&m_impl->drawRefcnt);

    int i;
    Point2d pt1, pt2, ptLast;
    vector<Point2d> pxpoints;
    vector<Point2d> pointBuf;
    bool ret = false;
    Matrix2d matD(S2D(xf(), modelUnit));

    const Box2d extent (count, points);                 // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    if (DRAW_MAXR(m_impl, modelUnit).contains(extent))  // 全部在显示区域内
    {
        pxpoints.resize(count);
        Point2d* pxs = &pxpoints.front();
        int n = 0;
        for (i = 0; i < count; i++)
        {
            pt2 = points[i] * matD;
            if (i == 0 || fabs(pt1.x - pt2.x) > 2 || fabs(pt1.y - pt2.y) > 2)
            {
                pt1 = pt2;
                pxs[n++] = pt2;
            }
        }
        ret = rawLines(ctx, pxs, n);
    }
    else                                            // 部分在显示区域内
    {
        pointBuf.resize(count);
        for (i = 0; i < count; i++)                 // 转换到像素坐标
            pointBuf[i] = points[i] * matD;
        Point2d* pts = &pointBuf.front();

        ptLast = pts[0];
        PolylineAux aux(this, ctx);
        for (i = 0; i < count - 1; i++)
        {
            ret = DrawEdge(count, i, pts, ptLast, aux, m_impl->rectDraw) || ret;
        }
    }

    return ret;
}
Exemplo n.º 29
0
/*
 *	PIO data transfer routine using the scatter gather table.
 */
static void ide_scsi_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
				unsigned int bcount, int write)
{
	ide_hwif_t *hwif = drive->hwif;
	const struct ide_tp_ops *tp_ops = hwif->tp_ops;
	xfer_func_t *xf = write ? tp_ops->output_data : tp_ops->input_data;
	char *buf;
	int count;

	while (bcount) {
		count = min(pc->sg->length - pc->b_count, bcount);
		if (PageHighMem(sg_page(pc->sg))) {
			unsigned long flags;

			local_irq_save(flags);
			buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) +
					  pc->sg->offset;
			xf(drive, NULL, buf + pc->b_count, count);
			kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
			local_irq_restore(flags);
		} else {
			buf = sg_virt(pc->sg);
			xf(drive, NULL, buf + pc->b_count, count);
		}
		bcount -= count; pc->b_count += count;
		if (pc->b_count == pc->sg->length) {
			if (!--pc->sg_cnt)
				break;
			pc->sg = sg_next(pc->sg);
			pc->b_count = 0;
		}
	}

	if (bcount) {
		printk(KERN_ERR "%s: scatter gather table too small, %s\n",
				drive->name, write ? "padding with zeros"
						   : "discarding data");
		ide_pad_transfer(drive, write, bcount);
	}
}
Exemplo n.º 30
0
bool GiCanvasWin::beginPaint(HDC hdc, HDC attribDC, bool buffered, bool)
{
    if (m_owner->isDrawing() || hdc == NULL)
        return false;

    if (attribDC == hdc)
        attribDC = NULL;
    HDC prtDC = (attribDC != NULL) ? attribDC : hdc;
    if (::GetMapMode(prtDC) != MM_TEXT)
        return false;

    m_attribDC = attribDC;
    m_impl->drawColors = GetDeviceCaps(prtDC, NUMCOLORS);
    m_impl->xform->setResolution((float)GetDeviceCaps(prtDC, LOGPIXELSX), 
        (float)GetDeviceCaps(prtDC, LOGPIXELSY));
    m_impl->isPrint = (DT_RASDISPLAY != GetDeviceCaps(prtDC, TECHNOLOGY));
    if (m_impl->isPrint)
    {
        m_impl->xform->setWndSize(GetDeviceCaps(prtDC, HORZRES),
            GetDeviceCaps(prtDC, VERTRES));
    }
    else
    {
        m_attribDC = NULL;
    }

    RECT clipBox;

    if (m_owner->isPrint()
        || (buffered && !hasCachedBitmap())
        || ERROR == ::GetClipBox(hdc, &clipBox)
        || ::IsRectEmpty(&clipBox))
    {
        ::SetRect(&clipBox, 0, 0, xf().getWidth(), xf().getHeight());
    }

    m_owner->_beginPaint(giConvertRect(clipBox));

    return true;
}