Choreonoid  1.8
SceneWidget.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_BASE_SCENE_WIDGET_H
6 #define CNOID_BASE_SCENE_WIDGET_H
7 
8 #include <cnoid/SceneGraph>
9 #include <cnoid/Widget>
10 #include <QBoxLayout>
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15 class ExtensionManager;
16 class SceneRenderer;
17 class Archive;
18 class MenuManager;
19 class SceneWidgetEvent;
20 class SceneWidgetEventHandler;
21 class SceneWidgetRoot;
22 class Menu;
23 class InteractiveCameraTransform;
24 
25 class CNOID_EXPORT SceneWidget : public Widget
26 {
27 public:
28  static void initializeClass(ExtensionManager* ext);
29  static SignalProxy<void(SceneWidget*)> sigSceneWidgetCreated();
30 
31  SceneWidget(QWidget* parent);
32  ~SceneWidget();
33 
34  static void forEachInstance(SgNode* node, std::function<void(SceneWidget* sceneWidget, const SgNodePath& path)> function);
35 
36  void setModeSyncEnabled(bool on);
37 
38  SceneWidgetRoot* sceneRoot();
39  SgGroup* scene();
40  SgGroup* systemNodeGroup();
41 
42  SceneRenderer* renderer();
43 
44  void renderScene(bool doImmediately = false);
45 
46  [[deprecated("Use renderScene(true).")]]
47  void draw() { renderScene(true); }
48 
49  SignalProxy<void()> sigStateChanged() const;
50 
51  void setEditMode(bool on);
52  bool isEditMode() const;
53 
54  // Issue a unique ID from 2.
55  // ID 0 is used as the non-custom mode ID.
56  // ID 1 is used as the default (common) customo mode ID that can be used for any customo mode.
57  static int issueUniqueCustomModeId();
58 
59  void activateCustomMode(SceneWidgetEventHandler* modeHandler, int modeId = 1);
60  SceneWidgetEventHandler* activeCustomModeHandler();
61  int activeCustomMode() const;
62  // If modeHandler is nullptr, any current custom mode is deactivated.
63  void deactivateCustomMode(SceneWidgetEventHandler* modeHandler = nullptr);
64 
65  SceneWidgetEvent* latestEvent();
66  Vector3 lastClickedPoint() const;
67 
70  FirstPersonMode
71  };
72  void setViewpointOperationMode(ViewpointOperationMode mode);
73  ViewpointOperationMode viewpointOperationMode() const;
74 
75  SgPosTransform* builtinCameraTransform(void);
76  SgPerspectiveCamera* builtinPerspectiveCamera() const;
77  SgOrthographicCamera* builtinOrthographicCamera() const;
78  bool isBuiltinCameraCurrent() const;
79  bool isBuiltinCamera(SgCamera* camera) const;
80  InteractiveCameraTransform* findOwnerInteractiveCameraTransform(int cameraIndex);
81 
82  void startBuiltinCameraViewChange(const Vector3& center);
83  void rotateBuiltinCameraView(double dPitch, double dYaw);
84  void translateBuiltinCameraView(const Vector3& dp_local);
85 
86  bool unproject(double x, double y, double z, Vector3& out_projected) const;
87 
88  void viewAll();
89 
90  // This is same as SgPolygonDrawStyle::PolygonElement
92  PolygonFace = 1,
93  PolygonEdge = 2,
94  PolygonVertex = 4
95  };
96  void setVisiblePolygonElements(int elementFlags);
97  int visiblePolygonElements() const;
98 
99  void setHighlightingEnabled(bool on);
100  bool isHighlightingEnabled() const;
101 
102  void setCollisionLineVisibility(bool on);
103  bool collisionLineVisibility() const;
104 
105  void setHeadLightIntensity(double value);
106  void setWorldLightIntensity(double value);
107  void setWorldLightAmbient(double value);
108  void setFloorGridSpan(double value);
109  void setFloorGridInterval(double value);
110  void setLineWidth(double value);
111  void setPointSize(double value);
112  void setNormalLength(double value);
113 
114  void setHeadLightEnabled(bool on);
115  void setHeadLightLightingFromBack(bool on);
116  void setWorldLight(bool on);
117  void setAdditionalLights(bool on);
118  void setFloorGrid(bool on);
119  void setNormalVisualization(bool on);
120  void setCoordinateAxes(bool on);
121  void setShowFPS(bool on);
122 
123  void setBackgroundColor(const Vector3& color);
124  Vector3 backgroundColor();
125  void setColor(const Vector4& color);
126 
127  void setCameraPosition(const Vector3& eye, const Vector3& direction, const Vector3& up);
128  void setFieldOfView(double value);
129  void setHeight(double value);
130  void setNear(double value);
131  void setFar(double value);
132 
133  bool setSceneFocus(const SgNodePath& path);
134 
138  //int setCursor(const QCursor cursor);
139  //void releaseCursor(int cursorId);
140 
141  void setCursor(const QCursor cursor);
142 
143  Menu* contextMenu();
144  void showContextMenuAtPointerPosition();
145  SignalProxy<void(SceneWidgetEvent* event, MenuManager* menuManager)> sigContextMenuRequest();
146 
147  void showConfigDialog();
148  QVBoxLayout* configDialogVBox();
149 
150  bool saveImage(const std::string& filename);
151  QImage getImage();
152  void setScreenSize(int width, int height);
153 
154  void updateIndicator(const std::string& text);
155  QWidget* indicator();
156 
157  bool storeState(Archive& archive);
158  bool restoreState(const Archive& archive);
159 
160  SignalProxy<void(bool isFocused)> sigWidgetFocusChanged();
161  SignalProxy<void()> sigAboutToBeDestroyed();
162 
163  class Impl;
164 
165 private:
166  Impl* impl;
167 };
168 
169 
170 class CNOID_EXPORT SceneWidgetRoot : public SgGroup
171 {
172 public:
173  SceneWidget* sceneWidget() { return sceneWidget_; }
174 private:
175  SceneWidgetRoot(SceneWidget* sceneWidget);
176  SceneWidget* sceneWidget_;
177  SgUnpickableGroupPtr systemGroup;
178  friend class SceneWidget;
179 };
181 
182 }
183 
184 #endif
cnoid::SgPosTransform
Definition: SceneGraph.h:357
cnoid::Vector3
Eigen::Vector3d Vector3
Definition: EigenTypes.h:57
cnoid::SceneWidget::PolygonElement
PolygonElement
Definition: SceneWidget.h:91
cnoid::SgPerspectiveCamera
Definition: SceneCameras.h:56
cnoid::ExtensionManager
Definition: ExtensionManager.h:23
cnoid::SgGroup
Definition: SceneGraph.h:220
cnoid::SgCamera
Definition: SceneCameras.h:14
cnoid::Archive
Definition: Archive.h:22
cnoid::MenuManager
Definition: MenuManager.h:14
cnoid::SceneWidget::ThirdPersonMode
@ ThirdPersonMode
Definition: SceneWidget.h:69
cnoid::SceneWidgetRoot::sceneWidget
SceneWidget * sceneWidget()
Definition: SceneWidget.h:173
cnoid::SceneWidgetRoot
Definition: SceneWidget.h:170
cnoid::ref_ptr< SgUnpickableGroup >
cnoid::SceneWidgetEventHandler
Definition: SceneWidgetEventHandler.h:15
cnoid::SceneWidgetEvent
Definition: SceneWidgetEvent.h:15
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::Vector4
Eigen::Vector4d Vector4
Definition: EigenTypes.h:59
cnoid::SceneWidgetRootPtr
ref_ptr< SceneWidgetRoot > SceneWidgetRootPtr
Definition: SceneWidget.h:180
cnoid::InteractiveCameraTransform
Definition: InteractiveCameraTransform.h:13
cnoid::SgNodePath
std::vector< SgNode * > SgNodePath
Definition: SceneGraph.h:24
cnoid::Widget
Definition: Widget.h:10
cnoid::SignalProxy
Definition: Signal.h:470
cnoid::Menu
Definition: Menu.h:14
cnoid::SceneWidget
Definition: SceneWidget.h:25
cnoid::SgNode
Definition: SceneGraph.h:157
cnoid::SgOrthographicCamera
Definition: SceneCameras.h:83
cnoid::SceneRenderer
Definition: SceneRenderer.h:15
cnoid::SceneWidget::ViewpointOperationMode
ViewpointOperationMode
Definition: SceneWidget.h:68
cnoid::SceneWidget::draw
void draw()
Definition: SceneWidget.h:47