1 // File: OpenGl_PriorityList.cxx
2 // Created: 2 November 2011
3 // Author: Sergey ZERCHANINOV
4 // Copyright: OPEN CASCADE 2011
6 #include <OpenGl_PriorityList.hxx>
8 #include <OpenGl_Structure.hxx>
10 /*----------------------------------------------------------------------*/
12 void OpenGl_PriorityList::Add (const OpenGl_Structure *AStructure,const Standard_Integer APriority)
14 Standard_Integer anIndex = APriority;
15 if (anIndex < 0) anIndex = 0;
16 else if (anIndex >= myArray.Length()) anIndex = myArray.Length()-1;
17 myArray(anIndex).Append(AStructure);
21 /*----------------------------------------------------------------------*/
23 Standard_Integer OpenGl_PriorityList::Remove (const OpenGl_Structure *AStructure)
25 const Standard_Integer aNbPr = myArray.Length();
26 Standard_Integer i = 0;
27 OpenGl_SequenceOfStructure::Iterator its;
28 for (; i < aNbPr; i++)
30 OpenGl_SequenceOfStructure &aSeq = myArray(i);
31 for (its.Init(aSeq); its.More(); its.Next())
33 if (its.Value() == AStructure)
45 /*----------------------------------------------------------------------*/
47 void OpenGl_PriorityList::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
49 const Standard_Integer aNbPr = myArray.Length();
50 Standard_Integer i = 0;
51 OpenGl_SequenceOfStructure::Iterator its;
52 for (; i < aNbPr; i++)
54 for (its.Init(myArray(i)); its.More(); its.Next())
55 its.Value()->Render(AWorkspace);
59 //=======================================================================
62 //=======================================================================
64 Standard_Boolean OpenGl_PriorityList::Append (const OpenGl_PriorityList& theOther)
66 // the source priority list shouldn't have more priorities
67 const Standard_Integer aNbPriorities = theOther.NbPriorities ();
68 if (aNbPriorities > NbPriorities ())
69 return Standard_False;
71 // add all structures to destination priority list
72 Standard_Integer aIdx = 0;
73 OpenGl_SequenceOfStructure::Iterator anIts;
74 for (; aIdx < aNbPriorities; aIdx++)
76 const OpenGl_SequenceOfStructure& aSeq = theOther.myArray (aIdx);
77 for (anIts.Init (aSeq); anIts.More (); anIts.Next ())
78 Add (anIts.Value (), aIdx);
84 //=======================================================================
85 //function : NbPriorities
87 //=======================================================================
89 Standard_Integer OpenGl_PriorityList::NbPriorities() const
91 return myArray.Length();