参考代码下载:
https://download.csdn.net/download/x1131230123/11830648
首先确认好模型里有这些层,可以打开已有的模型直接用,或者使用setup>layers自己添加层。
新建一个cell
处于当前的cell
选择tools>macro,
回到cell,按键盘Home,切到主显示。
代码:
/*
* *************************************************************************
* * FILE: text.c
* * DESCRIPTION: get data from text
* *************************************************************************
*/
module textGet
{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "ldata.h" /* Main UPI header. */
#define PI 3.14159265358979323846
#define SIZE 1000
#define NUM_WG_POINTS 5
#define LEN_TEXT_WID 5
#define LEN_TEXT_HEI 40
#define POS_TEXT_X_STA -1000
#define POS_TEXT_Y_CEN 200
#define base_width 0.46
#define gap 0.15
#define radius 8.5
//circle 1
void drawC_1( LCell Cell, LLayer Layer, double offsetX, double offsetY )
{
int i=0;
int cnt = 1002;
float x[1002],y[1002];
float rad_w=8.5+(base_width/2.0);//外圆环
float rad_n=8.5-(base_width/2.0);//内圆环
LPoint *points;
//装点
//wai
for ( i = 0; i < 501 ; i++ )
{
x[i]=rad_w/500.0*i;
y[i]=sqrt(rad_w*rad_w-x[i]*x[i]);
}
//nei
for ( i = 0; i < 501 ; i++ )
{
x[501+i]=rad_n-rad_n/500.0*i;
y[501+i]=sqrt(rad_n*rad_n-x[501+i]*x[501+i]);
}
points = (LPoint *) malloc( (cnt) * sizeof(LPoint) );//get arm
for ( i = 0; i < cnt ; i++ )
{
points[i] = LPoint_Set( x[i] * SIZE + offsetX, y[i] * SIZE + offsetY );
}
LPolygon_New( Cell, Layer, points, cnt );
free( points );
return;
}
void drawRowland()
{
/*
* 绘图函数的入参必须指定cell、文件和图层,需先获取
* 获取当前cell和文件
*/
LCell Cell_Now = LCell_GetVisible();
LFile File_Now = LCell_GetFile( Cell_Now );
/* 获取当前图层 */
LLayer Layer_Poly = LLayer_Find( File_Now, "Poly" );
if ( !Layer_Poly )
{
LDialog_AlertBox( "There is no Poly layer.\nMake sure Poly is in the layer map!" );
return;
}
LLayer Layer_Active = LLayer_Find( File_Now, "Active" );
if ( !Layer_Active )
{
LDialog_AlertBox( "There is no Active layer.\nMake sure Poly is in the layer map!" );
return;
}
LLayer Layer_Metal1 = LLayer_Find( File_Now, "Metal1" );
if ( !Layer_Metal1 )
{
LDialog_AlertBox( "There is no N Select layer.\nMake sure Metal1 is in the layer map!" );
return;
}
double offsetX = 0;
double offsetY = 0;
//circle
drawC_1( Cell_Now, Layer_Active, offsetX, offsetY );
return;
}
void drawRowland_main( void )
{
LMacro_BindToHotKey( KEY_F1, "drawRowland", "drawRowland" );
}
} /* end of module textGet */
drawRowland_main();
总结:
1、程序大体过程是获取当前的cell,查看layers是否有必要的层,然后调用绘制函数。
2、绘制函数是使用了很多点包围自己想要的二维图形,调用LPolygon_New方法会按照给点顺序连接这些点形成一个图形。
3、所以自己需要什么图形的时候,给足够多的点包围这个图形,然后使用LPolygon_New方法绘制即可。