2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vabstracttool.h
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-07-25 20:39:51 +02:00
|
|
|
#ifndef VABSTRACTTOOL_H
|
|
|
|
#define VABSTRACTTOOL_H
|
|
|
|
|
2013-08-13 18:48:36 +02:00
|
|
|
#include "vdatatool.h"
|
2014-02-25 15:02:09 +01:00
|
|
|
#include "../xml/vpattern.h"
|
2014-02-05 16:32:50 +01:00
|
|
|
#include <QMessageBox>
|
2013-07-25 20:39:51 +02:00
|
|
|
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief The VAbstractTool abstract class for all tools.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
class VAbstractTool: public VDataTool
|
|
|
|
{
|
2013-07-25 20:39:51 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-26 09:18:59 +01:00
|
|
|
/**
|
|
|
|
* @brief VAbstractTool container.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with data.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param parent parent object.
|
|
|
|
*/
|
2014-02-26 10:22:05 +01:00
|
|
|
VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent = nullptr);
|
2014-02-26 09:18:59 +01:00
|
|
|
virtual ~VAbstractTool(){}
|
2014-01-24 13:54:29 +01:00
|
|
|
/**
|
|
|
|
* @brief NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view.
|
|
|
|
* @param sc scene.
|
|
|
|
* @param view view.
|
|
|
|
*/
|
2014-01-15 10:20:46 +01:00
|
|
|
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view);
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief LineIntersectRect find point intersection line and rect.
|
|
|
|
* @param rec rect.
|
|
|
|
* @param line line.
|
|
|
|
* @return point intersection.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-27 12:56:05 +01:00
|
|
|
static QPointF LineIntersectRect(QRectF rec, QLineF line);
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief LineIntersectCircle find point intersection line and circle.
|
|
|
|
* @param center arc center.
|
|
|
|
* @param radius arc radius.
|
|
|
|
* @param line line
|
|
|
|
* @param p1 first intersection point.
|
|
|
|
* @param p2 second intersection point.
|
|
|
|
* @return 0 - intersection doesn't exist, 1 - one intersection point, 2 - two intersection points.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-11-06 22:11:12 +01:00
|
|
|
static qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1,
|
|
|
|
QPointF &p2);
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief ClosestPoint find point projection of point onto line.
|
|
|
|
* @param line line.
|
|
|
|
* @param p point.
|
|
|
|
* @return point on line or extended line if origin size too small.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-01-29 10:18:26 +01:00
|
|
|
static QPointF ClosestPoint(const QLineF &line, const QPointF &point);
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
|
|
|
* @brief addVector
|
|
|
|
* @param p
|
|
|
|
* @param p1
|
|
|
|
* @param p2
|
|
|
|
* @param k
|
|
|
|
* @return
|
|
|
|
*/
|
2013-11-06 22:11:12 +01:00
|
|
|
static QPointF addVector (const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k);
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief getId return object id.
|
|
|
|
* @return id.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
quint32 getId() const;
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief LineCoefficients coefficient for equation of segment. Segment equestion ax+by+c=0.
|
|
|
|
* @param line line
|
|
|
|
* @param a a value
|
|
|
|
* @param b b value
|
|
|
|
* @param c c value
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-27 12:56:05 +01:00
|
|
|
static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c);
|
2013-10-29 14:45:07 +01:00
|
|
|
static const QString AttrType;
|
|
|
|
static const QString AttrMx;
|
|
|
|
static const QString AttrMy;
|
|
|
|
static const QString AttrName;
|
|
|
|
static const QString AttrX;
|
|
|
|
static const QString AttrY;
|
|
|
|
static const QString AttrTypeLine;
|
|
|
|
static const QString AttrLength;
|
|
|
|
static const QString AttrBasePoint;
|
|
|
|
static const QString AttrFirstPoint;
|
|
|
|
static const QString AttrSecondPoint;
|
|
|
|
static const QString AttrThirdPoint;
|
|
|
|
static const QString AttrCenter;
|
|
|
|
static const QString AttrRadius;
|
|
|
|
static const QString AttrAngle;
|
|
|
|
static const QString AttrAngle1;
|
|
|
|
static const QString AttrAngle2;
|
|
|
|
static const QString AttrP1Line;
|
|
|
|
static const QString AttrP2Line;
|
|
|
|
static const QString AttrP1Line1;
|
|
|
|
static const QString AttrP2Line1;
|
|
|
|
static const QString AttrP1Line2;
|
|
|
|
static const QString AttrP2Line2;
|
|
|
|
static const QString AttrPShoulder;
|
|
|
|
static const QString AttrPoint1;
|
|
|
|
static const QString AttrPoint4;
|
|
|
|
static const QString AttrKAsm1;
|
|
|
|
static const QString AttrKAsm2;
|
|
|
|
static const QString AttrKCurve;
|
|
|
|
static const QString AttrPathPoint;
|
|
|
|
static const QString AttrPSpline;
|
|
|
|
static const QString AttrAxisP1;
|
|
|
|
static const QString AttrAxisP2;
|
|
|
|
static const QString TypeLineNone;
|
|
|
|
static const QString TypeLineLine;
|
2014-01-29 13:47:43 +01:00
|
|
|
static const QString TypeLineDashLine;
|
|
|
|
static const QString TypeLineDotLine;
|
|
|
|
static const QString TypeLineDashDotLine;
|
|
|
|
static const QString TypeLineDashDotDotLine;
|
|
|
|
/**
|
|
|
|
* @brief Styles return list of all line styles.
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
static const QStringList Styles();
|
2014-01-02 16:50:01 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief AddRecord add record about tool in history.
|
|
|
|
* @param id object id in container
|
|
|
|
* @param toolType tool type
|
2014-01-02 16:50:01 +01:00
|
|
|
* @param doc dom document container
|
|
|
|
*/
|
2014-03-11 12:43:24 +01:00
|
|
|
static void AddRecord(const quint32 id, const Valentina::Tools &toolType, VPattern *doc);
|
2013-07-25 20:39:51 +02:00
|
|
|
public slots:
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief FullUpdateFromFile update tool data form file.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-27 12:56:05 +01:00
|
|
|
virtual void FullUpdateFromFile()=0;
|
2013-07-25 20:39:51 +02:00
|
|
|
signals:
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief toolhaveChange emit if tool create change that need save.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-27 12:56:05 +01:00
|
|
|
void toolhaveChange();
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief ChoosedTool emit if object was clicked.
|
|
|
|
* @param id object id in container.
|
|
|
|
* @param type type of scene object.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-03-11 12:43:24 +01:00
|
|
|
void ChoosedTool(quint32 id, Valentina::Scenes type);
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief FullUpdateTree emit if need reparse pattern file.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-27 12:56:05 +01:00
|
|
|
void FullUpdateTree();
|
2013-07-25 20:39:51 +02:00
|
|
|
protected:
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
|
|
|
* @brief doc dom document container
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
VPattern *doc;
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief id object id.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
const quint32 id;
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief baseColor base color for tool.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-01-07 13:54:50 +01:00
|
|
|
Qt::GlobalColor baseColor;
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief currentColor current tool color.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-27 12:56:05 +01:00
|
|
|
Qt::GlobalColor currentColor;
|
2014-01-29 13:47:43 +01:00
|
|
|
/**
|
|
|
|
* @brief typeLine line type.
|
|
|
|
*/
|
|
|
|
QString typeLine;
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief AddToFile add tag with informations about tool into file.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-27 12:56:05 +01:00
|
|
|
virtual void AddToFile()=0;
|
2013-12-24 12:24:29 +01:00
|
|
|
/**
|
|
|
|
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
|
|
|
|
*/
|
|
|
|
virtual void RefreshDataInFile()=0;
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 14:00:15 +01:00
|
|
|
* @brief getData return pointer to data container.
|
2014-01-24 13:54:29 +01:00
|
|
|
* @return container.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
const VContainer *getData() const;
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief RemoveReferens decrement value of reference.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-27 12:56:05 +01:00
|
|
|
virtual void RemoveReferens(){}
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-24 13:54:29 +01:00
|
|
|
* @brief RemoveAllChild remove all child from file.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
*/
|
|
|
|
void RemoveAllChild(QDomElement &domElement);
|
|
|
|
/**
|
|
|
|
* @brief DeleteTool full delete object form scene and file.
|
|
|
|
* @param tool tool
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-01-03 16:13:43 +01:00
|
|
|
virtual void DeleteTool(QGraphicsItem *tool);
|
2014-01-29 13:47:43 +01:00
|
|
|
/**
|
|
|
|
* @brief LineStyle return pen style for current line style.
|
|
|
|
* @return pen style.
|
|
|
|
*/
|
|
|
|
Qt::PenStyle LineStyle();
|
2013-08-20 12:26:02 +02:00
|
|
|
private:
|
2013-09-26 20:50:52 +02:00
|
|
|
Q_DISABLE_COPY(VAbstractTool)
|
2013-07-25 20:39:51 +02:00
|
|
|
};
|
2014-02-26 09:18:59 +01:00
|
|
|
|
|
|
|
inline quint32 VAbstractTool::getId() const
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const VContainer *VAbstractTool::getData() const
|
|
|
|
{
|
|
|
|
return &data;
|
|
|
|
}
|
2013-07-25 20:39:51 +02:00
|
|
|
#endif // VABSTRACTTOOL_H
|