~andrew-plumb/kicad/kicad

« back to all changes in this revision

Viewing changes to pcbnew/specctra_export.cpp

  • Committer: jean-pierre charras
  • Date: 2013-10-04 14:32:59 UTC
  • mfrom: (4363.1.3 testing)
  • Revision ID: jp.charras@wanadoo.fr-20131004143259-uwro11qhd63wlhj3
3D board display: better rendering of the board: the board polygon outlines (generated by the specctra function which calclaltes outlines) is now used to create the 3D body of the board,
in pcbnew and cvpcb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1251
1251
    }
1252
1252
}
1253
1253
 
 
1254
/* This function is not used in SPECCTRA export,
 
1255
 * but uses a lot of functions from it
 
1256
 * and is used to extract a board outlines (3D view, automatic zones build ...)
 
1257
 * makes the board perimeter for the DSN file by filling the BOUNDARY element.
 
1258
 * Any closed outline inside the main outline is a hole
 
1259
 * All contours should be closed, i.e. valid closed polygon vertices
 
1260
 */
 
1261
bool SPECCTRA_DB::GetBoardPolygonOutlines( BOARD* aBoard,
 
1262
                                           CPOLYGONS_LIST& aOutlines,
 
1263
                                           CPOLYGONS_LIST& aHoles,
 
1264
                                           wxString* aErrorText )
 
1265
{
 
1266
    bool success = true;
 
1267
    double specctra2UIfactor = IU_PER_MM / 1000.0;  // Specctra unite = micron
 
1268
 
 
1269
    if( ! pcb )
 
1270
    {
 
1271
        pcb = new PCB();
 
1272
        pcb->structure = new STRUCTURE( pcb );
 
1273
    }
 
1274
 
 
1275
    CPolyPt corner;
 
1276
    BOUNDARY* boundary = new BOUNDARY( 0 );
 
1277
    pcb->structure->SetBOUNDARY( boundary );
 
1278
 
 
1279
    try
 
1280
    {
 
1281
        fillBOUNDARY( aBoard, boundary );
 
1282
        std::vector<double> buffer;
 
1283
        boundary->GetCorners( buffer );
 
1284
 
 
1285
        for( unsigned ii = 0; ii < buffer.size(); ii+=2 )
 
1286
        {
 
1287
            corner.x = buffer[ii] * specctra2UIfactor;
 
1288
            corner.y =  - buffer[ii+1] * specctra2UIfactor;
 
1289
            aOutlines.Append( corner );
 
1290
        }
 
1291
 
 
1292
        aOutlines.CloseLastContour();
 
1293
 
 
1294
        // Export holes, stored as keepouts polygonal shapes.
 
1295
        // by fillBOUNDARY()
 
1296
        KEEPOUTS& holes = pcb->structure->keepouts;
 
1297
 
 
1298
        for( KEEPOUTS::iterator i=holes.begin();  i!=holes.end();  ++i )
 
1299
        {
 
1300
            KEEPOUT& keepout = *i;
 
1301
            PATH* poly_hole = (PATH*)keepout.shape;
 
1302
            POINTS& plist = poly_hole->GetPoints();
 
1303
            for( unsigned ii = 0; ii < plist.size(); ii+=2 )
 
1304
            {
 
1305
                corner.x = plist[ii].x * specctra2UIfactor;
 
1306
                corner.y =  - plist[ii].y * specctra2UIfactor;
 
1307
                aHoles.Append( corner );
 
1308
            }
 
1309
            aHoles.CloseLastContour();
 
1310
        }
 
1311
    }
 
1312
    catch( IO_ERROR ioe )
 
1313
    {
 
1314
        // Creates a valid polygon outline is not possible.
 
1315
        // So uses the board edge cuts bounding box to create a
 
1316
        // rectangular outline
 
1317
        // (when no edge cuts items, fillBOUNDARY biuld n outline
 
1318
        // from global bounding box
 
1319
        success = false;
 
1320
        if( aErrorText )
 
1321
            *aErrorText = ioe.errorText;
 
1322
 
 
1323
        EDA_RECT bbbox = aBoard->ComputeBoundingBox( true );
 
1324
        corner.x = bbbox.GetOrigin().x;
 
1325
        corner.y = bbbox.GetOrigin().y;
 
1326
        aOutlines.Append( corner );
 
1327
 
 
1328
        corner.x = bbbox.GetOrigin().x;
 
1329
        corner.y = bbbox.GetEnd().y;
 
1330
        aOutlines.Append( corner );
 
1331
 
 
1332
        corner.x = bbbox.GetEnd().x;
 
1333
        corner.y = bbbox.GetEnd().y;
 
1334
        aOutlines.Append( corner );
 
1335
 
 
1336
        corner.x = bbbox.GetEnd().x;
 
1337
        corner.y = bbbox.GetOrigin().y;
 
1338
        aOutlines.Append( corner );
 
1339
 
 
1340
        aOutlines.CloseLastContour();
 
1341
    }
 
1342
 
 
1343
    return success;
 
1344
}
 
1345
 
1254
1346
 
1255
1347
typedef std::set<std::string>                   STRINGSET;
1256
1348
typedef std::pair<STRINGSET::iterator, bool>    STRINGSET_PAIR;