CStrVector CH3CDlg::ParseCmdLine() { // 从命令行获取文件路径 CStrVector parameters; tstring tstrCmdLine(theApp.m_lpCmdLine); size_t cmdLen = tstrCmdLine.length(); if(cmdLen > 0) { for(size_t i = 0; i < cmdLen; ++i) { CString para(_T("")); if(tstrCmdLine[i] == _T('"')) { ++i; for(; i < cmdLen && tstrCmdLine[i] != _T('"'); ++i) para.AppendChar(tstrCmdLine[i]); parameters.push_back(para); ++i; } else { for(; i < cmdLen && tstrCmdLine[i] != _T(' '); ++i) para.AppendChar(tstrCmdLine[i]); parameters.push_back(para); } } } // 从命令行获取文件路径结束 return parameters; }
void TestChainTraverserComments::TestFixAnnotationChrFmt() { RTFFileContext context; CRtfDocumentChainBuilder bld(&context); CChainTraverser_FixCommentStyles trav(&bld); CRTF_String string(bld.GetContext(), Detached); trav.FixAnnotationChrFmt(&string); CRTF_Note note(bld.GetContext(), Detached); trav.FixAnnotationChrFmt(¬e); CRTF_ParaMarker para(bld.GetContext(), Detached); CRTF_CharacterProperties props(&context); RTFchrfmt cfmt(&context); cfmt.SetAnnotationChrfmt(asAnnotationConfirmed); cfmt.Flags.byBits.m_iHidden = 1; props.SetChrfmt(cfmt); para.SetCharFormat(&props); assertMessage(para.GetCharFormat()->GetChrfmt().GetAnnotationChrfmt()==asNone, _T("Annotation Chrfmt is always set to asNone now. We don't write them out any more.")); assertTest(para.GetCharFormat()->GetChrfmt().get_bHidden()); trav.FixAnnotationChrFmt(¶); assertTest(para.GetCharFormat()->GetChrfmt().GetAnnotationChrfmt()==asNone); assertTest(!para.GetCharFormat()->GetChrfmt().get_bHidden()); }
//Run inference with Lazy Flipper initialized to setting in initlab void runICM(GraphicalModelType* gm,std::string ofname, std::string initlab) { //Initial Labelling std::vector<LabelType> startPoint(gm->numberOfVariables()); std::ifstream input; input.open(initlab.c_str()); int label; for(size_t i=0;i<gm->numberOfVariables();i++) { input>>label; startPoint[i] = LabelType(label); #ifdef DEBUG std::cout<<"L"<<i<<":"<<label<<" "; #endif } //Run Inference ICM::Parameter para(startPoint); ICM icm(*gm,para); std::cout<<"Running Inference"<<std::endl; icm.infer(); std::cout << "MAP Result: " << icm.value() << " Bound: "<<icm.bound()<<std::endl; std::vector<LabelType> result; icm.arg(result); //Write Result writeResult(result,ofname); }
//Run inference with Lazy Flipper initialized to setting in initlab void runLazyFlipper(GraphicalModelType* gm,std::string ofname, std::string initlab, size_t subGraphsize) { //Initial Labelling std::vector<LabelType> startPoint(gm->numberOfVariables()); std::ifstream input; input.open(initlab.c_str()); int label; for(size_t i=0;i<gm->numberOfVariables();i++) { input>>label; startPoint[i] = LabelType(label); #ifdef DEBUG std::cout<<"L"<<i<<":"<<label<<" "; #endif } //Run Inference size_t maxSubgraphsize; if(subGraphsize<=0) maxSubgraphsize = gm->numberOfVariables()/2; else maxSubgraphsize = subGraphsize; LazyFlipper::Parameter para(maxSubgraphsize); LazyFlipper lf(*gm,para); lf.setStartingPoint(startPoint.begin()); std::cout<<"Running Inference"<<std::endl; lf.infer(); std::cout << "MAP Result: " << lf.value() << " Bound: "<<lf.bound()<<std::endl; std::vector<LabelType> result; lf.arg(result); //Write Result writeResult(result,ofname); }
const BOOL CartridgeFinder::Reconstr(CString& bkColor, CString& PointTotal, CString& MsrPointIndex, CString& Parameter) { if (color(bkColor) & pointTotal(PointTotal) & msrIndex(MsrPointIndex) & para(Parameter)) return TRUE; else return FALSE; }
void nsSceneTracker::HandleCDataEvent (nsIDOMEvent* anEvent) { nsCOMPtr<nsIDOMEventTarget> aTarget; anEvent->GetTarget(getter_AddRefs(aTarget)); nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aTarget)); if (! node) return; nsCOMPtr<nsIDOMHTMLParagraphElement> para (do_QueryInterface(node)); nsresult rv; while (! para) { nsIDOMNode* parent; rv = node->GetParentNode(&parent); if (NS_FAILED(rv)) return; if (! parent) return; node = parent; NS_RELEASE(parent); para = do_QueryInterface(node); } // Check if it's a non-scene structure element nsString className; para->GetAttribute(NS_LITERAL_STRING("class"), className); nsString nodeID; para->GetAttribute(NS_LITERAL_STRING("id"), nodeID); if (! className.Equals(NS_LITERAL_STRING("sceneheading"))) { nsCOMPtr<nsIDOMElement> scene; mEditor->SceneContaining(node, getter_AddRefs(scene)); if (scene) { scene->GetAttribute(NS_LITERAL_STRING("id"), nodeID); if (! nodeID.IsEmpty()) { nsCOMPtr<nsIRDFResource> sceneres; rv = SceneForSceneID(nodeID, getter_AddRefs(sceneres)); if (NS_SUCCEEDED(rv)) NotifySceneContentChanged(sceneres); } } return; } if (mSceneHeaderTimer) { mSceneHeaderTimer->Cancel(); // Invoke the last timer's callback if it's a different scene ID if (! (mSceneID.IsEmpty() || nodeID.Equals(mSceneID))) SceneHeaderChanged(mSceneID); } if (nodeID.IsEmpty()) { printf("No ID on a scene node, triggering a full update.\n"); Update(); return; } mSceneID.Assign(nodeID); mSceneHeaderTimer = do_CreateInstance("@mozilla.org/timer;1"); mSceneHeaderTimer->InitWithFuncCallback(SceneHeaderChangedFunc, (void *)this, 1500, nsITimer::TYPE_ONE_SHOT); }
int main(int argc, char *argv[]){ if(argc==1){ QApplication a(argc, argv); XeVe_Window w; w.show(); return a.exec(); } if(argc==2){ QString help(argv[1]); if(help=="-h" || help=="--help"){ fprintf(stderr, "usage: evaluate <file1> [<file2>]\n"); fprintf(stderr, "\tdetector configuration: -c <configfile>\n"); fprintf(stderr, "\taddback + Coincidence: -a/--addCoinc\n"); fprintf(stderr, "\tdebug mode: -d/--debug\n"); fprintf(stderr, "\tcreate no matrices: -nm/--noMatrices\n"); fprintf(stderr, "\tprint index summary: -s\n"); exit(1); } } if(argc>=3){ evaluate *iSort = new evaluate; iSort->debug=false; iSort->addCoinc=false; iSort->createMatrices=true; iSort->addback=false; for(int i=0; i<argc; i++){ QString para(argv[i]); if(para=="-a" || para=="--addCoinc"){ qDebug() << "addCoinc mode"; iSort->createMatrices=true; iSort->addCoinc=true; } if(para=="-nm" || para=="--noMatrices"){ iSort->createMatrices=false; qDebug() << "no matrices"; } if(para=="-d" || para=="--debug"){ iSort->debug=true; } } iSort->countingRate=true; iSort->crTop=188; iSort->crBottom=182; iSort->crTimeDiff=3600; iSort->countingRateFile="./CountingRates"; return iSort->sort(argc, argv); } }
int main(int argc, char *argv[]) { QApplication a(argc, argv); // bamWindow *w = new bamWindow; creatorWindow *x = new creatorWindow; if(argc>1){ for(int i=1; i<argc; i++){ QString para(argv[i]); switch(switchParameters(para)){ case 0: if(!file){ exit(1); } break; case 1: creatorWin=true; break; case 2: bamWin=true; break; case 3: file=i; break; case 4: switchParameters("-h"); break; } } } // if(bamWin){ // w->show(); // return a.exec(); // } if(creatorWin || argc==1){ x->show(); return a.exec(); } if(file){ QString fileName(argv[file+1]); x->file=1; x->loadFileName=fileName; x->loadInput(); x->calculate(); // w->close(); x->close(); a.quit(); } }
bool LinearParameter::Write2XML(TiXmlNode& root) { TiXmlElement para("Parameter"); para.SetAttribute("Type","Linear"); Parameter::Write2XML(para); para.SetDoubleAttribute("min",dMin); para.SetDoubleAttribute("max",dMax); para.SetDoubleAttribute("step",dStep); root.InsertEndChild(para); return true; }
task main() { waitForStart(); while(true){ getJoystickSettings(joystick); moveBase(joystick.joy1_x1, joystick.joy1_y1); lift(); para(); } }
void PageIterator::RestartParagraph() { if (it_->block() == NULL) return; // At end of the document. PAGE_RES_IT para(page_res_); PAGE_RES_IT next_para(para); next_para.forward_paragraph(); while (next_para.cmp(*it_) <= 0) { para = next_para; next_para.forward_paragraph(); } *it_ = para; BeginWord(0); }
void StateInitializer::rootSolveActivations(const SimTK::State& s, const Vector& muscleForces, const Vector& lm, const Vector& lm_dot, const Vector& acts_min, const Vector& acts_max, const Vector& tol_acts, Vector& activations) const { int numMuscles = lm.size(); Array<double> para(0.0,numMuscles*2); for(int i=0;i<numMuscles;i++) { para[i] = lm[i]; para[numMuscles+i] = lm_dot[i]; } ROCINForceController::rootSolve(&(ROCINForceController::evaluateMuscleForceBasedOnActivation),*_model,s,muscleForces,acts_min,acts_max,tol_acts,activations,¶[0]); }
void Q_Wordreciting::init() { if (!wordreciting->ifStart()) { this->setEnabled(false); q_WordrecitingInit->show(); q_WordrecitingInit->start(wordreciting); } else { para(); } }
int main(int argc, char** argv) { xdl::IPXdevLCore core = xdl::createCore(); core->plug(xdl::XdevLPluginName("XdevLComputeDeviceCL"), xdl::XdevLVersion(0,1,0)); auto computeDevice = xdl::createModule<xdl::IPXdevLComputeDevice>(core, xdl::XdevLModuleName("XdevLComputeDevice"), xdl::XdevLID("MyComputeDevice")); // We need a context. auto context = computeDevice->createContext(); // We need a command queue to run commands. auto commandQueue = context->createCommandQueue(); auto program = context->createProgram(); auto inBuffer = context->createBuffer(xdl::XDEVL_COMPUTE_BUFFER_READ_ONLY, sizeof(float) * 10); auto outBuffer = context->createBuffer(xdl::XDEVL_COMPUTE_BUFFER_WRITE_ONLY, sizeof(float) * 10); // // Load and build the kernel. // auto kernel = program->compileFromFile(xdl::XdevLFileName("compute_device_demo.cl"), xdl::XdevLString("calculate_sqrt")); for(int a = 0; a < 100; a++) { kernel->setArgumentBuffer(0, inBuffer); kernel->setArgumentBuffer(1, outBuffer); kernel->setArgumentFloat(2, 2); inBuffer->upload(commandQueue.get(), sizeof(float) * 10, (xdl::xdl_uint8*)data); xdl::XdevLComputeExecuteParameter para(commandQueue.get(), kernel.get(), {32}); program->execute(para); // std::cout << "Before: " << std::endl; // for(auto item : data) { // std::cout << item << " : "; // } // std::cout << std::endl; outBuffer->download(commandQueue.get(), sizeof(float) * 10, (xdl::xdl_uint8*)data); std::cout << "After: " << std::endl; for(auto item : data) { std::cout << item << " : "; } std::cout << std::endl; } xdl::destroyCore(core); }
void CommunicateSensor::createObstacleSensorsAgents(){ for(auto onePair : checkAgentContainer){ if(onePair.second.first == false){ Sensor* obstacleSensor = SensorFactory::createSensor(sensorType::OBSTACLE_ACTOR,createGlmVec(body->GetPosition()),0.1f); std::pair<unsigned int, Sensor*> para(obstacleSensor->getId(),obstacleSensor); obstacleSensorContainer.insert(para); obstacleSensor->setParentSensor(this); obstacleSensor->sendObstacleSensor(onePair.second.second); obstacleSensor->setWhereIWasSend(onePair.first); std::pair<bool,b2Vec2> positionPair(true,onePair.second.second); checkAgentContainer[onePair.first] = positionPair; } } }
task main() { //initializeRobot(); while(true){ getJoystickSettings(joystick); servoChangeRate[servo1] = SERVO_CHANGE_RATE; main_wheel(joystick.joy1_x1, joystick.joy1_y1); lift(joystick.joy2_y1); para(joystick.joy2_y2); servoSwitch(joy1Btn(2), joy1Btn(4)); } }
void GeneticClass::generateNastepniki(){ // Tworzenie wektora wierzcholkow, kazdy wierzcholek ma wektor wierzcholkow ktore pasuja do niego i maja ocene mniejsza od 1000 nastepniki.resize(GraphClass::vertex); for (int i = 0; i <GraphClass::vertex; i++) { for (int j = 0; j < GraphClass::vertex; j++) { if (GraphClass::matrix[i][j] != 10){ vector<int> para(2); para[0] = j; para[1] = GraphClass::matrix[i][j]; nastepniki[i].push_back(para); } } sort(nastepniki[i].begin(), nastepniki[i].end(), rosnaco); // cout << i << ":\t"; showVector(nastepniki[i]); } }
bool TextFormatter::FormatFwd(CFDC& dc, FilePos start) { AdjustPos(start); // just to be safe if (start.para >= m_tf->Length(start.docid)) return false; // at eof m_lines.RemoveAll(); m_top = start; bool header = true; for (int page = 0; page < m_pages; ++page) { int h = 0; int beg = m_lines.GetSize(); while (h < m_height && start.para < m_tf->Length(start.docid)) { Paragraph para(m_tf->GetParagraph(start.docid, start.para)); bool empty = para.len == 0 || para.len == 1 && para.str[0] == _T(' '); if (h == 0 && empty) { start.off = para.len; AdjustPos(start); continue; } if (para.flags & Paragraph::header) { if (!header) break; } else if (!empty && !(para.flags & Paragraph::image)) header = false; int lh = WrapLine(dc, para, start, m_lines, h, m_height - h); if (lh < 0) break; AdjustPos(start); h += lh; } m_pagelen.SetAtGrow(page, m_lines.GetSize() - beg); } m_bot = start; Highlight(); // add one dummy line always Line l; l.pos = m_bot; m_lines.Add(l); return true; }
void nsSceneTracker::HandleInsertedEvent (nsIDOMEvent* anEvent) { nsCOMPtr<nsIDOMEventTarget> aTarget; anEvent->GetTarget(getter_AddRefs(aTarget)); nsCOMPtr<nsIDOMHTMLParagraphElement> para(do_QueryInterface(aTarget)); if (! para) return; nsString className; para->GetAttribute(NS_LITERAL_STRING("class"), className); if (className.Equals(NS_LITERAL_STRING("sceneheading"))) { PRBool propagateChanges = PR_TRUE; while (propagateChanges && para) { nsresult rv = AssignDefaultSceneNumber(para, &propagateChanges); if (NS_FAILED(rv)) return; rv = UpdateSceneNumberLiterals(para); if (NS_FAILED(rv)) return; nsCOMPtr<nsIDOMHTMLParagraphElement> node = para; rv = GetNextScene(node, getter_AddRefs(para)); if (NS_FAILED(rv)) return; } Update(); return; } // It wasn't a scene heading, so it must be a change to scene contents nsCOMPtr<nsIDOMElement> scene; nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aTarget)); mEditor->SceneContaining(node, getter_AddRefs(scene)); if (scene) { nsString nodeID; scene->GetAttribute(NS_LITERAL_STRING("id"), nodeID); if (! nodeID.IsEmpty()) { nsCOMPtr<nsIRDFResource> sceneres; nsresult rv = SceneForSceneID(nodeID, getter_AddRefs(sceneres)); if (NS_SUCCEEDED(rv)) NotifySceneContentChanged(sceneres); } } }
static int ShellExecAsUser_HandlerProc(IShellDispatch2 *const dispatch, const void *const data) { int iSuccess = SHELL_EXEC_AS_USER_FAILED; const shell_exec_as_user_param_t *const param = (const shell_exec_as_user_param_t*) data; DispatchPendingMessages(125); variant_t vEmpty; variant_t verb(param->pcOperation); variant_t file(param->pcFileName); variant_t para(param->pcParameters); variant_t show(SW_SHOWNORMAL); HRESULT hr = dispatch->ShellExecute(file, para, vEmpty, verb, show); if(SUCCEEDED(hr)) { iSuccess = SHELL_EXEC_AS_USER_SUCCESS; } return iSuccess; }
void nsSceneTracker::HandleRemovedEvent (nsIDOMEvent* anEvent) { nsCOMPtr<nsIDOMEventTarget> aTarget; anEvent->GetTarget(getter_AddRefs(aTarget)); nsCOMPtr<nsIDOMHTMLParagraphElement> para(do_QueryInterface(aTarget)); if (! para) return; // We have to react on a timer callback, otherwise the scene will not have // removed yet and the update will be premature. nsString className; para->GetAttribute(NS_LITERAL_STRING("class"), className); // Signal a full update for removed scene headings if (className.Equals(NS_LITERAL_STRING("sceneheading"))) mTimerFullUpdate = PR_TRUE; else mTimerNodes.AppendObject(para); // No need to schedule multiple timers, we batch using mTimerNodes if (mTimer) return; mTimer = do_CreateInstance("@mozilla.org/timer;1"); mTimer->InitWithCallback(this, 100, 0); }
void nsScriptPaginator::AdjustNextPageBreak () { NS_NAMED_LITERAL_STRING(kClassStr, "class"); NS_NAMED_LITERAL_STRING(kSoftBreakStr, "softbreak"); NS_NAMED_LITERAL_STRING(kHardBreakStr, "hardbreak"); NS_NAMED_LITERAL_STRING(kActStr, "act"); NS_NAMED_LITERAL_STRING(kDivStr, "div"); // Allow an extra line per page to accommodate bottom margins const PRInt32 kPageHeight = PRInt32(mLineHeight * (mLinesPerPage + 1)); nsCOMPtr<nsIDOMNode> node = mNextPageStartsAt; if (! node) { nsCOMPtr<nsIDOMHTMLDocument> hdoc(do_QueryInterface(mScript)); nsCOMPtr<nsIDOMHTMLElement> body; hdoc->GetBody(getter_AddRefs(body)); if (! body) { return; } body->GetFirstChild(getter_AddRefs(node)); mCurPageBreakNum = 0; if (! node) { return; } } nsCOMPtr<nsIDOMNSHTMLElement> element(do_QueryInterface(node)); if (! element) return; PRInt32 offset = 0; element->GetOffsetTop(&offset); PRUint32 pageEnd = PRUint32(offset + kPageHeight); nsCOMPtr<nsIDOMNSHTMLElement> innerBreak(nsnull); // Adjust for height of page break if we start at one nsString className; { nsCOMPtr<nsIDOMElement> elemnode(do_QueryInterface(node)); elemnode->GetAttribute(kClassStr, className); if (className.Equals(kSoftBreakStr) || className.Equals(kHardBreakStr)) { PRInt32 height; element->GetClientHeight(&height); pageEnd += height; } } // Basic strategy: // 1. Get the next node // 2. If the next node is undefined // 2.1. If the page break cache extends further // 2.1.1. Splice the remaining page breaks // 2.2. Exit // 3. Else if the next node is a hard break (or act) // 3.1. Advance the page cursor // 3.2. Exit // 4. Else if the next node is a soft break // 4.1. If a soft break is cached as |innerBreak| // 4.1.1. Remove |innerBreak| // 4.2. Cache the node as |innerBreak| // 5. Else if the node does not fit the page // 5.1. Find the last node (inclusive) that allows a break before it // 5.2. If a soft break is cached as |innerBreak| // 5.2.1. If |innerBreak| occurs as the previous sibling to the last node // 5.2.1.1. Advance the page cursor // 5.2.1.2. Exit // 5.2.2. Else // 5.2.2.1. Remove |innerBreak| // 5.2.2.2. Insert a new soft page break // 5.2.2.3. Advance the page cursor // 5.2.2.4. Exit // 5.3. Else // 5.3.1. Insert a new soft page break // 5.3.2. Advance the page cursor // 5.3.3. Exit // 6. Else // 6.1. Continue nsCOMPtr<nsIDOMNode> tmpnode; PRUint16 nodeType = 0; nsCOMPtr<nsIDOMNode> elemnode(do_QueryInterface(element)); elemnode->GetNextSibling(getter_AddRefs(tmpnode)); if (tmpnode) tmpnode->GetNodeType(&nodeType); while (tmpnode && nodeType != nsIDOMNode::ELEMENT_NODE) { nsCOMPtr<nsIDOMNode> tmpnode2; tmpnode->GetNextSibling(getter_AddRefs(tmpnode2)); tmpnode = tmpnode2; if (tmpnode) tmpnode->GetNodeType(&nodeType); } if (tmpnode) element = do_QueryInterface(tmpnode); else element = nsnull; while (element) { nsCOMPtr<nsIDOMElement> elemnode(do_QueryInterface(element)); elemnode->GetAttribute(kClassStr, className); element->GetOffsetTop(&offset); // If it's an act, make sure it's got a page break before it, unless // it's the first element in the script. if (className.Equals(kActStr)) { // Get the previous element to this act that isn't a page break elemnode->GetPreviousSibling(getter_AddRefs(tmpnode)); /* if (tmpnode) tmpnode->GetNodeType(&nodeType); while (tmpnode && nodeType != nsIDOMNode::ELEMENT_NODE) { nsCOMPtr<nsIDOMNode> tmpnode2; tmpnode->GetPreviousSibling(getter_AddRefs(tmpnode2)); tmpnode = tmpnode2; if (tmpnode) tmpnode->GetNodeType(&nodeType); } */ while (tmpnode) { nsCOMPtr<nsIDOMHTMLParagraphElement> para(do_QueryInterface(tmpnode)); if (para) break; nsCOMPtr<nsIDOMNode> tmpnode2; tmpnode->GetPreviousSibling(getter_AddRefs(tmpnode2)); tmpnode = tmpnode2; } nsCOMPtr<nsIDOMElement> prev(do_QueryInterface(tmpnode)); // If no previous element, then this isn't important if (prev) { // Otherwise, make sure the act is preceded by a page break prev->GetAttribute(kClassStr, className); if (! className.Equals(kSoftBreakStr) && ! className.Equals(kHardBreakStr)) { // Make a break! nsCOMPtr<nsIDOMElement> breaknode; mScript->CreateElement(kDivStr, getter_AddRefs(breaknode)); prev = do_QueryInterface(breaknode); prev->SetAttribute(kClassStr, kSoftBreakStr); nsCOMPtr<nsIDOMText> text; mScript->CreateTextNode(NS_LITERAL_STRING(" "), getter_AddRefs(text)); nsCOMPtr<nsIDOMNode> dummy; prev->AppendChild(text, getter_AddRefs(dummy)); nsCOMPtr<nsIDOMNode> parent; elemnode->GetParentNode(getter_AddRefs(parent)); parent->InsertBefore(prev, elemnode, getter_AddRefs(dummy)); } nsCOMPtr<nsIDOMNSHTMLElement> htmlprev(do_QueryInterface(prev)); htmlprev->GetOffsetTop(&offset); if (mCurPageBreakNum >= mPageBreakOffsets.Length()) mPageBreakOffsets.AppendElement((PRUint32) offset); else mPageBreakOffsets[mCurPageBreakNum] = (PRUint32) offset; ++mCurPageBreakNum; mNextPageStartsAt = do_QueryInterface(element); return; } } // Hard breaks don't move. Just record the offset and keep going. if (className.Equals(kHardBreakStr)) { element->GetOffsetTop(&offset); if (mCurPageBreakNum >= mPageBreakOffsets.Length()) mPageBreakOffsets.AppendElement(offset); else mPageBreakOffsets[mCurPageBreakNum] = offset; ++mCurPageBreakNum; mNextPageStartsAt = do_QueryInterface(element); return; } element->GetOffsetTop(&offset); PRInt32 height; element->GetClientHeight(&height); if (className.Equals(kSoftBreakStr)) { // Soft break! Make sure it's in the right position, and eliminate // or move up any preceding soft break that isn't necessary. if (innerBreak) { // Remove the last inner break, and make this one the new inner // break. No need to adjust pageEnd, because the removed page break // balances the current page break. nsCOMPtr<nsIDOMNode> parent; nsCOMPtr<nsIDOMNode> innernode(do_QueryInterface(innerBreak)); nsCOMPtr<nsIDOMNode> dummy; innernode->GetParentNode(getter_AddRefs(parent)); parent->RemoveChild(innernode, getter_AddRefs(dummy)); } else { elemnode->GetNextSibling(getter_AddRefs(tmpnode)); if (tmpnode) tmpnode->GetNodeType(&nodeType); while (tmpnode && nodeType != nsIDOMNode::ELEMENT_NODE) { nsCOMPtr<nsIDOMNode> tmpnode2; tmpnode->GetNextSibling(getter_AddRefs(tmpnode2)); tmpnode = tmpnode2; if (tmpnode) tmpnode->GetNodeType(&nodeType); } if (tmpnode) { nsCOMPtr<nsIDOMNSHTMLElement> next(do_QueryInterface(tmpnode)); PRInt32 nextOffset = 0; next->GetOffsetTop(&nextOffset); // pageEnd += PRUint32(nextOffset - offset); } } innerBreak = element; } else if (PRUint32(offset + height) > pageEnd) { // Not a soft break, but it exceeds the page length so // we need to paginate. // If we can't break here, rewind until we reach a node where we can. tmpnode = do_QueryInterface(element); while (! CanBreakBeforeNode(tmpnode) && tmpnode != mNextPageStartsAt) { nsCOMPtr<nsIDOMNode> prev; tmpnode->GetPreviousSibling(getter_AddRefs(prev)); if (! prev) break; prev->GetNodeType(&nodeType); while (prev && nodeType != nsIDOMNode::ELEMENT_NODE) { nsCOMPtr<nsIDOMNode> tmpnode2; prev->GetPreviousSibling(getter_AddRefs(tmpnode2)); if (tmpnode2) tmpnode2->GetNodeType(&nodeType); prev = tmpnode2; } tmpnode = prev; } // If |tmpnode| == |mNextPageStartsAt|, we've backtracked to the // previous page. This generally happens when an element is too big // to fit on the page. Until we can break long elements in half, keep // going forward until the next opportunity to insert a break. if (tmpnode == mNextPageStartsAt) { // Set |element| to the next element elemnode->GetNextSibling(getter_AddRefs(tmpnode)); if (tmpnode) tmpnode->GetNodeType(&nodeType); while (tmpnode && nodeType != nsIDOMNode::ELEMENT_NODE) { nsCOMPtr<nsIDOMNode> tmpnode2; tmpnode->GetNextSibling(getter_AddRefs(tmpnode2)); tmpnode = tmpnode2; if (tmpnode) tmpnode->GetNodeType(&nodeType); } if (tmpnode) element = do_QueryInterface(tmpnode); else element = nsnull; continue; } if (innerBreak) { // Move up the inner break to the current position (unless it's // already the previous element) nsCOMPtr<nsIDOMNode> prev; tmpnode->GetPreviousSibling(getter_AddRefs(prev)); if (! prev) break; prev->GetNodeType(&nodeType); while (prev && nodeType != nsIDOMNode::ELEMENT_NODE) { nsCOMPtr<nsIDOMNode> tmpnode2; prev->GetPreviousSibling(getter_AddRefs(tmpnode2)); if (tmpnode2) tmpnode2->GetNodeType(&nodeType); prev = tmpnode2; } nsCOMPtr<nsIDOMNode> innernode(do_QueryInterface(innerBreak)); if (prev != innernode) { nsCOMPtr<nsIDOMNode> parent; tmpnode->GetParentNode(getter_AddRefs(parent)); nsCOMPtr<nsIDOMNode> dummy; parent->InsertBefore(innernode, tmpnode, getter_AddRefs(dummy)); } } else { nsCOMPtr<nsIDOMElement> pagebreak; mScript->CreateElement(kDivStr, getter_AddRefs(pagebreak)); pagebreak->SetAttribute(kClassStr, kSoftBreakStr); nsCOMPtr<nsIDOMText> text; nsCOMPtr<nsIDOMNode> dummy; mScript->CreateTextNode(NS_LITERAL_STRING(" "), getter_AddRefs(text)); pagebreak->AppendChild(text, getter_AddRefs(dummy)); nsCOMPtr<nsIDOMNode> parent; tmpnode->GetParentNode(getter_AddRefs(parent)); parent->InsertBefore(pagebreak, tmpnode, getter_AddRefs(dummy)); innerBreak = do_QueryInterface(pagebreak); } innerBreak->GetOffsetTop(&offset); if (mCurPageBreakNum >= mPageBreakOffsets.Length()) mPageBreakOffsets.AppendElement(offset); else mPageBreakOffsets[mCurPageBreakNum] = offset; ++mCurPageBreakNum; mNextPageStartsAt = tmpnode; return; } // set |element| to the next element // Man does XPCOM make some conventions difficult! e.g., expressing // while (element = element.nextSibling && element.nodeType != ...) elemnode->GetNextSibling(getter_AddRefs(tmpnode)); if (tmpnode) tmpnode->GetNodeType(&nodeType); while (tmpnode && nodeType != nsIDOMNode::ELEMENT_NODE) { nsCOMPtr<nsIDOMNode> tmpnode2; tmpnode->GetNextSibling(getter_AddRefs(tmpnode2)); tmpnode = tmpnode2; if (tmpnode) tmpnode->GetNodeType(&nodeType); } if (tmpnode) element = do_QueryInterface(tmpnode); else element = nsnull; } // This should be guaranteed if (! element) { // Strip away any remaining page break offsets if (mPageBreakOffsets.Length() > 0 && mPageBreakOffsets.Length() > mCurPageBreakNum + 1) { mPageBreakOffsets.SetLength(mCurPageBreakNum + 1); } if (innerBreak) { nsCOMPtr<nsIDOMNode> parent; nsCOMPtr<nsIDOMNode> innernode(do_QueryInterface(innerBreak)); nsCOMPtr<nsIDOMNode> dummy; innernode->GetParentNode(getter_AddRefs(parent)); parent->RemoveChild(innernode, getter_AddRefs(dummy)); } mNextPageStartsAt = nsnull; } }
bool TextFormatter::FormatBack(CFDC& dc, FilePos start, FilePos prev_top) { AdjustPos(start, true); if (start.para == 0 && start.off == 0) return false; // at the top m_lines.RemoveAll(); m_bot = start; for (int page = m_pages - 1; page >= 0; --page) { LineArray tmp; FilePos pos = start; int h = 0; // while there are still paragrahs before while (h < m_height && (pos.para>0 || pos.off > 0)) { // format entire paragraph LineArray cp; Paragraph para(m_tf->GetParagraph(pos.docid, pos.para)); if (pos.off < para.len) // double check args para.len = pos.off; else pos.off = para.len; FilePos fp = FilePos(pos.para, 0, pos.docid); WrapLine(dc, para, fp, cp, 0, 32768); // insert the formatted paragraph at start of list tmp.InsertAt(0, &cp); for (int i = 0; i < cp.GetSize(); ++i) h += cp[i].height; pos.off = 0; AdjustPos(pos, true); } // delete extra lines int j; // remove top lines for (h = 0, j = tmp.GetUpperBound(); j >= 0 && h + tmp[j].height <= m_height; --j) h += tmp[j].height; if (j < tmp.GetUpperBound()) { if (j >= 0 && prev_top != 0 && tmp[j + 1].pos >= prev_top) { --j; tmp.RemoveAt(0, j + 1); // now remove bottom lines for (h = j = 0; j < tmp.GetSize() && h + tmp[j].height <= m_height; ++j) h += tmp[j].height; if (j < tmp.GetSize()) tmp.RemoveAt(j, tmp.GetSize() - j); } else { tmp.RemoveAt(0, j + 1); } } // save lines m_lines.InsertAt(0, &tmp); m_pagelen.SetAtGrow(page, tmp.GetSize()); start = m_lines[0].pos; if (start.para == 0 && start.off == 0) // we reached the top of file return FormatFwd(dc, FilePos(0, 0, start.docid)); } // save positions m_top = m_lines[0].pos; Highlight(); // add one dummy line always Line l; l.pos = m_bot; m_lines.Add(l); return true; }
void ISOP2P1::solveNS(int method) { int n_dof_v = fem_space_v.n_dof(); int n_dof_p = fem_space_p.n_dof(); int n_total_dof = n_dof_v * 2 + n_dof_p; /// 开始迭代. double error_N = 1.0; int iteration_times = 0; while (error_N > n_tol) { /// Newton 迭代或 Picard 迭代. /// 先更新和速度场有关的矩阵块. updateNonlinearMatrix(); /// 构建迭代矩阵. if (method == 1) buildNewtonSys4NS(); else if (method == 2) buildPicardSys4NS(); else if (method == 3) if (iteration_times < 2) buildPicardSys4NS(); else buildNewtonSys4NS(); else { std::cout << "Newton: 1, Picard: 2, Hybrid: 3." << std::endl; exit(1); } /// 建立右端项. rhs.reinit(n_total_dof); FEMSpace<double, DIM>::ElementIterator the_element_v = fem_space_v.beginElement(); FEMSpace<double, DIM>::ElementIterator end_element_v = fem_space_v.endElement(); FEMSpace<double, DIM>::ElementIterator the_element_p = fem_space_p.beginElement(); FEMSpace<double, DIM>::ElementIterator end_element_p = fem_space_p.endElement(); /// 遍历速度单元, 拼装相关系数矩阵和右端项. for (the_element_v = fem_space_v.beginElement(); the_element_v != end_element_v; ++the_element_v) { /// 当前单元信息. double volume = the_element_v->templateElement().volume(); /// 积分精度, u 和 p 都是 1 次, 梯度和散度 u 都是常数. 因此矩阵拼 /// 装时积分精度不用超过 1 次. (验证一下!) const QuadratureInfo<DIM>& quad_info = the_element_v->findQuadratureInfo(4); std::vector<double> jacobian = the_element_v->local_to_global_jacobian(quad_info.quadraturePoint()); int n_quadrature_point = quad_info.n_quadraturePoint(); std::vector<Point<DIM> > q_point = the_element_v->local_to_global(quad_info.quadraturePoint()); /// 速度单元信息. std::vector<std::vector<std::vector<double> > > basis_gradient_v = the_element_v->basis_function_gradient(q_point); std::vector<std::vector<double> > basis_value_v = the_element_v->basis_function_value(q_point); const std::vector<int>& element_dof_v = the_element_v->dof(); std::vector<double> fx_value = source_v[0].value(q_point, *the_element_v); std::vector<double> fy_value = source_v[1].value(q_point, *the_element_v); int n_element_dof_v = the_element_v->n_dof(); std::vector<double> vx_value = v_h[0].value(q_point, *the_element_v); std::vector<double> vy_value = v_h[1].value(q_point, *the_element_v); std::vector<std::vector<double> > vx_gradient = v_h[0].gradient(q_point, *the_element_v); std::vector<std::vector<double> > vy_gradient = v_h[1].gradient(q_point, *the_element_v); /// 压力单元信息. Element<double, DIM> &p_element = fem_space_p.element(index_ele_v2p[the_element_v->index()]); const std::vector<int>& element_dof_p = p_element.dof(); std::vector<std::vector<std::vector<double> > > basis_gradient_p = p_element.basis_function_gradient(q_point); std::vector<std::vector<double> > basis_value_p = p_element.basis_function_value(q_point); std::vector<double> p_value = p_h.value(q_point, p_element); int n_element_dof_p = p_element.n_dof(); /// 实际拼装. for (int l = 0; l < n_quadrature_point; ++l) { double Jxw = quad_info.weight(l) * jacobian[l] * volume; for (int i = 0; i < n_element_dof_v; ++i) { double rhs_cont = fx_value[l] * basis_value_v[i][l]; rhs_cont -= (vx_value[l] * vx_gradient[l][0] + vy_value[l] * vx_gradient[l][1]) * basis_value_v[i][l]; rhs_cont -= viscosity * innerProduct(basis_gradient_v[i][l], vx_gradient[l]); rhs_cont += p_value[l] * basis_gradient_v[i][l][0]; rhs_cont *= Jxw; rhs(element_dof_v[i]) += rhs_cont; rhs_cont = fy_value[l] * basis_value_v[i][l]; rhs_cont -= (vx_value[l] * vy_gradient[l][0] + vy_value[l] * vy_gradient[l][1]) * basis_value_v[i][l]; rhs_cont -= viscosity * innerProduct(basis_gradient_v[i][l], vy_gradient[l]); rhs_cont += p_value[l] * basis_gradient_v[i][l][1]; rhs_cont *= Jxw; rhs(n_dof_v + element_dof_v[i]) += rhs_cont; } } } /// 遍历压力单元. 拼装矩阵和右端项. for (the_element_p = fem_space_p.beginElement(); the_element_p != end_element_p; ++the_element_p) { const std::vector<int>& element_dof_p = the_element_p->dof(); int n_element_dof_p = the_element_p->n_dof(); for (int i = 0; i < n_element_dof_p; ++i) { int idx_p = the_element_p->index(); int n_chi = index_ele_p2v[idx_p].size(); for (int k = 0; k < n_chi; k++) { /// 速度单元信息. Element<double, DIM> &v_element = fem_space_v.element(index_ele_p2v[idx_p][k]); /// 几何信息. double volume = v_element.templateElement().volume(); const QuadratureInfo<DIM>& quad_info = v_element.findQuadratureInfo(4); std::vector<double> jacobian = v_element.local_to_global_jacobian(quad_info.quadraturePoint()); int n_quadrature_point = quad_info.n_quadraturePoint(); std::vector<Point<DIM> > q_point = v_element.local_to_global(quad_info.quadraturePoint()); std::vector<std::vector<double> > vx_gradient = v_h[0].gradient(q_point, v_element); std::vector<std::vector<double> > vy_gradient = v_h[1].gradient(q_point, v_element); std::vector<double> vx_value = v_h[0].value(q_point, v_element); std::vector<double> vy_value = v_h[1].value(q_point, v_element); /// 压力单元信息. std::vector<std::vector<double> > basis_value_p = the_element_p->basis_function_value(q_point); /// 具体拼装. for (int l = 0; l < n_quadrature_point; ++l) { double Jxw = quad_info.weight(l) * jacobian[l] * volume; /// 右端项还是零. 源项和 Neumann 条件. double rhs_cont = Jxw * basis_value_p[i][l] * (vx_gradient[l][0] + vy_gradient[l][1]); rhs(2 * n_dof_v + element_dof_p[i]) += rhs_cont; } } } } /// 初始化未知量. Vector<double> x(n_total_dof); /// 边界条件处理. boundaryValueNS(x); std::cout << "nonlinear res:" << std::endl; double revx = 0.0; for (int i = 0; i < n_dof_v; ++i) revx += rhs(i) * rhs(i); std::cout << "vx re: " << sqrt(revx) << std::endl; double revy = 0.0; for (int i = 0; i < n_dof_v; ++i) revy += rhs(i + n_dof_v) * rhs(i + n_dof_v); std::cout << "vy re: " << sqrt(revy) << std::endl; double rep = 0.0; for (int i = 0; i < n_dof_p; ++i) rep += rhs(i + 2 * n_dof_v) * rhs(i + 2 * n_dof_v); std::cout << "p re: " << sqrt(rep) << std::endl; double re = revx + revy +rep; std::cout << "total re: " << sqrt(re) << std::endl; std::cout << "pause ..." << std::endl; getchar(); if (sqrt(re) < n_tol) { std::cout << "Covergence with residual: " << sqrt(re) << " in step " << iteration_times << std::endl; break; } std::cout << "Building precondition matrix ..." << std::endl; /// 矩阵求解. SparseMatrix<double> mat_Axx(sp_vxvx); SparseMatrix<double> mat_Ayy(sp_vyvy); SparseMatrix<double> mat_Wxy(sp_vyvx); SparseMatrix<double> mat_Wyx(sp_vxvy); SparseMatrix<double> mat_BTx(sp_pvx); SparseMatrix<double> mat_BTy(sp_pvy); for (int i = 0; i < sp_vxvx.n_nonzero_elements(); ++i) mat_Axx.global_entry(i) = matrix.global_entry(index_vxvx[i]); for (int i = 0; i < sp_vyvy.n_nonzero_elements(); ++i) mat_Ayy.global_entry(i) = matrix.global_entry(index_vyvy[i]); for (int i = 0; i < sp_vyvx.n_nonzero_elements(); ++i) mat_Wxy.global_entry(i) = matrix.global_entry(index_vyvx[i]); for (int i = 0; i < sp_vxvy.n_nonzero_elements(); ++i) mat_Wyx.global_entry(i) = matrix.global_entry(index_vxvy[i]); for (int i = 0; i < sp_pvx.n_nonzero_elements(); ++i) mat_BTx.global_entry(i) = matrix.global_entry(index_pvx[i]); for (int i = 0; i < sp_pvy.n_nonzero_elements(); ++i) mat_BTy.global_entry(i) = matrix.global_entry(index_pvy[i]); std::cout << "Precondition matrix builded!" << std::endl; /// 矩阵求解. dealii::SolverControl solver_control (4000000, l_tol); SolverGMRES<Vector<double> >::AdditionalData para(2000, false, true); SolverGMRES<Vector<double> > gmres (solver_control, para); std::cout << "Begin to solve linear system ..." << std::endl; // gmres.solve (matrix, x, rhs, navierstokes_preconditioner); gmres.solve (matrix, x, rhs, PreconditionIdentity()); /// 调试块: 直接观测真实残量. // Vector<double> tmp(n_total_dof); // matrix.vmult(tmp, x); // tmp -= rhs; // std::cout << "linear residual: " << tmp.l2_norm() << std::endl; // getchar(); FEMFunction<double, DIM> res_vx(fem_space_v); FEMFunction<double, DIM> res_vy(fem_space_v); FEMFunction<double, DIM> res_p(fem_space_p); /// 更新数值解. for (int i = 0; i < n_dof_v; ++i) { v_h[0](i) += x(i); res_vx(i) = x(i); v_h[1](i) += x(i + n_dof_v); res_vy(i) = x(i+ n_dof_v); } for (int i = 0; i < n_dof_p; ++i) { p_h(i) += x(i + 2 * n_dof_v); res_p(i) = x(i + 2 * n_dof_v); } double r_vx = Functional::L2Norm(res_vx, 1); double r_vy = Functional::L2Norm(res_vy, 1); double r_p = Functional::L2Norm(res_p, 1); /// 这个其实是更新... error_N = r_vx + r_vy + r_p; std::cout.setf(std::ios::fixed); std::cout.precision(20); std::cout << "updated vx: " << r_vx << std::endl; std::cout << "updated vy: " << r_vy << std::endl; std::cout << "updated p: " << r_p << std::endl; std::cout << "total updated: " << error_N << std::endl; std::cout << "step " << iteration_times << ", total updated: " << error_N << ", GMRES stpes: " << solver_control.last_step() << std::endl; iteration_times++; if (iteration_times > 10) { std::cout << "Disconvergence at step 10." << std::endl; break; } } };
void SemanticMarkupEdition::createActions(KActionCollection* actionCollection) { Q_ASSERT(actionCollection); mEmphasisAction = new KAction("emphasis", actionCollection); mEmphasisAction->setCheckable(true); mEmphasisAction->setToolTip(i18nc("@info:tooltip", "Emphasized text")); mEmphasisAction->setWhatsThis(i18nc("@info:whatsthis", "Phrase tag to emphasize a word or phrase in the text.<nl/>" "Example: <emphasis>emphasized text</emphasis>")); actionCollection->addAction("kuit-edition-phrase-emphasis", mEmphasisAction); connect(mEmphasisAction, SIGNAL(triggered()), this, SLOT(emphasis())); mActions.append(mEmphasisAction); mEmphasisStrongAction = new KAction("emphasis (strong)", actionCollection); mEmphasisStrongAction->setCheckable(true); mEmphasisStrongAction->setToolTip(i18nc("@info:tooltip", "Strongly emphasized text")); mEmphasisStrongAction->setWhatsThis(i18nc("@info:whatsthis", "Phrase tag to strongly emphasize a word or phrase in the text.<nl/>" "Example: <emphasis strong=\"1\">strongly emphasized text</emphasis>")); actionCollection->addAction("kuit-edition-phrase-emphasis-strong", mEmphasisStrongAction); connect(mEmphasisStrongAction, SIGNAL(triggered()), this, SLOT(emphasisStrong())); mActions.append(mEmphasisStrongAction); mFilenameAction = new KAction("filename", actionCollection); mFilenameAction->setCheckable(true); mFilenameAction->setToolTip(i18nc("@info:tooltip", "Filename or path")); mFilenameAction->setWhatsThis(i18nc("@info:whatsthis", "Phrase tag for file or folder name or path.<nl/>" "The path separators will be transformed into what is native to the " "platform.<nl/>" "Example: <filename>/home/user/Music/song.ogg</filename>")); actionCollection->addAction("kuit-edition-phrase-filename", mFilenameAction); connect(mFilenameAction, SIGNAL(triggered()), this, SLOT(filename())); mActions.append(mFilenameAction); mInterfaceAction = new KAction("interface", actionCollection); mInterfaceAction->setCheckable(true); mInterfaceAction->setToolTip(i18nc("@info:tooltip", "GUI interface element")); mInterfaceAction->setWhatsThis(i18nc("@info:whatsthis", "Phrase tag for paths to GUI interface elements.<nl/>" "If there is more than one element in the path, use \"|\" to delimit " "elements, which will be converted into canonical delimiter.<nl/>" "Example: <interface>File|Open</interface>")); actionCollection->addAction("kuit-edition-phrase-interface", mInterfaceAction); connect(mInterfaceAction, SIGNAL(triggered()), this, SLOT(interface())); mActions.append(mInterfaceAction); mLinkAction = new KAction("link", actionCollection); mLinkAction->setCheckable(true); mLinkAction->setToolTip(i18nc("@info:tooltip", "Link to URL or widget")); mLinkAction->setWhatsThis(i18nc("@info:whatsthis", "Phrase tag to link to a URL-addressable resource.<nl/>" "Widgets in the target application interface can be linked using " "<emphasis>widget:theObjectNameOfTheWidget</emphasis><nl/>" "Example: <link url=\"http://www.kde.org\">a link</link>")); actionCollection->addAction("kuit-edition-phrase-link", mLinkAction); connect(mLinkAction, SIGNAL(triggered()), this, SLOT(link())); mActions.append(mLinkAction); mNlAction = new KAction("nl", actionCollection); mNlAction->setToolTip(i18nc("@info:tooltip", "Line break")); mNlAction->setWhatsThis(i18nc("@info:whatsthis", "Phrase tag for line breaks.<nl/>" "Example: line<nl/>break")); actionCollection->addAction("kuit-edition-phrase-nl", mNlAction); connect(mNlAction, SIGNAL(triggered()), this, SLOT(nl())); mActions.append(mNlAction); mShortcutAction = new KAction("shortcut", actionCollection); mShortcutAction->setCheckable(true); mShortcutAction->setToolTip(i18nc("@info:tooltip", "Combination of keys to press")); mShortcutAction->setWhatsThis(i18nc("@info:whatsthis", "Phrase tag for combinations of keys to press.<nl/>" "Separate the keys by \"+\" or \"-\", and the shortcut will be " "converted into canonical form.<nl/>" "Example: <shortcut>Ctrl+N</shortcut>")); actionCollection->addAction("kuit-edition-phrase-shortcut", mShortcutAction); connect(mShortcutAction, SIGNAL(triggered()), this, SLOT(shortcut())); mActions.append(mShortcutAction); mParaAction = new KAction("para", actionCollection); mParaAction->setCheckable(true); mParaAction->setToolTip(i18nc("@info:tooltip", "Paragraph")); mParaAction->setWhatsThis(i18nc("@info:whatsthis", "<para>Structure tag for text paragraphs.<nl/>" "Example: one paragraph</para><para>Other paragraph</para>")); actionCollection->addAction("kuit-edition-structure-para", mParaAction); connect(mParaAction, SIGNAL(triggered()), this, SLOT(para())); mActions.append(mParaAction); mListAction = new KAction("list", actionCollection); mListAction->setCheckable(true); mListAction->setToolTip(i18nc("@info:tooltip", "List of items")); mListAction->setWhatsThis(i18nc("@info:whatsthis", "<para>Structure tag for lists of items.<nl/>" "Can contain only <item> as subtags. List is considered an " "element of the paragraph, so the <list> must be found inside " "<para>.<nl/>" "Example: <list>" " <item>One item</item>" " <item>Other item</item>" " </list></para>")); actionCollection->addAction("kuit-edition-structure-list", mListAction); connect(mListAction, SIGNAL(triggered()), this, SLOT(list())); mActions.append(mListAction); mItemAction = new KAction("item", actionCollection); mItemAction->setCheckable(true); mItemAction->setToolTip(i18nc("@info:tooltip", "List items")); mItemAction->setWhatsThis(i18nc("@info:whatsthis", "<para>Structure tag for list items.<nl/>" "Example: <list>" " <item>One item</item>" " <item>Other item</item>" " </list></para>")); actionCollection->addAction("kuit-edition-structure-item", mItemAction); connect(mItemAction, SIGNAL(triggered()), this, SLOT(item())); mActions.append(mItemAction); updateActionStates(); }
void nuiDrawContext::DrawGradient(const nuiGradient& rGradient, const nuiRect& rEnclosingRect, nuiSize x1, nuiSize y1, nuiSize x2, nuiSize y2) { nuiVector2 vec(x2 - x1, y2 - y1); nuiVector2 para(-vec[1], vec[0]); nuiVector2 vec1(vec); nuiVector2 para1(para); vec1.Normalize(); para1.Normalize(); // What Quadrant are we in?: // | // a | b // | // ---------------- // | // c | d // | float xa, xb, xc, xd; float ya, yb, yc, yd; float x, y; float xp, yp; float xx, yy; float xxp, yyp; xa = xc = rEnclosingRect.Left(); xb = xd = rEnclosingRect.Right(); ya = yb = rEnclosingRect.Top(); yc = yd = rEnclosingRect.Bottom(); if (x1 < x2) { // Go from a to d or c to b if (y1 == y2) { x = xa; y = ya; xp = xc; yp = yc; xx = xd; yy = yd; xxp= xb; yyp= yb; } else if (y1 < y2) { // a to d IntersectLines(xa,ya, para1[0], para1[1], xb, yb, vec1[0], vec1[1], x, y); IntersectLines(xa,ya, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xp, yp); IntersectLines(xd,yd, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xx, yy); IntersectLines(xd,yd, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xxp, yyp); } else { // c to d IntersectLines(xc,yc, para1[0], para1[1], xa, ya, vec1[0], vec1[1], x, y); IntersectLines(xc,yc, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xp, yp); IntersectLines(xb,yb, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xx, yy); IntersectLines(xb,yb, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xxp, yyp); } } else { if (y1 == y2) { x = xd; y = yd; xp = xb; yp = yb; xx = xa; yy = ya; xxp= xc; yyp= yc; } else if (y1 < y2) { // b to c IntersectLines(xb,yb, para1[0], para1[1], xd, yd, vec1[0], vec1[1], x, y); IntersectLines(xb,yb, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xp, yp); IntersectLines(xc,yc, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xx, yy); IntersectLines(xc,yc, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xxp, yyp); } else { // d to a IntersectLines(xd,yd, para1[0], para1[1], xc, yc, vec1[0], vec1[1], x, y); IntersectLines(xd,yd, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xp, yp); IntersectLines(xa,ya, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xx, yy); IntersectLines(xa,ya, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xxp, yyp); } } float startx,starty; float startxp,startyp; float stopx,stopy; float stopxp,stopyp; if (y1 != y2) { IntersectLines(x1, y1, para1[0], para1[1], x, y, vec1[0], vec1[1], startx, starty); IntersectLines(x1, y1, para1[0], para1[1], xp, yp, vec1[0], vec1[1], startxp, startyp); IntersectLines(x2, y2, para1[0], para1[1], x, y, vec1[0], vec1[1], stopx, stopy); IntersectLines(x2, y2, para1[0], para1[1], xp, yp, vec1[0], vec1[1], stopxp, stopyp); } else { startx = x1; starty = y; startxp = x1; startyp = yp; stopx = x2; stopy = y; stopxp = x2; stopyp = yp; } nuiGradientStopList::const_iterator it = rGradient.GetStopList().begin(); nuiGradientStopList::const_iterator end = rGradient.GetStopList().end(); float px1, py1; float px2, py2; PushClipping(); Clip(rEnclosingRect); EnableClipping(true); nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLE_STRIP); pArray->EnableArray(nuiRenderArray::eVertex); pArray->EnableArray(nuiRenderArray::eColor); // nuiRenderArray Array(GL_LINES); // pArray->SetVertexElements(3); // pArray->SetColorElements(4); nuiColor col = it->second; pArray->SetVertex(x, y); pArray->SetColor(col); pArray->PushVertex(); pArray->SetVertex(xp, yp); pArray->PushVertex(); for ( ; it != end; ++it) { float r = it->first; float rm = 1.0f - r; px1 = startx * rm + stopx * r; py1 = starty * rm + stopy * r; px2 = startxp * rm + stopxp * r; py2 = startyp * rm + stopyp * r; col = it->second; pArray->SetColor(col); pArray->SetVertex(px2, py2); pArray->PushVertex(); pArray->SetVertex(px1, py1); pArray->PushVertex(); } pArray->SetVertex(xx, yy); pArray->PushVertex(); pArray->SetVertex(xxp, yyp); pArray->PushVertex(); DrawArray(pArray); PopClipping(); }
void CZRegHelper::ParseReg(wchar_t **arg,int num) { wchar_t szApplication[MAX_PATH]; DWORD cchLength = _countof(szApplication); QueryFullProcessImageName(GetCurrentProcess(), 0, szApplication, &cchLength); CString appPath; appPath.Format(L"%s",szApplication); if(2 == num) { if(0 == _wcsnicmp(arg[1],L"/reg",4) && wcslen(arg[1]) > 4) { CString para(arg[1]); para = para.Right(para.GetLength()-4); int index = 0; int last = 0; CString tmp; CString icoIndex ; icoIndex.Format(L"%s,0",appPath); while(-1 != (index = para.Find('|'))) { tmp = para.Left(index); para = para.Right(para.GetLength() - index -1); if(0 == tmp.CompareNoCase(L"flac")) { RegisterFileRelation(L".FLAC",appPath,L"ZLP.FLAC",icoIndex,L"FLAC"); } else if(0 == tmp.CompareNoCase(L"ape")) { RegisterFileRelation(L".APE",appPath,L"ZLP.APE",icoIndex,L"APE"); } else if(0 == tmp.CompareNoCase(L"wav")) { RegisterFileRelation(L".WAV",appPath,L"ZLP.WAV",icoIndex,L"WAV"); } else if(0 == tmp.CompareNoCase(L"mp3")) { RegisterFileRelation(L".MP3",appPath,L"ZLP.MP3",icoIndex,L"MP3"); } else if(0 == tmp.CompareNoCase(L"cue")) { RegisterFileRelation(L".CUE",appPath,L"ZLP.CUE",icoIndex,L"CUE"); } else if(0 == tmp.CompareNoCase(L"ofr")) { RegisterFileRelation(L".OFR",appPath,L"ZLP.OFR",icoIndex,L"OFR"); } else if(0 == tmp.CompareNoCase(L"ogg")) { RegisterFileRelation(L".OGG",appPath,L"ZLP.OGG",icoIndex,L"OGG"); } else if(0 == tmp.CompareNoCase(L"tak")) { RegisterFileRelation(L".TAK",appPath,L"ZLP.TAK",icoIndex,L"TAK"); } else if(0 == tmp.CompareNoCase(L"wv")) { RegisterFileRelation(L".WV",appPath,L"ZLP.WV",icoIndex,L"WV"); } else if(0 == tmp.CompareNoCase(L"aac")) { RegisterFileRelation(L".AAC",appPath,L"ZLP.AAC",icoIndex,L"AAC"); } else if(0 == tmp.CompareNoCase(L"m4a")) { RegisterFileRelation(L".M4A",appPath,L"ZLP.M4A",icoIndex,L"M4A"); } else if(0 == tmp.CompareNoCase(L"tta")) { RegisterFileRelation(L".TTA",appPath,L"ZLP.TTA",icoIndex,L"TTA"); } tmp.Empty(); } tmp.Empty(); while(-1!=(index = para.Find(','))) { tmp = para.Left(index); para = para.Right(para.GetLength() - index -1); if(0 == tmp.CompareNoCase(L"flac")) { UnRegisterFileRelation(L".FLAC",L"ZLP.FLAC"); } else if(0 == tmp.CompareNoCase(L"ape")) { UnRegisterFileRelation(L".APE",L"ZLP.APE"); } else if(0 == tmp.CompareNoCase(L"wav")) { UnRegisterFileRelation(L".WAV",L"ZLP.WAV"); } else if(0 == tmp.CompareNoCase(L"mp3")) { UnRegisterFileRelation(L".MP3",L"ZLP.MP3"); } else if(0 == tmp.CompareNoCase(L"cue")) { UnRegisterFileRelation(L".CUE",L"ZLP.CUE"); } else if(0 == tmp.CompareNoCase(L"ofr")) { UnRegisterFileRelation(L".OFR",L"ZLP.OFR"); } else if(0 == tmp.CompareNoCase(L"ogg")) { UnRegisterFileRelation(L".OGG",L"ZLP.OGG"); } else if(0 == tmp.CompareNoCase(L"tak")) { UnRegisterFileRelation(L".TAK",L"ZLP.TAK"); } else if(0 == tmp.CompareNoCase(L"wv")) { UnRegisterFileRelation(L".WV",L"ZLP.WV"); } else if(0 == tmp.CompareNoCase(L"aac")) { UnRegisterFileRelation(L".AAC",L"ZLP.AAC"); } else if(0 == tmp.CompareNoCase(L"m4a")) { UnRegisterFileRelation(L".M4A",L"ZLP.M4A"); } else if(0 == tmp.CompareNoCase(L"tta")) { UnRegisterFileRelation(L".TTA",L"ZLP.TTA"); } tmp.Empty(); } icoIndex.Empty(); para.Empty(); tmp.Empty(); SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); appPath.Empty(); } } }
TEST(SaveLoadTest, SaveLoadLatestVersion) { // Use the temp application. TaskSystem *pTempApp1 = new TaskSystem(); TaskSystem* pPreviousApp = SetWorkingBrain(pTempApp1); { Parameter para(_T("OS"), _T("Windows7")); para.SetComments(_T("global")); GetWorkingBrain()->GetVariableManager()->AddUserParameter(para); } CString conditionId = _T("DoesRegExist"); { ConditionPtr pRegCondition = Condition::Create(_T("RegisterKeyExistsCondition"), GetWorkingBrain()->GetBehaviorManager()); Parameter objectId(OBJECT_ID, conditionId); Parameter para1(_T("RootKey"), _T("HKEY_LOCAL_MACHINE")); Parameter para2(_T("SubKey"), _T("Software\\Microsoft")); pRegCondition->GetParameterTable().AddParameter(objectId); pRegCondition->GetParameterTable().AddParameter(para1); pRegCondition->GetParameterTable().AddParameter(para2); //GetWorkingBrain()->GetBehaviorManager()->RegisterCondition(pRegCondition); } CString actionId = _T("DemoToRunSysCmd"); { ActionPtr pNewAction = Action::Create(_T("RunSystemCommandAction"), GetWorkingBrain()->GetBehaviorManager()); Parameter objectId(OBJECT_ID, actionId); objectId.SetComments(_T("Object Id is used to reference this object everywhere.")); Parameter objectType; pNewAction->GetParameterTable().GetParameter(OBJECT_TYPE, objectType); objectType.SetComments(_T("Object type indicates which behavior body will this action invokes.")); Parameter cmd(APPLICATION_NAME, _T("regedit.exe")); cmd.SetComments(_T("Indicate which command will be run")); pNewAction->GetParameterTable().AddParameter(objectId); pNewAction->GetParameterTable().AddParameter(objectType); pNewAction->GetParameterTable().AddParameter(cmd); //GetWorkingBrain()->GetBehaviorManager()->RegisterAction(pNewAction); GetWorkingBrain()->GetBehaviorManager()->AddActionTask(pNewAction); } CString fileName(_T("C:\\braintest.xml")); // Save bool ret = GetWorkingBrain()->XmlOut(fileName); EXPECT_EQ(true, ret); // Load TaskSystem *pTempApp2 = new TaskSystem(); SetWorkingBrain(pTempApp2); ret = GetWorkingBrain()->XmlIn(fileName); EXPECT_EQ(true, ret); { ActionPtr pAction = GetWorkingBrain()->GetBehaviorManager()->GetActionById(actionId); EXPECT_EQ(true, (pAction != NULL)); } { ConditionPtr pCondition = GetWorkingBrain()->GetBehaviorManager()->GetConditionById(conditionId); EXPECT_EQ(true, (pCondition != NULL)); } // Recover SetWorkingBrain(pPreviousApp); }
void nuiGLDrawContext::DrawGradient(const nuiGradient& rGradient, const nuiRect& rEnclosingRect, nuiSize x1, nuiSize y1, nuiSize x2, nuiSize y2) { nglVector2f vec(x2 - x1, y2 - y1); nglVector2f para(-vec[1], vec[0]); nglVector2f vec1(vec); nglVector2f para1(para); vec1.Normalize(); para1.Normalize(); // What Quadrant are we in?: // | // a | b // | // ---------------- // | // c | d // | float xa, xb, xc, xd; float ya, yb, yc, yd; float x, y; float xp, yp; float xx, yy; float xxp, yyp; xa = xc = rEnclosingRect.Left(); xb = xd = rEnclosingRect.Right(); ya = yb = rEnclosingRect.Top(); yc = yd = rEnclosingRect.Bottom(); if (x1 < x2) { // Go from a to d or c to b if (y1 == y2) { x = xa; y = ya; xp = xc; yp = yc; xx = xd; yy = yd; xxp= xb; yyp= yb; } else if (y1 < y2) { // a to d IntersectLines(xa,ya, para1[0], para1[1], xb, yb, vec1[0], vec1[1], x, y); IntersectLines(xa,ya, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xp, yp); IntersectLines(xd,yd, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xx, yy); IntersectLines(xd,yd, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xxp, yyp); } else { // c to d IntersectLines(xc,yc, para1[0], para1[1], xa, ya, vec1[0], vec1[1], x, y); IntersectLines(xc,yc, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xp, yp); IntersectLines(xb,yb, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xx, yy); IntersectLines(xb,yb, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xxp, yyp); } } else { if (y1 == y2) { x = xd; y = yd; xp = xb; yp = yb; xx = xa; yy = ya; xxp= xc; yyp= yc; } else if (y1 < y2) { // b to c IntersectLines(xb,yb, para1[0], para1[1], xd, yd, vec1[0], vec1[1], x, y); IntersectLines(xb,yb, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xp, yp); IntersectLines(xc,yc, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xx, yy); IntersectLines(xc,yc, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xxp, yyp); } else { // d to a IntersectLines(xd,yd, para1[0], para1[1], xc, yc, vec1[0], vec1[1], x, y); IntersectLines(xd,yd, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xp, yp); IntersectLines(xa,ya, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xx, yy); IntersectLines(xa,ya, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xxp, yyp); } } float startx,starty; float startxp,startyp; float stopx,stopy; float stopxp,stopyp; if (y1 != y2) { IntersectLines(x1, y1, para1[0], para1[1], x, y, vec1[0], vec1[1], startx, starty); IntersectLines(x1, y1, para1[0], para1[1], xp, yp, vec1[0], vec1[1], startxp, startyp); IntersectLines(x2, y2, para1[0], para1[1], x, y, vec1[0], vec1[1], stopx, stopy); IntersectLines(x2, y2, para1[0], para1[1], xp, yp, vec1[0], vec1[1], stopxp, stopyp); } else { startx = x1; starty = y; startxp = x1; startyp = yp; stopx = x2; stopy = y; stopxp = x2; stopyp = yp; } nuiGradientStopList::const_iterator it = rGradient.GetStopList().begin(); nuiGradientStopList::const_iterator end = rGradient.GetStopList().end(); float px1, py1; float px2, py2; PushClipping(); nuiRect r = rEnclosingRect; nglMatrixf m(GetMatrix()); nglVectorf v1(r.Left(), r.Top(), 0); v1 = m * v1; nglVectorf v2 = nglVectorf(r.Right(), r.Bottom(), 0); v2 = m * v2; r.Set(v1[0], v1[1], v2[0], v2[1], false); Clip(r); SetClipping(true); std::vector<nuiShape::CacheElement::Vertex> vertices; nuiColor col = it->second; vertices.push_back(nuiShape::CacheElement::Vertex(x, y, col)); vertices.push_back(nuiShape::CacheElement::Vertex(xp, yp, col)); for ( ; it != end; ++it) { float r = it->first; float rm = 1.0f - r; px1 = startx * rm + stopx * r; py1 = starty * rm + stopy * r; px2 = startxp * rm + stopxp * r; py2 = startyp * rm + stopyp * r; col = it->second; vertices.push_back(nuiShape::CacheElement::Vertex(px1, py1, col)); vertices.push_back(nuiShape::CacheElement::Vertex(px2, py2, col)); } vertices.push_back(nuiShape::CacheElement::Vertex(xxp, yyp, col)); vertices.push_back(nuiShape::CacheElement::Vertex(xx, yy, col)); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(4, GL_FLOAT, sizeof(nuiShape::CacheElement::Vertex), vertices[0].mColor); glVertexPointer(3, GL_FLOAT, sizeof(nuiShape::CacheElement::Vertex), vertices[0].mCoord); glDrawArrays(GL_QUAD_STRIP, 0, vertices.size()); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); PopClipping(); }
int ShellExecAsUser(const TCHAR *pcOperation, const TCHAR *pcFileName, const TCHAR *pcParameters, const HWND parentHwnd) { /*BOOL bRet; HANDLE hToken; HANDLE hNewToken; // Notepad is used as an example //WCHAR wszProcessName[MAX_PATH] = L"C:\\Windows\\Notepad.exe"; // Low integrity SID: 0x1000 = 4096. To use Medium integrity, use 0x2000 = 8192 WCHAR wszIntegritySid[20] = L"S-1-16-4096"; PSID pIntegritySid = NULL; TOKEN_MANDATORY_LABEL TIL = {0}; PROCESS_INFORMATION ProcInfo = {0}; STARTUPINFO StartupInfo = {0}; ULONG ExitCode = 0; if (OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, &hToken)) { if (DuplicateTokenEx(hToken, MAXIMUM_ALLOWED, NULL, SecurityImpersonation, TokenPrimary, &hNewToken)) { if (ConvertStringSidToSid(wszIntegritySid, &pIntegritySid)) { TIL.Label.Attributes = SE_GROUP_INTEGRITY; TIL.Label.Sid = pIntegritySid; // Set the process integrity level if (SetTokenInformation(hNewToken, TokenIntegrityLevel, &TIL, sizeof(TOKEN_MANDATORY_LABEL) + GetLengthSid(pIntegritySid))) { // Create the new process at Low integrity bRet = CreateProcessAsUser(hNewToken, NULL, (LPWSTR)pcFileName, NULL, NULL, FALSE, 0, NULL, NULL, &StartupInfo, &ProcInfo); } LocalFree(pIntegritySid); } CloseHandle(hNewToken); } CloseHandle(hToken); } return bRet;*/ int bSuccess = 0; HRESULT hr = CoInitialize(NULL); if((hr == S_FALSE) || (hr == S_OK)) { IShellWindows *psw = NULL; hr = CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&psw)); if(SUCCEEDED(hr)) { HWND hwnd = 0; IDispatch* pdisp = NULL; variant_t vEmpty; if(S_OK == psw->FindWindowSW(&vEmpty.get(), &vEmpty.get(), SWC_DESKTOP, (long*)&hwnd, SWFO_NEEDDISPATCH, &pdisp)) { if((hwnd != NULL) && (hwnd != INVALID_HANDLE_VALUE)) { IShellBrowser *psb; hr = IUnknown_QueryService(pdisp, SID_STopLevelBrowser, IID_PPV_ARGS(&psb)); if(SUCCEEDED(hr)) { IShellView *psv = NULL; hr = psb->QueryActiveShellView(&psv); if(SUCCEEDED(hr)) { IDispatch *pdispBackground = NULL; hr = psv->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&pdispBackground)); if (SUCCEEDED(hr)) { IShellFolderViewDual *psfvd = NULL; hr = pdispBackground->QueryInterface(IID_PPV_ARGS(&psfvd)); if (SUCCEEDED(hr)) { IDispatch *pdisp2 = NULL; hr = psfvd->get_Application(&pdisp2); if (SUCCEEDED(hr)) { IShellDispatch2 *psd; hr = pdisp2->QueryInterface(IID_PPV_ARGS(&psd)); if(SUCCEEDED(hr)) { variant_t verb(pcOperation); variant_t file(pcFileName); variant_t para(pcParameters); variant_t show(SW_SHOWNORMAL); hr = psd->ShellExecute(file.get().bstrVal, para.get(), vEmpty.get(), verb.get(), show.get()); if(SUCCEEDED(hr)) bSuccess = 1; psd->Release(); psd = NULL; } pdisp2->Release(); pdisp2 = NULL; } } pdispBackground->Release(); pdispBackground = NULL; } psv->Release(); psv = NULL; } psb->Release(); psb = NULL; } } pdisp->Release(); pdisp = NULL; } psw->Release(); psw = NULL; } CoUninitialize(); } if(bSuccess < 1) { dcassert(0); HINSTANCE hInst = ShellExecuteW(parentHwnd, pcOperation, pcFileName, pcParameters, NULL, SW_SHOWNORMAL); if(((int) hInst) <= 32) bSuccess = -1; } return bSuccess; }