Skip to content
OE_interfaceDisplay.cpp 27.5 KiB
Newer Older
/*
 * Copyright (c) 2015 Tricoire Sebastien 3dsman@free.fr
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not
 * claim that you wrote the original software. If you use this software
 * in a product, an acknowledgment in the product documentation would be
 * appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 * misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 *
 */

#include "OE_interfaceDisplay.h"
#include "OE_utils.h"

#include "OE_controller.h"

#include <iostream>
raoul's avatar
raoul committed
#include <qevent.h>
#include <GL/gl.h>
#include <cstdlib>
#include <math.h>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <QFileDialog>
#include "actions/OE_actionsCurves.h"
#include "actions/OE_actionsStitchs.h"
#include "actions/OE_actionsLineStitchs.h"
#include "actions/OE_actionsBirailStitchs.h"
3dsman's avatar
3dsman committed
#include "actions/OE_actionsFillStitchs.h"
#include "actions/OE_actionsSelection.h"
#include "actions/OE_actionsThreads.h"

raoul's avatar
raoul committed
static const GLuint TOOLSSELID = 0;
static const GLuint STITCHSSELID  = 1;
static const GLuint CURVESSELID = 2;
raoul's avatar
raoul committed
static const GLuint ZEROID  = 0;
static const GLuint TRANSTOOLID = 1;
static const GLuint MOVETOOLID = 0;
static const GLuint SCALETOOLID = 1;
raoul's avatar
raoul committed
OE_interfaceDisplay::OE_interfaceDisplay(QWidget *parent, Qt::WindowFlags f) : OE_display(parent, f)
	editStyle = new OE_display::OE_displayStyle();
	commandStyle = new OE_display::OE_displayStyle();
	commandStyle->drawGrid = false;
	commandStyle->drawCurves = false;
	commandStyle->drawStitches = false;
	commandStyle->drawCommands = true;
raoul's avatar
raoul committed
	setDocument(nullptr);
	modState = Qt::KeyboardModifier::NoModifier;
}

OE_interfaceDisplay::~OE_interfaceDisplay()
{
raoul's avatar
raoul committed
bool OE_interfaceDisplay::setDocument(OE_document* document)
raoul's avatar
raoul committed
	return true;
OE_document* OE_interfaceDisplay::getDocument()
{
    return document;
}

OE_controller* OE_interfaceDisplay::getController()
{
    return controller;
}


bool OE_interfaceDisplay::setController(OE_controller* controller)
{
raoul's avatar
raoul committed
	return true;
raoul's avatar
raoul committed
bool OE_interfaceDisplay::mouse_Pos(double x, double y)
raoul's avatar
raoul committed
	bool redraw = false;
	redraw |= OE_display::mouse_Pos(x, y);
	vector_2dt oldClosestPoint = editClosestPoint;
raoul's avatar
raoul committed
	vector_2d absMove = vector_2d((mouse.x - clicOldMouse.x)*zoom*2, (mouse.y - clicOldMouse.y)*zoom*2);
raoul's avatar
raoul committed
	if (editionState == MoveSelection) //if the move action is enabled
raoul's avatar
raoul committed
		controller->editActionMoveSelection(vector_2d((mouse.x - clicOldMouse.x)*zoom*2,
		                                              (mouse.y - clicOldMouse.y)*zoom*2));
raoul's avatar
raoul committed
		return true;
raoul's avatar
raoul committed
	if (editionState == ScaleSelection) //if the scale action is enabled
	{
		vector_2d bbCenter = controller->getSelectionBoundingBox().getCenter();
		float scale = (absMouse-bbCenter).len()/(screenToDocument(clicOldMouse)-bbCenter).len();
        controller->editActionScaleSelection(vector_2d(scale,scale));
        emit refreshStitchList();
raoul's avatar
raoul committed
		return true;
	if (editionState == NewSubcurve) //if we must find the closest subcurve (get the closest point on it too)
	{
		closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
raoul's avatar
raoul committed
		redraw = true;
	}
	else if (editSubcurve) //if we are working on a defined subcurve get the closest point on it
raoul's avatar
raoul committed
	{
		editClosestPoint = controller->getClosestPoint(editSubcurve->getCurve(), absMouse);
raoul's avatar
raoul committed
		redraw = true;
raoul's avatar
raoul committed
	}
	if (editionState == MovePointcurve && selControlCurve && selControlType==0) //if we're moving a curve control point
raoul's avatar
raoul committed
		controller->editActionMovePointCurve(vector_2d((mouse.x - clicOldMouse.x)*zoom*2,
		                                               (mouse.y - clicOldMouse.y)*zoom*2));
raoul's avatar
raoul committed
		return true;
	if (editionState == MovePointstitch) //if we're moving a linkstitch control point
	{
		controller->editActionMovePointLinkStitch(absMove);
        controller->editActionMoveGridPointFillStitch(absMove);
        emit refreshStitchList();
        return true;

	//if we're editing the scaleWidth of a linestitch
	if (editionState == OffsetWidthLinestitch)
raoul's avatar
raoul committed
	{
		controller->editActionSetLinestitchWidth((mouse.x - clicOldMouse.x)/100.0f, true);
raoul's avatar
raoul committed
		return true;
	//if we're define a new subcurve and the reference curve is already picked
	if ((editionState == NewSubcurve)&&(selControlStitch))
	{
		editionState = TraceSubcurve;
		if (oldClosestPoint.t>editClosestPoint.t) controller->editActionAddSubcurvePosSwitchDir();
        redraw = true;
        emit refreshStitchList();
	}

	if (editionState == TraceSubcurve)
	{
        controller->editActionAddSubcurvePosEnd(editClosestPoint.t);
        redraw = true;
        emit refreshStitchList();
	}
	else if (editionState == MoveSubcurve)
	{
		controller->editActionSetSubcurvePos(editClosestPoint.t);
        redraw = true;
        emit refreshStitchList();
    }

raoul's avatar
raoul committed
	return redraw;
raoul's avatar
raoul committed
bool OE_interfaceDisplay::mouse_Button(QMouseEvent* event)
raoul's avatar
raoul committed
	bool redraw = false;
	redraw |= OE_display::mouse_Button(event);
	if (curScreen == edit && event->button() == Qt::LeftButton && event->type() == QEvent::MouseButtonPress)
raoul's avatar
raoul committed
		redraw = true;
raoul's avatar
raoul committed
		if (editionState == NewSubcurve)
		{
			if (!closestCurve)
raoul's avatar
raoul committed
			else
			{
				controller->addAction(new OE_actionJoincurveAddSubCurve(document, curJoincurve, subcurve_id, closestCurve,
raoul's avatar
raoul committed
				                                                        editClosestPoint.t, editClosestPoint.t,
Loading full blame...