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)); correctPoints.append(points.at(i));
} }
} }
if(correctPoints.size()<3) // if(correctPoints.size()<3)
{ // {
return correctPoints; // return correctPoints;
} // }
//Remove point on line // //Remove point on line
QPointF point; // QPointF point;
for(qint32 i = 1; i <correctPoints.size()-1; ++i) // for(qint32 i = 1; i <correctPoints.size()-1; ++i)
{ // {
QLineF l1(correctPoints[i-1], correctPoints[i]); // QLineF l1(correctPoints[i-1], correctPoints[i]);
QLineF l2(correctPoints[i], correctPoints[i+1]); // QLineF l2(correctPoints[i], correctPoints[i+1]);
QLineF::IntersectType intersect = l1.intersect(l2, &point); // QLineF::IntersectType intersect = l1.intersect(l2, &point);
if (intersect == QLineF::NoIntersection) // if (intersect == QLineF::NoIntersection)
{ // {
correctPoints.remove(i); // correctPoints.remove(i);
} // }
} // }
return correctPoints; return correctPoints;
} }

View File

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

View File

@ -511,6 +511,7 @@ private:
Draw::Draws mode; Draw::Draws mode;
qint32 currentDrawIndex; qint32 currentDrawIndex;
qint32 currentToolBoxIndex; qint32 currentToolBoxIndex;
bool drawMode;
/** /**
* @brief ToolBarOption * @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(AttrMx, QString().setNum(toMM(newPos.x())));
domElement.setAttribute(AttrMy, QString().setNum(toMM(newPos.y()))); 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(); 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); BiasRotatePoint(p1, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
qint64 idP1 = data->AddGObject(p1); 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); 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); BiasRotatePoint(&p3, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
VPointF *p4 = new VPointF(spline->GetP4()); 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); BiasRotatePoint(p4, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
qint64 idP4 = data->AddGObject(p4); 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); Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
idObject = data->AddGObject(spl); idObject = data->AddGObject(spl);
VSpline *spl1 = new VSpline(*spl); VSpline *spl1 = new VSpline(*spl);
@ -208,10 +208,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai
if (i==1) if (i==1)
{ {
path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), 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(), path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180,
splinePath->at(i).KAsm1())); splinePath->at(i).KAsm2()));
} }
while(k>=0) while(k>=0)
{ {
@ -310,9 +310,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
++idCount; ++idCount;
data->UpdateGObject(idDetail+idCount, p4); 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); Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
++idCount; ++idCount;
data->UpdateGObject(idDetail+idCount, spl); data->UpdateGObject(idDetail+idCount, spl);
@ -364,10 +365,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
if (i==1) if (i==1)
{ {
path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), 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(), path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180,
splinePath->at(i).KAsm1())); splinePath->at(i).KAsm2()));
} }
while(k>=0) while(k>=0)

View File

@ -31,10 +31,14 @@
#include <QtWidgets> #include <QtWidgets>
VMainGraphicsScene::VMainGraphicsScene() 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) 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) void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{ {