Sample Code: Custom Operator show marker on selected line

Language: C#

Sample code of custom selection operator, this operator selects a line and shows markers on a selected line during the mouse is moving.

namespace wpf_sandbox
{
   class MyOperator : Operator
   {
       private MainWindow Window { get; set; }

   	private SegmentKey pointsegment;

   	public MyOperator(MainWindow window) : base(MouseButtons.ButtonLeft(), new ModifierKeys())
       {
           Window = window;
       }

       public override string GetName()
       {
           return "WPF_MyOperator";
       }

       public override void OnViewAttached(View in_attached_view)
       {
   		pointsegment = in_attached_view.GetSegmentKey().Subsegment("selectedpnt");
   		pointsegment.GetMaterialMappingControl().SetMarkerColor(new RGBAColor(0, 0, 1));
   		pointsegment.GetMarkerAttributeControl().SetSize(2);
   		pointsegment.GetVisibilityControl().SetMarkers(true);
       }

       public override bool OnMouseMove(MouseState in_state)
       {
   
   		WindowKey window = in_state.GetEventSource();

   		SelectionOptionsKit selection_options = new SelectionOptionsKit();
   		SelectionResults selection_results;

   		selection_options
   				.SetLevel(Selection.Level.Subentity)
   				.SetAlgorithm(Selection.Algorithm.Visual)
   				.SetSelectability(new SelectabilityKit().SetLines(true).SetEdges(true))
   				.SetProximity(0.2f).SetRelatedLimit(0);

   		ulong count = in_state.GetEventSource().GetSelectionControl().SelectByPoint(in_state.GetLocation(), selection_options, out selection_results);

   		pointsegment.Flush(Search.Type.Marker);


   		if (count > 0)
   		{
   			SelectionResultsIterator itr = selection_results.GetIterator();

   			while (itr.IsValid())
   			{
   				SelectionItem selectionItem = itr.GetItem();
   				Key key;
   				selectionItem.ShowSelectedItem(out key);

   				HPS.Type ktype = key.Type();

   				if (ktype == HPS.Type.LineKey)
   				{
   					WorldPoint point;
   					selectionItem.ShowSelectionPosition(out point);

   					LineKey linekey = (LineKey)key;
   					Point[] pnts;
   					linekey.ShowPoints(out pnts);

   					foreach (Point pnt in pnts)
   					{
   						pointsegment.InsertMarker(pnt);
   					}


   					pointsegment.InsertMarker(point);
   					GetAttachedView().Update();
   				}

   				itr.Next();
   			}
   		}
   		else
   		{
   			pointsegment.Flush(Search.Type.Marker);
   			GetAttachedView().Update();
   		}
   		GetAttachedView().Update();
   		return true;
       }
   }
}