void addLink(Link *firstLink, Node *node) { // case 1: first link is not in use if (!firstLink) { firstLink = createLink(node); return; } Link *lastLink = firstLink; do { // case 2: there is already a link to this node if (lastLink->node == node) { lastLink->weight++; return; } lastLink = lastLink->nextLink; } while (lastLink->nextLink != NULL); // case 3: there is no link to this node lastLink->nextLink = createLink(node); }
void MudGameView::onSelectProfile() { Profile current(m_manager.getProfile()); SelectProfileDlg dlg(current); if (dlg.DoModal() != IDOK) return; const ProfileData& profile = dlg.getProfile(); if (!profile.create_new) { // load profile if (loadProfile(profile.profile) && profile.create_link) createLink(profile.profile); return; } if (!profile.copy_from_src) { if (!profile.create_empty) { // new profile from resources Profile src; src.group = profile.profile.group; src.name = L"player"; if (copyProfile(true, profile.profile, src) && profile.create_link) createLink(profile.profile); return; } // new empty profile if (newProfile(profile.profile) && profile.create_link) createLink(profile.profile); return; } // new profile and copy from src profile if (copyProfile(false, profile.profile, profile.src) && profile.create_link) createLink(profile.profile); }
Dialog() { QString localFile("test.html"); // server/shared/test.html should be replaced to point to a real file QString UNCPath("file://server/shared/test.html"); QVBoxLayout* vBox = new QVBoxLayout(); vBox->addWidget(new QLabel("Clicking on the links should open their" " contents in the default browser !")); vBox->addWidget(createLink(localFile)); vBox->addWidget(new QLabel("The following link must point to " "a file in a shared folder on a network !")); vBox->addWidget(createLink(UNCPath)); setLayout(vBox); }
void DBWorker::navigateTo(int tabId, QString url, QString title, QString path) { // TODO: rollback in case of failure if (url.isEmpty()) { return; } // Return if the current url of the tab is the same as the parameter url Link currentLink = getCurrentLink(tabId); if (currentLink.isValid() && currentLink.url() == url) { return; } clearDeprecatedTabHistory(tabId, currentLink.linkId()); int linkId = createLink(url, title, path); if (addToBrowserHistory(url, title) == Error) { qWarning() << Q_FUNC_INFO << "failed to add url to history" << url; } int historyId = addToTabHistory(tabId, linkId); if (historyId > 0) { updateTab(tabId, historyId); } else { qWarning() << Q_FUNC_INFO << "failed to add url to tab history" << url; } #if DEBUG_LOGS qDebug() << "emit tab changed:" << tabId << historyId << title << url; #endif }
void DeclarativeTabModel::addTab(const QString& url, const QString &title) { if (!LinkValidator::navigable(QUrl(url))) { return; } int tabId = createTab(); int linkId = createLink(tabId, url, title); Tab tab(tabId, Link(linkId, url, "", title), 0, 0); #if DEBUG_LOGS qDebug() << "new tab data:" << &tab; #endif int index = m_tabs.count(); beginInsertRows(QModelIndex(), index, index); m_tabs.append(tab); endInsertRows(); // We should trigger this only when // tab is added through new window request. In all other // case we should keep the new tab in background. updateActiveTab(tab, true); emit countChanged(); emit tabAdded(tabId); m_nextTabId = ++tabId; emit nextTabIdChanged(); setWaitingForNewTab(false); }
bool Connector::onConnected() { // 成功连接上对端 Link* link = createLink(m_sockfd, m_peerAddr); if (NULL == link) { LOG_ERROR << m_pNetReactor->name() << " connector create link failed, socket = " << m_sockfd; this->close(); socktool::closeSocket(m_sockfd); return false; } this->close(); link->open(); TaskQueue::TaskList taskList; // 将连接成功的消息投到业务层 taskList.push_back(boost::bind(&INetReactor::onConnected, m_pNetReactor, link, link->getLocalAddr(), m_peerAddr)); // 等业务层处理完新连接后,才允许该连接开始读 taskList.push_back(boost::bind(&NetModel::enableRead, link->m_net, link)); m_pNetReactor->getTaskQueue().put(taskList); return true; }
void DBWorker::createTab(const Tab &tab) { #if DEBUG_LOGS qDebug() << "new tab id: " << tab.tabId(); #endif QSqlQuery query = prepare("INSERT INTO tab (tab_id, tab_history_id) VALUES (?,?);"); query.bindValue(0, tab.tabId()); query.bindValue(1, 0); execute(query); if (tab.url().isEmpty()) { return; } int linkId = createLink(tab.url(), tab.title(), tab.thumbnailPath()); if (addToBrowserHistory(tab.url(), tab.title()) == Error) { qWarning() << Q_FUNC_INFO << "failed to add url to history" << tab.url(); } int historyId = addToTabHistory(tab.tabId(), linkId); if (historyId > 0) { updateTab(tab.tabId(), historyId); } else { qWarning() << Q_FUNC_INFO << "failed to add url to tab history" << tab.url(); } #if DEBUG_LOGS qDebug() << "created link:" << linkId << "with history id:" << historyId << "for tab:" << tab.tabId() << tab.url(); #endif }
Element * Factory::createElementFromXML(const QDomElement & element, const ElementsMap& elementsMap) { QString type = element.tagName(); Element * result = 0; if ( type == "link" ) result = createLink(element, elementsMap); else result = createNode(element); return result; }
void FeatureFS::data(const std::string &name_or_id) { if (name_or_id.empty()) throw EmptyString("data(id)"); if (!block->hasEntity({name_or_id, ObjectType::DataArray})) throw std::runtime_error("FeatureFS::data: DataArray not found in block!"); if (hasObject("data")) removeObjectByNameOrAttribute("name", "data"); auto target = std::dynamic_pointer_cast<DataArrayFS>(block->getEntity({name_or_id, ObjectType::DataArray})); bfs::path p(location()), m("data"); target->createLink(p / m); forceUpdatedAt(); }
// The file Parser returns a map of Nodes by Name and Type (string) and a map of Links // First we initialize all the Nodes // Afterwards we will link them by setting their neighbours std::map<std::string, Node*> NodeGraphCreator::parseParserOutput(map<string,string> *nodes, map<string, vector<string> > *edges) { //Nodes for (std::map<string, string>::iterator it = nodes->begin(); it != nodes->end(); it++) { createNode(it->first,it->second); } //Edges for (std::map<string, vector<string>>::iterator it = edges->begin(); it != edges->end(); it++) { createLink(it->first,it->second); } return nodeMap; }
Net::Net(glm::vec2 dimension, const glm::vec3 &start, const glm::vec3 &interval1, const glm::vec3 &interval2, VerletManager* vm, GLuint shader) : Verlet(vm), m_shader(shader) { int width = dimension.x; int height = dimension.y; int count = 0; for(int i = 0; i<width; i++){ for(int j = 0; j<height; j++){ createPoint(start+(float)j*interval1+(float)i*interval2); if(j!=0) //attach to the left createLink(count-1,count); if(i!=0) //attach to top createLink(count-width, count); count++; } } m_mesh = new Mesh(); m_mesh->initStrip(m_shader, width, height, getPosArray(), getNormArray()); }
/** * Adds a new link with the given value after the given link and * increments the list's size. */ static void addLinkAfter(struct CircularList* list, struct Link* link, TYPE value) { // FIXME: you must write this assert(list != 0); assert(link != 0); struct Link* newLink = createLink(value); newLink->next = link->next; link->next = newLink; newLink->prev = link; newLink->next->prev = newLink; newLink->value = value; list->size++; }
void EntityWithMetadataFS::metadata(const std::string &id) { if (fileMode() == FileMode::ReadOnly) { throw std::runtime_error("EntityWithMetdata::metadata trying to set metadata in ReadOnly mode."); } if (id.empty()) throw EmptyString("metadata"); if (hasMetadata()) metadata(none); File tmp = file(); auto found = tmp.findSections(util::IdFilter<Section>(id)); if (found.empty()) throw std::runtime_error("EntityWithMetadataFS::metadata: Section not found in file!"); auto target = std::dynamic_pointer_cast<SectionFS>(found.front().impl()); bfs::path t(target->location()), p(location()), m("metadata"); target->createLink(p / m); }
bool setRegRun(bool stat) { HKEY hKey; //打开指定子键 DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建 if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS) return false; //创建一个新的键值,设置键值数据为文件名 if (stat) { if (createLink()) { std::string filename = XFile::getCurrentExeFileFullPath(); if (filename.size() >= 3) { memcpy(&filename[filename.size() - 3], &"lnk", 3); //filename[filename.size() - 3] = 'l'; //filename[filename.size() - 2] = 'n'; //filename[filename.size() - 1] = 'k'; } else return false; //读取注册表中该键的键值,如果已经相同则不重复设置。 if (RegSetValueEx(hKey, XEG.m_windowData.windowTitle.c_str(), 0, REG_SZ, (BYTE*)filename.c_str(), filename.length()) == ERROR_SUCCESS) LogStr("自动启动设置成功!"); } else { RegCloseKey(hKey); return false; } } else { if (RegDeleteValue(hKey, XEG.m_windowData.windowTitle.c_str()) == ERROR_SUCCESS) LogStr("取消自动启动!"); } // 关闭子键句柄 RegCloseKey(hKey); return true; }
void ColladaBodyLoaderImpl::convertToBody(Body& body) { DaeNode* extNode = parser->findRootLink(); if (!extNode) { SgGroup* scene = parser->createScene(fileName); if(scene){ Link* link = body.createLink(); link->setName("Root"); link->setShape(scene); link->setMass(1.0); link->setInertia(Matrix3::Identity()); body.setRootLink(link); body.setModelName(getBasename(fileName)); } return; } int jointId = 0; links.clear(); joints.clear(); bool duplicate; Link* link = createLink(body, static_cast<DaeLink*>(extNode)->name, &duplicate); link->setName(static_cast<DaeLink*>(extNode)->name); body.setRootLink(link); // !!! important !!! // There is no category in the joint of collada. // But joint of the root node must be "FREE-TYPE" or "FIXED-TYPE". // Set to "FIXED-TYPE" if the link of the route had been "grounded". (Ex. PA10) // I have to set "FREE-TYPE" otherwise. (Ex. HRP4C, SR1, GR001, etc, etc) link->setJointType(extNode->transform.translate[2] == 0 ? Link::FIXED_JOINT : Link::FREE_JOINT); body.setModelName(parser->findRootName()); setPosition(extNode, link); buildLinks(extNode, extNode, link, body, jointId); body.updateLinkTree(); }
NetworkCm02Model::NetworkCm02Model() :NetworkModel() { char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim"); int select = xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update"); if (!strcmp(optim, "Full")) { p_updateMechanism = UM_FULL; m_selectiveUpdate = select; } else if (!strcmp(optim, "Lazy")) { p_updateMechanism = UM_LAZY; m_selectiveUpdate = 1; xbt_assert((select == 1) || (xbt_cfg_is_default_value (_sg_cfg_set, "network/maxmin_selective_update")), "Disabling selective update while using the lazy update mechanism is dumb!"); } else { xbt_die("Unsupported optimization (%s) for this model", optim); } if (!p_maxminSystem) p_maxminSystem = lmm_system_new(m_selectiveUpdate); routing_model_create(createLink("__loopback__", 498000000, NULL, 0.000015, NULL, SURF_RESOURCE_ON, NULL, SURF_LINK_FATPIPE, NULL)); if (p_updateMechanism == UM_LAZY) { p_actionHeap = xbt_heap_new(8, NULL); xbt_heap_set_update_callback(p_actionHeap, surf_action_lmm_update_index_heap); p_modifiedSet = new ActionLmmList(); p_maxminSystem->keep_track = p_modifiedSet; } m_haveGap = false; }
static void fifoPush(TSMPacketList * packets, const AVPacket * packet, double timeStamp) { TSMPacketLink * link = createLink(packet, timeStamp); if (!packets->head) { assert(!packets->tail); assert(!packets->size); packets->head = link; packets->tail = link; packets->size = 1; } else { /* attach at the tail */ assert(packets->size > 0); packets->tail->next = link; packets->tail = link; packets->size++; } }
void ColladaBodyLoaderImpl::buildLinks(DaeNode* extNode, DaeNode* parentNode, Link* parentLink, Body& body, int& jointId) { bool duplicate; Link* link = NULL; if (DaeLink* extLink = dynamic_cast<DaeLink*>(extNode)) { // It will record the link. // The link and joint is one in two. // In addition, link will be child relationship (except root) in the parent joint always. setLink(extNode, parentLink, body); setMass(extLink, parentLink); for (DaeLinkChildren::iterator iterl = extLink->children.begin(); iterl != extLink->children.end(); iterl++) { DaeNode* extJoint = parser->findJointByLink(*iterl); buildLinks(extJoint, extLink, parentLink, body, jointId); } } else if (DaeJoint* extJoint = dynamic_cast<DaeJoint*>(extNode)) { if (!parentLink) { throwException((format(_("joint node can not be root link"))).str()); } // It will record the link. link = createLink(body, static_cast<DaeJoint*>(extNode)->name, &duplicate); // The joint and link is one in the link. setJoint(extNode, parentNode, link, jointId); parentLink->appendChild(link); for (DaeJointChildren::iterator iterj = extJoint->children.begin(); iterj != extJoint->children.end(); iterj++) { // Joint is same as link. (Comprehension) DaeNode* extLink = parser->findLinkByJoint(*iterj); buildLinks(extLink, extJoint, link, body, jointId); } } else { return; } }
int DBWorker::createLink(int tabId, QString url) { if (url.isEmpty()) { return 0; } int linkId = createLink(url, "", ""); if (!addToHistory(linkId)) { qWarning() << Q_FUNC_INFO << "failed to add url to history" << url; } int historyId = addToTabHistory(tabId, linkId); if (historyId > 0) { updateTab(tabId, historyId); } else { qWarning() << Q_FUNC_INFO << "failed to add url to tab history" << url; } #ifdef DEBUG_LOGS qDebug() << "created link:" << linkId << "with history id:" << historyId << "for tab:" << tabId << url; #endif return linkId; }
HtmlEditor::HtmlEditor(QWidget *parent) : QMainWindow(parent) , ui(new Ui_MainWindow) , sourceDirty(true) , highlighter(0) , ui_dialog(0) , insertHtmlDialog(0) { ui->setupUi(this); ui->tabWidget->setTabText(0, "Normal View"); ui->tabWidget->setTabText(1, "HTML Source"); connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(changeTab(int))); resize(600, 600); highlighter = new Highlighter(ui->plainTextEdit->document()); QWidget *spacer = new QWidget(this); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); ui->standardToolBar->insertWidget(ui->actionZoomOut, spacer); zoomLabel = new QLabel; ui->standardToolBar->insertWidget(ui->actionZoomOut, zoomLabel); zoomSlider = new QSlider(this); zoomSlider->setOrientation(Qt::Horizontal); zoomSlider->setMaximumWidth(150); zoomSlider->setRange(25, 400); zoomSlider->setSingleStep(25); zoomSlider->setPageStep(100); connect(zoomSlider, SIGNAL(valueChanged(int)), SLOT(changeZoom(int))); ui->standardToolBar->insertWidget(ui->actionZoomIn, zoomSlider); connect(ui->actionFileNew, SIGNAL(triggered()), SLOT(fileNew())); connect(ui->actionFileOpen, SIGNAL(triggered()), SLOT(fileOpen())); connect(ui->actionFileSave, SIGNAL(triggered()), SLOT(fileSave())); connect(ui->actionFileSaveAs, SIGNAL(triggered()), SLOT(fileSaveAs())); connect(ui->actionExit, SIGNAL(triggered()), SLOT(close())); connect(ui->actionInsertImage, SIGNAL(triggered()), SLOT(insertImage())); connect(ui->actionCreateLink, SIGNAL(triggered()), SLOT(createLink())); connect(ui->actionInsertHtml, SIGNAL(triggered()), SLOT(insertHtml())); connect(ui->actionZoomOut, SIGNAL(triggered()), SLOT(zoomOut())); connect(ui->actionZoomIn, SIGNAL(triggered()), SLOT(zoomIn())); // these are forward to internal QWebView FORWARD_ACTION(ui->actionEditUndo, QWebPage::Undo); FORWARD_ACTION(ui->actionEditRedo, QWebPage::Redo); FORWARD_ACTION(ui->actionEditCut, QWebPage::Cut); FORWARD_ACTION(ui->actionEditCopy, QWebPage::Copy); FORWARD_ACTION(ui->actionEditPaste, QWebPage::Paste); FORWARD_ACTION(ui->actionFormatBold, QWebPage::ToggleBold); FORWARD_ACTION(ui->actionFormatItalic, QWebPage::ToggleItalic); FORWARD_ACTION(ui->actionFormatUnderline, QWebPage::ToggleUnderline); // Qt 4.5.0 has a bug: always returns 0 for QWebPage::SelectAll connect(ui->actionEditSelectAll, SIGNAL(triggered()), SLOT(editSelectAll())); connect(ui->actionStyleParagraph, SIGNAL(triggered()), SLOT(styleParagraph())); connect(ui->actionStyleHeading1, SIGNAL(triggered()), SLOT(styleHeading1())); connect(ui->actionStyleHeading2, SIGNAL(triggered()), SLOT(styleHeading2())); connect(ui->actionStyleHeading3, SIGNAL(triggered()), SLOT(styleHeading3())); connect(ui->actionStyleHeading4, SIGNAL(triggered()), SLOT(styleHeading4())); connect(ui->actionStyleHeading5, SIGNAL(triggered()), SLOT(styleHeading5())); connect(ui->actionStyleHeading6, SIGNAL(triggered()), SLOT(styleHeading6())); connect(ui->actionStylePreformatted, SIGNAL(triggered()), SLOT(stylePreformatted())); connect(ui->actionStyleAddress, SIGNAL(triggered()), SLOT(styleAddress())); connect(ui->actionFormatFontName, SIGNAL(triggered()), SLOT(formatFontName())); connect(ui->actionFormatFontSize, SIGNAL(triggered()), SLOT(formatFontSize())); connect(ui->actionFormatTextColor, SIGNAL(triggered()), SLOT(formatTextColor())); connect(ui->actionFormatBackgroundColor, SIGNAL(triggered()), SLOT(formatBackgroundColor())); // no page action exists yet for these, so use execCommand trick connect(ui->actionFormatStrikethrough, SIGNAL(triggered()), SLOT(formatStrikeThrough())); connect(ui->actionFormatAlignLeft, SIGNAL(triggered()), SLOT(formatAlignLeft())); connect(ui->actionFormatAlignCenter, SIGNAL(triggered()), SLOT(formatAlignCenter())); connect(ui->actionFormatAlignRight, SIGNAL(triggered()), SLOT(formatAlignRight())); connect(ui->actionFormatAlignJustify, SIGNAL(triggered()), SLOT(formatAlignJustify())); connect(ui->actionFormatDecreaseIndent, SIGNAL(triggered()), SLOT(formatDecreaseIndent())); connect(ui->actionFormatIncreaseIndent, SIGNAL(triggered()), SLOT(formatIncreaseIndent())); connect(ui->actionFormatNumberedList, SIGNAL(triggered()), SLOT(formatNumberedList())); connect(ui->actionFormatBulletedList, SIGNAL(triggered()), SLOT(formatBulletedList())); // necessary to sync our actions connect(ui->webView->page(), SIGNAL(selectionChanged()), SLOT(adjustActions())); connect(ui->webView->page(), SIGNAL(contentsChanged()), SLOT(adjustSource())); ui->webView->setFocus(); setCurrentFileName(QString()); QString initialFile = ":/example.html"; const QStringList args = QCoreApplication::arguments(); if (args.count() == 2) initialFile = args.at(1); if (!load(initialFile)) fileNew(); adjustActions(); adjustSource(); setWindowModified(false); changeZoom(100); }
QString AbstractDeclarationNavigationContext::html(bool shorten) { clear(); m_shorten = shorten; modifyHtml() += "<html><body><p>" + fontSizePrefix(shorten); addExternalHtml(m_prefix); if(!m_declaration.data()) { modifyHtml() += i18n("<br /> lost declaration <br />"); return currentHtml(); } if( m_previousContext ) { QString link = createLink( m_previousContext->name(), m_previousContext->name(), NavigationAction(m_previousContext) ); modifyHtml() += navigationHighlight(i18n("Back to %1<br />", link)); } KSharedPtr<IDocumentation> doc; if( !shorten ) { doc = ICore::self()->documentationController()->documentationForDeclaration(m_declaration.data()); const AbstractFunctionDeclaration* function = dynamic_cast<const AbstractFunctionDeclaration*>(m_declaration.data()); if( function ) { htmlFunction(); } else if( m_declaration->isTypeAlias() || m_declaration->kind() == Declaration::Instance ) { if( m_declaration->isTypeAlias() ) modifyHtml() += importantHighlight("typedef "); if(m_declaration->type<EnumeratorType>()) modifyHtml() += i18n("enumerator "); AbstractType::Ptr useType = m_declaration->abstractType(); if(m_declaration->isTypeAlias()) { //Do not show the own name as type of typedefs if(useType.cast<TypeAliasType>()) useType = useType.cast<TypeAliasType>()->type(); } eventuallyMakeTypeLinks( useType ); modifyHtml() += ' ' + nameHighlight(Qt::escape(declarationName(m_declaration))) + "<br>"; }else{ if( m_declaration->kind() == Declaration::Type && m_declaration->abstractType().cast<StructureType>() ) { htmlClass(); } if ( m_declaration->kind() == Declaration::Namespace ) { modifyHtml() += i18n("namespace %1 <br />", nameHighlight(Qt::escape(m_declaration->qualifiedIdentifier().toString()))); } if(m_declaration->type<EnumerationType>()) { EnumerationType::Ptr enumeration = m_declaration->type<EnumerationType>(); modifyHtml() += i18n("enumeration %1 <br/>", Qt::escape(m_declaration->identifier().toString()) ); } if(m_declaration->isForwardDeclaration()) { ForwardDeclaration* forwardDec = static_cast<ForwardDeclaration*>(m_declaration.data()); Declaration* resolved = forwardDec->resolve(m_topContext.data()); if(resolved) { modifyHtml() += i18n("( resolved forward-declaration: "); makeLink(resolved->identifier().toString(), KDevelop::DeclarationPointer(resolved), NavigationAction::NavigateDeclaration ); modifyHtml() += i18n(") "); }else{ modifyHtml() += i18n("(unresolved forward-declaration) "); QualifiedIdentifier id = forwardDec->qualifiedIdentifier(); uint count; const IndexedDeclaration* decls; PersistentSymbolTable::self().declarations(id, count, decls); bool had = false; for(uint a = 0; a < count; ++a) { if(decls[a].isValid() && !decls[a].data()->isForwardDeclaration()) { modifyHtml() += "<br />"; makeLink(i18n("possible resolution from"), KDevelop::DeclarationPointer(decls[a].data()), NavigationAction::NavigateDeclaration); modifyHtml() += ' ' + decls[a].data()->url().str(); had = true; } } if(had) modifyHtml() += "<br />"; } } } }else{ AbstractType::Ptr showType = m_declaration->abstractType(); if(showType && showType.cast<FunctionType>()) { showType = showType.cast<FunctionType>()->returnType(); if(showType) modifyHtml() += labelHighlight(i18n("Returns: ")); }else if(showType) { modifyHtml() += labelHighlight(i18n("Type: ")); } if(showType) { eventuallyMakeTypeLinks(showType); modifyHtml() += " "; } } QualifiedIdentifier identifier = m_declaration->qualifiedIdentifier(); if( identifier.count() > 1 ) { if( m_declaration->context() && m_declaration->context()->owner() ) { Declaration* decl = m_declaration->context()->owner(); FunctionDefinition* definition = dynamic_cast<FunctionDefinition*>(decl); if(definition && definition->declaration()) decl = definition->declaration(); if(decl->abstractType().cast<EnumerationType>()) modifyHtml() += labelHighlight(i18n("Enum: ")); else modifyHtml() += labelHighlight(i18n("Container: ")); makeLink( declarationName(DeclarationPointer(decl)), DeclarationPointer(decl), NavigationAction::NavigateDeclaration ); modifyHtml() += " "; } else { QualifiedIdentifier parent = identifier; parent.pop(); modifyHtml() += labelHighlight(i18n("Scope: %1 ", typeHighlight(Qt::escape(parent.toString())))); } } if( shorten && !m_declaration->comment().isEmpty() ) { QString comment = QString::fromUtf8(m_declaration->comment()); if( comment.length() > 60 ) { comment.truncate(60); comment += "..."; } comment.replace('\n', " "); comment.replace("<br />", " "); comment.replace("<br/>", " "); modifyHtml() += commentHighlight(Qt::escape(comment)) + " "; } QString access = stringFromAccess(m_declaration); if( !access.isEmpty() ) modifyHtml() += labelHighlight(i18n("Access: %1 ", propertyHighlight(Qt::escape(access)))); ///@todo Enumerations QString detailsHtml; QStringList details = declarationDetails(m_declaration); if( !details.isEmpty() ) { bool first = true; foreach( const QString &str, details ) { if( !first ) detailsHtml += ", "; first = false; detailsHtml += propertyHighlight(str); } }
MYBOOL crash_basis(lprec *lp) { int i; MATrec *mat = lp->matA; MYBOOL ok = TRUE; /* Initialize basis indicators */ if(lp->basis_valid) lp->var_basic[0] = FALSE; else default_basis(lp); /* Set initial partial pricing blocks */ if(lp->rowblocks != NULL) lp->rowblocks->blocknow = 1; if(lp->colblocks != NULL) lp->colblocks->blocknow = ((lp->crashmode == CRASH_NONE) || (lp->colblocks->blockcount == 1) ? 1 : 2); /* Construct a basis that is in some measure the "most feasible" */ if((lp->crashmode == CRASH_MOSTFEASIBLE) && mat_validate(mat)) { /* The logic here follows Maros */ LLrec *rowLL = NULL, *colLL = NULL; int ii, rx, cx, ix, nz; REAL wx, tx, *rowMAX = NULL, *colMAX = NULL; int *rowNZ = NULL, *colNZ = NULL, *rowWT = NULL, *colWT = NULL; REAL *value; int *rownr, *colnr; report(lp, NORMAL, "crash_basis: 'Most feasible' basis crashing selected\n"); /* Tally row and column non-zero counts */ ok = allocINT(lp, &rowNZ, lp->rows+1, TRUE) && allocINT(lp, &colNZ, lp->columns+1, TRUE) && allocREAL(lp, &rowMAX, lp->rows+1, FALSE) && allocREAL(lp, &colMAX, lp->columns+1, FALSE); if(!ok) goto Finish; nz = mat_nonzeros(mat); rownr = &COL_MAT_ROWNR(0); colnr = &COL_MAT_COLNR(0); value = &COL_MAT_VALUE(0); for(i = 0; i < nz; i++, rownr += matRowColStep, colnr += matRowColStep, value += matValueStep) { rx = *rownr; cx = *colnr; wx = fabs(*value); rowNZ[rx]++; colNZ[cx]++; if(i == 0) { rowMAX[rx] = wx; colMAX[cx] = wx; colMAX[0] = wx; } else { SETMAX(rowMAX[rx], wx); SETMAX(colMAX[cx], wx); SETMAX(colMAX[0], wx); } } /* Reduce counts for small magnitude to preserve stability */ rownr = &COL_MAT_ROWNR(0); colnr = &COL_MAT_COLNR(0); value = &COL_MAT_VALUE(0); for(i = 0; i < nz; i++, rownr += matRowColStep, colnr += matRowColStep, value += matValueStep) { rx = *rownr; cx = *colnr; wx = fabs(*value); #ifdef CRASH_SIMPLESCALE if(wx < CRASH_THRESHOLD * colMAX[0]) { rowNZ[rx]--; colNZ[cx]--; } #else if(wx < CRASH_THRESHOLD * rowMAX[rx]) rowNZ[rx]--; if(wx < CRASH_THRESHOLD * colMAX[cx]) colNZ[cx]--; #endif } /* Set up priority tables */ ok = allocINT(lp, &rowWT, lp->rows+1, TRUE); createLink(lp->rows, &rowLL, NULL); ok &= (rowLL != NULL); if(!ok) goto Finish; for(i = 1; i <= lp->rows; i++) { if(get_constr_type(lp, i)==EQ) ii = 3; else if(lp->upbo[i] < lp->infinite) ii = 2; else if(fabs(lp->rhs[i]) < lp->infinite) ii = 1; else ii = 0; rowWT[i] = ii; if(ii > 0) appendLink(rowLL, i); } ok = allocINT(lp, &colWT, lp->columns+1, TRUE); createLink(lp->columns, &colLL, NULL); ok &= (colLL != NULL); if(!ok) goto Finish; for(i = 1; i <= lp->columns; i++) { ix = lp->rows+i; if(is_unbounded(lp, i)) ii = 3; else if(lp->upbo[ix] >= lp->infinite) ii = 2; else if(fabs(lp->upbo[ix]-lp->lowbo[ix]) > lp->epsmachine) ii = 1; else ii = 0; colWT[i] = ii; if(ii > 0) appendLink(colLL, i); } /* Loop over all basis variables */ for(i = 1; i <= lp->rows; i++) { /* Select row */ rx = 0; wx = -lp->infinite; for(ii = firstActiveLink(rowLL); ii > 0; ii = nextActiveLink(rowLL, ii)) { tx = rowWT[ii] - CRASH_SPACER*rowNZ[ii]; if(tx > wx) { rx = ii; wx = tx; } } if(rx == 0) break; removeLink(rowLL, rx); /* Select column */ cx = 0; wx = -lp->infinite; for(ii = mat->row_end[rx-1]; ii < mat->row_end[rx]; ii++) { /* Update NZ column counts for row selected above */ tx = fabs(ROW_MAT_VALUE(ii)); ix = ROW_MAT_COLNR(ii); #ifdef CRASH_SIMPLESCALE if(tx >= CRASH_THRESHOLD * colMAX[0]) #else if(tx >= CRASH_THRESHOLD * colMAX[ix]) #endif colNZ[ix]--; if(!isActiveLink(colLL, ix) || (tx < CRASH_THRESHOLD * rowMAX[rx])) continue; /* Now do the test for best pivot */ tx = my_sign(lp->orig_obj[ix]) - my_sign(ROW_MAT_VALUE(ii)); tx = colWT[ix] + CRASH_WEIGHT*tx - CRASH_SPACER*colNZ[ix]; if(tx > wx) { cx = ix; wx = tx; } } if(cx == 0) break; removeLink(colLL, cx); /* Update row NZ counts */ ii = mat->col_end[cx-1]; rownr = &COL_MAT_ROWNR(ii); value = &COL_MAT_VALUE(ii); for(; ii < mat->col_end[cx]; ii++, rownr += matRowColStep, value += matValueStep) { wx = fabs(*value); ix = *rownr; #ifdef CRASH_SIMPLESCALE if(wx >= CRASH_THRESHOLD * colMAX[0]) #else if(wx >= CRASH_THRESHOLD * rowMAX[ix]) #endif rowNZ[ix]--; } /* Set new basis variable */ set_basisvar(lp, rx, lp->rows+cx); } /* Clean up */ Finish: FREE(rowNZ); FREE(colNZ); FREE(rowMAX); FREE(colMAX); FREE(rowWT); FREE(colWT); freeLink(&rowLL); freeLink(&colLL); } /* Construct a basis that is in some measure the "least degenerate" */ else if((lp->crashmode == CRASH_LEASTDEGENERATE) && mat_validate(mat)) { /* The logic here follows Maros */ LLrec *rowLL = NULL, *colLL = NULL; int ii, rx, cx, ix, nz, *merit = NULL; REAL *value, wx, hold, *rhs = NULL, *eta = NULL; int *rownr, *colnr; report(lp, NORMAL, "crash_basis: 'Least degenerate' basis crashing selected\n"); /* Create temporary arrays */ ok = allocINT(lp, &merit, lp->columns + 1, FALSE) && allocREAL(lp, &eta, lp->rows + 1, FALSE) && allocREAL(lp, &rhs, lp->rows + 1, FALSE); createLink(lp->columns, &colLL, NULL); createLink(lp->rows, &rowLL, NULL); ok &= (colLL != NULL) && (rowLL != NULL); if(!ok) goto FinishLD; MEMCOPY(rhs, lp->orig_rhs, lp->rows + 1); for(i = 1; i <= lp->columns; i++) appendLink(colLL, i); for(i = 1; i <= lp->rows; i++) appendLink(rowLL, i); /* Loop until we have found enough new bases */ while(colLL->count > 0) { /* Tally non-zeros matching in RHS and each active column */ nz = mat_nonzeros(mat); rownr = &COL_MAT_ROWNR(0); colnr = &COL_MAT_COLNR(0); ii = 0; MEMCLEAR(merit, lp->columns + 1); for(i = 0; i < nz; i++, rownr += matRowColStep, colnr += matRowColStep) { rx = *rownr; cx = *colnr; if(isActiveLink(colLL, cx) && (rhs[rx] != 0)) { merit[cx]++; ii++; } } if(ii == 0) break; /* Find maximal match; break ties with column length */ i = firstActiveLink(colLL); cx = i; for(i = nextActiveLink(colLL, i); i != 0; i = nextActiveLink(colLL, i)) { if(merit[i] >= merit[cx]) { if((merit[i] > merit[cx]) || (mat_collength(mat, i) > mat_collength(mat, cx))) cx = i; } } /* Determine the best pivot row */ i = mat->col_end[cx-1]; nz = mat->col_end[cx]; rownr = &COL_MAT_ROWNR(i); value = &COL_MAT_VALUE(i); rx = 0; wx = 0; MEMCLEAR(eta, lp->rows + 1); for(; i < nz; i++, rownr += matRowColStep, value += matValueStep) { ix = *rownr; hold = *value; eta[ix] = rhs[ix] / hold; hold = fabs(hold); if(isActiveLink(rowLL, ix) && (hold > wx)) { wx = hold; rx = ix; } } /* Set new basis variable */ if(rx > 0) { /* We have to update the rhs vector for the implied transformation in order to be able to find the new RHS non-zero pattern */ for(i = 1; i <= lp->rows; i++) rhs[i] -= wx * eta[i]; rhs[rx] = wx; /* Do the exchange */ set_basisvar(lp, rx, lp->rows+cx); removeLink(rowLL, rx); } removeLink(colLL, cx); } /* Clean up */ FinishLD: FREE(merit); FREE(rhs); freeLink(&rowLL); freeLink(&colLL); } return( ok ); }
/* LOCAL HELPER ROUTINE */ int bfp_LUSOLfactorize(lprec *lp, MYBOOL *usedpos, int *rownum, int *singular) { int i, j, nz, deltarows = bfp_rowoffset(lp); INVrec *invB = lp->invB; /* Handle normal, presumed nonsingular case */ if(singular == NULL) { /* Optionally do a symbolic minimum degree ordering; not that slack variables should not be processed */ /*#define UsePreprocessMDO*/ #ifdef UsePreprocessMDO int *mdo; mdo = lp->bfp_createMDO(lp, usedpos, lp->rows, TRUE); if(mdo != NULL) { for(i = 1; i <= lp->rows; i++) lp->set_basisvar(lp, i, mdo[i]); FREE(mdo); } #endif /* Reset the factorization engine */ LUSOL_clear(invB->LUSOL, TRUE); /* Add the basis columns in the original order */ for(i = 1; i <= invB->dimcount; i++) { nz = lp->get_basiscolumn(lp, i, rownum, invB->value); LUSOL_loadColumn(invB->LUSOL, rownum, i, invB->value, nz, 0); if((i > deltarows) && (lp->var_basic[i-deltarows] > lp->rows)) lp->invB->user_colcount++; } /* Factorize */ i = LUSOL_factorize(invB->LUSOL); } /* Handle case where a column may be singular */ else { LLrec *map; /* Reset the factorization engine */ i = bfp_LUSOLidentity(lp, rownum); /* Build map of available columns */ nz = createLink(lp->rows, &map, NULL); for(i = 1; i <= lp->rows; i++) { if(lp->var_basic[i] <= lp->rows) removeLink(map, i); } /* Rebuild the basis, column by column, while skipping slack columns */ j = firstActiveLink(map); for(i = 1; i <= lp->rows; i++) { if(lp->var_basic[i] <= lp->rows) continue; nz = bfp_LUSOLsetcolumn(lp, j+deltarows, lp->var_basic[i]); if(nz == LUSOL_INFORM_LUSUCCESS) lp->invB->user_colcount++; else { nz = bfp_LUSOLsetcolumn(lp, j+deltarows, i); lp->set_basisvar(lp, i, i); } j = nextActiveLink(map, j); } /* Sort the basis list */ MEMCOPY(rownum, lp->var_basic, lp->rows+1); sortByINT(lp->var_basic, rownum, lp->rows, 1, TRUE); } return( i ); }
void DirtyList::addRect(int x, int y, int width, int height) { if (x >= screenWidth_ || y >= screenHeight_ ) { return; } if (pHead_ == NULL) { // Create new link pHead_ = createLink(x, y, width, height); } else { Link *pCurr = pHead_; do { if (pCurr->element.x <= x && pCurr->element.y <= y && (pCurr->element.x + pCurr->element.width) >= (x + width) && (pCurr->element.y + pCurr->element.height) >= (y + height)) { // Current rect is enclosing new rect so don't add new rect return; } else if (pCurr->element.x > x && pCurr->element.y > y && (pCurr->element.x + pCurr->element.width) < (x + width) && (pCurr->element.y + pCurr->element.height) < (y + height)) { // Current rect is enclosed by new rect so remove it from the list Link *pToRemove = pCurr; if (pToRemove->pNext != NULL && pToRemove->pPrev != NULL) { // Current is between 2 links pToRemove->pPrev->pNext = pToRemove->pNext; pToRemove->pNext->pPrev = pToRemove->pPrev; pCurr = pToRemove->pNext; } else if (pToRemove->pPrev != NULL && pToRemove->pNext == NULL) { // We are on the last element of the list pToRemove->pPrev->pNext = NULL; pCurr = pToRemove->pPrev; } else if (pToRemove->pPrev == NULL && pToRemove->pNext != NULL) { // There no previous so we're on the head pHead_ = pCurr = pToRemove->pNext; pHead_->pPrev = NULL; } else { pCurr = NULL; } // Delete current pToRemove->pNext = NULL; pToRemove->pPrev = NULL; delete pToRemove; size_--; } else if (pCurr->pNext == NULL) { break; } else { pCurr = pCurr->pNext; } } while(pCurr != NULL); Link *l = createLink(x, y, width, height); if (pCurr == NULL) { pHead_ = l; } else { pCurr->pNext = l; l->pPrev = pCurr; } } size_++; }
void AbstractNavigationContext::makeLink( const QString& name, QString targetId, const NavigationAction& action) { modifyHtml() += createLink(name, targetId, action); }
//Dimension: specifies the number of points in (width,height)- not number of triangles //w: triangles are equilateral, with sides of length w //start: position of point 0 //a: which Axis the cloth lies 'flat' along Cloth::Cloth(const Vector2 &dimension, float w, const Vector3 &start, Axis a, VerletManager *vm, int angle): Verlet(vm) { int r = dimension.y; int c = dimension.x; row = r; col = c; //Calculate width and height after rotating by angle (r_w, r_h) QPair<Vector2,Vector2> dim = rotateTriangle(w,angle); Vector2 r_w = dim.first; Vector2 r_h = dim.second; //Assign based on axis orientation Vector3 width, height; int nextA = next(a); int prevA = prev(a); width.xyz[a]=0; height.xyz[a]=0; width.xyz[prevA]=r_w.x; height.xyz[prevA]=r_h.x; width.xyz[nextA]=r_w.y; height.xyz[nextA]=r_h.y; Vector3 half_width = width*.5; //Create points //.__.__. //._.__._. //^points on even + odd rows, w/ c of 3 for(int i =0; i<r; i++) { if(i%2==0) { //even for(int j = 0; j<c; j++) createPoint(start+j*width+i*height); } else { //odd for(int j = 0; j<=c; j++) if(j==0) createPoint(start+i*height); else if(j==c) createPoint(start+(j-1)*width+i*height); else createPoint(half_width+start+(j-1)*width+i*height); } } //***************************************************TESTING COLLISIONS triPP.resize(numPoints); //Create structural links //|\/\/| | / / \ \ | //|/\/\| | \ \ / / | //^vertical ^left ^right for(int i =0; i<r; i++) { bool even = i%2==0; for(int j = 0; (j<c&&even) || (j<=c&&!even); j++) { int index = j+i*c+i/2; if((j<c-1&&even) || (j<c&&!even)) //last point in row doesn't have link after it createLink(index, index+1); //horizontal if(i<r-1) { //last row doesn't have link beneath it if(even) { //even createLink(index, index+c); //vertical, left createLink(index, index+c+1); //vertical, right } else { //odd if(j<c) //furthest right point on odd row doesn't have point to left beneath it createLink(index, index+c+1); //vertical, left if(j>0) //furthest left point on odd row doesn't have point to right beneath it createLink(index, index+c); //vertical, right } } } } //Triangulate for(int i =0; i<r; i++) { bool even = i%2==0; for(int j = 0; (j<c-1&&even) || (j<c&&!even); j++) { int index = j+i*c+i/2; if(i<r-1) //triangles below points of row triangulate(index,index+c+1,index+1); if(i>0) //triangles above points of row triangulate(index,index+1,index-c); //triangulate(index,index-c,index+1); //alternating normals } } //Create bend constraints //| \ / _._ //| \ / for(int i = 0; i<r; i++) { bool even = i%2==0; for(int j = 0; j<=c; j++) { int index = j+i*c+i/2; if((j+2<c&&even) || (j+2<=c&&!even)) //horizontal createLink(index,index+2); if(i+2<r && ((even&&(j==0 || j==c-1)) || (!even&&(j==0 || j==c)))) //vertical, at edges createLink(index,index+2*c+1); if((even&&j>=1&&j<=c)||(!even&&j>=2&&j<=c)) //diagonal, left if(i+2<r && ((even&&j>=1&&j<c)||(!even&&j>=2&&j<c))) //diagonal, left createLink(index,index+2*c); if(i+2<r && ((even&&j>=0&&j<c-1)||(!even&&j>=1&&j<c-1))) //diagonal, right createLink(index,index+2*(c+1)); } } }
// Returns true upon error. static bool createSymLink(const char *to, const char *from) { return createLink(&CreateSymbolicLinkW, to, from); }
// Returns true upon error. static bool createHardLink(const char *to, const char *from) { return createLink(&CreateHardLinkW, to, from); }
/** * This functions sets whether we can traverse to the other node. A link is * created if necessary. Note that calls to this function should be * symmetric - you should also call other->setLink(this, blah). * * @param other The other node to link to. * @param canTraverse Can we go from this node to other? * * @return The link from this to other. */ ChunkLinkPtr EditorChunkItemLinkable::setLink(EditorChunkItemLinkable *other, bool canTraverse) { if (other == NULL) return ChunkLinkPtr(); preloadLinks_[other->guid_] = canTraverse; // If there isn't a link, create one: bool owns = guid() < other->guid(); ChunkLinkPtr link = findLink(other); if (link == NULL) { link = createLink(); if (owns) { link->startItem(chunkItem()); link->endItem(other->chunkItem()); } else { link->startItem(other->chunkItem()); link->endItem(chunkItem()); } links_.push_back(link); other->links_.push_back(link); if (owns) { if (chunkItem()->chunk() != NULL) chunkItem()->chunk()->addStaticItem(link); } else { if (other->chunkItem()->chunk() != NULL) other->chunkItem()->chunk()->addStaticItem(link); } } ChunkLink::Direction dir = link->direction(); if (canTraverse) { if (owns) { link->direction ( (ChunkLink::Direction)(dir | ChunkLink::DIR_START_END) ); } else { link->direction ( (ChunkLink::Direction)(dir | ChunkLink::DIR_END_START) ); } } else { if (owns) { link->direction ( (ChunkLink::Direction) (ChunkLink::DIR_BOTH & (dir & ~ChunkLink::DIR_START_END)) ); } else { link->direction ( (ChunkLink::Direction) (ChunkLink::DIR_BOTH & (dir & ~ChunkLink::DIR_END_START)) ); } } return link; }
ClothSimulation::Link ClothSimulation::createLink(const float4* vtx, const float* mass, u32 idxA, u32 idxB, float dampingFactor) { return createLink( vtx[idxA], vtx[idxB], idxA, idxB, mass[idxA], mass[idxB], dampingFactor ); }