SHAPER 9.16.0
XGUI_Displayer.h
1// Copyright (C) 2014-2026 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
47class XGUI_Workshop;
48
49#define OPTIMIZE_PRS
50
51#ifdef TINSPECTOR
52class VInspectorAPI_CallBack;
53#endif
54
55
56#ifdef OPTIMIZE_PRS
58{
59public:
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
160private:
161 QMap<ObjectPtr, Handle(AIS_InteractiveObject)> myResultToAISMap;
162 QMap<Handle(AIS_InteractiveObject), ObjectPtr> myAIStoResultMap;
163};
164#endif
165
166
171class XGUI_EXPORT XGUI_Displayer : public QObject
172{
173 Q_OBJECT
174public:
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
222 bool displayAIS(Handle(AIS_InteractiveObject) theAISIO, const bool toActivateInSelectionModes,
223 const Standard_Integer theDisplayMode = 0, bool theUpdateViewer = true);
224
229 bool redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
230
232 void redisplayObjects();
233
239 void setSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
240 bool theUpdateViewer = true);
241
245 void clearSelected(const bool theUpdateViewer = true);
246
251 bool erase(ObjectPtr theObject, const bool theUpdateViewer = true);
252
257 bool eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
258
262 bool eraseAIS(Handle(AIS_InteractiveObject) theAISIO, const bool theUpdateViewer = true);
263
267 bool eraseAll(const bool theUpdateViewer = true);
268
271 void deactivateSelectionFilters(const bool theAddFilterOnly = true);
272
275 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
276
279 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
280
283 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
284
286 void removeFilters();
287
294 bool enableUpdateViewer(const bool isEnabled);
295
297 bool isUpdateEnabled() const
298 {
299 return myViewerBlockedRecursiveCount == 0;
300 }
301
303 void updateViewer() const;
304
308 AISObjectPtr getAISObject(ObjectPtr theObject) const;
309
313 ObjectPtr getObject(const AISObjectPtr& theIO) const;
314
318 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
319
323 void deactivateObjects(const QObjectPtrList& theObjList,
324 const bool theUpdateViewer = true);
325
327 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
328
332 DisplayMode displayMode(ObjectPtr theObject) const;
333
336 void showOnly(const QObjectPtrList& theList);
337
339 int objectsCount() const { return myResult2AISObjectMap.size(); }
340
342 QObjectPtrList displayedObjects() const {
343#ifdef OPTIMIZE_PRS
344 return myResult2AISObjectMap.objects();
345#else
346 return myResult2AISObjectMap.keys();
347#endif
348 }
349
351#ifdef OPTIMIZE_PRS
353 {
354 return myResult2AISObjectMap.presentations();
355 }
356#else
357 QList<AISObjectPtr> displayedPresentations() const
358 {
359 return myResult2AISObjectMap.values();
360 }
361#endif
362
365 bool canBeShaded(ObjectPtr theObject) const;
366
372 QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
373
376 void displayTrihedron(bool theToDisplay) const;
377
378#ifdef TINSPECTOR
379 void setCallBack(const Handle(VInspectorAPI_CallBack)& theCallBack)
380 { myVCallBack = theCallBack; }
381 Handle(VInspectorAPI_CallBack) getCallBack() const { return myVCallBack; }
382#endif
383
389 static bool isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject);
390
391
393 GeomPlanePtr getScreenPlane() const;
394
396 double getViewScale() const;
397
400 void setSelectionColor(const std::vector<int>& theColor);
401
403 std::vector<int> selectionColor() const;
404
405signals:
409 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
410
414 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
415
416 protected:
418 Handle(AIS_InteractiveContext) AISContext() const;
419
422 Handle(SelectMgr_AndFilter) GetFilter();
423
430 bool display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
431 bool theUpdateViewer = true);
432
433private:
439 bool customizeObject(ObjectPtr theObject);
440
444 void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
445
446#ifdef _DEBUG
449 std::string getResult2AISObjectMapInfo() const;
450#endif
451
456 void getPresentations(const ObjectPtr& theObject,
457 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations);
458
466 static void AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
467 const NCollection_DataMap<TopoDS_Shape,
468 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected);
469
470private:
471 XGUI_SelectionActivate* selectionActivate() const;
472
473private:
474 XGUI_Workshop* myWorkshop;
475#ifdef TINSPECTOR
476 Handle(VInspectorAPI_CallBack) myVCallBack;
477#endif
478 Handle(SelectMgr_AndFilter) myAndFilter;
479
481#ifdef OPTIMIZE_PRS
482 XGUI_TwoSidePresentationMap myResult2AISObjectMap;
483#else
484 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
485 ResultToAISMap myResult2AISObjectMap;
486#endif
487
489 int myViewerBlockedRecursiveCount;
490
491 mutable void* myContextId;
492 mutable bool myNeedUpdate;
493};
494
495#endif
Interface for AIS_InteractiveObject.
Definition: GeomAPI_AISObject.h:39
Feature function that represents the particular functionality of this operation.
Definition: ModelAPI_Feature.h:41
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:297
void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
Signal on before object erase.
int objectsCount() const
Returns number of displayed objects.
Definition: XGUI_Displayer.h:339
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:342
QList< Handle > displayedPresentations() const
Returns list of displayed objects.
Definition: XGUI_Displayer.h:352
A class which implements activation/deactivate selection modes and using selection filters.
Definition: XGUI_SelectionActivate.h:41
Definition: XGUI_Displayer.h:58
QList< Handle > presentations() const
returns list of presentations
Definition: XGUI_Displayer.h:146
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
ObjectPtr value(const Handle &theAIS) const
Returns object by presentation.
Definition: XGUI_Displayer.h:132
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
void clear()
Removes all values.
Definition: XGUI_Displayer.h:101
Class which defines a configuration of the application (Workshop) and launches it.
Definition: XGUI_Workshop.h:83