14bbbdcb |
1 | // Created on: 2017-06-16 |
2 | // Created by: Natalia ERMOLAEVA |
3 | // Copyright (c) 2017 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #if !defined _WIN32 |
17 | #define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */ |
18 | #endif |
19 | |
0cb512c0 |
20 | #include <inspector/View_Window.hxx> |
14bbbdcb |
21 | |
0cb512c0 |
22 | #include <inspector/View_Displayer.hxx> |
23 | #include <inspector/View_ToolBar.hxx> |
6822a3be |
24 | #include <inspector/View_Tools.hxx> |
0cb512c0 |
25 | #include <inspector/View_Viewer.hxx> |
26 | #include <inspector/View_Widget.hxx> |
14bbbdcb |
27 | |
6822a3be |
28 | #include <V3d.hxx> |
29 | |
130eb114 |
30 | #include <Standard_WarningsDisable.hxx> |
14bbbdcb |
31 | #include <QComboBox> |
32 | #include <QDockWidget> |
33 | #include <QGridLayout> |
6822a3be |
34 | #include <QMenu> |
14bbbdcb |
35 | #include <QToolBar> |
130eb114 |
36 | #include <Standard_WarningsRestore.hxx> |
14bbbdcb |
37 | |
38 | const int DEFAULT_SPACING = 3; |
39 | |
40 | // ======================================================================= |
41 | // function : Constructor |
42 | // purpose : |
43 | // ======================================================================= |
6822a3be |
44 | View_Window::View_Window (QWidget* theParent, const bool isUseKeepView, const bool isFitAllActive) |
14bbbdcb |
45 | : QWidget (theParent) |
46 | { |
47 | QGridLayout* aViewLayout = new QGridLayout (this); |
48 | aViewLayout->setContentsMargins (0, 0, 0, 0); |
49 | aViewLayout->setSpacing (DEFAULT_SPACING); |
50 | |
6822a3be |
51 | myView = new View_Widget (this, isFitAllActive); |
52 | myViewToolBar = new View_ToolBar (this, isUseKeepView); |
14bbbdcb |
53 | aViewLayout->addWidget (myViewToolBar->GetControl(), 0, 0, 1, 2); |
54 | connect (myViewToolBar, SIGNAL (contextChanged()), this, SLOT (onViewSelectorActivated())); |
55 | connect (myViewToolBar, SIGNAL (actionClicked (int)), |
56 | this, SLOT (onToolBarActionClicked (int))); |
57 | |
6822a3be |
58 | connect (myView, SIGNAL (checkedStateChanged(int, bool)), this, SLOT (onCheckedStateChanged (int, bool))); |
59 | |
60 | myView->setContextMenuPolicy (Qt::CustomContextMenu); |
61 | connect (myView, SIGNAL (customContextMenuRequested (const QPoint&)), |
62 | this, SLOT (onViewContextMenuRequested (const QPoint&))); |
63 | |
14bbbdcb |
64 | myActionsToolBar = new QToolBar (this); |
65 | myActionsToolBar->layout()->setContentsMargins (0, 0, 0, 0); |
66 | myActionsToolBar->setOrientation (Qt::Vertical); |
67 | |
6822a3be |
68 | myActionsToolBar->addWidget (myView-> GetWidget (View_ViewActionType_FitAllId)); |
69 | for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++) |
14bbbdcb |
70 | myActionsToolBar->addAction (myView->GetViewAction ((View_ViewActionType)anActionId)); |
6822a3be |
71 | |
14bbbdcb |
72 | aViewLayout->addWidget (myActionsToolBar, 1, 0); |
73 | aViewLayout->addWidget (myView, 1, 1); |
74 | aViewLayout->setRowStretch (1, 1); |
75 | |
76 | Handle(AIS_InteractiveContext) aContext = myView->GetViewer()->GetContext(); |
77 | myViewToolBar->SetContext (View_ContextType_Own, aContext); |
78 | |
79 | myDisplayer = new View_Displayer(); |
6822a3be |
80 | if (!isUseKeepView) |
81 | myDisplayer->KeepPresentations (true); |
82 | myDisplayer->SetFitAllActive (isFitAllActive); |
14bbbdcb |
83 | connect (myView, SIGNAL (displayModeClicked()), this, SLOT (onDisplayModeChanged())); |
84 | onViewSelectorActivated(); |
85 | } |
86 | |
87 | // ======================================================================= |
88 | // function : SetContext |
89 | // purpose : |
90 | // ======================================================================= |
91 | void View_Window::SetContext (View_ContextType /*theType*/, const Handle(AIS_InteractiveContext)& theContext) |
92 | { |
93 | GetViewToolBar()->SetContext (View_ContextType_External, theContext); |
94 | } |
95 | |
96 | // ======================================================================= |
97 | // function : onViewSelectorActivated |
98 | // purpose : |
99 | // ======================================================================= |
100 | void View_Window::onViewSelectorActivated() |
101 | { |
102 | View_ContextType aType = myViewToolBar->GetCurrentContextType(); |
103 | bool isViewEnabled = aType == View_ContextType_Own; |
104 | |
105 | myView->SetEnabledView (isViewEnabled); |
106 | |
107 | Handle(AIS_InteractiveContext) aContext = myViewToolBar->GetCurrentContext(); |
108 | myDisplayer->EraseAllPresentations (true); |
6822a3be |
109 | emit eraseAllPerformed(); |
110 | |
14bbbdcb |
111 | myDisplayer->SetContext (aContext); |
112 | } |
113 | |
114 | // ======================================================================= |
115 | // function : onToolBarActionClicked |
116 | // purpose : |
117 | // ======================================================================= |
118 | void View_Window::onToolBarActionClicked (const int theActionId) |
119 | { |
120 | switch (theActionId) |
121 | { |
122 | case View_ToolActionType_KeepViewId: |
123 | { |
124 | myDisplayer->KeepPresentations (myViewToolBar->IsActionChecked (theActionId)); |
125 | break; |
126 | } |
127 | case View_ToolActionType_KeepViewOffId: |
128 | { |
129 | myDisplayer->KeepPresentations (!myViewToolBar->IsActionChecked (theActionId)); |
130 | break; |
131 | } |
132 | case View_ToolActionType_ClearViewId: |
133 | { |
134 | myDisplayer->EraseAllPresentations (true); |
6822a3be |
135 | emit eraseAllPerformed(); |
14bbbdcb |
136 | break; |
137 | } |
138 | default: |
139 | break; |
140 | } |
141 | } |
142 | |
6822a3be |
143 | // ======================================================================= |
144 | // function : onCheckedStateChanged |
145 | // purpose : |
146 | // ======================================================================= |
147 | void View_Window::onCheckedStateChanged (int theActionId, bool theState) |
148 | { |
149 | if (theActionId == View_ViewActionType_FitAllId) |
150 | myDisplayer->SetFitAllActive (theState); |
151 | } |
152 | |
153 | // ======================================================================= |
154 | // function : onViewContextMenuRequested |
155 | // purpose : |
156 | // ======================================================================= |
157 | void View_Window::onViewContextMenuRequested (const QPoint& thePosition) |
158 | { |
159 | QMenu* aMenu = new QMenu (this); |
160 | QMenu* anOrientationSubMenu = aMenu->addMenu ("Set View Orientation"); |
161 | |
162 | for (int i = 0; i < (int)V3d_XnegYnegZneg; i++) |
163 | { |
164 | V3d_TypeOfOrientation anOrientationType = (V3d_TypeOfOrientation)i; |
165 | anOrientationSubMenu->addAction (View_Tools::CreateAction (V3d::TypeOfOrientationToString (anOrientationType), |
166 | SLOT (onSetOrientation()), this, this)); |
167 | } |
168 | aMenu->addMenu (anOrientationSubMenu); |
169 | |
170 | QPoint aPoint = myView->mapToGlobal (thePosition); |
171 | aMenu->exec (aPoint); |
172 | } |
173 | |
174 | // ======================================================================= |
175 | // function : onSetOrientation |
176 | // purpose : |
177 | // ======================================================================= |
178 | void View_Window::onSetOrientation() |
179 | { |
180 | QAction* anAction = (QAction*)(sender()); |
181 | |
182 | TCollection_AsciiString anOrientationStr (anAction->text().toStdString().c_str()); |
183 | |
184 | V3d_TypeOfOrientation anOrientationType; |
185 | if (!V3d::TypeOfOrientationFromString (anOrientationStr.ToCString(), anOrientationType)) |
186 | return; |
187 | |
188 | Handle(V3d_View) aView = myView->GetViewer()->GetView(); |
189 | if (aView.IsNull()) |
190 | return; |
191 | |
192 | aView->SetProj (anOrientationType); |
193 | aView->FitAll(); |
194 | aView->Redraw(); |
195 | } |
196 | |
14bbbdcb |
197 | // ======================================================================= |
198 | // function : onDisplayModeChanged |
199 | // purpose : |
200 | // ======================================================================= |
201 | void View_Window::onDisplayModeChanged() |
202 | { |
203 | int aDisplayMode = myView->GetDisplayMode(); |
204 | for (NCollection_DataMap<View_PresentationType, NCollection_Shared<AIS_ListOfInteractive> >::Iterator |
205 | anIterator(myDisplayer->GetDisplayed()); anIterator.More(); anIterator.Next()) |
206 | myDisplayer->SetDisplayMode (aDisplayMode, anIterator.Key(), false); |
207 | myDisplayer->UpdateViewer(); |
208 | } |