CorePlotting::Interaction::PolygonInteractionController
CorePlotting::Interaction::PolygonInteractionController
Controller for interactive polygon creation and modification. More…
#include <PolygonInteractionController.hpp>
Inherits from CorePlotting::Interaction::IGlyphInteractionController
Public Functions
| Name | |
|---|---|
| PolygonInteractionController() =default Construct with default configuration. |
|
| PolygonInteractionController(PolygonInteractionConfig config) Construct with custom configuration. |
|
| void | setConfig(PolygonInteractionConfig config) Set configuration. |
| PolygonInteractionConfig const & | getConfig() const Get current configuration. |
| AddVertexResult | addVertex(float canvas_x, float canvas_y) Add a vertex to the polygon being constructed. |
| void | updateCursorPosition(float canvas_x, float canvas_y) Update the cursor position for preview rendering. |
| bool | canComplete() const Check if the polygon can be completed (has enough vertices). |
| std::size_t | getVertexCount() const Get the number of vertices in the current polygon. |
| std::vector< glm::vec2 > const & | getVertices() const Get all vertices in the current polygon. |
| glm::vec2 | getCursorPosition() const Get the current cursor position (for preview line). |
| bool | removeLastVertex() Remove the last added vertex (undo). |
| void | startVertexDrag(float canvas_x, float canvas_y, std::string series_key, EntityId entity_id, std::size_t vertex_index, std::vector< glm::vec2 > original_vertices) Start vertex drag mode for modifying an existing polygon. |
| PolygonVertexHandle | getDraggedVertex() const Get the vertex handle being dragged (if in vertex drag mode). |
| bool | isVertexDrag() const Check if this is a vertex drag (modification) vs creation. |
| std::optional< std::vector< glm::vec2 > > const & | getOriginalVertices() const Get original polygon vertices (for modification mode). |
| virtual void | start(float canvas_x, float canvas_y, std::string series_key, std::optional< EntityId > existing_entity_id =std::nullopt) override Begin polygon creation at the given position. |
| virtual void | update(float canvas_x, float canvas_y) override Update during drag (for vertex modification mode). |
| virtual void | complete() override Complete the interaction successfully. |
| virtual void | cancel() override Cancel the interaction without applying changes. |
| virtual bool | isActive() const override Check if an interaction is currently in progress. |
| virtual GlyphPreview | getPreview() const override Get the current preview geometry. |
| virtual std::string const & | getSeriesKey() const override Get the target series key. |
| virtual std::optional< EntityId > | getEntityId() const override Get the EntityId if modifying an existing element. |
Additional inherited members
Public Functions inherited from CorePlotting::Interaction::IGlyphInteractionController
| Name | |
|---|---|
| virtual | ~IGlyphInteractionController() =default |
| bool | isModification() const Check if this interaction is modifying an existing element. |
Detailed Description
class CorePlotting::Interaction::PolygonInteractionController;Controller for interactive polygon creation and modification.
See:
- IGlyphInteractionController for the interface contract
- PolygonSelectionHandler for the original Qt-based implementation
Unlike LineInteractionController and RectangleInteractionController which use drag-based interactions, PolygonInteractionController uses a click-based approach where each click adds a new vertex to the polygon.
Creation Mode (via [start()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-start) + repeated [addVertex()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-addvertex) calls):
- Call
[start()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-start)to begin polygon creation (adds first vertex) - Call
[addVertex()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-addvertex)for each additional vertex - Call
[complete()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-complete)to finalize the polygon (requires min_vertices) - Alternatively, click near the first vertex to auto-close (if enabled)
Modification Mode (via [startVertexDrag()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-startvertexdrag)):
- Used when user clicks on a vertex of an existing polygon
- Only the specified vertex moves during drag
- Shows ghost of original polygon
Preview Updates:
- Call
[updateCursorPosition()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-updatecursorposition)during mouse move to show a preview line from the last vertex to the current cursor position
Public Functions Documentation
function PolygonInteractionController
PolygonInteractionController() =defaultConstruct with default configuration.
function PolygonInteractionController
inline explicit PolygonInteractionController(
PolygonInteractionConfig config
)Construct with custom configuration.
function setConfig
inline void setConfig(
PolygonInteractionConfig config
)Set configuration.
function getConfig
inline PolygonInteractionConfig const & getConfig() constGet current configuration.
function addVertex
AddVertexResult addVertex(
float canvas_x,
float canvas_y
)Add a vertex to the polygon being constructed.
Parameters:
- canvas_x X coordinate in canvas pixels
- canvas_y Y coordinate in canvas pixels
Return: Result indicating what action was taken
This is the primary method for building the polygon during creation mode. Call this on each mouse click after start() has been called.
function updateCursorPosition
void updateCursorPosition(
float canvas_x,
float canvas_y
)Update the cursor position for preview rendering.
Parameters:
- canvas_x Current X coordinate in canvas pixels
- canvas_y Current Y coordinate in canvas pixels
Call this during mouse move to show a preview line from the last vertex to the current cursor position. This does NOT add a vertex.
function canComplete
bool canComplete() constCheck if the polygon can be completed (has enough vertices).
Return: True if vertex count >= min_vertices
function getVertexCount
inline std::size_t getVertexCount() constGet the number of vertices in the current polygon.
function getVertices
inline std::vector< glm::vec2 > const & getVertices() constGet all vertices in the current polygon.
function getCursorPosition
inline glm::vec2 getCursorPosition() constGet the current cursor position (for preview line).
function removeLastVertex
bool removeLastVertex()Remove the last added vertex (undo).
Return: True if a vertex was removed, false if polygon has only one vertex
function startVertexDrag
void startVertexDrag(
float canvas_x,
float canvas_y,
std::string series_key,
EntityId entity_id,
std::size_t vertex_index,
std::vector< glm::vec2 > original_vertices
)Start vertex drag mode for modifying an existing polygon.
Parameters:
- canvas_x Starting X coordinate in canvas pixels
- canvas_y Starting Y coordinate in canvas pixels
- series_key Identifier of the series containing the polygon
- entity_id EntityId of the polygon being modified
- vertex_index Index of the vertex being dragged
- original_vertices Original polygon vertices in canvas coords
function getDraggedVertex
inline PolygonVertexHandle getDraggedVertex() constGet the vertex handle being dragged (if in vertex drag mode).
function isVertexDrag
inline bool isVertexDrag() constCheck if this is a vertex drag (modification) vs creation.
function getOriginalVertices
inline std::optional< std::vector< glm::vec2 > > const & getOriginalVertices() constGet original polygon vertices (for modification mode).
function start
virtual void start(
float canvas_x,
float canvas_y,
std::string series_key,
std::optional< EntityId > existing_entity_id =std::nullopt
) overrideBegin polygon creation at the given position.
Reimplements: CorePlotting::Interaction::IGlyphInteractionController::start
This adds the first vertex of the polygon. Continue adding vertices with addVertex() calls.
function update
virtual void update(
float canvas_x,
float canvas_y
) overrideUpdate during drag (for vertex modification mode).
Reimplements: CorePlotting::Interaction::IGlyphInteractionController::update
In creation mode, use updateCursorPosition() instead for preview updates, and addVertex() to add points.
function complete
virtual void complete() overrideComplete the interaction successfully.
Reimplements: CorePlotting::Interaction::IGlyphInteractionController::complete
Called when the user finishes the interaction (typically on mouse release). After this call, [isActive()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-isactive) returns false and [getPreview()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-getpreview) contains the final geometry for conversion to data coordinates.
function cancel
virtual void cancel() overrideCancel the interaction without applying changes.
Reimplements: CorePlotting::Interaction::IGlyphInteractionController::cancel
Called when the interaction should be aborted (e.g., Escape key pressed). After this call, [isActive()](/api_generated/Classes/classCorePlotting_1_1Interaction_1_1PolygonInteractionController.md#function-isactive) returns false.
function isActive
inline virtual bool isActive() const overrideCheck if an interaction is currently in progress.
Return: true if between start() and complete()/cancel()
Reimplements: CorePlotting::Interaction::IGlyphInteractionController::isActive
function getPreview
virtual GlyphPreview getPreview() const overrideGet the current preview geometry.
Return: Current preview geometry (valid even after complete())
Reimplements: CorePlotting::Interaction::IGlyphInteractionController::getPreview
Returns the preview in canvas coordinates, suitable for rendering via PreviewRenderer. The preview type matches the controller type (e.g., RectangleInteractionController produces Rectangle previews).
function getSeriesKey
inline virtual std::string const & getSeriesKey() const overrideGet the target series key.
Return: Series key passed to start(), empty string if not active
Reimplements: CorePlotting::Interaction::IGlyphInteractionController::getSeriesKey
function getEntityId
inline virtual std::optional< EntityId > getEntityId() const overrideGet the EntityId if modifying an existing element.
Return: EntityId if modifying, std::nullopt if creating new
Reimplements: CorePlotting::Interaction::IGlyphInteractionController::getEntityId
Updated on 2026-11-13 at 20:25:42 +0000