private void button1_Click(object sender, EventArgs e) { string path = textBox5.Text; string s1 = textBox1.Text; string s2 = textBox2.Text; string s3 = textBox3.Text; string s4 = textBox4.Text; string mes = String.Empty; IPosition61 dztpos = null; TECoClass = new TerraExplorerClass(); ITerraExplorer = (ITerraExplorer5)TECoClass; IInfoTree = (IInformationTree5)TECoClass; IObjectManager = (IObjectManager5)TECoClass; try { double dxcoord = double.Parse(s1); double dycoord = double.Parse(s2); double altitude = double.Parse(s3); AltitudeTypeCode ealit = AltitudeTypeCode.ATC_TERRAIN_RELATIVE; dztpos = MainForm.sgworld.Creator.CreatePosition(dxcoord, dycoord, altitude, ealit, 0, 90, 100.0, 1000); dzt = MainForm.sgworld.Creator.CreateModel(dztpos, path, 1, ModelTypeCode.MT_NORMAL, 0, s4); } catch (Exception ex) { mes = String.Format("CreateLabelButton_Click Exception :{0}", ex.Message); Log4NetHelper.WriteLog(typeof(AddgeologicbodyForm), ex); MessageBox.Show(mes); } }
void TE_OnLButtonDown(int Flags, int X, int Y, ref object pbHandled) { string strModel = ConfigurationManager.AppSettings["FloorPath"]; ITerraExplorerObject61 objModel = Program.pCreator6.GetObject(Program.IInfoTree.GetTerraObjectID(Program.IInfoTree.FindItem(strModel))); ////model.ModelType = ModelTypeCode.MT_ANIMATION; m_ModelFloor = objModel as ITerrainModel61; //Type[] types= model.GetType().GetInterfaces(); m_ModelFloor.Visibility.Show = true; if (m_FrmFloor == null || m_FrmFloor.IsDisposed) { m_FrmFloor = new FrmFloor(); m_FrmFloor.FormClosed += new FormClosedEventHandler(m_FrmFloor_FormClosed); } if (m_FrmFloor.Visible == false) { m_FrmFloor.Show(this.m_Hook.UIHook.MainForm); } }
private void simpleButton1_Click(object sender, EventArgs e) { if (m_Flag) { if (MessageBox.Show("已经分析过了,确定要再次分析吗?", "Sunz", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } else { this.Height = this.Height + txtResult.Height; this.Refresh(); Application.DoEvents(); } Clear(); try { // 获取设置 double lampHeight = (double)spinEdit1.Value; double carHeight = (double)spinEdit2.Value; double setHeight = (double)spinEdit3.Value; double carLength = (double)spinEdit4.Value; double lampMustDistance = (double)spinEdit5.Value; LampSetting lampSetting = new LampSetting(); lampSetting.MostLampHeight = lampHeight; lampSetting.MostCarHeight = carHeight; lampSetting.LestSetHeight = setHeight; lampSetting.MostCarLength = carLength; lampSetting.MustViewDistance = lampMustDistance; m_Result.Setting = lampSetting; object[] args = { lampHeight, carHeight, setHeight, carLength, lampMustDistance }; string strArgs = string.Format("信号灯最大高度:{0}米;车辆最大高度:{1}米;车座最小高度:{2}米;车辆最大长度:{3}米;信号灯最小必须可见距离:{4}米", args); string lyr = ConfigurationManager.AppSettings["CrossLayer"]; int lyrID = m_Hook.ProjectTree.FindItem(lyr); if (lyrID < 0) { MessageBox.Show("您的配置有问题或者路口图层没有加载"); return; } ILayer61 teLayer = null; try { teLayer = m_Hook.ProjectTree.GetLayer(lyrID); if (teLayer == null) { return; } } catch { MessageBox.Show("您配置的路口图层不是矢量图层"); return; } // 准备信号灯图层 int lampGroup = m_Hook.ProjectTree.FindItem(m_LampGroup); if (lampGroup > -1) { m_Hook.ProjectTree.DeleteItem(lampGroup); } lampGroup = m_Hook.ProjectTree.CreateGroup(m_LampGroup); int fCount = teLayer.FeatureGroups.Point.Count; string[] strDirects = { "东", "南", "西", "北" }; int fIndex = 0; while (true) { double crossWidth = 10; SendMessage(string.Format("正在分析第{0}个路口...", fIndex + 1)); IFeature61 tefCurrent = teLayer.FeatureGroups.Point[fIndex] as IFeature61; for (int i = 0; i < 4; i++) { SendMessage(string.Format(" 正在分析{0}面的信号灯...", strDirects[i])); crossWidth = Convert.ToDouble(tefCurrent.FeatureAttributes.GetFeatureAttribute(m_RoadWidthFields[i]).Value); if (crossWidth <= 0) { SendMessage(string.Format(" {0}没有支路,不需要信号灯。", strDirects[i])); continue; } string strRoadInfo = string.Format("路口宽度:{0}米", crossWidth); SendMessage(string.Format(" 加载参数:{0};{1}...", strArgs, strRoadInfo)); SendMessage(string.Format(" 正在添加信号灯...")); // 添加信号灯 IPoint fPoint = tefCurrent.Geometry as IPoint; double offSet = crossWidth / 2.0; if (fPoint.X < 180) // 坐标转换 { offSet = offSet / 102166.66666666666666666666666667; } // 按东南西北移动到对面的斑马线 double modelX = fPoint.X + (i == 0 ? -offSet : (i == 2 ? offSet : 0)); double modelY = fPoint.Y + (i == 1 ? offSet : (i == 3 ? -offSet : 0)); // 按东南西北移动到右侧 modelX = modelX + (i == 1 ? offSet : (i == 3 ? -offSet : 0)); modelY = modelY + (i == 0 ? offSet : (i == 2 ? -offSet : 0)); // 根据路口实际方位与正东南西北方位偏移角做位置调整 double rawOffSet = Convert.ToDouble(tefCurrent.FeatureAttributes.GetFeatureAttribute(m_RoadOffsetFields[i]).Value); double dgree = rawOffSet / 180 * Math.PI; double dgreeBase = Math.PI / 4; double dOffsetX = 0; double dOffsetY = 0; switch (i) { case 0: dOffsetX = offSet * (Math.Cos(dgreeBase) - Math.Cos(dgree + dgreeBase)); dOffsetY = offSet * (Math.Sin(dgree + dgreeBase) - Math.Sin(dgreeBase)); break; case 1: dOffsetX = offSet * (Math.Sin(dgree + dgreeBase) - Math.Sin(dgreeBase)); dOffsetY = -offSet * (Math.Cos(dgreeBase) - Math.Cos(dgree + dgreeBase)); break; case 2: dOffsetX = -offSet * (Math.Cos(dgreeBase) - Math.Cos(dgree + dgreeBase)); dOffsetY = -offSet * (Math.Sin(dgree + dgreeBase) - Math.Sin(dgreeBase)); break; case 3: dOffsetX = -offSet * (Math.Sin(dgree + dgreeBase) - Math.Sin(dgreeBase)); dOffsetY = offSet * (Math.Cos(dgreeBase) - Math.Cos(dgree + dgreeBase)); break; } modelX = modelX + dOffsetX; modelY = modelY + dOffsetY; double raw = (rawOffSet + 90 * (1 + i)) % 360; IPosition61 position = m_Hook.Creator.CreatePosition(modelX, modelY, fPoint.Z, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, raw); string strName = string.Format("第{0}个路口{1}面支路", fIndex + 1, strDirects[i]); ITerrainModel61 theModel = m_Hook.Creator.CreateModel(position, m_ModelFile, 1, ModelTypeCode.MT_NORMAL, lampGroup, strName); //m_Hook.Navigate.SetPosition(position); //Application.DoEvents(); // 信号灯信息 LampInfo lampInfo = new LampInfo(); lampInfo.CrossName = (fIndex + 1).ToString(); lampInfo.Name = strName; lampInfo.DirectString = strDirects[i]; lampInfo.CrossWidth = crossWidth; lampInfo.RawOffset = rawOffSet; lampInfo.TheLamp = theModel; lampInfo.X = modelX; lampInfo.Y = modelY; m_Result.AddLamp(lampInfo); // 无论后来计算的结果如何,先添加到结果 // 计算大车遮挡 // 计算时间太短,停一秒 System.Threading.Thread.Sleep(Convert.ToInt32(ConfigurationManager.AppSettings["HeightSleep"])); double lampMustHeight = (carHeight - setHeight) * (lampMustDistance + crossWidth) / (lampMustDistance - carLength) + setHeight; lampInfo.LestHeight = lampMustHeight; SendMessage(string.Format(" 信号最小理论高度为{0}米...", lampMustHeight)); if (lampHeight < lampMustHeight) { lampInfo.HeightFlag = true; SendMessage(string.Format(" 信号灯在有大车情况下不能在规定的最小距离内看到信号灯,必须在路对面增加辅助信号灯.")); SendMessage(string.Format(" 正在添加辅助信号灯...")); // 添加辅助信号灯 position = m_Hook.Creator.CreatePosition(fPoint.X + (i < 1 ? -offSet : offSet), fPoint.Y + (i == 1 || i == 2 ? offSet : -offSet), fPoint.Z); ITerrainModel61 assistantModel = m_Hook.Creator.CreateModel(position, m_ModelFile, 1, ModelTypeCode.MT_NORMAL, lampGroup, string.Format("第{0}个路口{1}辅助", fIndex + 1, strDirects[i])); lampInfo.AssistantLamp = assistantModel; continue; } SendMessage(string.Format(" 正在计算是否会因为建筑物及绿化带等引起信号灯盲区...")); // 计算因为建筑物及绿化带等引起的 // 计算过程就先不计算了,从数据里读吧,停2秒 System.Threading.Thread.Sleep(Convert.ToInt32(ConfigurationManager.AppSettings["BuildingSleep"])); if (Convert.ToInt32(tefCurrent.FeatureAttributes.GetFeatureAttribute(m_FlagField).Value) > 0) // 引起盲区 { lampInfo.ViewFlag = false; SendMessage(string.Format(" 由于建筑物及绿化带等将引起信号灯盲区,必须在路对面增加辅助信号灯.")); SendMessage(string.Format(" 正在添加辅助信号灯...")); // 添加辅助信号灯 position = m_Hook.Creator.CreatePosition(fPoint.X + (i < 1 ? -offSet : offSet), fPoint.Y + (i == 1 || i == 2 ? offSet : -offSet), fPoint.Z); ITerrainModel61 assistantModel = m_Hook.Creator.CreateModel(position, m_ModelFile, 1, ModelTypeCode.MT_NORMAL, lampGroup, string.Format("第{0}个路口{1}辅助", fIndex + 1, strDirects[i])); lampInfo.AssistantLamp = assistantModel; } } fIndex++; if (fIndex == fCount) { break; } } SendMessage("自动化分析已完成。"); m_Result.LampAnalysisFinished(); m_Flag = true; } catch { MessageBox.Show("对不起,分析过程出现错误,这通常是由配置与数据不匹配引起的"); return; } }
/// <summary> /// 左键单击事件 /// 获取建筑物信息 /// </summary> /// <param name="Flags"></param> /// <param name="X"></param>mo /// <param name="Y"></param> /// <param name="pbHandled"></param> void TE_OnLButtonDown(int Flags, int X, int Y, ref object pbHandled) { try { int modelLayerID = Hook.ProjectTree.FindItem(ConfigurationManager.AppSettings["LayerPath"]); // 模型复原 // 显示 int groupID = Hook.ProjectTree.FindItem(Pipe_Group_Name); if (groupID > 0) { Hook.ProjectTree.DeleteItem(groupID); } if (m_FeatureSelected != null) { //m_FeatureSelected.FeatureAttributes.GetFeatureAttribute("MODELNAME").Value = m_ModelName; if (modelLayerID > 0) { ILayer61 lyrModel = Hook.ProjectTree.GetLayer(modelLayerID); lyrModel.Filter = ""; //lyrModel.Refresh(); //lyrModel.Save(); //lyrModel.Refresh(); } } // 开始新的 // 取到模型 object longitude, latitude, objectID, height, objType; objType = 17; Program.pRender.ScreenToWorld(X, Y, ref objType, out longitude, out height, out latitude, out objectID); if (objectID.ToString() == "") { objType = 16; Program.pRender.ScreenToWorld(X, Y, ref objType, out longitude, out height, out latitude, out objectID); } if (objectID.ToString() == "") { return; } groupID = Hook.ProjectTree.CreateGroup(Pipe_Group_Name); ITerraExplorerObject61 teOjbect = Program.pCreator6.GetObject(objectID as string); m_FeatureSelected = teOjbect as IFeature61; if (m_FeatureSelected == null) { return; } m_ModelName = m_FeatureSelected.FeatureAttributes.GetFeatureAttribute(m_ModelField).Value; string strFile = System.IO.Path.Combine(ConfigurationManager.AppSettings["ModelPath"], m_ModelName); IPoint pSel = m_FeatureSelected.Geometry as IPoint; ITerrainModel61 m_Model = Hook.Creator.CreateModel(Hook.Creator.CreatePosition(pSel.X, pSel.Y), strFile, 1, ModelTypeCode.MT_NORMAL, groupID, "Temp"); m_Model.Visibility.Show = false; if (m_Model == null) { return; } m_AnalysisResult = false; string strPipedFileList = ConfigurationManager.AppSettings["PipedFileList"]; strPipedFileList = strPipedFileList.ToLower(); m_HoleBox = m_Model.Terrain.BBox; Hook.Creator.DeleteObject(m_Model.ID); double[] points = { m_HoleBox.MinX, m_HoleBox.MinY, 0, m_HoleBox.MaxX, m_HoleBox.MinY, 0, m_HoleBox.MaxX, m_HoleBox.MaxY, 0, m_HoleBox.MinX, m_HoleBox.MaxY, 0 }; IPolygon polygonHole = Hook.Creator.GeometryCreator.CreatePolygonGeometry(points); Hook.Creator.CreateHoleOnTerrain(polygonHole as IGeometry, groupID, Pipe_Hole_Name); if (strPipedFileList.Contains(m_ModelName.ToLower())) { m_AnalysisResult = true; } // 隐藏 // m_FeatureSelected.FeatureAttributes.GetFeatureAttribute("MODELNAME").Value = ""; if (modelLayerID > 0) { ILayer61 lyrModel = Hook.ProjectTree.GetLayer(modelLayerID); //lyrModel.Save(); lyrModel.Filter = string.Format("{0} <> '{1}'", m_ModelField, m_ModelName); lyrModel.Refresh(); } } catch (Exception ex) { HasError = true; } finally { if (Analysised != null) { Analysised.Invoke(); } EndPipeAnalysis(); } }
/// <summary> /// 鼠标左键按下时发生的事件(建立缓冲区的主要方法) /// </summary> /// <param name="Flags"></param> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="pbHandled"></param> void TE_OnLButtonDown(int Flags, int X, int Y, ref object pbHandled) { if (En == "DrawGeo") { } else if (En == "SelectModle") { // 2012-9-20 张航宇 // 若成功的完成了一次缓冲分析,则将状态释放,要求重新点击 IWorldPointInfo61 pIWorldPointInfo = this.SgWorld.Window.PixelToWorld(X, Y, WorldPointType.WPT_MODEL); if (pIWorldPointInfo.ObjectID != "" && pIWorldPointInfo.ObjectID != null) { try { ITerraExplorerObject61 pp = this.SgWorld.Creator.GetObject(pIWorldPointInfo.ObjectID); if (pp.ObjectType == ObjectTypeCode.OT_FEATURE) { IFeature61 pIF = pp as IFeature61; this.geo = pIF.GeometryZ.SpatialOperator.buffer((double)this.spinEdit1.Value); ITerrainPolygon61 polygon = this.SgWorld.Creator.CreatePolygon(this.geo, -16711936, -10197916, cbRelative.Checked?AltitudeTypeCode.ATC_TERRAIN_RELATIVE: AltitudeTypeCode.ATC_ON_TERRAIN, GroupID, "Buffer" + System.Guid.NewGuid().ToString().Substring(0, 6)); if (cbRelative.Checked) { polygon.Position.Altitude = (double)speHeight.Value; } this.En = null; this.Select.Checked = false; } else { ITerrainModel61 pITerrainModel = this.SgWorld.Creator.GetObject(pIWorldPointInfo.ObjectID) as ITerrainModel61; IBBox3D61 pBBox = pITerrainModel.Terrain.BBox; cVerticesArray = new double[] { pBBox.MaxX, pBBox.MinY, 0, pBBox.MaxX, pBBox.MaxY, 0, pBBox.MinX, pBBox.MaxY, 0, pBBox.MinX, pBBox.MinY, 0, }; ILinearRing cRing = this.SgWorld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray); IPolygon cPolygonGeometry = this.SgWorld.Creator.GeometryCreator.CreatePolygonGeometry(cRing, null); //this.geo = cPolygonGeometry as IGeometry; ISpatialOperator _SpatialOperator = cPolygonGeometry.SpatialOperator; this.geo = _SpatialOperator.buffer((double)this.spinEdit1.Value); ITerrainPolygon61 polygon = this.SgWorld.Creator.CreatePolygon(this.geo, -16711936, -10197916, cbRelative.Checked ? AltitudeTypeCode.ATC_TERRAIN_RELATIVE : AltitudeTypeCode.ATC_ON_TERRAIN, GroupID, "Buffer" + System.Guid.NewGuid().ToString().Substring(0, 6)); if (cbRelative.Checked) { polygon.Position.Altitude = (double)speHeight.Value; } this.En = null; this.Select.Checked = false; } } catch { } } } }
void m_Hook_OnLButtonDown(int Flags, int X, int Y, ref object pbHandled) { try { object obj1, obj2, obj3; this.m_TerraExplorer.GetMouseInfo(out obj1, out obj2, out obj3); double longitude, latitude, height; this.m_TerraExplorer.ScreenToTerrain(X, Y, out longitude, out latitude, out height); IPosition61 position = m_Hook.Creator.CreatePosition(longitude, latitude, 0,AltitudeTypeCode.ATC_PIVOT_RELATIVE); int tempGroup = this.m_Hook.ProjectTree.FindItem(m_TempGroupName); if (tempGroup > -1) { this.m_Hook.ProjectTree.DeleteItem(tempGroup); } tempGroup = this.m_Hook.ProjectTree.CreateGroup(m_TempGroupName); this.m_Model = this.m_Hook.Creator.CreateModel(position, ConfigurationManager.AppSettings["LampModelFile"], 1, ModelTypeCode.MT_NORMAL, tempGroup, m_TempModelName); if (cbAuto.Checked) { LampAnalysis(); } pbHandled = true; m_Flag = false; } catch { MessageBox.Show("您当前的配置不能完成此操作,请修改配置!"); } finally { this.m_TerraExplorer.OnLButtonDown -= new TerraExplorerX._ITerraExplorerEvents5_OnLButtonDownEventHandler(m_Hook_OnLButtonDown); } }
void TE_OnLButtonDown(int Flags, int X, int Y, ref object pbHandled) { string strModel = ConfigurationManager.AppSettings["FloorPath"]; ITerraExplorerObject61 objModel = Program.pCreator6.GetObject(Program.IInfoTree.GetTerraObjectID(Program.IInfoTree.FindItem(strModel))); ////model.ModelType = ModelTypeCode.MT_ANIMATION; m_ModelFloor = objModel as ITerrainModel61; //Type[] types= model.GetType().GetInterfaces(); m_ModelFloor.Visibility.Show = true; if (m_FrmFloor == null || m_FrmFloor.IsDisposed) { m_FrmFloor = new FrmFloor(); m_FrmFloor.FormClosed += new FormClosedEventHandler(m_FrmFloor_FormClosed); } if (m_FrmFloor.Visible == false) m_FrmFloor.Show(this.m_Hook.UIHook.MainForm); }