Re: [Kicad-developers] help with redraw
Hi Orson, that fixed it. Thanks a lot! Cheers, Andreas On 12/21/2017 01:11 PM, Maciej Sumiński wrote: > Hi Andreas, > > You might be missing VIEW::Update() [1] call to invalidate a VIEW_ITEM > after it has been modified. If it does not help, I will have a look at > the code. > > Cheers, > orson > > 1. > http://ci.kicad-pcb.org/job/kicad-doxygen/ws/Documentation/doxygen/html/classKIGFX_1_1VIEW.html#af8f6652fbafaf7ed08281ee9311e7857 > > > On 12/21/2017 01:02 PM, Andreas Buhr wrote: >> Hi, >> >> could you maybe help me finding the right redraw or refresh or whatever >> function? I can draw everything, but I see my polygons only after I >> switched the canvas once (Cairo->OpenGL or vice versa). So my workflow >> at the moment is: 1. Open pcbnew, 2. switch the canvas, 3. then work >> normally. >> >> I followed the structure of RATSNEST and added a layer "LAYER_SI_MESH" >> (like "LAYER_RATSNEST"). >> >> https://github.com/andreasbuhr/kicad/blob/e9695ce2f735d660771e342c4538ad707e97aa16/include/layers_id_colors_and_visibility.h#L205 >> >> >> I then added a "SI_MESH_VIEWITEM" (like "RATSNEST_VIEWITEM") which has a >> "ViewDraw" function, wherein I draw the polygons on the GAL. >> >> https://github.com/andreasbuhr/kicad/blob/e9695ce2f735d660771e342c4538ad707e97aa16/pcbnew/si_mesh_viewitem.cpp#L54 >> >> >> In PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard ), I added the >> SI_MESH_VIEWITEM >> >> https://github.com/andreasbuhr/kicad/blob/e9695ce2f735d660771e342c4538ad707e97aa16/pcbnew/pcb_draw_panel_gal.cpp#L178 >> >> But it seems I am missing something. Any suggestions? >> >> Thanks a lot! >> Andreas >> >> ___ >> Mailing list: https://launchpad.net/~kicad-developers >> Post to : kicad-developers@lists.launchpad.net >> Unsubscribe : https://launchpad.net/~kicad-developers >> More help : https://help.launchpad.net/ListHelp >> > > > > > ___ > Mailing list: https://launchpad.net/~kicad-developers > Post to : kicad-developers@lists.launchpad.net > Unsubscribe : https://launchpad.net/~kicad-developers > More help : https://help.launchpad.net/ListHelp > ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
[Kicad-developers] help with redraw
Hi, could you maybe help me finding the right redraw or refresh or whatever function? I can draw everything, but I see my polygons only after I switched the canvas once (Cairo->OpenGL or vice versa). So my workflow at the moment is: 1. Open pcbnew, 2. switch the canvas, 3. then work normally. I followed the structure of RATSNEST and added a layer "LAYER_SI_MESH" (like "LAYER_RATSNEST"). https://github.com/andreasbuhr/kicad/blob/e9695ce2f735d660771e342c4538ad707e97aa16/include/layers_id_colors_and_visibility.h#L205 I then added a "SI_MESH_VIEWITEM" (like "RATSNEST_VIEWITEM") which has a "ViewDraw" function, wherein I draw the polygons on the GAL. https://github.com/andreasbuhr/kicad/blob/e9695ce2f735d660771e342c4538ad707e97aa16/pcbnew/si_mesh_viewitem.cpp#L54 In PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard ), I added the SI_MESH_VIEWITEM https://github.com/andreasbuhr/kicad/blob/e9695ce2f735d660771e342c4538ad707e97aa16/pcbnew/pcb_draw_panel_gal.cpp#L178 But it seems I am missing something. Any suggestions? Thanks a lot! Andreas ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] [PATCH] Reduction of Polygon Complexity
Hi Orson, I see that this is a high risk change and I fully understand if you don't want to merge it now. best, Andreas On 12/20/2017 10:53 AM, Maciej Sumiński wrote: > Hi Andreas, > > I tested the patch with many boards and I confirm it reduces the polygon > complexity, without introducing any DRC violations. I would love to > merge it, but it is difficult for me to assess the risk of adding new > bugs, which are particularly not wanted during the feature freeze. If > Wayne says it is not the right time for such changes, then I am going to > merge your patch in v6-dev branch. > > Cheers, > Orson > > On 12/11/2017 11:16 AM, Andreas Buhr wrote: >> Dear Kicad developers, >> >> when looking at the polygons generated by converting all copper layers >> to polygons, I found some very small segments. I further investigated >> these segments and the reason was that zones are inflated by adding >> segments with rounded ends to their boundary. The rounded ends are >> segmented into a specified number of segments. This was not aligned. >> Often, two of these half-circles lye on each other and are bool-added >> afterwards. This creates these small segments. >> >> Find attached some code which aligns the segmentation. With the change, >> circles are always segmented the same way and two circles with same >> center and same radius have the same vertices in the generated polygon. >> >> Generating all polygons for all copper layers of the Olimex A64 board >> resulted in 415312 vertices before. With this patch applied, this number >> goes down to 280378 vertices. >> >> I hope you like it. Source code is clang-format-ed :-). >> >> Cheers, >> Andreas >> >> >> >> ___ >> Mailing list: https://launchpad.net/~kicad-developers >> Post to : kicad-developers@lists.launchpad.net >> Unsubscribe : https://launchpad.net/~kicad-developers >> More help : https://help.launchpad.net/ListHelp >> > > > > > ___ > Mailing list: https://launchpad.net/~kicad-developers > Post to : kicad-developers@lists.launchpad.net > Unsubscribe : https://launchpad.net/~kicad-developers > More help : https://help.launchpad.net/ListHelp > ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
[Kicad-developers] drawing of polygons with holes
Hi, both OPENGL_GAL::DrawPolygon( const SHAPE_POLY_SET& aPolySet ) and CAIRO_GAL::DrawPolygon( const SHAPE_POLY_SET& aPolySet ) do not plot the holes in the polygon. Is this intentionally? I do need a plot function which also plots the holes. I could: 1. Add some quick-fix just for me in my mirror, or 2. provide a patch. If I provide a patch, I could: a) Treat this as a bug and modify the drawing functions to also draw the holes. b) Add an argument "aDrawHoles" which defaults to "false". If it is set to "true", also the holes are drawn. c) Add a function "DrawPolygonWithHoles" What would you prefer? best, Andreas ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
[Kicad-developers] Question about zone to polygon transformation
Hi all, when converting a zone to a polygon, the function TransformRoundedEndsSegmentToPolygon is called on each segment of the polygon describing the zone. This is done to enlarge the polygon. This leads to a large number of polygons describing the zone. Why isn't the polygon enlarged using the clipper library? Attached is a patch which reduces the complexity of the polygons generated considerably. The patch is untested and not intended to be merged, it's just to illustrate my question. If the clipper library is not used here only for historic reasons, I'd create a tested patch in the coming weeks. thanks a lot in advance and best regards, Andreas diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index 7f64d4e..ba11704 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -361,23 +361,9 @@ void ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet( return; // add filled areas polygons -aCornerBuffer.Append( m_FilledPolysList ); - -// add filled areas outlines, which are drawn with thick lines -for( int i = 0; i < m_FilledPolysList.OutlineCount(); i++ ) -{ -const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( i ); - -for( int j = 0; j < path.PointCount(); j++ ) -{ -const VECTOR2I& a = path.CPoint( j ); -const VECTOR2I& b = path.CPoint( j + 1 ); - -TransformRoundedEndsSegmentToPolygon( aCornerBuffer, wxPoint( a.x, a.y ), wxPoint( b.x, b.y ), -aCircleToSegmentsCount, -GetMinThickness() ); -} -} +SHAPE_POLY_SET polyList(m_FilledPolysList); +polyList.Inflate(GetMinThickness() / 2, aCircleToSegmentsCount); +aCornerBuffer.Append( polyList ); } /** ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
[Kicad-developers] [PATCH] Reduction of Polygon Complexity
Dear Kicad developers, when looking at the polygons generated by converting all copper layers to polygons, I found some very small segments. I further investigated these segments and the reason was that zones are inflated by adding segments with rounded ends to their boundary. The rounded ends are segmented into a specified number of segments. This was not aligned. Often, two of these half-circles lye on each other and are bool-added afterwards. This creates these small segments. Find attached some code which aligns the segmentation. With the change, circles are always segmented the same way and two circles with same center and same radius have the same vertices in the generated polygon. Generating all polygons for all copper layers of the Olimex A64 board resulted in 415312 vertices before. With this patch applied, this number goes down to 280378 vertices. I hope you like it. Source code is clang-format-ed :-). Cheers, Andreas From f138235f2b768b1749572a4bb7e66f8e8e36a748 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Mon, 11 Dec 2017 11:03:41 +0100 Subject: [PATCH] always align segmentation of circles Rounded end segments were converted to a polygon using a specified "aCircleToSegmentCount". But the segmentation was not aligned to be 0 degree, delta degree, 2*delta degree etc, but it was aligned with the angle of the segment. Often, two rounded segment ends are joined (boolAdd). Because their segmentation did not align, this resulted in more segments than necessary and sometimes very small segments. This commit changes this behavior to create aligned segmentations. This reduces the number of vertices in the generated polygons substantially. --- common/convert_basic_shapes_to_polygon.cpp | 71 -- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/common/convert_basic_shapes_to_polygon.cpp b/common/convert_basic_shapes_to_polygon.cpp index f2efe03..0c42263 100644 --- a/common/convert_basic_shapes_to_polygon.cpp +++ b/common/convert_basic_shapes_to_polygon.cpp @@ -149,59 +149,82 @@ void TransformRoundRectToPolygon( SHAPE_POLY_SET& aCornerBuffer, * Note: the polygon is inside the arc ends, so if you want to have the polygon * outside the circle, you should give aStart and aEnd calculated with a correction factor */ -void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer, - wxPoint aStart, wxPoint aEnd, - int aCircleToSegmentsCount, - int aWidth ) +void TransformRoundedEndsSegmentToPolygon( SHAPE_POLY_SET& aCornerBuffer, wxPoint aStart, +wxPoint aEnd, int aCircleToSegmentsCount, int aWidth ) { -int radius = aWidth / 2; -wxPoint endp= aEnd - aStart; // end point coordinate for the same segment starting at (0,0) -wxPoint startp = aStart; -wxPoint corner; +int radius = aWidth / 2; +wxPoint direction = +aEnd - aStart; // end point coordinate for the same segment starting at (0,0) +wxPoint startp = aStart; +wxPoint endp = aEnd; +wxPoint corner; VECTOR2I polypoint; aCornerBuffer.NewOutline(); // normalize the position in order to have endp.x >= 0; -if( endp.x < 0 ) +if( direction.x < 0 ) { -endp= aStart - aEnd; -startp = aEnd; +direction = aStart - aEnd; +startp = aEnd; +endp = aStart; } -double delta_angle = ArcTangente( endp.y, endp.x ); // delta_angle is in 0.1 degrees -int seg_len= KiROUND( EuclideanNorm( endp ) ); +double delta_angle = ArcTangente( direction.y, direction.x ); // delta_angle is in 0.1 degrees -int delta = 3600 / aCircleToSegmentsCount;// rot angle in 0.1 degree +int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree // Compute the outlines of the segment, and creates a polygon // add right rounded end: -for( int ii = 0; ii < 1800; ii += delta ) + +// Start arc: +corner = wxPoint( 0, radius ); +RotatePoint( &corner, -delta_angle ); +corner += endp; +polypoint.x = corner.x; +polypoint.y = corner.y; +aCornerBuffer.Append( polypoint.x, polypoint.y ); + +int ii = int( delta_angle ) % delta; +if( ii <= 0 ) +ii += delta; +for( ; ii < 1800; ii += delta ) { +assert( ( ii - int( delta_angle ) ) % delta == 0 ); corner = wxPoint( 0, radius ); -RotatePoint( &corner, ii ); -corner.x += seg_len; -RotatePoint( &corner, -delta_angle ); -corner += startp; +RotatePoint( &corner, ii - int( delta_angle ) ); +corner += endp; polypoint.x = corner.x; polypoint.y = corner.y; aCornerBuffer.Append( polypoint.x, polypoint.y ); } // Finish arc: -corner = wxPoint( seg_len, -radius ); +c
Re: [Kicad-developers] [PATCH] bugfix: OPENGL_GAL::drawPolygon did not respect fill settings
On 12/11/2017 10:11 AM, Maciej Sumiński wrote: > > There is a minor code formatting violation, that I will fix. I suppose > that unfilled polygons have not been used so far, therefore the issue > could not be observed. If you use them, can you confirm the behavior is > coherent with the cairo backend? Hello Orson, thanks a lot. What was the formatting violation? I'll try to format my coming patches better. The behavior is coherent with the cairo backend, i.e. the cairo backend fills correctly. Cheers, aDnreas ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
[Kicad-developers] [PATCH] Bugfix: EDA_RECT to BOX2I generated wrong boxes
Dear Kicad developers, The "operator BOX2I() const" of EDA_RECT produced wrong boxes, usually much to big. It passed its end-position as second argument to the constructor of BOX2I. However, BOX2I expects its size as second argument. This caused a dramatic performance penalty in some cases. Took me about a day to figure this out. Cheers, Andreas >From 90f991e9938e0841908e58d665103e0f41fdbb43 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Sun, 10 Dec 2017 23:04:23 +0100 Subject: [PATCH] Bugfix: EDA_RECT to BOX2I generated wrong boxes The "operator BOX2I() const" of EDA_RECT produced wrong boxes, usually much to big. It passed its end-position as second argument to the constructor of BOX2I. However, BOX2I expects its size as second argument. This caused a dramatic performance penalty in some cases. --- include/class_eda_rect.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/class_eda_rect.h b/include/class_eda_rect.h index 3062d0a..c6b0acf 100644 --- a/include/class_eda_rect.h +++ b/include/class_eda_rect.h @@ -227,7 +227,7 @@ public: { EDA_RECT rect( m_Pos, m_Size ); rect.Normalize(); -return BOX2I( rect.GetOrigin(), rect.GetEnd() ); +return BOX2I( rect.GetOrigin(), rect.GetSize() ); } /** -- 2.7.4 ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
[Kicad-developers] [PATCH] bugfix: OPENGL_GAL::DrawPolygon did not close closed polygons
Dear Kicad developers, The polygon drawing routing in the OpenGL-GAL did not plot polygons which are "closed", i.e. have a segment from their last point to their first point, correctly. That segment was omitted. The patch attached fixes this bug. Cheers, Andreas >From 837eecbdae9b778525b12fdde19731456b7ffe26 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Sun, 10 Dec 2017 22:56:06 +0100 Subject: [PATCH] bugfix: OPENGL_GAL::DrawPolygon did not close closed polygons The polygon drawing routing in the OpenGL-GAL did not plot polygons which are "closed", i.e. have a segment from their last point to their first point, correctly. That segment was omitted. This commit fixes this bug. --- common/gal/opengl/opengl_gal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 63f08ee..2d50c3d 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -826,11 +826,11 @@ void OPENGL_GAL::DrawPolygon( const SHAPE_POLY_SET& aPolySet ) for( int j = 0; j < aPolySet.OutlineCount(); ++j ) { const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j ); -const int pointCount = outline.PointCount(); +const int pointCount = outline.SegmentCount() + 1; std::unique_ptr points( new GLdouble[3 * pointCount] ); GLdouble* ptr = points.get(); -for( int i = 0; i < outline.PointCount(); ++i ) +for( int i = 0; i < pointCount; ++i ) { const VECTOR2I& p = outline.CPoint( i ); *ptr++ = p.x; -- 2.7.4 ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] Signal integrity simulation within Kicad
On 11/29/2017 08:07 PM, Tomasz Wlostowski wrote: > I've made a quick test program that prints most of the board's geometry > as bare polygons. It's here: > > https://github.com/twlostow/kicad-dev/tree/tom-polygon-gen/qa/polygon_generator Hi Tom, thanks a lot for your help extracting polygons from PCBs. I plotted the polygons on top of the PCB, green lines are all polygons from all layers. It works fine for tracks. For some pads, it works correctly. Other pads are somehow enlarged. For zones, the polygons I get are always smaller than what is visible. Could you hint me at what I have to do to get the correct polygons for zones? See attached pictures for an example (Olimex A64 board). Cheers, Andreas ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
[Kicad-developers] [PATCH] bugfix: OPENGL_GAL::drawPolygon did not respect fill settings
Dear Kicad developers, The OPENGL_GAL::drawPolygon function and all functions using it did not respect the isFillEnabled member set by GAL::SetIsFill. This is fixed by the attached patch. I hope you find it useful. Cheers, Andreas >From d99a51c99e03bc6c28f2c0bc12c4a2327ecc378e Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Fri, 8 Dec 2017 12:44:46 +0100 Subject: [PATCH] bugfix: OPENGL_GAL::drawPolygon did not respect fill settings The OPENGL_GAL::drawPolygon function and all functions using it did not respect the isFillEnabled member set by GAL::SetIsFill. This is fixed by this patch. --- common/gal/opengl/opengl_gal.cpp | 36 +++- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 63f08ee..763d08f 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -1511,28 +1511,30 @@ void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRa void OPENGL_GAL::drawPolygon( GLdouble* aPoints, int aPointCount ) { -currentManager->Shader( SHADER_NONE ); -currentManager->Color( fillColor.r, fillColor.g, fillColor.b, fillColor.a ); +if(isFillEnabled){ +currentManager->Shader( SHADER_NONE ); +currentManager->Color( fillColor.r, fillColor.g, fillColor.b, fillColor.a ); -// Any non convex polygon needs to be tesselated -// for this purpose the GLU standard functions are used -TessParams params = { currentManager, tessIntersects }; -gluTessBeginPolygon( tesselator, ¶ms ); -gluTessBeginContour( tesselator ); +// Any non convex polygon needs to be tesselated +// for this purpose the GLU standard functions are used +TessParams params = { currentManager, tessIntersects }; +gluTessBeginPolygon( tesselator, ¶ms ); +gluTessBeginContour( tesselator ); -GLdouble* point = aPoints; +GLdouble* point = aPoints; -for( int i = 0; i < aPointCount; ++i ) -{ -gluTessVertex( tesselator, point, point ); -point += 3; // 3 coordinates -} +for( int i = 0; i < aPointCount; ++i ) +{ +gluTessVertex( tesselator, point, point ); +point += 3; // 3 coordinates +} -gluTessEndContour( tesselator ); -gluTessEndPolygon( tesselator ); +gluTessEndContour( tesselator ); +gluTessEndPolygon( tesselator ); -// Free allocated intersecting points -tessIntersects.clear(); +// Free allocated intersecting points +tessIntersects.clear(); +} if( isStrokeEnabled ) drawPolyline( [&](int idx) { return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] ); }, -- 2.7.4 ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
[Kicad-developers] [PATCH] fix double free and memory leak in SHAPE_POLY_SET
Dear Kicad developers, the attached patch fixes two bugs in SHAPE_POLY_SET. There were two problems in the triangulation caching of SHAPE_POLY_SET: First there was a double free: While SHAPE_POLY_SET implements the copy constructor, it did not implement the operator=, which resulted in the default operator= being generated by the compiler. The default operator= copied the member m_triangulatedPolys, which is a std::vector of pointers. So after operator= execution, there are two SHAPE_POLY_SET having pointers to the same TRIANGULATED_POLYGONs, each of them deleting them in their destructors. This led to segfaults, because calling TransformShapeWithClearanceToPolygon on a Zone uses operator= to copy the contained SHAPE_POLY_SET. The new SHAPE_POLY_SET then went out of scope and deleted the cached triangulation within the Zone. This first problem is fixed by implementing operator= for SHAPE_POLY_SET. Second, there was a memory leak: Calling "CacheTriangulation" on a SHAPE_POLY_SET, then changing the polygon and then calling "CacheTriangulation" again led to leaking the triangulations generated in the first call. This second problem is fixed by holding the cached triangulations in a unique_ptr. I hope you find this patch useful. Cheers, Andreas >From 947bf92c5a83cbd7202a6ad2220ac8c15aa3f9c8 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Fri, 8 Dec 2017 12:20:02 +0100 Subject: [PATCH] fix double free and memory leak in SHAPE_POLY_SET There were two problems in the triangulation caching of SHAPE_POLY_SET: First there was a double free: While SHAPE_POLY_SET implements the copy constructor, it did not implement the operator=, which resulted in the default operator= being generated by the compiler. The default operator= copied the member m_triangulatedPolys, which is a std::vector of pointers. So after operator= execution, there are two SHAPE_POLY_SET having pointers to the same TRIANGULATED_POLYGONs, each of them deleting them in their destructors. This led to segfaults, because calling TransformShapeWithClearanceToPolygon on a Zone uses operator= to copy the contained SHAPE_POLY_SET. The new SHAPE_POLY_SET then went out of scope and deleted the cached triangulation within the Zone. This first problem is fixed by implementing operator= for SHAPE_POLY_SET. Second, there was a memory leak: Calling "CacheTriangulation" on a SHAPE_POLY_SET, then changing the polygon and then calling "CacheTriangulation" again led to leaking the triangulations generated in the first call. This second problem is fixed by holding the cached triangulations in a unique_ptr. --- common/geometry/shape_poly_set.cpp | 27 +++ include/geometry/shape_poly_set.h | 9 + 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/common/geometry/shape_poly_set.cpp b/common/geometry/shape_poly_set.cpp index ff2ad87..3b81809 100644 --- a/common/geometry/shape_poly_set.cpp +++ b/common/geometry/shape_poly_set.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -58,14 +57,6 @@ SHAPE_POLY_SET::SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther ) : { } - -SHAPE_POLY_SET::~SHAPE_POLY_SET() -{ -for( auto p : m_triangulatedPolys ) -delete p; -} - - SHAPE* SHAPE_POLY_SET::Clone() const { return new SHAPE_POLY_SET( *this ); @@ -1871,6 +1862,19 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode, } +SHAPE_POLY_SET &SHAPE_POLY_SET::operator=(const SHAPE_POLY_SET & aOther) +{ +static_cast(*this) = aOther; +m_polys = aOther.m_polys; + +// reset poly cache: +m_hash = MD5_HASH{}; +m_triangulationValid = false; +m_triangulatedPolys.clear(); +return *this; +} + + typedef std::map P2T_MAP; typedef std::vectorP2T_VEC; @@ -2022,9 +2026,8 @@ void SHAPE_POLY_SET::CacheTriangulation() for( int i = 0; i < tmpSet.OutlineCount(); i++ ) { -auto p = new TRIANGULATED_POLYGON(); -m_triangulatedPolys.push_back( p ); -triangulateSingle( tmpSet.Polygon( i ), *p ); +m_triangulatedPolys.push_back( std::make_unique() ); +triangulateSingle( tmpSet.Polygon( i ), *m_triangulatedPolys.back() ); } m_triangulationValid = true; diff --git a/include/geometry/shape_poly_set.h b/include/geometry/shape_poly_set.h index cec3491..78308bc 100644 --- a/include/geometry/shape_poly_set.h +++ b/include/geometry/shape_poly_set.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -406,8 +407,6 @@ class SHAPE_POLY_SET : public SHAPE */ SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther ); -~SHAPE_POLY_SET(); - /** * Function GetRelativeIndices * @@ -585,7 +584,7 @@ class SHAPE_POLY_SET : public SHAPE const TRIANGULATED_POLYGON* TriangulatedPolygon( int aIndex ) const { -return m_tria
Re: [Kicad-developers] Signal integrity simulation within Kicad
Hi Jon, thanks a lot for your help. On 12/05/2017 03:51 PM, Jon Evans wrote: > For (2), the PCB_BASE_FRAME methods are for the legacy canvas, so I > wouldn't worry about implementing your feature there if I were you, > since it will eventually be removed. > The RATSNEST_VIEWITEM is what is used on the GAL (OpenGL/Cairo) canvases. > > Regarding the layer, you could use LAYER_GP_OVERLAY for prototyping, but > you are right that (at the moment) you can't add layers at runtime. > If you think that all of the simulation outputs can be drawn with a > single graphics layer, I think it is perfectly reasonable for you to > expand the enum with another layer definition. > You could use this new layer for your triangle mesh drawing, and then > use LAYER_GP_OVERLAY if you wanted to add any annotations to the > graphics perhaps? (meaning: measurements, etc, as is done with the > RULER_ITEM) Following the structure of the RATSNEST_VIEWITEM, I created a SI_MESH_VIEWITEM which should display the triangle mesh used in simulation. At the moment, my SI_MESH_VIEWITEM only displays a cross at position (0,0). It works fine for Cairo and OpenGL canvas. Is it possible to make the legacy canvas also use the VIEW_ITEM::ViewDraw() function? You can find my source code at https://github.com/andreasbuhr/kicad/commits/add_triangle_meshing thanks and best regards, Andreas > > -Jon > > On Tue, Dec 5, 2017 at 9:42 AM, Andreas Buhr <mailto:andr...@andreasbuhr.de>> wrote: > > Dear Kicad developers, > > I am browsing the Kicad source code to get an idea how to integrate a > simulation tool. > > I'd like the following: > > 1. The plugin should be informed whenever something changes. It would be > great to get a bounding box of the change. > 2. The plugin should be able to draw on the canvas. I'd like to register > a new layer (for example to show the triangle mesh). The user should > then be able to enable/disable this layer. > > These two requirements are in some sense similar to the requirements of > "ratsnest", so I followed "ratsnest" through the code. > > Concerning (1): > I got the impression that it is not easy to be informed about all > changes in a BOARD. Is this correct? > > Concerning (2): > And I got the impression that there is not one way to draw to the > canvas. I found two drawing methods for ratsnest, one in PCB_BASE_FRAME, > the other in RATSNEST_VIEWITEM::ViewDraw. Is it necessary to implement > two drawing methods for each feature? > > And it seems that the layers are organized in an enum (GAL_LAYER_ID), so > adding a layer at runtime seems impossible without larger infrastructure > changes. Is this correct? > > What would you propose? How can a plugin be informed about all changes > to the board? And how could a plugin draw on the canvas? > > thanks a lot in advance, > Cheers, > Andreas > > > On 11/30/2017 12:18 AM, Wayne Stambaugh wrote: > > Hi Andreas, > > > > Per our previous conversation, if you want to write your solver in > C++, > > then I would prefer that you do it as part of a solver plugin rather > > than a command event handler in Pcbnew. I image there would be other > > uses for a solver plugin object such as a thermal mapping solver which > > has been proposed in the past. The other option would be to use the > > Python action object and write the entire solver in Python rather than > > C++. That may make your life a bit easier. > > > > Cheers, > > > > Wayne > > > > On 11/29/2017 01:09 PM, Andreas Buhr wrote: > >> Dear Kicad developers, > >> > >> I'm new to Kicad development. Maybe you could give me some > starting tips? > >> > >> I am a 5th year PhD student at the university of Münster in Germany, > >> website: > >> > https://www.uni-muenster.de/AMM/en/ohlberger/team/andreas_buhr.shtml > <https://www.uni-muenster.de/AMM/en/ohlberger/team/andreas_buhr.shtml> > >> > >> I am doing mathematical research targeted at developing solvers > for 3D > >> Maxwell's equations in highly complex structures, such as PCBs. While > >> being in an early stage, the goal is to develop a signal integrity > >> solver which does a full-wave simulation of the electromagnetic > fields > >> and calculates S-parameters within a very short time. > >> > >> I would love to develop
Re: [Kicad-developers] Signal integrity simulation within Kicad
Dear Kicad developers, I am browsing the Kicad source code to get an idea how to integrate a simulation tool. I'd like the following: 1. The plugin should be informed whenever something changes. It would be great to get a bounding box of the change. 2. The plugin should be able to draw on the canvas. I'd like to register a new layer (for example to show the triangle mesh). The user should then be able to enable/disable this layer. These two requirements are in some sense similar to the requirements of "ratsnest", so I followed "ratsnest" through the code. Concerning (1): I got the impression that it is not easy to be informed about all changes in a BOARD. Is this correct? Concerning (2): And I got the impression that there is not one way to draw to the canvas. I found two drawing methods for ratsnest, one in PCB_BASE_FRAME, the other in RATSNEST_VIEWITEM::ViewDraw. Is it necessary to implement two drawing methods for each feature? And it seems that the layers are organized in an enum (GAL_LAYER_ID), so adding a layer at runtime seems impossible without larger infrastructure changes. Is this correct? What would you propose? How can a plugin be informed about all changes to the board? And how could a plugin draw on the canvas? thanks a lot in advance, Cheers, Andreas On 11/30/2017 12:18 AM, Wayne Stambaugh wrote: > Hi Andreas, > > Per our previous conversation, if you want to write your solver in C++, > then I would prefer that you do it as part of a solver plugin rather > than a command event handler in Pcbnew. I image there would be other > uses for a solver plugin object such as a thermal mapping solver which > has been proposed in the past. The other option would be to use the > Python action object and write the entire solver in Python rather than > C++. That may make your life a bit easier. > > Cheers, > > Wayne > > On 11/29/2017 01:09 PM, Andreas Buhr wrote: >> Dear Kicad developers, >> >> I'm new to Kicad development. Maybe you could give me some starting tips? >> >> I am a 5th year PhD student at the university of Münster in Germany, >> website: >> https://www.uni-muenster.de/AMM/en/ohlberger/team/andreas_buhr.shtml >> >> I am doing mathematical research targeted at developing solvers for 3D >> Maxwell's equations in highly complex structures, such as PCBs. While >> being in an early stage, the goal is to develop a signal integrity >> solver which does a full-wave simulation of the electromagnetic fields >> and calculates S-parameters within a very short time. >> >> I would love to develop and test my algorithms within KiCad. >> >> The input which my solver needs would be an array of polygons, >> representing the copper-filled areas on each layer. >> I then want to create a 2D triangle mesh and based on that a 3D prism >> mesh for finite element analysis. >> >> What would you recommend? How to I get polygons, representing the copper >> filled areas of each layer? >> I do have some experience developing C++. >> >> thanks a lot in advance, >> best regards, >> >> Andreas >> >> >> >> ___ >> Mailing list: https://launchpad.net/~kicad-developers >> Post to : kicad-developers@lists.launchpad.net >> Unsubscribe : https://launchpad.net/~kicad-developers >> More help : https://help.launchpad.net/ListHelp >> > > ___ > Mailing list: https://launchpad.net/~kicad-developers > Post to : kicad-developers@lists.launchpad.net > Unsubscribe : https://launchpad.net/~kicad-developers > More help : https://help.launchpad.net/ListHelp > signature.asc Description: OpenPGP digital signature ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
Re: [Kicad-developers] Signal integrity simulation within Kicad
On 11/29/2017 08:07 PM, Tomasz Wlostowski wrote: > On 29/11/17 19:09, Andreas Buhr wrote: [snip] >> The input which my solver needs would be an array of polygons, >> representing the copper-filled areas on each layer. >> I then want to create a 2D triangle mesh and based on that a 3D prism >> mesh for finite element analysis. > > I've made a quick test program that prints most of the board's geometry > as bare polygons. It's here: > > https://github.com/twlostow/kicad-dev/tree/tom-polygon-gen/qa/polygon_generator > > Hope it can serve you as a starting point. Hi Tom, wow, that's absolutely amazing. Thank you so much. I just generated 20 megabytes of polygons, running your test program on the A64 OLinuxino board by Olimex :-) I hope I can do some SI simulations of its DDR3 memory channel. :-) Cheers, Andreas signature.asc Description: OpenPGP digital signature ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp
[Kicad-developers] Signal integrity simulation within Kicad
Dear Kicad developers, I'm new to Kicad development. Maybe you could give me some starting tips? I am a 5th year PhD student at the university of Münster in Germany, website: https://www.uni-muenster.de/AMM/en/ohlberger/team/andreas_buhr.shtml I am doing mathematical research targeted at developing solvers for 3D Maxwell's equations in highly complex structures, such as PCBs. While being in an early stage, the goal is to develop a signal integrity solver which does a full-wave simulation of the electromagnetic fields and calculates S-parameters within a very short time. I would love to develop and test my algorithms within KiCad. The input which my solver needs would be an array of polygons, representing the copper-filled areas on each layer. I then want to create a 2D triangle mesh and based on that a 3D prism mesh for finite element analysis. What would you recommend? How to I get polygons, representing the copper filled areas of each layer? I do have some experience developing C++. thanks a lot in advance, best regards, Andreas signature.asc Description: OpenPGP digital signature ___ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp