Commit e3a32ea8 authored by denis's avatar denis

Turtle pos buffering

parent 45ecdd6d
......@@ -220,7 +220,7 @@
"WallColor": {
"order": 4,
"type": "color",
"default": "#C8C800",
"default": "#C8C810",
"title": {"ascii": "Wall color", "ru_RU": "Цвет стен"}
},
"NormalColor": {
......
......@@ -5047,7 +5047,9 @@ void RobotModule::editEnv()
field->setMode(NEDIT_MODE);
startField->setModeFlag(NORMAL_MODE);
setWindowSize();
setWindowSize();
reloadSettings(robotSettings(), QStringList());
field->update();
};
void RobotModule::createEmptyField(int rows,int cols)
{
......
......@@ -336,7 +336,7 @@ void TurtlePult::Up()
turtleObj->runForward(stepVal->value ());
Logger->appendText(QString::fromUtf8("вперед(")+QString::number(stepVal->value ())+")\n",QString::fromUtf8("вперед(")+QString::number(stepVal->value ())+")","OK");
turtleObj->getCurView()->forceRedraw();
turtleObj->updateTurtle();
};
......@@ -347,14 +347,14 @@ void TurtlePult::Down()
turtleObj->runBack(stepVal->value ());
Logger->appendText(QString::fromUtf8("назад(")+QString::number(stepVal->value ())+")\n",QString::fromUtf8("назад(")+QString::number(stepVal->value ())+")","OK");
turtleObj->getCurView()->forceRedraw();
turtleObj->updateTurtle();
};
void TurtlePult::Left()
{
turtleObj->runLeft(gradVal->value ());
Logger->appendText(QString::fromUtf8("влево(")+QString::number(gradVal->value ())+")\n",QString::fromUtf8("влево(")+QString::number(gradVal->value ())+")","OK");
turtleObj->getCurView()->forceRedraw();
turtleObj->updateTurtle();
};
void TurtlePult::Right()
......@@ -363,7 +363,7 @@ void TurtlePult::Right()
turtleObj->runRight(gradVal->value ());
Logger->appendText(QString::fromUtf8("вправо(")+QString::number(gradVal->value ())+")\n",QString::fromUtf8("вправо(")+QString::number(gradVal->value ())+")","OK");
turtleObj->getCurView()->forceRedraw();
turtleObj->updateTurtle();
};
void TurtlePult::SwStena()
......
......@@ -943,8 +943,12 @@ QString TurtleModule::initialize(const QStringList &configurationParameters, con
Q_UNUSED(current); // Remove this line on implementation
usleep(10);
CurScene->fromBufferToScene();
CurScene->fromBufferToScene();
mPen->setTransform(QTransform().translate(AncX*CurView->zoom(), AncY*CurView->zoom()).rotate(curAngle).translate(-AncX*CurView->zoom(), -AncY*CurView->zoom()));
mPen->setPos(mPen->penPos());
mPen->show();
currentState=current;
CurView->setViewportUpdateMode (QGraphicsView::FullViewportUpdate);
CurView->setViewportUpdateMode (QGraphicsView::SmartViewportUpdate);
CurView->forceRedraw();
CurScene->update(CurScene->sceneRect());
CurView->repaint();
......@@ -1002,6 +1006,7 @@ QString TurtleModule::initialize(const QStringList &configurationParameters, con
mPen->tailUp();
penIsDrawing=false;
mPen->setPos(0,0);
mPen->resetPen();
mPen->setRotation(0);
curAngle=0;
mPen->setTransform(QTransform().translate(AncX*CurView->zoom(), AncY*CurView->zoom()).rotate(curAngle).translate(-AncX*CurView->zoom(), -AncY*CurView->zoom()));
......@@ -1051,29 +1056,32 @@ mutex.unlock();
{
// if(animation)msleep(50);
mutex.lock();
qreal oldX=mPen->pos().x();
qreal oldY=mPen->pos().y();
qreal oldX=mPen->penPos().x();
qreal oldY=mPen->penPos().y();
qreal moveX=dist*sin(curAngle*(Pi/180));
qreal moveY=-dist*cos(curAngle*(Pi/180));
qreal curX,curY;
curX=mPen->pos().x()+dist*sin(curAngle*(Pi/180));
curY=mPen->pos().y()-dist*cos(curAngle*(Pi/180));
curX=mPen->penPos().x()+dist*sin(curAngle*(Pi/180));
curY=mPen->penPos().y()-dist*cos(curAngle*(Pi/180));
mPen->moveBy(moveX,moveY);
// mPen->moveBy(moveX,moveY);
mPen->movePen(moveX, moveY);
//t2->moveBy(moveX,moveY);
//t3->moveBy(moveX,moveY);
if(!mPen->isTailUp()) CurScene->addDrawLine(QLineF(QPointF(oldX,oldY),mPen->pos()), QColor(penColor.r, penColor.g, penColor.b, penColor.a),mySettings()->value("LineWidth",4).toFloat());
if(!mPen->isTailUp()) CurScene->addDrawLine(QLineF(QPointF(oldX,oldY),mPen->penPos()), QColor(penColor.r, penColor.g, penColor.b, penColor.a),mySettings()->value("LineWidth",4).toFloat());
// CurScene->update();
mutex.unlock();
int bsize=maxBuff;
while(bsize>maxBuff-1)
{
usleep(1);
mutex.lock();
bsize=CurScene->buffSize();
mutex.unlock();
}
}
......@@ -1081,29 +1089,30 @@ mutex.unlock();
/* public slot */ void TurtleModule::runBack(const qreal dist)
{
mutex.lock();
qreal oldX=mPen->pos().x();
qreal oldY=mPen->pos().y();
qreal oldX=mPen->penPos().x();
qreal oldY=mPen->penPos().y();
qreal moveX=-dist*sin(curAngle*(Pi/180));
qreal moveY=dist*cos(curAngle*(Pi/180));
qreal curX,curY;
curX=mPen->pos().x()-dist*sin(curAngle*(Pi/180));
curY=mPen->pos().y()+dist*cos(curAngle*(Pi/180));
curX=mPen->penPos().x()-dist*sin(curAngle*(Pi/180));
curY=mPen->penPos().y()+dist*cos(curAngle*(Pi/180));
mPen->moveBy(moveX,moveY);
mPen->movePen(moveX,moveY);
//t2->moveBy(moveX,moveY);
//t3->moveBy(moveX,moveY);
if(!mPen->isTailUp()) CurScene->addDrawLine(QLineF(QPointF(oldX,oldY),mPen->pos()), QColor(penColor.r, penColor.g, penColor.b, penColor.a),mySettings()->value("LineWidth",4).toFloat());
if(!mPen->isTailUp()) CurScene->addDrawLine(QLineF(QPointF(oldX,oldY),mPen->penPos()), QColor(penColor.r, penColor.g, penColor.b, penColor.a),mySettings()->value("LineWidth",4).toFloat());
mutex.unlock();
// CurScene->update();
int bsize=maxBuff;
while(bsize>maxBuff-1)
{
{ usleep(1);
mutex.lock();
bsize=CurScene->buffSize();
mutex.unlock();
}
}
......@@ -1115,11 +1124,11 @@ mutex.unlock();
curAngle=curAngle-angle;
if(curAngle<0)curAngle=360+curAngle;
if(curAngle>360)curAngle=curAngle-360;
mPen->setTransform(QTransform().translate(AncX*CurView->zoom(), AncY*CurView->zoom()).rotate(curAngle).translate(-AncX*CurView->zoom(), -AncY*CurView->zoom()));
// Turtle->rotate();
mutex.unlock();
CurScene->update();
// CurScene->update();
}
......@@ -1130,11 +1139,11 @@ mutex.unlock();
curAngle=curAngle+angle;
if(curAngle<0)curAngle=360+curAngle;
if(curAngle>360)curAngle=curAngle-360;
mPen->setTransform(QTransform().translate(AncX*CurView->zoom(), AncY*CurView->zoom()).rotate(curAngle).translate(-AncX*CurView->zoom(), -AncY*CurView->zoom()));
//mPen->setTransform(QTransform().translate(AncX*CurView->zoom(), AncY*CurView->zoom()).rotate(curAngle).translate(-AncX*CurView->zoom(), -AncY*CurView->zoom()));
// Turtle->rotate();
mutex.unlock();
CurScene->update();
//CurScene->update();
}
/* public slot */ void TurtleModule::runSetPenColor(const Color& color)
......@@ -1334,15 +1343,22 @@ mutex.unlock();
CurView->update();
CurView->forceRedraw();
};
void TurtleModule::redraw()
void TurtleModule::updateTurtle()
{
if (currentState!=Shared::PluginInterface::GS_Running)return;
mutex.lock();
CurScene->fromBufferToScene();
mPen->setTransform(QTransform().translate(AncX*CurView->zoom(), AncY*CurView->zoom()).rotate(curAngle).translate(-AncX*CurView->zoom(), -AncY*CurView->zoom()));
mPen->setPos(mPen->penPos());
mPen->show();
CurScene->update();
CurView->update();
}
void TurtleModule::redraw()
{
if (currentState!=Shared::PluginInterface::GS_Running)return;
mutex.lock();
updateTurtle();
mutex.unlock();
// drawNet();
......
......@@ -36,7 +36,7 @@ namespace ActorTurtle {
public:
TurtlePen(QGraphicsItem *parent, const QString svgFileName): QGraphicsItem(parent)
{
turtle=new QGraphicsSvgItem(svgFileName);
turtle=new QGraphicsSvgItem(svgFileName,parent);
// turtle->scale(0.01,0.01);
// See Qt documentation!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
......@@ -50,7 +50,12 @@ namespace ActorTurtle {
tailColor=QColor(Qt::black);
tail=mat.map(tail);
mX=30;mY=30;
mPosX=0;
mPosY=0;
tailup=false;
turtleImage=new QImage(55,60,QImage::Format_ARGB32);
QPainter p(turtleImage);
turtle->renderer()->render(&p,boundingRect());
}
void setTailColor(const QColor color)
{
......@@ -76,7 +81,6 @@ namespace ActorTurtle {
{
turtle->setVisible(vis);
turtle->update();
turtle->renderer();
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
......@@ -88,16 +92,36 @@ namespace ActorTurtle {
painter->drawPath(tail);
qDebug()<<"TPE";
}
if(turtle->isVisible())turtle->renderer()->render(painter,QRectF(-15,-30,30,30));
//painter->drawImage( boundingRect(),turtleImage->copy());
if(turtle->isVisible())turtle->renderer()->render(painter,boundingRect());
if(! turtle->renderer()->isValid() ) qDebug()<<"BAD SVG RENDERER!!";
}
void resetPen()
{
mPosX = 0;
mPosY = 0;
};
void movePen(qreal dx,qreal dy)
{
mPosX +=dx;
mPosY += dy;
};
QPointF penPos()
{
return QPointF(mPosX,mPosY);
}
private:
qreal mX,mY;
QGraphicsSvgItem* turtle;
QImage* turtleImage;
QPainterPath tail;
QColor tailColor;
bool tailup;
qreal mPosX,mPosY;
};
class TurtleView
......@@ -273,6 +297,7 @@ public /* methods */:
{
return CurView;
}
void updateTurtle();
public slots:
void changeGlobalState(ExtensionSystem::GlobalState old, ExtensionSystem::GlobalState current);
void loadActorData(QIODevice * source);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment