Imports Nevron.Chart Imports Nevron.GraphicsCore Imports Nevron.Chart.WinForm Imports System.Math Public Class frmNevronProblem #Region "Set how form loads and set up Nevron Chart" Private Sub frmNevronProblem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim FileName As String cboInteractivity.SelectedIndex = 0 BuildingCount = 0 Dim XMin, Xmax, YMin, YMax As Double XMin = 272000 Xmax = 417000 YMin = 679000 YMax = 863000 NChartControl1.Clear() m_chart = CType(NChartControl1.Charts(0), NCartesianChart) m_chart.Enable3D = True NChartControl1.Controller.Tools.Add(New NSelectorTool) NChartControl1.Controller.Tools.Add(New NDataCursorTool) m_chart.Projection.SetPredefinedProjection(PredefinedProjection.OrthogonalTop) m_chart.Wall(ChartWallType.Back).Width = 0 m_chart.Wall(ChartWallType.Left).Width = 0 m_chart.Wall(ChartWallType.Floor).Width = 0 m_chart.LightModel.EnableLighting = False ' setup axes Dim linearScale As NLinearScaleConfigurator = New NLinearScaleConfigurator m_chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale m_chart.Axis(StandardAxis.PrimaryX).View = New NRangeAxisView(New NRange1DD(XMin, Xmax)) 'linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, True) linearScale.RoundToTickMax = False linearScale.RoundToTickMin = False linearScale = New NLinearScaleConfigurator m_chart.Axis(StandardAxis.Depth).ScaleConfigurator = linearScale m_chart.Axis(StandardAxis.Depth).View = New NRangeAxisView(New NRange1DD(YMin, YMax)) 'linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, True) linearScale.RoundToTickMax = False linearScale.RoundToTickMin = False ' add the point BuildingPoint = DirectCast(m_chart.Series.Add(SeriesType.Point), NPointSeries) ' subscribe for mouse down AddHandler NChartControl1.MouseDown, AddressOf ImageClickedNevron AddHandler NChartControl1.MouseMove, AddressOf OnChartMouseMoveNevron Dim legendsCollection As NLegendCollection = NChartControl1.Legends Dim legend As NLegend = legendsCollection(0) legend.Location = New NPointL(New NLength(50, NRelativeUnit.ParentPercentage), New NLength(5)) legend.Data.ExpandMode = LegendExpandMode.RowsFixed legend.Data.RowCount = 1 legend.Visible = False Dim x1, y1 As Single x1 = 0.1 y1 = 0.1 m_chart.Location = New NPointL(New NLength(x1), New NLength(y1)) m_chart.Size = New NSizeL(New NLength(99, NRelativeUnit.ParentPercentage), New NLength(99, NRelativeUnit.ParentPercentage)) m_chart.Width = 90.0F m_chart.Depth = 90.0F m_chart.Height = 0.01F ' add horizontal axis cursor HorzAxisCursor = New NAxisCursor HorzAxisCursor.BeginEndAxis = CType(StandardAxis.Depth, Integer) HorzAxisCursor.SynchronizeOnMouseAction = MouseAction.Move m_chart.Axis(StandardAxis.PrimaryX).Cursors.Add(HorzAxisCursor) 'AddHandler HorzAxisCursor.ValueChanged, AddressOf OnValueChanged ' add vertical axis cursor VertAxisCursor = New NAxisCursor VertAxisCursor.BeginEndAxis = CType(StandardAxis.PrimaryX, Integer) VertAxisCursor.SynchronizeOnMouseAction = MouseAction.Move m_chart.Axis(StandardAxis.Depth).Cursors.Add(VertAxisCursor) 'AddHandler VertAxisCursor.ValueChanged, AddressOf OnValueChanged NChartControl1.Settings.RenderSurface = RenderSurface.Bitmap NChartControl1.Settings.EnableJittering = True 'AddHandler m_chart.AfterPaint, AddressOf chart_AfterPaint 'AddHandler NChartControl1.KeyDown, AddressOf nChartControl1_KeyDown 'AddHandler NChartControl1.KeyUp, AddressOf nChartControl1_KeyUp 'AddHandler NChartControl1.MouseDown, AddressOf nChartControl1_MouseDown 'Not sure how this works once we have loaded in the correct dimensions? 'Probably also sorted by always fixing the range of the X and Y axis m_chart.UsePlotAspect = True FileName = "Pipeline View" Dim SetupFile As String = Application.ExecutablePath SetupFile = System.IO.Directory.GetCurrentDirectory FileName = SetupFile & "\" & FileName & ".png" NChartControl1.ImageExporter.SaveToFile(FileName, New NSize(1100, 1000), NResolution.ScreenResolution, New NPngImageFormat) NChartControl1.Refresh() GC.Collect() Catch ex As Exception MessageBox.Show("Error in creating the chart: " & ex.Message, "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub #End Region #Region "Mouse Events" Public Sub OnChartMouseMoveNevron(ByVal sender As Object, ByVal e As MouseEventArgs) Try ProcessMouseEvent("MouseMove", sender, e) Catch MessageBox.Show("Error when mouse move event is used.", "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Protected Sub ProcessMouseEvent(ByVal mouseEvent As String, ByVal sender As Object, ByVal e As MouseEventArgs) Try FillParamsListNevron(NChartControl1.HitTest(e.X, e.Y), e) Catch ex As Exception MessageBox.Show("Error trying to process mouse event: " & ex.Message, "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Public Sub FillParamsListNevron(ByVal hitTestResult As NHitTestResult, ByVal e As MouseEventArgs) Try Dim nChartElement As Integer = CInt(Fix(hitTestResult.ChartElement)) Dim sInfo As String = "" Dim DataPointValue As Integer Dim DataPointName As String DataPointName = "" SelectedPoint = -99 txtMouseLocation.Text = DataPointName txtDataPointValue.Text = CStr(SelectedPoint) Dim horzAxis As NAxis = m_chart.Axis(StandardAxis.PrimaryX) Dim vertAxis As NAxis = m_chart.Axis(StandardAxis.PrimaryY) Dim depthAxis As NAxis = m_chart.Axis(StandardAxis.Depth) Dim vecModelPoint As New NVector3DF vecModelPoint.X = m_chart.Axis(StandardAxis.PrimaryX).TransformScaleToModel(False, 0) vecModelPoint.Y = m_chart.Axis(StandardAxis.PrimaryY).TransformScaleToModel(False, 0) vecModelPoint.Z = m_chart.Axis(StandardAxis.Depth).TransformScaleToModel(False, 0) Dim ptViewPoint As New Point(e.X, e.Y) Dim fDepthValue As Single = 0.0F Dim fX, fY, fZ As Double fX = horzAxis.TransformModelToScale(vecModelPoint.X, True) fY = vertAxis.TransformModelToScale(vecModelPoint.Y, True) fZ = depthAxis.TransformModelToScale(vecModelPoint.Z, True) TextBox4.Text = hitTestResult.ChartElement.ToString Select Case hitTestResult.ChartElement Case ChartElement.DataPoint If (m_chart.TransformClientToModel(NChartControl1.View.Context, horzAxis, depthAxis, vertAxis, fDepthValue, ptViewPoint, vecModelPoint)) Then fX = horzAxis.TransformModelToScale(vecModelPoint.X, True) fY = vertAxis.TransformModelToScale(vecModelPoint.Y, True) fZ = depthAxis.TransformModelToScale(vecModelPoint.Z, True) TextBox1.Text = CStr(fX) TextBox2.Text = CStr(fY) TextBox3.Text = CStr(fZ) End If sInfo = "Data point [" & hitTestResult.DataPointIndex.ToString() & "] from series [" & (CType(hitTestResult.Object.ParentNode, NSeriesBase)).Name & "]" HitTestPoint = hitTestResult.DataPointIndex If hitTestResult.Series.Name = "Pipeline Route 1" Then HitTestRoute = 0 ElseIf hitTestResult.Series.Name = "Pipeline Route 2" Then HitTestRoute = 1 ElseIf hitTestResult.Series.Name = "Pipeline Route 3" Then HitTestRoute = 2 Else HitTestRoute = 0 End If txtMouseLocation.Text = sInfo SelectedPoint = hitTestResult.DataPointIndex Dim Name As String Name = hitTestResult.Series.Name If Name = "Pipeline Route 1" Or Name = "Pipeline Route 2" Or Name = "Pipeline Route 3" Then DataPointName = Name DataPointValue = SelectedPoint ElseIf Name = "Infrastructure" Then DataPointName = Name DataPointValue = SelectedPoint ElseIf Name = "Borehole" Then DataPointName = Name DataPointValue = SelectedPoint ElseIf Name.Split(CChar(" "))(0) = "Crossing" Then DataPointName = Name.Split(CChar(" "))(0) SelectedPoint = CInt(Name.Split(CChar(" "))(1)) DataPointValue = SelectedPoint Else DataPointName = "Nothing Selected" DataPointValue = -99 End If txtMouseLocation.Text = DataPointName txtDataPointValue.Text = CStr(SelectedPoint) Case Else If (m_chart.TransformClientToModel(NChartControl1.View.Context, horzAxis, depthAxis, vertAxis, fDepthValue, ptViewPoint, vecModelPoint)) Then fX = horzAxis.TransformModelToScale(vecModelPoint.X, True) fY = vertAxis.TransformModelToScale(vecModelPoint.Y, True) fZ = depthAxis.TransformModelToScale(vecModelPoint.Z, True) TextBox1.Text = CStr(fX) TextBox2.Text = CStr(fY) TextBox3.Text = CStr(fZ) End If DataPointName = "Nothing Selected" SelectedPoint = -99 HitTestPoint = -99 HitTestRoute = -99 txtMouseLocation.Text = DataPointName txtDataPointValue.Text = CStr(SelectedPoint) End Select txtMouseLocation.Text = DataPointName If SelectedPoint = -99 Then txtDataPointValue.Text = "" Else txtDataPointValue.Text = CStr(SelectedPoint) End If Catch MessageBox.Show("Error showing what section of chart we are over.", "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub #End Region #Region "NEVRON: Image Clicked Subroutine" Public Sub ImageClickedNevron(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown Try If e.X = OldpointEx And e.Y = OldPointEy Then Exit Sub ' This avoids the double hit scenario End If OldpointEx = e.X OldPointEy = e.Y Dim chart As NCartesianChart = CType(NChartControl1.Charts(0), NCartesianChart) Dim hitTestResult As NHitTestResult = NChartControl1.HitTest(e.X, e.Y) Dim ptViewPoint As New Point(e.X, e.Y) Dim fDepthValue As Single = 0.0F ' XY plane Dim horzAxis As NAxis = m_chart.Axis(StandardAxis.PrimaryX) Dim vertAxis As NAxis = m_chart.Axis(StandardAxis.PrimaryY) Dim depthAxis As NAxis = m_chart.Axis(StandardAxis.Depth) Dim vecModelPoint As New NVector3DF vecModelPoint.X = m_chart.Axis(StandardAxis.PrimaryX).TransformScaleToModel(False, 0) vecModelPoint.Y = m_chart.Axis(StandardAxis.PrimaryY).TransformScaleToModel(False, 0) vecModelPoint.Z = m_chart.Axis(StandardAxis.Depth).TransformScaleToModel(False, 0) Dim fX, fY, fZ As Double If cboInteractivity.Text <> "Select Area" Then If hitTestResult.ChartElement = ChartElement.ChartWall Or hitTestResult.ChartElement = ChartElement.Axis _ Or hitTestResult.ChartElement = ChartElement.DataPoint _ Or hitTestResult.ChartElement = ChartElement.SurfaceDataPoint Then If (m_chart.TransformClientToModel(NChartControl1.View.Context, horzAxis, depthAxis, vertAxis, fDepthValue, ptViewPoint, vecModelPoint)) Then vecModelPoint.Y = 0.0 fX = horzAxis.TransformModelToScale(vecModelPoint.X, True) fY = vertAxis.TransformModelToScale(vecModelPoint.Y, True) fZ = depthAxis.TransformModelToScale(vecModelPoint.Z, True) If fX = OldPointFx And fY = OldPointFy And fZ = OldPointFz Then Exit Sub ' This avoids the double hit scenario End If OldPointFx = fX OldPointFy = fY OldPointFz = fZ fY = fZ AddBuildingPointsNevron(fX, fY) BuildingCount = BuildingCount + 1 End If Else fX = -999 fY = -999 fZ = -999 End If End If Catch MessageBox.Show("Error when clicking on chart.", "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub #End Region #Region "Add Building Points to the Chart" Public Sub AddBuildingPointsNevron(ByVal X As Double, ByVal Y As Double) Try XBuildingArrayNevron(BuildingCount) = X YBuildingArrayNevron(BuildingCount) = Y BuildingPoint.ClearDataPoints() BuildingPoint.Name = "Infrastructure" BuildingPoint.BorderStyle.Width = New NLength(0.0, NGraphicsUnit.Pixel) BuildingPoint.DataLabelStyle.Visible = False If ModifiedInfrastructureStyle = False Then BuildingPoint.Size = New NLength(0.25F, NRelativeUnit.ParentPercentage) End If BuildingPoint.FillStyle = New NColorFillStyle(Color.Red) 'As with Borehole, couldn't get these to be transparent 'Dim BuildingImage As String 'BuildingImage = "House1.png" 'Dim SetupFile As String = Application.StartupPath 'BuildingImage = SetupFile & "\" & BuildingImage 'HouseFillStyle = New NImageFillStyle(BuildingImage) 'BuildingPoint.FillStyle = HouseFillStyle BuildingPoint.FillStyle.SetTransparencyPercent(50) Dim i As Integer For i = 0 To XBuildingArrayNevron.GetUpperBound(0) BuildingPoint.Values.Add(0.0) BuildingPoint.XValues.Add(XBuildingArrayNevron(i)) BuildingPoint.ZValues.Add(YBuildingArrayNevron(i)) BuildingPoint.UseXValues = True BuildingPoint.UseZValues = True Next NChartControl1.Refresh() Catch MessageBox.Show("Error when Adding Infrastructure Points to Chart", "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub #End Region #Region "ZOOM using Buttons" Private Sub btnZoomIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoomIn.Click Try Dim CurrentZoom As Single CurrentZoom = m_chart.Projection.Zoom m_chart.Projection.Zoom = CurrentZoom + ZoomStep Dim x1, y1 As Single x1 = m_chart.Size.Height.Value y1 = m_chart.Size.Width.Value x1 = x1 * (CurrentZoom + ZoomStep) / 100 y1 = y1 * (CurrentZoom + ZoomStep) / 100 'm_chart.Size = New NSizeL(New NLength(x1, NRelativeUnit.ParentPercentage), New NLength(y1, NRelativeUnit.ParentPercentage)) NChartControl1.Refresh() Catch MessageBox.Show("Error using ZOOM buttons.", "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btnZoomOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoomOut.Click Dim CurrentZoom As Single CurrentZoom = m_chart.Projection.Zoom m_chart.Projection.Zoom = Max(0, CurrentZoom - ZoomStep) NChartControl1.Refresh() End Sub #End Region #Region "OFFSET using Buttons" Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeft.Click Try Dim CurrentX As Integer Dim CurrentY As Integer CurrentX = CInt(m_chart.Location.X.Value) CurrentY = CInt(m_chart.Location.Y.Value) m_chart.Location = New NPointL(New NLength(CurrentX - NudgeStep, NRelativeUnit.ParentPercentage), New NLength(CurrentY, NRelativeUnit.ParentPercentage)) NChartControl1.Refresh() Catch MessageBox.Show("Error using Left Offset button.", "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRight.Click Try Dim CurrentX As Integer Dim CurrentY As Integer CurrentX = CInt(m_chart.Location.X.Value) CurrentY = CInt(m_chart.Location.Y.Value) m_chart.Location = New NPointL(New NLength(CurrentX + NudgeStep, NRelativeUnit.ParentPercentage), New NLength(CurrentY, NRelativeUnit.ParentPercentage)) NChartControl1.Refresh() Catch MessageBox.Show("Error using Right Offset button.", "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click Try Dim CurrentX As Integer Dim CurrentY As Integer CurrentX = CInt(m_chart.Location.X.Value) CurrentY = CInt(m_chart.Location.Y.Value) m_chart.Location = New NPointL(New NLength(CurrentX, NRelativeUnit.ParentPercentage), New NLength(CurrentY - NudgeStep, NRelativeUnit.ParentPercentage)) NChartControl1.Refresh() Catch MessageBox.Show("Error using Up Offset button.", "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click Try Dim CurrentX As Integer Dim CurrentY As Integer CurrentX = CInt(m_chart.Location.X.Value) CurrentY = CInt(m_chart.Location.Y.Value) m_chart.Location = New NPointL(New NLength(CurrentX, NRelativeUnit.ParentPercentage), New NLength(CurrentY + NudgeStep, NRelativeUnit.ParentPercentage)) NChartControl1.Refresh() Catch MessageBox.Show("Error using Down Offset button.", "Input Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub #End Region End Class