2014-02-25 15:02:09 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vpattern.h
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-02-25 15:02:09 +01:00
|
|
|
** @date 24 2, 2014
|
|
|
|
**
|
|
|
|
** @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.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VPATTERN_H
|
|
|
|
#define VPATTERN_H
|
|
|
|
|
|
|
|
#include "vdomdocument.h"
|
|
|
|
#include "../widgets/vmaingraphicsscene.h"
|
|
|
|
#include "../tools/vdatatool.h"
|
|
|
|
#include "vtoolrecord.h"
|
|
|
|
#include <QComboBox>
|
|
|
|
|
|
|
|
namespace Document
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief The Document enum parse types.
|
|
|
|
*/
|
|
|
|
enum Document { LiteParse, FullParse};
|
|
|
|
Q_DECLARE_FLAGS(Documents, Document)
|
|
|
|
}
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Document::Documents)
|
|
|
|
|
2014-05-16 16:11:31 +02:00
|
|
|
/*
|
|
|
|
VAL_VERSION is (major << 16) + (minor << 8) + patch.
|
|
|
|
*/
|
|
|
|
// version without patch part
|
|
|
|
#define VAL_MIN_VERSION 0x000100
|
|
|
|
// max support version of format
|
|
|
|
#define VAL_VERSION 0x000100
|
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief The VPattern class working with pattern file.
|
|
|
|
*/
|
|
|
|
class VPattern : public QObject, public VDomDocument
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-03-11 12:43:24 +01:00
|
|
|
VPattern(VContainer *data, QComboBox *comboBoxDraws, Valentina::Draws *mode, QObject *parent = nullptr);
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief CreateEmptyFile create minimal empty file.
|
2014-03-16 07:32:52 +01:00
|
|
|
* @param tablePath
|
2014-02-25 15:02:09 +01:00
|
|
|
*/
|
2014-03-16 07:32:52 +01:00
|
|
|
void CreateEmptyFile(const QString &tablePath);
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief ChangeActivDraw set new pattern peace name.
|
|
|
|
* @param name new name.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
*/
|
|
|
|
void ChangeActivDraw(const QString& name, const Document::Documents &parse = Document::FullParse);
|
|
|
|
/**
|
|
|
|
* @brief GetNameActivDraw return current pattern peace name.
|
|
|
|
* @return pattern peace name.
|
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
QString GetNameActivDraw() const;
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief GetActivDrawElement return draw tag for current pattern peace.
|
|
|
|
* @param element draw tag.
|
|
|
|
* @return true if found.
|
|
|
|
*/
|
|
|
|
bool GetActivDrawElement(QDomElement &element);
|
|
|
|
/**
|
|
|
|
* @brief appendDraw add new pattern peace structure to the file.
|
|
|
|
* @param name pattern peace name.
|
|
|
|
* @return true if success.
|
|
|
|
*/
|
|
|
|
bool appendDraw(const QString& name);
|
|
|
|
/**
|
|
|
|
* @brief SetNameDraw change current pattern peace.
|
|
|
|
* @param name pattern peace name.
|
|
|
|
* @return true if success.
|
|
|
|
*/
|
|
|
|
bool SetNameDraw(const QString& name);
|
|
|
|
/**
|
|
|
|
* @brief Parse parse file.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param sceneDraw pointer to draw scene.
|
|
|
|
* @param sceneDetail pointer to details scene.
|
|
|
|
*/
|
|
|
|
void Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw,
|
|
|
|
VMainGraphicsScene *sceneDetail);
|
|
|
|
/**
|
|
|
|
* @brief getTools return list of tools pointers.
|
|
|
|
* @return list.
|
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
QHash<quint32, VDataTool*>* getTools();
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief getTool return tool from tool list.
|
|
|
|
* @param id tool id.
|
|
|
|
* @return tool.
|
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
VDataTool* getTool(const quint32 &id);
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief getHistory return list with list of history records.
|
|
|
|
* @return list of history records.
|
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
QVector<VToolRecord> *getHistory();
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief getCursor return cursor.
|
|
|
|
* @return cursor.
|
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
quint32 getCursor() const;
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief setCursor set cursor.
|
|
|
|
* @param value cursor.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void setCursor(const quint32 &value);
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief setCurrentData set current data set.
|
|
|
|
*/
|
|
|
|
void setCurrentData();
|
|
|
|
/**
|
|
|
|
* @brief AddTool add tool to list tools.
|
|
|
|
* @param id tool id.
|
|
|
|
* @param tool tool.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void AddTool(const quint32 &id, VDataTool *tool);
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief UpdateToolData update tool in list tools.
|
|
|
|
* @param id tool id.
|
|
|
|
* @param data container with variables.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void UpdateToolData(const quint32 &id, VContainer *data);
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief IncrementReferens increment reference parent objects.
|
|
|
|
* @param id parent object id.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void IncrementReferens(quint32 id) const;
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief DecrementReferens decrement reference parent objects.
|
|
|
|
* @param id parent object id.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void DecrementReferens(quint32 id) const;
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief TestUniqueId test exist unique id in pattern file. Each id must be unique.
|
|
|
|
*/
|
|
|
|
void TestUniqueId() const;
|
|
|
|
/**
|
|
|
|
* @brief SPointActiveDraw return id base point current pattern peace.
|
|
|
|
* @return id base point.
|
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
quint32 SPointActiveDraw();
|
|
|
|
bool isPatternModified() const;
|
|
|
|
void setPatternModified(bool value);
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief GetActivNodeElement find element in current pattern piece by name.
|
|
|
|
* @param name name tag.
|
|
|
|
* @param element element.
|
|
|
|
* @return true if found.
|
|
|
|
*/
|
|
|
|
bool GetActivNodeElement(const QString& name, QDomElement& element);
|
2014-03-21 11:08:29 +01:00
|
|
|
QString MPath() const;
|
2014-03-24 16:02:57 +01:00
|
|
|
void SetPath(const QString &path);
|
2014-03-21 11:08:29 +01:00
|
|
|
Valentina::Units MUnit() const;
|
|
|
|
Pattern::Measurements MType() const;
|
2014-02-25 19:03:17 +01:00
|
|
|
static const QString TagPattern;
|
2014-02-25 15:02:09 +01:00
|
|
|
static const QString TagCalculation;
|
|
|
|
static const QString TagModeling;
|
|
|
|
static const QString TagDetails;
|
|
|
|
static const QString TagAuthor;
|
|
|
|
static const QString TagDescription;
|
|
|
|
static const QString TagNotes;
|
2014-03-16 07:32:52 +01:00
|
|
|
static const QString TagMeasurements;
|
2014-02-25 15:02:09 +01:00
|
|
|
static const QString TagIncrements;
|
2014-02-25 19:03:17 +01:00
|
|
|
static const QString TagIncrement;
|
2014-02-25 15:02:09 +01:00
|
|
|
static const QString TagDraw;
|
2014-02-25 19:03:17 +01:00
|
|
|
static const QString TagPoint;
|
|
|
|
static const QString TagLine;
|
|
|
|
static const QString TagSpline;
|
|
|
|
static const QString TagArc;
|
|
|
|
static const QString TagTools;
|
2014-02-25 15:02:09 +01:00
|
|
|
static const QString AttrName;
|
2014-02-25 19:03:17 +01:00
|
|
|
static const QString AttrType;
|
2014-03-21 11:08:29 +01:00
|
|
|
static const QString AttrPath;
|
2014-02-25 19:03:17 +01:00
|
|
|
static const QString IncrementName;
|
|
|
|
static const QString IncrementBase;
|
|
|
|
static const QString IncrementKsize;
|
|
|
|
static const QString IncrementKgrowth;
|
|
|
|
static const QString IncrementDescription;
|
2014-03-28 14:11:46 +01:00
|
|
|
virtual bool SaveDocument(const QString &fileName);
|
2014-02-25 15:02:09 +01:00
|
|
|
signals:
|
|
|
|
/**
|
|
|
|
* @brief ChangedActivDraw change active pattern peace.
|
|
|
|
* @param newName new pattern peace name.
|
|
|
|
*/
|
|
|
|
void ChangedActivDraw(const QString &newName);
|
|
|
|
/**
|
|
|
|
* @brief ChangedNameDraw save new name active pattern peace.
|
|
|
|
* @param oldName old name.
|
|
|
|
* @param newName new name.
|
|
|
|
*/
|
|
|
|
void ChangedNameDraw(const QString &oldName, const QString &newName);
|
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromFile update tool data form file.
|
|
|
|
*/
|
|
|
|
void FullUpdateFromFile();
|
|
|
|
/**
|
|
|
|
* @brief patternChanged emit if we have unsaved change.
|
|
|
|
*/
|
|
|
|
void patternChanged();
|
|
|
|
/**
|
|
|
|
* @brief ShowTool highlight tool.
|
|
|
|
* @param id tool id.
|
|
|
|
* @param color highlight color.
|
|
|
|
* @param enable enable or disable highlight.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void ShowTool(quint32 id, Qt::GlobalColor color, bool enable);
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief ChangedCursor change cursor position.
|
|
|
|
* @param id tool id.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void ChangedCursor(quint32 id);
|
2014-02-25 15:02:09 +01:00
|
|
|
public slots:
|
|
|
|
/**
|
|
|
|
* @brief FullUpdateTree lite parse file.
|
|
|
|
*/
|
|
|
|
void FullUpdateTree();
|
|
|
|
/**
|
|
|
|
* @brief haveLiteChange we have unsaved change.
|
|
|
|
*/
|
|
|
|
void haveLiteChange();
|
|
|
|
/**
|
|
|
|
* @brief ShowHistoryTool hightlight tool.
|
|
|
|
* @param id tool id.
|
|
|
|
* @param color hightlight color.
|
|
|
|
* @param enable enable or diasable hightlight.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void ShowHistoryTool(quint32 id, Qt::GlobalColor color, bool enable);
|
2014-02-25 15:02:09 +01:00
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(VPattern)
|
|
|
|
/**
|
|
|
|
* @brief nameActivDraw name current pattern peace.
|
|
|
|
*/
|
|
|
|
QString nameActivDraw;
|
|
|
|
/**
|
|
|
|
* @brief tools list with pointer on tools.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
QHash<quint32, VDataTool*> tools;
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief history history records.
|
|
|
|
*/
|
|
|
|
QVector<VToolRecord> history;
|
|
|
|
/**
|
|
|
|
* @brief cursor cursor keep id tool after which we will add new tool in file.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 cursor;
|
2014-02-25 15:02:09 +01:00
|
|
|
QComboBox *comboBoxDraws;
|
|
|
|
/**
|
|
|
|
* @brief mode current draw mode.
|
|
|
|
*/
|
2014-03-11 12:43:24 +01:00
|
|
|
Valentina::Draws *mode;
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief fileModified true if exist change in file.
|
|
|
|
*/
|
|
|
|
bool patternModified;
|
|
|
|
/**
|
|
|
|
* @brief CheckNameDraw check if exist pattern peace with this name.
|
|
|
|
* @param name pattern peace name.
|
|
|
|
* @return true if exist.
|
|
|
|
*/
|
|
|
|
bool CheckNameDraw(const QString& name) const;
|
|
|
|
/**
|
|
|
|
* @brief SetActivDraw set current pattern peace.
|
|
|
|
* @param name pattern peace name.
|
|
|
|
*/
|
|
|
|
void SetActivDraw(const QString& name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ParseDrawElement parse draw tag.
|
|
|
|
* @param sceneDraw draw scene.
|
|
|
|
* @param sceneDetail details scene.
|
|
|
|
* @param node node.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
*/
|
|
|
|
void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
|
|
|
|
const QDomNode& node, const Document::Documents &parse);
|
|
|
|
/**
|
|
|
|
* @brief ParseDrawMode parse draw tag with draw mode.
|
|
|
|
* @param sceneDraw draw scene.
|
|
|
|
* @param sceneDetail details scene.
|
|
|
|
* @param node node.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param mode draw mode.
|
|
|
|
*/
|
|
|
|
void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
|
2014-03-11 12:43:24 +01:00
|
|
|
const QDomNode& node, const Document::Documents &parse, const Valentina::Draws &mode);
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief ParseDetailElement parse detail tag.
|
|
|
|
* @param sceneDetail detail scene.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
*/
|
|
|
|
void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
|
|
|
|
const Document::Documents &parse);
|
|
|
|
/**
|
|
|
|
* @brief ParseDetails parse details tag.
|
|
|
|
* @param sceneDetail detail scene.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
*/
|
|
|
|
void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
|
|
|
|
const Document::Documents &parse);
|
|
|
|
/**
|
|
|
|
* @brief ParsePointElement parse point tag.
|
|
|
|
* @param scene scene.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param type type of point.
|
|
|
|
* @param mode draw mode.
|
|
|
|
*/
|
|
|
|
void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement,
|
|
|
|
const Document::Documents &parse, const QString &type);
|
|
|
|
/**
|
|
|
|
* @brief ParseLineElement parse line tag.
|
|
|
|
* @param scene scene.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param mode draw mode.
|
|
|
|
*/
|
|
|
|
void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement,
|
|
|
|
const Document::Documents &parse);
|
|
|
|
/**
|
|
|
|
* @brief ParseSplineElement parse spline tag.
|
|
|
|
* @param scene scene.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param type type of spline.
|
|
|
|
* @param mode draw mode.
|
|
|
|
*/
|
|
|
|
void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement,
|
|
|
|
const Document::Documents &parse, const QString& type);
|
|
|
|
/**
|
|
|
|
* @brief ParseArcElement parse arc tag.
|
|
|
|
* @param scene scene.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param type type of spline.
|
|
|
|
* @param mode draw mode.
|
|
|
|
*/
|
|
|
|
void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement,
|
|
|
|
const Document::Documents &parse, const QString& type);
|
|
|
|
/**
|
|
|
|
* @brief ParseToolsElement parse tools tag.
|
|
|
|
* @param scene scene.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param type type of spline.
|
|
|
|
*/
|
|
|
|
void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement,
|
|
|
|
const Document::Documents &parse, const QString& type);
|
|
|
|
/**
|
|
|
|
* @brief ParseIncrementsElement parse increments tag.
|
|
|
|
* @param node tag in xml tree.
|
|
|
|
*/
|
|
|
|
void ParseIncrementsElement(const QDomNode& node);
|
|
|
|
/**
|
|
|
|
* @brief GetParametrId return value id attribute.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @return id value.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 GetParametrId(const QDomElement& domElement) const;
|
2014-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique.
|
|
|
|
* @param node tag in xml tree.
|
|
|
|
* @param vector list with ids.
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
|
2014-02-25 15:02:09 +01:00
|
|
|
void PrepareForParse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw,
|
|
|
|
VMainGraphicsScene *sceneDetail);
|
2014-03-24 16:02:57 +01:00
|
|
|
void UpdateMeasurements();
|
2014-02-25 15:02:09 +01:00
|
|
|
};
|
|
|
|
|
2014-02-26 09:18:59 +01:00
|
|
|
inline QString VPattern::GetNameActivDraw() const
|
|
|
|
{
|
|
|
|
return nameActivDraw;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline QHash<quint32, VDataTool *> *VPattern::getTools()
|
|
|
|
{
|
|
|
|
return &tools;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline QVector<VToolRecord> *VPattern::getHistory()
|
|
|
|
{
|
|
|
|
return &history;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline quint32 VPattern::getCursor() const
|
|
|
|
{
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool VPattern::isPatternModified() const
|
|
|
|
{
|
|
|
|
return patternModified;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void VPattern::setPatternModified(bool value)
|
|
|
|
{
|
|
|
|
patternModified = value;
|
|
|
|
}
|
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
#endif // VPATTERN_H
|