Merge with feature. Fixed issue #332. Issue with deleted details and valentina

file.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-12-26 19:11:44 +02:00
commit 40103a0132
34 changed files with 763 additions and 254 deletions

View File

@ -1790,6 +1790,7 @@ void MainWindow::ActionDraw(bool checked)
leftGoToStage->setPixmap(QPixmap("://icon/24x24/fast_forward_left_to_right_arrow.png"));
rightGoToStage->setPixmap(QPixmap("://icon/24x24/left_to_right_arrow.png"));
ui->actionDraw->setChecked(true);
ui->actionDetails->setChecked(false);
ui->actionLayout->setChecked(false);
SaveCurrentScene();
@ -1868,6 +1869,7 @@ void MainWindow::ActionDetails(bool checked)
rightGoToStage->setPixmap(QPixmap("://icon/24x24/left_to_right_arrow.png"));
ui->actionDraw->setChecked(false);
ui->actionDetails->setChecked(true);
ui->actionLayout->setChecked(false);
SaveCurrentScene();
@ -1955,6 +1957,7 @@ void MainWindow::ActionLayout(bool checked)
ui->actionDraw->setChecked(false);
ui->actionDetails->setChecked(false);
ui->actionLayout->setChecked(true);
SaveCurrentScene();
PrepareDetailsForLayout(details);
@ -2192,7 +2195,7 @@ void MainWindow::Clear()
qCDebug(vMainWindow, "Reseting main window.");
lock.reset();
qCDebug(vMainWindow, "Unlocked pattern file.");
ui->actionDraw->setChecked(true);
ActionDraw(true);
qCDebug(vMainWindow, "Returned to Draw mode.");
pattern->Clear();
qCDebug(vMainWindow, "Clearing pattern.");
@ -2489,9 +2492,7 @@ void MainWindow::Layout()
else
{
listDetails.clear();
ui->actionDetails->setChecked(false);
ui->actionLayout->setChecked(false);
ui->actionDraw->setChecked(true);
ActionDraw(true);
SetLayoutModeActions(false);
}
}
@ -3543,7 +3544,7 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu
//Fit scene size to best size for first show
ZoomFirstShow();
ui->actionDraw->setChecked(true);
ActionDraw(true);
}
qApp->setOpeningPattern();// End opening file
return true;

View File

