Commit b2a76062 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

All: use CPOLYGONS_LIST, a typedef of std::vector<CPolyPt> to handle a Corners Polygons List.

This is a starting point of some code enhancements relative to polygons in Pcbew and 3D viewer.
parent ea990230
Loading
Loading
Loading
Loading
+1 −12
Original line number Diff line number Diff line
@@ -30,15 +30,8 @@
#ifndef _3D_CANVAS_H_
#define _3D_CANVAS_H_

#include <wxBasePcbFrame.h>         // for m_auimanager member.
#include <layers_id_colors_and_visibility.h>    // Layers id definitions
#include <PolyLine.h>               // for CPolyPt

#if !wxUSE_GLCANVAS
#error Please set wxUSE_GLCANVAS to 1 in setup.h.
#endif

#include <wx/glcanvas.h>
#include <wxBasePcbFrame.h>         // for m_auimanager member.

#ifdef __WXMAC__
#  ifdef __DARWIN__
@@ -53,10 +46,6 @@
#include <3d_struct.h>

class BOARD_DESIGN_SETTINGS;
class TRACK;
class TEXTE_PCB;
class DRAWSEGMENT;
class ZONE_CONTAINER;
class EDA_3D_FRAME;
class S3D_VERTEX;
class SEGVIA;
+198 −169
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ static GLfloat Get3DLayer_Z_Orientation( LAYER_NUM aLayer );
 * Used only to draw pads outlines on silkscreen layers.
 */
static void BuildPadShapeThickOutlineAsPolygon( D_PAD*          aPad,
                                std::vector <CPolyPt>& aCornerBuffer,
                                                CPOLYGONS_LIST& aCornerBuffer,
                                                int             aWidth,
                                                int             aCircleToSegmentsCount,
                                                double          aCorrectionFactor )
@@ -83,7 +83,7 @@ static void BuildPadShapeThickOutlineAsPolygon( D_PAD * aPad,
    }

    // For other shapes, draw polygon outlines
    std::vector <CPolyPt> corners;
    CPOLYGONS_LIST corners;
    aPad->BuildPadShapePolygon( corners, wxSize( 0, 0 ),
                                aCircleToSegmentsCount, aCorrectionFactor );

@@ -97,6 +97,7 @@ static void BuildPadShapeThickOutlineAsPolygon( D_PAD * aPad,
    }
}


void EDA_3D_CANVAS::Redraw( bool finish )
{
    // SwapBuffer requires the window to be shown before calling
@@ -145,6 +146,7 @@ void EDA_3D_CANVAS::Redraw( bool finish )
    SwapBuffers();
}


void EDA_3D_CANVAS::BuildBoard3DView()
{
    PCB_BASE_FRAME* pcbframe = Parent()->Parent();
@@ -158,12 +160,13 @@ void EDA_3D_CANVAS::BuildBoard3DView()
                                                // for holes and items which do not need
                                                // a fine representation
    double          correctionFactorLQ = 1.0 / cos( M_PI / (segcountLowQuality * 2) );
    std::vector <CPolyPt> bufferPolys;
    CPOLYGONS_LIST  bufferPolys;

    bufferPolys.reserve( 200000 );                  // Reserve for large board (tracks mainly)
    std::vector <CPolyPt> bufferZonesPolys;
    CPOLYGONS_LIST  bufferZonesPolys;
    bufferPolys.reserve( 500000 );                  // Reserve for large board ( copper zones mainly )
    std::vector <CPolyPt> currLayerHoles;   // Contains holes for the current layer
    std::vector <CPolyPt> allLayerHoles;    // Contains through holes, calculated only once
    CPOLYGONS_LIST  currLayerHoles;                 // Contains holes for the current layer
    CPOLYGONS_LIST  allLayerHoles;                  // Contains through holes, calculated only once
    allLayerHoles.reserve( 20000 );
    bool            throughHolesListBuilt = false;  // flag to build the through hole polygon list only once
    bool            hightQualityMode = false;
@@ -171,13 +174,13 @@ void EDA_3D_CANVAS::BuildBoard3DView()
    for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER;
         layer++ )
    {

        if( layer != LAST_COPPER_LAYER &&
            layer >= g_Parm_3D_Visu.m_CopperLayersCount )
        if( layer != LAST_COPPER_LAYER
            && layer >= g_Parm_3D_Visu.m_CopperLayersCount )
            continue;

        if( !g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) )
            continue;

        bufferPolys.clear();
        bufferZonesPolys.clear();
        currLayerHoles.clear();
