1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
20 #include <inspector/View_Window.hxx>
22 #include <inspector/View_Displayer.hxx>
23 #include <inspector/View_ToolBar.hxx>
24 #include <inspector/View_Viewer.hxx>
25 #include <inspector/View_Widget.hxx>
28 #include <QDockWidget>
29 #include <QGridLayout>
32 const int DEFAULT_SPACING = 3;
34 // =======================================================================
35 // function : Constructor
37 // =======================================================================
38 View_Window::View_Window (QWidget* theParent)
41 QGridLayout* aViewLayout = new QGridLayout (this);
42 aViewLayout->setContentsMargins (0, 0, 0, 0);
43 aViewLayout->setSpacing (DEFAULT_SPACING);
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)));
52 myActionsToolBar = new QToolBar (this);
53 myActionsToolBar->layout()->setContentsMargins (0, 0, 0, 0);
54 myActionsToolBar->setOrientation (Qt::Vertical);
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);
62 Handle(AIS_InteractiveContext) aContext = myView->GetViewer()->GetContext();
63 myViewToolBar->SetContext (View_ContextType_Own, aContext);
65 myDisplayer = new View_Displayer();
66 connect (myView, SIGNAL (displayModeClicked()), this, SLOT (onDisplayModeChanged()));
67 onViewSelectorActivated();
70 // =======================================================================
71 // function : SetContext
73 // =======================================================================
74 void View_Window::SetContext (View_ContextType /*theType*/, const Handle(AIS_InteractiveContext)& theContext)
76 GetViewToolBar()->SetContext (View_ContextType_External, theContext);
79 // =======================================================================
80 // function : onViewSelectorActivated
82 // =======================================================================
83 void View_Window::onViewSelectorActivated()
85 View_ContextType aType = myViewToolBar->GetCurrentContextType();
86 bool isViewEnabled = aType == View_ContextType_Own;
88 myView->SetEnabledView (isViewEnabled);
90 Handle(AIS_InteractiveContext) aContext = myViewToolBar->GetCurrentContext();
91 myDisplayer->EraseAllPresentations (true);
92 myDisplayer->SetContext (aContext);
95 // =======================================================================
96 // function : onToolBarActionClicked
98 // =======================================================================
99 void View_Window::onToolBarActionClicked (const int theActionId)
103 case View_ToolActionType_KeepViewId:
105 myDisplayer->KeepPresentations (myViewToolBar->IsActionChecked (theActionId));
108 case View_ToolActionType_KeepViewOffId:
110 myDisplayer->KeepPresentations (!myViewToolBar->IsActionChecked (theActionId));
113 case View_ToolActionType_ClearViewId:
115 myDisplayer->EraseAllPresentations (true);
123 // =======================================================================
124 // function : onDisplayModeChanged
126 // =======================================================================
127 void View_Window::onDisplayModeChanged()
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();