//------------------------------------------------------------------------- // 功能: 凸多边形转换为障碍信息 //------------------------------------------------------------------------- void KObj::PolygonChangeToBar( KPolygon Polygon, // 凸多边形 int nGridWidth, // 格子长 int nGridHeight, // 格子宽 int nTableWidth, // 表格长 int nTableHeight, // 表格宽 BYTE *lpbBarTable) // 表格内容 { if ( !lpbBarTable ) return; if (nGridWidth <= 0 || nGridHeight <= 0 || nTableWidth <= 0 || nTableHeight <= 0) return; int nTemp, nTempLT, nTempRT, nTempLB, nTempRB, nFlag = 0; POINT TempPos; for (int i = 0; i < nTableWidth * nTableHeight; i++) { Polygon.GetCenterPos(&TempPos); // 左上 TempPos.x += ((i % nTableWidth) * nGridWidth) - ((nTableWidth / 2) * nGridWidth + nGridWidth / 2); TempPos.y += ((i / nTableWidth) * nGridHeight) - ((nTableHeight / 2) * nGridHeight + nGridHeight / 2); nTempLT = Polygon.IsPointInPolygon(TempPos); // 右上 TempPos.x += nGridWidth; nTempRT = Polygon.IsPointInPolygon(TempPos); // 左下 TempPos.x -= nGridWidth; TempPos.y += nGridHeight; nTempLB = Polygon.IsPointInPolygon(TempPos); // 右下 TempPos.x += nGridWidth; nTempRB = Polygon.IsPointInPolygon(TempPos); nTemp = nTempLT + nTempRT + nTempLB + nTempRB; if (nTemp == 0) lpbBarTable[i] = Obj_Bar_Empty; else if (nTemp > 1) { lpbBarTable[i] = Obj_Bar_Full; nFlag = 1; } else { if (nTempLT) lpbBarTable[i] = Obj_Bar_LT; else if (nTempRT) lpbBarTable[i] = Obj_Bar_RT; else if (nTempLB) lpbBarTable[i] = Obj_Bar_LB; else if (nTempRB) lpbBarTable[i] = Obj_Bar_RB; } } lpbBarTable[(nTableHeight / 2) * nTableWidth + nTableWidth / 2] = Obj_Bar_Full; }
/** * Function OuputOnePolygon * write one polygon to output file. * Polygon coordinates are expected scaled by the polygon extraction function */ void BITMAPCONV_INFO::OuputOnePolygon( KPolygon & aPolygon, const char * aBrdLayerName ) { unsigned ii, jj; KPolyPoint currpoint; int offsetX = (int)( m_PixmapWidth / 2 * m_ScaleX ); int offsetY = (int)( m_PixmapHeight / 2 * m_ScaleY ); KPolyPoint startpoint = *aPolygon.begin(); switch( m_Format ) { case POSTSCRIPT_FMT: offsetY = (int)( m_PixmapHeight * m_ScaleY ); fprintf( m_Outfile, "newpath\n%d %d moveto\n", startpoint.x(), offsetY - startpoint.y() ); jj = 0; for( ii = 1; ii < aPolygon.size(); ii++ ) { currpoint = *(aPolygon.begin() + ii); fprintf( m_Outfile, " %d %d lineto", currpoint.x(), offsetY - currpoint.y() ); if( jj++ > 6 ) { jj = 0; fprintf( m_Outfile, ("\n") ); } } fprintf( m_Outfile, "\nclosepath fill\n" ); break; case PCBNEW_KICAD_MOD: { double width = 0.1; fprintf( m_Outfile, " (fp_poly (pts" ); jj = 0; for( ii = 0; ii < aPolygon.size(); ii++ ) { currpoint = *( aPolygon.begin() + ii ); fprintf( m_Outfile, " (xy %f %f)", (currpoint.x() - offsetX) / 1e6, (currpoint.y() - offsetY) / 1e6 ); if( jj++ > 6 ) { jj = 0; fprintf( m_Outfile, ("\n ") ); } } // Close polygon fprintf( m_Outfile, " (xy %f %f) )", (startpoint.x() - offsetX) / 1e6, (startpoint.y() - offsetY) / 1e6 ); fprintf( m_Outfile, "(layer %s) (width %f)\n )\n", aBrdLayerName, width ); } break; case KICAD_LOGO: fprintf( m_Outfile, " (pts" ); // Internal units = micron, file unit = mm jj = 0; for( ii = 0; ii < aPolygon.size(); ii++ ) { currpoint = *( aPolygon.begin() + ii ); fprintf( m_Outfile, " (xy %.3f %.3f)", (currpoint.x() - offsetX) / 1e3, (currpoint.y() - offsetY) / 1e3 ); if( jj++ > 4 ) { jj = 0; fprintf( m_Outfile, ("\n ") ); } } // Close polygon fprintf( m_Outfile, " (xy %.3f %.3f) )\n", (startpoint.x() - offsetX) / 1e3, (startpoint.y() - offsetY) / 1e3 ); break; case EESCHEMA_FMT: fprintf( m_Outfile, "P %d 0 0 1", (int) aPolygon.size() + 1 ); for( ii = 0; ii < aPolygon.size(); ii++ ) { currpoint = *(aPolygon.begin() + ii); fprintf( m_Outfile, " %d %d", currpoint.x() - offsetX, currpoint.y() - offsetY ); } // Close polygon fprintf( m_Outfile, " %d %d", startpoint.x() - offsetX, startpoint.y() - offsetY ); fprintf( m_Outfile, " F\n" ); break; } }
/** * Function OuputOnePolygon * write one polygon to output file. * Polygon coordinates are expected scaled by the polugon extraction function */ void BITMAPCONV_INFO::OuputOnePolygon( KPolygon & aPolygon ) { unsigned ii; KPolyPoint currpoint; int offsetX = (int)( m_PixmapWidth / 2 * m_ScaleX ); int offsetY = (int)( m_PixmapHeight / 2 * m_ScaleY ); KPolyPoint startpoint = *aPolygon.begin(); switch( m_Format ) { case POSTSCRIPT_FMT: fprintf( m_Outfile, "%d %d moveto\n", startpoint.x(), startpoint.y() ); for( ii = 1; ii < aPolygon.size(); ii++ ) { currpoint = *(aPolygon.begin() + ii); fprintf( m_Outfile, "%d %d lineto\n", currpoint.x(), currpoint.y() ); } fprintf( m_Outfile, "0 setgray fill\n" ); break; case PCBNEW_FMT: { #define SILKSCREEN_N_FRONT 21 int layer = SILKSCREEN_N_FRONT; int width = 1; fprintf( m_Outfile, "DP %d %d %d %d %d %d %d\n", 0, 0, 0, 0, (int) aPolygon.size() + 1, width, layer ); for( ii = 0; ii < aPolygon.size(); ii++ ) { currpoint = *( aPolygon.begin() + ii ); fprintf( m_Outfile, "Dl %d %d\n", currpoint.x() - offsetX, currpoint.y() - offsetY ); } // Close polygon fprintf( m_Outfile, "Dl %d %d\n", startpoint.x() - offsetX, startpoint.y() - offsetY ); } break; case EESCHEMA_FMT: fprintf( m_Outfile, "P %d 0 0 1", (int) aPolygon.size() + 1 ); for( ii = 0; ii < aPolygon.size(); ii++ ) { currpoint = *(aPolygon.begin() + ii); fprintf( m_Outfile, " %d %d", currpoint.x() - offsetX, currpoint.y() - offsetY ); } // Close polygon fprintf( m_Outfile, " %d %d", startpoint.x() - offsetX, startpoint.y() - offsetY ); fprintf( m_Outfile, " F\n" ); break; } }