==================
Standard operators
==================

Overview
========

In order for the user to interact with the scene, your application needs to respond to various input events that might be coming from the mouse, the keyboard, or a touch device. While you are free to handle user input yourself and make calls into the Web Viewer API in response to them, |HCNOW| provides the concept of "operators" for this purpose. An operator is a hook into the user input event loop with a predefined structure to respond to user input in a sensible way.

For example, one operator might handle a mouse click which selects geometry. Another might handle keystrokes. |HCNOW| have any number of operators active at the same time.

The Web Viewer offers a set of standard operators for the most common user interactions such as camera manipulation, selection, and inserting markup, but you can also write your own operators with completely custom functionality. 


Built-in operators
==================

The Web Viewer supports several predefined, standard operators in various categories. All those operators are available with fully readable source-code. We encourage you to browse through the source code to understand the design patterns when writing operator code.

The :doc:`OperatorManager </api_ref/viewing/classes/Communicator.OperatorManager>` maintains a stack of operators that are all active at the same time and receive events based on their position in the stack with the operator pushed on the stack last getting to "see" the events first. When starting the Web Viewer this is what the operator stack looks like:

#. Navigate
#. Select
#. CuttingPlane
#. Handles
#. NavCube
#. AxisTriad


Activating a predefined operator
================================

The :doc:`Communicator.OperatorId </api_ref/viewing/enum/Communicator.OperatorId>` enum stores a list of all predefined operator IDs. To activate one of them, simply use one of the operator IDs with the push or set functions of the :doc:`OperatorManager </api_ref/viewing/classes/Communicator.OperatorManager>`:

.. literalinclude:: /../../applications/client/docs/PG_Viewing_Operators.ts
   :start-after: //! [webviewer_setoperator2]
   :end-before: //! [webviewer_setoperator2]

As with the custom operators, you need to be mindful of how an activated operator interacts with other operators already on the stack. For example, if you want to use one of the walk operators you should not just push it to the top of the stack but instead, replace the existing camera-related operator (Navigate in the default configuration) with it. If in doubt it is best to experiment to see how the predefined operators interact with each other and define your operator stack accordingly. 


Operator categories
===================

The built-in operators fall into a few major categories:


Camera
......

* :doc:`Navigate </api_ref/viewing/classes/Communicator.Operator.CameraNavigationOperator>`
* :doc:`Orbit </api_ref/viewing/classes/Communicator.Operator.CameraOrbitOperator>`
* :doc:`Pan </api_ref/viewing/classes/Communicator.Operator.CameraPanOperator>`
* :doc:`Zoom </api_ref/viewing/classes/Communicator.Operator.CameraZoomOperator>`
* :doc:`Turntable </api_ref/viewing/classes/Communicator.Operator.CameraTurntableOperator>`
* :doc:`WalkMode </api_ref/viewing/classes/Communicator.Operator.CameraWalkModeOperator>`
* :doc:`Walk </api_ref/viewing/classes/Communicator.Operator.CameraWalkOperator>`
* :doc:`KeyboardWalk </api_ref/viewing/classes/Communicator.Operator.CameraKeyboardWalkOperator>`


Selection
.........

* :doc:`Select </api_ref/viewing/classes/Communicator.Operator.SelectionOperator>`
* :doc:`AreaSelect </api_ref/viewing/classes/Communicator.Operator.AreaSelectionOperator>`
* :doc:`RayDrillSelect </api_ref/viewing/classes/Communicator.Operator.RayDrillSelectionOperator>`


Markup
......

* :doc:`Note </api_ref/viewing/classes/Communicator.Operator.NoteOperator>`
* :doc:`RedlineCircle </api_ref/viewing/classes/Communicator.Operator.RedlineCircleOperator>`
* :doc:`RedlinePolyline </api_ref/viewing/classes/Communicator.Operator.RedlinePolylineOperator>`
* :doc:`RedlineRectangle </api_ref/viewing/classes/Communicator.Operator.RedlineRectangleOperator>`
* :doc:`RedlineText </api_ref/viewing/classes/Communicator.Operator.RedlineTextOperator>`


Measurement
...........

* :doc:`MeasureEdgeLength </api_ref/viewing/classes/Communicator.Operator.MeasureEdgeLengthOperator>`
* :doc:`MeasureFaceFaceAngle </api_ref/viewing/classes/Communicator.Operator.MeasureFaceFaceAngleOperator>`
* :doc:`MeasureLineLineAngle </api_ref/viewing/classes/Communicator.Operator.MeasureLineLineAngleOperator>`
* :doc:`MeasureFaceFaceDistance </api_ref/viewing/classes/Communicator.Operator.MeasureFaceFaceDistanceOperator>`
* :doc:`MeasureBodyBodyDistance </api_ref/viewing/classes/Communicator.Operator.MeasureBodyBodyDistanceOperator>`
* :doc:`MeasurePointPointDistance </api_ref/viewing/classes/Communicator.Operator.MeasurePointPointDistanceOperator>`
* :doc:`MeasurePolylineDistanceOperator </api_ref/viewing/classes/Communicator.Operator.MeasurePolylineDistanceOperator>`


Misc.
.....

* :doc:`AxisTriad </api_ref/viewing/classes/Communicator.Operator.AxisTriadOperator>`
* :doc:`Handle </api_ref/viewing/classes/Communicator.Operator.HandleOperator>`
* :doc:`NavCube </api_ref/viewing/classes/Communicator.Operator.NavCubeOperator>`

Please see the :doc:`reference manual </api_ref/viewing/modules/Communicator.Operator>` for more information on each operator category. Some of them will also be discussed throughout this Programming Guide.
