#ifndef ULIB_VTK_VIEWPORT_H #define ULIB_VTK_VIEWPORT_H #include "uLibVtkInterface.h" #include #include #include "Core/FontConfig.h" #include "Math/Dense.h" namespace uLib { class Object; } // VTK classes are in the global namespace class vtkRenderer; class vtkCornerAnnotation; class vtkOrientationMarkerWidget; class vtkCameraOrientationWidget; class vtkPlaneSource; class vtkActor; class vtkAxes; class vtkNamedColors; class vtkCellPicker; class vtkCallbackCommand; class vtkProp; class vtk3DWidget; class vtkRenderWindow; class vtkRenderWindowInteractor; class vtkCamera; namespace uLib { namespace Vtk { struct ViewportData; class HandlerWidget; class MultiSelectionProp; class ObjectsContext; /** * @class Viewport * @brief Base class for VTK viewports, providing core rendering and prop management. */ class Viewport { public: Viewport(); virtual ~Viewport(); // Render scene virtual void Render() = 0; void Reset(); void ZoomAuto(); void ZoomSelected(); // Prop3D / prop management void AddProp3D(Prop3D &prop); void RemoveProp3D(Prop3D &prop); /** @brief Selects a specific Prop3D. If multi is true, it toggles selection in a group. */ void SelectProp3D(Prop3D* target, bool multi = false); /** @brief Creates a persistent Selection Group from the current multi-selection. */ void GroupSelection(uLib::ObjectsContext* targetCtx); void addProp(vtkProp *prop); void RemoveProp(vtkProp *prop); // Widget integration void AddWidget(vtk3DWidget *widget); // Direct access to VTK internals vtkRenderer* GetRenderer(); virtual vtkRenderWindow* GetRenderWindow() = 0; virtual vtkRenderWindowInteractor* GetInteractor() = 0; vtkCornerAnnotation* GetAnnotation(); vtkCameraOrientationWidget* GetCameraWidget(); void DisableHandler(); virtual void OnSelectionChanged(Prop3D* p) {} const std::vector& getProp3Ds() const { return m_Prop3Ds; } // Grid control void SetGridVisible(bool visible); bool GetGridVisible() const; enum Axis { X=0, Y, Z }; void SetGridAxis(Axis axis); Axis GetGridAxis() const { return m_GridAxis; } // Projection control void SetParallelProjection(bool parallel); bool GetParallelProjection() const; // Font configuration void SetFont(const FontConfig& font); FontConfig GetFont() const; void SetFontColor(const Vector3d& color); Vector3d GetFontColor() const; protected: void SetupPipeline(vtkRenderWindowInteractor* iren); void UpdateGrid(); // Internal Prop3D registration void RegisterProp3D(Prop3D* p, bool isPart = false); void UnregisterProp3D(Prop3D* p); void ObserveContext(ObjectsContext* ctx); struct ViewportData *pv; Axis m_GridAxis; std::vector m_Prop3Ds; std::vector m_SelectedProps; MultiSelectionProp* m_MultiSelectionProp; std::map m_ObjectToProp3D; }; } // namespace Vtk } // namespace uLib #endif // ULIB_VTK_VIEWPORT_H