Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-11-02 |
2 | // Created by: Sergey ZERCHANINOV | |
3 | // Copyright (c) 2011-2012 OPEN CASCADE SAS | |
4 | // | |
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. | |
9 | // | |
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. | |
12 | // | |
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. | |
19 | ||
2166f0fa SK |
20 | |
21 | #include <OpenGl_PriorityList.hxx> | |
22 | ||
23 | #include <OpenGl_Structure.hxx> | |
24 | ||
25 | /*----------------------------------------------------------------------*/ | |
26 | ||
27 | void OpenGl_PriorityList::Add (const OpenGl_Structure *AStructure,const Standard_Integer APriority) | |
28 | { | |
29 | Standard_Integer anIndex = APriority; | |
30 | if (anIndex < 0) anIndex = 0; | |
31 | else if (anIndex >= myArray.Length()) anIndex = myArray.Length()-1; | |
32 | myArray(anIndex).Append(AStructure); | |
33 | myNbStructures++; | |
34 | } | |
35 | ||
36 | /*----------------------------------------------------------------------*/ | |
37 | ||
59f45b7c | 38 | Standard_Integer OpenGl_PriorityList::Remove (const OpenGl_Structure *AStructure) |
2166f0fa SK |
39 | { |
40 | const Standard_Integer aNbPr = myArray.Length(); | |
41 | Standard_Integer i = 0; | |
42 | OpenGl_SequenceOfStructure::Iterator its; | |
43 | for (; i < aNbPr; i++) | |
44 | { | |
45 | OpenGl_SequenceOfStructure &aSeq = myArray(i); | |
46 | for (its.Init(aSeq); its.More(); its.Next()) | |
47 | { | |
48 | if (its.Value() == AStructure) | |
49 | { | |
50 | aSeq.Remove(its); | |
51 | myNbStructures--; | |
59f45b7c | 52 | return i; |
2166f0fa SK |
53 | } |
54 | } | |
55 | } | |
59f45b7c | 56 | |
57 | return -1; | |
2166f0fa SK |
58 | } |
59 | ||
60 | /*----------------------------------------------------------------------*/ | |
61 | ||
62 | void OpenGl_PriorityList::Render (const Handle(OpenGl_Workspace) &AWorkspace) const | |
63 | { | |
64 | const Standard_Integer aNbPr = myArray.Length(); | |
65 | Standard_Integer i = 0; | |
66 | OpenGl_SequenceOfStructure::Iterator its; | |
67 | for (; i < aNbPr; i++) | |
68 | { | |
69 | for (its.Init(myArray(i)); its.More(); its.Next()) | |
70 | its.Value()->Render(AWorkspace); | |
71 | } | |
72 | } | |
73 | ||
59f45b7c | 74 | //======================================================================= |
75 | //function : Append | |
76 | //purpose : | |
77 | //======================================================================= | |
78 | ||
79 | Standard_Boolean OpenGl_PriorityList::Append (const OpenGl_PriorityList& theOther) | |
80 | { | |
81 | // the source priority list shouldn't have more priorities | |
82 | const Standard_Integer aNbPriorities = theOther.NbPriorities (); | |
83 | if (aNbPriorities > NbPriorities ()) | |
84 | return Standard_False; | |
85 | ||
86 | // add all structures to destination priority list | |
87 | Standard_Integer aIdx = 0; | |
88 | OpenGl_SequenceOfStructure::Iterator anIts; | |
89 | for (; aIdx < aNbPriorities; aIdx++) | |
90 | { | |
91 | const OpenGl_SequenceOfStructure& aSeq = theOther.myArray (aIdx); | |
92 | for (anIts.Init (aSeq); anIts.More (); anIts.Next ()) | |
93 | Add (anIts.Value (), aIdx); | |
94 | } | |
95 | ||
96 | return Standard_True; | |
97 | } | |
98 | ||
99 | //======================================================================= | |
100 | //function : NbPriorities | |
101 | //purpose : | |
102 | //======================================================================= | |
103 | ||
104 | Standard_Integer OpenGl_PriorityList::NbPriorities() const | |
105 | { | |
106 | return myArray.Length(); | |
107 | } |