editor/AdvancedMappingTools/Placement/PowerLineEditor.cs

An editor placement tool in the Advanced Mapping Tools package. Extends PathEditor to draw power line paths, then uses PowerLineGenerator with PowerLineSettings to build a preview mesh and place poles at the spacing and on every corner with wires hung between them. Pole and wire materials are picked from the primitive tool's surface and trim materials.

namespace AdvancedMappingTools;

/// <summary>
/// Draws a power line. Poles stand at the spacing and on every corner, the crossarm carries
/// the wires, and the wires hang between the poles.
/// </summary>
[ToolCategory( "Street" )]
[Title( "Power Line" ), Icon( "power" )]
public sealed class PowerLineEditor : PathEditor
{
	readonly PowerLineGenerator _generator = new();

	public PowerLineEditor( PrimitiveTool tool ) : base( tool ) { }

	public PowerLineSettings Settings { get; } = new();

	public override object ExtraSettings => Settings;

	protected override int MinPoints => 2;

	protected override bool PlacesObjects => true;

	protected override bool AllowsHeight => true;

	protected override bool SnapsToLines => true;

	protected override bool Connects => true;

	protected override bool UsesBends => false;

	protected override IEnumerable<string> Hints =>
	[
		"Click: place a point",
		"Every corner gets a pole",
		"Enter: create, Esc: stop"
	];

	protected override void BuildMesh( MeshKit kit ) { }

	void Prepare()
	{
		Settings.Path = Curve();
		Settings.PoleMaterial = PartTool.Pick( Settings.PoleMaterial, SurfaceMaterial );
		Settings.WireMaterial = PartTool.Pick( Settings.WireMaterial, TrimMaterial );
	}

	protected override PolygonMesh BuildPreview()
	{
		Prepare();

		return PartService.Plan( _generator, Settings ).Flatten( new Transform( Vector3.Zero, Rotation.Identity ) );
	}

	protected override void PlaceObjects()
	{
		Prepare();
		PartTool.Place( _generator, Settings, new Transform( Vector3.Zero, Rotation.Identity ) );
	}
}