SHAPER  9.12.0
XGUI_Displayer.h
1 // Copyright (C) 2014-2023 CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef XGUI_Displayer_H
21 #define XGUI_Displayer_H
22 
23 #include "XGUI.h"
24 
25 #include <GeomAPI_AISObject.h>
26 #include <GeomAPI_Pln.h>
27 
28 #include <ModelAPI_Result.h>
29 
30 #include <ModuleBase_Definitions.h>
31 
32 #include <AIS_InteractiveObject.hxx>
33 #include <AIS_InteractiveContext.hxx>
34 #include <NCollection_Map.hxx>
35 #include <NCollection_DataMap.hxx>
36 #include <SelectMgr_AndFilter.hxx>
37 #include <TopoDS_Shape.hxx>
38 
39 #include <QColor>
40 #include <QMap>
41 #include <QObject>
42 #include <QString>
43 
45 class ModelAPI_Feature;
47 class XGUI_Workshop;
48 
49 #define OPTIMIZE_PRS
50 
51 #ifdef TINSPECTOR
52 class VInspectorAPI_CallBack;
53 #endif
54 
55 
56 #ifdef OPTIMIZE_PRS
58 {
59 public:
61 
65  bool add(const ObjectPtr& theObj, const AISObjectPtr& theAIS)
66  {
67  if (myResultToAISMap.contains(theObj))
68  return false;
69  Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
70  myResultToAISMap[theObj] = anAIS;
71  myAIStoResultMap[anAIS] = theObj;
72  return true;
73  }
74 
77  bool remove(const ObjectPtr& theObj)
78  {
79  if (!myResultToAISMap.contains(theObj))
80  return false;
81  Handle(AIS_InteractiveObject) aAIS = myResultToAISMap[theObj];
82  myResultToAISMap.remove(theObj);
83  myAIStoResultMap.remove(aAIS);
84  return true;
85  }
86 
89  bool remove(const AISObjectPtr& theAIS)
90  {
91  Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
92  if (!myAIStoResultMap.contains(anAIS))
93  return false;
94  ObjectPtr aObj = myAIStoResultMap[anAIS];
95  myResultToAISMap.remove(aObj);
96  myAIStoResultMap.remove(anAIS);
97  return true;
98  }
99 
101  void clear()
102  {
103  myResultToAISMap.clear();
104  myAIStoResultMap.clear();
105  }
106 
109  AISObjectPtr value(const ObjectPtr& theObj) const
110  {
111  if (myResultToAISMap.contains(theObj)) {
112  Handle(AIS_InteractiveObject) anAIS = myResultToAISMap[theObj];
113  AISObjectPtr anAISObj = AISObjectPtr(new GeomAPI_AISObject());
114  anAISObj->setImpl(new Handle(AIS_InteractiveObject)(anAIS));
115  return anAISObj;
116  }
117  return AISObjectPtr();
118  }
119 
122  ObjectPtr value(const AISObjectPtr& theAIS) const
123  {
124  Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
125  if (myAIStoResultMap.contains(anAIS))
126  return myAIStoResultMap[anAIS];
127  return ObjectPtr();
128  }
129 
132  ObjectPtr value(const Handle(AIS_InteractiveObject)& theAIS) const
133  {
134  if (myAIStoResultMap.contains(theAIS))
135  return myAIStoResultMap[theAIS];
136  return ObjectPtr();
137  }
138 
140  int size() const { return myResultToAISMap.size(); }
141 
143  QObjectPtrList objects() const { return myResultToAISMap.keys(); }
144 
146  QList<Handle(AIS_InteractiveObject)> presentations() const { return myAIStoResultMap.keys(); }
147 
150  bool contains(const ObjectPtr& theObj) const { return myResultToAISMap.contains(theObj); }
151 
154  bool contains(const AISObjectPtr& theAIS) const
155  {
156  Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
157  return myAIStoResultMap.contains(anAIS);
158  }
159 
160 private:
161  QMap<ObjectPtr, Handle(AIS_InteractiveObject)> myResultToAISMap;
162  QMap<Handle(AIS_InteractiveObject), ObjectPtr> myAIStoResultMap;
163 };
164 #endif
165 
166 
171 class XGUI_EXPORT XGUI_Displayer : public QObject
172 {
173  Q_OBJECT
174 public:
176  enum DisplayMode {
177  NoMode = -1,
179  Shading
180  };
181 
184  XGUI_Displayer(XGUI_Workshop* theWorkshop);
185 
187  virtual ~XGUI_Displayer();
188 
191  bool isVisible(ObjectPtr theObject) const;
192 
197  bool display(ObjectPtr theObject, bool theUpdateViewer = true);
198 
209  bool displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
210  const Standard_Integer theDisplayMode = 0, bool theUpdateViewer = true);
211 
216  bool redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
217 
219  void redisplayObjects();
220 
226  void setSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
227  bool theUpdateViewer = true);
228 
232  void clearSelected(const bool theUpdateViewer = true);
233 
238  bool erase(ObjectPtr theObject, const bool theUpdateViewer = true);
239 
244  bool eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
245 
249  bool eraseAll(const bool theUpdateViewer = true);
250 
253  void deactivateSelectionFilters(const bool theAddFilterOnly = true);
254 
257  void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
258 
261  void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
262 
265  virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
266 
268  void removeFilters();
269 
276  bool enableUpdateViewer(const bool isEnabled);
277 
279  bool isUpdateEnabled() const
280  {
281  return myViewerBlockedRecursiveCount == 0;
282  }
283 
285  void updateViewer() const;
286 
290  AISObjectPtr getAISObject(ObjectPtr theObject) const;
291 
295  ObjectPtr getObject(const AISObjectPtr& theIO) const;
296 
300  ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
301 
305  void deactivateObjects(const QObjectPtrList& theObjList,
306  const bool theUpdateViewer = true);
307 
309  void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
310 
314  DisplayMode displayMode(ObjectPtr theObject) const;
315 
318  void showOnly(const QObjectPtrList& theList);
319 
321  int objectsCount() const { return myResult2AISObjectMap.size(); }
322 
324  QObjectPtrList displayedObjects() const {
325 #ifdef OPTIMIZE_PRS
326  return myResult2AISObjectMap.objects();
327 #else
328  return myResult2AISObjectMap.keys();
329 #endif
330  }
331 
333 #ifdef OPTIMIZE_PRS
335  {
336  return myResult2AISObjectMap.presentations();
337  }
338 #else
339  QList<AISObjectPtr> displayedPresentations() const
340  {
341  return myResult2AISObjectMap.values();
342  }
343 #endif
344 
347  bool canBeShaded(ObjectPtr theObject) const;
348 
354  QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
355 
358  void displayTrihedron(bool theToDisplay) const;
359 
360 #ifdef TINSPECTOR
361  void setCallBack(const Handle(VInspectorAPI_CallBack)& theCallBack)
362  { myVCallBack = theCallBack; }
363  Handle(VInspectorAPI_CallBack) getCallBack() const { return myVCallBack; }
364 #endif
365 
371  static bool isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject);
372 
373 
375  GeomPlanePtr getScreenPlane() const;
376 
378  double getViewScale() const;
379 
382  void setSelectionColor(const std::vector<int>& theColor);
383 
385  std::vector<int> selectionColor() const;
386 
387 signals:
391  void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
392 
396  void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
397 
398  protected:
400  Handle(AIS_InteractiveContext) AISContext() const;
401 
404  Handle(SelectMgr_AndFilter) GetFilter();
405 
412  bool display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
413  bool theUpdateViewer = true);
414 
415 private:
421  bool customizeObject(ObjectPtr theObject);
422 
426  void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
427 
428 #ifdef _DEBUG
431  std::string getResult2AISObjectMapInfo() const;
432 #endif
433 
438  void getPresentations(const ObjectPtr& theObject,
439  NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations);
440 
448  static void AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
449  const NCollection_DataMap<TopoDS_Shape,
450  NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected);
451 
452 private:
453  XGUI_SelectionActivate* selectionActivate() const;
454 
455 private:
456  XGUI_Workshop* myWorkshop;
457 #ifdef TINSPECTOR
458  Handle(VInspectorAPI_CallBack) myVCallBack;
459 #endif
460  Handle(SelectMgr_AndFilter) myAndFilter;
461 
463 #ifdef OPTIMIZE_PRS
464  XGUI_TwoSidePresentationMap myResult2AISObjectMap;
465 #else
466  typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
467  ResultToAISMap myResult2AISObjectMap;
468 #endif
469 
471  int myViewerBlockedRecursiveCount;
472 
473  mutable void* myContextId;
474  mutable bool myNeedUpdate;
475 };
476 
477 #endif
Interface for AIS_InteractiveObject.
Definition: GeomAPI_AISObject.h:39
Feature function that represents the particular functionality of this operation.
Definition: ModelAPI_Feature.h:39
Presentation.
Definition: ModuleBase_ViewerPrs.h:37
Displayer.
Definition: XGUI_Displayer.h:172
bool isUpdateEnabled() const
Returns true if the viewer update is not blocked.
Definition: XGUI_Displayer.h:279
QList< Handle > displayedPresentations() const
Returns list of displayed objects.
Definition: XGUI_Displayer.h:334
void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
Signal on before object erase.
int objectsCount() const
Returns number of displayed objects.
Definition: XGUI_Displayer.h:321
DisplayMode
display mode
Definition: XGUI_Displayer.h:176
@ Wireframe
Wireframe display mode.
Definition: XGUI_Displayer.h:178
void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
Signal on object display.
QObjectPtrList displayedObjects() const
Returns list of displayed objects.
Definition: XGUI_Displayer.h:324
A class which implements activation/deactivate selection modes and using selection filters.
Definition: XGUI_SelectionActivate.h:41
Definition: XGUI_Displayer.h:58
ObjectPtr value(const AISObjectPtr &theAIS) const
Returns object by presentation.
Definition: XGUI_Displayer.h:122
bool remove(const ObjectPtr &theObj)
Removes values by object.
Definition: XGUI_Displayer.h:77
QObjectPtrList objects() const
Returns list of objects.
Definition: XGUI_Displayer.h:143
AISObjectPtr value(const ObjectPtr &theObj) const
Returns presentation by object.
Definition: XGUI_Displayer.h:109
bool remove(const AISObjectPtr &theAIS)
Removes values by presentation.
Definition: XGUI_Displayer.h:89
bool add(const ObjectPtr &theObj, const AISObjectPtr &theAIS)
Add new values pair to the map.
Definition: XGUI_Displayer.h:65
int size() const
Returns number of values.
Definition: XGUI_Displayer.h:140
bool contains(const ObjectPtr &theObj) const
Returns true if the Map contains the object.
Definition: XGUI_Displayer.h:150
bool contains(const AISObjectPtr &theAIS) const
Returns true if the Map contains the presentation.
Definition: XGUI_Displayer.h:154
ObjectPtr value(const Handle &&theAIS) const
Returns object by presentation.
Definition: XGUI_Displayer.h:132
void clear()
Removes all values.
Definition: XGUI_Displayer.h:101
QList< Handle > presentations() const
returns list of presentations
Definition: XGUI_Displayer.h:146
Class which defines a configuration of the application (Workshop) and launches it.
Definition: XGUI_Workshop.h:82