void CDMDialog::OnBnClickedBtnRemove() { boost::lock_guard<boost::mutex> lock(buildermtx); //DMresult << "getting remove lock" << DMendl; boost::lock_guard<boost::mutex> guard(*dialogmtx); //http://stackoverflow.com/questions/20839499/how-to-delete-selected-row-of-a-list-control-in-mfc UINT i, uSelectedCount = lst_Images.GetSelectedCount(); int nItem; DMresult << "entering selected items loop" << DMendl; for (i = 0; i < uSelectedCount; i++) { nItem = lst_Images.GetNextItem(-1, LVNI_SELECTED); ASSERT(nItem != -1); std::string sID(lst_Images.GetItemText(nItem, 1)); unsigned long id = boost::lexical_cast<unsigned long>(sID); DMresult << "about to remove" << DMendl; // remove from our std::list removeBuilder(id); // remove from list control lst_Images.DeleteItem(nItem); } }
int getObjectById(lua_State *l) { Ogre::String sID(lua_tostring(l, 1)); CPhysicsUserPointer *pObject = GameScriptParser::getSingleton().getMap()->getObjectManager().getObjectBySafeStateId(sID); unsigned int id = GameScriptParser::getSingleton().getIDOfPointerOrAdd(pObject, GameScriptParser::UserPointerData::PHYSICS_USER_POINTER); lua_pushunsigned(l,id); return 1; }
bool SIMoutput::writeGlvP (const Vector& ssol, int iStep, int& nBlock, int idBlock, const char* prefix, std::vector<PointValue>* maxVal) { if (ssol.empty()) return true; else if (!myVtf) return false; Matrix field; Vector lovec; std::vector<IntVec> sID(myProblem->getNoFields(2)); size_t i, j; int geomID = myGeomID; for (i = 0; i < myModel.size(); i++) { if (myModel[i]->empty()) continue; // skip empty patches if (msgLevel > 1) IFEM::cout <<"Writing projected solution for patch "<< i+1 << std::endl; // Evaluate the solution variables at the visualization points myModel[i]->extractNodeVec(ssol,lovec,sID.size()); if (!myModel[i]->evalSolution(field,lovec,opt.nViz)) return false; // Write out to VTF-file as scalar fields const ElementBlock* grid = myVtf->getBlock(++geomID); for (j = 0; j < field.rows() && j < sID.size(); j++) { Vector comp(field.getRow(1+j)); if (!myVtf->writeNres(comp,++nBlock,geomID)) return false; else sID[j].push_back(nBlock); if (maxVal && j < maxVal->size()) { // Update extremal values size_t indx = 0; double cmax = comp.normInf(indx); PointValue& pv = (*maxVal)[j]; if (fabs(cmax) > fabs(pv.second)) pv = std::make_pair(grid->getCoord(indx-1),cmax); } } } // Write result block identifications for (j = 0; j < sID.size() && !sID[j].empty(); j++) if (!myVtf->writeSblk(sID[j],myProblem->getField2Name(j,prefix).c_str(), ++idBlock,iStep)) return false; return true; }
SessionData::SessionData( const String& SID ): m_lastError( 0 ), m_sID( SID ), m_bInvalid( false ) { m_dataLock.item() = SafeItem( new CoreDict( new LinearDict ) ); m_dataLock.item().asDict()->bless(true); m_dataLock.item().asDict()->put( SafeItem( new CoreString( "SID" )), SafeItem(new CoreString(sID())) ); }
void CDMDialog::removeListID(unsigned long id) { int nItem = -1; int n = lst_Images.GetItemCount(); for (int i = 0; i < n; ++i) { nItem = lst_Images.GetNextItem(nItem, LVNI_ALL); ASSERT(nItem != -1); if (nItem < 0 || nItem >= n) return; std::string sID(lst_Images.GetItemText(nItem, 1)); unsigned long cID = boost::lexical_cast<unsigned long>(sID); if (cID == id) { // I think this ID is just what we currently have in 'i' lst_Images.DeleteItem(nItem); } } }
ALERROR CItemEnhancement::InitFromDesc (const CString &sDesc, CString *retsError) // InitFromDesc // // Initializes from a string of the following forms: // // {number} Interpret as a mod code // +armor:{n} Add armor special damage, where n is an item level // +hpBonus:{n} Add hp bonus. // +immunity:{s} Immunity to special damage s. // +reflect:{s} Reflects damage type s. // +regen Regenerate // +resist:{s}:{n} DamageAdj for type s set to n // +resistDamageClass:{s}:{n} DamageAdj for type s (and its next-tier mate) set to n // +resistDamageTier:{s}:{n} DamageAdj for type s (and its tier mate) set to n // +resistEnergy:{n} DamageAdj for energy damage set to n // +resistMatter:{n} DamageAdj for matter damage set to n // +shield:{n} Add shield disrupt special damage, where n is an item level // +speed:{n} Faster. n is new delay value as a percent of normal { // If the string is a number then we interpret it as a mod code. bool bFailed; DWORD dwCode = strToInt(sDesc, 0, &bFailed); if (!bFailed) { m_dwMods = dwCode; return NOERROR; } // Parse the string char *pPos = sDesc.GetASCIIZPointer(); // Expect either "+" or "-" (for disadvantage) bool bDisadvantage; if (*pPos == '+') bDisadvantage = false; else if (*pPos == '-') bDisadvantage = true; else { if (retsError) *retsError = CONSTLIT("Invalid enhancement description: expected '+' or '-'."); return ERR_FAIL; } pPos++; // Parse the enhancement name char *pStart = pPos; while (*pPos != ':' && *pPos != '\0') pPos++; CString sID(pStart, (int)(pPos - pStart)); // See if we have a value int iValue = 0; CString sValue; if (*pPos == ':') { pPos++; if (*pPos == '-' || *pPos == '+' || (*pPos >= '0' && *pPos <= '9')) iValue = strParseInt(pPos, 0, &pPos); else { char *pStart = pPos; while (*pPos != '\0' && *pPos != ':') pPos++; sValue = CString(pStart, (int)(pPos - pStart)); } } // See if we have a second value int iValue2 = 0; if (*pPos == ':') { pPos++; iValue2 = strParseInt(pPos, 0, &pPos); } // See if this is an hpBonus if (strEquals(sID, CONSTLIT("hpBonus"))) { if (bDisadvantage && iValue > 0) iValue = -iValue; if (iValue < -100) { if (retsError) *retsError = CONSTLIT("hpBonus penalty cannot exceed 100%."); return ERR_FAIL; } else if (iValue < 0) SetModCode(EncodeAX(etHPBonus | etDisadvantage, 0, -iValue)); else if (iValue == 0) SetModCode(Encode12(etStrengthen)); else if (iValue <= 1000) SetModCode(EncodeAX(etHPBonus, 0, iValue)); else { if (retsError) *retsError = CONSTLIT("hpBonus cannot exceed 1000%."); return ERR_FAIL; } } // Immunity else if (strEquals(sID, CONSTLIT("immunity"))) { if (strEquals(sValue, CONSTLIT("ionEffects"))) m_dwMods = Encode12(etImmunityIonEffects); else { SpecialDamageTypes iSpecial = DamageDesc::ConvertToSpecialDamageTypes(sValue); switch (iSpecial) { case specialRadiation: case specialBlinding: case specialEMP: case specialDeviceDamage: case specialDisintegration: case specialMomentum: case specialShieldDisrupt: case specialDeviceDisrupt: case specialShatter: { if (bDisadvantage) { if (retsError) *retsError = CONSTLIT("Disadvantage not supported."); return ERR_FAIL; } SetModImmunity(iSpecial); break; } default: { if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid immunity: %s"), sID); return ERR_FAIL; } } } } // Reflect bonus else if (strEquals(sID, CONSTLIT("reflect"))) { DamageTypes iDamageType = LoadDamageTypeFromXML(sValue); if (iDamageType == damageError) { if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid damage type: %s"), sValue); return ERR_FAIL; } SetModReflect(iDamageType); } // Regen else if (strEquals(sID, CONSTLIT("regen"))) { m_dwMods = Encode12(etRegenerate | (bDisadvantage ? etDisadvantage : 0)); } // Resist damage else if (strEquals(sID, CONSTLIT("resist"))) { DamageTypes iDamageType = LoadDamageTypeFromXML(sValue); if (iDamageType == damageError) { if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid damage type: %s"), sValue); return ERR_FAIL; } SetModResistDamage(iDamageType, iValue2); } // Resist damage else if (strEquals(sID, CONSTLIT("resistDamageClass"))) { DamageTypes iDamageType = LoadDamageTypeFromXML(sValue); if (iDamageType == damageError) { if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid damage type: %s"), sValue); return ERR_FAIL; } SetModResistDamageClass(iDamageType, iValue2); } // Resist damage tier else if (strEquals(sID, CONSTLIT("resistDamageTier"))) { DamageTypes iDamageType = LoadDamageTypeFromXML(sValue); if (iDamageType == damageError) { if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid damage type: %s"), sValue); return ERR_FAIL; } SetModResistDamageTier(iDamageType, iValue2); } // Resist energy/matter else if (strEquals(sID, CONSTLIT("resistEnergy"))) SetModResistEnergy(iValue); else if (strEquals(sID, CONSTLIT("resistMatter"))) SetModResistMatter(iValue); // Speed bonus else if (strEquals(sID, CONSTLIT("speed"))) { if (iValue <= 0) { if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid speed value: %s."), iValue); return ERR_FAIL; } else // LATER: Support min and max delay limits SetModSpeed(iValue); } // Otherwise, see if this is a special damage else { SpecialDamageTypes iSpecial = DamageDesc::ConvertToSpecialDamageTypes(sID); switch (iSpecial) { case specialArmor: case specialShieldDisrupt: { if (bDisadvantage) { if (retsError) *retsError = CONSTLIT("Disadvantage not supported."); return ERR_FAIL; } if (iValue < 1 || iValue > MAX_ITEM_LEVEL) { if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid %s damage level: %d"), sID, iValue); return ERR_FAIL; } SetModSpecialDamage(iSpecial, iValue); break; } default: { if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid enhancement name: %s"), sID); return ERR_FAIL; } } } // Done return NOERROR; }
bool SIMoutput::writeGlvS2 (const Vector& psol, int iStep, int& nBlock, double time, int idBlock, int psolComps) { if (psol.empty()) return true; // No primary solution else if (!myVtf || !myProblem) return false; else if (myProblem->getNoSolutions() < 1) return true; // No patch-level primary solution size_t nf = myProblem->getNoFields(2); if (nf < 1) return true; // No secondary solution bool haveAsol = false; if (mySol) { if (this->getNoFields() == 1) haveAsol = mySol->hasScalarSol() > 1; else haveAsol = mySol->hasVectorSol() > 1; } bool doProject = (opt.discretization == ASM::Spline || opt.discretization == ASM::SplineC1) && opt.project.find(SIMoptions::GLOBAL) != opt.project.end(); size_t sMAX = nf; if (haveAsol) sMAX += nf; if (doProject) sMAX += nf; std::vector<IntVec> sID(sMAX); std::array<IntVec,2> vID; Matrix field, pdir; Vector lovec; size_t i, j, k; int geomID = myGeomID; for (i = 0; i < myModel.size(); i++) { if (myModel[i]->empty()) continue; // skip empty patches if (msgLevel > 1) IFEM::cout <<"Writing secondary solution for patch "<< i+1 << std::endl; // Direct evaluation of secondary solution variables LocalSystem::patch = i; myProblem->initResultPoints(time,true); myModel[i]->extractNodeVec(psol,myProblem->getSolution(),psolComps,0); this->extractPatchDependencies(myProblem,myModel,i); this->setPatchMaterial(i+1); if (!myModel[i]->evalSolution(field,*myProblem,opt.nViz)) return false; myModel[i]->filterResults(field,myVtf->getBlock(++geomID)); for (j = 1, k = 0; j <= field.rows() && k < sMAX; j++) if (!myVtf->writeNres(field.getRow(j),++nBlock,geomID)) return false; else sID[k++].push_back(nBlock); // Write principal directions, if any, as vector fields size_t nPoints = field.cols(); for (j = 0; j < 2 && myProblem->getPrincipalDir(pdir,nPoints,j+1); j++) { myModel[i]->filterResults(pdir,myVtf->getBlock(geomID)); if (!myVtf->writeVres(pdir,++nBlock,geomID,this->getNoSpaceDim())) return -2; else vID[j].push_back(nBlock); } if (doProject) { // Projection of secondary solution variables (tensorial splines only) myProblem->initResultPoints(time); if (!myModel[i]->evalSolution(field,*myProblem,opt.nViz,'D')) return false; myModel[i]->filterResults(field,myVtf->getBlock(geomID)); for (j = 1; j <= field.rows() && k < sMAX; j++) if (!myVtf->writeNres(field.getRow(j),++nBlock,geomID)) return false; else sID[k++].push_back(nBlock); } if (haveAsol) { // Evaluate analytical solution variables if (msgLevel > 1) IFEM::cout <<"Writing exact solution for patch "<< i+1 << std::endl; const ElementBlock* grid = myVtf->getBlock(geomID); Vec3Vec::const_iterator cit = grid->begin_XYZ(); field.fill(0.0); for (j = 1; cit != grid->end_XYZ() && haveAsol; j++, cit++) { Vec4 Xt(*cit,time); if (mySol->hasScalarSol() == 3 || mySol->hasVectorSol() == 3) haveAsol = myProblem->evalSol(lovec,*mySol->getStressSol(),Xt); else if (this->getNoFields() == 1) haveAsol = myProblem->evalSol(lovec,*mySol->getScalarSecSol(),Xt); else haveAsol = myProblem->evalSol(lovec,*mySol->getVectorSecSol(),Xt); if (haveAsol) field.fillColumn(j,lovec); } for (j = 1; j <= field.rows() && k < sMAX && haveAsol; j++) if (!myVtf->writeNres(field.getRow(j),++nBlock,geomID)) return false; else sID[k++].push_back(nBlock); } } // Write result block identifications std::string vname("Principal direction P1"); for (i = 0; i < 2; i++, vname[vname.size()-1]++) if (!vID[i].empty()) if (!myVtf->writeVblk(vID[i],vname.c_str(),idBlock+i,iStep)) return false; const char* prefix = haveAsol ? "FE" : nullptr; for (i = j = 0; i < nf && j < sMAX && !sID[j].empty(); i++, j++) if (!myVtf->writeSblk(sID[j],myProblem->getField2Name(i,prefix).c_str(), idBlock++,iStep)) return false; if (doProject) for (i = 0; i < nf && j < sMAX && !sID[j].empty(); i++, j++) if (!myVtf->writeSblk(sID[j],myProblem->getField2Name(i,"Projected").c_str(), idBlock++,iStep)) return false; if (haveAsol) for (i = 0; i < nf && j < sMAX && !sID[j].empty(); i++, j++) if (!myVtf->writeSblk(sID[j],myProblem->getField2Name(i,"Exact").c_str(), idBlock++,iStep)) return false; return true; }
int SIMoutput::writeGlvS1 (const Vector& psol, int iStep, int& nBlock, double time, const char* pvecName, int idBlock, int psolComps, bool scalarOnly) { if (psol.empty()) return 0; else if (!myVtf) return -99; bool scalarEq = scalarOnly || this->getNoFields() == 1; size_t nVcomp = scalarEq ? 1 : this->getNoFields(); if (nVcomp > this->getNoSpaceDim()) nVcomp = this->getNoSpaceDim(); bool haveXsol = false; if (mySol) { if (scalarEq) haveXsol = mySol->getScalarSol() != nullptr; else haveXsol = mySol->getVectorSol() != nullptr; } size_t nf = scalarEq ? 1 : this->getNoFields(); size_t pMAX = haveXsol ? nf+nf : nf; std::vector<IntVec> sID(pMAX); std::array<IntVec,2> vID; Matrix field; Vector lovec; size_t i, j, k; int geomID = myGeomID; for (i = 0; i < myModel.size(); i++) { if (myModel[i]->empty()) continue; // skip empty patches if (msgLevel > 1) IFEM::cout <<"Writing primary solution for patch "<< i+1 << std::endl; // Evaluate primary solution variables myModel[i]->extractNodeVec(psol,lovec,psolComps,0); if (!myModel[i]->evalSolution(field,lovec,opt.nViz)) return -1; myModel[i]->filterResults(field,myVtf->getBlock(++geomID)); if (!scalarOnly && (nVcomp > 1 || !pvecName)) { // Output as vector field if (!myVtf->writeVres(field,++nBlock,geomID,nVcomp)) return -2; else vID[0].push_back(nBlock); } for (j = 1, k = 0; j <= field.rows() && k < pMAX; j++) if (!myVtf->writeNres(field.getRow(j),++nBlock,geomID)) return -3; else sID[k++].push_back(nBlock); if (haveXsol) { if (msgLevel > 1) IFEM::cout <<"Writing exact solution for patch "<< i+1 << std::endl; // Evaluate exact primary solution const ElementBlock* grid = myVtf->getBlock(geomID); Vec3Vec::const_iterator cit = grid->begin_XYZ(); field.fill(0.0); if (scalarEq) { const RealFunc& pSol = *mySol->getScalarSol(); for (j = 1; cit != grid->end_XYZ() && haveXsol; j++, ++cit) field(1,j) = pSol(Vec4(*cit,time)); } else { const VecFunc& pSol = *mySol->getVectorSol(); for (j = 1; cit != grid->end_XYZ() && haveXsol; j++, ++cit) field.fillColumn(j,pSol(Vec4(*cit,time)).ptr()); if (mySol->getScalarSol()) { cit = grid->begin_XYZ(); const RealFunc& sSol = *mySol->getScalarSol(); for (j = 1; cit != grid->end_XYZ() && haveXsol; j++, ++cit) field(field.rows(),j) = sSol(Vec4(*cit,time)); } } for (j = 1; j <= field.rows() && k < pMAX && haveXsol; j++) if (!myVtf->writeNres(field.getRow(j),++nBlock,geomID)) return -3; else sID[k++].push_back(nBlock); if (!myVtf->writeVres(field,++nBlock,geomID,nVcomp)) return -2; else vID[1].push_back(nBlock); } } // Write result block identifications bool ok = true; std::string pname(pvecName ? pvecName : "Solution"); for (i = 0; i < 2 && ok; i++) if (!vID[i].empty()) { std::string vname(i == 1 ? "Exact " + pname : pname); if (pvecName) ok = myVtf->writeVblk(vID[i],vname.c_str(),idBlock+i,iStep); else ok = myVtf->writeDblk(vID[i],vname.c_str(),idBlock+i,iStep); } if (idBlock <= (int)this->getNoSpaceDim()) idBlock = this->getNoSpaceDim()+1; // Since we might have written BCs above std::vector<std::string> xname; if (haveXsol) xname.reserve(nf); if (nf > 1) pname += "_w"; for (i = j = 0; i < nf && j < pMAX && !sID[j].empty() && ok; i++) { if (myProblem && (!pvecName || nf > nVcomp)) pname = myProblem->getField1Name(i); else if (nf > 1) (*pname.rbegin()) ++; ok = myVtf->writeSblk(sID[j++],pname.c_str(),idBlock++,iStep); if (haveXsol) xname.push_back("Exact " + pname); } for (i = 0; i < xname.size() && j < pMAX && !sID[j].empty() && ok; i++) ok = myVtf->writeSblk(sID[j++],xname[i].c_str(),idBlock++,iStep); return ok ? idBlock : -4; }