@@ -199,6 +202,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
                int holediameter    = track->GetDrillValue();
                int thickness       = g_Parm_3D_Visu.GetCopperThicknessBIU();
                int hole_outer_radius = (holediameter + thickness) / 2;

                if( shape != VIA_THROUGH )
                    TransformCircleToPolygon( currLayerHoles,
                                              track->GetStart(), hole_outer_radius,
@@ -214,16 +218,23 @@ void EDA_3D_CANVAS::BuildBoard3DView()
        for( MODULE* module = pcb->m_Modules; module != NULL; module = module->Next() )
        {
            module->TransformPadsShapesWithClearanceToPolygon( layer,
                    bufferPolys, 0, segcountforcircle, correctionFactor );
                                                               bufferPolys,
                                                               0,
                                                               segcountforcircle,
                                                               correctionFactor );

            // Micro-wave modukes may have items on copper layers
            module->TransformGraphicShapesWithClearanceToPolygonSet( layer,
                    bufferPolys, 0, segcountforcircle, correctionFactor );
                                                                     bufferPolys,
                                                                     0,
                                                                     segcountforcircle,
                                                                     correctionFactor );

            // Add pad hole, if any
            if( !throughHolesListBuilt )
            {
                D_PAD* pad = module->Pads();

                for( ; pad != NULL; pad = pad->Next() )
                    pad->BuildPadDrillShapePolygon( allLayerHoles, 0,
                                                    segcountLowQuality );
@@ -283,6 +294,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
        // Add holes in polygon list
        currLayerHoles.insert( currLayerHoles.begin(),
                               allLayerHoles.begin(), allLayerHoles.end() );

        if( currLayerHoles.size() > 0 )
            AddPolygonCornersToKiPolygonList( currLayerHoles, polysetHoles );

@@ -301,6 +313,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
        Draw3D_SolidHorizontalPolyPolygons( bufferPolys, zpos,
                                            thickness,
                                            g_Parm_3D_Visu.m_BiuTo3Dunits );

        if( bufferZonesPolys.size() )
            Draw3D_SolidHorizontalPolyPolygons( bufferZonesPolys, zpos,
                                                thickness,
@@ -315,6 +328,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
        if( track->Type() == PCB_VIA_T )
            Draw3DViaHole( (SEGVIA*) track );
    }

    // Draw pads holes (vertical cylinders)
    for( MODULE* module = pcb->m_Modules; module != NULL; module = module->Next() )
    {
@@ -333,6 +347,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
            continue;

        bufferPolys.clear();

        for( BOARD_ITEM* item = pcb->m_Drawings; item; item = item->Next() )
        {
            if( !item->IsOnLayer( layer ) )
@@ -368,6 +383,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
                {
                    if( !pad->IsOnLayer( layer ) )
                        continue;

                    BuildPadShapeThickOutlineAsPolygon( pad, bufferPolys,
                                                        linewidth,
                                                        segcountforcircle, correctionFactor );
@@ -375,10 +391,16 @@ void EDA_3D_CANVAS::BuildBoard3DView()
            }
            else
                module->TransformPadsShapesWithClearanceToPolygon( layer,
                            bufferPolys, 0, segcountforcircle, correctionFactor );
                                                                   bufferPolys,
                                                                   0,
                                                                   segcountforcircle,
                                                                   correctionFactor );

            module->TransformGraphicShapesWithClearanceToPolygonSet( layer,
                            bufferPolys, 0, segcountforcircle, correctionFactor );
                                                                     bufferPolys,
                                                                     0,
                                                                     segcountforcircle,
                                                                     correctionFactor );
        }

        // bufferPolys contains polygons to merge. Many overlaps .
@@ -395,6 +417,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
        EDA_COLOR_T color = g_ColorsSettings.GetLayerColor( layer );
        int         thickness = g_Parm_3D_Visu.GetLayerObjectThicknessBIU( layer );
        int         zpos = g_Parm_3D_Visu.GetLayerZcoordBIU( layer );

        if( layer == EDGE_N )
        {
            thickness = g_Parm_3D_Visu.GetLayerZcoordBIU( LAYER_N_FRONT )
@@ -417,6 +440,7 @@ void EDA_3D_CANVAS::BuildBoard3DView()
        module->ReadAndInsert3DComponentShape( this );
}


