1 /*
2  * RGraphicsPlotManipulatorManager.hpp
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 
16 #ifndef R_SESSION_GRAPHICS_PLOT_MANIPULATOR_MANAGER_HPP
17 #define R_SESSION_GRAPHICS_PLOT_MANIPULATOR_MANAGER_HPP
18 
19 #include <core/BoostSignals.hpp>
20 #include <shared_core/Error.hpp>
21 #include <shared_core/json/Json.hpp>
22 
23 #include <r/RSexp.hpp>
24 
25 #include "RGraphicsTypes.hpp"
26 
27 namespace rstudio {
28 namespace core {
29    class Error;
30 }
31 }
32 
33 namespace rstudio {
34 namespace r {
35 namespace session {
36 namespace graphics {
37 
38 // singleton
39 class PlotManipulatorManager;
40 PlotManipulatorManager& plotManipulatorManager();
41 
42 
43 class PlotManipulatorManager : boost::noncopyable
44 {
45 private:
46    friend PlotManipulatorManager& plotManipulatorManager();
47    PlotManipulatorManager();
48 
49 public:
~PlotManipulatorManager()50    virtual ~PlotManipulatorManager() {}
51 
52 public:
53    core::Error initialize(const UnitConversionFunctions& convert);
54 
55    RSTUDIO_BOOST_SIGNAL<void ()>& onShowManipulator();
56    void setPlotManipulatorValues(const core::json::Object& values);
57    void manipulatorPlotClicked(int x, int y);
58 
59    void executeAndAttachManipulator(SEXP manipulatorSEXP);
60    bool hasActiveManipulator() const;
61    SEXP activeManipulator() const;
62 
replayingManipulator() const63    bool replayingManipulator() const { return replayingManipulator_; }
pendingManipulatorSEXP() const64    SEXP pendingManipulatorSEXP() const { return pendingManipulatorSEXP_; }
65 
clearPendingManipulatorState()66    void clearPendingManipulatorState()
67    {
68       pendingManipulatorSEXP_ = R_NilValue;
69       replayingManipulator_ = false;
70    }
71 
72    void ensureManipulatorSaved();
73 
74 private:
75    bool manipulatorIsActive() const;
76    bool trackingMouseClicks(SEXP manipulatorSEXP) const;
77    void replayManipulator(SEXP manipulatorSEXP);
78 
79 private:
80    // pending manipulator
81    SEXP pendingManipulatorSEXP_;
82 
83    // are we currently replaying a manipulator call?
84    bool replayingManipulator_;
85 
86    // manipulator event hook
87    RSTUDIO_BOOST_SIGNAL<void ()> onShowManipulator_;
88 
89    // unit conversion function
90    UnitConversionFunctions convert_;
91 
92 };
93 
94 } // namespace graphics
95 } // namespace session
96 } // namespace r
97 } // namespace rstudio
98 
99 #endif // R_SESSION_GRAPHICS_PLOT_MANIPULATOR_MANAGER_HPP
100 
101