TViewExtenderCompBase.h
Go to the documentation of this file.
1 #ifndef iqt2d_TSceneExtenderCompBase_included
2 #define iqt2d_TSceneExtenderCompBase_included
3 
4 
5 // ACF includes
6 #include <istd/TPointerVector.h>
7 #include <i2d/ICalibration2d.h>
8 #include <iview/IShapeView.h>
9 #include <iview/CShapeBase.h>
11 #include <iqt2d/IViewProvider.h>
12 #include <iqt2d/IViewExtender.h>
13 
14 
15 namespace iqt2d
16 {
17 
18 
19 template <class Base>
20 class TViewExtenderCompBase: public Base, virtual public IViewExtender
21 {
22 public:
23  typedef Base BaseClass;
24 
25  I_BEGIN_BASE_COMPONENT(TViewExtenderCompBase);
26  I_REGISTER_INTERFACE(IViewExtender);
27  I_ASSIGN(m_slaveExtenderCompPtr, "SlaveSceneExtender", "Scene extender will be used to provide background shapes", false, "SlaveSceneExtender");
28  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);
29  I_ASSIGN_MULTI_0(m_idFiltersAttrPtr, "SceneIdFilters", "Optional scene ID filters allowing to ignore some scene providers", false);
30  I_END_COMPONENT;
31 
33 
34  // reimplemented (iqt2d::IViewExtender)
35  virtual void AddItemsToScene(IViewProvider* providerPtr, int flags);
36  virtual void RemoveItemsFromScene(IViewProvider* providerPtr);
37 
38 protected:
40  {
45  };
46 
48  typedef QMap<IViewProvider*, Shapes> ShapesMap;
49 
50  bool IsViewIdSupported(int viewId) const;
51  const ShapesMap& GetShapesMap() const;
52 
56  void UpdateAllViews();
57 
58  // abstract methods
63  virtual void CreateShapes(int viewId, Shapes& result) = 0;
64 
65 private:
66  ShapesMap m_shapesMap;
67  bool m_isSlaveShown;
68 
69  I_REF(IViewExtender, m_slaveExtenderCompPtr);
70  I_ATTR(int, m_sceneExtenderModeAttrPtr);
71  I_MULTIATTR(int, m_idFiltersAttrPtr);
72 };
73 
74 
75 // public methods
76 
77 template <class Base>
79 : m_isSlaveShown(false)
80 {
81 }
82 
83 
84 // reimplemented (iqt2d::IViewExtender)
85 
86 template <class Base>
88 {
89  Q_ASSERT(providerPtr != NULL);
90 
91  int viewId = providerPtr->GetViewId();
92  iview::IShapeView* viewPtr = providerPtr->GetView();
93 
94  bool showOwnShapes = true;
95  bool showSlaveShapes = true;
96 
97  switch (*m_sceneExtenderModeAttrPtr){
98  case EM_SLAVE_DIRECT_ONLY:
99  showSlaveShapes = ((flags & SF_DIRECT) != 0);
100  break;
101 
102  case EM_OWN_SHAPES_INDIRECT:
103  showOwnShapes = ((flags & SF_DIRECT) == 0);
104  break;
105 
106  case EM_SLAVE_DIRECT_ONLY_OWN_SHAPES_INDIRECT:
107  showOwnShapes = ((flags & SF_DIRECT) == 0);
108  showSlaveShapes = ((flags & SF_DIRECT) != 0);
109  break;
110 
111  default:
112  break;
113  };
114 
115 
116  if ( showOwnShapes &&
117  (viewPtr != NULL) &&
118  IsViewIdSupported(viewId) &&
119  (m_shapesMap.find(providerPtr) == m_shapesMap.end())){
120  Shapes& shapes = m_shapesMap[providerPtr];
121 
122  bool isBackground = ((flags & SF_BACKGROUND) != 0);
123  CreateShapes(viewId, shapes);
124 
125  int shapesCount = shapes.GetCount();
126  for (int i = 0; i < shapesCount; ++i){
127  iview::IShape* shapePtr = shapes.GetAt(i);
128  if (shapePtr != NULL){
129  // If the shape should be placed in the scene background
130  // and is not already a background shape, move it to inactive layer:
131  if (isBackground && (shapePtr->GetLayerType() != iview::IViewLayer::LT_BACKGROUND)){
132  iview::CShapeBase* shapeImplPtr = dynamic_cast<iview::CShapeBase*>(shapePtr);
133  if (shapeImplPtr != NULL){
135  }
136  }
137 
138  viewPtr->ConnectShape(shapePtr);
139  }
140  }
141  }
142 
143  if (showSlaveShapes && m_slaveExtenderCompPtr.IsValid()){
144  m_slaveExtenderCompPtr->AddItemsToScene(providerPtr, (flags | SF_BACKGROUND) & ~SF_DIRECT);
145 
146  m_isSlaveShown = true;
147  }
148  else{
149  m_isSlaveShown = false;
150  }
151 }
152 
153 
154 template <class Base>
156 {
157  Q_ASSERT(providerPtr != NULL);
158 
159  if (m_isSlaveShown){
160  Q_ASSERT(m_slaveExtenderCompPtr.IsValid());
161 
162  m_slaveExtenderCompPtr->RemoveItemsFromScene(providerPtr);
163  }
164 
165  ShapesMap::iterator iter = m_shapesMap.find(providerPtr);
166  if (iter != m_shapesMap.end()){
167  iview::IShapeView* viewPtr = providerPtr->GetView();
168 
169  if (viewPtr != NULL){
170  Shapes& shapes = iter.value();
171 
172  int shapesCount = shapes.GetCount();
173  for (int i = 0; i < shapesCount; ++i){
174  iview::IShape* shapePtr = shapes.GetAt(i);
175  if (shapePtr != NULL){
176  viewPtr->DisconnectShape(shapePtr);
177  }
178  }
179  }
180 
181  m_shapesMap.erase(iter);
182  }
183 }
184 
185 
186 // protected methods
187 
188 template <class Base>
190 {
191  if (m_idFiltersAttrPtr.IsValid()){
192  int filtersCount = m_idFiltersAttrPtr.GetCount();
193  for (int i = 0; i < filtersCount; ++i){
194  int filterId = m_idFiltersAttrPtr[i];
195  if (viewId == filterId){
196  return true;
197  }
198  }
199 
200  return false;
201  }
202 
203  return true;
204 }
205 
206 
207 template <class Base>
209 {
210  return m_shapesMap;
211 }
212 
213 
214 template <class Base>
216 {
217  for (ShapesMap::iterator index = m_shapesMap.begin(); index != m_shapesMap.end(); ++index){
218  IViewProvider* viewProvderPtr = index.key();
219  Q_ASSERT(viewProvderPtr != NULL);
220 
221  iview::IShapeView* viewPtr = viewProvderPtr->GetView();
222  Q_ASSERT(viewPtr != NULL);
223 
224  viewPtr->Update();
225  }
226 }
227 
228 
229 } // namespace iqt2d
230 
231 
232 #endif // !iqt2d_TSceneExtenderCompBase_included
233 
234 
Interface for GUI objects presenting its results using extern view objects.
Definition: IViewExtender.h:19
Pointer * GetAt(int index) const
Get pointer at specified index.
virtual void AddItemsToScene(IViewProvider *providerPtr, int flags)
Called when items should be added to specified scene.
istd::TPointerVector< iview::IShape > Shapes
Common interface for a general shape view implementations.
Definition: IShapeView.h:24
virtual void Update()=0
Updates all invalidates shapes.
virtual bool AssignToLayer(int layerType)
Assign this shape to same layer.
virtual void CreateShapes(int viewId, Shapes &result)=0
Create shapes for the view.
virtual int GetViewId() const =0
Get ID indentifing this view.
virtual bool DisconnectShape(IShape *shapePtr)=0
Disconnect shape object from view.
const ShapesMap & GetShapesMap() const
virtual bool ConnectShape(IShape *shapePtr)=0
Connect shape object to view.
int GetCount() const
Get number of stored elements.
Common interface for all display console shapes.
Definition: IShape.h:27
Implementation of a pointer container, which controls the live cycle of the pointer object...
virtual iview::IShapeView * GetView() const =0
Called when items should be removed from specified view.
#define NULL
Definition: istd.h:64
bool IsViewIdSupported(int viewId) const
void UpdateAllViews()
It calls Update for all used views.
Interface for GUI objects managing view.
Definition: IViewProvider.h:24
QMap< IViewProvider *, Shapes > ShapesMap
virtual void RemoveItemsFromScene(IViewProvider *providerPtr)
Called when items should be removed from specified scene.
Layer with inactive shapes.
Definition: IViewLayer.h:44
virtual int GetLayerType() const =0
Get layer type of this shape object.

© 2007-2017 Witold Gantzke and Kirill Lepskiy