4 // File Graphic3d_StructureManager.cxx
8 //-Copyright MatraDatavision 1991,1992
12 //-Design Declaration of variables specific to managers
14 //-Warning Manager manages a set of structures
23 #include <Graphic3d_StructureManager.ixx>
24 #include <Graphic3d_StructureManager.pxx>
25 static Standard_Boolean Initialisation = Standard_True;
26 static int StructureManager_ArrayId[StructureManager_MAX];
27 static Standard_Integer StructureManager_CurrentId = 0;
29 #include <Graphic3d_Structure.pxx>
30 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
34 //-Global data definitions
36 // -- l'identifieur du manager
37 // MyId : Standard_Integer;
39 // -- le mode de mise a jour de l'affichage
40 // MyUpdateMode : TypeOfUpdate;
42 // -- les differents contextes de primitives
43 // MyAspectLine3d : AspectLine3d;
44 // MyAspectText3d : AspectText3d;
45 // MyAspectMarker3d : AspectMarker3d;
46 // MyAspectFillArea3d : AspectFillArea3d;
48 // -- les structures affichees
49 // MyDisplayedStructure : SequenceOfStructure;
51 // -- les structures mises en evidence
52 // MyHighlightedStructure : SequenceOfStructure;
54 // -- les structures visibles
55 // MyVisibleStructure : SequenceOfStructure;
57 // -- les structures detectables
58 // MyPickStructure : SequenceOfStructure;
60 // -- le generateur d'identificateurs de structures
61 // MyStructGenId : GenId;
65 Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Aspect_GraphicDevice)& aDevice):
66 MyDisplayedStructure (),
67 MyHighlightedStructure (),
68 MyVisibleStructure (),
73 Standard_Boolean NotFound = Standard_True;
74 Standard_Integer Limit = Graphic3d_StructureManager::Limit ();
76 /* Initialize PHIGS and start up */
79 Initialisation = Standard_False;
80 /* table to manage IDs of StructureManager */
81 for (i=1; i<=Limit; i++) StructureManager_ArrayId[i] = 0;
83 StructureManager_CurrentId = 1;
84 StructureManager_ArrayId[1] = 1;
88 for (i=1; i<=Limit && NotFound; i++)
89 if (StructureManager_ArrayId[i] == 0) {
90 NotFound = Standard_False;
91 StructureManager_CurrentId = i;
92 StructureManager_ArrayId[i] = 1;
96 Graphic3d_InitialisationError::Raise
97 ("Too many ViewManagers are defined");
100 Coef = (Structure_IDMIN+Structure_IDMAX)/Limit;
101 Aspect_GenId theGenId(
102 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId-1)),
103 Standard_Integer (Structure_IDMIN+Coef*StructureManager_CurrentId-1));
104 MyStructGenId = theGenId;
106 MyId = StructureManager_CurrentId;
108 MyAspectLine3d = new Graphic3d_AspectLine3d ();
109 MyAspectText3d = new Graphic3d_AspectText3d ();
110 MyAspectMarker3d = new Graphic3d_AspectMarker3d ();
111 MyAspectFillArea3d = new Graphic3d_AspectFillArea3d ();
113 MyUpdateMode = Aspect_TOU_WAIT;
114 MyGraphicDevice = aDevice;
120 void Graphic3d_StructureManager::Destroy () {
123 cout << "Graphic3d_StructureManager::Destroy (" << MyId << ")\n";
127 MyDisplayedStructure.Clear ();
128 MyHighlightedStructure.Clear ();
129 MyVisibleStructure.Clear ();
130 MyPickStructure.Clear ();
131 StructureManager_ArrayId[MyId] = 0;
137 void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) {
139 MyUpdateMode = AType;
143 Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const {
145 return (MyUpdateMode);
149 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
151 MyAspectLine3d = CTX;
155 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
157 MyAspectFillArea3d = CTX;
161 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
163 MyAspectText3d = CTX;
167 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
169 MyAspectMarker3d = CTX;
173 void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {
175 CTXL = MyAspectLine3d;
176 CTXT = MyAspectText3d;
177 CTXM = MyAspectMarker3d;
178 CTXF = MyAspectFillArea3d;
182 Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
184 return (MyAspectLine3d);
188 Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
190 return (MyAspectText3d);
194 Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
196 return (MyAspectMarker3d);
200 Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
202 return (MyAspectFillArea3d);
206 void Graphic3d_StructureManager::Remove (const Standard_Integer AnId) {
209 cout << "Graphic3d_StructureManager::Remove " << AnId << "\n" << flush;
212 MyStructGenId.Free (AnId);
216 void Graphic3d_StructureManager::Visible (const Handle(Graphic3d_Structure)& AStructure) {
218 MyVisibleStructure.Add(AStructure);
222 void Graphic3d_StructureManager::Invisible (const Handle(Graphic3d_Structure)& AStructure) {
224 MyVisibleStructure.Remove(AStructure);
228 void Graphic3d_StructureManager::Detectable (const Handle(Graphic3d_Structure)& AStructure) {
230 MyPickStructure.Add(AStructure);
234 void Graphic3d_StructureManager::Undetectable (const Handle(Graphic3d_Structure)& AStructure) {
236 MyPickStructure.Remove(AStructure);
240 void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
242 SG.Assign(MyDisplayedStructure);
244 //JMBStandard_Integer Length = MyDisplayedStructure.Length ();
246 //JMBfor (Standard_Integer i=1; i<=Length; i++)
247 //JMB SG.Add (MyDisplayedStructure.Value (i));
251 Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
253 Standard_Integer Length = MyDisplayedStructure.Extent ();
259 //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
261 //return (MyDisplayedStructure.Value (AnIndex));
265 void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
267 SG.Assign(MyHighlightedStructure);
271 void Graphic3d_StructureManager::PickStructures (Graphic3d_MapOfStructure& SG) const {
273 SG.Assign(MyPickStructure);
277 void Graphic3d_StructureManager::VisibleStructures (Graphic3d_MapOfStructure& SG) const {
279 SG.Assign(MyVisibleStructure);
284 void Graphic3d_StructureManager::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
286 Standard_Boolean Flag = Standard_True;
287 Standard_Real Xm, Ym, Zm, XM, YM, ZM, RL, RF;
292 XMin = YMin = ZMin = RL;
293 XMax = YMax = ZMax = RF;
295 Graphic3d_MapIteratorOfMapOfStructure it(MyDisplayedStructure);
296 for (; it.More(); it.Next()) {
297 Handle(Graphic3d_Structure) SG = it.Key();
298 if (! (SG->IsEmpty() || SG->IsInfinite ())) {
299 SG->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
300 if (Xm < XMin) XMin = Xm;
301 if (Ym < YMin) YMin = Ym;
302 if (Zm < ZMin) ZMin = Zm;
303 if (XM > XMax) XMax = XM;
304 if (YM > YMax) YMax = YM;
305 if (ZM > ZMax) ZMax = ZM;
306 Flag = Standard_False;
310 // If all structures are empty or infinite
312 XMin = YMin = ZMin = RF;
313 XMax = YMax = ZMax = RL;
318 Standard_Integer Graphic3d_StructureManager::NewIdentification () {
320 Standard_Integer Id = MyStructGenId.Next ();
323 cout << "Graphic3d_StructureManager::NewIdentification " << Id << "\n";
331 Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
333 // Standard_Integer ind=0;
334 Standard_Boolean notfound = Standard_True;
336 Handle(Graphic3d_Structure) StructNull;
338 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
340 Handle(Graphic3d_Structure) SGfound;
342 for (; it.More() && notfound; it.Next()) {
343 Handle(Graphic3d_Structure) SG = it.Key();
344 if ( SG->Identification () == AId) {
345 notfound = Standard_False;
358 Standard_Integer Graphic3d_StructureManager::Identification () const {
364 Standard_Integer Graphic3d_StructureManager::Limit () {
366 return (StructureManager_MAX);
370 Standard_Integer Graphic3d_StructureManager::CurrentId () {
372 return (StructureManager_CurrentId);
376 Handle(Aspect_GraphicDevice) Graphic3d_StructureManager::GraphicDevice () const {
378 return (MyGraphicDevice);