1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
22 //-Design Declaration of variables specific to managers
24 //-Warning Manager manages a set of structures
33 #include <Graphic3d_StructureManager.ixx>
34 #include <Graphic3d_StructureManager.pxx>
35 static Standard_Boolean Initialisation = Standard_True;
36 static int StructureManager_ArrayId[StructureManager_MAX];
37 static Standard_Integer StructureManager_CurrentId = 0;
39 #include <Graphic3d_Structure.pxx>
40 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
44 //-Global data definitions
46 // -- l'identifieur du manager
47 // MyId : Standard_Integer;
49 // -- le mode de mise a jour de l'affichage
50 // MyUpdateMode : TypeOfUpdate;
52 // -- les differents contextes de primitives
53 // MyAspectLine3d : AspectLine3d;
54 // MyAspectText3d : AspectText3d;
55 // MyAspectMarker3d : AspectMarker3d;
56 // MyAspectFillArea3d : AspectFillArea3d;
58 // -- les structures affichees
59 // MyDisplayedStructure : SequenceOfStructure;
61 // -- les structures mises en evidence
62 // MyHighlightedStructure : SequenceOfStructure;
64 // -- les structures detectables
65 // MyPickStructure : SequenceOfStructure;
67 // -- le generateur d'identificateurs de structures
68 // MyStructGenId : GenId;
72 Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver):
73 MyDisplayedStructure (),
74 MyHighlightedStructure (),
79 Standard_Boolean NotFound = Standard_True;
80 Standard_Integer Limit = Graphic3d_StructureManager::Limit ();
82 /* Initialize PHIGS and start up */
85 Initialisation = Standard_False;
86 /* table to manage IDs of StructureManager */
87 for (i=0; i<Limit; i++) StructureManager_ArrayId[i] = 0;
89 StructureManager_CurrentId = 0;
90 StructureManager_ArrayId[0] = 1;
94 for (i=0; i<Limit && NotFound; i++)
95 if (StructureManager_ArrayId[i] == 0) {
96 NotFound = Standard_False;
97 StructureManager_CurrentId = i;
98 StructureManager_ArrayId[i] = 1;
103 Standard_SStream anErrorDescription;
104 anErrorDescription<<"You are trying to create too many ViewManagers at the same time!\n"<<
105 "The number of simultaneously created ViewManagers can't exceed "<<Limit<<".\n";
106 Graphic3d_InitialisationError::Raise(anErrorDescription);
110 Coef = (Structure_IDMIN+Structure_IDMAX)/Limit;
111 Aspect_GenId theGenId(
112 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId)),
113 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId+1)-1));
114 MyStructGenId = theGenId;
116 MyId = StructureManager_CurrentId;
118 MyAspectLine3d = new Graphic3d_AspectLine3d ();
119 MyAspectText3d = new Graphic3d_AspectText3d ();
120 MyAspectMarker3d = new Graphic3d_AspectMarker3d ();
121 MyAspectFillArea3d = new Graphic3d_AspectFillArea3d ();
123 MyUpdateMode = Aspect_TOU_WAIT;
124 MyGraphicDriver = theDriver;
130 void Graphic3d_StructureManager::Destroy () {
133 cout << "Graphic3d_StructureManager::Destroy (" << MyId << ")\n";
137 MyDisplayedStructure.Clear ();
138 MyHighlightedStructure.Clear ();
139 MyPickStructure.Clear ();
140 StructureManager_ArrayId[MyId] = 0;
146 void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) {
148 MyUpdateMode = AType;
152 Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const {
154 return (MyUpdateMode);
158 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
160 MyAspectLine3d = CTX;
164 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
166 MyAspectFillArea3d = CTX;
170 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
172 MyAspectText3d = CTX;
176 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
178 MyAspectMarker3d = CTX;
182 void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {
184 CTXL = MyAspectLine3d;
185 CTXT = MyAspectText3d;
186 CTXM = MyAspectMarker3d;
187 CTXF = MyAspectFillArea3d;
191 Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
193 return (MyAspectLine3d);
197 Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
199 return (MyAspectText3d);
203 Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
205 return (MyAspectMarker3d);
209 Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
211 return (MyAspectFillArea3d);
215 void Graphic3d_StructureManager::Remove (const Standard_Integer AnId) {
218 cout << "Graphic3d_StructureManager::Remove " << AnId << "\n" << flush;
221 MyStructGenId.Free (AnId);
225 void Graphic3d_StructureManager::Detectable (const Handle(Graphic3d_Structure)& AStructure) {
227 MyPickStructure.Add(AStructure);
231 void Graphic3d_StructureManager::Undetectable (const Handle(Graphic3d_Structure)& AStructure) {
233 MyPickStructure.Remove(AStructure);
237 void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
239 SG.Assign(MyDisplayedStructure);
241 //JMBStandard_Integer Length = MyDisplayedStructure.Length ();
243 //JMBfor (Standard_Integer i=1; i<=Length; i++)
244 //JMB SG.Add (MyDisplayedStructure.Value (i));
248 Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
250 Standard_Integer Length = MyDisplayedStructure.Extent ();
256 //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
258 //return (MyDisplayedStructure.Value (AnIndex));
262 void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
264 SG.Assign(MyHighlightedStructure);
268 void Graphic3d_StructureManager::PickStructures (Graphic3d_MapOfStructure& SG) const {
270 SG.Assign(MyPickStructure);
274 void Graphic3d_StructureManager::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
276 Standard_Boolean Flag = Standard_True;
277 Standard_Real Xm, Ym, Zm, XM, YM, ZM, RL, RF;
282 XMin = YMin = ZMin = RL;
283 XMax = YMax = ZMax = RF;
285 Graphic3d_MapIteratorOfMapOfStructure it(MyDisplayedStructure);
286 for (; it.More(); it.Next()) {
287 Handle(Graphic3d_Structure) SG = it.Key();
288 if (! (SG->IsEmpty() || SG->IsInfinite ())) {
289 SG->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
290 if (Xm < XMin) XMin = Xm;
291 if (Ym < YMin) YMin = Ym;
292 if (Zm < ZMin) ZMin = Zm;
293 if (XM > XMax) XMax = XM;
294 if (YM > YMax) YMax = YM;
295 if (ZM > ZMax) ZMax = ZM;
296 Flag = Standard_False;
300 // If all structures are empty or infinite
302 XMin = YMin = ZMin = RF;
303 XMax = YMax = ZMax = RL;
308 Standard_Integer Graphic3d_StructureManager::NewIdentification () {
310 Standard_Integer Id = MyStructGenId.Next ();
313 cout << "Graphic3d_StructureManager::NewIdentification " << Id << "\n";
321 Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
323 // Standard_Integer ind=0;
324 Standard_Boolean notfound = Standard_True;
326 Handle(Graphic3d_Structure) StructNull;
328 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
330 Handle(Graphic3d_Structure) SGfound;
332 for (; it.More() && notfound; it.Next()) {
333 Handle(Graphic3d_Structure) SG = it.Key();
334 if ( SG->Identification () == AId) {
335 notfound = Standard_False;
348 Standard_Integer Graphic3d_StructureManager::Identification () const {
354 Standard_Integer Graphic3d_StructureManager::Limit () {
356 return (StructureManager_MAX);
360 Standard_Integer Graphic3d_StructureManager::CurrentId () {
362 return (StructureManager_CurrentId);
366 const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const {
368 return (MyGraphicDriver);
372 void Graphic3d_StructureManager::RecomputeStructures()
374 // Go through all unique structures including child (connected) ones and ensure that they are computed.
375 Graphic3d_MapOfStructure aStructNetwork;
377 for (Graphic3d_MapIteratorOfMapOfStructure anIter(MyDisplayedStructure); anIter.More(); anIter.Next())
379 Handle(Graphic3d_Structure) aStructure = anIter.Key();
380 anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork);
383 RecomputeStructures (aStructNetwork);
386 void Graphic3d_StructureManager::RecomputeStructures (const Graphic3d_MapOfStructure& theStructures)
388 for (Graphic3d_MapIteratorOfMapOfStructure anIter (theStructures); anIter.More(); anIter.Next())
390 Handle(Graphic3d_Structure) aStruct = anIter.Key();