0029025: TInspector include files are not installed to inc directory by CMake
[occt.git] / tools / View / View_Window.cxx
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
20 #include <inspector/View_Window.hxx>
21
22 #include <inspector/View_Displayer.hxx>
23 #include <inspector/View_ToolBar.hxx>
24 #include <inspector/View_Viewer.hxx>
25 #include <inspector/View_Widget.hxx>
26
27 #include <QComboBox>
28 #include <QDockWidget>
29 #include <QGridLayout>
30 #include <QToolBar>
31
32 const int DEFAULT_SPACING = 3;
33
34 // =======================================================================
35 // function : Constructor
36 // purpose :
37 // =======================================================================
38 View_Window::View_Window (QWidget* theParent)
39 : QWidget (theParent)
40 {
41   QGridLayout* aViewLayout = new QGridLayout (this);
42   aViewLayout->setContentsMargins (0, 0, 0, 0);
43   aViewLayout->setSpacing (DEFAULT_SPACING);
44
45   myView = new View_Widget (this);
46   myViewToolBar = new View_ToolBar (this);
47   aViewLayout->addWidget (myViewToolBar->GetControl(), 0, 0, 1, 2);
48   connect (myViewToolBar, SIGNAL (contextChanged()), this, SLOT (onViewSelectorActivated()));
49   connect (myViewToolBar, SIGNAL (actionClicked (int)),
50           this, SLOT (onToolBarActionClicked (int)));
51
52   myActionsToolBar = new QToolBar (this);
53   myActionsToolBar->layout()->setContentsMargins (0, 0, 0, 0);
54   myActionsToolBar->setOrientation (Qt::Vertical);
55
56   for (int anActionId = View_ViewActionType_FitAllId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
57     myActionsToolBar->addAction (myView->GetViewAction ((View_ViewActionType)anActionId));
58   aViewLayout->addWidget (myActionsToolBar, 1, 0);
59   aViewLayout->addWidget (myView, 1, 1);
60   aViewLayout->setRowStretch (1, 1);
61
62   Handle(AIS_InteractiveContext) aContext = myView->GetViewer()->GetContext();
63   myViewToolBar->SetContext (View_ContextType_Own, aContext);
64
65   myDisplayer = new View_Displayer();
66   connect (myView, SIGNAL (displayModeClicked()), this, SLOT (onDisplayModeChanged()));
67   onViewSelectorActivated();
68 }
69
70 // =======================================================================
71 // function : SetContext
72 // purpose :
73 // =======================================================================
74 void View_Window::SetContext (View_ContextType /*theType*/, const Handle(AIS_InteractiveContext)& theContext)
75 {
76   GetViewToolBar()->SetContext (View_ContextType_External, theContext);
77 }
78
79 // =======================================================================
80 // function : onViewSelectorActivated
81 // purpose :
82 // =======================================================================
83 void View_Window::onViewSelectorActivated()
84 {
85   View_ContextType aType = myViewToolBar->GetCurrentContextType();
86   bool isViewEnabled = aType == View_ContextType_Own;
87
88   myView->SetEnabledView (isViewEnabled);
89
90   Handle(AIS_InteractiveContext) aContext = myViewToolBar->GetCurrentContext();
91   myDisplayer->EraseAllPresentations (true);
92   myDisplayer->SetContext (aContext);
93 }
94
95 // =======================================================================
96 // function : onToolBarActionClicked
97 // purpose :
98 // =======================================================================
99 void View_Window::onToolBarActionClicked (const int theActionId)
100 {
101   switch (theActionId)
102   {
103     case View_ToolActionType_KeepViewId:
104     {
105       myDisplayer->KeepPresentations (myViewToolBar->IsActionChecked (theActionId));
106       break;
107     }
108     case View_ToolActionType_KeepViewOffId:
109     {
110       myDisplayer->KeepPresentations (!myViewToolBar->IsActionChecked (theActionId));
111       break;
112     }
113     case View_ToolActionType_ClearViewId:
114     {
115       myDisplayer->EraseAllPresentations (true);
116       break;
117     }
118     default:
119       break;
120   }
121 }
122
123 // =======================================================================
124 // function : onDisplayModeChanged
125 // purpose :
126 // =======================================================================
127 void View_Window::onDisplayModeChanged()
128 {
129   int aDisplayMode = myView->GetDisplayMode();
130   for (NCollection_DataMap<View_PresentationType, NCollection_Shared<AIS_ListOfInteractive> >::Iterator
131        anIterator(myDisplayer->GetDisplayed()); anIterator.More(); anIterator.Next())
132     myDisplayer->SetDisplayMode (aDisplayMode, anIterator.Key(), false);
133   myDisplayer->UpdateViewer();
134 }