void CUIDesignerView::OnRemoveUI() { CArray<CControlUI*,CControlUI*> arrSelected; m_MultiTracker.GetSelected(arrSelected); //remove form for (int i=0; i<arrSelected.GetSize(); i++) { CControlUI* pControl = arrSelected[i]; if(pControl == m_LayoutManager.GetForm()) { arrSelected.RemoveAt(i); break;; } } m_UICommandHistory.Begin(arrSelected, actionDelete); for(int i=0; i<arrSelected.GetSize(); i++) { CControlUI* pControl = arrSelected[i]; CControlUI* pParent=pControl->GetParent(); HTREEITEM hDelete=(HTREEITEM)(((ExtendedAttributes*)pControl->GetTag())->hItem); g_pClassView->RemoveUITreeItem(hDelete); RemoveUI(pControl); if(pParent) pParent->NeedUpdate(); } m_UICommandHistory.End(); g_pPropertiesWnd->HideAllProperties(TRUE,TRUE); m_MultiTracker.RemoveAll(); }
void CDebuggerView::OnDbTogglebreakpoint() { int pos = m_editor.SendEditor(SCI_GETCURRENTPOS); int lineNumber = m_editor.SendEditor(SCI_LINEFROMPOSITION, pos); // Is there a breakpoint currently here? int breakpointIndex = FindBreakpoint(m_currentFileName, lineNumber); if (breakpointIndex == -1) { // No, add it. m_editor.SendEditor(SCI_MARKERDEFINE, MARKER_BREAKPOINT, SC_MARK_CIRCLE); m_editor.SendEditor(SCI_MARKERSETFORE, MARKER_BREAKPOINT, RGB(0x00, 0x00, 0)); m_editor.SendEditor(SCI_MARKERSETBACK, MARKER_BREAKPOINT, RGB(0xff, 0x00, 0x00)); m_editor.SendEditor(SCI_MARKERADD, lineNumber, MARKER_BREAKPOINT); // Add the breakpoint. BreakpointInfo info; info.m_fileName = m_currentFileName; info.m_lineNumber = lineNumber; m_breakpointInfo.Add(info); } else { // Remove the breakpoint. m_editor.SendEditor(SCI_MARKERDELETE, lineNumber, MARKER_BREAKPOINT); m_breakpointInfo.RemoveAt(breakpointIndex); } CString command; command.Format(_T("DebugSetBreakpoint('%s',%d,%s)"), m_currentFileName, lineNumber, (breakpointIndex == -1) ? _T("true") : _T("false")); theApp.GetNetworkClient().SendCommand(command); }
void CUIDesignerView::RemoveForm(CArray<CControlUI*,CControlUI*>& arrSelected) { for (int i=0; i<arrSelected.GetSize(); i++) { CControlUI* pControl = arrSelected[i]; if(pControl == m_LayoutManager.GetForm()) { arrSelected.RemoveAt(i); break; } } }
void main() { CArray arr; arr.Add(1234); arr.Add(23); arr.Add(44); arr.Add(21); arr.Add(5); arr.RemoveAt(2,20000000); //从第二个位置起,删除2个数据 arr.InsertAt(3,10,2); int i = 0; int nSize = arr.GetSize(); cout << "共有 " << nSize << " 条数据" << endl; TYPE *p = arr.GetData(); qsort(p,nSize,sizeof(TYPE),compar); while(i < nSize) { cout << arr[i] << endl; ++i; } }
HRESULT ProfileUtils::GetRecentProfiles(CArray<RegistryProfileInfo *, RegistryProfileInfo *> &arRecentProfiles) { HRESULT hr = S_OK; arRecentProfiles.RemoveAll(); _TCHAR tszActiveProfile[MAX_PATH]; unsigned long lLength = MAX_PATH; DWORD dwEntriesCount = 0; bool bSuccess = LRegistry::EnumRegistryValues(HKEY_CURRENT_USER, _T("Software\\imc AG\\LECTURNITY\\Publisher\\Profiles\\Recent\\List"), NULL, &dwEntriesCount, false); if (!bSuccess) hr = E_FAIL; LRegistry::ENTRY **paEntries = NULL; if (SUCCEEDED(hr)) { paEntries = new LRegistry::ENTRY*[dwEntriesCount+1]; for (int i = 0; i < dwEntriesCount; ++i) paEntries[i] = new LRegistry::ENTRY(); } if (SUCCEEDED(hr)) { bSuccess = LRegistry::EnumRegistryValues(HKEY_CURRENT_USER, _T("Software\\imc AG\\LECTURNITY\\Publisher\\Profiles\\Recent\\List"), paEntries, &dwEntriesCount, false); if (!bSuccess) hr = E_FAIL; } if (SUCCEEDED(hr)) { for (int i = 0; i < dwEntriesCount; ++i) { CString csName = paEntries[i]->lsName; bool bSuccess = LRegistry::ReadStringRegistryEntry(HKEY_CURRENT_USER, _T("Software\\imc AG\\LECTURNITY\\Publisher\\Profiles\\Recent\\List"), csName, tszActiveProfile, &lLength); if (bSuccess && lLength > 0) { RegistryProfileInfo *pNewProfileInfo = new RegistryProfileInfo(csName, tszActiveProfile); arRecentProfiles.Add(pNewProfileInfo); int k = 0; } } } if (paEntries != NULL) { for (int i = 0; i < dwEntriesCount; ++i) delete paEntries[i]; delete[] paEntries; } if (SUCCEEDED(hr)) { // check recent profiles (existance) CArray<ProfileInfo *, ProfileInfo *> aProfileInformation; hr = ReadCustomProfiles(aProfileInformation); CArray<int, int> arPositionsToDelete; // Remove all custom profiles which are no longer existing arPositionsToDelete.RemoveAll(); for (int i = 0; i < arRecentProfiles.GetCount(); ++i) { if (arRecentProfiles[i]->GetProfileType() == PublishingFormat::TYPE_CUSTOM) { bool bFound = false; for (int j = 0; j < aProfileInformation.GetCount() && !bFound; ++j) { if (arRecentProfiles[i]->GetCustomProfileID() == aProfileInformation[j]->GetID()) bFound = true; } if (!bFound) arPositionsToDelete.Add(i); } } for (int i = arPositionsToDelete.GetCount()-1; i >= 0; --i) { if (arRecentProfiles[arPositionsToDelete[i]] != NULL) delete arRecentProfiles[arPositionsToDelete[i]]; arRecentProfiles.RemoveAt(arPositionsToDelete[i]); } // Remove old custom profile if there are more than five bool bFinished = false; while (!bFinished) { int iCustomProfileCount = 0; CTime *pOldest = NULL; int iOldestPos = -1; for (int i = 0; i < arRecentProfiles.GetCount(); ++i) { if (arRecentProfiles[i]->GetProfileType() == PublishingFormat::TYPE_CUSTOM) { CTime *pElementTime = arRecentProfiles[i]->GetLastActivatedTime(); if (pOldest == NULL || (pElementTime != NULL && *pElementTime < *pOldest)) { pOldest = pElementTime; iOldestPos = i; } ++iCustomProfileCount; } } if (iCustomProfileCount <= 5 || iOldestPos < 0) bFinished = true; else { if (arRecentProfiles[iOldestPos] != NULL) delete arRecentProfiles[iOldestPos]; arRecentProfiles.RemoveAt(iOldestPos); } } for (int i = 0; i < aProfileInformation.GetCount(); ++i) if (aProfileInformation[i] != NULL) delete aProfileInformation[i]; aProfileInformation.RemoveAll(); } return S_OK; }
void CItemData::DeleteColumn(int nColumn) { aTextColors.RemoveAt(nColumn); aBkColors.RemoveAt(nColumn); }
// Diese Funktion entfernt die benötigten Ressourcen aus dem lokalen Lager des Systems und falls Ressourcenrouten // bestehen auch die Ressourcen in den Startsystemen der Route. Aber nur falls dies auch notwendig sein sollte. void CAssemblyList::RemoveResourceFromStorage(BYTE res, const CPoint &ko, std::vector<CSystem>& systems, CArray<CPoint>* routesFrom) { if (ko == CPoint(-1,-1)) return; CSystem *system = &systems.at(ko.x+(ko.y)*STARMAP_SECTORS_HCOUNT); // für Deritium gibt es keine Ressourcenroute if (res != DERITIUM) { // zuerst wird immer versucht, die Ressourcen aus dem lokalen Lager zu nehmen long remainingRes = GetNeededResourceInAssemblyList(0, res) - system->GetResourceStore(res); // werden zusätzliche Ressourcen aus anderen Lagern benötigt, so kann das lokale Lager // auf NULL gesetzt werden if (remainingRes > 0) { *system->GetResourceStorages(res) = NULL; // zusätzliche Ressourcen müssen aus den Lagern der Systeme mit den Ressourcenrouten // bezogen werden. Dafür ein Feld anlegen, indem alle Startsysteme mit der zur Ressouce passenden // Ressourcenroute beinhaltet sind. struct ROUTELIST { CResourceRoute *route; CPoint fromSystem; ROUTELIST() : route(0), fromSystem(0) {} ROUTELIST(CResourceRoute *_route, CPoint _fromSystem) : route(_route), fromSystem(_fromSystem) {} }; CArray<ROUTELIST> routes; for (int j = 0; j < routesFrom->GetSize(); j++) { CPoint p = routesFrom->GetAt(j); for (int k = 0; k < systems.at(p.x+(p.y)*STARMAP_SECTORS_HCOUNT).GetResourceRoutes()->GetSize(); k++) { // Stimmt die Ressource überein= if (systems.at(p.x+(p.y)*STARMAP_SECTORS_HCOUNT).GetResourceRoutes()->GetAt(k).GetResource() == res) { // Stimmt das Zielsystem mit unserem überein? if (systems.at(p.x+(p.y)*STARMAP_SECTORS_HCOUNT).GetResourceRoutes()->GetAt(k).GetKO() == ko) { // prüfen das die Route nicht schon verwendet wird bool bUsed = false; for (int l = 0; l < routes.GetSize(); l++) if (routes.GetAt(l).fromSystem == p) { bUsed = true; break; } if (!bUsed) routes.Add(ROUTELIST(&systems.at(p.x+(p.y)*STARMAP_SECTORS_HCOUNT).GetResourceRoutes()->GetAt(k), p)); } } } } // in routes sind nun die Zeiger auf die richtigen Ressourcenrouten, also die Routen, welche auch den // passenden Rohstoff liefern könnten. while (routes.GetSize()) { // zufällig eine Route aus den möglichen auswählen, damit nicht immer das gleiche System zuerst // die Rohstoffe liefern muss, falls mehrere Routen der selben Art ins System eingehen. int random = rand()%routes.GetSize(); int percent = 0; CPoint start = routes.GetAt(random).fromSystem; // sind im jeweiligen Lager des Startsystem genügend Rohstoffe vorhanden if (systems.at(start.x+(start.y)*STARMAP_SECTORS_HCOUNT).GetResourceStore(res) >= (ULONG)remainingRes) { *systems.at(start.x+(start.y)*STARMAP_SECTORS_HCOUNT).GetResourceStorages(res) -= remainingRes; if (GetNeededResourceInAssemblyList(0, res) > NULL) percent = 100 * remainingRes / GetNeededResourceInAssemblyList(0, res); CResourceRoute* pResRoute = routes.GetAt(random).route; pResRoute->SetPercent((BYTE)percent); remainingRes = 0; } else { remainingRes -= systems.at(start.x+(start.y)*STARMAP_SECTORS_HCOUNT).GetResourceStore(res); if (GetNeededResourceInAssemblyList(0, res) > NULL) percent = 100 * systems.at(start.x+(start.y)*STARMAP_SECTORS_HCOUNT).GetResourceStore(res) / GetNeededResourceInAssemblyList(0, res); CResourceRoute* pResRoute = routes.GetAt(random).route; pResRoute->SetPercent((BYTE)percent); *systems.at(start.x+(start.y)*STARMAP_SECTORS_HCOUNT).GetResourceStorages(res) = NULL; } // ROUTELIST Eintrag entfernen, wenn dieser abgearbeitet wurde routes.RemoveAt(random); // werden keine Ressourcen mehr benötigt, so kann abgebrochen werden if (remainingRes == 0) { routes.RemoveAll(); break; } } ASSERT(remainingRes == 0); } // anderenfalls werden nur die benötigten Ressourcen aus dem lokalen Lager abgezogen else *system->GetResourceStorages(res) -= GetNeededResourceInAssemblyList(0, res); } else *system->GetResourceStorages(res) -= m_iNeededDeritiumInAssemblyList[0]; }
void DLrtfhtml::addProToArr(CStringArray &arr,CArray<rtfProperty,rtfProperty&> &proArr) { CString temp; CString protemp; int count=arr.GetCount(); int j=0; rtfProperty pro;//property struct for(int i=0;i<arr.GetCount();i++) { temp=arr.GetAt(i); memset(&pro,0,sizeof(rtfProperty)); if(temp.Compare(_T("\\b"))==0) { if(proIsExist(temp,proArr)==-1) { pro.data=0; lstrcpy(pro.rtfType,temp.GetBuffer()); temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,_T("<b>")); lstrcpy(pro.htmlTagE,_T("</b>")); proArr.Add(pro); } } else if(temp.Compare(_T("\\b0"))==0) { int id=proIsExist(temp,proArr); if(id!=-1) proArr.RemoveAt(id); } else if(temp.Compare(_T("\\i"))==0) { if(proIsExist(temp,proArr)==-1) { pro.data=0; lstrcpy(pro.rtfType,temp.GetBuffer()); temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,_T("<i>")); lstrcpy(pro.htmlTagE,_T("</i>")); proArr.Add(pro); } } else if(temp.Compare(_T("\\i0"))==0) { int id=proIsExist(temp,proArr); if(id!=-1) proArr.RemoveAt(id); } else if(temp.Compare(_T("\\ul"))==0) { if(proIsExist(temp,proArr)==-1) { pro.data=0; lstrcpy(pro.rtfType,temp.GetBuffer()); temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,_T("<u>")); lstrcpy(pro.htmlTagE,_T("</u>")); proArr.Add(pro); } } else if(temp.Compare(_T("\\ulnono"))==0) { int id=proIsExist(temp,proArr); if(id!=-1) proArr.RemoveAt(id); } else if(temp.Compare(_T("\\strike"))==0) { if(proIsExist(temp,proArr)==-1) { pro.data=0; lstrcpy(pro.rtfType,temp.GetBuffer()); temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,_T("<strike>")); lstrcpy(pro.htmlTagE,_T("</strike>")); proArr.Add(pro); } } else if(temp.Compare(_T("\\strike0"))==0) { int id=proIsExist(temp,proArr); if(id!=-1); proArr.RemoveAt(id); } else if(temp.Find(_T("\\fs"))>=0) { int num=strGetNumber(temp); if(num<=0) num=24; int id=proIsExist(_T("\\fs"),proArr); if(id==-1) { pro.data=num; lstrcpy(pro.rtfType,_T("\\fs")); //temp.ReleaseBuffer(); protemp.Format(_T("font-size:%d;"),num); lstrcpy(pro.htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); pro.single=TRUE; proArr.Add(pro); } else{ proArr.GetAt(id).data=num; } } else if(temp.Find(_T("\\cf"))>=0) //颜色 { int num=strGetNumber(temp); if(num==-1) continue; int id=proIsExist(_T("\\cf"),proArr); if(num>m_cg.GetCount()) protemp.Format(_T("color:#%FFFFFF")); else if(num>=1) protemp.Format(_T("color:#%02x%02x%02x;"),GetRValue(m_cg.GetAt(num-1)),GetGValue(m_cg.GetAt(num-1)),GetBValue(m_cg.GetAt(num-1))); if(num==0 && id!=-1) { proArr.RemoveAt(id); //protemp.Format(_T("color:#%FF#FF#FF")); } else if(num>=1 && id!=-1) //修改 { proArr.GetAt(id).data=num; lstrcpy(proArr.GetAt(id).htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); } else if(id==-1) //添加 { pro.data=num; lstrcpy(pro.rtfType,_T("\\cf")); //temp.ReleaseBuffer(); lstrcpy(pro.htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); pro.single=TRUE; proArr.Add(pro); } }else if(temp.Find(_T("\\highlight"))>=0) //颜色 { int num=strGetNumber(temp); if(num==-1) continue; int id=proIsExist(_T("\\highlight"),proArr); if(num>m_cg.GetCount()) protemp.Format(_T("color:#%FFFFFF")); else if(num>=1) protemp.Format(_T("color:#%02x%02x%02x;"),GetRValue(m_cg.GetAt(num-1)),GetGValue(m_cg.GetAt(num-1)),GetBValue(m_cg.GetAt(num-1))); if(num==0 && id!=-1) { proArr.RemoveAt(id); }else if(num>=1 && id!=-1) //修改 { proArr.GetAt(id).data=num; lstrcpy(proArr.GetAt(id).htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); }else if(id==-1) //添加 { pro.data=num; lstrcpy(pro.rtfType,_T("\\highlight")); lstrcpy(pro.htmlTagB,protemp.GetBuffer()); protemp.ReleaseBuffer(); pro.single=TRUE; proArr.Add(pro); } } } }
void CProxy::AdminHandler(char *request, int *adminFlag) { int playlistpos = 0; char suppliedPass[255] = ""; char msg[255] = ""; int valid = 0; int errorCode = 0; char variable[255] = ""; char value[255] = ""; int action = 0; char tempRequest[1024] = ""; strcpy(tempRequest, request); // if (!strncmp(tempRequest, "/admin.cgi", strlen("/admin.cgi"))) { char *p1; p1 = strchr(tempRequest, '?'); if (p1) { p1++; char *token; token = strtok(p1, "&"); while (token != NULL) { char *p2; p2 = strchr(token, '='); if (p2) { memset(variable, '\000', sizeof(variable)); memset(value, '\000', sizeof(value)); int lengthtocopy = 0; if ((p2-token) > (sizeof(variable)-1)) { lengthtocopy = sizeof(variable)-1; } else { lengthtocopy = p2-token; } strncpy(variable, token, lengthtocopy); p2++; strncpy(value, p2, sizeof(value)-1); if (!strcmp(variable, "pass")) { strncpy(suppliedPass, value, sizeof(suppliedPass)-1); } if (!strcmp(variable, "action")) { if (!strcmp(value, "delete")) { action = 1; } if (!strcmp(value, "play")) { action = 2; } if (!strcmp(value, "prev")) { action = 3; } if (!strcmp(value, "pause")) { action = 4; } if (!strcmp(value, "stop")) { action = 5; } if (!strcmp(value, "next")) { action = 6; } if (!strcmp(value, "refreshcache")) { action = 7; } } if (!strcmp(variable, "listpos")) { playlistpos = atoi(value); } } token = strtok(NULL, "&"); } } int passok = 0; if (strlen(g_AdminPassword) > 0) { if (!strcmp(suppliedPass, g_AdminPassword)) { *adminFlag = 1; passok = 1; } else { *adminFlag = 0; passok = 0; } } if (passok) { int winampCommand = 0; switch (action) { case 2: PlayWinamp(); winampCommand = 1; break; case 3: PrevWinamp(); winampCommand = 1; break; case 4: PauseWinamp(); winampCommand = 1; break; case 5: StopWinamp(); winampCommand = 1; break; case 6: NextWinamp(); winampCommand = 1; break; case 7: repopulatePlaylistCache(); winampCommand = 1; break; } if (winampCommand) { char buf[255] = ""; _snprintf(buf, sizeof(buf)-1, "Location: /admin.cgi?pass=%s", g_AdminPassword); send_headers(302, "Moved Temporarily", (char*) buf, 0, -1, -1 ); } } // } // if (sscanf(request, "/admin.cgi?pass=%s&action=delete&listpos=%d", suppliedPass, &playlistpos) == 2) { if (action == 1) { if (strlen(g_AdminPassword) > 0) { if (!strcmp(suppliedPass, g_AdminPassword)) { *adminFlag = 1; if (playlistpos-1 <= RequestQueue.GetUpperBound()) { RequestQueue.RemoveAt(RequestQueue.GetUpperBound() - playlistpos + 1); errorCode = DELETE_ACCEPTED; } else { errorCode = ERR_POSITION_OUT_OF_RANGE; } } else { *adminFlag = 0; errorCode = ERR_BAD_PASSWORD; } } char location[1024] = ""; if (strlen(m_Referrer) > 0) { if (errorCode == 0) { _snprintf(location, sizeof(location)-1, "Location: %s", m_Referrer); } else { _snprintf(location, sizeof(location)-1, "Location: %s&errorCode=%d", m_Referrer, errorCode); } } else { if (errorCode == 0) { _snprintf(location, sizeof(location)-1, "Location: /playlist.cgi"); } else { _snprintf(location, sizeof(location)-1, "Location: /playlist.cgi?errorCode=%d", errorCode); } } send_headers(302, "Moved Temporarily", (char*) location, 0, -1, -1 ); } if (strlen(g_AdminPassword) > 0) { if (!strcmp(suppliedPass, g_AdminPassword)) { *adminFlag = 1; } else { *adminFlag = 0; } } return; // if (sscanf(request, "/admin.cgi?pass=%s&errorCode=%d", suppliedPass, &errorCode) == 2) { }
// Call triangle to order segments on the boundary properly BOOL ChdrawDoc::FunnyOnWritePoly() { FILE *fp; int i,j,k,l,t,n,n0,n1,n2; double z,R,dL; CComplex a0,a1,a2,c; CComplex b0,b1,b2; char instring[1024]; CString s; CArray< CNode, CNode&> nodelst; CArray< CSegment, CSegment&> linelst; CArray< CArcSegment, CArcSegment&> arclst; CArray< CBlockLabel, CBlockLabel&> blocklst; CArray< CPeriodicBoundary, CPeriodicBoundary&> pbclst; CArray< CCommonPoint, CCommonPoint& >ptlst; CNode node; CSegment segm; CPeriodicBoundary pbc; CCommonPoint pt; nodelst.RemoveAll(); linelst.RemoveAll(); pbclst.RemoveAll(); ptlst.RemoveAll(); UpdateUndo(); // calculate length used to kludge fine meshing near input node points for (i=0,z=0;i<linelist.GetSize();i++) { a0.Set(nodelist[linelist[i].n0].x,nodelist[linelist[i].n0].y); a1.Set(nodelist[linelist[i].n1].x,nodelist[linelist[i].n1].y); z += (abs(a1-a0)/((double) linelist.GetSize())); } dL=z/LineFraction; // copy node list as it is; for(i=0;i<nodelist.GetSize();i++) nodelst.Add(nodelist[i]); // discretize input segments for(i=0;i<linelist.GetSize();i++) { // abuse the IsSelected flag to carry a notation // of which line or arc in the input geometry a // particular segment is associated with segm=linelist[i]; segm.IsSelected=i; a0.Set(nodelist[linelist[i].n0].x,nodelist[linelist[i].n0].y); a1.Set(nodelist[linelist[i].n1].x,nodelist[linelist[i].n1].y); if (linelist[i].MaxSideLength==-1) k=1; else{ z=abs(a1-a0); k=(int) ceil(z/linelist[i].MaxSideLength); } if (k==1) // default condition where discretization on line is not specified { if ((abs(a1-a0)<(3.*dL)) || (!theApp.d_SmartMesh)) linelst.Add(segm); // line is too short to add extra points else{ // add extra points at a distance of dL from the ends of the line. // this forces Triangle to finely mesh near corners for(j=0;j<3;j++) { if(j==0) { a2=a0+dL*(a1-a0)/abs(a1-a0); node.x=a2.re; node.y=a2.im; l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=linelist[i].n0; segm.n1=l; linelst.Add(segm); } if(j==1) { a2=a1+dL*(a0-a1)/abs(a1-a0); node.x=a2.re; node.y=a2.im; l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=l-1; segm.n1=l; linelst.Add(segm); } if(j==2) { l=(int) nodelst.GetSize()-1; segm.n0=l; segm.n1=linelist[i].n1; linelst.Add(segm); } } } } else{ for(j=0;j<k;j++) { a2=a0+(a1-a0)*((double) (j+1))/((double) k); node.x=a2.re; node.y=a2.im; if(j==0){ l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=linelist[i].n0; segm.n1=l; linelst.Add(segm); } else if(j==(k-1)) { l=(int) nodelst.GetSize()-1; segm.n0=l; segm.n1=linelist[i].n1; linelst.Add(segm); } else{ l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=l-1; segm.n1=l; linelst.Add(segm); } } } } // discretize input arc segments for(i=0;i<arclist.GetSize();i++) { segm.IsSelected=i+(int) linelist.GetSize(); a2.Set(nodelist[arclist[i].n0].x,nodelist[arclist[i].n0].y); k=(int) ceil(arclist[i].ArcLength/arclist[i].MaxSideLength); segm.BoundaryMarker=arclist[i].BoundaryMarker; segm.InConductor=arclist[i].InConductor; GetCircle(arclist[i],c,R); a1=exp(I*arclist[i].ArcLength*PI/(((double) k)*180.)); if(k==1){ segm.n0=arclist[i].n0; segm.n1=arclist[i].n1; linelst.Add(segm); } else for(j=0;j<k;j++) { a2=(a2-c)*a1+c; node.x=a2.re; node.y=a2.im; if(j==0){ l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=arclist[i].n0; segm.n1=l; linelst.Add(segm); } else if(j==(k-1)) { l=(int) nodelst.GetSize()-1; segm.n0=l; segm.n1=arclist[i].n1; linelst.Add(segm); } else{ l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=l-1; segm.n1=l; linelst.Add(segm); } } } // create correct output filename; CString pn = GetPathName(); CString plyname=pn.Left(pn.ReverseFind('.')) + ".poly"; // check to see if we are ready to write a datafile; if ((fp=fopen(plyname,"wt"))==NULL){ MsgBox("Couldn't write to specified .poly file"); Undo(); UnselectAll(); return FALSE; } // write out node list fprintf(fp,"%i 2 0 1\n",nodelst.GetSize()); for(i=0;i<nodelst.GetSize();i++) { fprintf(fp,"%i %.17g %.17g %i\n", i,nodelst[i].x,nodelst[i].y,0); } // write out segment list fprintf(fp,"%i 1\n",linelst.GetSize()); for(i=0;i<linelst.GetSize();i++) { t=-(linelst[i].IsSelected+2); fprintf(fp,"%i %i %i %i\n",i,linelst[i].n0,linelst[i].n1,t); } // write out list of holes; for(i=0,j=0;i<blocklist.GetSize();i++) if(blocklist[i].BlockType=="<No Mesh>") j++; fprintf(fp,"%i\n",j); for(i=0,k=0;i<blocklist.GetSize();i++) if(blocklist[i].BlockType=="<No Mesh>") { fprintf(fp,"%i %.17g %.17g\n",k,blocklist[i].x,blocklist[i].y); k++; } // figure out a good default mesh size for block labels where // mesh size isn't explicitly specified CComplex xx,yy; double DefaultMeshSize; if (nodelst.GetSize()>1) { xx=nodelst[0].CC(); yy=xx; for(k=0;k<nodelst.GetSize();k++) { if (nodelst[k].x<Re(xx)) xx.re=nodelst[k].x; if (nodelst[k].y<Im(xx)) xx.im=nodelst[k].y; if (nodelst[k].x>Re(yy)) yy.re=nodelst[k].x; if (nodelst[k].y>Im(yy)) yy.im=nodelst[k].y; } DefaultMeshSize=pow((double)(abs(yy - xx) / BoundingBoxFraction), (double)2); if (!theApp.d_SmartMesh) DefaultMeshSize=abs(yy-xx); } else DefaultMeshSize=-1; // write out regional attributes fprintf(fp,"%i\n",blocklist.GetSize()-j); for(i=0,k=0;i<blocklist.GetSize();i++) if(blocklist[i].BlockType!="<No Mesh>") { fprintf(fp,"%i %.17g %.17g ",k,blocklist[i].x,blocklist[i].y); fprintf(fp,"%i ",k+1); if ((blocklist[i].MaxArea>0) && (blocklist[i].MaxArea<DefaultMeshSize)) fprintf(fp,"%.17g\n",blocklist[i].MaxArea); else fprintf(fp,"%.17g\n",DefaultMeshSize); k++; } fclose(fp); //call triangle CString rootname="\"" + pn.Left(pn.ReverseFind('.')) + "\""; char CommandLine[512]; sprintf(CommandLine,"\"%striangle.exe\" -p -P -q%f -e -A -a -z -Q -I %s", BinDir,MinAngle,rootname); STARTUPINFO StartupInfo = {0}; PROCESS_INFORMATION ProcessInfo; StartupInfo.cb = sizeof(STARTUPINFO); StartupInfo.dwFlags = STARTF_USESHOWWINDOW; StartupInfo.wShowWindow = SW_SHOWNOACTIVATE|SW_MINIMIZE; if (CreateProcess(NULL,CommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &StartupInfo, &ProcessInfo)){ if(bLinehook==FALSE) WaitForSingleObject(ProcessInfo.hProcess, INFINITE); else{ DWORD ExitCode; hProc=ProcessInfo.hProcess; do{ GetExitCodeProcess(ProcessInfo.hProcess,&ExitCode); ((CFemmApp *)AfxGetApp())->line_hook(lua,NULL); Sleep(1); } while(ExitCode==STILL_ACTIVE); hProc=NULL; } } else { MsgBox("Couldn't spawn triangle.exe"); Undo(); UnselectAll(); return FALSE; } DWORD ExitCode; GetExitCodeProcess( ProcessInfo.hProcess, // handle to the process &ExitCode // address to receive termination status ); CloseHandle(ProcessInfo.hProcess); CloseHandle(ProcessInfo.hThread); if (ExitCode!=0) { MsgBox("Call to triangle was unsuccessful"); Undo(); UnselectAll(); return FALSE; } //#endif // So far, so good. Now, read back in the .edge file // to make sure the points in the segments and arc // segments are ordered in a consistent way so that // the (anti)periodic boundary conditions can be applied. //read meshlines; plyname=pn.Left(pn.ReverseFind('.')) + ".edge"; if((fp=fopen(plyname,"rt"))==NULL){ MsgBox("Call to triangle was unsuccessful"); Undo(); UnselectAll(); return FALSE; } fgets(instring,1024,fp); sscanf(instring,"%i",&k); UnselectAll(); // abuse IsSelected again to keep a // tally of how many subsegments each // entity is sliced into. ptlst.SetSize(linelist.GetSize()+arclist.GetSize()); for(i=0;i<ptlst.GetSize();i++) ptlst[i].t=0; for(i=0;i<k;i++) { fgets(instring,1024,fp); sscanf(instring,"%i %i %i %i",&l,&n0,&n1,&j); if(j!=0) { j=-(j+2); // convert back to the `right' numbering // store a reference line that we can use to // determine whether or not this is a // boundary segment w/out re-running triangle. if (ptlst[j].t==0) { ptlst[j].t=1; if(n0<n1){ ptlst[j].x=n0; ptlst[j].y=n1; } else{ ptlst[j].x=n1; ptlst[j].y=n0; } } if(j<linelist.GetSize()) { // deal with segments linelist[j].IsSelected++; if((linelist[j].n0==n1) || (linelist[j].n1==n0)) { t=linelist[j].n0; linelist[j].n0=linelist[j].n1; linelist[j].n1=t; } } else{ // deal with arc segments; // Can't just flip the point order with // impunity in the arc segments, so we flip // a marker which denotes which side the // normal is on. j=j-(int) linelist.GetSize(); arclist[j].IsSelected++; if((arclist[j].n0==n1) || (arclist[j].n1==n0)) arclist[j].NormalDirection=FALSE; if((arclist[j].n0==n0) || (arclist[j].n1==n1)) arclist[j].NormalDirection=TRUE; } } } fclose(fp); // figure out which segments / arcsegments are on the // boundary and force an appropriate mesh density on // these based on how many divisions are in the first // trial meshing of the domain. // paw through the element list to find out how many // elements each reference segment appears in. If a // segment is on the boundary, it ought to appear in just // one element. Otherwise, it appears in two. plyname=pn.Left(pn.ReverseFind('.')) + ".ele"; if((fp=fopen(plyname,"rt"))==NULL){ MsgBox("Call to triangle was unsuccessful"); Undo(); UnselectAll(); return FALSE; } fgets(instring,1024,fp); sscanf(instring,"%i",&k); for(i=0;i<k;i++) { fgets(instring,1024,fp); sscanf(instring,"%i %i %i %i",&j,&n0,&n1,&n2); // Sort out the three nodes... if (n0>n1) { n=n0; n0=n1; n1=n; } if (n1>n2) { n=n1; n1=n2; n2=n; } if (n0>n1) { n=n0; n0=n1; n1=n; } // now, check to see if any of the test segments // are sides of this node... for(j=0;j<ptlst.GetSize();j++) { if ((n0==ptlst[j].x) && (n1==ptlst[j].y)) ptlst[j].t--; if ((n0==ptlst[j].x) && (n2==ptlst[j].y)) ptlst[j].t--; if ((n1==ptlst[j].x) && (n2==ptlst[j].y)) ptlst[j].t--; } } fclose(fp); // impose "new" mesh constraints on bdry arcs and segments.... for(i=0;i<linelist.GetSize();i++) { if (ptlst[i].t==0) linelist[i].MaxSideLength= LineLength(i)/((double) linelist[i].IsSelected); } for(i=0;i<arclist.GetSize();i++) { if (ptlst[i+linelist.GetSize()].t==0){ // alter maxsidelength, but do it in such // a way that it carries only 4 significant // digits. There's no use in carrying double // precision here, because it looks crappy // when you open up the arc segment to see // its properties. char kludge[32]; arclist[i].MaxSideLength= arclist[i].ArcLength/((double) arclist[i].IsSelected); sprintf(kludge,"%.1e",arclist[i].MaxSideLength); sscanf(kludge,"%lf",&arclist[i].MaxSideLength); } } ptlst.RemoveAll(); // want to impose explicit discretization only on // the boundary arcs and segments. After the meshing // is done, spacing on boundary segments should be // restored to the value that was there before meshing // was called, but the arc segments should keep the // "new" MaxSideLength--this is used in other places // and must always be consistent with the the mesh. // Now, do a shitload of checking to make sure that // the PBCs haven't been defined by the user // in a messed up way. // First, search through defined bc's for periodic ones; for(i=0;i<lineproplist.GetSize();i++) { if ((lineproplist[i].BdryFormat==4) || (lineproplist[i].BdryFormat==5)){ pbc.BdryName=lineproplist[i].BdryName; pbc.BdryFormat=lineproplist[i].BdryFormat-4; // 0 for pbc, 1 for apbc pbclst.Add(pbc); } } for(i=0;i<linelist.GetSize();i++) { for(j=0;j<pbclst.GetSize();j++) { if (pbclst[j].BdryName==linelist[i].BoundaryMarker) { // A pbc or apbc can only be applied to 2 segs // at a time. If it is applied to multiple segs // at the same time, flag it and kick it out. if (pbclst[j].nseg==2) { MsgBox("An (anti)periodic BC is assigned to more than two segments"); Undo(); UnselectAll(); return FALSE; } pbclst[j].seg[pbclst[j].nseg]=i; pbclst[j].nseg++; } } } for(i=0;i<arclist.GetSize();i++) { for(j=0;j<pbclst.GetSize();j++) { if (pbclst[j].BdryName==arclist[i].BoundaryMarker) { // A pbc or apbc can only be applied to 2 arcs // at a time. If it is applied to multiple arcs // at the same time, flag it and kick it out. if (pbclst[j].narc==2) { MsgBox("An (anti)periodic BC is assigned to more than two arcs"); Undo(); UnselectAll(); return FALSE; } pbclst[j].seg[pbclst[j].narc]=i; pbclst[j].narc++; } } } j=0; while(j<pbclst.GetSize()) { // check for a bc that is a mix of arcs and segments. // this is an error, and it should get flagged. if ((pbclst[j].nseg>0) && (pbclst[j].narc>0)) { MsgBox("Can't mix arcs and segments for (anti)periodic BCs"); Undo(); UnselectAll(); return FALSE; } // remove any periodic BC's that aren't actually in play if((pbclst[j].nseg<2) && (pbclst[j].narc<2)) pbclst.RemoveAt(j); else j++; } for(j=0;j<pbclst.GetSize();j++) { // check to see if adjoining entries are applied // to objects of compatible size/shape, and // reconcile meshing on the objects. // for segments: if(pbclst[j].nseg>0){ // make sure that lines are pretty much the same length if(fabs(LineLength(pbclst[j].seg[0]) -LineLength(pbclst[j].seg[1]))>1.e-06) { MsgBox("(anti)periodic BCs applied to dissimilar segments"); Undo(); UnselectAll(); return FALSE; } // make sure that both lines have the same spacing double len1,len2,len; len1=linelist[pbclst[j].seg[0]].MaxSideLength; len2=linelist[pbclst[j].seg[1]].MaxSideLength; if(len1<=0) len1=len2; if(len2<=0) len2=len1; len=min(len1,len2); linelist[pbclst[j].seg[0]].MaxSideLength=len; linelist[pbclst[j].seg[1]].MaxSideLength=len; } // for arc segments: if(pbclst[j].narc>0){ // make sure that arcs are pretty much the // same arc length if(fabs(arclist[pbclst[j].seg[0]].ArcLength -arclist[pbclst[j].seg[1]].ArcLength)>1.e-06) { MsgBox("(anti)periodic BCs applied to dissimilar arc segments"); Undo(); UnselectAll(); return FALSE; } // make sure that both lines have the same spacing double len1,len2,len; len1=arclist[pbclst[j].seg[0]].MaxSideLength; len2=arclist[pbclst[j].seg[1]].MaxSideLength; len=min(len1,len2); arclist[pbclst[j].seg[0]].MaxSideLength=len; arclist[pbclst[j].seg[1]].MaxSideLength=len; } } // write out new poly and write out adjacent // boundary nodes in a separate .pbc file. // kludge things a bit and use IsSelected to denote // whether or not a line or arc has already been processed. UnselectAll(); nodelst.RemoveAll(); linelst.RemoveAll(); // first, add in existing nodes for(n=0;n<nodelist.GetSize();n++) nodelst.Add(nodelist[n]); for(n=0;n<pbclst.GetSize();n++) { if (pbclst[n].nseg!=0) // if this pbc is a line segment... { int s0,s1; CNode node0,node1; s0=pbclst[n].seg[0]; s1=pbclst[n].seg[1]; linelist[s0].IsSelected=TRUE; linelist[s1].IsSelected=TRUE; // make is so that first point on first line // maps to first point on second line... t=linelist[s1].n1; linelist[s1].n1=linelist[s1].n0; linelist[s1].n0=t; // store number of sub-segments in k if (linelist[s0].MaxSideLength==-1) k=1; else{ a0=nodelist[linelist[s0].n0].CC(); a1=nodelist[linelist[s0].n1].CC(); b0=nodelist[linelist[s1].n0].CC(); b1=nodelist[linelist[s1].n1].CC(); z=abs(a1-a0); k=(int) ceil(z/linelist[s0].MaxSideLength); } // add segment end points to the list; pt.x=linelist[s0].n0; pt.y=linelist[s1].n0; pt.t=pbclst[n].BdryFormat; ptlst.Add(pt); pt.x=linelist[s0].n1; pt.y=linelist[s1].n1; pt.t=pbclst[n].BdryFormat; ptlst.Add(pt); if (k==1){ // catch the case in which the line // doesn't get subdivided. linelst.Add(linelist[s0]); linelst.Add(linelist[s1]); } else{ segm=linelist[s0]; for(j=0;j<k;j++) { a2=a0+(a1-a0)*((double) (j+1))/((double) k); b2=b0+(b1-b0)*((double) (j+1))/((double) k); node0.x=a2.re; node0.y=a2.im; node1.x=b2.re; node1.y=b2.im; if(j==0){ l=(int) nodelst.GetSize(); nodelst.Add(node0); segm.n0=linelist[s0].n0; segm.n1=l; linelst.Add(segm); pt.x=l; l=(int) nodelst.GetSize(); nodelst.Add(node1); segm.n0=linelist[s1].n0; segm.n1=l; linelst.Add(segm); pt.y=l; pt.t=pbclst[n].BdryFormat; ptlst.Add(pt); } else if(j==(k-1)) { // last subdivision--no ptlst // entry associated with this one. l=(int) nodelst.GetSize()-2; segm.n0=l; segm.n1=linelist[s0].n1; linelst.Add(segm); l=(int) nodelst.GetSize()-1; segm.n0=l; segm.n1=linelist[s1].n1; linelst.Add(segm); } else{ l=(int) nodelst.GetSize(); nodelst.Add(node0); nodelst.Add(node1); segm.n0=l-2; segm.n1=l; linelst.Add(segm); segm.n0=l-1; segm.n1=l+1; linelst.Add(segm); pt.x=l; pt.y=l+1; pt.t=pbclst[n].BdryFormat; ptlst.Add(pt); } } } } else{ // if this pbc is an arc segment... int s0,s1; int p0[2],p1[2]; CNode node0,node1; CComplex bgn0,bgn1,c0,c1,d0,d1; double r0,r1; s0=pbclst[n].seg[0]; s1=pbclst[n].seg[1]; arclist[s0].IsSelected=TRUE; arclist[s1].IsSelected=TRUE; k=(int) ceil(arclist[s0].ArcLength/arclist[s0].MaxSideLength); segm.BoundaryMarker=arclist[s0].BoundaryMarker; segm.InConductor=arclist[s0].InConductor; GetCircle(arclist[s0],c0,r0); GetCircle(arclist[s1],c1,r1); if (arclist[s0].NormalDirection==0){ bgn0=nodelist[arclist[s0].n0].CC(); d0=exp(I*arclist[s0].ArcLength*PI/(((double) k)*180.)); p0[0]=arclist[s0].n0; p0[1]=arclist[s0].n1; } else{ bgn0=nodelist[arclist[s0].n1].CC(); d0=exp(-I*arclist[s0].ArcLength*PI/(((double) k)*180.)); p0[0]=arclist[s0].n1; p0[1]=arclist[s0].n0; } if (arclist[s1].NormalDirection!=0){ bgn1=nodelist[arclist[s1].n0].CC(); d1=exp(I*arclist[s1].ArcLength*PI/(((double) k)*180.)); p1[0]=arclist[s1].n0; p1[1]=arclist[s1].n1; } else{ bgn1=nodelist[arclist[s1].n1].CC(); d1=exp(-I*arclist[s1].ArcLength*PI/(((double) k)*180.)); p1[0]=arclist[s1].n1; p1[1]=arclist[s1].n0; } // add arc segment end points to the list; pt.x=p0[0]; pt.y=p1[0]; pt.t=pbclst[n].BdryFormat; ptlst.Add(pt); pt.x=p0[1]; pt.y=p1[1]; pt.t=pbclst[n].BdryFormat; ptlst.Add(pt); if (k==1){ // catch the case in which the line // doesn't get subdivided. segm.n0=p0[0]; segm.n1=p0[1]; linelst.Add(segm); segm.n0=p1[0]; segm.n1=p1[1]; linelst.Add(segm); } else{ for(j=0;j<k;j++) { bgn0=(bgn0-c0)*d0+c0; node0.x=bgn0.re; node0.y=bgn0.im; bgn1=(bgn1-c1)*d1+c1; node1.x=bgn1.re; node1.y=bgn1.im; if(j==0){ l=(int) nodelst.GetSize(); nodelst.Add(node0); segm.n0=p0[0]; segm.n1=l; linelst.Add(segm); pt.x=l; l=(int) nodelst.GetSize(); nodelst.Add(node1); segm.n0=p1[0]; segm.n1=l; linelst.Add(segm); pt.y=l; pt.t=pbclst[n].BdryFormat; ptlst.Add(pt); } else if(j==(k-1)) { // last subdivision--no ptlst // entry associated with this one. l=(int) nodelst.GetSize()-2; segm.n0=l; segm.n1=p0[1]; linelst.Add(segm); l=(int) nodelst.GetSize()-1; segm.n0=l; segm.n1=p1[1]; linelst.Add(segm); } else{ l=(int) nodelst.GetSize(); nodelst.Add(node0); nodelst.Add(node1); segm.n0=l-2; segm.n1=l; linelst.Add(segm); segm.n0=l-1; segm.n1=l+1; linelst.Add(segm); pt.x=l; pt.y=l+1; pt.t=pbclst[n].BdryFormat; ptlst.Add(pt); } } } } } // Then, do the rest of the lines and arcs in the // "normal" way and write .poly file. // discretize input segments for(i=0;i<linelist.GetSize();i++) if(linelist[i].IsSelected==FALSE){ a0.Set(nodelist[linelist[i].n0].x,nodelist[linelist[i].n0].y); a1.Set(nodelist[linelist[i].n1].x,nodelist[linelist[i].n1].y); if (linelist[i].MaxSideLength==-1) k=1; else{ z=abs(a1-a0); k=(int) ceil(z/linelist[i].MaxSideLength); } segm=linelist[i]; if (k==1) // default condition where discretization on line is not specified { if ((abs(a1-a0)<(3.*dL)) || (!theApp.d_SmartMesh)) linelst.Add(segm); // line is too short to add extra points else{ // add extra points at a distance of dL from the ends of the line. // this forces Triangle to finely mesh near corners for(j=0;j<3;j++) { if(j==0) { a2=a0+dL*(a1-a0)/abs(a1-a0); node.x=a2.re; node.y=a2.im; l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=linelist[i].n0; segm.n1=l; linelst.Add(segm); } if(j==1) { a2=a1+dL*(a0-a1)/abs(a1-a0); node.x=a2.re; node.y=a2.im; l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=l-1; segm.n1=l; linelst.Add(segm); } if(j==2) { l=(int) nodelst.GetSize()-1; segm.n0=l; segm.n1=linelist[i].n1; linelst.Add(segm); } } } } else{ for(j=0;j<k;j++) { a2=a0+(a1-a0)*((double) (j+1))/((double) k); node.x=a2.re; node.y=a2.im; if(j==0){ l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=linelist[i].n0; segm.n1=l; linelst.Add(segm); } else if(j==(k-1)) { l=(int) nodelst.GetSize()-1; segm.n0=l; segm.n1=linelist[i].n1; linelst.Add(segm); } else{ l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=l-1; segm.n1=l; linelst.Add(segm); } } } } // discretize input arc segments for(i=0;i<arclist.GetSize();i++) if(arclist[i].IsSelected==FALSE){ a2.Set(nodelist[arclist[i].n0].x,nodelist[arclist[i].n0].y); k=(int) ceil(arclist[i].ArcLength/arclist[i].MaxSideLength); segm.BoundaryMarker=arclist[i].BoundaryMarker; segm.InConductor =arclist[i].InConductor; GetCircle(arclist[i],c,R); a1=exp(I*arclist[i].ArcLength*PI/(((double) k)*180.)); if(k==1){ segm.n0=arclist[i].n0; segm.n1=arclist[i].n1; linelst.Add(segm); } else for(j=0;j<k;j++) { a2=(a2-c)*a1+c; node.x=a2.re; node.y=a2.im; if(j==0){ l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=arclist[i].n0; segm.n1=l; linelst.Add(segm); } else if(j==(k-1)) { l=(int) nodelst.GetSize()-1; segm.n0=l; segm.n1=arclist[i].n1; linelst.Add(segm); } else{ l=(int) nodelst.GetSize(); nodelst.Add(node); segm.n0=l-1; segm.n1=l; linelst.Add(segm); } } } // create correct output filename; pn = GetPathName(); plyname=pn.Left(pn.ReverseFind('.')) + ".poly"; // check to see if we are ready to write a datafile; if ((fp=fopen(plyname,"wt"))==NULL){ MsgBox("Couldn't write to specified .poly file"); Undo(); UnselectAll(); return FALSE; } // write out node list fprintf(fp,"%i 2 0 1\n",nodelst.GetSize()); for(i=0;i<nodelst.GetSize();i++) { // include boundary marker; for(j=0,t=0;j<nodeproplist.GetSize();j++) if(nodeproplist[j].PointName==nodelst[i].BoundaryMarker) t=j+2; // include conductor number; for(j=0;j<circproplist.GetSize();j++) if(circproplist[j].CircName==nodelst[i].InConductor) t+=((j+1)*0x10000); fprintf(fp,"%i %.17g %.17g %i\n",i,nodelst[i].x,nodelst[i].y,t); } // write out segment list fprintf(fp,"%i 1\n",linelst.GetSize()); for(i=0;i<linelst.GetSize();i++) { // include boundary marker; for(j=0,t=0;j<lineproplist.GetSize();j++) if(lineproplist[j].BdryName==linelst[i].BoundaryMarker) t=-(j+2); // include conductor number; for(j=0;j<circproplist.GetSize();j++) if(circproplist[j].CircName==linelst[i].InConductor) t-=((j+1)*0x10000); fprintf(fp,"%i %i %i %i\n",i,linelst[i].n0,linelst[i].n1,t); } // write out list of holes; for(i=0,j=0;i<blocklist.GetSize();i++) if(blocklist[i].BlockType=="<No Mesh>") j++; fprintf(fp,"%i\n",j); for(i=0,k=0;i<blocklist.GetSize();i++) if(blocklist[i].BlockType=="<No Mesh>") { fprintf(fp,"%i %.17g %.17g\n",k,blocklist[i].x,blocklist[i].y); k++; } // write out regional attributes fprintf(fp,"%i\n",blocklist.GetSize()-j); for(i=0,k=0;i<blocklist.GetSize();i++) if(blocklist[i].BlockType!="<No Mesh>") { fprintf(fp,"%i %.17g %.17g ",k,blocklist[i].x,blocklist[i].y); fprintf(fp,"%i ",k+1); if ((blocklist[i].MaxArea>0) && (blocklist[i].MaxArea<DefaultMeshSize)) fprintf(fp,"%.17g\n",blocklist[i].MaxArea); else fprintf(fp,"%.17g\n",DefaultMeshSize); k++; } fclose(fp); // Make sure to prune out any duplications in the ptlst for(k=0;k<ptlst.GetSize();k++) ptlst[k].Order(); k=0; while((k+1) < ptlst.GetSize()) { j=k+1; while(j < ptlst.GetSize()) { if((ptlst[k].x==ptlst[j].x) && (ptlst[k].y==ptlst[j].y)) ptlst.RemoveAt(j); else j++; } k++; } // used to have a check to eliminate the case where a point // and its companion are the same point--actually, this shouldn't // be a problem just to let the algorithm deal with this // as usual. // One last error check--each point must have only one companion point. // however, it would be possible to screw up in the definition of the BCs // so that this isn't the case. Look through the points to try and catch // this one. /* // let's let this check go away for a minute... for(k=0,n=FALSE;(k+1)<ptlst.GetSize();k++) { for(j=k+1;j<ptlst.GetSize();j++) { if(ptlst[k].x==ptlst[j].x) n=TRUE; if(ptlst[k].y==ptlst[j].y) n=TRUE; if(ptlst[k].x==ptlst[j].y) n=TRUE; if(ptlst[k].y==ptlst[j].x) n=TRUE; } } if (n==TRUE){ MsgBox("Nonphysical (anti)periodic boundary assignments"); Undo(); UnselectAll(); return FALSE; } */ // write out a pbc file containing a list of linked nodes plyname=pn.Left(pn.ReverseFind('.')) + ".pbc"; if ((fp=fopen(plyname,"wt"))==NULL){ MsgBox("Couldn't write to specified .pbc file"); Undo(); UnselectAll(); return FALSE; } fprintf(fp,"%i\n",ptlst.GetSize()); for(k=0;k<ptlst.GetSize();k++) fprintf(fp,"%i %i %i %i\n",k,ptlst[k].x,ptlst[k].y,ptlst[k].t); fclose(fp); // call triangle with -Y flag. rootname="\"" + pn.Left(pn.ReverseFind('.')) + "\""; sprintf(CommandLine,"\"%striangle.exe\" -p -P -q%f -e -A -a -z -Q -I -Y %s", BinDir,MinAngle,rootname); StartupInfo.cb = sizeof(STARTUPINFO); StartupInfo.dwFlags = STARTF_USESHOWWINDOW; StartupInfo.wShowWindow = SW_SHOWNOACTIVATE|SW_MINIMIZE; if (CreateProcess(NULL,CommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &StartupInfo, &ProcessInfo)){ if(bLinehook==FALSE) WaitForSingleObject(ProcessInfo.hProcess, INFINITE); else{ DWORD ExitCode; hProc=ProcessInfo.hProcess; do{ GetExitCodeProcess(ProcessInfo.hProcess,&ExitCode); ((CFemmApp *)AfxGetApp())->line_hook(lua,NULL); Sleep(1); } while(ExitCode==STILL_ACTIVE); hProc=NULL; } } else { MsgBox("Couldn't spawn triangle.exe"); Undo(); UnselectAll(); return FALSE; } GetExitCodeProcess( ProcessInfo.hProcess, // handle to the process &ExitCode // address to receive termination status ); CloseHandle(ProcessInfo.hProcess); CloseHandle(ProcessInfo.hThread); if (ExitCode!=0) { MsgBox("Call to triangle was unsuccessful"); Undo(); UnselectAll(); return FALSE; } UnselectAll(); // Now restore boundary segment discretizations that have // been mucked up in the process... for(i=0;i<linelist.GetSize();i++) linelist[i]=undolinelist[i]; // and save the latest version of the document to make sure // any changes to arc discretization get propagated into // the solution description.... OnSaveDocument(pn); return TRUE; }
void CCorruptionBlackBox::CorruptedData(uint32 nStartPos, uint32 nEndPos){ if (nEndPos - nStartPos >= EMBLOCKSIZE){ ASSERT( false ); return; } // convert pos to relative block pos uint16 nPart = nStartPos / PARTSIZE; uint32 nRelStartPos = nStartPos - nPart*PARTSIZE; uint32 nRelEndPos = nEndPos - nPart*PARTSIZE; if (nRelEndPos >= PARTSIZE){ ASSERT( false ); return; } if (nPart >= m_aaRecords.GetCount()){ //ASSERT( false ); m_aaRecords.SetSize(nPart+1); } uint32 nDbgVerifiedBytes = 0; CArray<uint32, uint32> aGuiltyClients; for (int i= 0; i < m_aaRecords[nPart].GetCount(); i++){ if (m_aaRecords[nPart][i].m_BBRStatus == BBR_NONE){ if (m_aaRecords[nPart][i].m_nStartPos >= nRelStartPos && m_aaRecords[nPart][i].m_nEndPos <= nRelEndPos){ nDbgVerifiedBytes += (m_aaRecords[nPart][i].m_nEndPos-m_aaRecords[nPart][i].m_nStartPos)+1; m_aaRecords[nPart][i].m_BBRStatus = BBR_CORRUPTED; aGuiltyClients.Add(m_aaRecords[nPart][i].m_dwIP); } else if (m_aaRecords[nPart][i].m_nStartPos < nRelStartPos && m_aaRecords[nPart][i].m_nEndPos > nRelEndPos){ // need to split it 2* uint32 nTmpEndPos1 = m_aaRecords[nPart][i].m_nEndPos; uint32 nTmpStartPos1 = nRelEndPos + 1; uint32 nTmpStartPos2 = m_aaRecords[nPart][i].m_nStartPos; uint32 nTmpEndPos2 = nRelStartPos - 1; m_aaRecords[nPart][i].m_nEndPos = nRelEndPos; m_aaRecords[nPart][i].m_nStartPos = nRelStartPos; m_aaRecords[nPart].Add(CCBBRecord(nTmpStartPos1, nTmpEndPos1, m_aaRecords[nPart][i].m_dwIP, m_aaRecords[nPart][i].m_BBRStatus)); m_aaRecords[nPart].Add(CCBBRecord(nTmpStartPos2, nTmpEndPos2, m_aaRecords[nPart][i].m_dwIP, m_aaRecords[nPart][i].m_BBRStatus)); nDbgVerifiedBytes += (m_aaRecords[nPart][i].m_nEndPos-m_aaRecords[nPart][i].m_nStartPos)+1; m_aaRecords[nPart][i].m_BBRStatus = BBR_CORRUPTED; aGuiltyClients.Add(m_aaRecords[nPart][i].m_dwIP); } else if (m_aaRecords[nPart][i].m_nStartPos >= nRelStartPos && m_aaRecords[nPart][i].m_nStartPos <= nRelEndPos){ // need to split it uint32 nTmpEndPos = m_aaRecords[nPart][i].m_nEndPos; uint32 nTmpStartPos = nRelEndPos + 1; m_aaRecords[nPart][i].m_nEndPos = nRelEndPos; m_aaRecords[nPart].Add(CCBBRecord(nTmpStartPos, nTmpEndPos, m_aaRecords[nPart][i].m_dwIP, m_aaRecords[nPart][i].m_BBRStatus)); nDbgVerifiedBytes += (m_aaRecords[nPart][i].m_nEndPos-m_aaRecords[nPart][i].m_nStartPos)+1; m_aaRecords[nPart][i].m_BBRStatus = BBR_CORRUPTED; aGuiltyClients.Add(m_aaRecords[nPart][i].m_dwIP); } else if (m_aaRecords[nPart][i].m_nEndPos >= nRelStartPos && m_aaRecords[nPart][i].m_nEndPos <= nRelEndPos){ // need to split it uint32 nTmpStartPos = m_aaRecords[nPart][i].m_nStartPos; uint32 nTmpEndPos = nRelStartPos - 1; m_aaRecords[nPart][i].m_nStartPos = nRelStartPos; m_aaRecords[nPart].Add(CCBBRecord(nTmpStartPos, nTmpEndPos, m_aaRecords[nPart][i].m_dwIP, m_aaRecords[nPart][i].m_BBRStatus)); nDbgVerifiedBytes += (m_aaRecords[nPart][i].m_nEndPos-m_aaRecords[nPart][i].m_nStartPos)+1; m_aaRecords[nPart][i].m_BBRStatus = BBR_CORRUPTED; aGuiltyClients.Add(m_aaRecords[nPart][i].m_dwIP); } } } // check if any IPs are already banned, so we can skip the test for those for(int k = 0; k < aGuiltyClients.GetCount();){ // remove doubles for(int y = k+1; y < aGuiltyClients.GetCount();){ if (aGuiltyClients[k] == aGuiltyClients[y]) aGuiltyClients.RemoveAt(y); else y++; } if (theApp.clientlist->IsBannedClient(aGuiltyClients[k])){ AddDebugLogLine(DLP_DEFAULT, false, _T("CorruptionBlackBox: Suspicous IP (%s) is already banned, skipping recheck"), ipstr(aGuiltyClients[k])); aGuiltyClients.RemoveAt(k); } else k++; } AddDebugLogLine(DLP_HIGH, false, _T("Found and marked %u recorded bytes of %u as corrupted in the CorruptionBlackBox records, %u clients involved"), nDbgVerifiedBytes, (nEndPos-nStartPos)+1, aGuiltyClients.GetCount()); if (aGuiltyClients.GetCount() > 0){ // parse all recorded data for this file to produce a statistic for the involved clients // first init arrays for the statistic CArray<uint32, uint32> aDataCorrupt; CArray<uint32, uint32> aDataVerified; aDataCorrupt.SetSize(aGuiltyClients.GetCount()); aDataVerified.SetSize(aGuiltyClients.GetCount()); for (int j = 0; j < aGuiltyClients.GetCount(); j++) aDataCorrupt[j] = aDataVerified[j] = 0; // now the parsing for (int nPart = 0; nPart < m_aaRecords.GetCount(); nPart++){ for (int i = 0; i < m_aaRecords[nPart].GetCount(); i++){ for(int k = 0; k < aGuiltyClients.GetCount(); k++){ if (m_aaRecords[nPart][i].m_dwIP == aGuiltyClients[k]){ if (m_aaRecords[nPart][i].m_BBRStatus == BBR_CORRUPTED){ // corrupted data records are always counted as at least blocksize or bigger aDataCorrupt[k] += max((m_aaRecords[nPart][i].m_nEndPos-m_aaRecords[nPart][i].m_nStartPos)+1, EMBLOCKSIZE); } else if(m_aaRecords[nPart][i].m_BBRStatus == BBR_VERIFIED){ aDataVerified[k] += (m_aaRecords[nPart][i].m_nEndPos-m_aaRecords[nPart][i].m_nStartPos)+1; } } } } } for(int k = 0; k < aGuiltyClients.GetCount(); k++){ // calculate the percentage of corrupted data for each client and ban // him if the limit is reached int nCorruptPercentage; if ((aDataVerified[k] + aDataCorrupt[k]) > 0) nCorruptPercentage = (int)(((uint64)aDataCorrupt[k]*100)/(aDataVerified[k] + aDataCorrupt[k])); else { AddDebugLogLine(DLP_HIGH, false, _T("CorruptionBlackBox: Programm Error: No records for guilty client found!")); ASSERT( false ); nCorruptPercentage = 0; } if ( nCorruptPercentage > CBB_BANTHRESHOLD){ CUpDownClient* pEvilClient = theApp.clientlist->FindClientByIP(aGuiltyClients[k]); if (pEvilClient != NULL){ AddDebugLogLine(DLP_HIGH, false, _T("CorruptionBlackBox: Banning: Found client which send %s of %s corrupted data, %s"), CastItoXBytes(aDataCorrupt[k]), CastItoXBytes((aDataVerified[k] + aDataCorrupt[k])), pEvilClient->DbgGetClientInfo()); theApp.clientlist->AddTrackClient(pEvilClient); pEvilClient->Ban(_T("Identified as sender of corrupt data")); } else{ AddDebugLogLine(DLP_HIGH, false, _T("CorruptionBlackBox: Banning: Found client which send %s of %s corrupted data, %s"), CastItoXBytes(aDataCorrupt[k]), CastItoXBytes((aDataVerified[k] + aDataCorrupt[k])), ipstr(aGuiltyClients[k])); theApp.clientlist->AddBannedClient(aGuiltyClients[k]); } } else{ CUpDownClient* pSuspectClient = theApp.clientlist->FindClientByIP(aGuiltyClients[k]); if (pSuspectClient != NULL){ AddDebugLogLine(DLP_DEFAULT, false, _T("CorruptionBlackBox: Reporting: Found client which probably send %s of %s corrupted data, but it is within the acceptable limit, %s"), CastItoXBytes(aDataCorrupt[k]), CastItoXBytes((aDataVerified[k] + aDataCorrupt[k])), pSuspectClient->DbgGetClientInfo()); theApp.clientlist->AddTrackClient(pSuspectClient); } else AddDebugLogLine(DLP_DEFAULT, false, _T("CorruptionBlackBox: Reporting: Found client which probably send %s of %s corrupted data, but it is within the acceptable limit, %s"), CastItoXBytes(aDataCorrupt[k]), CastItoXBytes((aDataVerified[k] + aDataCorrupt[k])), ipstr(aGuiltyClients[k])); } } } }
// 用户开户查询 void CCardopenConsumeView::QueryRegister(void) { CArray<NS_DAL::CCardOpenInfo, NS_DAL::CCardOpenInfo &> CardOpenDBArray; CString strSQL; strSQL.Append(_T("SELECT cardopen.*, member.classId, member.memberId, member.name, member.serialNum, member.idNumber ")); strSQL.Append(_T("FROM cardopen, member ")); strSQL.Append(_T("WHERE cardopen.memberId = member.memberId ")); strSQL.Append(_T("AND cardopen.classId = member.classId ")); strSQL.AppendFormat(_T("AND member.classId in %s "), GetCommonClassIdAsString()); strSQL.AppendFormat(_T("AND cardopen.operationDateTime BETWEEN '%s' AND '%s'") , m_StartTime.ToString(), m_EndTime.ToString()); strSQL.Append(_T(" ORDER BY cardopen.operationDateTime DESC")); CIBALog::GetInstance()->WriteFormat(CIBALog::ELT_SQL, _T("QueryRegister:%s"), strSQL); CADODBConnInfo* pDb = NULL; if (!CIBADAL::GetInstance()->GetDBConnInfo(pDb)) return; CADORecordset Rs(pDb->GetConn()); if (Rs.Open(strSQL)) { INT i = 0; while (!Rs.IsEof()) { INT nTmp = 0; CString strTmp; CCardOpenInfo CardOpenInfo; Rs.GetFieldValue(_T("serialNum"), strTmp); CardOpenInfo.SetSerialNum(strTmp); Rs.GetFieldValue(_T("name"), strTmp); CardOpenInfo.SetUserName(strTmp); Rs.GetFieldValue(_T("idNumber"), strTmp); CardOpenInfo.SetIdNumber(strTmp); Rs.GetFieldValue(_T("memberId"), nTmp); CardOpenInfo.SetMemberId(nTmp); Rs.GetFieldValue(_T("operationDateTime"), strTmp); CardOpenInfo.SetOperationDateTime(strTmp); Rs.GetFieldValue(_T("operator"), strTmp); CardOpenInfo.SetOperator(strTmp); i++; CardOpenDBArray.Add(CardOpenInfo); Rs.MoveNext(); } Rs.Close(); } pDb->Release(); for (INT ii = 0; ii < CardOpenDBArray.GetCount(); ii++) { #ifdef _DEBUG if (CardOpenDBArray.GetAt(ii).GetMemberId() == 178547) { int kkk = 0; } #endif CString strSQL; strSQL.Append(_T("SELECT returned.* ")); strSQL.Append(_T("FROM returned ")); strSQL.AppendFormat(_T("WHERE returned.memberId = '%d' AND returned.classId in %s ") , CardOpenDBArray.GetAt(ii).GetMemberId(), GetCommonClassIdAsString()); strSQL.AppendFormat(_T("AND returned.returnDate >= '%s'") , CardOpenDBArray.GetAt(ii).GetOperationDateTime()); strSQL.Append(_T(" ORDER BY returned.returnDate DESC")); CIBALog::GetInstance()->WriteFormat(CIBALog::ELT_SQL, _T("QueryReturned:%s"), strSQL); CADODBConnInfo* pDb = NULL; if (!CIBADAL::GetInstance()->GetDBConnInfo(pDb)) return; CADORecordset Rs(pDb->GetConn()); if (Rs.Open(strSQL)) { if (!Rs.IsEof()) { CardOpenDBArray.RemoveAt(ii); ii--; } Rs.Close(); } pDb->Release(); } for (INT jj = 0; jj < CardOpenDBArray.GetCount(); jj++) { INT nTmp = 0; CString strTmp; m_InfoList.InsertItem(jj, CardOpenDBArray.GetAt(jj).GetSerialNum()); m_InfoList.SetItemText(jj, 1, CardOpenDBArray.GetAt(jj).GetUserName()); m_InfoList.SetItemText(jj, 3, CardOpenDBArray.GetAt(jj).GetIdNumber()); strTmp.Format(_T("%d"), CardOpenDBArray.GetAt(jj).GetMemberId()); m_InfoList.SetItemText(jj, 4, strTmp); m_InfoList.SetItemText(jj, 5, CardOpenDBArray.GetAt(jj).GetOperationDateTime()); } CardOpenDBArray.RemoveAll(); }
void CEnumSerial::EnumSerialPorts(CArray<SSerInfo,SSerInfo&> &asi, BOOL bIgnoreBusyPorts) { // Clear the output array asi.RemoveAll(); // Use different techniques to enumerate the available serial // ports, depending on the OS we're using OSVERSIONINFO vi; vi.dwOSVersionInfoSize = sizeof(vi); if (!GetVersionEx(&vi)) { CString str; str.Format(_T("Could not get OS version. (err=%lx)"), GetLastError()); throw str; } // Handle windows 9x and NT4 specially if (vi.dwMajorVersion < 5) { if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) EnumPortsWNt4(asi); else Win9xListPorts(asi); } else { // Win2k and later support a standard API for // enumerating hardware devices. EnumPortsWdm(asi); } for (int ii=0; ii<asi.GetSize(); ii++) { SSerInfo& rsi = asi[ii]; if (bIgnoreBusyPorts) { // Only display ports that can be opened for read/write HANDLE hCom; hCom = CreateFile(rsi.strDevPath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hCom == INVALID_HANDLE_VALUE) { // It can't be opened; remove it. asi.RemoveAt(ii); ii--; continue; } else { // It can be opened! Close it and add it to the list CloseHandle(hCom); } } // Come up with a name for the device. // If there is no friendly name, use the port name. if (rsi.strFriendlyName.IsEmpty()) rsi.strFriendlyName = rsi.strPortName; // If there is no description, try to make one up from // the friendly name. if (rsi.strPortDesc.IsEmpty()) { // If the port name is of the form "ACME Port (COM3)" // then strip off the " (COM3)" rsi.strPortDesc = rsi.strFriendlyName; int startdex = rsi.strPortDesc.Find(_T(" (")); int enddex = rsi.strPortDesc.Find(_T(")")); if ( (startdex > 0) && (enddex == (rsi.strPortDesc.GetLength()-1))) rsi.strPortDesc = rsi.strPortDesc.Left(startdex); } } }
BOOL CUPnpMgr::CleanedFillupBug() { CSingleLock localLock(&m_cs, TRUE); if (FAILED(m_nat.SearchDevice())) return FALSE; HRESULT hr; USHORT usIndex; USHORT usExternalPort; CString strProtocol; CString strDesc; CString strInternalClient; CString strLocalIP; CArray<CUPnpNatMapping, const CUPnpNatMapping&> arrMapping; CUPnpNatMapping mapping; strLocalIP = GetLocalIPStr(); for (usIndex = 0; usIndex < 128; usIndex++) // 最多查询128项,以防止有些路由器可能会一直返回成功。 { hr = m_nat.GetGenericPortMappingEntry(usIndex, NULL, &usExternalPort, &strProtocol, NULL, &strInternalClient, NULL, &strDesc); if (-1 != strDesc.Find(_T("eMule ("))) // 描述里包含指定字样 { if (strInternalClient == strLocalIP) // 是本机添加的映射 m_nat.DeletePortMapping(CString(_T("")),usExternalPort, strProtocol); else { mapping.m_strInternalClient = strInternalClient; mapping.m_wExternalPort = usExternalPort; mapping.m_strProtocol = strProtocol; arrMapping.Add(mapping); } } if (FAILED(hr)) // 返回Failed结果,表示已经全部取完了。 break; } // 如果同一ip做的eMule映射超过3项,则很有可能是以前的bug所致。则清除。<begin> int i; int iMappingCount; CString strTestIp; while (! arrMapping.IsEmpty()) { strTestIp = arrMapping[0].m_strInternalClient; iMappingCount = 0; for (i = 0; i < arrMapping.GetCount(); i++) { if (strTestIp == arrMapping[i].m_strInternalClient) iMappingCount++; } for (i = arrMapping.GetCount() - 1; i >= 0; i--) { if (strTestIp == arrMapping[i].m_strInternalClient) { if (iMappingCount > 3) { m_nat.DeletePortMapping(CString(_T("")), arrMapping[i].m_wExternalPort, arrMapping[i].m_strProtocol); } arrMapping.RemoveAt(i); } } } // 如果同一ip做的eMule映射超过3项,则很有可能是以前的bug所致。则清除。<end> return TRUE; }