void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { IPickResult pr = PickResult; if (pr == null && CTRL && Mask == gviModKeyMask.gviModKeyCtrl) { return; } if (!CTRL || (CTRL && Mask != gviModKeyMask.gviModKeyCtrl)) //ctrl键 { this.axRenderControl1.FeatureManager.UnhighlightAll(); } if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { if (PickResult != null) { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); } } } } } }
void axRenderControl1_RcMouseDragSelect(IPickResultCollection PickResults, gviModKeyMask Mask) { IPickResultCollection prc = PickResults; if (prc == null && CTRL && Mask == gviModKeyMask.gviModKeyCtrl) { return; } if (!CTRL || (CTRL && Mask != gviModKeyMask.gviModKeyCtrl)) //ctrl键 { this.axRenderControl1.FeatureManager.UnhighlightAll(); } if (prc != null) { for (int i = 0; i < prc.Count; i++) { IPickResult pr = prc.Get(i); if (pr != null && pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); } } } } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { this.axRenderControl1.FeatureManager.UnhighlightAll(); IPickResult pr = PickResult; if (pr != null && pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; curSelectFid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { curSelectFc = fc; break; } } this.axRenderControl1.FeatureManager.HighlightFeature(curSelectFc, curSelectFid, System.Drawing.Color.Red); this.tsb_Delete.Enabled = true; this.tsb_Update.Enabled = true; this.tsb_Insert.Enabled = true; } else { this.tsb_Delete.Enabled = false; this.tsb_Update.Enabled = false; this.tsb_Insert.Enabled = false; } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { this.axRenderControl1.FeatureManager.UnhighlightAll(); IPickResult pr = PickResult; if (pr == null) { this.btn_AttachmentManager.Enabled = false; return; } else if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; curSelectFid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; curSelectFc = fcuidMap[fl.FeatureClassId] as IFeatureClass; this.btn_AttachmentManager.Enabled = true; this.axRenderControl1.FeatureManager.HighlightFeature(curSelectFc, curSelectFid, System.Drawing.Color.Red); } else { this.btn_AttachmentManager.Enabled = false; return; } } }
private bool _3DControl_RcMouseMove(object sender, Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseMoveEvent e) { IPoint pt; IPickResult prTemp = this._3DControl.Camera.ScreenToWorld(e.x, e.y, out pt); if (pt != null) { if (_rPoint != null) { this._objectManager.DeleteObject(_rPoint.Guid); System.Runtime.InteropServices.Marshal.ReleaseComObject(_rPoint); _rPoint = null; } _rPoint = this._objectManager.CreateRenderPoint(pt, this._simplePointSymbol, this._rootID); } if (prTemp != null && prTemp.Type == gviObjectType.gviObjectFeatureLayer) { if (this._hoverFL != null && this._hoverFL != this._curSelectedFL && this._curSelectedID != this._hoverID) { this._hoverFL.UnhighlightFeature(this._hoverID); } IFeatureLayerPickResult pr = prTemp as IFeatureLayerPickResult; pr.FeatureLayer.HighlightFeature(pr.FeatureId, this._hightlightColor); this._hoverFL = pr.FeatureLayer; this._hoverID = pr.FeatureId; } return(false); }
/// <summary> /// 鼠标悬停事件 /// </summary> /// <param name="PickResult"></param> /// <param name="IntersectPoint"></param> /// <param name="Mask"></param> /// <param name="EventSender"></param> void g_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { if (PickResult != null) { IFeatureLayerPickResult pr = PickResult as IFeatureLayerPickResult; string featureId = pr.FeatureId.ToString(); IFeatureClass featureClass = null; IFeatureLayer fl = pr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.ToString() == fl.FeatureClassId.ToString()) { featureClass = fc; break; } } if (featureClass != null) { DataTable dt = CreateDataTable(featureClass); string filterString = string.Format("oid={0}", featureId); IQueryFilter filter = new QueryFilter(); filter.WhereClause = filterString; GetResultSet(featureClass, filter, dt); showInfo(dt, IntersectPoint); } } }
void axRenderControl1_RcMouseClickSelect_CreateFeature(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { _geoEditor.FinishEdit(); //用于当拾取到基准面时,或者没有正常右键结束连续调用Start时 this.axRenderControl1.FeatureManager.UnhighlightAll(); if (PickResult != null) { switch (PickResult.Type) { case gviObjectType.gviObjectFeatureLayer: { IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult; int fid = flpr.FeatureId; //加载多FeatureClass时要每次重新获取 _featureClass = (IFeatureClass)fcGUIDMap[flpr.FeatureLayer.FeatureClassId]; _featureLayer = flpr.FeatureLayer; IFdeCursor cursor = null; try { _buffer = _featureClass.CreateRowBuffer(); IQueryFilter filter = new QueryFilter(); //filter.AddSubField("oid"); //注意:StartEditFeatureGeometry里必须传入一个完整的rowbuffer,所以这里不能限定字段 filter.WhereClause = "oid =" + fid; cursor = _featureClass.Search(filter, false); IRowBuffer row = null; if ((row = cursor.NextRow()) != null) { _buffer = row as IRowBuffer; int pos = _buffer.FieldIndex("Geometry"); oldfdeGeometry = _buffer.GetValue(pos) as IGeometry; _buffer.SetValue(0, _featureClass.GetCount(null)); //修改fid为不同值,否则不是创建而是编辑 } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { } this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow); resultCode = _geoEditor.StartEditFeatureGeometry(_buffer, _featureLayer, gviGeoEditType.gviGeoEditCreator); if (!resultCode) { MessageBox.Show(this.axRenderControl1.GetLastError().ToString()); } } break; } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { IPickResult pr = PickResult; if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { if (PickResult != null) { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap_POI.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { IRowBuffer row = fc.GetRow(fid); int pos = row.FieldIndex("Geometry"); IPoint point = row.GetValue(pos) as IPoint; try { INetworkLocation location = new NetworkLocation(); location.Position = point; routeSolver.AddLocation(location); } catch (COMException ex) { MessageBox.Show("所选点距离网络太远,请调整LocationSearchTolerance大小"); return; } pos = row.FieldIndex("Name"); if (row.GetValue(pos) == null) { pos = 0; } if (txtLocationNames.Text == "") { txtLocationNames.Text = row.GetValue(pos).ToString(); } else { txtLocationNames.Text = txtLocationNames.Text + Environment.NewLine + row.GetValue(pos).ToString(); } this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); } } } } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { this.axRenderControl1.FeatureManager.UnhighlightAll(); // 置空 _buffer = null; _featureLayer = null; if (PickResult != null) { switch (PickResult.Type) { case gviObjectType.gviObjectFeatureLayer: { IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult; int fid = flpr.FeatureId; //加载多FeatureClass时要每次重新获取 _featureClass = (IFeatureClass)fcGUIDMap[flpr.FeatureLayer.FeatureClassId]; _featureLayer = flpr.FeatureLayer; IFdeCursor cursor = null; try { _buffer = _featureClass.CreateRowBuffer(); QueryFilter filter = new QueryFilter(); //filter.AddSubField("oid"); //注意:StartEditFeatureGeometry里必须传入一个完整的rowbuffer,所以这里不能限定字段 filter.WhereClause = "oid =" + fid; cursor = _featureClass.Search(filter, false); IRowBuffer row = null; if ((row = cursor.NextRow()) != null) { _buffer = row as IRowBuffer; int pos = _buffer.FieldIndex("Geometry"); oldfdeGeometry = _buffer.GetValue(pos) as IGeometry; } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { } this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow); EditGeometry(); } break; } } }
private void HighlightFeature(IPickResult pr) { if (pr.Type == i3dObjectType.i3dObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in featureClasses) { if (fc.Guid.Equals(fl.FeatureClassId)) { _axRenderControl.FeatureManager.HighlightFeature(fc, fid, 0xffff0000); } } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { IPickResult pr = PickResult; if (pr == null && CTRL && Mask == gviModKeyMask.gviModKeyCtrl) { return; } if (!CTRL || (CTRL && Mask != gviModKeyMask.gviModKeyCtrl)) //ctrl键 { this.axRenderControl1.FeatureManager.UnhighlightAll(); } if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { if (PickResult != null) { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); } } WindowParam wp = new WindowParam(); wp.FilePath = @"D:\05_CityMaker_DeveloperKit\trunk\SDK\Samples\JS\beginner\HTMLWindow\PropertyWindow.html"; wp.Position = gviHTMLWindowPosition.gviWinPosCenterParent; wp.SizeX = 200; wp.SizeY = 150; wp.Hastitle = false; wp.IsPopupWindow = false; wp.UseMoveHoverEvent = true; wp.HideOnClick = false; wp.WinId = fid; IHTMLWindow hw = this.axRenderControl1 as IHTMLWindow; hw.ShowPopupWindowEx(IntersectPoint, wp, true); } } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { this.axRenderControl1.FeatureManager.UnhighlightAll(); IPickResult pr = PickResult; if (pr != null && pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; IFeatureLayer fl = flpr.FeatureLayer; this.axRenderControl1.FeatureManager.HighlightFeature(fcuidMap[fl.FeatureClassId] as IFeatureClass, flpr.FeatureId, System.Drawing.Color.Red); } else { return; } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { if (PickResult != null) { if (PickResult.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { IRowBuffer fdeRow = fc.GetRow(fid); int nPos = fdeRow.FieldIndex("Geometry"); switch (source) { case SOURCE.SELECT1: this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); geo1.AddGeometry(fdeRow.GetValue(nPos) as IPolygon); drawLabel(IntersectPoint, "要素一", System.Drawing.Color.Yellow); break; case SOURCE.SELECT2: this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Red); geo2.AddGeometry(fdeRow.GetValue(nPos) as IPolygon); drawLabel(IntersectPoint, "要素二", System.Drawing.Color.Yellow); break; } SelectObject obj = new SelectObject(); obj.FC = fc; obj.ID = fid; objToHide.Add(obj); } } // end foreach } } if (source == SOURCE.SELECT1 || source == SOURCE.SELECT2) { this.axRenderControl1.RcMouseClickSelect -= new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); this.axRenderControl1.InteractMode = gviInteractMode.gviInteractNormal; } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { IPickResult pr = PickResult; if (pr == null) { return; } if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { // 高亮Polygon this.axRenderControl1.FeatureManager.UnhighlightAll(); IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { IRowBuffer fdeRow = fc.GetRow(fid); IFieldInfoCollection col = fdeRow.Fields; for (int i = 0; i < col.Count; ++i) { IFieldInfo info = col.Get(i); if (info.GeometryDef != null && info.GeometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnPolyline) { int nPos = fdeRow.FieldIndex(info.Name); polyline = fdeRow.GetValue(nPos) as IPolyline; this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); //获取路宽 nPos = fdeRow.FieldIndex("WIDTH"); //width = (double)fdeRow.GetValue(nPos); width = 10; } } } // end " if (fc.Guid.Equals(fl.FeatureClassId))" } // end "foreach (IFeatureClass fc in fcMap.Keys)" } } }
/// <summary> /// 鼠标悬停事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <returns></returns> bool axRenderControl1_RcMouseHover(uint Flags, int X, int Y) { pic = this.axRenderControl1.Camera.ScreenToWorld(X, Y, out point); if (point == null || pic == null) { return(false); } //////////////////////////////测试WorldToScreen接口//////////////////////////////////////////// double screenx = 0.0, screeny = 0.0; bool inScreen = false; bool pval = this.axRenderControl1.Camera.WorldToScreen(point.X, point.Y, point.Z - 10, out screenx, out screeny, 1, out inScreen); this.Text = pval.ToString(); /////////////////////////////////////////////////////////////////////////////////////////////// IFeatureLayerPickResult pr = pic as IFeatureLayerPickResult; if (pr != null) { string featureId = pr.FeatureId.ToString(); IFeatureClass featureClass = null; IFeatureLayer fl = pr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.ToString() == fl.FeatureClassId.ToString()) { featureClass = fc; break; } } if (featureClass != null) { DataTable dt = CreateDataTable(featureClass); string filterString = string.Format("oid={0}", featureId); IQueryFilter filter = new QueryFilter(); filter.WhereClause = filterString; GetResultSet(featureClass, filter, dt); showInfo(dt, point); } } return(false); }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { IPickResult pr = PickResult; if (pr == null) { this.axRenderControl1.FeatureManager.UnhighlightAll(); return; } if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { if (PickResult != null) { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { if (cbClipPlaneEnable.Checked) { fl.AttributeMask = gviAttributeMask.gviAttributeClipPlane | gviAttributeMask.gviAttributeCollision | gviAttributeMask.gviAttributeHighlight; MessageBox.Show(string.Format("名称为{0}的FeatureLayer的AttributeMask已设置为参与裁剪", fc.Name)); } else { fl.AttributeMask = gviAttributeMask.gviAttributeCollision | gviAttributeMask.gviAttributeHighlight; MessageBox.Show(string.Format("名称为{0}的FeatureLayer的AttributeMask已设置为不参与裁剪", fc.Name)); } break; } } } } } }
private void _3DControl_RcMouseClickSelect(object sender, Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseClickSelectEvent e) { if (e.intersectPoint != null && e.pickResult != null && e.pickResult.Type == gviObjectType.gviObjectFeatureLayer) { this._onStartDraw(); if (this._curSelectedFL != null) { this._curSelectedFL.UnhighlightFeature(this._curSelectedID); } if (this._hoverFL != null) { this._hoverFL.UnhighlightFeature(this._hoverID); } IFeatureLayerPickResult pr = e.pickResult as IFeatureLayerPickResult; int featureID = pr.FeatureId; pr.FeatureLayer.HighlightFeature(featureID, this._hightlightColor); this._curSelectedFL = pr.FeatureLayer; this._curSelectedID = pr.FeatureId; this._selectFeatureLayerPickResult = pr; this._selectPoint = e.intersectPoint; this._onFinishedDraw(); } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { //this.axRenderControl1.FeatureManager.UnhighlightAll(); IPickResult pr = PickResult; if (pr != null && pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; curSelectFid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; curSelectFc = fcuidMap[fl.FeatureClassId] as IFeatureClass; this.axRenderControl1.FeatureManager.HighlightFeature(curSelectFc, curSelectFid, System.Drawing.Color.Red); FeatureAttrEditDlg myDlg = new FeatureAttrEditDlg(curSelectFc, curSelectFid); myDlg.Owner = this; myDlg.Show(); } else { return; } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { IPickResult pr = PickResult; this.axRenderControl1.FeatureManager.UnhighlightAll(); if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { if (PickResult != null) { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); //string htmlPath = Path.Combine(Application.StartupPath.Substring(0, flag), @"Samples\CSharp\bin\HTMLWindowSample.html"); //WindowParam wp = htmlwindow.CreateWindowParam(); //wp.FilePath = htmlPath + "?id=" + fid; //wp.SizeX = 200; //wp.SizeY = 200; //wp.Hastitle = true; //wp.Round = 10; //wp.HideOnClick = false; //wp.WinId = fid; //htmlwindow.ShowPopupWindowEx(IntersectPoint, wp, true); } } } } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { try { IPickResult pr = PickResult; if (pr == null) { return; } this.axRenderControl1.FeatureManager.UnhighlightAll(); if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { //删除画包围框的RenderPolyline for (int i = 0; i < rPolylinelist.Count; i++) { this.axRenderControl1.ObjectManager.DeleteObject((rPolylinelist[i] as IRenderPolyline).Guid); } rPolylinelist.Clear(); DrawEnvelope(fid, fc, out rPolylinelist); // 选择用作水印的图片 IImage waterImg = new ResourceFactory().CreateImageFromFile(this.toolStripTextBoxPicturePath.Text); if (waterImg == null) { MessageBox.Show("水印图片对象为空,请先更换图片"); return; } DialogResult result = MessageBox.Show("加水印操作不可逆,是否继续进行", "警告", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } // 准备Model对象 string filterString = string.Format("oid={0}", fid); IQueryFilter filter = new QueryFilter(); filter.WhereClause = filterString; IFdeCursor cursor = null; try { cursor = fc.Search(filter, true); if (cursor != null) { IRowBuffer fdeRow = null; while ((fdeRow = cursor.NextRow()) != null) { IFieldInfoCollection col = fdeRow.Fields; for (int i = 0; i < col.Count; ++i) { IFieldInfo info = col.Get(i); if (info.GeometryDef != null && info.GeometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnModelPoint) { int nPos = fdeRow.FieldIndex(info.Name); IModelPoint mp = fdeRow.GetValue(nPos) as IModelPoint; // 高亮选定模型边框 //DrawEnvelope(mp.Envelope, fc.FeatureDataSet.SpatialReference as ISpatialCRS); IResourceManager rm = fc.FeatureDataSet as IResourceManager; IModel model = rm.GetModel(mp.ModelName); // 加上水印 string[] imagenames = model.GetImageNames(); for (int j = 0; j < imagenames.Length; j++) { this.Text = string.Format("正在处理第{0}个图片/共{1}个", j, imagenames.Length); IImage image = rm.GetImage(imagenames[j]); image.EmbedWatermark(waterImg); rm.UpdateImage(imagenames[j], image); } this.axRenderControl1.FeatureManager.RefreshFeatureClass(fc); this.Text = "处理完成!"; } } } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (cursor != null) { //Marshal.ReleaseComObject(cursor); cursor = null; } } //end try } // end " if (fc.Guid.Equals(fl.FeatureClassId))" } // end "foreach (IFeatureClass fc in fcMap.Keys)" } } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } }
private void MousePickup(IPickResult pr, gviModKeyMask mask) { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } if ((mask == gviModKeyMask.gviModKeyCtrl || mask == gviModKeyMask.gviModKeyShift) && pr == null) { return; } //FDECommand fDECommand = new FDECommand(true, false); if (mask != gviModKeyMask.gviModKeyCtrl && mask != gviModKeyMask.gviModKeyShift) { app.Current3DMapControl.FeatureManager.UnhighlightAll(); } else { HashMap featureClassInfoMap = SelectCollection.Instance().FeatureClassInfoMap; if (featureClassInfoMap != null) { bool flag = true; System.Collections.IEnumerator enumerator = featureClassInfoMap.Keys.GetEnumerator(); try { if (enumerator.MoveNext()) { DF3DFeatureClass featureClassInfo = (DF3DFeatureClass)enumerator.Current; if (featureClassInfo.GetFeatureClass().Guid == CommonUtils.Instance().CurEditLayer.GetFeatureClass().Guid) { flag = true; } } } finally { System.IDisposable disposable = enumerator as System.IDisposable; if (disposable != null) { disposable.Dispose(); } } if (!flag) { SelectCollection.Instance().Clear(); } } } if (app.Current3DMapControl.ObjectEditor.IsEditing) { RenderControlEditServices.Instance().StopGeometryEdit(true); } if (pr == null) { SelectCollection.Instance().Clear(); app.Current3DMapControl.TransformHelper.Type = gviEditorType.gviEditorNone; } else { if (pr.Type == gviObjectType.gviObjectTerrain || pr.Type == gviObjectType.gviObjectReferencePlane) { SelectCollection.Instance().Clear(); app.Current3DMapControl.TransformHelper.Type = gviEditorType.gviEditorNone; } else { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult featureLayerPickResult = pr as IFeatureLayerPickResult; int featureId = featureLayerPickResult.FeatureId; IFeatureLayer featureLayer = featureLayerPickResult.FeatureLayer; if (featureLayer.Guid == CommonUtils.Instance().CurEditLayer.GetFeatureLayer().Guid) { DF3DFeatureClass featureClassInfo = DF3DFeatureClassManager.Instance.GetFeatureClassByID(featureLayer.FeatureClassId.ToString()); if (featureClassInfo != null) { IFeatureClass featureClass = featureClassInfo.GetFeatureClass(); HashMap hashMap = new HashMap(); if (mask == (gviModKeyMask)0) { hashMap[featureClassInfo] = new System.Collections.Generic.List <int> { featureId }; } else { foreach (DF3DFeatureClass key in SelectCollection.Instance().FeatureClassInfoMap.Keys) { ResultSetInfo resultSetInfo = SelectCollection.Instance().FeatureClassInfoMap[key] as ResultSetInfo; if (resultSetInfo != null && resultSetInfo.OidList != null) { hashMap[key] = resultSetInfo.OidList; } } System.Collections.Generic.List <int> list = hashMap[featureClassInfo] as System.Collections.Generic.List <int>; if (list != null) { if (list.Contains(featureId)) { app.Current3DMapControl.FeatureManager.UnhighlightFeature(featureClass, featureId); list.Remove(featureId); } else { list.Add(featureId); } } else { hashMap[featureClassInfo] = new System.Collections.Generic.List <int> { featureId }; } } SelectCollection.Instance().UpdateSelection(hashMap); } else { SelectCollection.Instance().Clear(); app.Current3DMapControl.TransformHelper.Type = gviEditorType.gviEditorNone; } } } } } RenderControlEditServices.Instance().SetEditorPosition(SelectCollection.Instance().FcRowBuffersMap); //fDECommand.SetSelectionMap(); //CommandManagerServices.Instance().CallCommand(fDECommand); app.Workbench.UpdateMenu(); }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { try { this.axRenderControl1.FeatureManager.UnhighlightAll(); if (PickResult != null) { if (PickResult.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult; int fid = flpr.FeatureId; this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow); ////////////////////////////////////////////////////////////////////////// // // GeometryConvert的代码添加在这里 // ////////////////////////////////////////////////////////////////////////// fidList.Clear(); fidList.Add(fid); IRowBuffer rowGC = _featureClass.GetRow(fidList[0]); int nPose = rowGC.FieldIndex("Geometry"); if (nPose == -1) { MessageBox.Show("不存在Geometry列"); return; } // 获取ModelPoint IModelPoint modelPointGC = null; if (rowGC != null) { nPose = rowGC.FieldIndex("Geometry"); IGeometry geo = rowGC.GetValue(nPose) as IGeometry; if (geo.GeometryType == gviGeometryType.gviGeometryModelPoint) { modelPointGC = geo as IModelPoint; } } this.Text = "拾取成功"; // 获取Model string modelName = modelPointGC.ModelName; IModel modelGC = (_featureClass.FeatureDataSet as IResourceManager).GetModel(modelName); // 1、获取MultiTriMesh IGeometryConvertor gc = new GeometryConvertor(); IMultiTriMesh multiTM = gc.ModelPointToTriMesh(modelGC, modelPointGC, false); this.Text = "ModelToTriMesh完成"; if (this.cbCreateRenderTriMesh.Checked) { // 创建RenderTriMesh在三维上显示 for (int i = 0; i < multiTM.GeometryCount; i++) { ITriMesh tm = multiTM.GetGeometry(i) as ITriMesh; IRenderTriMesh rtm = this.axRenderControl1.ObjectManager.CreateRenderTriMesh(tm, null, rootId); //随机颜色填充TriMesh Random randObj = new Random(i); int aColor = randObj.Next(0, 255); int gColor = randObj.Next(0, 255); int rColor = randObj.Next(0, 255); ISurfaceSymbol ss = new SurfaceSymbol(); ss.Color = System.Drawing.Color.FromArgb(rColor, gColor, aColor); rtm.Symbol = ss; rTMeshList.Add(rtm); } } if (this.cbCreateRenderPolygon.Checked) { // 2、获取投影MultiPolygon IMultiPolygon multiPolygon = gc.ProjectTriMeshToPolygon(multiTM, 1.0); this.Text = "MultiTriMeshToFootprint完成。面积:" + multiPolygon.GetArea(); // 创建RenderPolygon在三维上显示 for (int i = 0; i < multiPolygon.GeometryCount; i++) { IPolygon polygon = multiPolygon.GetGeometry(i) as IPolygon; IRenderPolygon rpolygon = this.axRenderControl1.ObjectManager.CreateRenderPolygon(polygon, null, rootId); rPolygonList.Add(rpolygon); } } if (this.cbCreateRenderPolygon2.Checked) { // 3、获取切割MultiPolygon double heightSpec = 0.0, heightIntersect = 0.0; Double.TryParse(IntersectPoint.Z.ToString(), out heightIntersect); fidList.Clear(); fidList.Add(fid); IEnvelope box = _featureClass.GetFeaturesEnvelope(fidList.ToArray(), "Geometry"); heightSpec = System.Math.Abs(heightIntersect - box.MinZ); // 注意:CutTriMeshToPolygon方法的第三个参数为空间分辨率,应该选择合适值。 // 值过大会导致结果不精确,值过小会导致转换时间过长。使用时应设置大小合适的值来平衡精度和效率问题。 IMultiPolygon multiPolygon2 = gc.CutTriMeshToPolygon(multiTM, heightSpec, 0.5); this.Text = "MultiTriMeshToFootprint2完成。面积:" + multiPolygon2.GetArea(); // 创建RenderPolygon在三维上显示 for (int i = 0; i < multiPolygon2.GeometryCount; i++) { IPolygon polygon2 = multiPolygon2.GetGeometry(i) as IPolygon; IRenderPolygon rpolygon2 = this.axRenderControl1.ObjectManager.CreateRenderPolygon(polygon2, null, rootId); rPolygonList2.Add(rpolygon2); } } if (this.cbCreateRenderMulPoint.Checked) { // 4、获取MultiPoint IMultiPoint multiPoint = gc.MultiTriMeshToMultiPoint(multiTM, 3.0); this.Text = "MultiTriMeshToMultiPoint完成。MultiPoint个数为:" + multiPoint.GeometryCount; //创建RenderPoint在三维上显示 IRenderMultiPoint rpoint = this.axRenderControl1.ObjectManager.CreateRenderMultiPoint(multiPoint, null, rootId); rPointList.Add(rpoint); } } } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } }
private void AxRenderControl3D_RcMouseClickSelect(object sender, Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseClickSelectEvent e) { IFdeCursor cursor = null; IRowBuffer row = null; try { IPickResult pr = e.pickResult; if (pr.Type == gviObjectType.gviObjectFeatureLayer && pr is IFeatureLayerPickResult) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int oid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; if (this._dictFeatureClass.ContainsKey(fl.FeatureClassId)) { IFeatureClass fc = this._dictFeatureClass[fl.FeatureClassId]; if (fc == null) { return; } IQueryFilter filter = new QueryFilter(); filter.WhereClause = "oid = " + oid; cursor = fc.Search(filter, true); IFieldInfoCollection fiCol = fc.GetFields(); Dictionary <string, string> dict = new Dictionary <string, string>(); if ((row = cursor.NextRow()) != null) { for (int i = 0; i < fiCol.Count; i++) { IFieldInfo fi = fiCol.Get(i); object obj = row.GetValue(i); if (obj == null) { continue; } string str = ""; switch (fi.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldUnknown: case gviFieldType.gviFieldGeometry: break; case gviFieldType.gviFieldFloat: case gviFieldType.gviFieldDouble: double d; if (double.TryParse(obj.ToString(), out d)) { str = d.ToString("0.00"); } break; default: str = obj.ToString(); break; } if (!string.IsNullOrEmpty(str.Trim())) { string temp = fi.Name + "(" + fi.Alias + ")"; dict[temp] = str; } } } #region ITableLabel tl = DrawTool.CreateTableLabel2(dict.Count); tl.TitleText = "属性查询"; int num = 0; foreach (KeyValuePair <string, string> kv in dict) { string k = kv.Key; string v = kv.Value; tl.SetRecord(num, 0, k); tl.SetRecord(num, 1, v); num++; } tl.Position = e.intersectPoint; allTLGuid.Add(tl.Guid); #endregion } } } catch (Exception ex) { } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { try { if (PickResult != null) { if (PickResult.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult; int fid = flpr.FeatureId; this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow); ////////////////////////////////////////////////////////////////////////// // // GeometryConvert的代码添加在这里 // ////////////////////////////////////////////////////////////////////////// fidList.Clear(); fidList.Add(fid); IRowBuffer rowGC = _featureClass.GetRow(fidList[0]); int nPose = rowGC.FieldIndex("Geometry"); if (nPose == -1) { MessageBox.Show("不存在Geometry列"); return; } // 获取polygon IPolygon polygonGC = null; if (rowGC != null) { nPose = rowGC.FieldIndex("Geometry"); IGeometry geo = rowGC.GetValue(nPose) as IGeometry; if (geo.GeometryType == gviGeometryType.gviGeometryPolygon) { polygonGC = geo as IPolygon; } } this.Text = "拾取成功"; //第一个Tab页:ExtrudePolygonToModel if (this.tabControl1.SelectedIndex == 0) { // 1.调接口构造模型 IGeometryConvertor gc = new GeometryConvertor(); gviRoofType rooftype = gviRoofType.gviRoofFlat; switch (this.comboxRoofType.Text) { case "Flat": rooftype = gviRoofType.gviRoofFlat; break; case "Gable": rooftype = gviRoofType.gviRoofGable; break; case "Hip": rooftype = gviRoofType.gviRoofHip; break; } string imgPath = (strMediaPath + @"\dds"); string roof = this.comboBoxRoofTexture.Text; string facade = this.comboBoxFacadeTexture.Text; IModelPoint mp = null; IModel model = null; if (!gc.ExtrudePolygonToModel(polygonGC, int.Parse(this.numFloorNumber.Value.ToString()), double.Parse(this.numFloorHeight.Value.ToString()), double.Parse(this.numSlopeAngle.Value.ToString()), rooftype, facade, roof, out mp, out model)) { MessageBox.Show("拉体块出错!"); return; } //2、将模型及贴图写入osg文件 string modelName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径 IResourceFactory resFactory = new ResourceFactory(); string[] imageNames = model.GetImageNames(); IPropertySet ps = new PropertySet(); for (int i = 0; i < imageNames.Length; i++) { string imgName = imageNames[i]; IImage img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\facade", imgName)); if (img == null) { img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\roof", imgName)); } ps.SetProperty(imgName, img); } model.WriteFile(modelName, ps); //3、测试显示模型 mp.ModelName = modelName; IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId); rmp.MouseSelectMask = gviViewportMask.gviViewNone; rmp.MaxVisibleDistance = 100000; this.axRenderControl1.Camera.LookAtEnvelope(mp.Envelope);//飞入 mpList.Add(rmp); } //第二个tab页:ExtrudePolygonToTriMesh else { // 1.调接口构造模型 IGeometryConvertor gc = new GeometryConvertor(); ITriMesh tm = gc.ExtrudePolygonToTriMesh(polygonGC, double.Parse(this.numHeight.Value.ToString()), true); if (tm == null) { MessageBox.Show("拉体块出错!"); return; } //2、显示三角面 //---- 渲染样式不是必须的 ----- ISurfaceSymbol surfaceSym = new SurfaceSymbol(); surfaceSym.Color = System.Drawing.Color.Red; surfaceSym.EnableLight = true; ICurveSymbol curveSym = new CurveSymbol(); curveSym.Color = System.Drawing.Color.Yellow; curveSym.Width = 10; surfaceSym.BoundarySymbol = curveSym; //---- ------------------ ----- IRenderTriMesh rmp = this.axRenderControl1.ObjectManager.CreateRenderTriMesh(tm, surfaceSym, rootId); rmp.MouseSelectMask = gviViewportMask.gviViewNone; rmp.MaxVisibleDistance = 100000; this.axRenderControl1.Camera.LookAtEnvelope(rmp.Envelope);//飞入 tmList.Add(rmp); } } } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } }
void axRenderControl1_RcMouseDragSelect(IPickResultCollection PickResults, gviModKeyMask Mask) { IPickResultCollection prc = PickResults; if (prc == null) { return; } Hashtable fcEnvMap = new Hashtable(); this.axRenderControl1.FeatureManager.UnhighlightAll(); for (int i = 0; i < prc.Count; i++) { IPickResult pr = prc.Get(i); if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); if (fcEnvMap.ContainsKey(fc)) { List <int> fids = fcEnvMap[fc] as List <int>; fids.Add(fid); fcEnvMap.Remove(fc); fcEnvMap.Add(fc, fids); } else { List <int> fids = new List <int>(); fids.Add(fid); fcEnvMap.Add(fc, fids); fcGUIDs.Add(fc.Guid); } } } } } // 计算Envelope env = null; foreach (IFeatureClass fc in fcEnvMap.Keys) { List <int> fids = fcEnvMap[fc] as List <int>; if (env == null) { env = fc.GetFeaturesEnvelope(fids.ToArray(), "Geometry"); } else { env.ExpandByEnvelope(fc.GetFeaturesEnvelope(fids.ToArray(), "Geometry")); } } // 设定出图参数 switch (type) { case ExportType.Export25D: { Export25D(); } break; case ExportType.ExportDEM: { ExportDEM(); } break; case ExportType.ExportDOM: { ExportDOM(); } break; case ExportType.ExportOrthoImage: { ExportOrthoImage(); } break; } // 恢复漫游模式 this.axRenderControl1.InteractMode = gviInteractMode.gviInteractNormal; }
private void ShowFlowDirect(IFeatureLayerPickResult pr) { if (pr == null) { return; } IRowBuffer row = null; IFdeCursor cursor = null; try { int fid = pr.FeatureId; DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(pr.FeatureLayer.FeatureClassId.ToString()); if (dffc == null) { return; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass fac = dffc.GetFacilityClass(); if (fc == null || fac == null || fac.Name != "PipeLine") { return; } DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("FlowDirect"); if (fi == null) { return; } IFieldInfoCollection fiCol = fc.GetFields(); int index = fiCol.IndexOf(fi.Name); if (index == -1) { return; } int indexShape = fiCol.IndexOf("Shape"); IQueryFilter filter = new QueryFilter(); filter.WhereClause = "oid=" + fid; cursor = fc.Search(filter, false); row = cursor.NextRow(); if (row == null) { return; } IPolyline line = null; if (indexShape != -1 && !row.IsNull(indexShape)) { object obj = row.GetValue(indexShape); if (obj != null && obj is IPolyline) { line = obj as IPolyline; } } string flowDirectValue = "0"; int type = 1;// 1表示具有流向字段;2表示从高到低 if (!row.IsNull(index)) { flowDirectValue = row.GetValue(index).ToString(); if (flowDirectValue != "0" && flowDirectValue != "1") { flowDirectValue = "0"; } type = 1; } else if (line != null) { if (line.StartPoint.Z > line.EndPoint.Z) { flowDirectValue = "0"; } else { flowDirectValue = "1"; } type = 2; } if (line == null) { return; } if (this._isAuth) { #region 流向渲染1 FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString()); if (reg == null) { return; } TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode); if (tc == null) { return; } FacStyleClass style = null; List <FacStyleClass> facilityStyles = FacilityInfoService.GetFacStyleByFacClassCode(reg.FacClassCode); if ((facilityStyles != null) && (facilityStyles.Count > 0)) { style = facilityStyles[0]; } PipeLineFac plfac = new PipeLineFac(reg, style, row, tc); IRenderModelPoint rmp = null; DrawGeometry.Ocx = DF3DApplication.Application.Current3DMapControl; plfac.ShowFlowDirection(int.Parse(flowDirectValue), out rmp); if (rmp != null) { this._listRender.Add(rmp.Guid); } #endregion } else { #region 流向渲染2 IEulerAngle angle = DF3DApplication.Application.Current3DMapControl.Camera.GetAimingAngles2(line.StartPoint, line.EndPoint); double dia = 0.0; string diaField = fac.GetFieldInfoNameBySystemName("Diameter"); int indexDia = fiCol.IndexOf(diaField); if (indexDia != -1 && !row.IsNull(indexDia)) { string diaStr = row.GetValue(indexDia).ToString(); int indexDia1 = diaStr.ToString().IndexOf('*'); if (indexDia1 != -1) { var dia1 = int.Parse(diaStr.ToString().Substring(0, indexDia1)); var dia2 = int.Parse(diaStr.ToString().Substring(indexDia1 + 1, diaStr.ToString().Length)); dia = ((dia1 > dia2) ? dia1 : dia2) * 0.001; } else { dia = int.Parse(diaStr) * 0.001; } } List <IPoint> points = new List <IPoint>(); if (flowDirectValue == "0") { for (int i = 0; i < line.PointCount; i++) { IPoint pt = line.GetPoint(i); pt.Z += dia / 2; points.Add(pt); } } else if (flowDirectValue == "1") { for (int i = line.PointCount - 1; i >= 0; i--) { IPoint pt = line.GetPoint(i); pt.Z += dia / 2; points.Add(pt); } } for (int i = 0; i < points.Count - 1; i++) { IPoint pt1 = points[i]; var pt2 = points[i + 1]; double delt = 0; double _rate, _distance; if (!(Math.Abs(dia) < 0.0000001)) { delt = 2.0 * dia; if (dia <= 0.5 && dia >= 0.3) { _rate = 7 * dia; _distance = 3 * dia / 0.4; } else if (dia < 0.3 && dia > 0.1) { _rate = 12 * dia; _distance = 6 * dia / 0.4; } else if (dia <= 0.1) { _rate = 22 * dia; _distance = 9 * dia / 0.4; } else { _rate = 3.5 * dia; _distance = 1.5 * dia / 0.4; } } else { _rate = 2.0; _distance = 3.0; //z = maxZ + 0.2; delt = 0.2; } List <IPoint> list = DisPerseLine(pt1, pt2, _distance); if (list.Count < 2) { return; } List <IPoint> list1 = new List <IPoint>(); IGeometryFactory geoFact = new GeometryFactoryClass(); for (int j = 0; j < list.Count - 1; j++) { IPoint p = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); p.X = (list[j].X + list[j + 1].X) / 2; p.Y = (list[j].Y + list[j + 1].Y) / 2; p.Z = (list[j].Z + list[j + 1].Z) / 2; list1.Add(p); } for (var m = 0; m < list1.Count; m++) { IPosition pos = new PositionClass(); pos.X = list1[m].X; pos.Y = list1[m].Y; pos.Altitude = list1[m].Z + delt; pos.AltitudeType = gviAltitudeType.gviAltitudeTerrainAbsolute; pos.Heading = angle.Heading; pos.Tilt = angle.Tilt; pos.Roll = angle.Roll; UInt32 color; if (type == 1) { color = 0xFFFFFF00; } else { color = 0xFF00FFFF; } ITerrainArrow rArrow = DF3DApplication.Application.Current3DMapControl.ObjectManager.CreateArrow(pos, 0.8 * _rate, 3, color, color, DF3DApplication.Application.Current3DMapControl.ProjectTree.RootID); this._listRender.Add(rArrow.Guid); } } #endregion } } catch (Exception ex) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { try { if (PickResult != null) { if (PickResult.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult; int fid = flpr.FeatureId; this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Red); ////////////////////////////////////////////////////////////////////////// // // GeometryConvert的代码添加在这里 // ////////////////////////////////////////////////////////////////////////// fidList.Clear(); fidList.Add(fid); IRowBuffer rowGC = _featureClass.GetRow(fidList[0]); int nPose = rowGC.FieldIndex("Geometry"); if (nPose == -1) { MessageBox.Show("不存在Geometry列"); return; } // 获取polygon IPolygon polygonGC = null; if (rowGC != null) { nPose = rowGC.FieldIndex("Geometry"); IGeometry geo = rowGC.GetValue(nPose) as IGeometry; if (geo.GeometryType == gviGeometryType.gviGeometryPolygon) { polygonGC = geo as IPolygon; } } this.Text = "拾取成功"; param = new PropertySet(); //第一个Tab页:PolygonToBuilding if (this.tabControl1.SelectedIndex == 0) { // 1.调接口构造模型 double floorNum = double.Parse(this.numFloorNumber.Value.ToString()); param.SetProperty("FloorNumber", floorNum); double floorHgt = double.Parse(this.numFloorHeight.Value.ToString()); param.SetProperty("FloorHeight", floorHgt); double interiorOffset = double.Parse(this.numInteriorOffset.Value.ToString()); param.SetProperty("InteriorOffset", interiorOffset); double exteriorOffset = double.Parse(this.numExteriorOffset.Value.ToString()); param.SetProperty("ExteriorOffset", exteriorOffset); double heightOffset = double.Parse(this.numHeightOffset.Value.ToString()); param.SetProperty("HeightOffset", heightOffset); string imgPath = (strMediaPath + @"\dds"); string roof = this.comboBoxRoofTexture.Text; string facade = this.comboBoxFacadeTexture.Text; param.SetProperty("FacadeTexture", roof); param.SetProperty("RoofTexture", facade); IModelPoint mp = null; IModel model = null; if (!paraModel.PolygonToBuilding(polygonGC, param, out mp, out model)) { MessageBox.Show("拉体块出错!"); return; } //2、将模型及贴图写入osg文件 string modelName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径 IResourceFactory resFactory = new ResourceFactory(); string[] imageNames = model.GetImageNames(); IPropertySet ps = new PropertySet(); for (int i = 0; i < imageNames.Length; i++) { string imgName = imageNames[i]; IImage img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\facade", imgName)); if (img == null) { img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\roof", imgName)); } ps.SetProperty(imgName, img); } model.WriteFile(modelName, ps); //3、测试显示模型 mp.ModelName = modelName; IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId); rmp.MouseSelectMask = gviViewportMask.gviViewNone; rmp.MaxVisibleDistance = 100000; this.axRenderControl1.Camera.LookAtEnvelope(mp.Envelope);//飞入 mpList.Add(rmp); } //第二个tab页:ExtrudePolygonToTriMesh else { // 1.调接口构造模型 double floorNum = double.Parse(this.numFloorNumber.Value.ToString()); param.SetProperty("FloorNumber", floorNum); double floorHgt = double.Parse(this.numFloorHeight.Value.ToString()); param.SetProperty("FloorHeight", floorHgt); double interiorOffset = double.Parse(this.numInteriorOffset.Value.ToString()); param.SetProperty("InteriorOffset", interiorOffset); double exteriorOffset = double.Parse(this.numExteriorOffset.Value.ToString()); param.SetProperty("ExteriorOffset", exteriorOffset); double heightOffset = double.Parse(this.numHeightOffset.Value.ToString()); param.SetProperty("HeightOffset", heightOffset); double buildingHeight = double.Parse(this.numBuildingHeight.Value.ToString()); param.SetProperty("BuildingHeight", buildingHeight); double buildingXScale = double.Parse(this.numBuildingXScale.Value.ToString()); param.SetProperty("BuildingXScale", buildingXScale); double buildingYScale = double.Parse(this.numBuildingYScale.Value.ToString()); param.SetProperty("BuildingYScale", buildingYScale); string imgPath = (strMediaPath + @"\dds"); string roof = this.comboBoxRoofTexture.Text; string facade = this.comboBoxFacadeTexture.Text; param.SetProperty("FacadeTexture", roof); param.SetProperty("RoofTexture", facade); IModelPoint mp = null; IModel model = null; if (!paraModel.PolygonToBuilding(polygonGC, param, out mp, out model)) { MessageBox.Show("拉体块出错!"); return; } //2、将模型及贴图写入osg文件 string modelName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径 IResourceFactory resFactory = new ResourceFactory(); string[] imageNames = model.GetImageNames(); IPropertySet ps = new PropertySet(); for (int i = 0; i < imageNames.Length; i++) { string imgName = imageNames[i]; IImage img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\facade", imgName)); if (img == null) { img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\roof", imgName)); } ps.SetProperty(imgName, img); } model.WriteFile(modelName, ps); //3、测试显示模型 mp.ModelName = modelName; IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId); rmp.MouseSelectMask = gviViewportMask.gviViewNone; rmp.MaxVisibleDistance = 100000; this.axRenderControl1.Camera.LookAtEnvelope(mp.Envelope);//飞入 mpList.Add(rmp); } } } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } }
private void OnFinishedDraw() { if (this._drawTool != null) { if (this.radioGroup1.SelectedIndex == 0) { if (this._drawTool.GetSelectFeatureLayerPickResult() != null && this._drawTool.GetSelectPoint() != null) { IFeatureLayerPickResult pr = this._drawTool.GetSelectFeatureLayerPickResult(); string g = pr.FeatureLayer.FeatureClassId.ToString(); string facName = Dictionary3DTable.Instance.GetFacilityClassNameByDFFeatureClassID(g); if (facName != "PipeLine") { XtraMessageBox.Show("您选择的不是管线设施。", "提示"); return; } DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(g); if (dffc == null) { return; } int fid = pr.FeatureId; MajorClass mc = LogicDataStructureManage3D.Instance.GetMajorClassByDFFeatureClassID(g); if (mc == null) { return; } _num++; IPoint interPoint = this._drawTool.GetSelectPoint(); ISimplePointSymbol sps = new SimplePointSymbol(); sps.FillColor = Convert.ToUInt32(SystemInfo.Instance.FillColor, 16); sps.Size = SystemInfo.Instance.SymbolSize; IRenderPoint rp = d3.ObjectManager.CreateRenderPoint(interPoint, sps, d3.ProjectTree.RootID); this._dict[_num] = rp.Guid; ILabel label = d3.ObjectManager.CreateLabel(d3.ProjectTree.RootID); IPoint pt = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pt.SetCoords(interPoint.X, interPoint.Y, interPoint.Z + 1, 0, 0); label.Position = pt; label.Text = _num.ToString(); TextSymbol ts = new TextSymbol(); TextAttribute ta = new TextAttribute(); ta.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16); ta.TextSize = SystemInfo.Instance.TextSize; ts.TextAttribute = ta; label.TextSymbol = ts; this._dictLabel[_num] = label.Guid; DataRow dr = this._dt.NewRow(); dr["Num"] = _num; dr["PipeType"] = mc; dr["Fid"] = fid; dr["FeatureClass"] = dffc.GetFeatureClass(); dr["InterPoint"] = interPoint; this._dt.Rows.Add(dr); } } if (this.radioGroup1.SelectedIndex == 1) { if (this._drawTool.GetGeo() != null) { WaitForm.Start("正在进行相交查询...", "请稍后"); IPolyline line = this._drawTool.GetGeo() as IPolyline; IPolyline l = line.Clone2(gviVertexAttribute.gviVertexAttributeNone) as IPolyline; List <DF3DFeatureClass> listdffc = DF3DFeatureClassManager.Instance.GetFeatureClassByFacilityClassName("PipeLine"); if (listdffc == null) { return; } foreach (DF3DFeatureClass dffc in listdffc) { IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null) { continue; } MajorClass mc = LogicDataStructureManage3D.Instance.GetMajorClassByDFFeatureClassID(fc.GuidString); if (mc == null) { continue; } if (this._dt.Rows.Count > 0) { if (this._dt.Rows[0]["PipeType"] != null && this._dt.Rows[0]["PipeType"] is MajorClass) { if (mc.Name != (this._dt.Rows[0]["PipeType"] as MajorClass).Name) { continue; } } } ISpatialFilter filter = new SpatialFilter(); filter.Geometry = l; filter.GeometryField = "FootPrint"; filter.SpatialRel = gviSpatialRel.gviSpatialRelIntersects; int counttemp = fc.GetCount(filter); if (counttemp == 0) { continue; } IFdeCursor cursor = null; IRowBuffer row = null; try { IFieldInfoCollection fields = fc.GetFields(); cursor = fc.Search(filter, true); while ((row = cursor.NextRow()) != null) { IPolyline geo = row.GetValue(fields.IndexOf("FootPrint")) as IPolyline; IPolyline geoShape = row.GetValue(fields.IndexOf("Shape")) as IPolyline; if (geo == null || geoShape == null || geo.GeometryType != gviGeometryType.gviGeometryPolyline || geoShape.GeometryType != gviGeometryType.gviGeometryPolyline) { continue; } if ((l as IRelationalOperator2D).Intersects2D(geo)) { IPoint intersectPointTemp = (l as ITopologicalOperator2D).Intersection2D(geo) as IPoint; double height = geoShape.StartPoint.Z + (geoShape.EndPoint.Z - geoShape.StartPoint.Z) * Math.Sqrt((geo.StartPoint.X - intersectPointTemp.X) * (geo.StartPoint.X - intersectPointTemp.X) + (geo.StartPoint.Y - intersectPointTemp.Y) * (geo.StartPoint.Y - intersectPointTemp.Y)) / geo.Length; IPoint intersectPoint = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ); intersectPoint.Z = height; intersectPoint.X = intersectPointTemp.X; intersectPoint.Y = intersectPointTemp.Y; int fid = int.Parse(row.GetValue(0).ToString()); _num++; ISimplePointSymbol sps = new SimplePointSymbol(); sps.FillColor = Convert.ToUInt32(SystemInfo.Instance.FillColor, 16); sps.Size = SystemInfo.Instance.SymbolSize; IRenderPoint rp = d3.ObjectManager.CreateRenderPoint(intersectPoint, sps, d3.ProjectTree.RootID); this._dict[_num] = rp.Guid; ILabel label = d3.ObjectManager.CreateLabel(d3.ProjectTree.RootID); IPoint pt = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pt.SetCoords(intersectPoint.X, intersectPoint.Y, intersectPoint.Z + 1, 0, 0); label.Position = pt; label.Text = _num.ToString(); TextSymbol ts = new TextSymbol(); TextAttribute ta = new TextAttribute(); ta.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16); ta.TextSize = SystemInfo.Instance.TextSize; ts.TextAttribute = ta; label.TextSymbol = ts; this._dictLabel[_num] = label.Guid; DataRow dr = this._dt.NewRow(); dr["Num"] = _num; dr["PipeType"] = mc; dr["Fid"] = fid; dr["FeatureClass"] = fc; dr["InterPoint"] = intersectPoint; this._dt.Rows.Add(dr); } } } catch (Exception ex) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } } WaitForm.Stop(); } } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { try { if (PickResult != null) { if (PickResult.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult; int fid = flpr.FeatureId; this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow); ////////////////////////////////////////////////////////////////////////// // // GeometryConvert的代码添加在这里 // ////////////////////////////////////////////////////////////////////////// fidList.Clear(); fidList.Add(fid); IRowBuffer rowGC = _featureClass.GetRow(fidList[0]); int nPose = rowGC.FieldIndex("Geometry"); if (nPose == -1) { MessageBox.Show("不存在Geometry列"); return; } // 获取polygon IPolyline polylineGC = null; if (rowGC != null) { nPose = rowGC.FieldIndex("Geometry"); IGeometry geo = rowGC.GetValue(nPose) as IGeometry; if (geo.GeometryType == gviGeometryType.gviGeometryPolyline) { polylineGC = geo as IPolyline; } } if (polylineGC != null) { this.Text = "拾取成功"; } else { this.Text = "拾取失败"; } param = new PropertySet(); if (this.tabControl1.SelectedIndex == 0) { // 1.调接口构造模型 double innerRadius = double.Parse(this.numInnerRadius.Value.ToString()); param.SetProperty("InnerRadius", innerRadius); double outerRadius = double.Parse(this.numOuterRadius.Value.ToString()); param.SetProperty("OuterRadius", outerRadius); double deflection = double.Parse(this.numDeflection.Value.ToString()); param.SetProperty("Deflection", deflection); Color difColor = Color.FromArgb(Convert.ToInt32(DifColorBox.Text, 16)); param.SetProperty("DiffuseColor", difColor); Color speColor = Color.FromArgb(Convert.ToInt32(SpeColorBox.Text, 16)); param.SetProperty("SpecularColor", speColor); IModelPoint mp = null; IModel model = null; if (!paraModel.PolylineToPipeLine(polylineGC, param, out mp, out model)) { MessageBox.Show("拉管线出错!"); return; } //2、将模型及贴图写入osg文件 string modelName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径 model.WriteFile(modelName, null); //3、测试显示模型 mp.ModelName = modelName; IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId); rmp.MouseSelectMask = gviViewportMask.gviViewNone; rmp.MaxVisibleDistance = 100000; this.axRenderControl1.Camera.LookAtEnvelope(mp.Envelope);//飞入 mpList.Add(rmp); } } } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { if (PickResult == null) { return; } this.dataGridView1.Rows.Clear(); this.axRenderControl1.FeatureManager.UnhighlightAll(); rowMap.Clear(); IPickResult pr = PickResult; if (pr.Type != gviObjectType.gviObjectFeatureLayer) { return; } IFeatureLayerPickResult fpr = pr as IFeatureLayerPickResult; IFeatureLayer layer = fpr.FeatureLayer; IFeatureClassInfo cinfo = layer.FeatureClassInfo; if (cinfo.DataSourceConnectionString.Contains("FireBird2x")) { return; } IDataSource ds = (new DataSourceFactory()).OpenDataSourceByString(cinfo.DataSourceConnectionString); IFeatureDataSet dset = ds.OpenFeatureDataset(cinfo.DataSetName); IFeatureClass shpfc = dset.OpenFeatureClass(cinfo.FeatureClassName); IRowBuffer shprow = shpfc.GetRow(fpr.FeatureId); int shpindex = shprow.FieldIndex("Geometry"); IPolygon polygon = shprow.GetValue(shpindex) as IPolygon; if (polygon == null) { return; } IFdeCursor cursor = null; try { foreach (IFeatureClass fc in fcMap.Keys) { IRowBuffer row = null; List <IRowBuffer> list = new List <IRowBuffer>(); ISpatialFilter filter = new SpatialFilter(); filter.Geometry = polygon; filter.SpatialRel = gviSpatialRel.gviSpatialRelEnvelope; filter.GeometryField = "Geometry"; cursor = fc.Search(filter, false); while ((row = cursor.NextRow()) != null) { list.Add(row); } foreach (IRowBuffer r in list) { int geometryIndex = -1; geometryIndex = r.FieldIndex("Geometry"); if (geometryIndex != -1) { int oid = int.Parse(r.GetValue(0).ToString()); this.axRenderControl1.FeatureManager.HighlightFeature(fc, oid, System.Drawing.Color.Red); string fid = ""; IEnvelope env = null; for (int i = 0; i < r.FieldCount; i++) { string fieldName = r.Fields.Get(i).Name; if (r.Fields.Get(i).Name == "oid") { fid = r.GetValue(i).ToString(); } else if (r.Fields.Get(i).Name == "Geometry") { IGeometry geometry = r.GetValue(i) as IModelPoint; env = geometry.Envelope; } } RowObject ro = new RowObject() { FID = fid, FCGUID = fc.Guid.ToString(), FCName = fc.Name, FeatureClass = fc, Envelop = env }; if (!rowMap.ContainsKey(ro.FID + "/" + ro.FCGUID)) { rowMap.Add(ro.FID + "/" + ro.FCGUID, ro); } } } // end of foreach (IRowBuffer r in list) } // end of foreach (IFeatureClass fc in fcMap.Keys) this.Text = "分析完成!"; LoadGridView(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (cursor != null) { cursor.Dispose(); cursor = null; } } }