1 // Copyright (c) 2020 OPEN CASCADE SAS
3 // This file is part of the examples of the Open CASCADE Technology software library.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
27 #include <Standard_WarningsDisable.hxx>
33 #include <Standard_WarningsRestore.hxx>
35 #include <AIS_InteractiveContext.hxx>
36 #include <AIS_ViewController.hxx>
37 #include <V3d_View.hxx>
41 enum CurrentAction3d { Nothing, DynamicZooming, WindowZooming,
42 DynamicPanning, GlobalPanning, DynamicRotation, ObjectDececting };
43 enum ViewAction { FitAll, FitArea, Zoom, Pan, GlobalPan, Front, Back, Top, Bottom,
44 Left, Right, Axo, Rotation, Reset, HlrOff, HlrOn, Shading, Wireframe, Transparency };
45 enum RaytraceAction { ToolRaytracing, ToolShadows, ToolReflections, ToolAntialiasing };
47 //! Qt widget containing V3d_View and toolbar with view manipulation buttons.
48 //! Also use AIS_ViewController for redirecting user input (mouse, keyboard)
49 //! into 3D viewer events (rotation, panning, zooming)
50 class View: public QWidget, protected AIS_ViewController
54 View (const Handle(AIS_InteractiveContext)& theContext, bool theIs3dView, QWidget* theParent);
62 QList<QAction*> getViewActions();
63 QAction* getViewAction(ViewAction theAction);
64 QList<QAction*> getRaytraceActions();
65 QAction* getRaytraceAction(RaytraceAction theAction);
67 void EnableRaytracing();
68 void DisableRaytracing();
70 void SetRaytracedShadows (bool theState);
71 void SetRaytracedReflections (bool theState);
72 void SetRaytracedAntialiasing (bool theState);
74 bool IsRaytracingMode() const { return myIsRaytracing; }
75 bool IsShadowsEnabled() const { return myIsShadowsEnabled; }
76 bool IsReflectionsEnabled() const { return myIsReflectionsEnabled; }
77 bool IsAntialiasingEnabled() const { return myIsAntialiasingEnabled; }
79 static QString GetMessages(int type,TopAbs_ShapeEnum aSubShapeType, TopAbs_ShapeEnum aShapeType);
80 static QString GetShapeType(TopAbs_ShapeEnum aShapeType);
82 Standard_EXPORT static void OnButtonuseraction(int ExerciceSTEP, Handle(AIS_InteractiveContext)& );
83 Standard_EXPORT static void DoSelection(int Id, Handle(AIS_InteractiveContext)& );
84 Standard_EXPORT static void OnSetSelectionMode(Handle(AIS_InteractiveContext)&,
86 TopAbs_ShapeEnum& SelectionMode,
88 virtual QPaintEngine* paintEngine() const;
89 const Handle(V3d_View)& getView() const { return myV3dView; }
91 void selectionChanged();
100 void onTransparency();
102 void updateToggled( bool );
104 void onEnvironmentMap();
105 void onRaytraceAction();
108 void onTransparencyChanged(int theVal);
111 virtual void paintEvent( QPaintEvent* ) Standard_OVERRIDE;
112 virtual void resizeEvent( QResizeEvent* ) Standard_OVERRIDE;
113 virtual void mousePressEvent( QMouseEvent* ) Standard_OVERRIDE;
114 virtual void mouseReleaseEvent(QMouseEvent* ) Standard_OVERRIDE;
115 virtual void mouseMoveEvent( QMouseEvent* ) Standard_OVERRIDE;
116 virtual void wheelEvent(QWheelEvent*) Standard_OVERRIDE;
118 virtual void addItemInPopup( QMenu* );
120 Handle(AIS_InteractiveContext)& getContext() { return myContext; }
122 void activateCursor( const CurrentAction3d );
124 CurrentAction3d getCurrentMode() const { return myCurrentMode; }
128 void initViewActions();
129 void initRaytraceActions();
131 QAction* RegisterAction(QString theIconPath, QString thePromt, void (View::*theSlot)(void));
135 bool myIsShadowsEnabled;
136 bool myIsReflectionsEnabled;
137 bool myIsAntialiasingEnabled;
141 Handle(V3d_View) myV3dView;
142 Handle(AIS_InteractiveContext) myContext;
143 AIS_MouseGestureMap myDefaultGestures;
144 Graphic3d_Vec2i myClickPos;
148 //! Setup mouse gestures.
149 void defineMouseGestures();
151 //! Set current action.
152 void setCurrentAction (CurrentAction3d theAction)
154 myCurrentMode = theAction;
155 defineMouseGestures();
158 //! Handle selection changed event.
159 void OnSelectionChanged(const Handle(AIS_InteractiveContext)& theCtx,
160 const Handle(V3d_View)& theView) Standard_OVERRIDE;
161 CurrentAction3d myCurrentMode;
162 Standard_Real myCurZoom;
163 QMap<ViewAction, QAction*> myViewActions;
164 QMap<RaytraceAction, QAction*> myRaytraceActions;