Bug in uniontool with splinepath.

--HG--
branch : feature
This commit is contained in:
dismine 2014-01-12 21:23:44 +02:00
parent 48d324e8c6
commit 8a2639b7aa
6 changed files with 90 additions and 39 deletions

View file

@ -241,22 +241,22 @@ QVector<QPointF> VContainer::CorrectEquidistantPoints(const QVector<QPointF> &po
correctPoints.append(points.at(i));
}
}
if(correctPoints.size()<3)
{
return correctPoints;
}
//Remove point on line
QPointF point;
for(qint32 i = 1; i <correctPoints.size()-1; ++i)
{
QLineF l1(correctPoints[i-1], correctPoints[i]);
QLineF l2(correctPoints[i], correctPoints[i+1]);
QLineF::IntersectType intersect = l1.intersect(l2, &point);
if (intersect == QLineF::NoIntersection)
{
correctPoints.remove(i);
}
}
// if(correctPoints.size()<3)
// {
// return correctPoints;
// }
// //Remove point on line
// QPointF point;
// for(qint32 i = 1; i <correctPoints.size()-1; ++i)
// {
// QLineF l1(correctPoints[i-1], correctPoints[i]);
// QLineF l2(correctPoints[i], correctPoints[i+1]);
// QLineF::IntersectType intersect = l1.intersect(l2, &point);
// if (intersect == QLineF::NoIntersection)
// {
// correctPoints.remove(i);
// }
// }
return correctPoints;
}

View file

@ -60,7 +60,7 @@ MainWindow::MainWindow(QWidget *parent)
dialogCutSpline(QSharedPointer<DialogCutSpline>()), dialogCutSplinePath (QSharedPointer<DialogCutSplinePath>()),
dialogUnionDetails(QSharedPointer<DialogUnionDetails>()), dialogCutArc(QSharedPointer<DialogCutArc>()),
dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false),
mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0)
mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true)
{
ui->setupUi(this);
static const char * GENERIC_ICON_TO_CHECK = "document-open";
@ -709,11 +709,14 @@ void MainWindow::currentDrawChanged( int index )
{
doc->setCurrentData();
doc->ChangeActivDraw(comboBoxDraws->itemText(index));
qint64 id = doc->SPointActiveDraw();
if (id != 0)
if(drawMode)
{
const VPointF *p = pattern->GeometricObject<const VPointF *>(id);
view->centerOn(p->toQPointF());
qint64 id = doc->SPointActiveDraw();
if (id != 0)
{
const VPointF *p = pattern->GeometricObject<const VPointF *>(id);
view->centerOn(p->toQPointF());
}
}
}
}
@ -920,6 +923,7 @@ void MainWindow::ActionDraw(bool checked)
mode = Draw::Calculation;
comboBoxDraws->setEnabled(true);
comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace
drawMode = true;
SetEnableTool(true);
doc->setCurrentData();
@ -942,10 +946,12 @@ void MainWindow::ActionDetails(bool checked)
view->setScene(sceneDetails);
RestoreCurrentScene();
drawMode = false;
currentDrawIndex = comboBoxDraws->currentIndex();//save current pattern peace
comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1);
comboBoxDraws->setEnabled(false);
mode = Draw::Modeling;
SetEnableTool(true);
currentToolBoxIndex = ui->toolBox->currentIndex();
@ -1014,10 +1020,26 @@ void MainWindow::ActionOpen()
if (fileName.isEmpty() && changeInFile == false)
{
OpenPattern(fName);
sceneDraw->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(),
view->contentsRect().height()-view->contentsRect().y()));
sceneDetails->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(),
view->contentsRect().height()-view->contentsRect().y()));
QRectF rect = sceneDraw->itemsBoundingRect();
//Correct BoundingRect
rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y());
QRect rec = view->contentsRect();
//Correct contentsRect
rec = QRect(0, 0, rec.width() - rec.x(), rec.height() - rec.y());
if(rec.contains(rect.toRect()))
{
sceneDraw->setSceneRect(rec);
sceneDetails->setSceneRect(rec);
}
else
{
rect = rect.united(rec);
sceneDraw->setSceneRect(rect);
sceneDetails->setSceneRect(rect);
}
}
else
{

View file

@ -511,6 +511,7 @@ private:
Draw::Draws mode;
qint32 currentDrawIndex;
qint32 currentToolBoxIndex;
bool drawMode;
/**
* @brief ToolBarOption
*/

View file

@ -247,6 +247,29 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const
{
domElement.setAttribute(AttrMx, QString().setNum(toMM(newPos.x())));
domElement.setAttribute(AttrMy, QString().setNum(toMM(newPos.y())));
QGraphicsScene *sc = this->scene();
QRectF rect = sc->itemsBoundingRect();
//Correct BoundingRect
rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y());
qDebug()<<"rect"<<rect;
QList<QGraphicsView*> list = sc->views();
QRect rec = list[0]->contentsRect();
qDebug()<<"rec"<<rec;
//Correct contentsRect
rec = QRect(0, 0, rec.width() - rec.x(), rec.height() - rec.y());
if(rec.contains(rect.toRect()))
{
sc->setSceneRect(rec);
}
else
{
rect = rect.united(rec);
sc->setSceneRect(rect);
}
doc->haveLiteChange();
}
}

View file

@ -139,10 +139,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai
BiasRotatePoint(p1, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
qint64 idP1 = data->AddGObject(p1);
VPointF p2 = VPointF(spline->GetP2().x(), spline->GetP2().y(), "A", 0, 0);
VPointF p2 = VPointF(spline->GetP2());
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
VPointF p3 = VPointF(spline->GetP3().x(), spline->GetP3().y(), "A", 0, 0);
VPointF p3 = VPointF(spline->GetP3());
BiasRotatePoint(&p3, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
VPointF *p4 = new VPointF(spline->GetP4());
@ -150,9 +150,9 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai
BiasRotatePoint(p4, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
qint64 idP4 = data->AddGObject(p4);
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve());
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
Draw::Modeling);
Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
idObject = data->AddGObject(spl);
VSpline *spl1 = new VSpline(*spl);
@ -208,10 +208,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai
if (i==1)
{
path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(),
splinePath->at(i-1).KAsm1()));
splinePath->at(i-1).KAsm2()));
}
path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(),
splinePath->at(i).KAsm1()));
path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180,
splinePath->at(i).KAsm2()));
}
while(k>=0)
{
@ -310,9 +310,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
++idCount;
data->UpdateGObject(idDetail+idCount, p4);
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve());
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
Draw::Modeling);
Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
++idCount;
data->UpdateGObject(idDetail+idCount, spl);
@ -364,10 +365,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
if (i==1)
{
path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(),
splinePath->at(i-1).KAsm1()));
splinePath->at(i-1).KAsm2()));
}
path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(),
splinePath->at(i).KAsm1()));
path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180,
splinePath->at(i).KAsm2()));
}
while(k>=0)

View file

@ -31,10 +31,14 @@
#include <QtWidgets>
VMainGraphicsScene::VMainGraphicsScene()
:QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){}
:QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform())
{
}
VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent)
:QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){}
:QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform())
{
}
void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{