基于矢量数据的拓展功能开发流程

基于矢量数据的拓展功能开发流程

通过拓展工具箱可以在项目中自定义开发基于点、线、面的矢量对象的处理工具,操作方式是首先导入矢量数据,在对象的右键菜单中激活拓展功能,找到对应的工具项进行操作。
面图层:VSpatialPolygonLayer
线图层:VSpatialPathLayer
点图层:VSpatialPointLayer

根据工具的复杂程度,UI上有所不同。一般分两种,通用和自定义。

通用型工具开发流程:

1.新建一个类继承自 mTooler T 代表待处理的类,该工具是针对该类对象的操作,可以是具体的类,也可以是接口,在拓展工具中,会自动匹配,如果某个类继承自该接口,也认为该类可以通过这个工具进行处理。
这种方式设计上比较方便灵活。
2.重写DrawInner,这里写入UI相关的代码。

1
protected override void DrawInner()

3.重写Process,完成点击[运行]按钮后执行的代码,这里传入的对象和this.fTarget是同一对象,使用中用哪个都行。如果有些工具不适合用运行的名称,可以在该类的构造函数中,指定按钮的名称。如

1
this.mBntRunName = "数据处理";
1
public override void Process(VSpatialPointLayer line)

upload successful

自定义工具开发流程:

最直观的理解是没有运行按钮,自定义UI,区别于通用型开发流程,无需理会Process,除非自己UI中执行了Process。UI在DrawContent中重写。

1
2
3
4
5
6
public override void DrawContent()
{
ImGui.BulletText(this.Title);
ImGui.Separator();
。。。。。
}

upload successful

示例代码1:点图层转换为粒子元素对象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    public class tMultiPointWidgetToSprite : mTooler<VSpatialPointLayer>
{
public override string Title { get { return "[转换] 为粒子元素缩放对象"; } }
private EModelStyle mmode = EModelStyle.XY2D;

protected override void DrawInner()
{
ImGuiHelper.Combox<EModelStyle>("元素类型", ref this.mmode);
}
public override void Process(VSpatialPointLayer line)
{
XMultiPointSquareInstanceRenderDescription<PointAttribute> des = new XMultiPointSquareInstanceRenderDescription<PointAttribute>();
des.Name = line.Name + "_Instance";
des.ModelStyle = this.mmode;
line.CreatePointArrayDes(des);
}
}

示例代码2:面数据转换为建筑数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
public class tMultiPolygonToSectionModelSet : mTooler<VSpatialPolygonLayer>
{
public override string Title { get { return "[转换] 为立体Section模型对象"; } }

public override void Process(VSpatialPolygonLayer polygon)
{
XMultiMeshSectionTileRenderDescription deset = new XMultiMeshSectionTileRenderDescription();
deset.Name = this.Name;
deset.Descrio = polygon.Description;
deset.NormalColor = polygon.DES.NormalColor;
deset.Mcenterlat = polygon.EnvelopeInner.Centre.Y;
deset.Mcenterlon = polygon.EnvelopeInner.Centre.X;
List<PolygonG> templist = new List<PolygonG>();
int totalcount = 0;
foreach (var item in polygon.Childrens.Values)
{
if (!item.IsSelected)
{
continue;
}
if (totalcount > 10000)
{
SubsetPolygonTile des = new SubsetPolygonTile();
des.Name = this.Name;
des.Descrio = polygon.Description;
des.NormalColor = polygon.DES.NormalColor;
des.Geometry.Rings.AddRange(templist.ToArray());
deset.SectionTiles.Add(des);
totalcount = 0;
templist.Clear();
}
int count = 0;
PolygonG plg = item.DES.Geometry;
plg.Attribute = item.DES.Altitude;
count += item.DES.Geometry.OuterBoundary.Count;
for (int i = 0; i < item.DES.Geometry.InnerBoundaries.Count; i++)
{
count += item.DES.Geometry.InnerBoundaries[i].Count;
}
templist.Add(plg);
totalcount += count;
}
if (templist.Count != 0)
{
SubsetPolygonTile des = new SubsetPolygonTile();
des.Name = this.Name;
des.Descrio = polygon.Description;
des.NormalColor = polygon.DES.NormalColor;
des.Geometry.Rings.AddRange(templist.ToArray());
deset.SectionTiles.Add(des);
totalcount = 0;
templist.Clear();
}
if (deset.SectionTiles.Count == 0)
{
System.Windows.Forms.MessageBox.Show("没有选中任何目标");
return;
}
base.CreateNewElement(polygon.Window, deset);
}
}

示例代码3:线图层转换为线集合对象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class tMultiLineToSingleLineGroup : mTooler<VSpatialPathLayer>
{
public override string Title { get { return "[转换] PathMeshModel]"; } }


private EPathMode mPath = EPathMode.Single;
public override void Process(VSpatialPathLayer line)
{
XMultiLinearStringRenderDescription geos = new XMultiLinearStringRenderDescription();
geos.Name = line.Name;
geos.Descrio = line.Description;
geos.NormalColor = line.DES.NormalColor;
geos.PathMode = this.mPath;
foreach (var item in line.Childrens.Values)
{
if (!item.IsSelected)
{
continue;
}
item.DES.Geometry.Attribute = item.DES.Altitude;
geos.Geometry.LineStringList.Add(item.DES.Geometry);
}

this.CreateNewElement(line.Window, geos);
}
protected override void DrawInner()
{
ImGui.InputText("名称", ref this.m_Name, 32);
ImGuiHelper.Combox<EPathMode>("样式", ref this.mPath);
}
}

示例代码4:面对象本地化信息输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class tPolygonToLocationPatch : mTooler<IPolygonEditor>
{
public override string Title { get { return "[创建] 本地化信息"; } }

private string regionname = "北京";
private string regiondescription = "未描述";
private string RMark = "XSCOPE";

public tPolygonToLocationPatch() : base()
{

}
public override void DrawContent()
{
ImGui.BulletText(this.Title);
ImGui.Separator();
this.DrawInner();
}
protected override void DrawInner()
{
ImGui.TextDisabled("生成本地化信息文件");
ImGui.InputText("名称", ref this.regionname, 32);
ImGui.InputText("描述", ref this.regiondescription, 32);
ImGui.InputText("产品代号", ref this.RMark, 32);
if (ImGui.Button("生成文件", this.bntsize))
{
}
ImGui.Separator();
if (ImGui.Button("导出VPLG文件"))
{
PolygonG pg = this.fTarget.PLG.ToPolygonG();
Gaiaxis.DirectX11.Gui.ImGuiSaveFileBrowser.Instance.ShowPopupModal("导出PolygonG文件(*.vplg)", new string[] { "*.vplg" }, (fileName) =>
{
Gaiaxis.IO.GaeaSerializer<PolygonG>.Save(fileName, pg);
});
}
ImGui.SameLine();
if (ImGui.Button("复制为字符串"))
{
string uriString = Gaiaxis.Geographics.Utilities.ShapeToBase64String.ToBase64String(this.fTarget.PLG);
Clipboard.SetDataObject(uriString, true);
}
Gaiaxis.DirectX11.Gui.ImGuiSaveFileBrowser.Instance.DrawPopup();
}
}