@ -91,6 +91,13 @@ void VPattern::CreateEmptyFile()
insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild());
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::setXMLContent(const QString &fileName)
{
VDomDocument::setXMLContent(fileName);
GarbageCollector();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Parse parse file.
@ -1896,7 +1903,7 @@ void VPattern::ParseNodeSpline(const QDomElement &domElement, const Document &pa
spl->setIdObject(idObject);
spl->setMode(Draw::Modeling);
data->UpdateGObject(id, spl);
VNodeSpline::Create(this, data, id, idObject, parse, Source::FromFile, idTool);
VNodeSpline::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, idTool);
}
catch (const VExceptionBadId &e)
{
@ -1922,7 +1929,7 @@ void VPattern::ParseNodeSplinePath(const QDomElement &domElement, const Document
path->setIdObject(idObject);
path->setMode(Draw::Modeling);
data->UpdateGObject(id, path);
VNodeSplinePath::Create(this, data, id, idObject, parse, Source::FromFile, idTool);
VNodeSplinePath::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, idTool);
}
catch (const VExceptionBadId &e)
{
@ -1993,7 +2000,7 @@ void VPattern::ParseNodeArc(const QDomElement &domElement, const Document &parse
arc->setIdObject(idObject);
arc->setMode(Draw::Modeling);
data->UpdateGObject(id, arc);
VNodeArc::Create(this, data, id, idObject, parse, Source::FromFile, idTool);
VNodeArc::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, idTool);
}
catch (const VExceptionBadId &e)
{
@ -2111,6 +2118,44 @@ QDomElement VPattern::FindIncrement(const QString &name) const
return QDomElement();
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::GarbageCollector()
{
QDomNodeList modelingList = elementsByTagName(TagModeling);
for (int i=0; i < modelingList.size(); ++i)
{
QDomElement modElement = modelingList.at(i).toElement();
if (not modElement.isNull())
{
QDomElement modNode = modElement.firstChild().toElement();
while (not modNode.isNull())
{
// First get next sibling because later will not have chance to get it
QDomElement nextSibling = modNode.nextSibling().toElement();
if (modNode.hasAttribute(VAbstractNode::AttrInUse))
{
const NodeUsage inUse = GetParametrUsage(modNode, VAbstractNode::AttrInUse);
if (inUse == NodeUsage::InUse)
{ // It is dangerous to leave object with attribute 'inUse'
// Each parse should confirm this status.
modNode.removeAttribute(VAbstractNode::AttrInUse);
}
else
{ // Parent was deleted. We do not need this object anymore
modElement.removeChild(modNode);
}
}
else
{ // Last parse did not confirm use of an object
modElement.removeChild(modNode); // was not used
}
modNode = nextSibling;
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ParseSplineElement parse spline tag.

View File

@ -58,6 +58,7 @@ public:
quint32 SPointActiveDraw();
virtual void setXMLContent(const QString &fileName) Q_DECL_OVERRIDE;
virtual bool SaveDocument(const QString &fileName, QString &error) const Q_DECL_OVERRIDE;
QRectF ActiveDrawBoundingRect() const;
@ -174,6 +175,8 @@ private:
QDomElement MakeEmptyIncrement(const QString &name);
QDomElement FindIncrement(const QString &name) const;
void GarbageCollector();
};
#endif // VPATTERN_H

View File

@ -8,6 +8,7 @@
<file>schema/pattern/v0.2.0.xsd</file>
<file>schema/pattern/v0.2.1.xsd</file>
<file>schema/pattern/v0.2.2.xsd</file>
<file>schema/pattern/v0.2.3.xsd</file>
<file>schema/standard_measurements/v0.3.0.xsd</file>
<file>schema/standard_measurements/v0.4.0.xsd</file>
<file>schema/standard_measurements/v0.4.1.xsd</file>

View File

@ -0,0 +1,416 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- XML Schema Generated from XML Document-->
<xs:element name="pattern">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="version" type="formatVersion"></xs:element>
<xs:element name="unit" type="units"></xs:element>
<xs:element name="author" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="notes" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="gradation" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="heights">
<xs:complexType>
<xs:attribute name="all" type="xs:boolean" use="required"></xs:attribute>
<xs:attribute name="h92" type="xs:boolean"></xs:attribute>
<xs:attribute name="h98" type="xs:boolean"></xs:attribute>
<xs:attribute name="h104" type="xs:boolean"></xs:attribute>
<xs:attribute name="h110" type="xs:boolean"></xs:attribute>
<xs:attribute name="h116" type="xs:boolean"></xs:attribute>
<xs:attribute name="h122" type="xs:boolean"></xs:attribute>
<xs:attribute name="h128" type="xs:boolean"></xs:attribute>
<xs:attribute name="h134" type="xs:boolean"></xs:attribute>
<xs:attribute name="h140" type="xs:boolean"></xs:attribute>
<xs:attribute name="h146" type="xs:boolean"></xs:attribute>
<xs:attribute name="h152" type="xs:boolean"></xs:attribute>
<xs:attribute name="h158" type="xs:boolean"></xs:attribute>
<xs:attribute name="h164" type="xs:boolean"></xs:attribute>
<xs:attribute name="h170" type="xs:boolean"></xs:attribute>
<xs:attribute name="h176" type="xs:boolean"></xs:attribute>
<xs:attribute name="h182" type="xs:boolean"></xs:attribute>
<xs:attribute name="h188" type="xs:boolean"></xs:attribute>
<xs:attribute name="h194" type="xs:boolean"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="sizes">
<xs:complexType>
<xs:attribute name="all" type="xs:boolean" use="required"></xs:attribute>
<xs:attribute name="s22" type="xs:boolean"></xs:attribute>
<xs:attribute name="s24" type="xs:boolean"></xs:attribute>
<xs:attribute name="s26" type="xs:boolean"></xs:attribute>
<xs:attribute name="s28" type="xs:boolean"></xs:attribute>
<xs:attribute name="s30" type="xs:boolean"></xs:attribute>
<xs:attribute name="s32" type="xs:boolean"></xs:attribute>
<xs:attribute name="s34" type="xs:boolean"></xs:attribute>
<xs:attribute name="s36" type="xs:boolean"></xs:attribute>
<xs:attribute name="s38" type="xs:boolean"></xs:attribute>
<xs:attribute name="s40" type="xs:boolean"></xs:attribute>
<xs:attribute name="s42" type="xs:boolean"></xs:attribute>
<xs:attribute name="s44" type="xs:boolean"></xs:attribute>
<xs:attribute name="s46" type="xs:boolean"></xs:attribute>
<xs:attribute name="s48" type="xs:boolean"></xs:attribute>
<xs:attribute name="s50" type="xs:boolean"></xs:attribute>
<xs:attribute name="s52" type="xs:boolean"></xs:attribute>
<xs:attribute name="s54" type="xs:boolean"></xs:attribute>
<xs:attribute name="s56" type="xs:boolean"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="custom" type="xs:boolean"></xs:attribute>
<xs:attribute name="defHeight" type="baseHeight"></xs:attribute>
<xs:attribute name="defSize" type="baseSize"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="measurements" type="xs:string"></xs:element>
<xs:element name="increments" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="increment" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="description" type="xs:string" use="required"></xs:attribute>
<xs:attribute name="name" type="shortName" use="required"></xs:attribute>
<xs:attribute name="formula" type="xs:string" use="required"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="incrementName">
<xs:selector xpath="increment"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
<xs:element name="draw" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="calculation" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="point" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="x" type="xs:double"></xs:attribute>
<xs:attribute name="y" type="xs:double"></xs:attribute>
<xs:attribute name="mx" type="xs:double"></xs:attribute>
<xs:attribute name="my" type="xs:double"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="name" type="shortName"></xs:attribute>
<xs:attribute name="firstPoint" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="secondPoint" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="thirdPoint" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="basePoint" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="pShoulder" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="p1Line" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="p2Line" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="length" type="xs:string"></xs:attribute>
<xs:attribute name="angle" type="xs:string"></xs:attribute>
<xs:attribute name="typeLine" type="xs:string"></xs:attribute>
<xs:attribute name="splinePath" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="spline" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="p1Line1" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="p1Line2" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="p2Line1" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="p2Line2" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="center" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="radius" type="xs:string"></xs:attribute>
<xs:attribute name="axisP1" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="axisP2" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="arc" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="curve" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="lineColor" type="colors"></xs:attribute>
<xs:attribute name="color" type="colors"></xs:attribute>
<xs:attribute name="firstArc" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="secondArc" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="crossPoint" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="c1Center" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="c2Center" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="c1Radius" type="xs:string"></xs:attribute>
<xs:attribute name="c2Radius" type="xs:string"></xs:attribute>
<xs:attribute name="cRadius" type="xs:string"></xs:attribute>
<xs:attribute name="tangent" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="cCenter" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="name1" type="shortName"></xs:attribute>
<xs:attribute name="mx1" type="xs:double"></xs:attribute>
<xs:attribute name="my1" type="xs:double"></xs:attribute>
<xs:attribute name="name2" type="shortName"></xs:attribute>
<xs:attribute name="mx2" type="xs:double"></xs:attribute>
<xs:attribute name="my2" type="xs:double"></xs:attribute>
<xs:attribute name="point1" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="point2" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="dartP1" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="dartP2" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="dartP3" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="baseLineP1" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="baseLineP2" type="xs:unsignedInt"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="line" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="firstPoint" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="secondPoint" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="typeLine" type="xs:string"></xs:attribute>
<xs:attribute name="lineColor" type="colors"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="arc" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="angle1" type="xs:string"></xs:attribute>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="angle2" type="xs:string"></xs:attribute>
<xs:attribute name="radius" type="xs:string"></xs:attribute>
<xs:attribute name="center" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="color" type="colors"></xs:attribute>
<xs:attribute name="length" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="spline" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="pathPoint" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="kAsm2" type="xs:string"></xs:attribute>
<xs:attribute name="pSpline" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="angle" type="xs:string"></xs:attribute>
<xs:attribute name="kAsm1" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="kCurve" type="xs:double"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="kAsm1" type="xs:double"></xs:attribute>
<xs:attribute name="kAsm2" type="xs:double"></xs:attribute>
<xs:attribute name="angle1" type="xs:double"></xs:attribute>
<xs:attribute name="angle2" type="xs:double"></xs:attribute>
<xs:attribute name="point1" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="point4" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="color" type="colors"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="modeling" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="point" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="idObject" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="mx" type="xs:double"></xs:attribute>
<xs:attribute name="typeObject" type="xs:string"></xs:attribute>
<xs:attribute name="my" type="xs:double"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="idTool" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="inUse" type="xs:boolean"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="arc" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="idObject" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="typeObject" type="xs:string"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="idTool" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="inUse" type="xs:boolean"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="spline" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="idObject" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="typeObject" type="xs:string"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="idTool" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="inUse" type="xs:boolean"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="tools" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="det" minOccurs="2" maxOccurs="2">
<xs:complexType>
<xs:sequence>
<xs:element name="node" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="nodeType" type="xs:string"></xs:attribute>
<xs:attribute name="idObject" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="mx" type="xs:double"></xs:attribute>
<xs:attribute name="my" type="xs:double"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="reverse" type="xs:unsignedInt"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="indexD1" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="indexD2" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="inUse" type="xs:boolean"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="details" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="detail" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="node" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="nodeType" type="xs:string"></xs:attribute>
<xs:attribute name="idObject" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="mx" type="xs:double"></xs:attribute>
<xs:attribute name="my" type="xs:double"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="reverse" type="xs:unsignedInt"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:unsignedInt" use="required"></xs:attribute>
<xs:attribute name="supplement" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="mx" type="xs:double"></xs:attribute>
<xs:attribute name="my" type="xs:double"></xs:attribute>
<xs:attribute name="width" type="xs:double"></xs:attribute>
<xs:attribute name="name" type="xs:string"></xs:attribute>
<xs:attribute name="closed" type="xs:unsignedInt"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="shortName">
<xs:restriction base="xs:string">
<xs:pattern value="^([^0-9*/^+\-=\s()?%:;!.,`'\&quot;]){1,1}([^*/^+\-=\s()?%:;!.,`'\&quot;]){0,}$"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="units">
<xs:restriction base="xs:string">
<xs:enumeration value="mm"/>
<xs:enumeration value="cm"/>
<xs:enumeration value="inch"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="measurementsTypes">
<xs:restriction base="xs:string">
<xs:enumeration value="standard"/>
<xs:enumeration value="individual"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="formatVersion">
<xs:restriction base="xs:string">
<xs:pattern value="^(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))$"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="colors">
<xs:restriction base="xs:string">
<xs:enumeration value="black"/>
<xs:enumeration value="green"/>
<xs:enumeration value="blue"/>
<xs:enumeration value="darkRed"/>
<xs:enumeration value="darkGreen"/>
<xs:enumeration value="darkBlue"/>
<xs:enumeration value="yellow"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="baseHeight">
<xs:restriction base="xs:unsignedInt">
<xs:enumeration value="92"/>
<xs:enumeration value="98"/>
<xs:enumeration value="104"/>
<xs:enumeration value="110"/>
<xs:enumeration value="116"/>
<xs:enumeration value="122"/>
<xs:enumeration value="128"/>
<xs:enumeration value="134"/>
<xs:enumeration value="140"/>
<xs:enumeration value="146"/>
<xs:enumeration value="152"/>
<xs:enumeration value="158"/>
<xs:enumeration value="164"/>
<xs:enumeration value="170"/>
<xs:enumeration value="176"/>
<xs:enumeration value="182"/>
<xs:enumeration value="188"/>
<xs:enumeration value="194"/>
<xs:enumeration value="920"/>
<xs:enumeration value="980"/>
<xs:enumeration value="1040"/>
<xs:enumeration value="1100"/>
<xs:enumeration value="1160"/>
<xs:enumeration value="1220"/>
<xs:enumeration value="1280"/>
<xs:enumeration value="1340"/>
<xs:enumeration value="1400"/>
<xs:enumeration value="1460"/>
<xs:enumeration value="1520"/>
<xs:enumeration value="1580"/>
<xs:enumeration value="1640"/>
<xs:enumeration value="1700"/>
<xs:enumeration value="1760"/>
<xs:enumeration value="1820"/>
<xs:enumeration value="1880"/>
<xs:enumeration value="1940"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="baseSize">
<xs:restriction base="xs:unsignedInt">
<xs:enumeration value="22"/>
<xs:enumeration value="24"/>
<xs:enumeration value="26"/>
<xs:enumeration value="28"/>
<xs:enumeration value="30"/>
<xs:enumeration value="32"/>
<xs:enumeration value="34"/>
<xs:enumeration value="36"/>
<xs:enumeration value="38"/>
<xs:enumeration value="40"/>
<xs:enumeration value="42"/>
<xs:enumeration value="44"/>
<xs:enumeration value="46"/>
<xs:enumeration value="48"/>
<xs:enumeration value="50"/>
<xs:enumeration value="52"/>
<xs:enumeration value="54"/>
<xs:enumeration value="56"/>
<xs:enumeration value="220"/>
<xs:enumeration value="240"/>
<xs:enumeration value="260"/>
<xs:enumeration value="280"/>
<xs:enumeration value="300"/>
<xs:enumeration value="320"/>
<xs:enumeration value="340"/>
<xs:enumeration value="360"/>
<xs:enumeration value="380"/>
<xs:enumeration value="400"/>
<xs:enumeration value="420"/>
<xs:enumeration value="440"/>
<xs:enumeration value="460"/>
<xs:enumeration value="480"/>
<xs:enumeration value="500"/>
<xs:enumeration value="520"/>
<xs:enumeration value="540"/>
<xs:enumeration value="560"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -274,6 +274,33 @@ bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString
return val;
}
//---------------------------------------------------------------------------------------------------------------------
NodeUsage VDomDocument::GetParametrUsage(const QDomElement &domElement, const QString &name) const
{
const bool value = GetParametrBool(domElement, name, QStringLiteral("true"));
if (value)
{
return NodeUsage::InUse;
}
else
{
return NodeUsage::NotInUse;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VDomDocument::SetParametrUsage(QDomElement &domElement, const QString &name, const NodeUsage &value)
{
if (value == NodeUsage::InUse)
{
domElement.setAttribute(name, QStringLiteral("true"));
}
else
{
domElement.setAttribute(name, QStringLiteral("false"));
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Returns the string value of the given attribute. RENAME: see above
@ -794,6 +821,7 @@ bool VDomDocument::SafeCopy(const QString &source, const QString &destination, Q
if (result)
{
QFile::remove(destination);
if (not destFile.rename(destination))
{
error = destFile.errorString();

View File

@ -87,13 +87,17 @@ public:
quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue) const;
bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue) const;
NodeUsage GetParametrUsage(const QDomElement& domElement, const QString &name) const;
void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value);
QString GetParametrString(const QDomElement& domElement, const QString &name,
const QString &defValue = QString()) const;
qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const;
quint32 GetParametrId(const QDomElement& domElement) const;
static void ValidateXML(const QString &schema, const QString &fileName);
void setXMLContent(const QString &fileName);
virtual void setXMLContent(const QString &fileName);
static Unit StrToUnits(const QString &unit);
static QString UnitsToStr(const Unit &unit, const bool translate = false);
static QString UnitsHelpString();

View File

@ -43,8 +43,8 @@
*/
const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.2");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.2.xsd");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.3");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.3.xsd");
//---------------------------------------------------------------------------------------------------------------------
VPatternConverter::VPatternConverter(const QString &fileName)
@ -104,6 +104,8 @@ QString VPatternConverter::XSDSchema(int ver) const
case (0x000201):
return QStringLiteral("://schema/pattern/v0.2.1.xsd");
case (0x000202):
return QStringLiteral("://schema/pattern/v0.2.2.xsd");
case (0x000203):
return CurrentSchema;
default:
{
@ -170,6 +172,13 @@ void VPatternConverter::ApplyPatches()
V_FALLTHROUGH
}
case (0x000202):
{
ToV0_2_3();
const QString schema = XSDSchema(0x000203);
ValidateXML(schema, fileName);
V_FALLTHROUGH
}
case (0x000203):
break;
default:
break;
@ -248,6 +257,13 @@ void VPatternConverter::ToV0_2_2()
Save();
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::ToV0_2_3()
{
SetVersion(QStringLiteral("0.2.3"));
Save();
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::TagUnitToV0_2_0()
{

View File

@ -62,6 +62,7 @@ private:
void ToV0_2_0();
void ToV0_2_1();
void ToV0_2_2();
void ToV0_2_3();
void TagUnitToV0_2_0();
void TagIncrementToV0_2_0();

View File

@ -54,6 +54,7 @@ enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Un
enum class MeasurementsType : char { Standard, Individual , Unknown};
enum class Unit : char { Mm = 0, Cm, Inch, Px, LAST_UNIT_DO_NOT_USE};
enum class Source : char { FromGui, FromFile, FromTool };
enum class NodeUsage : bool {NotInUse = false, InUse = true};
typedef unsigned char ToolVisHolderType;
enum class Tool : ToolVisHolderType

View File

@ -292,6 +292,7 @@ void DialogDetail::setDetail(const VDetail &value)
ui.listWidget->setCurrentRow(0);
ui.listWidget->setFocus(Qt::OtherFocusReason);
ui.toolButtonDelete->setEnabled(true);
ValidObjects(DetailIsValid());
}
//---------------------------------------------------------------------------------------------------------------------
@ -490,7 +491,7 @@ bool DialogDetail::DetailIsValid() const
}
if (FirstPointEqualLast())
{
url += tr("First point can not equal the last point!");
url += tr("First point cannot be equal to the last point!");
ui.helpLabel->setText(url);
return false;
}

View File

@ -27,7 +27,7 @@
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Do you really want union details?&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Do you really want to unite details?&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>

View File

@ -47,6 +47,7 @@ public:
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::BasePoint)};
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE;
virtual void decrementReferens() Q_DECL_OVERRIDE;
public slots:
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE;
virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE;
@ -60,7 +61,6 @@ protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE;
virtual void AddToFile() Q_DECL_OVERRIDE;
QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void decrementReferens() Q_DECL_OVERRIDE;
virtual void DeleteTool(bool ask = true) Q_DECL_OVERRIDE;
virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE;
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;

View File

@ -51,23 +51,6 @@ VAbstractNode::VAbstractNode(VAbstractPattern *doc, VContainer *data, const quin
_referens = 0;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractNode::DeleteNode()
{
if (_referens <= 1)
{
RemoveReferens();//deincrement referens
}
}
void VAbstractNode::RestoreNode()
{
if (_referens <= 1)
{
RestoreReferens();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractNode::ShowVisualization(bool show)
{
@ -75,14 +58,19 @@ void VAbstractNode::ShowVisualization(bool show)
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief AddToModeling add tag to modeling tag current pattern peace.
* @param domElement tag.
*/
void VAbstractNode::AddToModeling(const QDomElement &domElement)
void VAbstractNode::incrementReferens()
{
AddDetNode *addNode = new AddDetNode(domElement, doc);
qApp->getUndoStack()->push(addNode);
++_referens;
if (_referens == 1)
{
idTool != NULL_ID ? doc->IncrementReferens(idTool) : doc->IncrementReferens(idNode);
ShowNode();
QDomElement domElement = doc->elementById(id);
if (domElement.isElement())
{
doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::InUse);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -95,43 +83,25 @@ void VAbstractNode::decrementReferens()
{
--_referens;
}
if (_referens <= 0)
if (_referens == 0)
{
doc->DecrementReferens(idNode);
idTool != NULL_ID ? doc->DecrementReferens(idTool) : doc->DecrementReferens(idNode);
HideNode();
QDomElement domElement = doc->elementById(id);
if (domElement.isElement())
{
QDomNode element = domElement.parentNode();
if (element.isNull() == false)
{
element.removeChild(domElement);
}
doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::NotInUse);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractNode::RemoveReferens()
/**
* @brief AddToModeling add tag to modeling tag current pattern peace.
* @param domElement tag.
*/
void VAbstractNode::AddToModeling(const QDomElement &domElement)
{
if (idTool != 0)
{
doc->DecrementReferens(idTool);
}
else
{
doc->DecrementReferens(idNode);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractNode::RestoreReferens()
{
if (idTool != 0)
{
doc->IncrementReferens(idTool);
}
else
{
doc->IncrementReferens(idNode);
}
AddDetNode *addNode = new AddDetNode(domElement, doc);
qApp->getUndoStack()->push(addNode);
}

View File

@ -45,9 +45,9 @@ public:
virtual ~VAbstractNode() Q_DECL_OVERRIDE {}
static const QString AttrIdObject;
static const QString AttrIdTool;
virtual void DeleteNode();
virtual void RestoreNode();
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE;
virtual void incrementReferens() Q_DECL_OVERRIDE;
virtual void decrementReferens() Q_DECL_OVERRIDE;
protected:
/** @brief idNodenode id. */
quint32 idNode;
@ -59,10 +59,10 @@ protected:
QColor currentColor;
void AddToModeling(const QDomElement &domElement);
virtual void decrementReferens() Q_DECL_OVERRIDE;
virtual void RemoveReferens() Q_DECL_OVERRIDE;
virtual void RestoreReferens();
virtual void SetVisualization() {}
virtual void ShowNode()=0;
virtual void HideNode()=0;
};
#endif // VABSTRACTNODE_H

View File

@ -68,25 +68,25 @@ VNodeArc::VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32
* @param idTool tool id.
* @param parent QObject parent
*/
void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse,
const Source &typeCreation, const quint32 &idTool, QObject *parent)
void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, quint32 idArc,
const Document &parse, const Source &typeCreation, const quint32 &idTool, QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodeArc, doc);
if (parse == Document::FullParse)
{
VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, idTool, parent);
// Try to prevent memory leak
arc->hide();// If no one will use node, it will stay hidden
scene->addItem(arc);// First adopted by scene
doc->AddTool(id, arc);
if (idTool != 0)
if (idTool != NULL_ID)
{
doc->IncrementReferens(idTool);
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = doc->getTool(idTool);
SCASSERT(tool != nullptr);
arc->setParent(tool);
}
else
{
doc->IncrementReferens(idArc);
arc->setParent(tool);// Adopted by a tool
}
}
else
@ -95,26 +95,6 @@ void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DeleteNode delete node from detail.
*/
void VNodeArc::DeleteNode()
{
VAbstractNode::DeleteNode();
this->setVisible(false);
}
//---------------------------------------------------------------------------------------------------------------------
void VNodeArc::RestoreNode()
{
if (this->isVisible() == false)
{
VAbstractNode::RestoreNode();
this->setVisible(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VNodeArc::getTagName() const
{
@ -203,6 +183,18 @@ void VNodeArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))));
}
//---------------------------------------------------------------------------------------------------------------------
void VNodeArc::ShowNode()
{
show();
}
//---------------------------------------------------------------------------------------------------------------------
void VNodeArc::HideNode()
{
hide();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshGeometry refresh item on scene.

View File

@ -42,12 +42,11 @@ public:
VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation,
const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr);
static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse,
static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idArc, const Document &parse,
const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr);
static const QString TagName;
static const QString ToolType;
virtual void DeleteNode() Q_DECL_OVERRIDE;
virtual void RestoreNode() Q_DECL_OVERRIDE;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::NodeArc)};
virtual QString getTagName() const Q_DECL_OVERRIDE;
@ -59,6 +58,8 @@ protected:
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void ShowNode() Q_DECL_OVERRIDE;
virtual void HideNode() Q_DECL_OVERRIDE;
private:
void RefreshGeometry();
};

View File

@ -89,19 +89,19 @@ void VNodePoint::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsSc
//TODO Need create garbage collector and remove all nodes, what we don't use.
//Better check garbage before each saving file. Check only modeling tags.
VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, idTool, parent);
// Try to prevent memory leak
point->hide();// If no one will use node, it will stay hidden
scene->addItem(point);// First adopted by scene
connect(scene, &VMainGraphicsScene::EnableToolMove, point, &VNodePoint::EnableToolMove);
doc->AddTool(id, point);
if (idTool != 0)
if (idTool != NULL_ID)
{
doc->IncrementReferens(idTool);
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = doc->getTool(idTool);
SCASSERT(tool != nullptr);
point->setParent(tool);
}
else
{
doc->IncrementReferens(idPoint);
point->setParent(tool);// Adopted by a tool
}
}
else
@ -110,26 +110,6 @@ void VNodePoint::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsSc
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DeleteNode delete node from detail.
*/
void VNodePoint::DeleteNode()
{
VAbstractNode::DeleteNode();
this->setVisible(false);
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::RestoreNode()
{
if (this->isVisible() == false)
{
VAbstractNode::RestoreNode();
this->setVisible(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VNodePoint::getTagName() const
{
@ -291,6 +271,18 @@ void VNodePoint::RefreshLine()
VAbstractTool::RefreshLine(this, namePoint, lineName, radius);
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::ShowNode()
{
show();
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::HideNode()
{
hide();
}
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::EnableToolMove(bool move)
{

View File

@ -53,8 +53,6 @@ public:
const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr);
static const QString TagName;
static const QString ToolType;
virtual void DeleteNode() Q_DECL_OVERRIDE;
virtual void RestoreNode() Q_DECL_OVERRIDE;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::NodePoint)};
virtual QString getTagName() const Q_DECL_OVERRIDE;
@ -81,6 +79,8 @@ protected:
virtual void UpdateNamePosition(qreal mx, qreal my);
virtual void RefreshPointGeometry(const VPointF &point);
void RefreshLine();
virtual void ShowNode() Q_DECL_OVERRIDE;
virtual void HideNode() Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(VNodePoint)
};

View File

@ -69,8 +69,8 @@ VNodeSpline::VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, qu
* @param idTool id node.
* @return pointer to node.
*/
VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline,
const Document &parse,
VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const quint32 &idTool, QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodeSpline, doc);
@ -78,18 +78,18 @@ VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, quint3
if (parse == Document::FullParse)
{
spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, idTool, parent);
// Try to prevent memory leak
spl->hide();// If no one will use node, it will stay hidden
scene->addItem(spl);// First adopted by scene
doc->AddTool(id, spl);
if (idTool != 0)
if (idTool != NULL_ID)
{
doc->IncrementReferens(idTool);
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = doc->getTool(idTool);
SCASSERT(tool != nullptr);
spl->setParent(tool);
}
else
{
doc->IncrementReferens(idSpline);
spl->setParent(tool);// Adopted by a tool
}
}
else
@ -99,26 +99,6 @@ VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, quint3
return spl;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DeleteNode delete node from detail.
*/
void VNodeSpline::DeleteNode()
{
VAbstractNode::DeleteNode();
this->setVisible(false);
}
//---------------------------------------------------------------------------------------------------------------------
void VNodeSpline::RestoreNode()
{
if (this->isVisible() == false)
{
VAbstractNode::RestoreNode();
this->setVisible(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VNodeSpline::getTagName() const
{
@ -206,6 +186,18 @@ void VNodeSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))));
}
//---------------------------------------------------------------------------------------------------------------------
void VNodeSpline::ShowNode()
{
show();
}
//---------------------------------------------------------------------------------------------------------------------
void VNodeSpline::HideNode()
{
hide();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshGeometry refresh item on scene.

View File

@ -42,13 +42,11 @@ public:
VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation,
const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr);
static VNodeSpline *Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline,
const Document &parse,
static VNodeSpline *Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr);
static const QString TagName;
static const QString ToolType;
virtual void DeleteNode() Q_DECL_OVERRIDE;
virtual void RestoreNode() Q_DECL_OVERRIDE;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::NodeSpline)};
virtual QString getTagName() const Q_DECL_OVERRIDE;
@ -60,6 +58,8 @@ protected:
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void ShowNode() Q_DECL_OVERRIDE;
virtual void HideNode() Q_DECL_OVERRIDE;
private:
void RefreshGeometry ();
};

