#include #pragma hdrstop #include "TPActiveList.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- __fastcall TPActiveList::TPActiveList(){ FCountX=0; FCountY=0; // nThreshold=4*FCountX; // nActiveArray = new int[FCountX*FCountY]; ActiveListQueue = new TList; /* for(int i=0;iCount){ temp = (int *)ActiveListQueue->First(); ActiveListQueue->Remove(temp); delete temp; } delete ActiveListQueue; ActiveListQueue=NULL; } if(nActiveArray){ delete nActiveArray; nActiveArray=NULL; } } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::IsActivated(int nPartX,int nPartY){ return IsActivated(nPartY*FCountX+nPartX); } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::IsActivated(int num){ return nActiveArray[num]&1; } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::IsUndoActivated(int nPartX,int nPartY){ return IsUndoActivated(nPartY*FCountX+nPartX); } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::IsUndoActivated(int num){ return nActiveArray[num]&2; } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::ActivatePart(int nPartX,int nPartY){ return ActivatePart(nPartY*FCountX + nPartX); } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::ActivatePart(int num){ /* while(ActiveListQueue->Count>nThreshold){ DeleteOneActivatedPart(); } */ return AddOneActivatePart(num); } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::AddOneActivatePart(int num){ int *temp; //if(!(nActiveArray[num]&1)) if(!IsActivated(num)) { if(nActiveArray[num]==2){ nActiveArray[num]=3; }else{ nActiveArray[num]=1; } // nActiveArray[num]+=1; for(int i=0;iCount;i++){ temp = (int *)ActiveListQueue->Items[i]; if(*temp == num){ ActiveListQueue->Remove(temp); delete temp; } } temp = new int; *temp = num; ActiveListQueue->Add(temp); return true; }else{ for(int i=0;iCount;i++){ temp = (int *)ActiveListQueue->Items[i]; if(*temp == num){ ActiveListQueue->Remove(temp); ActiveListQueue->Add(temp); break; } } return false; } } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::UndoActivatePart(int nPartX,int nPartY){ return UndoActivatePart(nPartY*FCountX + nPartX); } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::UndoActivatePart(int num){ /* while(ActiveListQueue->Count>nThreshold){ DeleteOneActivatedPart(); } */ return AddOneUndoActivatePart(num); } //--------------------------------------------------------------------------- /* int __fastcall TPActiveList::DeleteOneActivatedPart(){ int *temp; int result; result = -1; if(ActiveListQueue->Count>nThreshold){} for(int i=0;iCount;i++){ temp = (int *)ActiveListQueue->Items[i]; if(!(LockMask & nActiveArray[*temp])) { nActiveArray[*temp]=0; result = *temp; ActiveListQueue->Remove(temp); delete temp; break; } } return result; }*/ //--------------------------------------------------------------------------- int __fastcall TPActiveList::DeleteOneActivatedPart(int limit){ int *temp; int result; int nThd; result = -1; if(limit == -1) { nThd = nThreshold; }else{ nThd = limit; } if(ActiveListQueue->Count>nThd){ for(int i=0;iCount;i++){ temp = (int *)ActiveListQueue->Items[i]; // if(!(1 & nActiveArray[*temp])) if(IsActivated(*temp)) { if(nActiveArray[*temp]==1){ nActiveArray[*temp]=0; result = *temp; ActiveListQueue->Remove(temp); delete temp; }else if(nActiveArray[*temp]==3){ nActiveArray[*temp]=2; result = *temp; } // if(result != -1) break; // } } } } return result; } //--------------------------------------------------------------------------- int __fastcall TPActiveList::DeleteOneUndoActivatedPart(int limit){ int *temp; int result; int nThd; result = -1; if(limit == -1) { nThd = nThreshold; }else{ nThd = limit; } if(ActiveListQueue->Count>nThd){ for(int i=0;iCount;i++){ temp = (int *)ActiveListQueue->Items[i]; // if(!(2 & nActiveArray[*temp])) if(IsUndoActivated(*temp)) { if(nActiveArray[*temp]==2){ nActiveArray[*temp]=0; result = *temp; ActiveListQueue->Remove(temp); delete temp; }else if(nActiveArray[*temp]==3){ nActiveArray[*temp]=1; result = *temp; } break; } } } return result; }//--------------------------------------------------------------------------- bool __fastcall TPActiveList::AddOneUndoActivatePart(int num){ int *temp; //if(!(nActiveArray[num]&2)) if(!IsUndoActivated(num)) { if(nActiveArray[num]==1){ nActiveArray[num]=3; }else{ nActiveArray[num]=2; } // nActiveArray[num]+=2; for(int i=0;iCount;i++){ temp = (int *)ActiveListQueue->Items[i]; if(*temp == num){ ActiveListQueue->Remove(temp); delete temp; } } temp = new int; *temp = num; ActiveListQueue->Add(temp); return true; }else{ //if this element exists already , then put this elt. to the end of List for(int i=0;iCount;i++){ temp = (int *)ActiveListQueue->Items[i]; if(*temp == num){ ActiveListQueue->Remove(temp); ActiveListQueue->Add(temp); break; } } return false; } } //--------------------------------------------------------------------------- /* //--------------------------------------------------------------------------- bool __fastcall TPActiveList::UndoActiveListRelease(){ int *temp; for(int i=0;iCount;i++){ temp = (int *)ActiveListQueue->Items[i]; if(nActiveArray[*temp]==LockMask){ nActiveArray[*temp]=0; ActiveListQueue->Remove(temp); delete temp; }else if(nActiveArray[*temp]&LockMask){ nActiveArray[*temp]-=2; } } LockMask=0; } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::UndoActiveListLock(){ LockMask=2; } //--------------------------------------------------------------------------- bool __fastcall TPActiveList::UndoActivatePartLine(int StartX,int EndX){ for(int i=StartX;i