Exemplo n.º 1
0
void MouseHandler::Build2DEllipse(string nameOfAlgo, IEllipsoidBuilder* builder, bool toDraw)
{
	Window* window = Window::Create();
	if (toDraw == true && (nameOfAlgo != Rublev && nameOfAlgo != Petunin)) toDraw = false;

	if (window->vertexes->size() < 3) return;
	Ellipsoid2D* el;

	vector<Point2D>* conv = NULL;
	if (nameOfAlgo == GeneticMatrix || nameOfAlgo == Khachiyan) conv = ConvHull(*window->vertexes);

	vector<Point2D> points;
	if (conv != NULL) points = (*conv);
	else points = *window->vertexes;

	if (toDraw) el = builder->Exec(points, window);
	else el = builder->Exec(points);

	DrawEvent* draw = new DrawEvent();
	draw->add(window->vertexes);
	if (el != NULL)
	{
		el->SetColor(Color(0.0f, 1.0f, 0.0f));
		draw->add(1, el);
	}
	window->AddNewDrawEvent(draw);
	delete draw; draw = NULL;

	WriteResultsToFile("Resources/Output Data.txt", nameOfAlgo, el);

	delete el; el = NULL;
}
Exemplo n.º 2
0
void MouseHandler::AddVertex(Point2D & p)
{
	Window* window = Window::Create();
	window->vertexes->push_back(p);
	DrawEvent* draw = new DrawEvent();
	draw->add(1, &p);
	window->AddNext(draw);
	delete draw;
	draw = NULL;
}
Exemplo n.º 3
0
void MouseHandler::ReadVertexesFromFile()
{
	Window* window = Window::Create();
	if (window->vertexes != NULL)
	{
		if (!window->vertexes->empty()) window->vertexes->clear();
		delete window->vertexes;
		window->vertexes = NULL;
	}
	window->clear();
	window->vertexes = Helper::ReadPoints("Resources/Input Data.txt");
	DrawEvent* draw = new DrawEvent();
	draw->add(window->vertexes);
	window->AddNext(draw);
	delete draw;
	draw = NULL;
}
Exemplo n.º 4
0
void CircleCreateOperation::on_drawEvent(const DrawEvent& event) {
    bool s = property("hasStartPoint").toBool();
    bool e = property("hasEndPoint").toBool();

    // For drawing we should create a interface to teh drawitems in the viewer so we always
    // draw something exactly like how the final drawing classes will draw entities
    if (s == true && e == false) {
        event.painter()->drawLine(_startPoint.pointF(), _lastSnapEvent.snapPoint().pointF());
        double r = (lc::geo::Coordinate(_startPoint) - lc::geo::Coordinate(_lastSnapEvent.snapPoint())).magnitude();
        event.painter()->drawEllipse(_startPoint.pointF(), r, r);
    }

    if (s == true && e == true) {
        double r = (lc::geo::Coordinate(_startPoint) - lc::geo::Coordinate(_endPoint)).magnitude();
        event.painter()->drawEllipse(_startPoint.pointF(), r, r);
    }

}
Exemplo n.º 5
0
void DragPoints::onDraw(DrawEvent const &event) const {
	double x = _size;
	double y = _size;

	double zeroCornerX = 0.;
	double zeroCornerY = 0.;

	event.painter().device_to_user(&zeroCornerX, &zeroCornerY);
	event.painter().device_to_user(&x, &y);

	double size = (x - zeroCornerX);

	event.painter().source_rgb(255, 255, 255);

	for(auto point : _points) {
		event.painter().rectangle(point.x() - size / 2, point.y() - size / 2, size, size);
	}
	event.painter().stroke();
}
Exemplo n.º 6
0
void Grid::draw(DrawEvent const & event) const {
    LcPainter &painter = event.painter();
    const lc::geo::Area &updateRect = event.updateRect();

    painter.save();
    painter.disable_antialias();
    double zeroCornerX = 0.;
    double zeroCornerY = 0.;
    painter.device_to_user(&zeroCornerX, &zeroCornerY);

    double gridSPacingX = _minimumGridSpacing;
    double gridSPacingY = _minimumGridSpacing;
    painter.device_to_user(&gridSPacingX, &gridSPacingY);

    // This brings the distance always between 10 and 100, need to have some math behind this
    double minDistancePoints = gridSPacingX - zeroCornerX;
    double factor = 1.0;

    while (minDistancePoints < 10.0 * (1/_convUnit)) {
        minDistancePoints *= 10.0 * (1/_convUnit);
        factor = factor * 10.0 * (1/_convUnit);
    }

    while (minDistancePoints > 100.0 * (1/_convUnit)) {
        minDistancePoints = minDistancePoints / 10.0 * (1/_convUnit);
        factor = factor / 10.0 * (1/_convUnit);
    }

    // determine the grid spacing
    double gridSize;

    if (minDistancePoints < 10.0 * (1/_convUnit)) {
        gridSize = (10.0 * (1/_convUnit) / factor);
    } else if (minDistancePoints < 20.0 * (1/_convUnit)) {
        gridSize = (20.0 * (1/_convUnit) / factor);
    } else if (minDistancePoints < 50.0 * (1/_convUnit)) {
        gridSize = (50.0  * (1/_convUnit) / factor);
    } else {
        gridSize = (100.0  * (1/_convUnit) / factor);
    }

    // TODO: THis assignedment doesn't make the grid thread save!!!
    // We have to fix that somehow or get rid of the snapPoints method
    // Risck might be very low because the mouse can snap to one display anyways assuming we use one mouse per computer :s
    _lastGridSize = gridSize;

    // Major lines
    double left = updateRect.minP().x() - fmod(updateRect.minP().x(), gridSize);
    double top = updateRect.maxP().y() - fmod(updateRect.maxP().y(), gridSize);

    painter.line_width(1);
    for (double x = left; x < updateRect.maxP().x(); x += gridSize) {
        painter.move_to(x, updateRect.maxP().y());
        painter.line_to(x, updateRect.minP().y());
    }

    for (double y = top; y > updateRect.minP().y(); y -= gridSize) {
        painter.move_to(updateRect.minP().x(), y);
        painter.line_to(updateRect.maxP().x(), y);
    }

    painter.source_rgba(_majorColor.red(), _majorColor.green(), _majorColor.blue(), _majorColor.alpha());
    painter.stroke();

    // Draw minor lines
    gridSize *= _numMinorLines;
    left = updateRect.minP().x() - fmod(updateRect.minP().x(), gridSize);
    top = updateRect.maxP().y() - fmod(updateRect.maxP().y(), gridSize);

    for (double x = left; x < updateRect.maxP().x(); x += gridSize) {
        painter.move_to(x, updateRect.maxP().y());
        painter.line_to(x, updateRect.minP().y());
    }

    for (double y = top; y > updateRect.minP().y(); y -= gridSize) {
        painter.move_to(updateRect.minP().x(), y);
        painter.line_to(updateRect.maxP().x(), y);
    }

    painter.source_rgba(_minorColor.red(), _minorColor.green(), _minorColor.blue(), _minorColor.alpha());
    painter.stroke();
    painter.restore();
}
Exemplo n.º 7
0
void Cursor::on_Draw_Event(const DrawEvent& event) {

    double zeroCornerX = 0.;
    double zeroCornerY = 0.;
    event.painter()->device_to_user(&zeroCornerX, &zeroCornerY);

    double gridSPacingX = _cursorSize;
    double gridSPacingY = _cursorSize;
    event.painter()->device_to_user(&gridSPacingX, &gridSPacingY);

    double minDistancePoints = (gridSPacingX - zeroCornerX) / 2.0;

    double x, y;

    // If we had a snao point, move the mouse to that area
    if (_lastSnapEvent.status() == true) {
        x = _lastSnapEvent.snapPoint().x();
        y = _lastSnapEvent.snapPoint().y();
    } else {
        x = event.mousePosition().x();
        y = event.mousePosition().y();
    }

    event.painter()->save();
    event.painter()->disable_antialias();

    event.painter()->move_to(-minDistancePoints + x, y);
    event.painter()->line_to(minDistancePoints + x, y);
    event.painter()->source_rgba(_xAxisColor.redF(), _xAxisColor.greenF(), _xAxisColor.blueF(), _xAxisColor.alphaF());
    event.painter()->stroke();

    event.painter()->move_to(x, -minDistancePoints + y);
    event.painter()->line_to(x, minDistancePoints + y);
    event.painter()->source_rgba(_yAxisColor.redF(), _yAxisColor.greenF(), _yAxisColor.blueF(), _yAxisColor.alphaF());
    event.painter()->stroke();


    event.painter()->restore();

}