View File

@ -70,30 +70,30 @@ VNodeSplinePath::VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint3
* @param idTool tool id.
* @param parent QObject parent.
*/
void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline,
const Document &parse,
void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const quint32 &idTool, QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodeSplinePath, doc);
if (parse == Document::FullParse)
{
VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool, parent);
// Try to prevent memory leak
splPath->hide();// If no one will use node, it will stay hidden
scene->addItem(splPath);// First adopted by scene
doc->AddTool(id, splPath);
const QSharedPointer<VSplinePath> path = data->GeometricObject<VSplinePath>(id);
const QVector<VSplinePoint> *points = path->GetPoint();
for (qint32 i = 0; i<points->size(); ++i)
{
if (idTool != 0)
if (idTool != NULL_ID)
{
doc->IncrementReferens(idTool);
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = doc->getTool(idTool);
SCASSERT(tool != nullptr);
splPath->setParent(tool);
}
else
{
doc->IncrementReferens(points->at(i).P().id());
splPath->setParent(tool);// Adopted by a tool
}
}
}
@ -103,26 +103,6 @@ void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, quint32 id
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DeleteNode delete node from detail.
*/
void VNodeSplinePath::DeleteNode()
{
VAbstractNode::DeleteNode();
this->setVisible(false);
}
//---------------------------------------------------------------------------------------------------------------------
void VNodeSplinePath::RestoreNode()
{
if (this->isVisible() == false)
{
VAbstractNode::RestoreNode();
this->setVisible(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VNodeSplinePath::getTagName() const
{
@ -210,6 +190,18 @@ void VNodeSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))));
}
//---------------------------------------------------------------------------------------------------------------------
void VNodeSplinePath::ShowNode()
{
show();
}
//---------------------------------------------------------------------------------------------------------------------
void VNodeSplinePath::HideNode()
{
hide();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshGeometry refresh item on scene.

View File

@ -41,12 +41,11 @@ class VNodeSplinePath : public VAbstractNode, public QGraphicsPathItem
public:
VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation,
const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr);
static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Document &parse,
static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id,
quint32 idSpline, const Document &parse,
const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = 0);
static const QString TagName;
static const QString ToolType;
virtual void DeleteNode() Q_DECL_OVERRIDE;
virtual void RestoreNode() Q_DECL_OVERRIDE;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::SplinePath)};
virtual QString getTagName() const Q_DECL_OVERRIDE;
@ -58,6 +57,8 @@ protected:
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void ShowNode() Q_DECL_OVERRIDE;
virtual void HideNode() Q_DECL_OVERRIDE;
private:
void RefreshGeometry();
};

