ICF 3.0.5.47
Technical documentation of ICF Libraries
TViewExtenderCompBase.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// ICF includes
10#include <istd/TPointerVector.h>
11#include <i2d/ICalibration2d.h>
13#include <iview/IShapeView.h>
14#include <iview/CShapeBase.h>
18
19
20namespace i2dgui
21{
22
23
24template <class Base>
25class TViewExtenderCompBase: public Base, virtual public IViewExtender
26{
27public:
28 typedef Base BaseClass;
29
30 I_BEGIN_BASE_COMPONENT(TViewExtenderCompBase);
31 I_REGISTER_INTERFACE(IViewExtender);
32 I_ASSIGN(m_slaveExtenderCompPtr, "SlaveSceneExtender", "Scene extender will be used to provide background shapes", false, "SlaveSceneExtender");
33 I_ASSIGN(m_sceneExtenderModeAttrPtr, "ViewExtenderMode", "Control how the view extender works:\n\t0 - combine slave with current shapes\n\t1 - use slave by direct calls only\n\t2 - use slave always and current shapes indirect only\n\t3 - use slave by direct calls only and current shapes indirect only", true, 0);
34 I_ASSIGN_MULTI_0(m_idFiltersAttrPtr, "SceneIdFilters", "Optional scene ID filters allowing to ignore some scene providers", false);
35 I_END_COMPONENT;
36
38
39 // reimplemented (i2dgui::IViewExtender)
40 void AddItemsToScene(IViewProvider* providerPtr, int flags) override;
41 void RemoveItemsFromScene(IViewProvider* providerPtr) override;
42
43protected:
51
53 typedef QMap<IViewProvider*, Shapes> ShapesMap;
54
55 bool IsViewIdSupported(int viewId) const;
56 const ShapesMap& GetShapesMap() const;
57
62
66 void SetAllShapesVisible(bool state = true);
67
68 // abstract methods
73 virtual void CreateShapes(int viewId, Shapes& result) = 0;
74
75private:
76 ShapesMap m_shapesMap;
77 bool m_isSlaveShown;
78
79 I_REF(IViewExtender, m_slaveExtenderCompPtr);
80 I_ATTR(int, m_sceneExtenderModeAttrPtr);
81 I_MULTIATTR(int, m_idFiltersAttrPtr);
82};
83
84
85// public methods
86
87template <class Base>
89: m_isSlaveShown(false)
90{
91}
92
93
94// reimplemented (i2dgui::IViewExtender)
95
96template <class Base>
98{
99 Q_ASSERT(providerPtr != nullptr);
100
101 int viewId = providerPtr->GetViewId();
102 iview::IShapeView* viewPtr = providerPtr->GetView();
103
104 bool showOwnShapes = true;
105 bool showSlaveShapes = true;
106
107 switch (*m_sceneExtenderModeAttrPtr){
108 case EM_SLAVE_DIRECT_ONLY:
109 showSlaveShapes = ((flags & SF_DIRECT) != 0);
110 break;
111
112 case EM_OWN_SHAPES_INDIRECT:
113 showOwnShapes = ((flags & SF_DIRECT) == 0);
114 break;
115
116 case EM_SLAVE_DIRECT_ONLY_OWN_SHAPES_INDIRECT:
117 showOwnShapes = ((flags & SF_DIRECT) == 0);
118 showSlaveShapes = ((flags & SF_DIRECT) != 0);
119 break;
120
121 default:
122 break;
123 };
124
125
126 if ( showOwnShapes &&
127 (viewPtr != nullptr) &&
128 IsViewIdSupported(viewId) &&
129 (m_shapesMap.find(providerPtr) == m_shapesMap.end())){
130 Shapes& shapes = m_shapesMap[providerPtr];
131
132 bool isBackground = ((flags & SF_BACKGROUND) != 0);
133 CreateShapes(viewId, shapes);
134
135 int shapesCount = shapes.GetCount();
136 for (int i = 0; i < shapesCount; ++i){
137 iview::IShape* shapePtr = shapes.GetAt(i);
138 if (shapePtr != nullptr){
139 // If the shape should be placed in the scene background
140 // and is not already a background shape, move it to inactive layer:
141 if (isBackground && (shapePtr->GetLayerType() != iview::IViewLayer::LT_BACKGROUND)){
142 iview::CShapeBase* shapeImplPtr = dynamic_cast<iview::CShapeBase*>(shapePtr);
143 if (shapeImplPtr != nullptr){
145 }
146 }
147
148 viewPtr->ConnectShape(shapePtr);
149 }
150 }
151 }
152
153 if (showSlaveShapes && m_slaveExtenderCompPtr != nullptr){
154 m_slaveExtenderCompPtr->AddItemsToScene(providerPtr, (flags | SF_BACKGROUND) & ~SF_DIRECT);
155
156 m_isSlaveShown = true;
157 }
158 else{
159 m_isSlaveShown = false;
160 }
161}
162
163
164template <class Base>
166{
167 Q_ASSERT(providerPtr != nullptr);
168
169 if (m_isSlaveShown){
170 Q_ASSERT(m_slaveExtenderCompPtr != nullptr);
171
172 m_slaveExtenderCompPtr->RemoveItemsFromScene(providerPtr);
173 }
174
175 ShapesMap::iterator iter = m_shapesMap.find(providerPtr);
176 if (iter != m_shapesMap.end()){
177 iview::IShapeView* viewPtr = providerPtr->GetView();
178
179 if (viewPtr != nullptr){
180 Shapes& shapes = iter.value();
181
182 int shapesCount = shapes.GetCount();
183 for (int i = 0; i < shapesCount; ++i){
184 iview::IShape* shapePtr = shapes.GetAt(i);
185 if (shapePtr != nullptr){
186 viewPtr->DisconnectShape(shapePtr);
187 }
188 }
189 }
190
191 m_shapesMap.erase(iter);
192 }
193}
194
195
196// protected methods
197
198template <class Base>
200{
201 if (m_idFiltersAttrPtr.IsValid()){
202 int filtersCount = m_idFiltersAttrPtr.GetCount();
203 for (int i = 0; i < filtersCount; ++i){
204 int filterId = m_idFiltersAttrPtr[i];
205 if (viewId == filterId){
206 return true;
207 }
208 }
209
210 return false;
211 }
212
213 return true;
214}
215
216
217template <class Base>
219{
220 return m_shapesMap;
221}
222
223
224template <class Base>
226{
227 for (ShapesMap::iterator iter = m_shapesMap.begin(); iter != m_shapesMap.end(); ++iter){
228 IViewProvider* viewProvderPtr = iter.key();
229 Q_ASSERT(viewProvderPtr != nullptr);
230
231 iview::IShapeView* viewPtr = viewProvderPtr->GetView();
232 Q_ASSERT(viewPtr != nullptr);
233
234 viewPtr->Update();
235 }
236}
237
238
239template <class Base>
241{
242 for (ShapesMap::iterator iter = m_shapesMap.begin(); iter != m_shapesMap.end(); ++iter){
243 Shapes& shapes = iter.value();
244
245 int shapesCount = shapes.GetCount();
246 for (int i = 0; i < shapesCount; ++i){
247 iview::IShape* shapePtr = shapes.GetAt(i);
248 if (shapePtr != nullptr){
249 shapePtr->SetVisible(state);
250 }
251 }
252 }
253}
254
255
256} // namespace i2dgui
257
258
Interface for GUI objects presenting its results using extern view objects.
Interface for GUI objects managing view.
virtual int GetViewId() const =0
Get ID indentifing this view.
virtual iview::IShapeView * GetView() const =0
Called when items should be removed from specified view.
void AddItemsToScene(IViewProvider *providerPtr, int flags) override
Called when items should be added to specified scene.
const ShapesMap & GetShapesMap() const
void SetAllShapesVisible(bool state=true)
Make all owned shapes visible or hidden.
bool IsViewIdSupported(int viewId) const
istd::TPointerVector< iview::IShape > Shapes
QMap< IViewProvider *, Shapes > ShapesMap
void UpdateAllViews()
It calls Update for all used views.
virtual void CreateShapes(int viewId, Shapes &result)=0
Create shapes for the view.
void RemoveItemsFromScene(IViewProvider *providerPtr) override
Called when items should be removed from specified scene.
Implementation of a pointer container, which controls the live cycle of the pointer object.
Pointer * GetAt(int index) const
Get pointer at specified index.
int GetCount() const
Get number of stored elements.
Base class of standard shape implementation.
Definition CShapeBase.h:34
virtual bool AssignToLayer(int layerType)
Assign this shape to same layer.
Common interface for all display console shapes.
Definition IShape.h:37
virtual void SetVisible(bool state=true)=0
Make shape to be visible or not.
virtual int GetLayerType() const =0
Get layer type of this shape object.
virtual bool DisconnectShape(IShape *shapePtr)=0
Disconnect shape object from view.
Common interface for a general shape view implementations.
Definition IShapeView.h:32
virtual bool ConnectShape(IShape *shapePtr)=0
Connect shape object to view.
virtual void Update()=0
Updates all invalidates shapes.
@ LT_BACKGROUND
Background layer.
Definition IViewLayer.h:44
@ LT_INACTIVE
Layer with inactive shapes.
Definition IViewLayer.h:49
This package contains Qt based implementations for 2D graphic objects.

© Witold Gantzke and Kirill Lepskiy