void SpecificWorker::manageRestPositionEdge(const RoboCompJointMotor::MotorStateMap &mMap) { QMutexLocker locker(mutex); if (isInRestPosition(mMap)) // We should make sure the link is there { printf("IN REST\n"); try { AGMModelEdge e = worldModel->getEdgeByIdentifiers(1, 1, "restArm"); } catch (...) { AGMModel::SPtr newModel(new AGMModel(worldModel)); newModel->addEdgeByIdentifiers(1, 1, "restArm"); sendModificationProposal(newModel, worldModel); } } else // We should make sure the edge is removed { printf("NOT IN REST\n"); try { AGMModelEdge e = worldModel->getEdgeByIdentifiers(1, 1, "restArm"); AGMModel::SPtr newModel(new AGMModel(worldModel)); newModel->removeEdgeByIdentifiers(1, 1, "restArm"); sendModificationProposal(newModel, worldModel); } catch (...) { } } }
unique_ptr<Model> newModel() { #ifdef BULLET_COLLISION return newModel(BULLET); #else return newModel(NONE); #endif }
/** ***************************************************************************/ void ExtensionManager::startQuery(const QString &searchTerm) { // Trim spaces QString trimmedTerm = searchTerm.trimmed(); // Ignore empty queries if (trimmedTerm.isEmpty()){ emit newModel(nullptr); return; } _currentQuery = std::make_shared<Query>(trimmedTerm); // ▼ TODO INTRODUCE MULTITHREADING HERE ▼ // Check if the query is prefixed with a trigger bool queryIsTriggered = false; QString potentialTrigger = trimmedTerm.section(' ', 0,0); for (IExtension *e : _extensions){ if (e->isTriggered()){ for (const QString& trigger : e->triggers()){ if (trigger==potentialTrigger){ e->handleQuery(_currentQuery); queryIsTriggered=true; } } } } // If it is triggered skip the full and fallback query if (queryIsTriggered){ emit newModel(_currentQuery->impl); return; } // Full query for (IExtension *e : _extensions) e->handleQuery(_currentQuery); // Fallback query if results are empty if (_currentQuery->impl->matches_.size()==0) for (IExtension *e : _extensions) e->handleFallbackQuery(_currentQuery); else // This is a conceptual hack for v0.7, the query should sor itself when the // remove friend query and query_p std::stable_sort(_currentQuery->impl->matches_.begin(), _currentQuery->impl->matches_.end(), [](const Match &lhs, const Match &rhs) { return lhs.score > rhs.score; }); // ▲ INTRODUCE MULTITHREADING HERE ▲ emit newModel(_currentQuery->impl); }
void SpecificWorker::ballCentered() { int32_t ball = atoi(params["b"].value.c_str()); int32_t robot = atoi(params["r"].value.c_str()); try { const float tx = str2float(worldModel->getSymbol(ball)->getAttribute("tx")); const float ty = str2float(worldModel->getSymbol(ball)->getAttribute("ty")); const float tz = str2float(worldModel->getSymbol(ball)->getAttribute("tz")); QVec poseTr = innerModel->transform("world", QVec::vec3(tx, ty, tz), "robot"); printf("gooooooo saccadic3D T=(%.2f, %.2f, %.2f)\n", poseTr(0), poseTr(1), poseTr(2)); saccadic3D(poseTr, QVec::vec3(0,-1,0)); /// Include "fixates" edge AGMModel::SPtr newModel(new AGMModel(worldModel)); newModel->addEdgeByIdentifiers(robot, ball, "fixates"); sendModificationProposal(worldModel, newModel); } catch(AGMModelException &e) { try { speech_proxy->say("acho, pasó algo raro con centered", true); } catch(AGMModelException &e) { printf("acho, pasó algo raro con speech en algo raro con centered\n"); } printf("I don't know object %d\n", ball); } }
void OSPlugin::newForSender() { LOG(Trace, "newForSender"); QObject* sender = this->sender(); OSDocument* osDocument = qobject_cast<OSDocument*>(sender); OS_ASSERT(osDocument); boost::optional<std::string> key = getKeyForDocument(osDocument); OS_ASSERT(key); if( !closeDocument(*key) ) { return; } openstudio::model::Model model = openstudio::model::exampleModel(); boost::shared_ptr<OSDocument> document( new OSDocument(model, model, openstudio::path(), boost::optional<openstudio::model::Model>(), "", true) ); connectDocumentSignals(document.get()); m_startupView->hide(); m_osDocuments.insert(std::make_pair<std::string, boost::shared_ptr<OSDocument> >(*key, document)); emit newModel(*key, document->model().getImpl<openstudio::model::detail::Model_Impl>().get()); emit documentShown(*key); }
void SpecificWorker::action_TellHumanAboutCoffeePot() { static bool first = true; static QTime lastTime = QTime::currentTime(); if (lastTime.elapsed() < 5000 and not first) return; first = false; lastTime = QTime::currentTime(); AGMModel::SPtr newModel(new AGMModel(worldModel)); try { auto symbols = newModel->getSymbolsMap(params, "person", "objectr", "conth"); // // BEFORE SUBMITTING A NEW MODIFICATION... BE SURE WE DON'T DO IT TWICE! { for (auto objEdgIt : *(symbols["objectr"])) { if (objEdgIt->getLabel() == "eq") { // We already told him!? :-? (Maybe we're too fast! :-D) return; } } } speech_proxy->say("This is a coffeepot.", false); while(speech_proxy->isBusy()) usleep(100000); // AGMModelSymbol::SPtr newObjH = newModel->newSymbol("object"); AGMModelSymbol::SPtr newObjHStatus = newModel->newSymbol("objectSt"); newModel->addEdge( symbols["person"], newObjH, "know"); newModel->addEdge(symbols["objectr"], newObjH, "eq"); newModel->addEdge( newObjH, symbols["conth"], "in"); newModel->addEdge( newObjH, newObjHStatus, "hasStatus"); newModel->addEdge( newObjH, newObjHStatus, "position"); newModel->addEdge( newObjH, newObjHStatus, "classified"); newModel->addEdge( newObjH, newObjHStatus, "coffeepot"); newModel->addEdge( newObjH, newObjHStatus, "see"); newModel->addEdge( newObjH, newObjHStatus, "reach"); newModel->addEdge( newObjH, newObjHStatus, "reachable"); try { sendModificationProposal(worldModel, newModel); } catch(...) { printf("Some error occurred when publishing the new model\n"); } } catch(...) { printf("Some error occurred when retrieving action's parameters\n"); } }
void MainWindow::on_actionOpen_triggered() { QString imageFilename = QFileDialog::getOpenFileName(this, "Open File", "."); if (imageFilename.length() > 0) { newModel(); openImage(imageFilename); } }
void SpecificWorker::compute( ) { // Create a copy of the model bool modelWasModified = false; AGMModel::SPtr newModel(new AGMModel(worldModel)); // Update InnerModel updateInnerModel(newModel); // Remove unseen tags from map removeUnseenTags(newModel); // Get the symbol of the robot and its status (just in case) int32_t statusId = newModel->getIdentifierByType("status"); int32_t robotId = newModel->getIdentifierByType("robot"); if (robotId == -1 or statusId == -1) { printf("didn't find the robot or its status!!\n"); return; } AGMModelSymbol::SPtr robot = newModel->getSymbol(robotId); // Include or update tags in the model includeOrUpdateTags(newModel, modelWasModified); // Remove balls which have not been seen in a while for (AGMModel::iterator itModel=worldModel->begin(); itModel!=worldModel->end(); itModel++) { if (itModel->symbolType == "ball") { bool found = false; for (TagModelMap::iterator itMap=tagMap.begin(); itMap!=tagMap.end(); itMap++) { if (itMap->second.id == str2int(itModel->attributes["id"])) { found = true; break; } } if (not found) { modelWasModified = true; newModel->removeSymbol(itModel->identifier); if (newModel->removeEdgeByIdentifiers(robotId, statusId, "happy")) newModel->addEdgeByIdentifiers(robotId, statusId, "bored"); newModel->removeDanglingEdges(); } } } // Send modification if needed if (modelWasModified) { sendModificationProposal(worldModel, newModel); } }
void SpecificWorker::action_handObject_offer(bool first) { static QTime time; static bool localFirst=true; if (localFirst) { time = QTime::currentTime(); time.addSecs(-1000); localFirst = false; } // Lock mutex and get a model's copy QMutexLocker locker(mutex); AGMModel::SPtr newModel(new AGMModel(worldModel)); // Get action parameters try { symbols = newModel->getSymbolsMap(params, "object", "person", "status"); } catch(...) { printf("graspingAgent: Couldn't retrieve action's parameters\n"); } // Attempt to get the 'offered' edge, in which case we're done try { newModel->getEdge(symbols["object"], symbols["person"], "offered"); return; } catch(...) { } // Attempt to get the person "reach" edge. Proceed if successfull. try { // Get the person "reach" edge. newModel->getEdge(symbols["person"], symbols["status"], "reach"); // Make the robot speak if (/*first or */time.elapsed() > 15000) { time = QTime::currentTime(); speech_proxy->say("Aquii tienes",false); } // Make the action noticeable in the model. newModel->addEdge(symbols["object"], symbols["person"], "offered"); // Publish the modification sendModificationProposal(worldModel, newModel); } catch(...) { // Edge not present yet or some error raised. Try again in a few milliseconds. } }
void MainWindow::on_actionClose_triggered() { QString imageFile = mYaffsModel->getImageFilename(); if (imageFile.length() > 0) { newModel(); mUi->statusBar->showMessage("Closed image file: " + imageFile); } mUi->linePath->clear(); updateWindowTitle(); setupActions(); }
void Subscribe::registerModels() { auto subscriptionModel = newModel("subscription", 0, QDate(2015, 9, 18)); subscriptionModel->addField("gid", ModelField::Integer).notNull(); subscriptionModel->addField("uid", ModelField::Integer).notNull(); subscriptionModel->addField("subscribed_on", ModelField::Timestamp); subscriptionModel->addUniqueIndex("gid", "uid"); subscriptionModel->addIndex("gid"); subscriptionModel->registerModel(); }
bool LocationModelManager::linkAgents(AgentId srcAgentId, AgentId dstAgentId) { Agent *src = mLevel->agentMan()->getAgent(srcAgentId); Agent *dst = mLevel->agentMan()->getAgent(dstAgentId); if(nullptr == src || nullptr == dst) { Debug::error("LocationModelManager::linkAgents(): an agent id is invalid: src=") (srcAgentId)(", dst:")(dstAgentId)(". Aborting.").endl(); return false; } // allocate new models for agents if necessary if(INVALID_ID == src->locationModelId()) src->linkToModel(ModelType::LOCATION, newModel()); if(INVALID_ID == dst->locationModelId()) dst->linkToModel(ModelType::LOCATION, newModel()); return linkLocations(src->locationModelId(), dst->locationModelId()); }
void SpecificWorker::action_TellHumanAboutMug() { static bool first = true; static QTime lastTime = QTime::currentTime(); if (lastTime.elapsed() < 5000 and not first) return; first = false; lastTime = QTime::currentTime(); printf("SpecificWorker::action_TellHumanAboutMug()\n"); AGMModel::SPtr newModel(new AGMModel(worldModel)); try { try { speech_proxy->say("This is a mug.", false); while(speech_proxy->isBusy()) usleep(100000); } catch(...) { printf("couldn't speak!!"); } auto symbols = newModel->getSymbolsMap(params, "person", "objectr", "conth"); AGMModelSymbol::SPtr newObjH = newModel->newSymbol("object"); AGMModelSymbol::SPtr newObjHStatus = newModel->newSymbol("objectSt"); newModel->addEdge( symbols["person"], newObjH, "know"); newModel->addEdge(symbols["objectr"], newObjH, "eq"); newModel->addEdge( newObjH, symbols["conth"], "in"); newModel->addEdge( newObjH, newObjHStatus, "hasStatus"); newModel->addEdge( newObjH, newObjHStatus, "position"); newModel->addEdge( newObjH, newObjHStatus, "classified"); newModel->addEdge( newObjH, newObjHStatus, "mug"); newModel->addEdge( newObjH, newObjHStatus, "see"); newModel->addEdge( newObjH, newObjHStatus, "reach"); newModel->addEdge( newObjH, newObjHStatus, "reachable"); try { sendModificationProposal(worldModel, newModel); } catch(...) { printf("Some error occurred when publishing the new model\n"); } } catch(...) { printf("Some error occurred when retrieving action's parameters\n"); } }
void OSPlugin::openForSender() { LOG(Trace, "openForLastKey"); QObject* sender = this->sender(); OSDocument* osDocument = qobject_cast<OSDocument*>(sender); OS_ASSERT(osDocument); boost::optional<std::string> key = getKeyForDocument(osDocument); OS_ASSERT(key); QString fileName = QFileDialog::getOpenFileName( m_sketchUpWidget, tr("Open"), QDir::homePath(), tr("(*.osm)") ); if( !(fileName == "") ){ boost::optional<IdfFile> idfFile; idfFile = openstudio::IdfFile::load(toPath(fileName),IddFileType::OpenStudio); if( idfFile ){ if( !closeDocument(*key) ) { return; } IdfFile _idfFile = idfFile.get(); model::Model model(_idfFile); m_startupView->hide(); processEvents(); boost::shared_ptr<OSDocument> document( new OSDocument(model, model, openstudio::path(), boost::optional<openstudio::model::Model>(), fileName, true) ); connectDocumentSignals(document.get()); m_osDocuments.insert(std::make_pair<std::string, boost::shared_ptr<OSDocument> >(*key, document)); emit newModel(*key, document->model().getImpl<openstudio::model::detail::Model_Impl>().get()); emit documentShown(*key); } } }
void ThothWindow::on_colorButton_clicked() { ModelInfo mi; int pos = ui->buttonGroup->checkedId(); int texture; popUp->setText(""); if(pos != -1) { switch(pos) { case -2: qDebug() << "Pressed 1"; mi.textureName.color.c1 = CPoint3D(m_color.red()/255.f, m_color.green()/255.f, m_color.blue()/255.f); mi.textureName.material.M1 = textureName; texture = 1; break; case -4: qDebug() << "Pressed 2"; mi.textureName.color.c2 = CPoint3D(m_color.red()/255.f, m_color.green()/255.f, m_color.blue()/255.f); mi.textureName.material.M2 = textureName; texture = 2; break; case -3: qDebug() << "Pressed 3"; mi.textureName.color.c3 = CPoint3D(m_color.red()/255.f, m_color.green()/255.f, m_color.blue()/255.f); mi.textureName.material.M3 = textureName; texture = 3; break; case -5: qDebug() << "Pressed 4"; mi.textureName.color.c4 = CPoint3D(m_color.red()/255.f, m_color.green()/255.f, m_color.blue()/255.f); mi.textureName.material.M4 = textureName; texture = 4; break; } ui->statusBar->showMessage("Changing texture to the objet...", 2000); emit newModel(mi, texture); } else { popUp->setText("Select in which texture you want to put it"); } }
void RMMMobileObject::renewModels(ReliabilityMultiModel &rm) { std::deque<SpReliabilitySingleModelInterface>::iterator it, it2, it3, it_end = rm.multiModelDAG.end(), it_end2; std::map<QString, SpReliabilitySingleModelInterface> modelsMap; //Only independent models init the process. multiModel.multiModelDAG.clear(); multiModel.mobile = this; multiModel.forwardIndependentModels = rm.forwardIndependentModels; multiModel.backwardIndependentModels = rm.backwardIndependentModels; for(it=rm.multiModelDAG.begin(); it != it_end; it++) { SpReliabilitySingleModelInterface inputModel = *it; SpReliabilitySingleModelInterface newModel(VideoAnalysis::modelConstructor[inputModel->model_name]()); newModel->copy_general_structure(inputModel); newModel->general_copy(inputModel); newModel->m_mobile = this; newModel->init(); multiModel.multiModelDAG.push_back(newModel); modelsMap[newModel->name] = newModel; } //Rebuid dependences for(it=rm.multiModelDAG.begin(), it3=rm.multiModelDAG.begin(); it != it_end; it++) { SpReliabilitySingleModelInterface inputModel = *it; SpReliabilitySingleModelInterface newModel = *it3; if(!inputModel->dependences.empty()) { newModel->dependences.clear(); it_end2 = inputModel->dependences.end(); for(it2=inputModel->dependences.begin(); it2 != it_end2; it2++) newModel->dependences.push_back(modelsMap[(*it2)->name]); } if(!inputModel->dependants.empty()) { newModel->dependants.clear(); it_end2 = inputModel->dependants.end(); for(it2=inputModel->dependants.begin(); it2 != it_end2; it2++) newModel->dependants.push_back(modelsMap[(*it2)->name]); } } }
void ScreenControl::select() { _model->select(); _new->setEnabled(_mode!=View); if (_model->rowCount()) { _mapper.toFirst(); //_save->setEnabled(_mode!=View); _view->setEnabled(true); _next->setEnabled(_model->rowCount() > 1); emit newModel(_model); } else { _view->setEnabled(false); _next->setEnabled(false); _prev->setEnabled(false); _next->setEnabled(false); } }
T * DataMapper<Subclass, T, I>::obtainFromIdentityMap(const QVariantMap & map) { T * model = nullptr; QVariant variantId = map[identityFieldName()]; // hack because of compile errors if those two lines are just one Identity id = variantId.value<Identity>(); if (m_identities.hasModel(id)) { model = m_identities.getModel(id); } else { model = newModel(); buildFromRecord(model, map); m_identities.registerModel(id, model); } return model; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); m_pOAuth2 = new OAuth2(this); m_API_key = m_pOAuth2->getSimpleAPIKey(); connect(m_pOAuth2, SIGNAL(loginDone()), this, SLOT(loginDone())); m_managerPrediction.setAPIKey(m_API_key); connect(&m_managerPrediction, SIGNAL(replyText(QString)), this, SLOT(addReplyText(QString))); connect(&m_managerPrediction, SIGNAL(recvModelsList(QVariantList)), this, SLOT(recvModelsList(QVariantList))); connect(&m_managerPrediction, SIGNAL(recvModelDescription(QVariant)), this, SLOT(recvModelDescription(QVariant))); connect(&m_managerPrediction, SIGNAL(recvPredictionResult(QVariant)), this, SLOT(recvPredictionResult(QVariant))); connect(&m_managerPrediction, SIGNAL(recvAddToModelComplete(bool)), this, SLOT(recvAddToModelComplete(bool))); connect(ui->lwModelsList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedModelChanged())); connect(ui->actionDeleteModel, SIGNAL(triggered()), this, SLOT(deleteModel())); connect(ui->actionNewModel, SIGNAL(triggered()), this, SLOT(newModel())); connect(ui->actionUpdateModelsList, SIGNAL(triggered()), this, SLOT(updateModelsList())); connect(ui->actionUpdateModelInfo, SIGNAL(triggered()), this, SLOT(updateModelInfo())); connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close())); connect(ui->predictButton, SIGNAL(clicked()), this, SLOT(predict())); connect(ui->lineEditTextToPredict, SIGNAL(returnPressed()), this, SLOT(predict())); connect(ui->actionLogin, SIGNAL(triggered()), this, SLOT(login())); connect(&timerTest, SIGNAL(timeout()), this, SLOT(testSendRequest())); startLogin(false); }
/* Pass in a schema name and a table name. If schema name is blank, it will be ignored. If there is a table name to set, data widget mappings will be set as well. */ void ScreenControl::setTable(QString s, QString t) { if (t.length()) { QString tablename=""; if (s.length()) tablename=s + "."; tablename+=t; if (_model->tableName() != tablename) { _model->setTable(tablename,_keyColumns); setDataWidgetMapper(_model); _search->setEnabled(true); _searchText->setEnabled(true); emit newModel(_model); } } else { _search->setEnabled(false); _searchText->setEnabled(false); } }
void SpecificWorker::resetGame() { try{ speech_proxy->say("He llegado", true); } catch (Ice::Exception e) { qDebug()<<"error talking to face tablet"; } usleep(1000000); bodyinversekinematics_proxy->goHome("RIGHTARM"); usleep(3000000); AGMModel::SPtr newModel(new AGMModel()); AGMModelConverter::fromXMLToInternal("/home/robocomp/robocomp/components/robocomp-ursus-touchgame/etc/initialModel.xml", newModel); tocaButton->setChecked(false); tocaButton->setText("toca?"); sendModificationProposal(worldModel, newModel); }
editorBrush::editorBrush(int owner, Vector mins, Vector maxs, int texture) { this->isBox = true; this->mins = mins; this->maxs = maxs; this->entType = 0; setOwner(owner); Vector v[8]; v[0][0] = mins[0]; v[0][1] = mins[1]; v[1][0] = maxs[0]; v[1][1] = mins[1]; v[2][0] = maxs[0]; v[2][1] = maxs[1]; v[3][0] = mins[0]; v[3][1] = maxs[1]; for(int i = 0; i < 4; i++) { v[i + 4][0] = v[i][0]; v[i + 4][1] = v[i][1]; v[i][2] = mins[2]; v[i + 4][2] = maxs[2]; } faces.resize(6); //faces = (editorFace**)malloc(6*sizeof(editorFace*)); faces[0] = editorFace(v[0],v[1],v[2],v[3]); faces[1] = editorFace(v[7],v[6],v[5],v[4]); faces[2] = editorFace(v[1],v[0],v[4],v[5]); faces[3] = editorFace(v[3],v[2],v[6],v[7]); faces[4] = editorFace(v[2],v[1],v[5],v[6]); faces[5] = editorFace(v[0],v[3],v[7],v[4]); for(int i = 0; i < 6; i++) faces[i].texture = texture; //faces_c = 6; newModel(); }
void SpecificWorker::action_PersonClassifiesMilkPot() { static bool first = true; static QTime lastTime = QTime::currentTime(); if (lastTime.elapsed() < 5000 and not first) return; first = false; lastTime = QTime::currentTime(); speech_proxy->say("Is this milk? What? ... I can't hear you... I guess you said yes.", false); while(speech_proxy->isBusy()) usleep(100000); AGMModel::SPtr newModel(new AGMModel(worldModel)); try { auto symbols = newModel->getSymbolsMap(params, "objectr", "statusr", "objecth", "statush"); newModel->renameEdge(symbols["objectr"], symbols["statusr"], "classifailed", "milkpot"); newModel->renameEdge(symbols["objecth"], symbols["statush"], "unclassified", "milkpot"); try { sendModificationProposal(worldModel, newModel); } catch(...) { printf("hriAgent: Couldn't publish new model\n"); } } catch(...) { printf("hriAgent: Couldn't retrieve action's parameters\n"); } }
void OSPlugin::newForLastKey( openstudio::NewFromTemplateEnum newFromTemplateEnum ) { LOG(Trace, "newForLastKey"); if( !closeDocument(m_lastKey) ) { return; } openstudio::model::Model model = openstudio::model::exampleModel(); boost::shared_ptr<OSDocument> document( new OSDocument(model, model, openstudio::path(), boost::optional<openstudio::model::Model>(), "", true) ); connectDocumentSignals(document.get()); m_startupView->hide(); m_osDocuments.insert(std::make_pair<std::string, boost::shared_ptr<OSDocument> >(m_lastKey, document)); emit newModel(m_lastKey, document->model().getImpl<openstudio::model::detail::Model_Impl>().get()); emit documentShown(m_lastKey); m_lastKey = ""; }
void editorBrush::reloadModel() { if(isBox) newModel(); //todo: "else" - reload models on faces }
boost::shared_ptr<IModel> CAnimModel::clone() const { boost::shared_ptr<CAnimModel> newModel(new CAnimModel(m_anim)); newModel->m_animMap = m_animMap; return newModel; }
/** ***************************************************************************/ void ExtensionManager::teardownSession() { for (IExtension *e : _extensions) e->teardownSession(); emit newModel(nullptr); _sessionIsActive = false; }
void XTreeView::setModel(XSqlTableModel * model) { QTreeView::setModel(model); for (int i = 0; i < QTreeView::model()->columnCount(); ++i) { QString h = QTreeView::model()->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(); QTreeView::model()->setHeaderData(i, Qt::Horizontal, h, Qt::UserRole); ColumnProps *cp = _columnByName.value(h, 0); if (! cp) { cp = new ColumnProps; cp->columnName = h; cp->logicalIndex = i; cp->defaultWidth = -1; cp->savedWidth = -1; cp->stretchy = true; cp->locked = false; cp->visible = true; cp->label = h; cp->fromSettings = false; cp->alignment = QTreeView::model()->headerData(i, Qt::Horizontal, Qt::TextAlignmentRole).toInt(); cp->label.replace(0, 1, cp->label.left(1).toUpper()); for (int j = 0; (j = cp->label.indexOf("_", j)) >= 0; /* empty */) { cp->label.replace(j, 1, " "); cp->label.replace(j + 1, 1, cp->label.mid(j + 1, 1).toUpper()); } _columnByName.insert(cp->columnName, cp); } QTreeView::model()->setHeaderData(i, Qt::Horizontal, cp->label, Qt::DisplayRole); QTreeView::model()->setHeaderData(i, Qt::Horizontal, cp->alignment, Qt::TextAlignmentRole); } if (! _settingsLoaded) { QString settingsPrefix = _windowName + "/" + objectName(); _settingsLoaded = true; _forgetful = xtsettingsValue(settingsPrefix + "/isForgetful").toBool(); QString savedString; QStringList savedParts; QString part, key, val; bool b1 = false, b2 = false; if(!_forgetful) { savedString = xtsettingsValue(settingsPrefix + "/columnWidths").toString(); savedParts = savedString.split("|", QString::SkipEmptyParts); for(int i = 0; i < savedParts.size(); i++) { part = savedParts.at(i); key = part.left(part.indexOf(",")); val = part.right(part.length() - part.indexOf(",") - 1); b1 = false; b2 = false; int k = key.toInt(&b1); int v = val.toInt(&b2); if(b1 && b2) { ColumnProps *cp = _columnByName.value(columnNameFromLogicalIndex(k), 0); if (cp) { cp->savedWidth = v; cp->stretchy = false; cp->fromSettings = true; } header()->resizeSection(k, v); } } } // Load any previously saved column hidden/visible information if(_x_preferences) { savedString = _x_preferences->value(settingsPrefix + "/columnsShown"); savedParts = savedString.split("|", QString::SkipEmptyParts); for(int i = 0; i < savedParts.size(); i++) { part = savedParts.at(i); key = part.left(part.indexOf(",")); val = part.right(part.length() - part.indexOf(",") - 1); int c = key.toInt(&b1); if(b1 && (val == "on" || val == "off")) { ColumnProps *cp = _columnByName.value(columnNameFromLogicalIndex(c), 0); if (cp) { cp->visible = (val == "on"); cp->fromSettings = true; } header()->setSectionHidden(c, (val != "on")); } } } } emit newModel(model); }
void OSPlugin::importIdfForSender() { LOG(Trace, "importIdfForSender"); QObject* sender = this->sender(); OSDocument* osDocument = qobject_cast<OSDocument*>(sender); OS_ASSERT(osDocument); boost::optional<std::string> key = getKeyForDocument(osDocument); OS_ASSERT(key); QString fileName = QFileDialog::getOpenFileName( m_sketchUpWidget, tr("Import Idf"), QDir::homePath(), tr("(*.idf)") ); if( ! (fileName == "") ){ boost::optional<IdfFile> idfFile; idfFile = openstudio::IdfFile::load(toPath(fileName),IddFileType::EnergyPlus); if( idfFile ){ if( !closeDocument(*key) ) { return; } IdfFile _idfFile = idfFile.get(); Workspace workspace(_idfFile); energyplus::ReverseTranslator trans; model::Model model = trans.translateWorkspace(workspace); m_startupView->hide(); processEvents(); boost::shared_ptr<OSDocument> document( new OSDocument(model, model, openstudio::path(), boost::optional<openstudio::model::Model>(), "", true) ); connectDocumentSignals(document.get()); document->markAsModified(); QMessageBox messageBox; messageBox.setText("Some portions of the idf file were not imported."); QString log; std::vector<LogMessage> messages = trans.errors(); for( std::vector<LogMessage>::iterator it = messages.begin(); it < messages.end(); it++ ) { log.append(QString::fromStdString(it->logMessage())); log.append("\n"); log.append("\n"); } messages = trans.warnings(); for( std::vector<LogMessage>::iterator it = messages.begin(); it < messages.end(); it++ ) { log.append(QString::fromStdString(it->logMessage())); log.append("\n"); log.append("\n"); } messageBox.setDetailedText(log); messageBox.exec(); m_osDocuments.insert(std::make_pair<std::string, boost::shared_ptr<OSDocument> >(*key, document)); emit newModel(*key, document->model().getImpl<openstudio::model::detail::Model_Impl>().get()); emit documentShown(*key); } } }
ModelId LocationModelManager::newModel() { ModelId mid = INVALID_ID; return newModel(mid); }