|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/tool.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tthreadmessage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstroke.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tmathutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/cursors.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tproperty.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/imageutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tcolumnhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tobjecthandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheethandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tstageobject.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/stage2.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tenv.h"
|
|
Toshihiro Shimizu |
890ddd |
// For Qt translation support
|
|
Toshihiro Shimizu |
890ddd |
#include <qcoreapplication></qcoreapplication>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace ToolUtils;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define POINT2POINT L"Endpoint to Endpoint"
|
|
Toshihiro Shimizu |
890ddd |
#define POINT2LINE L"Endpoint to Line"
|
|
Toshihiro Shimizu |
890ddd |
#define LINE2LINE L"Line to Line"
|
|
Toshihiro Shimizu |
890ddd |
#define NORMAL L"Normal"
|
|
Toshihiro Shimizu |
890ddd |
#define RECT L"Rectangular"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEnv::StringVar TapeMode("InknpaintTapeMode1", "Endpoint to Endpoint");
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar TapeSmooth("InknpaintTapeSmooth", 0);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::IntVar TapeJoinStrokes("InknpaintTapeJoinStrokes", 0);
|
|
Toshihiro Shimizu |
890ddd |
TEnv::StringVar TapeType("InknpaintTapeType1", "Normal");
|
|
Toshihiro Shimizu |
890ddd |
TEnv::DoubleVar AutocloseFactor("InknpaintAutocloseFactor", 4.0);
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class UndoAutoclose : public ToolUtils::TToolUndo
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int m_oldStrokeId1;
|
|
Toshihiro Shimizu |
890ddd |
int m_oldStrokeId2;
|
|
Toshihiro Shimizu |
890ddd |
int m_pos1, m_pos2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *m_oldStroke1;
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *m_oldStroke2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tfilledregioninf> *m_fillInformation;</tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int m_row;
|
|
Toshihiro Shimizu |
890ddd |
int m_column;
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<int> m_changedStrokes;</int>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *m_newStroke;
|
|
Toshihiro Shimizu |
890ddd |
int m_newStrokeId;
|
|
Toshihiro Shimizu |
890ddd |
int m_newStrokePos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
UndoAutoclose(TXshSimpleLevel *level, const TFrameId &frameId, int pos1, int pos2, std::vector<tfilledregioninf> *fillInformation, const std::vector<int> &changedStrokes)</int></tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
: ToolUtils::TToolUndo(level, frameId), m_oldStroke1(0), m_oldStroke2(0), m_pos1(pos1), m_pos2(pos2), m_newStrokePos(-1), m_fillInformation(fillInformation), m_changedStrokes(changedStrokes)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP image = level->getFrame(m_frameId, true);
|
|
Toshihiro Shimizu |
890ddd |
if (pos1 != -1) {
|
|
Toshihiro Shimizu |
890ddd |
m_oldStrokeId1 = image->getStroke(pos1)->getId();
|
|
Toshihiro Shimizu |
890ddd |
m_oldStroke1 = cloneVIStroke(image->getVIStroke(pos1));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (pos2 != -1 && pos1 != pos2 && image) {
|
|
Toshihiro Shimizu |
890ddd |
m_oldStrokeId2 = image->getStroke(pos2)->getId();
|
|
Toshihiro Shimizu |
890ddd |
m_oldStroke2 = cloneVIStroke(image->getVIStroke(pos2));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TTool::Application *app = TTool::getApplication();
|
|
Toshihiro Shimizu |
890ddd |
if (app) {
|
|
Toshihiro Shimizu |
890ddd |
m_row = app->getCurrentFrame()->getFrame();
|
|
Toshihiro Shimizu |
890ddd |
m_column = app->getCurrentColumn()->getColumnIndex();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
~UndoAutoclose()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
deleteVIStroke(m_newStroke);
|
|
Toshihiro Shimizu |
890ddd |
if (m_oldStroke1)
|
|
Toshihiro Shimizu |
890ddd |
deleteVIStroke(m_oldStroke1);
|
|
Toshihiro Shimizu |
890ddd |
if (m_oldStroke2)
|
|
Toshihiro Shimizu |
890ddd |
deleteVIStroke(m_oldStroke2);
|
|
Toshihiro Shimizu |
890ddd |
if (m_isLastInBlock)
|
|
Toshihiro Shimizu |
890ddd |
delete m_fillInformation;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void undo() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TTool::Application *app = TTool::getApplication();
|
|
Toshihiro Shimizu |
890ddd |
if (!app)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
if (app->getCurrentFrame()->isEditingScene()) {
|
|
Toshihiro Shimizu |
890ddd |
app->getCurrentColumn()->setColumnIndex(m_column);
|
|
Toshihiro Shimizu |
890ddd |
app->getCurrentFrame()->setFrame(m_row);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
app->getCurrentFrame()->setFid(m_frameId);
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP image = m_level->getFrame(m_frameId, true);
|
|
Toshihiro Shimizu |
890ddd |
assert(!!image);
|
|
Toshihiro Shimizu |
890ddd |
if (!image)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker lock(image->getMutex());
|
|
Toshihiro Shimizu |
890ddd |
int strokeIndex = image->getStrokeIndexById(m_newStrokeId);
|
|
Toshihiro Shimizu |
890ddd |
if (strokeIndex != -1)
|
|
Toshihiro Shimizu |
890ddd |
image->removeStroke(strokeIndex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_oldStroke1)
|
|
Toshihiro Shimizu |
890ddd |
image->insertStrokeAt(cloneVIStroke(m_oldStroke1), m_pos1);
|
|
Toshihiro Shimizu |
890ddd |
if (m_oldStroke2)
|
|
Toshihiro Shimizu |
890ddd |
image->insertStrokeAt(cloneVIStroke(m_oldStroke2), m_pos2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
image->notifyChangedStrokes(m_changedStrokes, std::vector<tstroke *="">());</tstroke>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!m_isLastInBlock)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < m_fillInformation->size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
TRegion *reg = image->getRegion((*m_fillInformation)[i].m_regionId);
|
|
Toshihiro Shimizu |
890ddd |
assert(reg);
|
|
Toshihiro Shimizu |
890ddd |
if (reg)
|
|
Toshihiro Shimizu |
890ddd |
reg->setStyle((*m_fillInformation)[i].m_styleId);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
app->getCurrentXsheet()->notifyXsheetChanged();
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void redo() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TTool::Application *app = TTool::getApplication();
|
|
Toshihiro Shimizu |
890ddd |
if (!app)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (app->getCurrentFrame()->isEditingScene()) {
|
|
Toshihiro Shimizu |
890ddd |
app->getCurrentColumn()->setColumnIndex(m_column);
|
|
Toshihiro Shimizu |
890ddd |
app->getCurrentFrame()->setFrame(m_row);
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
app->getCurrentFrame()->setFid(m_frameId);
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP image = m_level->getFrame(m_frameId, true);
|
|
Toshihiro Shimizu |
890ddd |
assert(!!image);
|
|
Toshihiro Shimizu |
890ddd |
if (!image)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker lock(image->getMutex());
|
|
Toshihiro Shimizu |
890ddd |
if (m_oldStroke1) {
|
|
Toshihiro Shimizu |
890ddd |
int strokeIndex = image->getStrokeIndexById(m_oldStrokeId1);
|
|
Toshihiro Shimizu |
890ddd |
if (strokeIndex != -1)
|
|
Toshihiro Shimizu |
890ddd |
image->removeStroke(strokeIndex);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_oldStroke2) {
|
|
Toshihiro Shimizu |
890ddd |
int strokeIndex = image->getStrokeIndexById(m_oldStrokeId2);
|
|
Toshihiro Shimizu |
890ddd |
if (strokeIndex != -1)
|
|
Toshihiro Shimizu |
890ddd |
image->removeStroke(strokeIndex);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *stroke = cloneVIStroke(m_newStroke);
|
|
Toshihiro Shimizu |
890ddd |
image->insertStrokeAt(stroke, m_pos1 == -1 ? m_newStrokePos : m_pos1, false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
image->notifyChangedStrokes(m_changedStrokes, std::vector<tstroke *="">());</tstroke>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
app->getCurrentXsheet()->notifyXsheetChanged();
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getSize() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return sizeof(*this) + m_fillInformation->capacity() * sizeof(TFilledRegionInf) + 500;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
virtual QString getToolName()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return QString("Autoclose Tool");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
int getHistoryType()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return HistoryType::AutocloseTool;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// Autoclose Tool
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class VectorTapeTool : public TTool
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Q_DECLARE_TR_FUNCTIONS(VectorTapeTool)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool m_draw;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool m_secondPoint;
|
|
Toshihiro Shimizu |
890ddd |
int m_strokeIndex1, m_strokeIndex2;
|
|
Toshihiro Shimizu |
890ddd |
double m_w1, m_w2, m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
TPointD m_pos;
|
|
Toshihiro Shimizu |
890ddd |
bool m_firstTime;
|
|
Toshihiro Shimizu |
890ddd |
TRectD m_selectionRect;
|
|
Toshihiro Shimizu |
890ddd |
TPointD m_startRect;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TBoolProperty m_smooth;
|
|
Toshihiro Shimizu |
890ddd |
TBoolProperty m_joinStrokes;
|
|
Toshihiro Shimizu |
890ddd |
TEnumProperty m_mode;
|
|
Toshihiro Shimizu |
890ddd |
TPropertyGroup m_prop;
|
|
Toshihiro Shimizu |
890ddd |
TDoubleProperty m_autocloseFactor;
|
|
Toshihiro Shimizu |
890ddd |
TEnumProperty m_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
VectorTapeTool()
|
|
Toshihiro Shimizu |
890ddd |
: TTool("T_Tape"), m_secondPoint(false), m_strokeIndex1(-1), m_strokeIndex2(-1), m_w1(-1.0), m_w2(-1.0), m_pixelSize(1), m_draw(false), m_smooth("Smooth", false) // W_ToolOptions_Smooth
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
m_joinStrokes("JoinStrokes", false), m_mode("Mode"), m_type("Type"), m_autocloseFactor("Distance", 0.1, 100, 0.5), m_firstTime(true), m_selectionRect(), m_startRect()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bind(TTool::Vectors);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_type);
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_mode);
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_autocloseFactor);
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_joinStrokes);
|
|
Toshihiro Shimizu |
890ddd |
m_prop.bind(m_smooth);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_mode.addValue(POINT2POINT);
|
|
Toshihiro Shimizu |
890ddd |
m_mode.addValue(POINT2LINE);
|
|
Toshihiro Shimizu |
890ddd |
m_mode.addValue(LINE2LINE);
|
|
Toshihiro Shimizu |
890ddd |
m_smooth.setId("Smooth");
|
|
Toshihiro Shimizu |
890ddd |
m_type.addValue(NORMAL);
|
|
Toshihiro Shimizu |
890ddd |
m_type.addValue(RECT);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_mode.setId("Mode");
|
|
Toshihiro Shimizu |
890ddd |
m_type.setId("Type");
|
|
Toshihiro Shimizu |
890ddd |
m_joinStrokes.setId("JoinVectors");
|
|
Toshihiro Shimizu |
890ddd |
m_autocloseFactor.setId("Distance");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ToolType getToolType() const { return TTool::LevelWriteTool; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
bool onPropertyChanged(std::string propertyName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TapeMode = toString(m_mode.getValue());
|
|
Toshihiro Shimizu |
890ddd |
TapeSmooth = (int)(m_smooth.getValue());
|
|
Shinya Kitaoka |
3bfa54 |
std::wstring s = m_type.getValue();
|
|
Toshihiro Shimizu |
890ddd |
if (!s.empty())
|
|
Toshihiro Shimizu |
890ddd |
TapeType = toString(s);
|
|
Toshihiro Shimizu |
890ddd |
TapeJoinStrokes = (int)(m_joinStrokes.getValue());
|
|
Toshihiro Shimizu |
890ddd |
AutocloseFactor = (double)(m_autocloseFactor.getValue());
|
|
Toshihiro Shimizu |
890ddd |
m_selectionRect = TRectD();
|
|
Toshihiro Shimizu |
890ddd |
m_startRect = TPointD();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (propertyName == "Distance" && (ToonzCheck::instance()->getChecks() & ToonzCheck::eAutoclose))
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void updateTranslation()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_smooth.setQStringName(tr("Smooth"));
|
|
Toshihiro Shimizu |
890ddd |
m_joinStrokes.setQStringName(tr("Join Vectors"));
|
|
Toshihiro Shimizu |
890ddd |
m_mode.setQStringName(tr("Mode:"));
|
|
Toshihiro Shimizu |
890ddd |
m_type.setQStringName(tr("Type:"));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPropertyGroup *getProperties(int targetType)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return &m_prop;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void draw()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP vi(getImage(false));
|
|
Toshihiro Shimizu |
890ddd |
if (!m_draw)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
if (!vi)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//TAffine viewMatrix = getViewer()->getViewMatrix();
|
|
Toshihiro Shimizu |
890ddd |
//glPushMatrix();
|
|
Toshihiro Shimizu |
890ddd |
//tglMultMatrix(viewMatrix);
|
|
Toshihiro Shimizu |
890ddd |
if (m_type.getValue() == RECT) {
|
|
Toshihiro Shimizu |
890ddd |
if (!m_selectionRect.isEmpty())
|
|
Toshihiro Shimizu |
890ddd |
ToolUtils::drawRect(m_selectionRect, TPixel::Black, 0x3F33, true);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_strokeIndex1 == -1 || m_strokeIndex1 >= (int)(vi->getStrokeCount()))
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
tglColor(TPixelD(0.1, 0.9, 0.1));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke1 = vi->getStroke(m_strokeIndex1);
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint point1 = stroke1->getPoint(m_w1);
|
|
Toshihiro Shimizu |
890ddd |
//TThickPoint point1 = stroke1->getControlPoint(m_cpIndex1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_pixelSize = getPixelSize();
|
|
Toshihiro Shimizu |
890ddd |
double thick = tmax(6.0 * m_pixelSize, point1.thick);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(point1, thick);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint point2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_secondPoint) {
|
|
Toshihiro Shimizu |
890ddd |
if (m_strokeIndex2 != -1) {
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke2 = vi->getStroke(m_strokeIndex2);
|
|
Toshihiro Shimizu |
890ddd |
point2 = stroke2->getPoint(m_w2);
|
|
Toshihiro Shimizu |
890ddd |
thick = tmax(6.0 * m_pixelSize, point2.thick);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
tglColor(TPixelD(0.6, 0.7, 0.4));
|
|
Toshihiro Shimizu |
890ddd |
thick = 4 * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
point2 = m_pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(point2, thick);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawSegment(point1, point2);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//glPopMatrix();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void mouseMove(const TPointD &pos, const TMouseEvent &)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP vi(getImage(false));
|
|
Toshihiro Shimizu |
890ddd |
if (!vi)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//BUTTA e rimetti (Dava problemi con la penna)
|
|
Toshihiro Shimizu |
890ddd |
if (!m_draw)
|
|
Toshihiro Shimizu |
890ddd |
return; //Questa riga potrebbe non essere messa
|
|
Toshihiro Shimizu |
890ddd |
//m_draw=true; //Perche'??? Non basta dargli true in onEnter??
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_type.getValue() == RECT)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double minDistance2 = 10000000000.;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex1 = -1;
|
|
Toshihiro Shimizu |
890ddd |
m_secondPoint = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int i, strokeNumber = vi->getStrokeCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke;
|
|
Toshihiro Shimizu |
890ddd |
double distance2, outW;
|
|
Toshihiro Shimizu |
890ddd |
TPointD point;
|
|
Toshihiro Shimizu |
890ddd |
int cpMax;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < strokeNumber; i++) {
|
|
Toshihiro Shimizu |
890ddd |
stroke = vi->getStroke(i);
|
|
Toshihiro Shimizu |
890ddd |
if (m_mode.getValue() == LINE2LINE) {
|
|
Toshihiro Shimizu |
890ddd |
if (stroke->getNearestW(pos, outW, distance2) && distance2 < minDistance2) {
|
|
Toshihiro Shimizu |
890ddd |
minDistance2 = distance2;
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex1 = i;
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(outW, 0.0, 1e-3))
|
|
Toshihiro Shimizu |
890ddd |
m_w1 = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (areAlmostEqual(outW, 1.0, 1e-3))
|
|
Toshihiro Shimizu |
890ddd |
m_w1 = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_w1 = outW;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else if (!stroke->isSelfLoop()) {
|
|
Toshihiro Shimizu |
890ddd |
point = stroke->getControlPoint(0);
|
|
Toshihiro Shimizu |
890ddd |
if ((distance2 = tdistance2(pos, point)) < minDistance2) {
|
|
Toshihiro Shimizu |
890ddd |
minDistance2 = distance2;
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex1 = i;
|
|
Toshihiro Shimizu |
890ddd |
m_w1 = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
//m_cpIndex1=0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cpMax = stroke->getControlPointCount() - 1;
|
|
Toshihiro Shimizu |
890ddd |
point = stroke->getControlPoint(cpMax);
|
|
Toshihiro Shimizu |
890ddd |
if ((distance2 = tdistance2(pos, point)) < minDistance2) {
|
|
Toshihiro Shimizu |
890ddd |
minDistance2 = distance2;
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex1 = i;
|
|
Toshihiro Shimizu |
890ddd |
m_w1 = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
//m_cpIndex1=cpMax;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void leftButtonDown(const TPointD &pos, const TMouseEvent &)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!(TVectorImageP)getImage(false))
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_type.getValue() == RECT) {
|
|
Toshihiro Shimizu |
890ddd |
m_startRect = pos;
|
|
Toshihiro Shimizu |
890ddd |
} else if (m_strokeIndex1 != -1)
|
|
Toshihiro Shimizu |
890ddd |
m_secondPoint = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP vi(getImage(false));
|
|
Toshihiro Shimizu |
890ddd |
if (!vi)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_type.getValue() == RECT) {
|
|
Toshihiro Shimizu |
890ddd |
m_selectionRect = TRectD(tmin(m_startRect.x, pos.x), tmin(m_startRect.y, pos.y), tmax(m_startRect.x, pos.x), tmax(m_startRect.y, pos.y));
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_strokeIndex1 == -1 || !m_secondPoint)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double minDistance2 = 900 * m_pixelSize;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int i, strokeNumber = vi->getStrokeCount();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStroke *stroke;
|
|
Toshihiro Shimizu |
890ddd |
double distance2, outW;
|
|
Toshihiro Shimizu |
890ddd |
TPointD point;
|
|
Toshihiro Shimizu |
890ddd |
int cpMax;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex2 = -1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < strokeNumber; i++) {
|
|
Toshihiro Shimizu |
890ddd |
if (!vi->sameGroup(m_strokeIndex1, i))
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
stroke = vi->getStroke(i);
|
|
Toshihiro Shimizu |
890ddd |
if (m_mode.getValue() != POINT2POINT) {
|
|
Toshihiro Shimizu |
890ddd |
if (stroke->getNearestW(pos, outW, distance2) && distance2 < minDistance2) {
|
|
Toshihiro Shimizu |
890ddd |
minDistance2 = distance2;
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex2 = i;
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(outW, 0.0, 1e-3))
|
|
Toshihiro Shimizu |
890ddd |
m_w2 = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (areAlmostEqual(outW, 1.0, 1e-3))
|
|
Toshihiro Shimizu |
890ddd |
m_w2 = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_w2 = outW;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!stroke->isSelfLoop()) {
|
|
Toshihiro Shimizu |
890ddd |
cpMax = stroke->getControlPointCount() - 1;
|
|
Toshihiro Shimizu |
890ddd |
if (!(m_strokeIndex1 == i && (m_w1 == 0.0 || cpMax < 3))) {
|
|
Toshihiro Shimizu |
890ddd |
point = stroke->getControlPoint(0);
|
|
Toshihiro Shimizu |
890ddd |
if ((distance2 = tdistance2(pos, point)) < minDistance2) {
|
|
Toshihiro Shimizu |
890ddd |
minDistance2 = distance2;
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex2 = i;
|
|
Toshihiro Shimizu |
890ddd |
m_w2 = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!(m_strokeIndex1 == i && (m_w1 == 1.0 || cpMax < 3))) {
|
|
Toshihiro Shimizu |
890ddd |
point = stroke->getControlPoint(cpMax);
|
|
Toshihiro Shimizu |
890ddd |
if ((distance2 = tdistance2(pos, point)) < minDistance2) {
|
|
Toshihiro Shimizu |
890ddd |
minDistance2 = distance2;
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex2 = i;
|
|
Toshihiro Shimizu |
890ddd |
m_w2 = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_pos = pos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void joinPointToPoint(const TVectorImageP &vi, std::vector<tfilledregioninf> *fillInfo)</tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int minindex = tmin(m_strokeIndex1, m_strokeIndex2);
|
|
Toshihiro Shimizu |
890ddd |
int maxindex = tmax(m_strokeIndex1, m_strokeIndex2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UndoAutoclose *autoCloseUndo = 0;
|
|
Toshihiro Shimizu |
890ddd |
TUndo *undo = 0;
|
|
Toshihiro Shimizu |
890ddd |
if (TTool::getApplication()->getCurrentObject()->isSpline())
|
|
Toshihiro Shimizu |
890ddd |
undo = new UndoPath(getXsheet()->getStageObject(getObjectId())->getSpline());
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *level = TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<int> v(1);</int>
|
|
Toshihiro Shimizu |
890ddd |
v[0] = minindex;
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo = new UndoAutoclose(level, getCurrentFid(), minindex, maxindex, fillInfo, v);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *newStroke = vi->joinStroke(m_strokeIndex1, m_strokeIndex2,
|
|
Toshihiro Shimizu |
890ddd |
(m_w1 == 0.0) ? 0 : vi->getStroke(m_strokeIndex1)->getControlPointCount() - 1,
|
|
Toshihiro Shimizu |
890ddd |
(m_w2 == 0.0) ? 0 : vi->getStroke(m_strokeIndex2)->getControlPointCount() - 1,
|
|
Toshihiro Shimizu |
890ddd |
m_smooth.getValue());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (autoCloseUndo) {
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo->m_newStroke = cloneVIStroke(newStroke);
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo->m_newStrokeId = vi->getStroke(minindex)->getId();
|
|
Toshihiro Shimizu |
890ddd |
undo = autoCloseUndo;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vi->notifyChangedStrokes(minindex);
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->add(undo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void joinPointToLine(const TVectorImageP &vi, std::vector<tfilledregioninf> *fillInfo)</tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TUndo *undo = 0;
|
|
Toshihiro Shimizu |
890ddd |
UndoAutoclose *autoCloseUndo = 0;
|
|
Toshihiro Shimizu |
890ddd |
if (TTool::getApplication()->getCurrentObject()->isSpline())
|
|
Toshihiro Shimizu |
890ddd |
undo = new UndoPath(getXsheet()->getStageObject(getObjectId())->getSpline());
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<int> v(2);</int>
|
|
Toshihiro Shimizu |
890ddd |
v[0] = m_strokeIndex1;
|
|
Toshihiro Shimizu |
890ddd |
v[1] = m_strokeIndex2;
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *level = TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo = new UndoAutoclose(level, getCurrentFid(), m_strokeIndex1, -1, fillInfo, v);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *newStroke;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
newStroke = vi->extendStroke(m_strokeIndex1, vi->getStroke(m_strokeIndex2)->getThickPoint(m_w2),
|
|
Toshihiro Shimizu |
890ddd |
(m_w1 == 0.0) ? 0 : vi->getStroke(m_strokeIndex1)->getControlPointCount() - 1,
|
|
Toshihiro Shimizu |
890ddd |
m_smooth.getValue());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (autoCloseUndo) {
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo->m_newStroke = cloneVIStroke(newStroke);
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo->m_newStrokeId = vi->getStroke(m_strokeIndex1)->getId();
|
|
Toshihiro Shimizu |
890ddd |
undo = autoCloseUndo;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vi->notifyChangedStrokes(m_strokeIndex1);
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->add(undo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void joinLineToLine(const TVectorImageP &vi, std::vector<tfilledregioninf> *fillInfo)</tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (TTool::getApplication()->getCurrentObject()->isSpline())
|
|
Shinya Kitaoka |
3bfa54 |
return; //Caanot add vectros to spline... Spline can be only one std::vector
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p1 = vi->getStroke(m_strokeIndex1)->getThickPoint(m_w1);
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint p2 = vi->getStroke(m_strokeIndex2)->getThickPoint(m_w2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
UndoAutoclose *autoCloseUndo = 0;
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<int> v(2);</int>
|
|
Toshihiro Shimizu |
890ddd |
v[0] = m_strokeIndex1;
|
|
Toshihiro Shimizu |
890ddd |
v[1] = m_strokeIndex2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *level = TTool::getApplication()->getCurrentLevel()->getSimpleLevel();
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo = new UndoAutoclose(level, getCurrentFid(), -1, -1, fillInfo, v);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tthickpoint> points(3);</tthickpoint>
|
|
Toshihiro Shimizu |
890ddd |
points[0] = p1;
|
|
Toshihiro Shimizu |
890ddd |
points[1] = 0.5 * (p1 + p2);
|
|
Toshihiro Shimizu |
890ddd |
points[2] = p2;
|
|
Toshihiro Shimizu |
890ddd |
TStroke *auxStroke = new TStroke(points);
|
|
Toshihiro Shimizu |
890ddd |
auxStroke->setStyle(TTool::getApplication()->getCurrentLevelStyleIndex());
|
|
Toshihiro Shimizu |
890ddd |
auxStroke->outlineOptions() = vi->getStroke(m_strokeIndex1)->outlineOptions();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int pos = vi->addStrokeToGroup(auxStroke, m_strokeIndex1);
|
|
Toshihiro Shimizu |
890ddd |
if (pos < 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
VIStroke *newStroke = vi->getVIStroke(pos);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo->m_newStrokePos = pos;
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo->m_newStroke = cloneVIStroke(newStroke);
|
|
Toshihiro Shimizu |
890ddd |
autoCloseUndo->m_newStrokeId = vi->getStroke(pos)->getId();
|
|
Shinya Kitaoka |
3bfa54 |
vi->notifyChangedStrokes(v, std::vector<tstroke *="">());</tstroke>
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->add(autoCloseUndo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void inline rearrangeClosingPoints(const TVectorImageP &vi, std::pair<int, double=""> &closingPoint, const TPointD &p)</int,>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int erasedIndex = tmax(m_strokeIndex1, m_strokeIndex2);
|
|
Toshihiro Shimizu |
890ddd |
int joinedIndex = tmin(m_strokeIndex1, m_strokeIndex2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (closingPoint.first == joinedIndex)
|
|
Toshihiro Shimizu |
890ddd |
closingPoint.second = vi->getStroke(joinedIndex)->getW(p);
|
|
Toshihiro Shimizu |
890ddd |
else if (closingPoint.first == erasedIndex) {
|
|
Toshihiro Shimizu |
890ddd |
closingPoint.first = joinedIndex;
|
|
Toshihiro Shimizu |
890ddd |
closingPoint.second = vi->getStroke(joinedIndex)->getW(p);
|
|
Toshihiro Shimizu |
890ddd |
} else if (closingPoint.first > erasedIndex)
|
|
Toshihiro Shimizu |
890ddd |
closingPoint.first--;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define p2p 1
|
|
Toshihiro Shimizu |
890ddd |
#define p2l 2
|
|
Toshihiro Shimizu |
890ddd |
#define l2p 3
|
|
Toshihiro Shimizu |
890ddd |
#define l2l 4
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tapeRect(const TVectorImageP &vi, const TRectD &rect)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tfilledregioninf> *fillInformation = new std::vector<tfilledregioninf>;</tfilledregioninf></tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
ImageUtils::getFillingInformationOverlappingArea(vi, *fillInformation, rect);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool initUndoBlock = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::pair<int, double="">> startPoints, endPoints;</std::pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
getClosingPoints(rect, m_autocloseFactor.getValue(), vi, startPoints, endPoints);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(startPoints.size() == endPoints.size());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tpointd> startP(startPoints.size()), endP(startPoints.size());</tpointd>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!startPoints.empty()) {
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->beginBlock();
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < startPoints.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
startP[i] = vi->getStroke(startPoints[i].first)->getPoint(startPoints[i].second);
|
|
Toshihiro Shimizu |
890ddd |
endP[i] = vi->getStroke(endPoints[i].first)->getPoint(endPoints[i].second);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (UINT i = 0; i < startPoints.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex1 = startPoints[i].first;
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex2 = endPoints[i].first;
|
|
Toshihiro Shimizu |
890ddd |
m_w1 = startPoints[i].second;
|
|
Toshihiro Shimizu |
890ddd |
m_w2 = endPoints[i].second;
|
|
Toshihiro Shimizu |
890ddd |
int type = doTape(vi, fillInformation, m_joinStrokes.getValue());
|
|
Toshihiro Shimizu |
890ddd |
if (type == p2p && m_strokeIndex1 != m_strokeIndex2) {
|
|
Toshihiro Shimizu |
890ddd |
for (UINT j = i + 1; j < startPoints.size(); j++) {
|
|
Toshihiro Shimizu |
890ddd |
rearrangeClosingPoints(vi, startPoints[j], startP[j]);
|
|
Toshihiro Shimizu |
890ddd |
rearrangeClosingPoints(vi, endPoints[j], endP[j]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else if (type == p2l || (type == p2p && m_strokeIndex1 == m_strokeIndex2)) {
|
|
Toshihiro Shimizu |
890ddd |
for (UINT j = i + 1; j < startPoints.size(); j++) {
|
|
Toshihiro Shimizu |
890ddd |
if (startPoints[j].first == m_strokeIndex1)
|
|
Toshihiro Shimizu |
890ddd |
startPoints[j].second = vi->getStroke(m_strokeIndex1)->getW(startP[j]);
|
|
Toshihiro Shimizu |
890ddd |
if (endPoints[j].first == m_strokeIndex1)
|
|
Toshihiro Shimizu |
890ddd |
endPoints[j].second = vi->getStroke(m_strokeIndex1)->getW(endP[j]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (!startPoints.empty())
|
|
Toshihiro Shimizu |
890ddd |
TUndoManager::manager()->endBlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
int doTape(const TVectorImageP &vi, std::vector<tfilledregioninf> *fillInformation, bool joinStrokes)</tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int type;
|
|
Toshihiro Shimizu |
890ddd |
if (!joinStrokes)
|
|
Toshihiro Shimizu |
890ddd |
type = l2l;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
type = (m_w1 == 0.0 || m_w1 == 1.0) ? ((m_w2 == 0.0 || m_w2 == 1.0) ? p2p : p2l) : ((m_w2 == 0.0 || m_w2 == 1.0) ? l2p : l2l);
|
|
Toshihiro Shimizu |
890ddd |
if (type == l2p) {
|
|
Toshihiro Shimizu |
890ddd |
tswap(m_strokeIndex1, m_strokeIndex2);
|
|
Toshihiro Shimizu |
890ddd |
tswap(m_w1, m_w2);
|
|
Toshihiro Shimizu |
890ddd |
type = p2l;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (type) {
|
|
Toshihiro Shimizu |
890ddd |
case p2p:
|
|
Toshihiro Shimizu |
890ddd |
joinPointToPoint(vi, fillInformation);
|
|
Toshihiro Shimizu |
890ddd |
CASE p2l : joinPointToLine(vi, fillInformation);
|
|
Toshihiro Shimizu |
890ddd |
CASE l2l : joinLineToLine(vi, fillInformation);
|
|
Toshihiro Shimizu |
890ddd |
DEFAULT:
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return type;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void leftButtonUp(const TPointD &, const TMouseEvent &)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP vi(getImage(true));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (vi && m_type.getValue() == RECT) {
|
|
Toshihiro Shimizu |
890ddd |
tapeRect(vi, m_selectionRect);
|
|
Toshihiro Shimizu |
890ddd |
m_selectionRect = TRectD();
|
|
Toshihiro Shimizu |
890ddd |
m_startRect = TPointD();
|
|
Toshihiro Shimizu |
890ddd |
notifyImageChanged();
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!vi || m_strokeIndex1 == -1 || !m_secondPoint || m_strokeIndex2 == -1) {
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex1 = -1;
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex2 = -1;
|
|
Toshihiro Shimizu |
890ddd |
m_w1 = -1.0;
|
|
Toshihiro Shimizu |
890ddd |
m_w2 = -1.0;
|
|
Toshihiro Shimizu |
890ddd |
m_secondPoint = false;
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
QMutexLocker lock(vi->getMutex());
|
|
Toshihiro Shimizu |
890ddd |
m_secondPoint = false;
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<tfilledregioninf> *fillInformation = new std::vector<tfilledregioninf>;</tfilledregioninf></tfilledregioninf>
|
|
Toshihiro Shimizu |
890ddd |
ImageUtils::getFillingInformationOverlappingArea(vi, *fillInformation, vi->getStroke(m_strokeIndex1)->getBBox() +
|
|
Toshihiro Shimizu |
890ddd |
vi->getStroke(m_strokeIndex2)->getBBox());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
doTape(vi, fillInformation, m_joinStrokes.getValue());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_strokeIndex2 = -1;
|
|
Toshihiro Shimizu |
890ddd |
m_w1 = -1.0;
|
|
Toshihiro Shimizu |
890ddd |
m_w2 = -1.0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void onEnter()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// getApplication()->editImage();
|
|
Toshihiro Shimizu |
890ddd |
m_draw = true;
|
|
Toshihiro Shimizu |
890ddd |
m_selectionRect = TRectD();
|
|
Toshihiro Shimizu |
890ddd |
m_startRect = TPointD();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void onLeave()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_draw = false;
|
|
Toshihiro Shimizu |
890ddd |
//m_strokeIndex1=-1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void onActivate()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_firstTime)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::wstring s = toWideString(TapeMode.getValue());
|
|
Toshihiro Shimizu |
890ddd |
if (s != L"")
|
|
Toshihiro Shimizu |
890ddd |
m_mode.setValue(s);
|
|
Toshihiro Shimizu |
890ddd |
s = toWideString(TapeType.getValue());
|
|
Toshihiro Shimizu |
890ddd |
if (s != L"")
|
|
Toshihiro Shimizu |
890ddd |
m_type.setValue(s);
|
|
Toshihiro Shimizu |
890ddd |
m_autocloseFactor.setValue(AutocloseFactor);
|
|
Toshihiro Shimizu |
890ddd |
m_smooth.setValue(TapeSmooth ? 1 : 0);
|
|
Toshihiro Shimizu |
890ddd |
m_joinStrokes.setValue(TapeJoinStrokes ? 1 : 0);
|
|
Toshihiro Shimizu |
890ddd |
m_firstTime = false;
|
|
Toshihiro Shimizu |
890ddd |
m_selectionRect = TRectD();
|
|
Toshihiro Shimizu |
890ddd |
m_startRect = TPointD();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getCursorId() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (ToonzCheck::instance()->getChecks() & ToonzCheck::eBlackBg)
|
|
Toshihiro Shimizu |
890ddd |
return ToolCursor::TapeCursorWhite;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return ToolCursor::TapeCursor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} vectorTapeTool;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//TTool *getAutocloseTool() {return &autocloseTool;}
|