void CMesh::BuildCollapseBuffer(bool bExplicitVertexCount, UINT uiMaxCollapses, CArray<uint8_t> const &arrUsedVertices, CProgressiveGeometry *pProgGeom) { int iCollapse, iPos; CArray<UINT> arrCollapses; CArray<uint16_t> arrTriIndices; UINT uiSrcMapFlags = (pProgGeom->m_pIB->m_uiFlags & CResource::RF_KEEPSYSTEMCOPY) ? CResource::RMF_SYSTEM_ONLY : 0; uint8_t *pSrcIndices = pProgGeom->m_pIB->Map(0, uiSrcMapFlags); arrTriIndices.SetCount(pProgGeom->GetIBIndexCount()); memcpy(arrTriIndices.m_pArray, pSrcIndices, arrTriIndices.m_iCount * sizeof(uint16_t)); pProgGeom->m_pIB->Unmap(); CIndexChain kChain; kChain.Init(arrTriIndices.m_pArray, arrTriIndices.m_iCount, pProgGeom->GetVBVertexCount(), bExplicitVertexCount); for (iCollapse = 0; iCollapse < (int) Util::Min<UINT>(m_arrCollapses.m_iCount, uiMaxCollapses); iCollapse++) { if (m_arrCollapses[iCollapse].m_iCollapseToIndex < 0) break; int iVertIndex, iCollapseToIndex, iBaseIndex; iVertIndex = m_arrReverseReorder[m_arrCollapses[iCollapse].m_iVertexIndex]; if (!arrUsedVertices[iVertIndex]) continue; iCollapseToIndex = m_arrReverseReorder[m_arrCollapses[iCollapse].m_iCollapseToIndex]; ASSERT(arrUsedVertices[iCollapseToIndex]); iBaseIndex = arrCollapses.m_iCount; arrCollapses.Append(iVertIndex); arrCollapses.Append(iCollapseToIndex); if (bExplicitVertexCount) // Reserve space for maximum vertex index arrCollapses.SetCount(arrCollapses.m_iCount + 1); iPos = kChain.m_arrVertexChain[iVertIndex]; ASSERT(iPos >= 0); while (iPos >= 0 && iPos < arrTriIndices.m_iCount) { arrCollapses.Append(iPos); ASSERT(arrTriIndices[iPos] == iVertIndex); arrTriIndices[iPos] = iCollapseToIndex; ASSERT(iPos < kChain.m_arrChains[iPos] || kChain.m_arrChains[iPos] < 0); iPos = kChain.m_arrChains[iPos]; } // Shrink index buffer while (arrTriIndices.m_iCount && CGeometry::IsTriangleDegenerate(&arrTriIndices[arrTriIndices.m_iCount - 3])) arrTriIndices.SetCount(arrTriIndices.m_iCount - 3); kChain.MergeChains(iVertIndex, iCollapseToIndex, arrTriIndices.m_iCount); if (bExplicitVertexCount) arrCollapses[iBaseIndex + 2] = kChain.GetLastActiveVertex(); arrCollapses.Append(CProgressiveGeometry::INVALID_INDEX); } pProgGeom->SetCollapses(arrCollapses.m_iCount, arrCollapses.m_pArray, bExplicitVertexCount); }
HRESULT CFeedback::Init(FeedbackTypeId idType, bool bIsDisabled, bool bIsInherited, CString &csText, CArray<DrawSdk::DrawObject *, DrawSdk::DrawObject *> *pObjects, CInteractionAreaEx *pOkButton) { HRESULT hr = Init(idType, bIsDisabled, bIsInherited); if (SUCCEEDED(hr)) { m_csText = csText; if (!bIsDisabled && !bIsInherited) { // Note: more or less any combination of parameters is allowed here. // For example: bIsDisabled == true and pObjects->GetSize() > 0 is possible. // But this case here is an error. if (pObjects == NULL) // TODO require? || pOkButton == NULL) return E_POINTER; } //if (bIsInherited && pObjects != NULL && pObjects->GetSize() > 0) // _ASSERT(false); if (pObjects != NULL) { for (int i=0; i<pObjects->GetSize(); ++i) m_aObjects.Add(pObjects->GetAt(i)->Copy()); } if (pOkButton != NULL) m_pOkButton = pOkButton; // calculate bounding box from objects CArray<DrawSdk::DrawObject *, DrawSdk::DrawObject *> aObjectsDummy; aObjectsDummy.Append(m_aObjects); if (pOkButton != NULL) aObjectsDummy.Append(*(pOkButton->GetNormalObjects())); CalculateDimensions(&aObjectsDummy, &m_rcDimensions); // TODO (inconsistency): no "+2" here (see CMoveableObjects); which is better? CreateNameAndType(); m_bHiddenDuringEdit = true; m_bHiddenDuringPreview = true; } return hr; }
void InformApp::GetWindowFrames(CArray<CFrameWnd*>& frames) { if (m_pMainWnd) { if (m_pMainWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd))) frames.Add((CFrameWnd*)m_pMainWnd); } frames.Append(m_frames); }
bool Dnd::handleEnterEvent(const XEvent& xEvent) { m_DragWindow = XDND_ENTER_SOURCE_WIN(&xEvent); CArray<Atom> typeList; if (XDND_STATUS_WILL_ACCEPT(&xEvent) == 0) { //cout << "Only three types" << endl; for (int i = 0; i < XDND_THREE; i++) { if (XDND_ENTER_TYPE(&xEvent, i) != 0) { typeList.Append(XDND_ENTER_TYPE(&xEvent, i)); } } for ( unsigned int i = 0; i < typeList.GetSize(); i++) { Atom atom = XInternAtom(m_pDisplay, "text/uri-list", False); if (typeList[i] == atom) { m_DesiredType = atom; } } } else { //cout << "More than three types - getting list" << endl; generateTypeList(XDND_STATUS_TARGET_WIN(&xEvent), typeList); if (!typeList.GetSize()) { for ( unsigned int i = 0; i < typeList.GetSize(); i++) { Atom atom = XInternAtom(m_pDisplay, "text/uri-list", False); if (typeList[i] == atom) { m_DesiredType = atom; } } } } return false; }
int CMainFrame::GetSliderPos (UINT nID) { CArray<CMFCRibbonBaseElement*, CMFCRibbonBaseElement*> ar; CArray<CMFCRibbonBaseElement*, CMFCRibbonBaseElement*> ar2; m_wndRibbonBar.GetElementsByID (ID_RIBBON_OBTN_5, ar); m_wndRibbonBar.GetElementsByID (ID_RIBBON_OBTN_6, ar2); ar.Append (ar2); int nPos1 = -1; int nPos2 = -1; for (int k = 0; k < 2; k++) { for (int i = 0; i < ar.GetSize (); i++) { CMFCRibbonSlider* pSlider = DYNAMIC_DOWNCAST (CMFCRibbonSlider, ar[i]); if (pSlider != NULL) { if (k == 0) { if (pSlider->GetID () != nID) { nPos2 = pSlider->GetPos (); nPos1 = nPos2; break; } } else { if (pSlider->GetID () == nID) { if (pSlider->GetPos () != nPos2) { nPos1 = pSlider->GetPos (); } } } } } } return nPos1; }
bool Dnd::generateTypeList(Window window, CArray<Atom>& typeList) { if (window == None) { return false; } Atom* element; Atom type; int format; unsigned long count, remaining; unsigned char* data = NULL; XGetWindowProperty(m_pDisplay, window, XdndTypeList, 0, 0x8000000L, False, XA_ATOM, &type, &format, &count, &remaining, &data); if((type != XA_ATOM) || (format != 32) || (count == 0) || (!data)) { if(data) { XFree(data); } //cerr << "XGetWindowProperty failed in generateTypeList" << endl; return false; } element = (Atom*) data; for(unsigned long i = 0; i < count; i++) { typeList.Append(element[i]); } XFree(data); return true; }
HRESULT CFeedback::Init(CFeedbackDefinition *pDefinition) { if (pDefinition == NULL) return E_POINTER; CString csType = pDefinition->GetType(); if (StringManipulation::StartsWith(csType, CString(_T("q-correct")))) m_idType = FEEDBACK_TYPE_Q_CORRECT; else if (StringManipulation::StartsWith(csType, CString(_T("q-wrong")))) m_idType = FEEDBACK_TYPE_Q_WRONG; else if (StringManipulation::StartsWith(csType, CString(_T("q-repeat")))) m_idType = FEEDBACK_TYPE_Q_REPEAT; else if (StringManipulation::StartsWith(csType, CString(_T("q-time")))) m_idType = FEEDBACK_TYPE_Q_TIME; else if (StringManipulation::StartsWith(csType, CString(_T("q-tries")))) m_idType = FEEDBACK_TYPE_Q_TRIES; else if (StringManipulation::StartsWith(csType, CString(_T("qq-passed")))) m_idType = FEEDBACK_TYPE_QQ_PASSED; else if (StringManipulation::StartsWith(csType, CString(_T("qq-failed")))) m_idType = FEEDBACK_TYPE_QQ_FAILED; else if (StringManipulation::StartsWith(csType, CString(_T("qq-eval")))) m_idType = FEEDBACK_TYPE_QQ_EVAL; else return E_INVALIDARG; m_bIsDisabled = pDefinition->IsDisabled(); m_csText = pDefinition->GetText(); // can be empty if (!m_bIsDisabled) { m_bIsInherited = pDefinition->IsInherited(); if (!m_bIsInherited) { pDefinition->ExtractObjects(&m_aObjects); // m_aObjects can be empty, eg for question feedback in the test/questionnaire (storing texts) //if (m_aObjects.GetSize() <= 0) // return E_INVALIDARG; // there must be some objects in this case CInteractionArea *pOldArea = pDefinition->ExtractOkButton(); if (pOldArea != NULL) { m_pOkButton = new CInteractionAreaEx(); HRESULT hr = m_pOkButton->Init(pOldArea, NULL, 0); // Note: CEditorDoc* and nInsertPositionMs hopefully (?) not necessary for this button. if (FAILED(hr)) delete m_pOkButton; // ignore error delete pOldArea; } } } // calculate bounding box from objects CArray<DrawSdk::DrawObject *, DrawSdk::DrawObject *> aObjectsDummy; aObjectsDummy.Append(m_aObjects); if (m_pOkButton != NULL) aObjectsDummy.Append(*(m_pOkButton->GetNormalObjects())); CalculateDimensions(&aObjectsDummy, &m_rcDimensions); // TODO (inconsistency): no "+2" here (see CMoveableObjects); which is better? m_bHiddenDuringEdit = true; m_bHiddenDuringPreview = true; CreateNameAndType(); return S_OK; }
HRESULT CFeedback::RecalculateDimensions(CRect *prcTotal) { if (prcTotal == NULL) return E_POINTER; prcTotal->SetRectEmpty(); // Define offsets --> see also CQuestionnaireEx::CreateFeedback(...) int OFFSET_X = 20; int OFFSET_Y = 5; // Calculate bounding box from objects // Note: The 2 border/background rectangles must be ignored here, because they // can change their dimensions and must be re-calculated again (sse below) CArray<DrawSdk::DrawObject *, DrawSdk::DrawObject *> aObjectsDummy; aObjectsDummy.Append(m_aObjects); // Get dimensions from feedback text double dTextX = 0.0; double dTextY = 0.0; double dTextWidth = 0.0; double dTextHeight = 0.0; double dTextAscent = 0.0; for (int i=0; i<aObjectsDummy.GetSize(); ++i) { if (aObjectsDummy.GetAt(i)->GetType() == DrawSdk::TEXT) { dTextX = aObjectsDummy.GetAt(i)->GetX(); dTextY = aObjectsDummy.GetAt(i)->GetY(); dTextWidth = aObjectsDummy.GetAt(i)->GetWidth(); dTextHeight = aObjectsDummy.GetAt(i)->GetHeight(); LOGFONT lf; ((DrawSdk::Text *)aObjectsDummy.GetAt(i))->GetLogFont(&lf); dTextAscent = ((DrawSdk::Text *)aObjectsDummy.GetAt(i))->GetTextAscent(&lf); } } // Get dimensions from feedback button double dOkButtonX = 0.0; double dOkButtonY = 0.0; double dOkButtonWidth = 0.0; double dOkButtonHeight = 0.0; if (m_pOkButton != NULL) { dOkButtonX = (double)m_pOkButton->GetArea().left; dOkButtonY = (double)m_pOkButton->GetArea().top; dOkButtonWidth = (double)m_pOkButton->GetArea().Width(); dOkButtonHeight = (double)m_pOkButton->GetArea().Height(); } // Calculate the new dimension of the feedback double dMin = MIN((int)dTextX, (int)dOkButtonX); double rcX1 = dMin - OFFSET_X; double rcY1 = dTextY - (dTextHeight+dTextAscent); double dMax = MAX((int)dTextWidth, (int)dOkButtonWidth); double rcX2 = rcX1 + dMax + 2*OFFSET_X; double rcY2 = dOkButtonY + dOkButtonHeight + OFFSET_Y; // Set the new feedback dimension prcTotal->SetRect((int)rcX1, (int)rcY1, (int)rcX2, (int)rcY2); // Resize the 2 border/background rectangles HRESULT hr = ResizeBorderRectangles(*prcTotal); return hr; }
void CMesh::CollapseEdge(TEdge *pEdge, bool bRemoveSecond) { TVertex *p2Remain, *p2Remove; CArray<TVertex *> arrInvalVerts; TEdgeHash hashEvaluatedEdges; int i, iTri; ASSERT(pEdge); p2Remain = pEdge->m_pVertices[!bRemoveSecond]; p2Remove = pEdge->m_pVertices[bRemoveSecond]; for (i = 0; i < p2Remove->m_pTriangles->m_iCount; i++) { TVertex *pOther0, *pOther1; p2Remove->m_pTriangles->At(i)->GetOtherVertices(p2Remove, pOther0, pOther1); arrInvalVerts.Append(pOther0); arrInvalVerts.Append(pOther1); } ASSERT(pEdge->m_pTriangles[0]); // Order of removal is important, if we remove the first one first and it's the only one left, // the edge will get deleted and the attempt to remove the other one will crash RemoveTriangle(pEdge->m_pTriangles[1]); RemoveTriangle(pEdge->m_pTriangles[0]); ASSERT(!GetEdge(p2Remain, p2Remove)); /* #ifdef _DEBUG { for (int i = 0; i < p2Remove->m_pTriangles->m_iCount; i++) { TVertex *pVert0, *pVert1; TTriangle *pTri = p2Remove->m_pTriangles->At(i); pTri->GetOtherVertices(p2Remove, pVert0, pVert1); TTriangle kTestTri(p2Remain, pVert0, pVert1); TTriangleHash::TIter it = m_hashTriangles.Find(&kTestTri); ASSERT(!it); if (it) TEdge *pE = GetEdge(pVert0, pVert1); } } #endif */ while (p2Remove->m_pTriangles->m_iCount > 0) { TVertex *pVert0, *pVert1; TTriangle *pTri = p2Remove->m_pTriangles->At(p2Remove->m_pTriangles->m_iCount - 1); pTri->GetOtherVertices(p2Remove, pVert0, pVert1); int iTriIndex = pTri->m_iIndex; RemoveTriangle(pTri); AddTriangle(p2Remain, pVert0, pVert1, iTriIndex); } m_hashVertices.RemoveValue(p2Remove); delete p2Remove; for (i = 0; i < arrInvalVerts.m_iCount; i++) { for (iTri = 0; iTri < arrInvalVerts[i]->m_pTriangles->m_iCount; iTri++) { TVertex *pOther[2]; TEdge *pEdge; int iVert; arrInvalVerts[i]->m_pTriangles->At(iTri)->GetOtherVertices(arrInvalVerts[i], pOther[0], pOther[1]); for (iVert = 0; iVert < 2; iVert++) { pEdge = GetEdge(arrInvalVerts[i], pOther[iVert]); if (hashEvaluatedEdges.Find(pEdge)) continue; EvaluateEdge(pEdge, false); EvaluateEdge(pEdge, true); hashEvaluatedEdges.Add(pEdge); } } } }
ERMsg CUIEnvCanRadar::ExecuteHistorical(CCallback& callback) { ERMsg msg; string workingDir = GetDir(WORKING_DIR); CreateMultipleDir(workingDir); CInternetSessionPtr pSession; CHttpConnectionPtr pConnection; msg = GetHttpConnection(SERVER_NAME[as<size_t>(TYPE)], pConnection, pSession); if (!msg) return msg; callback.AddMessage(GetString(IDS_UPDATE_DIR)); callback.AddMessage(workingDir, 1); callback.AddMessage(GetString(IDS_UPDATE_FROM)); callback.AddMessage(SERVER_NAME[as<size_t>(TYPE)], 1); callback.AddMessage(""); //Get remote station list StringVector imageList; if (msg) msg = GetRadarList(imageList, callback); if (msg) msg = CleanRadarList(imageList, callback); if (!msg) return msg; callback.PushTask("Download historical radar images (" + ToString(imageList.size())+ ")", imageList.size()); //callback.SetNbStep(imageList.size()); int nbRun = 0; int curI = 0; while (curI<imageList.size() && msg) { nbRun++; CInternetSessionPtr pSession; CHttpConnectionPtr pConnection; msg = GetHttpConnection(SERVER_NAME[as<size_t>(TYPE)], pConnection, pSession); if (msg) { TRY { for (int i = curI; i<imageList.size() && msg; i++) { string filePath = GetOutputFilePath(as<size_t>(TYPE), imageList[i]); msg += CreateMultipleDir(GetPath(filePath)); //msg += CopyFile(pConnection, imageList[i], filePath, INTERNET_FLAG_TRANSFER_BINARY | WININET_API_FLAG_SYNC); CString URL(imageList[i].c_str()); CHttpFile* pURLFile = pConnection->OpenRequest(_T("GET"), URL, NULL, 1, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_TRANSFER_BINARY | WININET_API_FLAG_SYNC | INTERNET_FLAG_NEED_FILE); //CStdioFile* pURLFile = pSession->OpenURL(UtilWin::Convert(imageList[i]), 0, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_EXISTING_CONNECT); bool bRep = false; if (pURLFile != NULL) { if (pURLFile->SendRequest() != 0) { CArray<char> source; int len = 0; CArray<char> tmp; tmp.SetSize(50); DWORD dwStatusCode = 0; pURLFile->QueryInfoStatusCode(dwStatusCode); ULONGLONG length = pURLFile->GetLength(); while (length > 0) { pURLFile->Read(tmp.GetData(), 50); source.Append(tmp); length = pURLFile->GetLength(); } pURLFile->QueryInfoStatusCode(dwStatusCode); pURLFile->Close(); ofStream file; msg = file.open(filePath, ios::out | ios::binary); if (msg) { if (!source.IsEmpty()) file.write(source.GetData(), (UINT)source.GetSize()); file.close(); //convert image to GeoTiff //ConvertToGeotiff(filePath, CCanadianRadar(CCanadianRadar::coord)); } } } if (msg) { curI++; nbRun = 0; msg += callback.StepIt(); } } } CATCH_ALL(e) { msg = UtilWin::SYGetMessage(*e); } END_CATCH_ALL //if an error occur: try again if (!msg && !callback.GetUserCancel()) { //callback.AddTask(1);//one step more if (nbRun < 5) { callback.AddMessage(msg); msg.asgType(ERMsg::OK); Sleep(1000);//wait 1 sec } } //clean connection pConnection->Close(); pSession->Close(); } } callback.AddMessage(GetString(IDS_NB_FILES_DOWNLOADED) + ToString(curI)); callback.PopTask(); return msg; }
void SgmlElement::GetElements(CArray<SgmlElement *, SgmlElement *> &aElements) { aElements.RemoveAll(); if (!m_aElements.IsEmpty()) aElements.Append(m_aElements); }