public override void Run(object sender, System.EventArgs e) { try { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) return; TrackBarControl control = sender as TrackBarControl; if (control != null) { double opac = double.Parse(control.EditValue.ToString()) / 100.0; app.Current3DMapControl.Terrain.Opacity = opac; string temp = (opac * 255.0).ToString(); int index = temp.IndexOf('.'); if (index == -1) return; string stra = temp.Substring(0, index); int a = int.Parse(stra); //地形模型 List<DF3DFeatureClass> list = Dictionary3DTable.Instance.GetFeatureClassByFacilityClassName("DX3DMODEL"); if (list != null) { foreach (DF3DFeatureClass dffc in list) { IFeatureLayer fl = dffc.GetFeatureLayer(); if (fl == null) continue; IModelPointSymbol mps = new ModelPointSymbol(); Color c = System.Drawing.Color.FromArgb(a, 255, 255, 255); mps.Color = (uint)c.ToArgb(); mps.EnableColor = true; ISimpleGeometryRender geoRender = new SimpleGeometryRender(); geoRender.Symbol = mps; fl.SetGeometryRender(geoRender); } } } } catch (Exception ex) { } }
private void comboBoxDomains_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxDomains.SelectedIndex < 0 || fieldNamesHasDomain.Count == 0) { return; } for (int l = 0; l < layerList.Count; l++) { IFeatureLayer layer = layerList[l]; ISimpleGeometryRender georenderNull = new SimpleGeometryRender(); layer.SetGeometryRender(georenderNull); layer.VisibleMask = gviViewportMask.gviViewAllNormalView; ISimpleGeometryRender georender = new SimpleGeometryRender(); georender.RenderGroupField = fieldNamesHasDomain[comboBoxDomains.SelectedIndex]; layer.SetGeometryRender(georender); } SetDomainTree(); }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "FeatureLayerSimpleRender.html"; } layerEnvelopeMap = new Hashtable(); layerFcMap = new Hashtable(); // 可视化Point类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\point.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* ISimpleTextRender textRender = new SimpleTextRender(); textRender.Expression = "''..$(oid)"; ITextSymbol textSymbol = new TextSymbol(); TextAttribute textAttribute = new TextAttribute(); textAttribute.TextColor = System.Drawing.Color.Red; textSymbol.TextAttribute = textAttribute; textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter; textSymbol.VerticalOffset = 10; // 注意:必须设置symbol,默认文字不显示 textRender.Symbol = textSymbol; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); // 特别注意:此处设置了逻辑组字段,则需要在CreateFeatureLayer后设置组的可见性。否则,默认FeatureLayer将不可见。 // 注意:必须用已注册RenderIndex的字段,否则CreateFeatureLayer创建不成功返回null geoRender.RenderGroupField = "Groupid"; IImagePointSymbol geoSymbol = new ImagePointSymbol(); //将点以图片的形式显示出来 geoSymbol.ImageName = "huang.png"; //使用素材库里存在的图片 geoSymbol.Size = 25; geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, true, "Point", textRender, geoRender); } // 可视化Polyline类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* ISimpleTextRender textRender = new SimpleTextRender(); textRender.Expression = "''..$(oid)"; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); // 特别注意:此处设置了逻辑组字段,则需要在CreateFeatureLayer后设置组的可见性。否则,默认FeatureLayer将不可见。 geoRender.RenderGroupField = "Groupid"; ICurveSymbol geoSymbol = new CurveSymbol(); geoSymbol.Color = System.Drawing.Color.Red; //线颜色为Purple geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, false, "Polyline", textRender, geoRender); } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polygon.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* ISimpleTextRender textRender = new SimpleTextRender(); textRender.Expression = "''..$(oid)"; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); // 特别注意:此处设置了逻辑组字段,则需要在CreateFeatureLayer后设置组的可见性。否则,默认FeatureLayer将不可见。 geoRender.RenderGroupField = "Groupid"; ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Yellow; //面填充色为Yellow geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, false, "Polygon", textRender, geoRender); } // 可视化ModelPoint类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\community.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* ISimpleTextRender textRender = new SimpleTextRender(); textRender.Expression = "''..$(oid)"; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); //特别注意:此处设置了逻辑组字段,则需要在CreateFeatureLayer后设置组的可见性。否则,默认FeatureLayer将不可见。 geoRender.RenderGroupField = "Groupid"; IModelPointSymbol geoSymbol = new ModelPointSymbol(); geoSymbol.Color = System.Drawing.Color.Yellow; //模型颜色为Red geoSymbol.EnableColor = true; //需开启,否则颜色设置无效 geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, false, "ModelPoint", textRender, geoRender); } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 开启顶点捕捉 this.axRenderControl1.MouseSnapMode = gviMouseSnapMode.gviMouseSnapVertex; _geoEditor = this.axRenderControl1.ObjectEditor; enableSnapBox.CheckedChanged += new System.EventHandler(enableSnapBox_CheckedChanged); this.toolStripComboBoxMeasure.SelectedIndex = 0; this.toolStripComboBoxEdit.SelectedIndex = 0; { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "MouseSnap.html"; } layerEnvelopeMap = new Hashtable(); fcGUIDMap = new Hashtable(); // 可视化Point类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\point.FDB"); ci.Database = tmpFDBPath; ISimpleGeometryRender render = new SimpleGeometryRender(); ISimplePointSymbol pointSymbol = new SimplePointSymbol(); pointSymbol.Size = 10; render.Symbol = pointSymbol; FeatureLayerVisualize(ci, true, "Point", render); } // 可视化Polyline类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, false, "Polyline", null); } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polygon.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, false, "Polygon", null); } // 可视化ModelPoint类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; FeatureLayerVisualize(ci, false, "ModelPoint", null); } // 绑定选择事件 this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载FDB try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\empty.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); TreeNode sourceNode = new TreeNode(ci.Database); this.treeViewCatalogTree.Nodes.Add(sourceNode); // 获取第1个dataset string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); TreeNode setNode = new TreeNode(setnames[0]); sourceNode.Nodes.Add(setNode); // 获取第1个featureclass string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fc = dataset.OpenFeatureClass(fcnames[0]); TreeNode fcNode = new TreeNode(fcnames[0]); setNode.Nodes.Add(fcNode); // 找到空间列字段 geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer layerList = new List <IFeatureLayer>(); foreach (string geoName in geoNames) { //****特别注意**** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); geoRender.RenderGroupField = "Groupid"; //**************** IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, geoRender, rootId); layerList.Add(featureLayer); // 设置featureLayer可见 SetGroupVisiable(dataset, featureLayer); IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } this.treeViewCatalogTree.ExpandAll(); // 加载FeatureDataSet对应的LogicGroupTree到界面控件 nodekeyMap = new Hashtable(); byte[] bb = GetLogicTreeContent(dataset); if (bb != null) { string strContent = System.Text.Encoding.UTF8.GetString(bb).Trim(); ShowCurDataSet(strContent); } // 删除回收站及其子节点 foreach (TreeNode node in this.treeViewLogicTree.Nodes[0].Nodes) { if (node.Text.Equals("回收站")) { this.treeViewLogicTree.Nodes.Remove(node); } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "ImportModel.html"; } CommonEntity.RenderEntity = this.axRenderControl1; CommonEntity.FormEntity = this; }
private static void AddSubClass(MajorClass mc, GroupLayerClass group, Dictionary <string, IFeatureClass> fcs, string geoColumnName) { if (mc == null || string.IsNullOrEmpty(mc.ClassifyField) || string.IsNullOrEmpty(mc.Fc3D)) { return; } string[] arrayFc3DGuids = mc.Fc3D.Split(';'); if (arrayFc3DGuids == null || arrayFc3DGuids.Count() == 0) { return; } // 给每个大类节点关联上所有的要素类,并记录上所有要素类 Dictionary <string, DF3DFeatureClass> dict = new Dictionary <string, DF3DFeatureClass>(); foreach (string fc3DGuid in arrayFc3DGuids) { foreach (KeyValuePair <string, IFeatureClass> kv in fcs) { if (kv.Key == fc3DGuid) { dict[kv.Key] = new DF3DFeatureClass(kv.Value); DF3DFeatureClassManager.Instance.Add(dict[kv.Key]); break; } } } if (group is TreeNodeMajorClass) { (group as TreeNodeMajorClass).FeatureClasses = dict; } // 可视化所有的要素类 DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } AxRenderControl d3 = app.Current3DMapControl; Dictionary <string, IFeatureLayer> dictLayers = new Dictionary <string, IFeatureLayer>(); foreach (DF3DFeatureClass dffc in dict.Values) { IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null) { continue; } IGeometryRender geoRender = new SimpleGeometryRender(); geoRender.RenderGroupField = "GroupId"; IFeatureLayer fl = d3.ObjectManager.CreateFeatureLayer(fc, geoColumnName, null, geoRender, d3.ProjectTree.RootID); if (fl != null) { dictLayers[fl.Guid.ToString()] = fl; dffc.SetFeatureLayer(fl); } } // 给每个大类节点划分二级子类 foreach (SubClass sc in mc.SubClasses) { TreeNodeSubClass tnsc = new TreeNodeSubClass() { Name = sc.Name, CustomValue = sc }; tnsc.FeatureLayers = dictLayers; tnsc.FeatureClasses = dict; tnsc.Visible = true; group.Add(tnsc); } group.Visible = true; group.CollapseAll(); }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } this.axRenderControl1.Camera.FlyTime = 0; // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\IFC.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } IFeatureClass fc = dataset.OpenFeatureClass(fcnames[0]); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } ISimpleGeometryRender geoRender = new SimpleGeometryRender(); geoRender.RenderGroupField = "ParentObjectId"; layer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, fieldinfo.Name, null, geoRender, rootId); IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 100, angle); Hashtable cusData = fc.CustomData.AsHashtable(); IEnumerator etor = cusData.Keys.GetEnumerator(); etor.MoveNext(); string strXML = (string)cusData[etor.Current]; ShowIFCTree(strXML); break; } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "IfcTree.html"; } }
private void btnApply_Click(object sender, System.EventArgs e) { string script = this.txtScript.Text.Trim(); if (script != "") { IGeometryRender render = selectedLayer.GetGeometryRender(); if (render != null) { if (render.RenderType == gviRenderType.gviRenderSimple) { ISimpleGeometryRender simpleRender = render as ISimpleGeometryRender; IGeometrySymbol geoSymbol = simpleRender.Symbol; geoSymbol.Script = script; simpleRender.Symbol = geoSymbol; if (!selectedLayer.SetGeometryRender(simpleRender)) { MessageBox.Show("错误码为:" + this.axRenderControl1.GetLastError()); } } } else { ISimpleGeometryRender simpleRender = new SimpleGeometryRender(); switch (type) { case LayerType.ModelPoint: { IModelPointSymbol mps = new ModelPointSymbol(); mps.Script = script; simpleRender.Symbol = mps; } break; case LayerType.Polyline: { ICurveSymbol cs = new CurveSymbol(); cs.Script = script; simpleRender.Symbol = cs; } break; case LayerType.Point: { if (script.Contains("<ImageName>")) { IImagePointSymbol ips = new ImagePointSymbol(); ips.Script = script; simpleRender.Symbol = ips; } else { ISimplePointSymbol sps = new SimplePointSymbol(); sps.Script = script; simpleRender.Symbol = sps; } } break; case LayerType.Polygon: { if (script.Contains("<Height>")) { IPolygon3DSymbol p3s = new Polygon3DSymbol(); p3s.Script = script; simpleRender.Symbol = p3s; } else { ISurfaceSymbol ss = new SurfaceSymbol(); ss.Script = script; simpleRender.Symbol = ss; } } break; } if (!selectedLayer.SetGeometryRender(simpleRender)) { MessageBox.Show("错误码为:" + this.axRenderControl1.GetLastError()); } } } else { selectedLayer.SetGeometryRender(null); } }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\7_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\7_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\7_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\7_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\7_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\7_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "GeometrySymbolScript.html"; } layerEnvelopeMap = new Hashtable(); // 可视化Point类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\point.FDB"); ci.Database = tmpFDBPath; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); //-- 配置为简单点 -- ISimplePointSymbol geoSymbol = new SimplePointSymbol(); geoSymbol.Script = "<Size>$(Groupid)*10</Size><FillColor>$(OBJECTID)</FillColor>"; //-- 配置为图片点 -- //IImagePointSymbol geoSymbol = new ImagePointSymbol(); //geoSymbol.Script = "<Size>$(Groupid)*10</Size><ImageName>$(ImageName)</ImageName>"; geoRender.Symbol = geoSymbol; type = LayerType.Point; FeatureLayerVisualize(ci, true, "Point", null, geoRender, type); } // 可视化Polyline类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.FDB"); ci.Database = tmpFDBPath; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); ICurveSymbol geoSymbol = new CurveSymbol(); geoSymbol.Script = "<Color>System.Drawing.Color.Yellow</Color><Width>$(Groupid)*10</Width><ImageName>$(ImageName)</ImageName><RepeatLength>100</RepeatLength>"; geoRender.Symbol = geoSymbol; type = LayerType.Polyline; FeatureLayerVisualize(ci, false, "Polyline", null, geoRender, type); } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polygon.FDB"); ci.Database = tmpFDBPath; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); //-- 配置为简单面 -- //ISurfaceSymbol geoSymbol = new SurfaceSymbol(); //geoSymbol.Script = "<Color>$(CommunitID)</Color>"; //-- 配置为立体矩形 -- IPolygon3DSymbol geoSymbol = new Polygon3DSymbol(); geoSymbol.Script = "<Color>$(CommunitID)</Color><Height>$(oid)</Height>"; ICurveSymbol curveSymbol = new CurveSymbol(); curveSymbol.Script = "<Color>$(CommunitID)</Color>"; geoSymbol.BoundarySymbol = curveSymbol; geoRender.Symbol = geoSymbol; type = LayerType.Polygon; FeatureLayerVisualize(ci, false, "Polygon", null, geoRender, type); } // 可视化ModelPoint类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; // *****定义几何物体渲染风格***** ISimpleGeometryRender geoRender = new SimpleGeometryRender(); IModelPointSymbol geoSymbol = new ModelPointSymbol(); geoSymbol.Script = "<Color>System.Drawing.Color.Yellow</Color>"; geoSymbol.EnableColor = true; // 记得要开启! geoRender.Symbol = geoSymbol; type = LayerType.ModelPoint; FeatureLayerVisualize(ci, false, "ModelPoint", null, geoRender, type); } }
private void MainForm_Load(object sender, EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(false, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; this.axRenderControl1.Camera.FlyTime = 0; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "ToolTipShow.html"; } layerEnvelopeMap = new Hashtable(); layerFcMap = new Hashtable(); // 可视化Point类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\point.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* IToolTipTextRender textRender = new ToolTipTextRender(); textRender.Expression = "''..$(oid)"; ISimpleGeometryRender geoRender = new SimpleGeometryRender(); IImagePointSymbol geoSymbol = new ImagePointSymbol(); //将点以图片的形式显示出来 geoSymbol.ImageName = "huang.png"; //使用素材库里存在的图片 geoSymbol.Size = 25; geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, true, "Point", textRender, geoRender); } // 可视化Polyline类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polyline.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* IToolTipTextRender textRender = new ToolTipTextRender(); textRender.Expression = "''..$(oid)"; ISimpleGeometryRender geoRender = new SimpleGeometryRender(); ICurveSymbol geoSymbol = new CurveSymbol(); geoSymbol.Color = System.Drawing.Color.Purple; //线颜色为Purple geoSymbol.Width = 5; geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, false, "Polyline", textRender, geoRender); } // 可视化Polygon类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\polygon.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* IToolTipTextRender textRender = new ToolTipTextRender(); textRender.Expression = "''..$(oid)"; ISimpleGeometryRender geoRender = new SimpleGeometryRender(); ISurfaceSymbol geoSymbol = new SurfaceSymbol(); geoSymbol.Color = System.Drawing.Color.Yellow; //面填充色为Yellow geoRender.Symbol = geoSymbol; FeatureLayerVisualize(ci, false, "Polygon", textRender, geoRender); } // 可视化ModelPoint类型FeatureLayer { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\community.FDB"); ci.Database = tmpFDBPath; // *******定义文字渲染风格******* IToolTipTextRender textRender = new ToolTipTextRender(); textRender.Expression = "''..$(oid)"; FeatureLayerVisualize(ci, false, "ModelPoint", textRender, null); } }
private void MainForm_Load(object sender, EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; this.axRenderControl1.Camera.FlyTime = 1; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\BIM.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } dataset = ds.OpenFeatureDataset(setnames[0]); //此处把dataset作为全局对象,以便后面调用 string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } //找出设置了域的字段 IDomain domain = fieldinfo.Domain; if (domain != null) { if (!fieldNamesHasDomain.Contains(fieldinfo.Name)) { fieldNamesHasDomain.Add(fieldinfo.Name); } } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } //设置可供选择的字段 comboBoxDomains.DataSource = fieldNamesHasDomain.ToArray(); if (fieldNamesHasDomain.Count > 0) { comboBoxDomains.SelectedIndex = 0; } SetDomainTree(); } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; layerList = new List <IFeatureLayer>(); foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { ISimpleGeometryRender georender = null; if (comboBoxDomains.SelectedIndex >= 0 && fieldNamesHasDomain.Count > 0) { georender = new SimpleGeometryRender(); georender.RenderGroupField = fieldNamesHasDomain[comboBoxDomains.SelectedIndex]; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, georender, rootId); layerList.Add(featureLayer); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } IEulerAngle angle = new EulerAngle(); angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } //绑定事件 this.comboBoxDomains.SelectedIndexChanged += new System.EventHandler(this.comboBoxDomains_SelectedIndexChanged); { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "DomainTree.html"; } }