0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / Graphic3d / Graphic3d_StructureManager.hxx
1 // Created on: 1991-09-05
2 // Created by: NW,JPB,CAL
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _Graphic3d_StructureManager_HeaderFile
18 #define _Graphic3d_StructureManager_HeaderFile
19
20 #include <Aspect_GenId.hxx>
21 #include <Aspect_TypeOfHighlightMethod.hxx>
22 #include <Graphic3d_CView.hxx>
23 #include <Graphic3d_MapOfObject.hxx>
24 #include <Graphic3d_MapOfStructure.hxx>
25 #include <Graphic3d_ViewAffinity.hxx>
26 #include <Graphic3d_ZLayerId.hxx>
27 #include <Graphic3d_ZLayerSettings.hxx>
28 #include <Standard_Transient.hxx>
29 #include <NCollection_IndexedMap.hxx>
30 #include <Standard.hxx>
31 #include <Standard_Boolean.hxx>
32 #include <Standard_Integer.hxx>
33 #include <Standard_Type.hxx>
34 #include <TColStd_Array2OfReal.hxx>
35
36 typedef NCollection_IndexedMap<Graphic3d_CView*> Graphic3d_IndexedMapOfView;
37
38 class Graphic3d_GraphicDriver;
39 class Graphic3d_Structure;
40 class Graphic3d_DataStructureManager;
41
42 //! This class allows the definition of a manager to
43 //! which the graphic objects are associated.
44 //! It allows them to be globally manipulated.
45 //! It defines the global attributes.
46 //! Keywords: Structure, Structure Manager, Update Mode,
47 //! Destroy, Highlight, Visible
48 class Graphic3d_StructureManager : public Standard_Transient
49 {
50   friend class Graphic3d_Structure;
51   DEFINE_STANDARD_RTTIEXT(Graphic3d_StructureManager, Standard_Transient)
52 public:
53
54   //! Initializes the ViewManager.
55   //! Currently creating of more than 100 viewer instances
56   //! is not supported and leads to InitializationError and
57   //! initialization failure.
58   //! This limitation might be addressed in some future OCCT releases.
59   //! Warning: Raises InitialisationError if the initialization
60   //! of the ViewManager failed.
61   Standard_EXPORT Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver);
62
63   //! Deletes the manager <me>.
64   Standard_EXPORT ~Graphic3d_StructureManager();
65
66   //! Invalidates bounding box of specified ZLayerId.
67   Standard_EXPORT virtual void Update (const Graphic3d_ZLayerId  theLayerId = Graphic3d_ZLayerId_UNKNOWN) const;
68
69   //! Deletes and erases the 3D structure manager.
70   Standard_EXPORT virtual void Remove();
71
72   //! Erases all the structures.
73   Standard_EXPORT virtual void Erase();
74
75   //! Returns the set of structures displayed in
76   //! visualiser <me>.
77   Standard_EXPORT void DisplayedStructures (Graphic3d_MapOfStructure& SG) const;
78
79   //! Returns the set of highlighted structures
80   //! in a visualiser <me>.
81   Standard_EXPORT void HighlightedStructures (Graphic3d_MapOfStructure& SG) const;
82
83   //! Forces a new construction of the structure.
84   //! if <theStructure> is displayed and TOS_COMPUTED.
85   Standard_EXPORT virtual void ReCompute (const Handle(Graphic3d_Structure)& theStructure);
86
87   //! Forces a new construction of the structure.
88   //! if <theStructure> is displayed in <theProjector> and TOS_COMPUTED.
89   Standard_EXPORT virtual void ReCompute (const Handle(Graphic3d_Structure)& theStructure, const Handle(Graphic3d_DataStructureManager)& theProjector);
90
91   //! Clears the structure.
92   Standard_EXPORT virtual void Clear (Graphic3d_Structure* theStructure, const Standard_Boolean theWithDestruction);
93
94   //! Connects the structures.
95   Standard_EXPORT virtual void Connect (const Graphic3d_Structure* theMother,
96                                         const Graphic3d_Structure* theDaughter);
97
98   //! Disconnects the structures.
99   Standard_EXPORT virtual void Disconnect (const Graphic3d_Structure* theMother,
100                                            const Graphic3d_Structure* theDaughter);
101
102   //! Display the structure.
103   Standard_EXPORT virtual void Display (const Handle(Graphic3d_Structure)& theStructure);
104
105   //! Erases the structure.
106   Standard_EXPORT virtual void Erase (const Handle(Graphic3d_Structure)& theStructure);
107
108   //! Highlights the structure.
109   Standard_EXPORT virtual void Highlight (const Handle(Graphic3d_Structure)& theStructure);
110
111   //! Transforms the structure.
112   Standard_EXPORT virtual void SetTransform (const Handle(Graphic3d_Structure)& theStructure, const Handle(TopLoc_Datum3D)& theTrsf);
113
114   //! Changes the display priority of the structure <AStructure>.
115   Standard_EXPORT virtual void ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure, const Standard_Integer theOldPriority, const Standard_Integer theNewPriority);
116
117   //! Change Z layer for structure. The Z layer mechanism allows to display structures in higher
118   //! layers in overlay of structures in lower layers.
119   Standard_EXPORT virtual void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, const Graphic3d_ZLayerId theLayerId);
120
121   //! Returns the graphic driver of <me>.
122   Standard_EXPORT const Handle(Graphic3d_GraphicDriver)& GraphicDriver() const;
123
124   //! Attaches the view to this structure manager and sets its identification number within the manager.
125   Standard_EXPORT Standard_Integer Identification (Graphic3d_CView* theView);
126
127   //! Detach the view from this structure manager and release its identification.
128   Standard_EXPORT void UnIdentification (Graphic3d_CView* theView);
129
130   //! Returns the group of views defined in the structure manager.
131   Standard_EXPORT const Graphic3d_IndexedMapOfView& DefinedViews() const;
132
133   //! Returns the theoretical maximum number of definable views in the manager.
134   //! Warning: It's not possible to accept an infinite number of definable views because each
135   //! view must have an identification and we have different managers.
136   Standard_EXPORT Standard_Integer MaxNumOfViews() const;
137
138   //! Returns the structure with the identification number <AId>.
139   Standard_EXPORT virtual Handle(Graphic3d_Structure) Identification (const Standard_Integer AId) const;
140
141   //! Suppress the highlighting on the structure <AStructure>.
142   Standard_EXPORT virtual void UnHighlight (const Handle(Graphic3d_Structure)& AStructure);
143
144   //! Suppresses the highlighting on all the structures in <me>.
145   Standard_EXPORT virtual void UnHighlight();
146
147   //! Recomputes all structures in the manager.
148   //! Resets Device Lost flag.
149   Standard_EXPORT void RecomputeStructures();
150
151   //! Recomputes all structures from theStructures.
152   Standard_EXPORT void RecomputeStructures (const NCollection_Map<Graphic3d_Structure*>& theStructures);
153
154   Standard_EXPORT Handle(Graphic3d_ViewAffinity) RegisterObject (const Handle(Standard_Transient)& theObject);
155
156   Standard_EXPORT void UnregisterObject (const Handle(Standard_Transient)& theObject);
157
158   Standard_EXPORT Handle(Graphic3d_ViewAffinity) ObjectAffinity (const Handle(Standard_Transient)& theObject) const;
159
160   //! Returns TRUE if Device Lost flag has been set and presentation data should be reuploaded onto graphics driver.
161   Standard_Boolean IsDeviceLost() const { return myDeviceLostFlag; }
162
163   //! Sets Device Lost flag.
164   void SetDeviceLost() { myDeviceLostFlag = Standard_True; }
165
166 protected:
167
168   //! Returns the number of structures displayed in
169   //! visualizer <me>.
170   //! Returns the structure displayed in visualizer <me>.
171   Standard_EXPORT Standard_Integer NumberOfDisplayedStructures() const;
172
173 protected:
174
175   Aspect_GenId myViewGenId;
176   Graphic3d_MapOfStructure myDisplayedStructure;
177   Graphic3d_MapOfStructure myHighlightedStructure;
178   Graphic3d_MapOfObject myRegisteredObjects;
179   Handle(Graphic3d_GraphicDriver) myGraphicDriver;
180   Graphic3d_IndexedMapOfView myDefinedViews;
181   Standard_Boolean myDeviceLostFlag;
182 };
183
184 DEFINE_STANDARD_HANDLE(Graphic3d_StructureManager, Standard_Transient)
185
186 #endif // _Graphic3d_StructureManager_HeaderFile