/**************************************************************************** ** Copyright (c) 2021, Fougue Ltd. ** All rights reserved. ** See license at https://github.com/fougue/mayo/blob/master/LICENSE.txt ****************************************************************************/ #pragma once #include "../base/document.h" #include "../base/global.h" #include "../base/signal.h" #include "../base/tkernel_utils.h" #include "../graphics/graphics_object_driver.h" #include "../graphics/graphics_scene.h" #include "../graphics/graphics_view_ptr.h" #include "v3d_view_camera_animation.h" #include #include #include #include #include #include #include namespace Mayo { class ApplicationItem; class GuiApplication; class V3dViewCameraAnimation; // Provides the link between Base::Document and graphical representations class GuiDocument { public: GuiDocument(const DocumentPtr& doc, GuiApplication* guiApp); ~GuiDocument(); // Not copyable GuiDocument(const GuiDocument&) = delete; GuiDocument& operator=(const GuiDocument&) = delete; const DocumentPtr& document() const { return m_document; } GuiApplication* guiApplication() const { return m_guiApp; } const OccHandle& v3dView() const { return m_v3dView; } GraphicsScene* graphicsScene() { return &m_gfxScene; } GraphicsViewPtr graphicsView() { return GraphicsViewPtr{ &m_gfxScene, m_v3dView }; } const Bnd_Box& graphicsBoundingBox() const { return m_gfxBoundingBox; } // Gets/sets the ratio between physical pixels and device-independent pixels for the target window. // This value is dependent on the screen the window is on, and may have to be updated when the // target window is moved. // Common values are 1.0(default) on normal displays and 2.0 on Apple "retina" displays double devicePixelRatio() const { return m_devicePixelRatio; } void setDevicePixelRatio(double ratio); // Executes callback 'fn' on all graphics objects associated to tree node 'nodeId' // This also includes all children(deep node traversal) void foreachGraphicsObject(TreeNodeId nodeId, const std::function& fn) const; // Finds the tree node id associated to graphics object TreeNodeId nodeFromGraphicsObject(const GraphicsObjectPtr& gfxObject) const; // Toggles selected status of an application item(doesn't affect Application's selection model) void toggleItemSelected(const ApplicationItem& appItem); // Executes action associated to a 3D sensitive item bool processAction(const GraphicsOwnerPtr& gfxOwner); // -- Display mode int activeDisplayMode(const GraphicsObjectDriverPtr& driver) const; void setActiveDisplayMode(const GraphicsObjectDriverPtr& driver, int mode); // -- Visible state of document's tree nodes CheckState nodeVisibleState(TreeNodeId nodeId) const; void setNodeVisible(TreeNodeId nodeId, bool on); // -- Exploding double explodingFactor() const { return m_explodingFactor; } void setExplodingFactor(double t); // Must be in [0,1] // -- Visibility of trihedron at world origin bool isOriginTrihedronVisible() const; void toggleOriginTrihedronVisibility(); // -- Camera animation V3dViewCameraAnimation* viewCameraAnimation() const { return m_cameraAnimation; } void setViewCameraOrientation(V3d_TypeOfOrientation projection); void runViewCameraAnimation(const V3dViewCameraAnimation::ViewFunction& fnViewChange); void stopViewCameraAnimation(); // -- View trihedron enum class ViewTrihedronMode { None, V3dViewZBuffer, AisViewCube // Requires OpenCascade >= v7.4.0 }; ViewTrihedronMode viewTrihedronMode() const { return m_viewTrihedronMode; } void setViewTrihedronMode(ViewTrihedronMode mode); Aspect_TypeOfTriedronPosition viewTrihedronCorner() const { return m_viewTrihedronCorner; } void setViewTrihedronCorner(Aspect_TypeOfTriedronPosition corner); int aisViewCubeBoundingSize() const; static bool isAisViewCubeObject(const GraphicsObjectPtr& gfxObject); // -- Background struct GradientBackground { Quantity_Color color1; Quantity_Color color2; Aspect_GradientFillMethod fillStyle; }; static const GradientBackground& defaultGradientBackground(); static void setDefaultGradientBackground(const GradientBackground& gradientBkgnd); // Signals using MapVisibilityByTreeNodeId = std::unordered_map; mutable Signal signalNodesVisibilityChanged; mutable Signal signalGraphicsBoundingBoxChanged; mutable Signal signalViewTrihedronModeChanged; mutable Signal signalViewTrihedronCornerChanged; // -- Implementation private: void onDocumentEntityAdded(TreeNodeId entityTreeNodeId); void onDocumentEntityAboutToBeDestroyed(TreeNodeId entityTreeNodeId); void onGraphicsSelectionChanged(); void mapEntity(TreeNodeId entityTreeNodeId); void unmapEntity(TreeNodeId entityTreeNodeId); struct GraphicsEntity { struct Object { Object(const GraphicsObjectPtr& p) : ptr(p) {} GraphicsObjectPtr ptr; gp_Trsf trsfOriginal; Bnd_Box bndBox; }; TreeNodeId treeNodeId; std::vector vecObject; std::unordered_map mapTreeNodeGfxObject; std::unordered_map mapGfxObjectTreeNode; Bnd_Box bndBox; }; const GraphicsEntity* findGraphicsEntity(TreeNodeId entityTreeNodeId) const; void v3dViewTrihedronDisplay(Aspect_TypeOfTriedronPosition corner); GuiApplication* m_guiApp = nullptr; DocumentPtr m_document; GraphicsScene m_gfxScene; OccHandle m_v3dView; OccHandle m_aisOriginTrihedron; double m_devicePixelRatio = 1.; V3dViewCameraAnimation* m_cameraAnimation = nullptr; ViewTrihedronMode m_viewTrihedronMode = ViewTrihedronMode::None; Aspect_TypeOfTriedronPosition m_viewTrihedronCorner = Aspect_TOTP_LEFT_UPPER; OccHandle m_aisViewCube; std::vector m_vecGraphicsEntity; Bnd_Box m_gfxBoundingBox; std::unordered_map m_mapGfxDriverDisplayMode; std::unordered_map m_mapTreeNodeCheckState; double m_explodingFactor = 0.; }; } // namespace Mayo