GLuint EDA_3D_CANVAS::CreateDrawGL_List()
{
    PCB_BASE_FRAME* pcbframe = Parent()->Parent();
@@ -543,6 +567,7 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM )
            glVertex3f( xmin, -(brd_center_pos.y + delta) * scale, zpos );
            glVertex3f( xmax, -(brd_center_pos.y + delta) * scale, zpos );
            glEnd();

            if( ii != 0 )
            {
                glBegin( GL_LINES );
@@ -597,7 +622,8 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM )
        double delta = ii * aGriSizeMM * IU_PER_MM * scale;

        if( delta <= zmax )
        {   // Draw grid lines on Z axis (positive Z axis coordinates)
        {
            // Draw grid lines on Z axis (positive Z axis coordinates)
            glBegin( GL_LINES );
            glVertex3f( xmin, -brd_center_pos.y * scale, delta );
            glVertex3f( xmax, -brd_center_pos.y * scale, delta );
@@ -605,7 +631,8 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM )
        }

        if( delta <= -zmin && ( ii != 0 ) )
        {   // Draw grid lines on Z axis (negative Z axis coordinates)
        {
            // Draw grid lines on Z axis (negative Z axis coordinates)
            glBegin( GL_LINES );
            glVertex3f( xmin, -brd_center_pos.y * scale, -delta );
            glVertex3f( xmax, -brd_center_pos.y * scale, -delta );
@@ -617,6 +644,7 @@ void EDA_3D_CANVAS::DrawGrid( double aGriSizeMM )
    }
}


void EDA_3D_CANVAS::Draw3DViaHole( SEGVIA* aVia )
{
    LAYER_NUM   top_layer, bottom_layer;
@@ -688,7 +716,7 @@ void EDA_3D_CANVAS::Draw3DPadHole( D_PAD * aPad )
        return;

    // Store here the points to approximate hole by segments
    std::vector <CPolyPt> holecornersBuffer;
    CPOLYGONS_LIST  holecornersBuffer;
    int             thickness   = g_Parm_3D_Visu.GetCopperThicknessBIU();
    int             height      = g_Parm_3D_Visu.GetLayerZcoordBIU( LAYER_N_FRONT ) -
                                  g_Parm_3D_Visu.GetLayerZcoordBIU( LAYER_N_BACK );
@@ -731,6 +759,7 @@ void EDA_3D_CANVAS::Draw3DPadHole( D_PAD * aPad )
    }
}


