bool FormularModel::setData(const QModelIndex &index, const QVariant &value, int role) { if(index.isValid() && role == Qt::EditRole) { FieldData *field = m_formularData.at(index.row()); if(field != NULL) { switch(field->getType()) { case FieldData::Integer: case FieldData::Real: case FieldData::Boolean: case FieldData::String: case FieldData::Unused: { delete field; break; } case FieldData::Scalable: { delete static_cast<FieldScalable*>(field); break; } case FieldData::Enumeration: { delete static_cast<FieldEnumeration*>(field); break; } case FieldData::Constant: { delete static_cast<FieldConstant*>(field); break; } } } m_formularData.replace(index.row(), (FieldData*)value.toInt()); emit dataChanged(index, index); return true; } return false; }
bool FieldSelectionPanel::ItemIsMandatory(size_t index) const { if (m_lbSelected->GetCount() > index) { FieldData* data = dynamic_cast<FieldData*>(m_lbSelected->GetClientObject(index)); return data && data->IsMandatory(); } return false; }
////////////////////////////////////////////////////////////////////////// // generate seeds ////////////////////////////////////////////////////////////////////////// bool SeedGenerator::GetSeeds(int timestep, VaporFlow* vFlow, float *pSeeds, const bool bRandom, const unsigned int randomSeed, int stride) { Rake* pRake = 0; if (bRandom) pRake = new SolidRake(); else { if(rakeDimension == POINT) pRake = new PointRake(); else if(rakeDimension == LINE) pRake = new LineRake(); else if(rakeDimension == PLANE) pRake = new PlaneRake(); else if(rakeDimension == SOLID) pRake = new SolidRake(); } const vector<double>&usrExts = vFlow->getDataMgr()->GetExtents((size_t)timestep); if(bRandom){ //Setup for biased distribution: //First calc min/max of field in rake. float fieldMin = 0., fieldMax=0.; vector<string>varnames; varnames.push_back(varx); varnames.push_back(vary); varnames.push_back(varz); if( distribBias != 0.){ bool rc = vFlow->getFieldMagBounds(&fieldMin, &fieldMax, varnames, true, numRefinements, timeStep); if (!rc) { return false; } } //Then set up the FieldData FieldData* fData = 0; fData = vFlow->setupFieldData(varnames, true, numRefinements, timeStep, false); if (!fData) {delete pRake; return false;} bool rc = pRake->GenSeedBiased(usrExts,distribBias,fieldMin,fieldMax, fData,numSeeds, rakeLocalMin,rakeLocalMax, pSeeds, randomSeed, stride); if (!rc) { MyBase::SetErrMsg(VAPOR_ERROR_SEEDS, "Unable to generate requested number of random seed points.\nEnsure the rake overlaps valid field data\nor choose a smaller bias."); delete fData; delete pRake; return false; } if (fData) {fData->releaseData(vFlow->getDataMgr()); delete fData; } } else pRake->GenSeedRegular(usrExts,numSeeds, rakeLocalMin, rakeLocalMax, pSeeds, stride); delete pRake; return true; }
void Projection::applyProjection(FieldData& a_velocity) { // this is const so it should only modify a_velocity /* * From the project handout, we have: * P = I - grad(DELTA^-1)div * * Discretized, we have: * P^h = I - (grad^h)((DELTA^h)^-1)div^h * (DELTA^h)(phi^h)_i = (1/(4h^2))(-4phi_i + phi_(i+e^0) + phi_(i-e^0) + phi_(i+e^1) + phi_(i-e^1)) * * After some conversation, it seems we will use: * Box vBox(a_velocity.m_grid) * MDArray<Real> R(vBox) <---- prepare for divergence calculation * divergence(R, a_velocity) <---- stores divergence in R * m_solver.solve(R) <---- gives (DELTA^-1 div) in R * MDArray<Real> Rghost(vBox.grow(1)) <---- prepare for gradient calculation * R.copyTo(Rghost) <---- set the data in Rghost * DeltaVelocity dv; <---- prepare for gradient * dv.init(a_velocity) <---- prepare for gradient * gradient(dv, Rghost) <---- get the gradient * * Now we have grad(DELTA^-1)div * We need to subtract this from the identity matrix. * Another way to put this is that we need to go through each index in dv and * perform 1-dv_element if the index is on the standard diagonal. * * This is slightly tricky since the indexing is a bit strange. */ // create a box that's the same as the one in a_velocity for use Box vBox(a_velocity.m_grid); a_velocity.fillGhosts(); // Create an MDArray for div, and get the divergence MDArray<Real> R(vBox); divergence(R, a_velocity); // Get DELTA^-1 div using the PoissonSolver m_solver.solve(R); // now create a ghosted box for the gradient MDArray<Real> Rghost(vBox.grow(1)); // and copy over DELTA^-1 div R.copyTo(Rghost); // need to fill ghosts on Rghost a_velocity.fillGhosts(Rghost); // And finally, get the gradient DeltaVelocity dv; dv.init(a_velocity); gradient(dv, Rghost); //a_velocity[0] -= dv[0]; //a_velocity[1] -= dv[1]; a_velocity.increment(-1.0, dv); // MDWrite(dv[0]); }
/* * This method parses a incoming string (the message is expected to be complete) * Depending on the instruction the action is undertaken. */ void SerialCommunicator::setReceivedMessage(const char* newMessage) { if (strcmp_P(newMessage, DUMP) == 0) { dumpAllFields(); } else if (strncmp_P(newMessage, GET, 4) == 0) { SerialOutput.println((__FlashStringHelper *) GET); FieldData *fieldData = FieldData::findField(newMessage + 4); if (fieldData != 0) fieldData->dump(); } else if (strncmp_P(newMessage, SET, 4) == 0) { SerialOutput.println((__FlashStringHelper *) SET); FieldData *fp = FieldData::findField(newMessage + 4); if (fp != 0) { fp->setValue(newMessage + 4 + strlen_P((const char *) fp->myClassName) + strlen_P((const char *) fp->myFieldName) + 2); fp->dump(); } } else if (strncmp_P(newMessage, SET, 3) == 0) { SerialOutput.println((__FlashStringHelper *) SET); FieldData::visitAllFields(dumpWritableData, true); } else if (strcmp_P(newMessage, LOG_HEADER) == 0) { SerialOutput.print((__FlashStringHelper *) LOG_HEADER); SerialOutput.print(FIELDSEPERATOR); FieldData::visitAllFields(logHeaderVisitor, true); SerialOutput.println(); return; } else if (strcmp_P(newMessage, LOG_VALUE) == 0) { logValue(); return; //#ifdef I_USE_RESET // } else if (strcmp_P(newMessage, RESET) == 0) // { // ForceHardReset(); //#endif } else { dumpCommands(); if ('?' != newMessage[0]) { SerialOutput.print((__FlashStringHelper *) ERROR); //Even though it is handy to see what has been send //The yun bootloader sends press ard to stop bootloader //echoing this means the bootloader receives ard //SerialOutput.println(newMessage); } return; } SerialOutput.println((__FlashStringHelper *) DONE); }
static void dumpWritableData(FieldData& fieldData) { if ((fieldData.myModFlag&MOD_WRITE)!=MOD_WRITE)return; SerialOutput.print((__FlashStringHelper *) SET); SerialOutput.print(fieldData.myClassName); SerialOutput.print(CLASSSEPERATOR); SerialOutput.print(fieldData.myFieldName); SerialOutput.print('='); SerialOutput.println(fieldData.getValue(commonlyUsedBuffer, commonlyUsedBuffersize)); }
/** Parses all the subfields looking for Camera and Viewport settings. */ void CameraManager::readConfig(FieldData* configuration){ int numViewport=0; FieldData* subfield; configuration->resetSubfields(); while(configuration->hasNextSubfield()){ subfield=configuration->getNextSubfield(); if(subfield->getFieldName()=="HMDCamera") readHMDCamera(subfield); else if(subfield->getFieldName()=="ProjectionCamera") readProjectionCamera(subfield); else if(subfield->getFieldName()=="DynamicCamera") readDynamicCamera(subfield); else if(subfield->getFieldName()=="Viewport"){ readViewport(subfield,numViewport); numViewport++; } } }
bool FormularModel::removeRows(int row, int count, const QModelIndex &parent) { if (row >= 0) { beginRemoveRows(parent, row, row + count - 1); for(int i = 0; i < count; i++) { FieldData *field = m_formularData.takeAt(row); if(field != NULL) { switch(field->getType()) { case FieldData::Integer: case FieldData::Real: case FieldData::Boolean: case FieldData::String: case FieldData::Unused: { delete field; break; } case FieldData::Scalable: { delete static_cast<FieldScalable*>(field); break; } case FieldData::Enumeration: { delete static_cast<FieldEnumeration*>(field); break; } case FieldData::Constant: { delete static_cast<FieldConstant*>(field); break; } } } } endRemoveRows(); emit dataChanged(index(row), index(row + count - 1, formularHeaderSections.size() - 1)); return true; } return false; }
static void dumpVisitor(FieldData& fieldData) { /* * If you get an error here about wdt_reset not defined and you are building for teensy * add the following to .../Arduino/hardware/teensy/avr/cores/teensyXX/avr/wdt.h * where XX is your teensy version * * #ifndef __WDT_H__ * #define __WDT_H__ * void wdt_reset() * { * #warning "wdt_reset is not implemented" * } * #endif * */ wdt_reset(); //make sure the watch dog does not trigger fieldData.dump(); }
bool BattleField::setFieldHit(int position, bool hit) { FieldData* fieldData = getFieldData(position); if(fieldData) { // Check if field is already tried if(fieldData->isTried()) return false; // Set information on the field fieldData->setIsHit(hit); fieldData->setIsTried(true); if(hit) { // Visualize a hit fieldData->setColor("#00ff00"); // Check if ship is sunken QList<FieldData*> shipFields = _fieldsById[fieldData->shipId()]; bool shipSunken = true; foreach(FieldData* field, shipFields) { shipSunken = field->isHit(); if(!shipSunken) break; } // If ship is sunken emit a signal with the new number of ships if(shipSunken) { _numberOfShips--; emit numberOfShipsChanged(_numberOfShips); foreach(FieldData* field, shipFields) { field->setHideImage(false); updateField(field->modelPosition()); } } }
static void logValueVisitor(FieldData& fieldData) { SerialOutput.print(fieldData.getValue(commonlyUsedBuffer, commonlyUsedBuffersize)); SerialOutput.print(FIELDSEPERATOR); }
QVariant FormularModel::data(const QModelIndex &index, int role) const { QVariant data = QVariant(); if(index.isValid()) { FieldData *field = m_formularData.at(index.row()); if(field != NULL) { switch(role) { case Qt::DisplayRole: { HeaderSection section = (HeaderSection)index.column(); switch(section) { case Size: { data = QVariant(field->getSize()); break; } case Type: { data = QVariant(FieldData::types.at(field->getType())); break; } case Name: { data = QVariant(field->getName()); break; } case Description: { data = QVariant(field->getDescription()); break; } } break; } case Qt::EditRole: { data = QVariant((long long int)field); break; } case Qt::ToolTipRole: { QString toolTip = QString::fromUtf8( "Размер:\t\t%size\n" "Тип:\t\t\t%type\n" "Размерность:\t\t%dimension\n" "Наименование:\t%name\n" "Описание:\t\t%description" "%additional" ); toolTip.replace("%size", QString::number(field->getSize())); toolTip.replace("%type", FieldData::types.at(field->getType())); toolTip.replace("%dimension", FieldData::dimensions.at(field->getDimension())); toolTip.replace("%name", field->getName()); toolTip.replace("%description", field->getDescription()); switch(field->getType()) { case FieldData::Integer: case FieldData::Real: case FieldData::Boolean: case FieldData::String: case FieldData::Unused: { toolTip.replace("%additional", QString()); break; } case FieldData::Scalable: { FieldScalable *fieldScalable = static_cast<FieldScalable*>(field); QString additional = QString::fromUtf8( "\n\nЦена %kind разряда:\t%order\n" "%sign" ); if(fieldScalable->hasAdditionalCode()) { additional.replace("%sign", QString::fromUtf8("Знак в дополнительном коде")); } else if(fieldScalable->hasHighBitSign()) { additional.replace("%sign", QString::fromUtf8("Знак в старшем разряде")); } else { additional.replace("%sign", QString()); } if(fieldScalable->getHighOrderBit() != 0.0) { additional.replace("%kind", QString::fromUtf8("старшего")); additional.replace("%order", QString::number(fieldScalable->getHighOrderBit())); } else if(fieldScalable->getLowerOrderBit() != 0.0) { additional.replace("%kind", QString::fromUtf8("младшего")); additional.replace("%order", QString::number(fieldScalable->getLowerOrderBit())); } else { additional = QString(); } toolTip.replace("%additional", additional); break; } case FieldData::Enumeration: { FieldEnumeration *fieldEnumeration = static_cast<FieldEnumeration*>(field); QString additional = "\n"; for(int i = 0; i < fieldEnumeration->getElements().size(); i++) { additional.append("\n%code - %transcript"); additional.replace("%code", fieldEnumeration->getElements()[i].getCode()); additional.replace("%transcript", fieldEnumeration->getElements()[i].getTranscript()); } toolTip.replace("%additional", additional); break; } case FieldData::Constant: { FieldConstant *fieldConstant = static_cast<FieldConstant*>(field); QString additional = QString::fromUtf8("\n\nКонстанта %constant"); additional.replace("%constant", fieldConstant->getValue()); toolTip.replace("%additional", additional); break; } } data = QVariant(toolTip); break; } // case Qt::SizeHintRole: { // int size = 0; // for(int i = 0; i <= index.row(); i++) { // size += index.model()->index(i, Size).data(Qt::DisplayRole).toInt(); // } // qDebug() << "Size" << size; // if(size == 16) { // data = QVariant(QSize(50,40)); // } else { // data = QVariant(QSize(50, 20)); // } // break; // } } } } return data; }
void TextFileStorage::saveToIndividualFile() { string str; ofstream file; // Declare actual field data object. FieldData* data; // Get the initial position of the internal iterator of the Datahandler. int pos = this->getInput()->getPosition(); ObjectData* objectData = NULL; if( onlyCurrent ) { // Get the current data object. objectData = getInput()->getCurrentObject(); } else { // Get the first data object. objectData = getInput()->getFirstObjectCompleted(); } // Loop over all elements in the datahandler while( objectData != NULL) { // Create the file name. stringstream integerConvertor; integerConvertor << fileNumber++; str = this->getLocation() + this->getFileName() + integerConvertor.str(); // Open the file; file.open( str.c_str() ); if( file.is_open() ) { // Loop through all fieldData elements in an objectData object. for( int j = 0; j < objectData->getSize(); j++ ) { data = objectData->getDataAt(j); switch( data->getType() ) { case typeFieldDataInt: file << data->getInt() << endl; break; case typeFieldDataFloat: file << data->getFloat() << endl; break; case typeFieldDataDouble: file << data->getDouble() << endl; break; case typeFieldDataString: file << data->getString() << endl; break; case typeFieldDataBool: if( data->getBool() ) { file << "true" << endl; } else { file << "false" << endl; } break; } } file.close(); } else { //TODO throw } if( onlyCurrent ) { // Stop the loop if only the current object is to be executed. objectData = NULL; } else { // Get the next data object. objectData = getInput()->getNextObjectCompleted(); } } // Resore the initial position of the internal Datahandler iterator. This is not as it is seposed to be. TODO alter the datahandler internal iterator. (this->getInput())->getObjectAt( pos ); // Set the output to the location of the files. this->setOutput( this->getLocation() ); };
void TextFileStorage::saveToSingleFile() { string str = this->getLocation() + this->getFileName(); ofstream file( str.c_str(), ios::app); // Get the initial position of the internal iterator of the Datahandler. int pos = this->getInput()->getPosition(); if( file.is_open() ) { ObjectData* objectData = NULL; if( onlyCurrent ) { // Get the current data object. objectData = getInput()->getCurrentObject(); } else { // Get the first data object. objectData = getInput()->getFirstObjectCompleted(); } // Declare actual field data object. FieldData* data; // Loop through all objectData elements in the Datahandler which are finched. while( objectData != NULL ) { // Start with a new object. file << "\n# BEGIN OF OBJECT\n"; // Loop through all fieldData elements in an objectData object. for( int j = 0; j < objectData->getSize(); j++ ) { data = objectData->getDataAt(j); switch( data->getType() ) { case typeFieldDataInt: file << data->getInt() << "\n"; break; case typeFieldDataFloat: file << data->getFloat() << "\n"; break; case typeFieldDataDouble: file << data->getDouble() << "\n"; break; case typeFieldDataString: file << data->getString() << "\n"; break; case typeFieldDataBool: if( data->getBool() ) { file << "true\n"; } else { file << "false\n"; } break; } } // The end of the object file << "# END OF OBJECT\n"; if( onlyCurrent ) { // Stop the loop if only the current object is to be executed. objectData = NULL; } else { // Get the next data object. objectData = getInput()->getNextObjectCompleted(); } } // Resore the initial position of the internal Datahandler iterator. This is not as it is seposed to be. TODO alter the datahandler internal iterator. getInput()->getObjectAt( pos ); // Close the file. file.close(); } else { //TODO throw } // Resore the initial position of the internal Datahandler iterator. This is not as it is seposed to be. TODO alter the datahandler internal iterator. (this->getInput())->getObjectAt( pos ); // Set the output to the full file name. this->setOutput( this->getLocation() + this->getFileName() ); };
bool FormularEditor::writeToFile(QString fileName) { QDomDocument domDocument("formular"); QDomNode xmlNode = domDocument.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); domDocument.insertBefore(xmlNode, domDocument.firstChildElement()); QDomElement domRoot; domRoot = domDocument.createElement("formular"); domRoot.setAttribute("capacity", Formular::capacities.at(ui->capacityBox->currentIndex())); domRoot.setAttribute("description", ui->descriptionEdit->toPlainText()); domDocument.appendChild(domRoot); for(int i = 0; i < m_formularModel->rowCount(); i++) { QDomElement domField = domDocument.createElement("field"); domRoot.appendChild(domField); FieldData *field = (FieldData*)m_formularModel->data(m_formularModel->index(i), Qt::EditRole).toInt(); domField.setAttribute("name", field->getName()); domField.setAttribute("description", field->getDescription()); domField.setAttribute("type", FieldData::types.at(field->getType())); domField.setAttribute("dimension", FieldData::dimensions.at(field->getDimension())); domField.setAttribute("size", field->getSize()); switch(field->getType()) { case FieldData::Integer: case FieldData::Real: case FieldData::Boolean: case FieldData::String: case FieldData::Unused: { break; } case FieldData::Scalable: { FieldScalable *fieldScalable = static_cast<FieldScalable*>((FieldData*)m_formularModel->data(m_formularModel->index(i), Qt::EditRole).toInt()); domField.setAttribute("highOrderBit", fieldScalable->getHighOrderBit()); domField.setAttribute("lowerOrderBit", fieldScalable->getLowerOrderBit()); domField.setAttribute("additionalCode", fieldScalable->hasAdditionalCode()); domField.setAttribute("highBitSign", fieldScalable->hasHighBitSign()); break; } case FieldData::Enumeration: { FieldEnumeration *fieldEnumeration = static_cast<FieldEnumeration*>((FieldData*)m_formularModel->data(m_formularModel->index(i), Qt::EditRole).toInt()); for (int j = 0; j < fieldEnumeration->getElements().size(); j++) { QDomElement domEnumerationElement = domDocument.createElement("element"); domField.appendChild(domEnumerationElement); domEnumerationElement.setAttribute("code", fieldEnumeration->getElements()[j].getCode()); domEnumerationElement.setAttribute("acronym", fieldEnumeration->getElements()[j].getAcronym()); domEnumerationElement.setAttribute("transcript", fieldEnumeration->getElements()[j].getTranscript()); } break; } case FieldData::Constant: { FieldConstant *fieldConstant = static_cast<FieldConstant*>((FieldData*)m_formularModel->data(m_formularModel->index(i), Qt::EditRole).toInt()); domField.setAttribute("value", fieldConstant->getValue()); break; } } } QFile file(fileName); if(!file.open(QIODevice::WriteOnly)) return false; QTextStream st(&file); domDocument.save(st, 4); file.close(); return true; }