CustusX  15.3.3-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxViewCollectionWidgetMixed.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
34 #include <QGridLayout>
37 #include "cxViewUtilities.h"
38 #include "vtkRenderWindow.h"
39 #include "cxGLHelpers.h"
40 
41 
42 namespace cx
43 {
44 
46  ViewCollectionWidget(parent)
47 {
48  mLayout = new QGridLayout(this);
49  this->setLayout(mLayout);
50  mViewCacheOverlay.reset(new ViewCache<ViewWidget>(this, "Overlay"));
51 
52  this->initBaseLayout();
53 }
54 
56 {
57 }
58 
59 void ViewCollectionWidgetMixed::initBaseLayout()
60 {
61  mBaseLayout = new ViewCollectionWidgetUsingViewContainer(this);
62  this->addWidgetToLayout(mLayout, mBaseLayout, LayoutRegion(0,0));
63  mBaseRegion = LayoutRegion(-1,-1);
64  mTotalRegion = LayoutRegion(-1,-1);
65 
66  this->setGridMargin(4);
67  this->setGridSpacing(2);
68 }
69 
71 {
72  ViewPtr view;
73  mTotalRegion = merge(region, mTotalRegion);
74 
75  if (type==View::VIEW_3D)
76  {
77  ViewWidget* overlay = this->mViewCacheOverlay->retrieveView();
78  overlay->getView()->setType(type);
79  overlay->show();
80  mOverlays.push_back(overlay);
81  mOverlayRegions.push_back(region);
82  view = overlay->getView();
83  this->addWidgetToLayout(mLayout, overlay, region);
84  }
85  else
86  {
87  mBaseRegion = merge(region, mBaseRegion);
88  view = mBaseLayout->addView(type, region);
89  // re-add the base widget with updated position in grid
90  this->addWidgetToLayout(mLayout, mBaseLayout, mBaseRegion);
91  }
92  view_utils::setStretchFactors(mLayout, mTotalRegion, 1);
93 
94  return view;
95 }
96 
97 void ViewCollectionWidgetMixed::addWidgetToLayout(QGridLayout* layout, QWidget* widget, LayoutRegion region)
98 {
99  layout->addWidget(widget,
100  region.pos.row, region.pos.col,
101  region.span.row, region.span.col);
102 }
103 
105 {
106  mViewCacheOverlay->clearUsedViews();
107 
108  for (unsigned i=0; i<mOverlays.size(); ++i)
109  {
110  mOverlays[i]->hide();
111  mLayout->removeWidget(mOverlays[i]);
112  }
113  mOverlays.clear();
114 
115  mBaseLayout->clearViews();
116  mLayout->removeWidget(mBaseLayout);
117 
118  // rebuild to default state:
119  view_utils::setStretchFactors(mLayout, mTotalRegion, 0);
120  this->addWidgetToLayout(mLayout, mBaseLayout, LayoutRegion(0,0));
121  mBaseRegion = LayoutRegion(-1,-1);
122  mTotalRegion = LayoutRegion(-1,-1);
123 }
124 
126 {
127  mBaseLayout->setModified();
128  for (unsigned i=0; i<mOverlays.size(); ++i)
129  mOverlays[i]->setModified();
130 }
131 
133 {
134  mBaseLayout->render();
135  report_gl_error_text(cstring_cast(QString("During rendering of base view")));
136 
137  for (unsigned i=0; i<mOverlays.size(); ++i)
138  {
139  mOverlays[i]->render();
140  report_gl_error_text(cstring_cast(QString("During rendering of: ") + mOverlays[i]->getView()->getName()));
141  }
142 }
143 
145 {
146  mLayout->setSpacing(val);
147  mBaseLayout->setGridSpacing(val);
148 }
149 
151 {
152  mBaseLayout->setGridMargin(0);
153  mLayout->setMargin(val);
154 }
155 
156 } /* namespace cx */
virtual void setModified()=0
virtual void render()=0
virtual void clearViews()=0
cstring_cast_Placeholder cstring_cast(const T &val)
LayoutPosition span
size of region
Definition: cxLayoutData.h:67
boost::shared_ptr< class View > ViewPtr
#define report_gl_error_text(text)
Definition: cxGLHelpers.h:46
virtual void setGridMargin(int val)=0
virtual void setGridSpacing(int val)=0
ViewRepCollectionPtr getView()
void setStretchFactors(QGridLayout *layout, LayoutRegion region, int stretchFactor)
LayoutPosition pos
start position of region
Definition: cxLayoutData.h:66
virtual ViewPtr addView(View::Type type, LayoutRegion region)=0
ViewPtr addView(View::Type type, LayoutRegion region)
LayoutRegion merge(LayoutRegion a, LayoutRegion b)