Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C#Winfrom to realize the function of drawing straight Line with Skyline

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to use C#Winfrom to achieve the function of drawing straight lines in Skyline. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. The logic of drawing lines:

Let me go back to TerraExplorer Pro and try to draw a line from each step to find out what's going on. 1. The left mouse button selects a point in the 3D window (determines the location of the first point). two。 Move the mouse and click the left mouse button at the second point (determine the location of the second point). 3. Hold down the left mouse button, move the earth in the 3D window, and find that there is no line drawn after loosening. Then the left button clicks on the next point and draws another line. (left-click to select drag and drop without drawing lines) 4. Right-click to cancel the last point, setting the previous point as the last end of the line (delete the last point and set the penultimate point as the end of the line)

It's important to try to draw a line by yourself, and you'll understand more or less of the above words after you finish it.

2. The code for drawing lines

Here are the events that need to be bound, and this code has a small Bug waiting for you to find out for yourself.

Sgworld.OnRButtonUp + = Sgworld_OnRButtonUp;// bind mouse right click lift event sgworld.OnLButtonUp + = Sgworld_OnLButtonUp;// bind mouse left click lift event sgworld.OnLButtonDown + = Sgworld_OnLButtonDown;// bind mouse left click down event sgworld.OnFrame + = Sgworld_OnFrame;// bind real time rendering event

Using System;using System.Windows.Forms;using TerraExplorerX;// refers to Skyline's namespace namespace Skyline drawing line {public partial class Form1: Form {public Form1 () {InitializeComponent ();} / / global variable SGWorld701 sgworld; bool Drawline = false; double centerX = 0; double centerY = 0; ITerrainPolyline701 polyline = null; / / the Name of the draw line button is Drawaline private void Drawaline_Click (object sender, EventArgs e) {Drawline = true } / / form load private void Form1_Load (object sender, EventArgs e) {sgworld = new SGWorld701 (); sgworld.Project.Open ("project path"); sgworld.OnRButtonUp + = Sgworld_OnRButtonUp;// bind mouse right click lift event sgworld.OnLButtonUp + = Sgworld_OnLButtonUp;// bind mouse left click lift event sgworld.OnLButtonDown + = Sgworld_OnLButtonDown;// bind mouse left click down event sgworld.OnFrame + = Sgworld_OnFrame / / bind real-time rendering event} / / left-click the mouse to get the screen center point location private bool Sgworld_OnLButtonDown (int Flags, int X, int Y) {IWorldPointInfo701 centerOfWorld1 = sgworld.Window.CenterPixelToWorld (WorldPointType.WPT_DEFAULT); centerX = centerOfWorld1.Position.X; centerY = centerOfWorld1.Position.Y; return false;} / / Real-time rendering event private void Sgworld_OnFrame () {IMouseInfo701 mouse1= sgworld.Window.GetMouseInfo () IWorldPointInfo701 worldPointInfo = sgworld.Window.PixelToWorld (mouse1.X, mouse1.Y); if (worldPointInfo! = null) {IPosition701 pos = worldPointInfo.Position; if (polylineage null) {polyline.Geometry.StartEdit (); ((ILineString) polyline.Geometry) .Points.DeletePoint (ILineString) polyline.Geometry). Points.Count-1); (ILineString) polyline.Geometry) .Points.AddPoint (worldPointInfo.Position.X, worldPointInfo.Position.Y, worldPointInfo.Position.Altitude); polyline.Geometry.EndEdit () } / / right-click pop-up event private bool Sgworld_OnLButtonUp (int Flags, int X, int Y) {IWorldPointInfo701 centerOfWorld2 = sgworld.Window.CenterPixelToWorld (WorldPointType.WPT_DEFAULT); double centerPointDistance = sgworld.CoordServices.GetDistance (centerOfWorld2.Position.X, centerOfWorld2.Position.Y, centerX, centerY); / / determine if the mouse clicks the underlined button and executes the following if (Drawline = = true) {IWorldPointInfo701 ipWorldInfor = sgworld.Window.PixelToWorld (X, Y) If (polyline = = null) {double dXCoord = ipWorldInfor.Position.X; double dYCoord = ipWorldInfor.Position.Y; double [] array = new double [] {}; array = new double [] {dXCoord, dYCoord, 0, dXCoord, dYCoord, 0,}; ILineString lr = sgworld.Creator.GeometryCreator.CreateLineStringGeometry (array); polyline = sgworld.Creator.CreatePolyline (lr, 0xffffff, AltitudeTypeCode.ATC_TERRAIN_ABSOLUTE, "", ");} else {if (centerPointDistance==0) {ILineString new_lr = polyline.Geometry as ILineString New_lr.StartEdit (); new_lr.Points.AddPoint (ipWorldInfor.Position.X, ipWorldInfor.Position.Y, ipWorldInfor.Position.Altitude); new_lr.EndEdit ();} return false;} / / the right mouse click event ends the line and deletes the last point private bool Sgworld_OnRButtonUp (int Flags, int X, int Y) {if (polyline! = null) {polyline.Geometry.StartEdit () ((ILineString) polyline.Geometry) .Points.DeletePoint (ILineString) polyline.Geometry) .Points.Count-1); polyline.Geometry.EndEdit ();} Drawline = false; polyline = null; return true;}

Due to the lack of time, I originally wanted to analyze and explain it in detail. We can make reference or copy it directly, but the most important thing is to understand. Only by understanding can we learn better. If you have any ideas, you can discuss and study together.

Thank you for reading! On "how to use C#Winfrom to achieve Skyline straight line function" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report