Thread Previous • Date Previous • Date Next • Thread Next |
Dick Hollenbeck a écrit :I now understand what Kicad is capable of by looking at void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )Jean-Pierre wrote: Kicad does *much more* than set the clipping area!All basic graphic items (circles, lines, .. seen gr_basic.cpp) ) are drawn only if in this clipping box.But the primary goal was not speed up.I wrote this code because under windows all draw coordinates are in 16 bits format (an other very good idea from Microsoft). Because kicad uses 32 bits coordinates (it was started as soon as i found a free 32 bits compiler (DJGPP, and a free graphic library, LIBGRX) for drawing, you can imagine what happens...Kicad was merely unuseable under Windows !.But it was important for me kicad was able to run under many operating systems. So, I was forced to write draw functions which handle the zoom level and use a clip box to draw objects only if in this clip box, and clip basic items (mainly lines) in order to draw graphics items using the 16 bit limited draw coordinates under Window (at this time, W95). Under Xwindows, this problem did not occurs but i found some related problems when drawing circles and ellipses, this clipping is usefull.
In Kicad, the dirty or "invalidated" rectangles coming from the event dispatcher into the OnPaint() function are used for these purposes:
1) The current dirty rectangle is used to decide which objects to draw. If any part of an object falls within the dirty rectangle, then the object is drawn, else not. The current dirty rectangle is passed to nested drawing functions through the WinEDA_DrawPanel::m_ClipBox EDA_Rect.
2) The current dirty rectangle is also used to establish a clipping region in wxWidgets so that it restricts all drawing primitives to within this clip box. This is done in OnPaint() before calling nested drawing functions.
3) In addition to the system clipping, Jean-Pierre once upon a time implemented his own clipping routines for several low level graphic primitives. These primitives still have and use that clipping code. It seems that the system clipping was not always good enough, so that now Kicad can still clip some primitives where the system would previously fall short. So for some primitives they are being doubly clipped, the Kicad application clips some, and if it did not, the wxWidgets and OS would have been responsible for this otherwise. This is a nice capability to have and there is not an intolerable performance cost that we can see.
Hopefully I got this right. There are really no short-comings that I can see in this design. Having the capability of 1) was missed by me initially because of the name of the rectangle variable. It serves two purposes, screening and clipping, but had the name for clipping, so I missed the screening role. I am pleased with this design.
2) We are actually going through the entire Kicad drawing code for as many times as there are dirty regions. Well ok, I would assume the number of dirty regions is probably normally exactly one most of the time. (But this may soon change if we implement the entire track delete with a number of dirty rectangles.)I also believe ReDraw() must be called only once.
I changed this yesterday so that we consolidate all the dirty rectangles into one big union and then call ReDraw() only once from OnPaint(). This seems to be an improvement under Linux.
Now we can search for this on the group when we have to re-visit this topic. Otherwise it seems like the discussion on dirty or invalidated rectangles is over.
Dick
Thread Previous • Date Previous • Date Next • Thread Next |