bool Is3DLayerEnabled( LAYER_NUM aLayer )
{
    int flg;
+2 −2
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@
 *  The top side is located at aZpos + aThickness / 2
 *  The bottom side is located at aZpos - aThickness / 2
 */
void    Draw3D_SolidHorizontalPolyPolygons( const std::vector<CPolyPt>& aPolysList,
void    Draw3D_SolidHorizontalPolyPolygons( const CPOLYGONS_LIST& aPolysList,
                                            int aZpos, int aThickness, double aBiuTo3DUnits );

/** draw the solid polygon found in aPolysList
@@ -55,7 +55,7 @@ void Draw3D_SolidHorizontalPolyPolygons( const std::vector<CPolyPt>& aPolysLi
 *  The top side is located at aZpos + aThickness / 2
 *  The bottom side is located at aZpos - aThickness / 2
 */
void    Draw3D_SolidHorizontalPolygonWithHoles( const std::vector<CPolyPt>& aPolysList,
void    Draw3D_SolidHorizontalPolygonWithHoles( const CPOLYGONS_LIST& aPolysList,
                                                int aZpos, int aThickness, double aBiuTo3DUnits );

/** draw a thick segment using 3D primitives, in a XY plane
+0 −2
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@
#define __3D_VIEWER_H__

#include <wxBasePcbFrame.h>         // for m_auimanager member.
#include <layers_id_colors_and_visibility.h>    // Layers id definitions
#include <PolyLine.h>               // fot CPolyPt

#if !wxUSE_GLCANVAS
#error Please set wxUSE_GLCANVAS to 1 in setup.h.
+56 −52
Original line number Diff line number Diff line
@@ -36,13 +36,13 @@
 * We are using a lots polygons in calculations.
 * and we are using 2 descriptions,
 * one easy to use with boost::polygon (KI_POLYGON_SET)
 * one easy to use in zones and in draw functions (std::vector<CPolyPt>)
 * one easy to use in zones and in draw functions (CPOLYGONS_LIST)
 * Copy polygons from a KI_POLYGON_SET set of polygons to
 * a std::vector<CPolyPt> polygon list
 * a CPOLYGONS_LIST polygon list
 * Therefore we need conversion functions between these 2 descriptions
 */
void CopyPolygonsFromKiPolygonListToPolysList( KI_POLYGON_SET&  aKiPolyList,
                                               std::vector<CPolyPt>& aPolysList )
                                               CPOLYGONS_LIST&  aPolysList )
{
    for( unsigned ii = 0; ii < aKiPolyList.size(); ii++ )
    {
@@ -64,14 +64,15 @@ void CopyPolygonsFromKiPolygonListToPolysList( KI_POLYGON_SET& aKiPolyList,
    }
}


/**
 * Helper function AddPolygonCornersToKiPolygonList
 * This function adds a KI_POLYGON_SET description to a
 * std::vector<CPolyPt> description
 * CPOLYGONS_LIST description
 * @param aCornersBuffer = source (set of polygons using CPolyPt corners descr)
 * @param aPolysList = destination (set of polygons)
 */
void AddPolygonCornersToKiPolygonList( std::vector <CPolyPt>& aCornersBuffer,
void AddPolygonCornersToKiPolygonList( CPOLYGONS_LIST&  aCornersBuffer,
                                       KI_POLYGON_SET&  aKiPolyList )
{
    std::vector<KI_POLY_POINT> cornerslist;
@@ -79,6 +80,7 @@ void AddPolygonCornersToKiPolygonList( std::vector <CPolyPt>& aCornersBuffer,

    // Count the number of polygons in aCornersBuffer
    int         polycount = 0;

    for( unsigned ii = 0; ii < corners_count; ii++ )
    {
        if( aCornersBuffer[ii].end_contour )
@@ -93,6 +95,7 @@ void AddPolygonCornersToKiPolygonList( std::vector <CPolyPt>& aCornersBuffer,
        cornerslist.clear();

        unsigned    ii;

        for( ii = icnt; ii < aCornersBuffer.size(); ii++ )
        {
            cornerslist.push_back( KI_POLY_POINT( aCornersBuffer[ii].x, aCornersBuffer[ii].y ) );
@@ -118,7 +121,7 @@ void AddPolygonCornersToKiPolygonList( std::vector <CPolyPt>& aCornersBuffer,
 * Note: the polygon is inside the circle, so if you want to have the polygon
 * outside the circle, you should give aRadius calculated with a corrrection factor
 */
void TransformCircleToPolygon( std::vector <CPolyPt>& aCornerBuffer,
void TransformCircleToPolygon( CPOLYGONS_LIST& aCornerBuffer,
                               wxPoint aCenter, int aRadius,
                               int aCircleToSegmentsCount )
{
@@ -153,7 +156,7 @@ void TransformCircleToPolygon( std::vector <CPolyPt>& 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( std::vector <CPolyPt>& aCornerBuffer,
void TransformRoundedEndsSegmentToPolygon( CPOLYGONS_LIST& aCornerBuffer,
                                           wxPoint aStart, wxPoint aEnd,
                                           int aCircleToSegmentsCount,
                                           int aWidth )
@@ -233,7 +236,7 @@ void TransformRoundedEndsSegmentToPolygon( std::vector <CPolyPt>& aCornerBuffer,
 * @param aCircleToSegmentsCount = the number of segments to approximate a circle
 * @param aWidth = width (thickness) of the line
 */
void TransformArcToPolygon( std::vector <CPolyPt>& aCornerBuffer,
void TransformArcToPolygon( CPOLYGONS_LIST& aCornerBuffer,
                            wxPoint aCentre, wxPoint aStart, int aArcAngle,
                            int aCircleToSegmentsCount, int aWidth )
{
@@ -272,6 +275,7 @@ void TransformArcToPolygon( std::vector <CPolyPt>& aCornerBuffer,
                                              aCircleToSegmentsCount, aWidth );
}


/**
 * Function TransformRingToPolygon
 * Creates a polygon from a ring
@@ -282,7 +286,7 @@ void TransformArcToPolygon( std::vector <CPolyPt>& aCornerBuffer,
 * @param aCircleToSegmentsCount = the number of segments to approximate a circle
 * @param aWidth = width (thickness) of the ring
 */
void TransformRingToPolygon( std::vector <CPolyPt>& aCornerBuffer,
void TransformRingToPolygon( CPOLYGONS_LIST& aCornerBuffer,
                             wxPoint aCentre, int aRadius,
                             int aCircleToSegmentsCount, int aWidth )
{
Loading