Newer
Older
/*
* This file is part of project OpenEmbroidery. It's copyrighted by
* the contributors recorded in the version control history of the file.
* Original project location https://code.electrolab.fr/openEmbroidery/openEmbroidery_software
*
* SPDX-License-Identifier: CECILL-2.1
* License-Filename: Licence_CeCILL_V2.1-en.txt
*/
#include "OE_interfaceDisplay.h"
#include "OE_utils.h"
#include "OE_preferences.h"
#include "OE_controller.h"
#include <iostream>
#include <GL/gl.h>
#include <cstdlib>
#include <math.h>
#include <cstdio>
#include <cstring>
#include "actions/OE_actionsCurves.h"
#include "actions/OE_actionsStitchs.h"
#include "actions/OE_actionsLineStitchs.h"
#include "actions/OE_actionsBirailStitchs.h"
3dsman
committed
#include "actions/OE_actionsLinkStitchs.h"
#include "actions/OE_actionsSelection.h"
#include "actions/OE_actionsThreads.h"
OE_interfaceDisplay::OE_interfaceDisplay(QWidget *parent, Qt::WindowFlags f) : OE_display(parent, f)
{
addDisplayStyle();
setDisplayStyle(0);
modState = Qt::KeyboardModifier::NoModifier;
}
OE_interfaceDisplay::~OE_interfaceDisplay()
{
//delete curDisplay;
}
bool OE_interfaceDisplay::setDocument(OE_document* document)
{
this->document = document;
}
OE_document* OE_interfaceDisplay::getDocument()
{
return document;
}
OE_controller* OE_interfaceDisplay::getController()
{
return controller;
}
bool OE_interfaceDisplay::setController(OE_controller* controller)
{
this->controller = controller;
}
bool OE_interfaceDisplay::setDisplayStyle(unsigned int displayStyleId)
{
if (displayStyles.size()>displayStyleId)
{
OE_display::setDisplayStyle(displayStyles[displayStyleId]);
emit styleChange();
return true;
}
return false;
}
OE_display::OE_displayStyle* OE_interfaceDisplay::addDisplayStyle()
{
OE_display::OE_displayStyle* displayStyle = new OE_display::OE_displayStyle();
displayStyles.push_back(displayStyle);
return displayStyle;
}
void OE_interfaceDisplay::showAll()
{
OE_display::showAll();
}
{
bool redraw = false;
redraw |= OE_display::mouse_Pos(x, y);
vector_2dt oldClosestPoint = editClosestPoint;
vector_2d absMove = vector_2d((mouse.x - clicOldMouse.x)*zoom*2, (mouse.y - clicOldMouse.y)*zoom*2);
if (editionState == MoveSelection) //if the move action is enabled
controller->editActionMoveSelection(vector_2d((mouse.x - clicOldMouse.x)*zoom*2,
(mouse.y - clicOldMouse.y)*zoom*2));
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();
if (editionState == NewSubcurve) //if we must find the closest subcurve (get the closest point on it too)
{
closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
redraw = true;
}
else if (editSubcurve) //if we are working on a defined subcurve get the closest point on it
{
editClosestPoint = controller->getClosestPoint(editSubcurve->getCurve(), absMouse);
if (editionState == MovePointcurve && selControlCurve && selControlType==0) //if we're moving a curve control point
controller->editActionMovePointCurve(vector_2d((mouse.x - clicOldMouse.x)*zoom*2,
(mouse.y - clicOldMouse.y)*zoom*2));
3dsman
committed
if (editionState == MovePointstitch) //if we're moving a linkstitch control point
{
controller->editActionMovePointLinkStitch(absMove);
controller->editActionMoveGridPointFillStitch(absMove);
emit refreshStitchList();
return true;
3dsman
committed
}
//if we're editing the scaleWidth of a linestitch
if (editionState == OffsetWidthLinestitch)
controller->editActionSetLinestitchWidth((mouse.x - clicOldMouse.x)/100.0f, 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();
}
}
{
bool redraw = false;
redraw |= OE_display::mouse_Button(event);
if (event->button() == Qt::LeftButton && event->type() == QEvent::MouseButtonPress)
if (editionState == NewSubcurve)
{
if (!closestCurve)
{
editionState = None;
}
controller->addAction(new OE_actionJoincurveAddSubCurve(document, curJoincurve, subcurve_id, closestCurve,
selControlStitch = controller->getStitch(-1);
selControlType = 0;
//editSubcurve = curJoincurve->getCurve(-1);
editSubcurve = curJoincurve->getCurve(subcurve_id);
Loading full blame...