1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
27 //-Design Declaration of variables specific to managers
29 //-Warning Manager manages a set of structures
38 #include <Graphic3d_StructureManager.ixx>
39 #include <Graphic3d_StructureManager.pxx>
40 static Standard_Boolean Initialisation = Standard_True;
41 static int StructureManager_ArrayId[StructureManager_MAX];
42 static Standard_Integer StructureManager_CurrentId = 0;
44 #include <Graphic3d_Structure.pxx>
45 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
49 //-Global data definitions
51 // -- l'identifieur du manager
52 // MyId : Standard_Integer;
54 // -- le mode de mise a jour de l'affichage
55 // MyUpdateMode : TypeOfUpdate;
57 // -- les differents contextes de primitives
58 // MyAspectLine3d : AspectLine3d;
59 // MyAspectText3d : AspectText3d;
60 // MyAspectMarker3d : AspectMarker3d;
61 // MyAspectFillArea3d : AspectFillArea3d;
63 // -- les structures affichees
64 // MyDisplayedStructure : SequenceOfStructure;
66 // -- les structures mises en evidence
67 // MyHighlightedStructure : SequenceOfStructure;
69 // -- les structures visibles
70 // MyVisibleStructure : SequenceOfStructure;
72 // -- les structures detectables
73 // MyPickStructure : SequenceOfStructure;
75 // -- le generateur d'identificateurs de structures
76 // MyStructGenId : GenId;
80 Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Aspect_GraphicDevice)& aDevice):
81 MyDisplayedStructure (),
82 MyHighlightedStructure (),
83 MyVisibleStructure (),
88 Standard_Boolean NotFound = Standard_True;
89 Standard_Integer Limit = Graphic3d_StructureManager::Limit ();
91 /* Initialize PHIGS and start up */
94 Initialisation = Standard_False;
95 /* table to manage IDs of StructureManager */
96 for (i=0; i<Limit; i++) StructureManager_ArrayId[i] = 0;
98 StructureManager_CurrentId = 0;
99 StructureManager_ArrayId[0] = 1;
103 for (i=0; i<Limit && NotFound; i++)
104 if (StructureManager_ArrayId[i] == 0) {
105 NotFound = Standard_False;
106 StructureManager_CurrentId = i;
107 StructureManager_ArrayId[i] = 1;
112 Standard_SStream anErrorDescription;
113 anErrorDescription<<"You are trying to create too many ViewManagers at the same time!\n"<<
114 "The number of simultaneously created ViewManagers can't exceed "<<Limit<<".\n";
115 Graphic3d_InitialisationError::Raise(anErrorDescription);
119 Coef = (Structure_IDMIN+Structure_IDMAX)/Limit;
120 Aspect_GenId theGenId(
121 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId)),
122 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId+1)-1));
123 MyStructGenId = theGenId;
125 MyId = StructureManager_CurrentId;
127 MyAspectLine3d = new Graphic3d_AspectLine3d ();
128 MyAspectText3d = new Graphic3d_AspectText3d ();
129 MyAspectMarker3d = new Graphic3d_AspectMarker3d ();
130 MyAspectFillArea3d = new Graphic3d_AspectFillArea3d ();
132 MyUpdateMode = Aspect_TOU_WAIT;
133 MyGraphicDevice = aDevice;
139 void Graphic3d_StructureManager::Destroy () {
142 cout << "Graphic3d_StructureManager::Destroy (" << MyId << ")\n";
146 MyDisplayedStructure.Clear ();
147 MyHighlightedStructure.Clear ();
148 MyVisibleStructure.Clear ();
149 MyPickStructure.Clear ();
150 StructureManager_ArrayId[MyId] = 0;
156 void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) {
158 MyUpdateMode = AType;
162 Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const {
164 return (MyUpdateMode);
168 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
170 MyAspectLine3d = CTX;
174 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
176 MyAspectFillArea3d = CTX;
180 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
182 MyAspectText3d = CTX;
186 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
188 MyAspectMarker3d = CTX;
192 void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {
194 CTXL = MyAspectLine3d;
195 CTXT = MyAspectText3d;
196 CTXM = MyAspectMarker3d;
197 CTXF = MyAspectFillArea3d;
201 Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
203 return (MyAspectLine3d);
207 Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
209 return (MyAspectText3d);
213 Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
215 return (MyAspectMarker3d);
219 Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
221 return (MyAspectFillArea3d);
225 void Graphic3d_StructureManager::Remove (const Standard_Integer AnId) {
228 cout << "Graphic3d_StructureManager::Remove " << AnId << "\n" << flush;
231 MyStructGenId.Free (AnId);
235 void Graphic3d_StructureManager::Visible (const Handle(Graphic3d_Structure)& AStructure) {
237 MyVisibleStructure.Add(AStructure);
241 void Graphic3d_StructureManager::Invisible (const Handle(Graphic3d_Structure)& AStructure) {
243 MyVisibleStructure.Remove(AStructure);
247 void Graphic3d_StructureManager::Detectable (const Handle(Graphic3d_Structure)& AStructure) {
249 MyPickStructure.Add(AStructure);
253 void Graphic3d_StructureManager::Undetectable (const Handle(Graphic3d_Structure)& AStructure) {
255 MyPickStructure.Remove(AStructure);
259 void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
261 SG.Assign(MyDisplayedStructure);
263 //JMBStandard_Integer Length = MyDisplayedStructure.Length ();
265 //JMBfor (Standard_Integer i=1; i<=Length; i++)
266 //JMB SG.Add (MyDisplayedStructure.Value (i));
270 Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
272 Standard_Integer Length = MyDisplayedStructure.Extent ();
278 //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
280 //return (MyDisplayedStructure.Value (AnIndex));
284 void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
286 SG.Assign(MyHighlightedStructure);
290 void Graphic3d_StructureManager::PickStructures (Graphic3d_MapOfStructure& SG) const {
292 SG.Assign(MyPickStructure);
296 void Graphic3d_StructureManager::VisibleStructures (Graphic3d_MapOfStructure& SG) const {
298 SG.Assign(MyVisibleStructure);
303 void Graphic3d_StructureManager::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
305 Standard_Boolean Flag = Standard_True;
306 Standard_Real Xm, Ym, Zm, XM, YM, ZM, RL, RF;
311 XMin = YMin = ZMin = RL;
312 XMax = YMax = ZMax = RF;
314 Graphic3d_MapIteratorOfMapOfStructure it(MyDisplayedStructure);
315 for (; it.More(); it.Next()) {
316 Handle(Graphic3d_Structure) SG = it.Key();
317 if (! (SG->IsEmpty() || SG->IsInfinite ())) {
318 SG->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
319 if (Xm < XMin) XMin = Xm;
320 if (Ym < YMin) YMin = Ym;
321 if (Zm < ZMin) ZMin = Zm;
322 if (XM > XMax) XMax = XM;
323 if (YM > YMax) YMax = YM;
324 if (ZM > ZMax) ZMax = ZM;
325 Flag = Standard_False;
329 // If all structures are empty or infinite
331 XMin = YMin = ZMin = RF;
332 XMax = YMax = ZMax = RL;
337 Standard_Integer Graphic3d_StructureManager::NewIdentification () {
339 Standard_Integer Id = MyStructGenId.Next ();
342 cout << "Graphic3d_StructureManager::NewIdentification " << Id << "\n";
350 Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
352 // Standard_Integer ind=0;
353 Standard_Boolean notfound = Standard_True;
355 Handle(Graphic3d_Structure) StructNull;
357 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
359 Handle(Graphic3d_Structure) SGfound;
361 for (; it.More() && notfound; it.Next()) {
362 Handle(Graphic3d_Structure) SG = it.Key();
363 if ( SG->Identification () == AId) {
364 notfound = Standard_False;
377 Standard_Integer Graphic3d_StructureManager::Identification () const {
383 Standard_Integer Graphic3d_StructureManager::Limit () {
385 return (StructureManager_MAX);
389 Standard_Integer Graphic3d_StructureManager::CurrentId () {
391 return (StructureManager_CurrentId);
395 Handle(Aspect_GraphicDevice) Graphic3d_StructureManager::GraphicDevice () const {
397 return (MyGraphicDevice);