View File

@ -41,6 +41,8 @@
#include <QMessageBox>
#include <QtCore/qmath.h>
const QString VAbstractTool::AttrInUse = QStringLiteral("inUse");
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VAbstractTool container.

View File

@ -56,6 +56,8 @@ public:
virtual ~VAbstractTool() Q_DECL_OVERRIDE;
quint32 getId() const;
static const QString AttrInUse;
static const QStringList StylesList();
static Qt::PenStyle LineStyleToPenStyle(const QString &typeLine);
static QMap<QString, QIcon> LineStylesPics();

View File

@ -98,7 +98,6 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
qDebug()<<"Get wrong tool type. Ignore.";
break;
}
doc->IncrementReferens(detail.at(i).getId());
}
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
@ -168,19 +167,19 @@ void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstrac
case (Tool::NodeArc):
{
id = CreateNode<VArc>(data, nodeD.getId());
VNodeArc::Create(doc, data, id, nodeD.getId(), Document::FullParse, Source::FromGui);
VNodeArc::Create(doc, data, scene, id, nodeD.getId(), Document::FullParse, Source::FromGui);
}
break;
case (Tool::NodeSpline):
{
id = CreateNode<VSpline>(data, nodeD.getId());
VNodeSpline::Create(doc, data, id, nodeD.getId(), Document::FullParse, Source::FromGui);
VNodeSpline::Create(doc, data, scene, id, nodeD.getId(), Document::FullParse, Source::FromGui);
}
break;
case (Tool::NodeSplinePath):
{
id = CreateNode<VSplinePath>(data, nodeD.getId());
VNodeSplinePath::Create(doc, data, id, nodeD.getId(), Document::FullParse, Source::FromGui);
VNodeSplinePath::Create(doc, data, scene, id, nodeD.getId(), Document::FullParse, Source::FromGui);
}
break;
default:
@ -306,7 +305,7 @@ void VToolDetail::AddToFile()
AddNode(doc, domElement, detail.at(i));
}
AddDet *addDet = new AddDet(domElement, doc);
AddDet *addDet = new AddDet(domElement, doc, detail);
connect(addDet, &AddDet::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing);
qApp->getUndoStack()->push(addDet);
}
@ -499,19 +498,6 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RemoveReferens decrement value of reference.
*/
void VToolDetail::RemoveReferens()
{
VDetail detail = VAbstractTool::data.GetDetail(id);
for (int i = 0; i< detail.CountNode(); ++i)
{
doc->DecrementReferens(detail.at(i).getId());
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief AddNode add node to the file.
@ -588,7 +574,7 @@ void VToolDetail::RefreshGeometry()
//---------------------------------------------------------------------------------------------------------------------
void VToolDetail::DeleteTool(bool ask)
{
DeleteDetail *delDet = new DeleteDetail(doc, id);
DeleteDetail *delDet = new DeleteDetail(doc, id, VAbstractTool::data.GetDetail(id));
if (ask)
{
if (ConfirmDeletion() == QMessageBox::No)

View File

@ -100,7 +100,6 @@ protected:
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE;
virtual void RemoveReferens() Q_DECL_OVERRIDE;
virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE;
virtual void SetVisualization() Q_DECL_OVERRIDE {}
private:

View File

@ -64,6 +64,7 @@ VToolUnionDetails::VToolUnionDetails(VAbstractPattern *doc, VContainer *data, co
const Source &typeCreation, QObject *parent)
:VAbstractTool(doc, data, id, parent), d1(d1), d2(d2), indexD1(indexD1), indexD2(indexD2)
{
_referens = 0;
ToolCreation(typeCreation);
}
@ -141,7 +142,7 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene,
arc2->setMode(Draw::Modeling);
id = data->AddGObject(arc2);
VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
VNodeArc::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
}
}
break;
@ -175,7 +176,7 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene,
VSpline *spl1 = new VSpline(*spl);
spl1->setMode(Draw::Modeling);
id = data->AddGObject(spl1);
VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
VNodeSpline::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
delete p4;
delete p1;
@ -230,7 +231,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene,
VSplinePath *path1 = new VSplinePath(*path);
path1->setMode(Draw::Modeling);
id = data->AddGObject(path1);
VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool);
VNodeSplinePath::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, idTool,
tool);
}
}
break;
@ -420,6 +422,57 @@ void VToolUnionDetails::ShowVisualization(bool show)
Q_UNUSED(show)
}
//---------------------------------------------------------------------------------------------------------------------
void VToolUnionDetails::incrementReferens()
{
++_referens;
if (_referens == 1)
{
for (int i = 0; i < d1.CountNode(); ++i)
{
doc->IncrementReferens(d1.at(i).getId());
}
for (int i = 0; i < d2.CountNode(); ++i)
{
doc->IncrementReferens(d2.at(i).getId());
}
QDomElement domElement = doc->elementById(id);
if (domElement.isElement())
{
doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::InUse);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolUnionDetails::decrementReferens()
{
if (_referens > 0)
{
--_referens;
}
if (_referens == 0)
{
for (int i = 0; i < d1.CountNode(); ++i)
{
doc->DecrementReferens(d1.at(i).getId());
}
for (int i = 0; i < d2.CountNode(); ++i)
{
doc->DecrementReferens(d2.at(i).getId());
}
QDomElement domElement = doc->elementById(id);
if (domElement.isElement())
{
doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::NotInUse);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Create help create tool from GUI.
@ -486,15 +539,6 @@ VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d
unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation, doc);
QHash<quint32, VDataTool*>* tools = doc->getTools();
tools->insert(id, unionDetails);
for (int i = 0; i < d1.CountNode(); ++i)
{
doc->IncrementReferens(d1.at(i).getId());
}
for (int i = 0; i < d2.CountNode(); ++i)
{
doc->IncrementReferens(d2.at(i).getId());
}
}
//Then create new details
VNodeDetail det1p1;

View File

@ -79,6 +79,8 @@ public:
const qreal &angle);
virtual QString getTagName() const Q_DECL_OVERRIDE;
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE;
virtual void incrementReferens() Q_DECL_OVERRIDE;
virtual void decrementReferens() Q_DECL_OVERRIDE;
public slots:
/**
* @brief FullUpdateFromFile update tool data form file.

View File

@ -29,8 +29,8 @@
#include "adddet.h"
//---------------------------------------------------------------------------------------------------------------------
AddDet::AddDet(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent)
: VUndoCommand(xml, doc, parent)
AddDet::AddDet(const QDomElement &xml, VAbstractPattern *doc, const VDetail &detail, QUndoCommand *parent)
: VUndoCommand(xml, doc, parent), detail(detail)
{
setText(tr("add detail"));
nodeId = doc->GetParametrId(xml);
@ -57,6 +57,15 @@ void AddDet::undo()
qCDebug(vUndo, "Can't delete node");
return;
}
QVector<VNodeDetail> nodes = detail.getNodes();
if (nodes.size()>0)
{
for (qint32 i = 0; i < nodes.size(); ++i)
{
doc->DecrementReferens(nodes.at(i).getId());
}
}
}
else
{

View File

@ -30,12 +30,13 @@
#define ADDDET_H
#include "vundocommand.h"
#include "../tools/vtooldetail.h"
class AddDet : public VUndoCommand
{
Q_OBJECT
public:
AddDet(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = 0);
AddDet(const QDomElement &xml, VAbstractPattern *doc, const VDetail &detail, QUndoCommand *parent = 0);
virtual ~AddDet() Q_DECL_OVERRIDE;
// cppcheck-suppress unusedFunction
virtual void undo() Q_DECL_OVERRIDE;
@ -43,6 +44,7 @@ public:
virtual void redo() Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(AddDet)
VDetail detail;
};
#endif // ADDDET_H

View File

@ -30,8 +30,8 @@
#include "../tools/vtooldetail.h"
//---------------------------------------------------------------------------------------------------------------------
DeleteDetail::DeleteDetail(VAbstractPattern *doc, quint32 id, QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID)
DeleteDetail::DeleteDetail(VAbstractPattern *doc, quint32 id, const VDetail &detail, QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID), detail(detail)
{
setText(tr("delete tool"));
nodeId = id;
@ -89,6 +89,15 @@ void DeleteDetail::redo()
SCASSERT(toolDet != nullptr);
toolDet->hide();
QVector<VNodeDetail> nodes = detail.getNodes();
if (nodes.size()>0)
{
for (qint32 i = 0; i < nodes.size(); ++i)
{
doc->DecrementReferens(nodes.at(i).getId());
}
}
emit NeedFullParsing(); // Doesn't work when UnionDetail delete detail.
}
else

View File

@ -30,13 +30,15 @@
#define DELETEDETAIL_H
#include "vundocommand.h"
#include "../tools/vtooldetail.h"
class QGraphicsItem;
class DeleteDetail : public VUndoCommand
{
Q_OBJECT
public:
DeleteDetail(VAbstractPattern *doc, quint32 id, QUndoCommand *parent = 0);
DeleteDetail(VAbstractPattern *doc, quint32 id, const VDetail &detail, QUndoCommand *parent = 0);
virtual ~DeleteDetail() Q_DECL_OVERRIDE;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
@ -44,6 +46,7 @@ private:
Q_DISABLE_COPY(DeleteDetail)
QDomNode parentNode;
quint32 siblingId;
VDetail detail;
};
#endif // DELETEDETAIL_H

View File

@ -60,13 +60,10 @@ void SaveDetailOptions::undo()
VToolDetail::AddNode(doc, domElement, oldDet.at(i));
}
QVector<VNodeDetail> nodes = oldDet.getNodes();
QHash<quint32, VDataTool*>* tools = doc->getTools();
if (nodes.size()>0)
{
for (qint32 i = 0; i < nodes.size(); ++i)
{
VAbstractNode *node = qobject_cast<VAbstractNode *>(tools->value(nodes.at(i).getId()));
node->RestoreNode();
doc->IncrementReferens(nodes.at(i).getId());
}
}
@ -94,13 +91,10 @@ void SaveDetailOptions::redo()
VToolDetail::AddNode(doc, domElement, newDet.at(i));
}
QList<quint32> list = oldDet.Missing(newDet);
QHash<quint32, VDataTool*>* tools = doc->getTools();
if (list.size()>0)
{
for (qint32 i = 0; i < list.size(); ++i)
{
VAbstractNode *node = qobject_cast<VAbstractNode *>(tools->value(list.at(i)));
node->DeleteNode();
doc->DecrementReferens(list.at(i));
}
}