← Back to team overview

kicad-developers team mailing list archive

Re: Re: redraw on erase track segment

 

jean-pierre charras wrote:
Dick Hollenbeck a écrit :

Jean-Pierre,

I have the track's bounding box now. How do I scale it to a dirty rectangle?

Here is what I have now:


// redraw the area where the track was
EDA_Rect dirty = Track->GetBoundingBox();

/* saw this going in the opposite direction from what I think I need:
curpos.x = ScreenPos.x * GetZoom();
curpos.y = ScreenPos.y * GetZoom();

curpos.x += m_DrawOrg.x;
curpos.y += m_DrawOrg.y;
*/

// here is the reverse:
int zoom = GetZoom();

wxPoint drwOrig = GetScreen()->m_DrawOrg;

dirty.m_Pos.x = (dirty.m_Pos.x - drwOrig.x) / zoom;
dirty.m_Pos.y = (dirty.m_Pos.y - drwOrig.y) / zoom;

dirty.m_Size.x = (dirty.m_Size.x - drwOrig.x) / zoom;
dirty.m_Size.y = (dirty.m_Size.y - drwOrig.y) / zoom;

// pass wxRect() via EDA_Rect::operator wxRect() overload
// convert from EDA_Rect to wxRect, no problem here
wxRect dirtyR = dirty;

DrawPanel->Refresh( TRUE, &dirtyR );



Does this look right?



For me, it looks right ( but i wrote the graphic code some years ago...)


There is no place in the kicad project where invalidated or dirty rectangles are generated by us. We are going where no Kicad code has gone before. So there is reason to question whether the handling of the dirty rectangles in OnPaint() has been wrong for a while and we have never noticed it because the rectangles coming *from the system* (as opposed to us calling Refresh() with a rect), are large enough to have masked a problem.

Or (and more likely) the calculation of the dirtyR above is wrong. The sized of the rectangles that we are seeing in OnPaint() are not anything like the rectangle that we calculate in dirtyR. I would think they would both be device coordinates, same engineering units. Using printf() statements in a DEBUG compile on the console, you can use the DEBUG compile and then run PCBNEW from the command line, and then pop up menu option Dimensions | User Grid Size, then move that popup window around the screen to see the types of dirty rectangles being passed to OnPaint() and they are significantly SMALLER than the dimensions of the rectangle that we calculate for dirtyR when deleting a track segment. So I am unclear at this point as to how to calculate dirtyR. Help is appreciated. I have spent most of a full day on this already. Thanks.



I also believe ReDraw() must be called only once


This is now in place, see OnPaint(). A debug counter added to old code confirmed that ReDraw() was being called as many as 10-15 times per OnPaint() when a small dialog window was being dragged across the drawpanel. So this is a speed improvement in many cases.


Dick








References