NED 文件中

在NED文件中如果涉及到圖的定義,在canvas示例中的代碼如下:

network CarDemo
{
    parameters:
       @display("bgb=800,500");
       @figure[road] (type=polygon; points=100,200, 200,100, 300,50, 500,50, 650,100, 700,200, 600,300, 500,350, 400,350, 200,350, 100,300; smooth=true; lineWidth=60; zoomLineWidth=true; lineColor=grey);
       @figure[paint](type=polygon; points=100,200, 200,100, 300,50, 500,50, 650,100, 700,200, 600,300, 500,350, 400,350, 200,350, 100,300; smooth=true; lineWidth=3; zoomLineWidth=true; lineColor=white; lineStyle=dashed);
       @figure[trail](type=polyline; lineWidth=5; lineOpacity=0.6; lineColor=orange);
       @figure[car](type=image; image="car-top-view"; pos=0,0; anchor=c);
       @figure[car.antenna](type=image; image="antenna"; pos=-10,-40; anchor=nw);
       @figure[car.antenna.beam](type=path; path="M 10 0 L 10 -20 L 1200 -100 L 1200 100 L 10 20 Z"; fillColor=blue; fillOpacity=0.1; lineColor=blue; lineOpacity=0.1);
       @figure[status](type=group; transform=translate(700,20));
       // or, for non-zooming status area: @figure[status](type=panel; pos=700,20);
       @figure[status.bg](type=rectangle; pos=0,0; size=150,100; anchor=n; cornerRadius=10; fillColor=#fafdb9; fillOpacity=0.2; lineColor=#fafdb9; lineOpacity=0.4);
       @figure[status.distanceTitle](type=text; pos=0,20; text="Distance Travelled"; anchor=center);
       @figure[status.distance](type=text; pos=0,40; text="0m"; anchor=center; font=Arial,22);
       @figure[status.headingTitle](type=text; pos=0,70; text="Heading"; anchor=center);
       @figure[status.heading](type=text; pos=0,90; text="0"; anchor=center; font=Arial,22);

    submodules:
       animator: CarAnimator;
}

其中@figure的定義表示一個圖,

在c++中可以引用:

 cCanvas *canvas = getParentModule()->getCanvas();

    canvas->setAnimationSpeed(50.0, this);

    road = check_and_cast<cPolygonFigure *>(canvas->getFigure("road"));
    trail = check_and_cast<cPolylineFigure *>(canvas->getFigure("trail"));
    car = check_and_cast<cImageFigure *>(canvas->getFigure("car"));
    antenna = check_and_cast<cFigure *>(canvas->getFigureByPath("car.antenna"));
    distanceDisplay = check_and_cast<cTextFigure *>(canvas->getFigureByPath("status.distance"));
    headingDisplay = check_and_cast<cTextFigure *>(canvas->getFigureByPath("status.heading"));

其中,@figure的類型有如下幾種:

@fifigure type

C++ class

中文含義

line

cLineFigure

直線

arc

cArcFigure

弧線

polyline

cPolylineFigure

折線

rectangle

cRectangleFigure

矩形

oval

cOvalFigure

橢圓

ring

cRingFigure

圓環

pieslice

cPieSliceFigure

餅圖部分

polygon

cPolygonFigure

多邊形

path

cPathFigure

路徑

text

cTextFigure

路徑

label

cLabelFigure

文本標籤

image

cImageFigure

圖像

icon

cIconFigure

圖標

pixmap

cPixmapFigure

位圖

group

cGroupFigure

 

每個圖由一組屬性參數來定義,屬性的類型如下表:

類型

值定義格式

備註

bool

true 或者false.

 

int

整數

 

double

實數

 

double01

[0,1]之間的實數

比如透明度,不透明度

degrees

表示溫度的實數

 

string

字符串

如果它包含逗號、分號、右括號或其他影響解析的字符,需要使用引號括起來

Anchor

c, center, n, e, s, w, nw, ne, se, sw, start, middle, or end.

text fifigures只能用後三個

Arrowhead :

CapStyle

none, simple, triangle, or barbed.

butt, square, or round.

箭頭

Color :

 

A color in HTML format (#rrggbb), a color in HSB format (@hhssbb), or a valid SVG color name.

 

 

Dimensions :

width, height

Size given as width and height.

FigureType :

各種內置圖類型

Register_Figure()

FillRule

evenodd or nonzero.

 

 

Font

typeface, size, style

 

All three items are optional. size is the font size in points. style is space-sparated list of

zero or more of the following words: normal, bold, italic, underline.

 

ImageName :

文件名

The name of an image.

Interpolation

none, fast, or best

 

JoinStyle

bevel, miter, or round

 

LineStyle

solid, dotted, or dashed

 

Point

x, y

一個點

Point2

x1, y1, x2, y2

2個點

PointList

x1, y1, x2, y2, x3, y3...

點列表

Rectangle

x, y, width, height

矩形,左上角,長寬

TagList

tag1, tag2, tag3...

 

Tint

Color, double01

Specififies tint color and the amount of tinting for images.

Transform

translate(x, y),

rotate(deg),

rotate(deg, centerx, centery),

scale(s), scale(sx, sy),

scale(s, centerx, centery),

scale(sx, sy, centerx, centery),

skewx(coeff),

skewx(coeff, centery),

skewy(coeff),

skewy(coeff, centerx),

matrix(a, b, c, d, t1, t2)

 

一個或者多個轉換組成的步驟列表

由上面表格的各種類型的屬性一起可以定義某個圖。不同的圖包含的屬性不同:

類型:父類

值格式定義

備註

(fifigure) :

 

type=<FigureType>; visible=<bool>; tags=<TagList>; childZ=<int>;transform=<Transform>;

基類

(abstractLine) : fifigure

 

lineColor=<Color>; lineStyle=<LineStyle>; lineWidth=<double>;

lineOpacity=<double>; capStyle=<CapStyle>; startArrowhead=<Arrowhead>;

endArrowhead=<Arrowhead>; zoomLineWidth=<bool>;

抽象類

line : abstractLine

points=<Point2>

直線

arc : abstractLine

bounds=<Rectangle> pos=<Point>; size=<Dimensions>; anchor=<Anchor>;

startAngle=<degrees>; endAngle=<degrees>

弧線

polyline : abstractLine

points=<PointList>; smooth=<bool>; joinstyle=<JoinStyle>

折線

(abstractShape) : fifigure

 

lineColor=<Color>; fillColor=<Color>; lineStyle=<LineStyle>;

lineWidth=<double>; lineOpacity=<double01>; fillOpacity=<double01>;

zoomLineWidth=<bool>

圖形類

rectangle : abstractShape

 

bounds=<Rectangle> pos=<Point>; size=<Dimensions>; anchor=<Anchor>;

cornerRadius=<double>|<Dimensions>

矩形

oval : abstractShape

 

bounds=<Rectangle> pos=<Point>; size=<Dimensions>; anchor=<Anchor>

 

橢圓

ring : abstractShape

 

bounds=<Rectangle> pos=<Point>; size=<Dimensions>; anchor=<Anchor>;

innerSize=<Dimensions>

 

圓環

pieslice : abstractShape

 

bounds=<Rectangle> pos=<Point>; size=<Dimensions>; anchor=<Anchor>;

startAngle=<degrees>; endAngle=<degrees>

 

餅圖部分

polygon : abstractShape

 

points=<PointList>; smooth=<bool>; joinStyle=<JoinStyle>; fillRule=<FillRule>

 

多邊形

path : abstractShape

 

path=<string>; offset=<Point>; joinStyle=<JoinStyle>; capStyle=<CapStyle>;

fillRule=<FillRule>

路徑

(abstractText) : figure

 

pos=<Point>; anchor=<Anchor> text=<string>; font=<Font>; opacity=<double01>;

color=<Color>;

 

抽象文字

label : abstractText

 

angle=<degrees>;

 

標籤

text : abstractText

 

 

文本框

(abstractImage) : figure

 

bounds=<Rectangle> pos=<Point>; size=<Dimensions>; anchor=<Anchor>;

interpolation=<Interpolation>; opacity=<double01>; tint=<Tint>

 

抽象圖片

image : abstractImage

image=<ImageName>

 

圖像

icon : abstractImage

image=<ImageName>

圖標

pixmap : abstractImage

resolution=<Dimensions>

位圖

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章