Fixed issue #263. Regression. Union tool doesn't work.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-03-31 13:39:10 +03:00
parent 8c5ea079d7
commit 478dbe13dd
6 changed files with 18 additions and 79 deletions

View File

@ -236,7 +236,7 @@ void VContainer::ClearGObjects()
//---------------------------------------------------------------------------------------------------------------------
void VContainer::ClearCalculationGObjects()
{
if (d->gObjects.size()>0)
if (not d->gObjects.isEmpty())
{
QVector<quint32> keys;
QHash<quint32, QSharedPointer<VGObject> >::iterator i;
@ -248,7 +248,8 @@ void VContainer::ClearCalculationGObjects()
keys.append(i.key());
}
}
if (keys.size()>0)
// We can't delete objects in previous loop it will destroy the iterator.
if (not keys.isEmpty())
{
for (int i = 0; i < keys.size(); ++i)
{
@ -324,7 +325,7 @@ template <typename key, typename val>
quint32 VContainer::AddObject(QHash<key, val> &obj, val value)
{
SCASSERT(value != nullptr);
quint32 id = getNextId();
const quint32 id = getNextId();
value->setId(id);
obj[id] = value;
return id;

View File

@ -226,18 +226,6 @@ QPointF VSplinePath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF
return QPointF();
}
//---------------------------------------------------------------------------------------------------------------------
qint32 VSplinePath::getMaxCountPoints() const
{
return d->maxCountPoints;
}
//---------------------------------------------------------------------------------------------------------------------
void VSplinePath::setMaxCountPoints(const qint32 &value)
{
d->maxCountPoints = value;
}
//---------------------------------------------------------------------------------------------------------------------
int VSplinePath::Segment(const QPointF &p) const
{

View File

@ -173,18 +173,6 @@ public:
*/
QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2,
QPointF &spl2p3) const;
/**
* @brief getMaxCountPoints return max count of points what can have spline path. This method use tool union detail.
* Because cutting point can change position spline can have diffirent count of points. Need know max value. This
* value stored from cuted spline path.
* @return count.
*/
qint32 getMaxCountPoints() const;
/**
* @brief setMaxCountPoints set max count points from cuted spline path.
* @param value max count.
*/
void setMaxCountPoints(const qint32 &value);
int Segment(const QPointF &p) const;
private:

View File

@ -43,15 +43,15 @@ class VSplinePathData : public QSharedData
public:
VSplinePathData()
: path(QVector<VSplinePoint>()), kCurve(1), maxCountPoints(0)
: path(QVector<VSplinePoint>()), kCurve(1)
{}
VSplinePathData(qreal kCurve)
: path(QVector<VSplinePoint>()), kCurve(kCurve), maxCountPoints(0)
: path(QVector<VSplinePoint>()), kCurve(kCurve)
{}
VSplinePathData(const VSplinePathData &splPath)
: QSharedData(splPath), path(splPath.path), kCurve(splPath.kCurve), maxCountPoints(splPath.maxCountPoints)
: QSharedData(splPath), path(splPath.path), kCurve(splPath.kCurve)
{}
virtual ~VSplinePathData();
@ -64,10 +64,6 @@ public:
* @brief kCurve coefficient of curvature spline.
*/
qreal kCurve;
/**
* @brief maxCountPoints max count of points what can have spline path.
*/
qint32 maxCountPoints;
};
VSplinePathData::~VSplinePathData()

View File

@ -197,9 +197,6 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString
splPath1->SetKCurve(splPath->GetKCurve());
splPath2->SetKCurve(splPath->GetKCurve());
splPath1->setMaxCountPoints(splPath->CountPoint());
splPath2->setMaxCountPoints(splPath->CountPoint());
if (typeCreation == Source::FromGui)
{
splPath1id = data->AddGObject(splPath1);

View File

@ -164,7 +164,6 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VPattern *doc, VContainer
VPointF *p1 = new VPointF(spline->GetP1());
BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
//quint32 idP1 = data->AddGObject(p1);
VPointF p2 = VPointF(spline->GetP2());
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
@ -174,7 +173,6 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VPattern *doc, VContainer
VPointF *p4 = new VPointF(spline->GetP4());
BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
//quint32 idP4 = data->AddGObject(p4);
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
Draw::Modeling);
@ -201,8 +199,6 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VPattern *doc, VContainer
VSplinePath *path = new VSplinePath();
path->setMode(Draw::Modeling);
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
qint32 k = splinePath->getMaxCountPoints();
SCASSERT (k >= 3)
for (qint32 i = 1; i <= splinePath->Count(); ++i)
{
VSpline spline(splinePath->at(i-1).P(), splinePath->at(i).P(),
@ -211,8 +207,6 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VPattern *doc, VContainer
VPointF *p1 = new VPointF(spline.GetP1());
BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
//quint32 idP1 = data->AddGObject(p1);
--k;
VPointF p2 = VPointF(spline.GetP2());
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
@ -222,8 +216,6 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VPattern *doc, VContainer
VPointF *p4 = new VPointF(spline.GetP4());
BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
//quint32 idP4 = data->AddGObject(p4);
--k;
VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve());
if (i==1)
@ -236,11 +228,6 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VPattern *doc, VContainer
delete p4;
delete p1;
}
while (k>=0)
{
data->getNextId();
--k;
}
idObject = data->AddGObject(path);
VSplinePath *path1 = new VSplinePath(*path);
@ -283,10 +270,10 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data,
VPointF *point = new VPointF(*data->GeometricObject<VPointF>(det.at(i).getId()));
point->setMode(Draw::Modeling);
BiasRotatePoint(point, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
++idCount;
++idCount;// For parent
data->UpdateGObject(idDetail+idCount, point);
++idCount;
++idCount;// For child
}
}
break;
@ -297,24 +284,24 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data,
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(det.at(i).getId());
VPointF p1 = VPointF(arc->GetP1());
BiasRotatePoint(&p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
VPointF p2 = VPointF(arc->GetP2());
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
VPointF *center = new VPointF(arc->GetCenter());
BiasRotatePoint(center, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
angle);
QLineF l1(center->toQPointF(), p1.toQPointF());
QLineF l2(center->toQPointF(), p2.toQPointF());
++idCount;
center->setMode(Draw::Modeling);
data->UpdateGObject(idDetail+idCount, center);
VArc *arc1 = new VArc(*center, arc->GetRadius(), arc->GetFormulaRadius(), l1.angle(),
QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle()));
arc1->setMode(Draw::Modeling);
++idCount;
++idCount;// For parent
data->UpdateGObject(idDetail+idCount, arc1);
++idCount;
++idCount;// For child
}
}
break;
@ -326,8 +313,6 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data,
VPointF *p1 = new VPointF(spline->GetP1());
BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
++idCount;
data->UpdateGObject(idDetail+idCount, p1);
VPointF p2 = VPointF(spline->GetP2());
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
@ -337,16 +322,14 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data,
VPointF *p4 = new VPointF(spline->GetP4());
BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(), angle);
++idCount;
data->UpdateGObject(idDetail+idCount, p4);
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
Draw::Modeling);
++idCount;
++idCount;// For parent
data->UpdateGObject(idDetail+idCount, spl);
++idCount;
++idCount;// For child
}
}
break;
@ -358,7 +341,6 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data,
path->setMode(Draw::Modeling);
const QSharedPointer<VSplinePath> splinePath = data->GeometricObject<VSplinePath>(det.at(i).getId());
SCASSERT(splinePath != nullptr);
qint32 k = splinePath->getMaxCountPoints();
for (qint32 i = 1; i <= splinePath->Count(); ++i)
{
VSpline spline(splinePath->at(i-1).P(), splinePath->at(i).P(),
@ -368,9 +350,6 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data,
VPointF *p1 = new VPointF(spline.GetP1());
BiasRotatePoint(p1, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
angle);
++idCount;
data->UpdateGObject(idDetail+idCount, p1);
--k;
VPointF p2 = VPointF(spline.GetP2());
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
@ -383,9 +362,6 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data,
VPointF *p4 = new VPointF(spline.GetP4());
BiasRotatePoint(p4, dx, dy, data->GeometricObject<VPointF>(pRotate)->toQPointF(),
angle);
++idCount;
data->UpdateGObject(idDetail+idCount, p4);
--k;
VSpline spl = VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline.GetKcurve());
if (i==1)
@ -397,17 +373,10 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data,
splinePath->at(i).KAsm2(), spl.GetAngle2()+180));
}
while (k>=0)
{
data->getNextId();
--k;
++idCount;
}
++idCount;
++idCount;//For parent
data->UpdateGObject(idDetail+idCount, path);
++idCount;
++idCount;// For child
}
}
break;