bool wxGISToolExecuteView::OnDropObjects(wxCoord x, wxCoord y, long nParentPointer, const wxArrayLong& TaskIds)
{
    wxBusyCursor wait;
    SetItemState(m_HighLightItem, 0, wxLIST_STATE_DROPHILITED);
    //SetItemState(m_HighLightItem, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);

    if(nParentPointer != wxThread::GetMainId())
        return false;

    wxPoint pt(x, y);
    unsigned long nFlags(0);
    long nItemId = HitTest(pt, (int &)nFlags);
    long nObjectID(m_nParentGxObjectId);

    if(nItemId == wxNOT_FOUND)
        return false;

    IGxTask* pBeforeTask(NULL);
    int nInsertPoint = GetItemCount() - TaskIds.GetCount(); //the end
    if(nFlags & wxLIST_HITTEST_ONITEM)
    {
        nInsertPoint = nItemId;// - 1;
        pBeforeTask = dynamic_cast<IGxTask*>(m_pCatalog->GetRegisterObject(GetItemData(nInsertPoint)));
    }

    //1. Read all items to map sortig using priority, but not adding moving items
    m_bDropping = true;
    std::map<long, IGxTask*> ItemsMap;
    for(int i = 0; i < GetItemCount(); ++i)
    {
        long nTaskId = GetItemData(i);
        if(TaskIds.Index(nTaskId) == wxNOT_FOUND)
        {
            IGxTask* pTask = dynamic_cast<IGxTask*>(m_pCatalog->GetRegisterObject(nTaskId));
            if(pTask && pTask->GetState() != enumGISTaskDone)
            {
                ItemsMap[pTask->GetPriority()] = pTask;
            }
        }
    }

    //wxWindowUpdateLocker noUpdates(this);

    //get min priority
    if(nInsertPoint < 0)
    {
        long nMinPrio = ItemsMap.begin()->first;
        for(size_t i = 0; i < TaskIds.GetCount(); ++i)
        {
            IGxTask* pTask = dynamic_cast<IGxTask*>(m_pCatalog->GetRegisterObject(TaskIds[i]));
            if(pTask)
            {
                pTask->SetPriority(++nMinPrio);
            }
        }
        for(std::map<long, IGxTask*>::iterator it = ItemsMap.begin(); it != ItemsMap.end(); ++it)
        {
            it->second->SetPriority(++nMinPrio);
        }
    }
    else if(nInsertPoint >= TaskIds.GetCount())
    {
        long nMinPrio = ItemsMap.begin()->first;
        for(std::map<long, IGxTask*>::iterator it = ItemsMap.begin(); it != ItemsMap.end(); ++it)
        {
            it->second->SetPriority(++nMinPrio);
        }

        for(size_t i = 0; i < TaskIds.GetCount(); ++i)
        {
            IGxTask* pTask = dynamic_cast<IGxTask*>(m_pCatalog->GetRegisterObject(TaskIds[i]));
            if(pTask)
            {
                pTask->SetPriority(++nMinPrio);
            }
        }
    }
    else
    {
        //2. Read from map until end for insert to array
        bool bSetPrio(false);
        long nMinPrio = wxNOT_FOUND;
        for(std::map<long, IGxTask*>::iterator it = ItemsMap.begin(); it != ItemsMap.end(); ++it)
        {
            if(pBeforeTask == it->second)
            {
                nMinPrio = pBeforeTask->GetPriority();
                for(size_t i = 0; i < TaskIds.GetCount(); ++i)
                {
                    IGxTask* pTask = dynamic_cast<IGxTask*>(m_pCatalog->GetRegisterObject(TaskIds[i]));
                    if(pTask)
                    {
                        pTask->SetPriority(++nMinPrio);
                    }
                }
                bSetPrio = true;
            }
            if(bSetPrio)
                it->second->SetPriority(++nMinPrio);
        }
    }

    SortItems(GxTaskCompareFunction, 0);

    m_bDropping = false;

    return true;
}
Exemple #2
0
bool wxGISTaskCmd::GetEnabled(void)
{
    wxGxSelection* pSel = m_pApp->GetGxSelection();
    wxGxCatalogBase* pCat = GetGxCatalog();

    switch(m_subtype)
	{
		case 0: //Show task config dialog
            if(pCat && pSel)
            {
                for(size_t i = 0; i < pSel->GetCount(); ++i)
                {
                    wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i));
                    IGxTask* pGxTask = dynamic_cast<IGxTask*>(pGxObject);
                    if(!pGxTask)
                        return false;
                    if(pGxTask->GetState() != enumGISTaskWork)
                        return true;
                }
            }
            return false;
		case 1: //Show task execution dialog
            if(pCat && pSel)
            {
                for(size_t i = 0; i < pSel->GetCount(); ++i)
                {
                    wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i));
                    IGxTask* pGxTask = dynamic_cast<IGxTask*>(pGxObject);
                    if(!pGxTask)
                        return false;
                    if(pGxTask->GetState() == enumGISTaskWork || pGxTask->GetState() == enumGISTaskDone || pGxTask->GetState() == enumGISTaskError)
                        return true;
                }
            }
            return false;
		case 2: //Start task
            if(pCat && pSel)
            {
                for(size_t i = 0; i < pSel->GetCount(); ++i)
                {
                    wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i));
                    IGxTask* pGxTask = dynamic_cast<IGxTask*>(pGxObject);
                    if(!pGxTask)
                        return false;
                    return !(pGxTask->GetState() == enumGISTaskQuered || pGxTask->GetState() == enumGISTaskWork);
                    //if(pGxTask->GetState() != enumGISTaskQuered && pGxTask->GetState() != enumGISTaskWork)
                    //    return true;
                }
            }
            return false;
		case 3: //Stop task
            if(pCat && pSel)
            {
                for(size_t i = 0; i < pSel->GetCount(); ++i)
                {
                    wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i));
                    IGxTask* pGxTask = dynamic_cast<IGxTask*>(pGxObject);
                    if(!pGxTask)
                        return false;
                    return !(pGxTask->GetState() == enumGISTaskPaused || pGxTask->GetState() == enumGISTaskError || pGxTask->GetState() == enumGISTaskDone);
                    //if(pGxTask->GetState() != enumGISTaskPaused)
                    //    return true;
                }
            }
            return false;
		default:
			return false;
	}
}