예제 #1
0
파일: align.cpp 프로젝트: PNCG/neuron
void AlignToGridCmd::Align (GraphicView* gv, float refx, float refy) {
    MoveData* md = (MoveData*) Recall(gv->GetGraphicComp());

    if (md == nil) {
        Viewer* v = gv->GetViewer();
        Grid* grid = (v == nil) ? nil : v->GetGrid();

        if (grid == nil) {
            return;
        }

        Graphic* g = gv->GetGraphic();
        Transformer t;
        g->Parent()->TotalTransformation(t);
        t.Invert();

        Coord cx = iv26_round(refx);
        Coord cy = iv26_round(refy);

        grid->Constrain(cx, cy);

        float dx, dy, trefx, trefy;

        t.Transform(float(cx), float(cy), dx, dy);
        t.Transform(refx, refy, trefx, trefy);

        dx -= trefx;
        dy -= trefy;
        Store(gv->GetGraphicComp(), new MoveData(dx, dy));

    }
    Move(gv->GetGraphicComp());
}
예제 #2
0
파일: rasterrect.cpp 프로젝트: PNCG/neuron
bool RasterRect::intersects (BoxObj& userb, Graphic* gs) {
    Transformer* t = gs->GetTransformer();
    Coord xmax = _raster->Width();
    Coord ymax = _raster->Height();
    Coord tx0, ty0, tx1, ty1;
    
    if (t != nil && t->Rotated()) {
	Coord x[4], tx[5];
	Coord y[4], ty[5];
    
	x[0] = x[3] = y[0] = y[1] = 0;
	x[2] = x[1] = xmax;
	y[2] = y[3] = ymax;
	transformList(x, y, 4, tx, ty, gs);
	tx[4] = tx[0];
	ty[4] = ty[0];
	FillPolygonObj fp (tx, ty, 5);
	return fp.Intersects(userb);
    
    } else if (t != nil) {
	t->Transform(0, 0, tx0, ty0);
	t->Transform(xmax, ymax, tx1, ty1);
	BoxObj b1 (tx0, ty0, tx1, ty1);
	return b1.Intersects(userb);

    } else {
	BoxObj b2 (0, 0, xmax, ymax);
	return b2.Intersects(userb);
    }
}
예제 #3
0
void Graphic::transform (Coord& x, Coord& y, Graphic* g) {
    Transformer* t = (g == nil) ? GetTransformer() : g->GetTransformer();

    if (t != nil) {
        t->Transform(x, y);
    }
}
예제 #4
0
파일: link.c 프로젝트: barak/ivtools-cvs
LinkComp::LinkComp (Line* line) {
    if (line != nil) {
        Coord x0, y0, x1, y1;
        float fx0, fy0, fx1, fy1;

        line->GetOriginal(x0, y0, x1, y1);
        Transformer* t = line->GetTransformer();
        Graphic* parent = new Picture(line);
        parent->SetTransformer(nil);

        if (t == nil) {
            fx0 = x0; fy0 = y0; fx1 = x1; fy1 = y1;
        } else {
            t->Transform(float(x0), float(y0), fx0, fy0);
            t->Transform(float(x1), float(y1), fx1, fy1);
        }
        delete line;
        line = new Line(0, 0, 1, 1);
        InitLine(line, fx0, fy0, fx1, fy1);

        PinGraphic* pg1 = new PinGraphic;
        PinGraphic* pg2 = new PinGraphic;
        pg1->SetBrush(psnonebr);
        pg2->SetBrush(psnonebr);
        pg1->Translate(fx0, fy0);
        pg2->Translate(fx1, fy1);

        _conn1 = new PinComp(pg1);
        _conn2 = new PinComp(pg2);

        parent->Append(line, pg1, pg2);
        SetGraphic(parent);
    }
}
예제 #5
0
파일: line.cpp 프로젝트: PNCG/neuron
void LineView::GetEndpoints (Coord& x0, Coord& y0, Coord& x1, Coord& y1) {
    Line* line = (Line*) GetGraphic();
    Transformer t;

    line->GetOriginal(x0, y0, x1, y1);
    line->TotalTransformation(t);
    t.Transform(x0, y0);
    t.Transform(x1, y1);
}
예제 #6
0
void Graphic::transform (float x, float y, float& tx, float& ty, Graphic* g) {
    Transformer* t = (g == nil) ? GetTransformer() : g->GetTransformer();

    if (t != nil) {
        t->Transform(x, y, tx, ty);
    } else {
        tx = x;
        ty = y;
    }
}
예제 #7
0
void Graphic::transform (Coord x, Coord y, Coord& tx, Coord& ty, Graphic* g) {
    Transformer* t = (g == nil) ? GetTransformer() : g->GetTransformer();

    if (t != nil) {
        t->Transform(x, y, tx, ty);
    } else {
        tx = x;
        ty = y;
    }
}
예제 #8
0
boolean Vertices::GetPoint (int index, Coord& px, Coord& py) {
    if (index<0 || index>=count()) return false;
    Coord tx, ty;
    Transformer t;
    tx = x()[index];
    ty = y()[index];
    TotalTransformation(t);
    t.Transform(tx, ty, px, py);
    return true;
}
예제 #9
0
TextOvComp::TextOvComp(istream& in, OverlayComp* parent) 
: OverlayComp(nil, parent) {
    _valid = GetParamList()->read_args(in, this); 

    /* correct font vertical position */
    PSFont* f = _gr->GetFont();
    float sep = 1 - (f ? f->GetLineHt() : 0);
    Transformer* t = _gr->GetTransformer();
    float dx = 0., dy = sep;

    if (t != nil) {
        float x0, y0, x1, y1;
        t->Transform(0., 0., x0, y0);
        t->Transform(0., sep, x1, y1);
        dx = x1 - x0;
        dy = y1 - y0;
    }
    _gr->Translate(dx, dy);
}
예제 #10
0
void TextView::Interpret (Command* cmd) {
    if (cmd->IsA(ALIGNTOGRID_CMD)) {
        Transformer total;
        GetGraphic()->TotalTransformation(total);

        float tx0, ty0;
        total.Transform(0., 0., tx0, ty0);
        ((AlignToGridCmd*) cmd)->Align(this, tx0, ty0);

    } else {
        GraphicView::Interpret(cmd);
    }
}
예제 #11
0
파일: line.cpp 프로젝트: PNCG/neuron
void LineView::Interpret (Command* cmd) {
    if (cmd->IsA(ALIGNTOGRID_CMD)) {
        Line* line = (Line*) GetGraphic();
        Transformer total;
        line->TotalTransformation(total);

        Coord x0, y0, x1, y1;
        float tx0, ty0;

        line->GetOriginal(x0, y0, x1, y1);
        total.Transform(float(x0), float(y0), tx0, ty0);
        ((AlignToGridCmd*) cmd)->Align(this, tx0, ty0);

    } else {
        GraphicView::Interpret(cmd);
    }
}
예제 #12
0
void PadView::Interpret (Command* cmd) {
    if (cmd->IsA(ALIGNTOGRID_CMD)) {
        PadGraphic* padg = (PadGraphic*) GetGraphic();
        Transformer total;
        padg->TotalTransformation(total);

        Coord x0, y0, x1, y1;
        float tx0, ty0;

        padg->GetOriginal(x0, y0, x1, y1);
        total.Transform(float(x0), float(y0), tx0, ty0);
        ((AlignToGridCmd*) cmd)->Align(this, tx0, ty0);

    } else {
        ConnectorView::Interpret(cmd);
    }
}
예제 #13
0
파일: splines.cpp 프로젝트: PNCG/neuron
bool SFH_ClosedBSpline::intersects (BoxObj& userb, Graphic* gs) {
    PointObj po;
    const Coord *x, *y;
    int count = GetOriginal(x, y);
    Transformer* t = gs->GetTransformer();

    for (int i = 0; i < count; i++) {
	po._x = x[i];
	po._y = y[i];

        if (t != nil) {
            t->Transform(po._x, po._y);
        }
	if (userb.Contains(po)) {
            return true;
        }
    }
    return SF_ClosedBSpline::intersects(userb, gs);
}
예제 #14
0
void Graphic::Align (Alignment falign, Graphic* moved, Alignment malign) {
    float fx0, fy0, fx1, fy1, mx0, my0, mx1, my1, dx = 0, dy = 0;

    GetBounds(fx0, fy0, fx1, fy1);
    moved->GetBounds(mx0, my0, mx1, my1);

    switch (falign) {
    case BottomLeft:
    case CenterLeft:
    case TopLeft:
    case Left:
        dx = fx0;
        break;
    case BottomCenter:
    case Center:
    case TopCenter:
    case HorizCenter:
        dx = (fx0 + fx1 + 1)/2;
        break;
    case BottomRight:
    case CenterRight:
    case TopRight:
    case Right:
        dx = fx1 + 1;
        break;
    }
    switch (falign) {
    case BottomLeft:
    case BottomCenter:
    case BottomRight:
    case Bottom:
        dy = fy0;
        break;
    case CenterLeft:
    case Center:
    case CenterRight:
    case VertCenter:
        dy = (fy0 + fy1 + 1)/2;
        break;
    case TopLeft:
    case TopCenter:
    case TopRight:
    case Top:
        dy = fy1 + 1;
        break;
    }

    switch (malign) {
    case BottomLeft:
    case CenterLeft:
    case TopLeft:
    case Left:
        dx -= mx0;
        break;
    case BottomCenter:
    case Center:
    case TopCenter:
    case HorizCenter:
        dx -= (mx0 + mx1 + 1)/2;
        break;
    case BottomRight:
    case CenterRight:
    case TopRight:
    case Right:
        dx -= (mx1 + 1);
        break;
    }
    switch (malign) {
    case BottomLeft:
    case BottomCenter:
    case BottomRight:
    case Bottom:
        dy -= my0;
        break;
    case CenterLeft:
    case Center:
    case CenterRight:
    case VertCenter:
        dy -= (my0 + my1 + 1)/2;
        break;
    case TopLeft:
    case TopCenter:
    case TopRight:
    case Top:
        dy -= (my1 + 1);
        break;
    }
    if (dx != 0 || dy != 0) {
        Transformer parents;
        moved->parentXform(parents);

        parents.Invert();
        parents.Transform(0.0, 0.0, fx0, fy0);
        parents.Transform(dx, dy, mx0, my0);

        moved->Translate(mx0-fx0, my0-fy0);
    }
}
예제 #15
0
void TextFileComp::Init() {

    /* read in the text from begstr to endstr */
    FILE* fptr = fopen(_pathname, "r");
    char *buffer;

    if (_linewidth == 0) {
	buffer = new char[1];
	buffer[0] = '\0';
	fclose (fptr);
	return;
    }
    if (!fptr) {
	buffer = new char[1];
	buffer[0] = '\0';
    } else {
	char inbuf[BUFSIZ];
        int nsub;
	buffer = new char[BUFSIZ];
	
	int bufsiz = BUFSIZ;
	int buflen = 0;

	fgets( inbuf, BUFSIZ, fptr);
	if (_begstr) 
	    while (!feof(fptr) && strncmp(_begstr, inbuf, strlen(_begstr)) != 0) 
		fgets( inbuf, BUFSIZ, fptr);

	int len;
	int nc = 0;
        int wordc = 0;
	char* wordbuf;
	char c;

	/* loop until eof or endstr is found */
	while (!feof(fptr) && (_endstr ? strncmp(_endstr, inbuf, strlen(_endstr)) != 0 : true)) {
	    len = strlen(inbuf);
            if (_linewidth > -1) 
	       nsub = len / _linewidth;
	    else 
	       nsub = 0;

	    /* double buffer length if needed */
	    if (buflen+len+nsub >= bufsiz) {
		bufsiz *= 2;
		char* newbuffer = new char[bufsiz];
		strcpy( newbuffer, buffer );
		delete buffer;
		buffer = newbuffer;
	    }

	    if (_linewidth > -1) {
		wordbuf = new char[len+nsub+1];

	        for (int i = 0; i < len; i++) {
	            c = inbuf[i];
		    ++nc;
		    if (c == ' ' || c == '\t' || c == '\n') {
			if (nc > _linewidth+1) {
			    strcpy(buffer+buflen, "\n");
	       		    ++buflen;
			    if (c == '\n' && nc > 1 ) {
			        wordbuf[wordc] = ' ';
			    } else {
			        wordbuf[wordc] = c;
                            }
			    wordbuf[wordc+1] = '\0';
			    nc = strlen(wordbuf);
			    wordc = 0;
			    strcpy(buffer+buflen, wordbuf);
	       		    buflen += strlen(wordbuf);
			
			} else {
			    if (c == '\n' && nc > 1 && i > 0) {
			        wordbuf[wordc] = ' ';
			        wordbuf[wordc+1] = '\0';
			    } else if (c == '\n' && i == 0) {
			        wordbuf[wordc] = c;
			        wordbuf[wordc+1] = c;
			        wordbuf[wordc+2] = '\0';
				nc = 0;
			    } else {
			        wordbuf[wordc] = c;
			        wordbuf[wordc+1] = '\0';
                            }
			    wordc = 0;
			    if (buffer[buflen-1] != ' ' || wordbuf[0] != ' ') {
				strcpy(buffer+buflen, wordbuf);
				buflen += strlen(wordbuf); 
			    } else {
				strcpy(buffer+buflen, wordbuf+1);
				buflen += strlen(wordbuf) - 1; 
			    }
			}
		    
		    } else {
			if (c=='\\') {
			    c = inbuf[++i];
			    if (isdigit(c)) {
				char buf[4];
				buf[0] = c; 
				buf[1] = buf[2] = buf[3] = '\0';
				if (isdigit(inbuf[i+1])) {
				    buf[1] = inbuf[++i];
				    if (isdigit(inbuf[i+1])) {
					buf[2] = inbuf[++i];
				    }
				}
				c = ParamList::octal(buf);
			    }
			} 
			wordbuf[wordc] = c;
			++wordc;
		    }
	        }
	        delete wordbuf;
	    
	    } else {
                strcpy(buffer+buflen, inbuf);
	        buflen += strlen(inbuf);
            }
	    fgets( inbuf, BUFSIZ, fptr);
	}
	/* done looping until eof or endstr is found */
    }

    fclose(fptr);

    /* setup the graphic */
    ((TextGraphic*)_gr)->SetOriginal(buffer);
    delete buffer;

    /* correct font vertical position */
    PSFont* f = _gr->GetFont();
    float sep = 1 - f->GetLineHt();
    Transformer* t = _gr->GetTransformer();
    float dx = 0., dy = sep;

    if (t != nil) {
        float x0, y0, x1, y1;
        t->Transform(0., 0., x0, y0);
        t->Transform(0., sep, x1, y1);
        dx = x1 - x0;
        dy = y1 - y0;
    }
    _gr->Translate(dx, dy);

}