void SE_StructItem::setDataItem(const SE_Vector4f& v, int index) { SE_DataItem di(SE_DataItem::VECTOR4F_ITEM); di.data.vec4f = new SE_Vector4f(v); SET_DATA_ITEM(di, index); }
void UnitTestSTKParallelDistributedIndex::test_update_generate() { typedef stk::parallel::DistributedIndex PDIndex ; stk::ParallelMachine comm = MPI_COMM_WORLD ; int p_rank = stk::parallel_machine_rank(comm); int p_size = stk::parallel_machine_size(comm); std::vector< PDIndex::KeySpan > partition_spans ; generate_test_spans_10x10000( partition_spans ); PDIndex di( comm , partition_spans ); std::vector<size_t> requests( partition_spans.size() , size_t(0) ); std::vector< std::vector<PDIndex::KeyType> > generated_keys ; std::vector<PDIndex::KeyProc> sharing_of_local_keys ; std::vector<PDIndex::KeyType> keys_to_add ; std::vector<PDIndex::KeyType> keys_to_remove ; //------------------------------ // Add ( 5 * j ) odd keys per process // starting at the beginning of the partition. const size_t old_size_multiplier = 5 ; for ( size_t j = 0 ; j < partition_spans.size() ; ++j ) { PDIndex::KeyType key_first = partition_spans[j].first ; if ( 0 == key_first % 2 ) { ++key_first ; } // Make it odd key_first += old_size_multiplier * p_rank ; const size_t n = old_size_multiplier * j ; for ( size_t i = 0 ; i < n ; ++i ) { PDIndex::KeyType key = key_first + 2 * i ; keys_to_add.push_back( key ); } } di.update_keys( keys_to_add , keys_to_remove ); //------------------------------ // Request 20 new keys per process per span // The maximum new key will be larger than some spans // and within the gaps of other spans. const size_t gen_count = 20 ; for ( size_t i = 0 ; i < requests.size() ; ++i ) { if ( i % 2 ) { requests[i] = gen_count ; } else { requests[i] = 0 ; } } di.generate_new_keys( requests , generated_keys ); for ( size_t i = 0 ; i < requests.size() ; ++i ) { EXPECT_EQ( requests[i] , generated_keys[i].size() ); const size_t old_count = p_size * old_size_multiplier * i ; const size_t tot_request = p_size * requests[i] ; PDIndex::KeyType max_gen_key = partition_spans[i].first ; if ( 0 == tot_request ) { EXPECT_TRUE( generated_keys[i].size() == 0 ); } else if ( tot_request < old_count ) { // Will only fill in gaps between odd keys max_gen_key += 2 * old_count ; EXPECT_TRUE( max_gen_key > generated_keys[i][ requests[i] - 1 ] ); } else { // Will fill in gaps contiguously after the old max key max_gen_key += old_count + tot_request - 1 ; EXPECT_TRUE( max_gen_key >= generated_keys[i][ requests[i] - 1 ] ); } // Sorted for ( size_t j = 0 ; j < generated_keys[i].size() ; ++j ) { if ( 0 < j ) { EXPECT_TRUE( generated_keys[i][j-1] < generated_keys[i][j] ); } } } }
void doexit(int16_t val, int16_t val2) { int16_t j; ptptr p; irqflags_t irq; #ifdef DEBUG kprintf("process %d exiting\n", udata.u_ptab->p_pid); kprintf ("udata.u_page %u, udata.u_ptab %x, udata.u_ptab->p_page %u\n", udata.u_page, udata.u_ptab, udata.u_ptab->p_page); #endif if (udata.u_ptab->p_pid == 1) panic("killed init"); _sync(); /* Not necessary, but a good idea. */ irq = di(); /* Discard our memory before we blow away and reuse the memory */ pagemap_free(udata.u_ptab); for (j = 0; j < UFTSIZE; ++j) { if (udata.u_files[j] != NO_FILE) doclose(j); } udata.u_ptab->p_exitval = (val << 8) | (val2 & 0xff); i_deref(udata.u_cwd); i_deref(udata.u_root); /* Stash away child's execution tick counts in process table, * overlaying some no longer necessary stuff. * * Pedantically POSIX says we should do this at the point of wait() */ udata.u_utime += udata.u_cutime; udata.u_stime += udata.u_cstime; memcpy(&(udata.u_ptab->p_priority), &udata.u_utime, 2 * sizeof(clock_t)); for (p = ptab; p < ptab_end; ++p) { if (p->p_status == P_EMPTY || p == udata.u_ptab) continue; /* Set any child's parents to our parent */ if (p->p_pptr == udata.u_ptab) p->p_pptr = udata.u_ptab->p_pptr; /* Send SIGHUP to any pgrp members and remove them from our pgrp */ if (p->p_pgrp == udata.u_ptab->p_pid) { p->p_pgrp = 0; ssig(p, SIGHUP); } } tty_exit(); irqrestore(irq); #ifdef DEBUG kprintf ("udata.u_page %u, udata.u_ptab %x, udata.u_ptab->p_page %u\n", udata.u_page, udata.u_ptab, udata.u_ptab->p_page); #endif #ifdef CONFIG_ACCT acctexit(p); #endif udata.u_page = 0xFFFFU; udata.u_page2 = 0xFFFFU; /* FIXME: send SIGCLD here */ /* FIXME: POSIX.1 says that SIG_IGN for SIGCLD means don't go zombie, just clean up as we go */ /* Wake up a waiting parent, if any. */ wakeup((char *) udata.u_ptab->p_pptr); udata.u_ptab->p_status = P_ZOMBIE; nready--; nproc--; switchin(getproc()); panic("doexit: won't exit"); }
Object HHVM_STATIC_METHOD(DateInterval, createFromDateString, const String& time) { SmartResource<DateInterval> di(newres<DateInterval>(time, true)); return DateIntervalData::wrap(di); }
void UnitTestSTKParallelDistributedIndex::test_update() { typedef stk::parallel::DistributedIndex PDIndex ; stk::ParallelMachine comm = MPI_COMM_WORLD ; int mpi_rank = stk::parallel_machine_rank(comm); int mpi_size = stk::parallel_machine_size(comm); std::vector< PDIndex::KeySpan > partition_spans ; generate_test_spans_10x10000( partition_spans ); PDIndex di( comm , partition_spans ); std::vector<PDIndex::KeyType> keys_to_add ; std::vector<PDIndex::KeyType> keys_to_remove ; std::vector<PDIndex::KeyProc> sharing_of_local_keys ; //------------------------------ // Update nothing: di.update_keys( keys_to_add , keys_to_remove ); EXPECT_TRUE( di.m_key_usage.empty() ); //------------------------------ // Update one key on all processes and // one key unique to each process. keys_to_add.push_back( partition_spans[0].first + 1 ); keys_to_add.push_back( partition_spans[1].first + 2 + mpi_rank ); di.update_keys( keys_to_add , keys_to_remove ); di.query( sharing_of_local_keys ); // First key shared by all processes // Second key shared just by this process EXPECT_EQ( sharing_of_local_keys.size() , size_t(mpi_size + 1) ); di.query( keys_to_add , sharing_of_local_keys ); EXPECT_EQ( sharing_of_local_keys.size() , size_t(mpi_size + 1) ); //------------------------------ // Repeat the update, should result in no changes. di.update_keys( keys_to_add , keys_to_remove ); di.query( sharing_of_local_keys ); // First key shared by all processes // Second key shared just by this process EXPECT_EQ( sharing_of_local_keys.size() , size_t(mpi_size + 1) ); //------------------------------ keys_to_remove.clear(); keys_to_add.clear(); keys_to_remove.push_back( partition_spans[0].second ); di.update_keys( keys_to_add , keys_to_remove ); di.query( sharing_of_local_keys ); EXPECT_EQ( sharing_of_local_keys.size() , size_t(mpi_size + 1) ); //------------------------------ // Remove shared key keys_to_remove.clear(); keys_to_add.clear(); keys_to_remove.push_back( partition_spans[0].first + 1 ); di.update_keys( keys_to_add , keys_to_remove ); di.query( sharing_of_local_keys ); EXPECT_EQ( sharing_of_local_keys.size() , size_t(1) ); //------------------------------ // Add two shared-by-all keys_to_remove.clear(); keys_to_add.clear(); keys_to_add.push_back( partition_spans[0].first + 1 ); keys_to_add.push_back( partition_spans[0].first + 2 ); di.update_keys( keys_to_add , keys_to_remove ); di.query( sharing_of_local_keys ); EXPECT_EQ( sharing_of_local_keys.size() , size_t(2*mpi_size + 1) ); di.query( keys_to_add , sharing_of_local_keys ); EXPECT_EQ( sharing_of_local_keys.size() , size_t(2*mpi_size) ); //------------------------------ keys_to_remove.clear(); keys_to_add.clear(); // Shared by even rank processes: if ( 0 == mpi_rank % 2 ) { keys_to_add.push_back( partition_spans[2].first ); } di.update_keys( keys_to_add , keys_to_remove ); di.query( sharing_of_local_keys ); { size_t expected = 2 * mpi_size + 1 ; if ( 0 == mpi_rank % 2 ) { expected += ( mpi_size + 1 ) / 2 ; } EXPECT_EQ( sharing_of_local_keys.size() , expected ); } }
INT_PTR CALLBACK MainDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { TSTR buf; RefWatch *rc = DLGetWindowLongPtr<RefWatch *>(hWnd); if (!rc && msg != WM_INITDIALOG ) return FALSE; switch (msg) { case WM_INITDIALOG: rc = (RefWatch *)lParam; DLSetWindowLongPtr(hWnd, rc); CenterWindow(hWnd, IP->GetMAXHWnd()); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), _T("")); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); return TRUE; case WM_CLOSE: DestroyWindow(rc->hMain); break; case WM_DESTROY: rc->DestroyWindow(); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_CLEAR: SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); break; case IDC_TVPICK: { TSTR str; HWND hIRefList = GetDlgItem(hWnd, IDC_IREF_LIST); HWND hRefMeList = GetDlgItem(hWnd, IDC_REFME_LIST); TrackViewPick tvp; tvp.anim = tvp.client = NULL; BOOL ok = IP->TrackViewPickDlg(hWnd, &tvp); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); if (ok) { if (tvp.anim && tvp.client) { rc->watchMe = tvp.anim; buf.printf(_T("Item Name: %s"), rc->GetName()); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), buf.data()); notifyObject.RemoveReference(); notifyObject.CreateReference(rc->watchMe); tvp.anim->GetClassName(str); buf.printf(_T("This Target ClassName: %s"), str); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), buf.data()); tvp.client->GetClassName(str); buf.printf(_T("Client ClassName: %s"), str); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), buf.data()); Tab<TSTR *> ptStr; TSTR *pTstr, Str(_T("")); pTstr = &Str; ptStr.Append(1, &pTstr); DisplayRefInfo(rc, hWnd, &ptStr); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); } else ok = FALSE; } if (!ok) { rc->watchMe = NULL; notifyObject.RemoveReference(); SendMessage(hIRefList, LB_RESETCONTENT, 0, 0L); SendMessage(hRefMeList, LB_RESETCONTENT, 0, 0L); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), _T("")); } break; }; return TRUE; case IDC_REFME_LIST: case IDC_IREF_LIST: if (HIWORD(wParam) == LBN_DBLCLK) { TSTR str; HWND hIRefList = GetDlgItem(hWnd, IDC_IREF_LIST); HWND hRefMeList = GetDlgItem(hWnd, IDC_REFME_LIST); BOOL ok = TRUE; // Get list item. HWND listbox = (HWND)lParam; int i = SendMessage(listbox, LB_GETCURSEL, 0, 0); // Change the currently watched object. if (LOWORD(wParam) == IDC_IREF_LIST) rc->watchMe = rc->watchMe->GetReference(i); else { bool fulltree = IsDlgButtonChecked(hWnd, IDC_FULLTREE) ? true : false; if (fulltree) { // Enum dependents. RefCheckFindDepEnumProc rfep(i, rc->watchMe); rc->watchMe->DoEnumDependents(&rfep); if (rfep.rmaker != NULL) { if (!OkToDisplay(hWnd, rfep.rmaker)) return TRUE; rc->watchMe = (ReferenceTarget*)rfep.rmaker; } else ok = FALSE; } else { // We only displayed first-level dependents. int count = 0; DependentIterator di(rc->watchMe); ReferenceMaker* maker = NULL; while ((maker = di.Next()) != NULL) { if (count == i) { if (!OkToDisplay(hWnd, maker)) return TRUE; rc->watchMe = (ReferenceTarget*)maker; break; } if (count > i) return TRUE;// not sure how this could happen... ++count; } } } SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); if (ok) { buf.printf(_T("Item Name: %s"), rc->GetName()); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), buf.data()); notifyObject.RemoveReference(); notifyObject.CreateReference(rc->watchMe); rc->watchMe->GetClassName(str); buf.printf(_T("This Target ClassName: %s"), str); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), buf.data()); buf.printf(_T("Client ClassName: %s"), _T("(Unable to determine)")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), buf.data()); Tab<TSTR *> ptStr; TSTR *pTstr, Str(_T("")); pTstr = &Str; ptStr.Append(1, &pTstr); DisplayRefInfo(rc, hWnd, &ptStr); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); } else { rc->watchMe = NULL; notifyObject.RemoveReference(); SendMessage(hIRefList, LB_RESETCONTENT, 0, 0L); SendMessage(hRefMeList, LB_RESETCONTENT, 0, 0L); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), _T("")); } } break; }; break; default: return FALSE; }; return TRUE; }
// // Check the given name to see if it is a valid macro name. // If realMacro is TRUE, then don't allow the name to be 'main'. // If it is return TRUE, othewise return FALSE and issue an error // message. // boolean SetMacroNameDialog::verifyMacroName(const char *name, boolean realMacro) { int i = 0; if (realMacro && IsToken(name,"main",i) && (!name[i] || IsWhiteSpace(name,i))) { ModalErrorMessage(this->getRootWidget(), "Macro name cannot be \"main\"."); return FALSE; } i = 0; if (!IsRestrictedIdentifier(name, i) ) { ModalErrorMessage(this->getRootWidget(), "Macro name `%s' must start with a letter and consist " "of only letters and numbers", name); return FALSE; } SkipWhiteSpace(name, i); if (name[i] != '\0') { ModalErrorMessage(this->getRootWidget(), "Macro name `%s' must start with a letter and consist " "of only letters and numbers", name); return FALSE; } if (IsReservedScriptingWord(name)) { ErrorMessage("Macro name \"%s\" is a reserved word", name); return FALSE; } NodeDefinition *nd; DictionaryIterator di(*theNodeDefinitionDictionary); Symbol nameSym = theSymbolManager->registerSymbol(name); while ( (nd = (NodeDefinition*)di.getNextDefinition()) ) { if (nd->getNameSymbol() == nameSym) { if (!nd->isDerivedFromMacro()) { ModalErrorMessage(this->getRootWidget(), "Macro name `%s' is the name of a Data Explorer module.\n" "Macro names must not be the same as a module name.", name); return FALSE; } else if (this->network->getDefinition() != (MacroDefinition*)nd) // && is Macro { ModalErrorMessage(this->getRootWidget(), "Macro name `%s' is the name of an already loaded macro.", name); return FALSE; } } } return TRUE; }
void ClangParser::start(const char *fileName,QStrList &filesInTranslationUnit) { static bool clangAssistedParsing = Config_getBool("CLANG_ASSISTED_PARSING"); static QStrList &includePath = Config_getList("INCLUDE_PATH"); static QStrList clangOptions = Config_getList("CLANG_OPTIONS"); if (!clangAssistedParsing) return; //printf("ClangParser::start(%s)\n",fileName); p->fileName = fileName; p->index = clang_createIndex(0, 0); p->curLine = 1; p->curToken = 0; char **argv = (char**)malloc(sizeof(char*)*(4+Doxygen::inputPaths.count()+includePath.count()+clangOptions.count())); QDictIterator<void> di(Doxygen::inputPaths); int argc=0; // add include paths for input files for (di.toFirst();di.current();++di,++argc) { QCString inc = QCString("-I")+di.currentKey(); argv[argc]=strdup(inc.data()); //printf("argv[%d]=%s\n",argc,argv[argc]); } // add external include paths for (uint i=0;i<includePath.count();i++) { QCString inc = QCString("-I")+includePath.at(i); argv[argc++]=strdup(inc.data()); } // user specified options for (uint i=0;i<clangOptions.count();i++) { argv[argc++]=strdup(clangOptions.at(i)); } // extra options argv[argc++]=strdup("-ferror-limit=0"); argv[argc++]=strdup("-x"); // Since we can be presented with a .h file that can contain C/C++ or // Objective C code and we need to configure the parser before knowing this, // we use the source file to detected the language. Detection will fail if you // pass a bunch of .h files containing ObjC code, and no sources :-( SrcLangExt lang = getLanguageFromFileName(fileName); if (lang==SrcLangExt_ObjC || p->detectedLang!=ClangParser::Private::Detected_Cpp) { QCString fn = fileName; if (p->detectedLang==ClangParser::Private::Detected_Cpp && (fn.right(4).lower()==".cpp" || fn.right(4).lower()==".cxx" || fn.right(3).lower()==".cc" || fn.right(2).lower()==".c")) { // fall back to C/C++ once we see an extension that indicates this p->detectedLang = ClangParser::Private::Detected_Cpp; } else if (fn.right(3).lower()==".mm") // switch to Objective C++ { p->detectedLang = ClangParser::Private::Detected_ObjCpp; } else if (fn.right(2).lower()==".m") // switch to Objective C { p->detectedLang = ClangParser::Private::Detected_ObjC; } } switch(p->detectedLang) { case ClangParser::Private::Detected_Cpp: argv[argc++]=strdup("c++"); break; case ClangParser::Private::Detected_ObjC: argv[argc++]=strdup("objective-c"); break; case ClangParser::Private::Detected_ObjCpp: argv[argc++]=strdup("objective-c++"); break; } // provide the input and and its dependencies as unsaved files so we can // pass the filtered versions argv[argc++]=strdup(fileName); static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES"); //printf("source %s ----------\n%s\n-------------\n\n", // fileName,p->source.data()); uint numUnsavedFiles = filesInTranslationUnit.count()+1; p->numFiles = numUnsavedFiles; p->sources = new QCString[numUnsavedFiles]; p->ufs = new CXUnsavedFile[numUnsavedFiles]; p->sources[0] = detab(fileToString(fileName,filterSourceFiles,TRUE)); p->ufs[0].Filename = strdup(fileName); p->ufs[0].Contents = p->sources[0].data(); p->ufs[0].Length = p->sources[0].length(); QStrListIterator it(filesInTranslationUnit); uint i=1; for (it.toFirst();it.current() && i<numUnsavedFiles;++it,i++) { p->fileMapping.insert(it.current(),new uint(i)); p->sources[i] = detab(fileToString(it.current(),filterSourceFiles,TRUE)); p->ufs[i].Filename = strdup(it.current()); p->ufs[i].Contents = p->sources[i].data(); p->ufs[i].Length = p->sources[i].length(); } // let libclang do the actual parsing p->tu = clang_parseTranslationUnit(p->index, 0, argv, argc, p->ufs, numUnsavedFiles, CXTranslationUnit_DetailedPreprocessingRecord); // free arguments for (int i=0;i<argc;++i) { free(argv[i]); } free(argv); if (p->tu) { // filter out any includes not found by the clang parser determineInputFilesInSameTu(filesInTranslationUnit); // show any warnings that the compiler produced for (uint i=0, n=clang_getNumDiagnostics(p->tu); i!=n; ++i) { CXDiagnostic diag = clang_getDiagnostic(p->tu, i); CXString string = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions()); err("%s [clang]\n",clang_getCString(string)); clang_disposeString(string); clang_disposeDiagnostic(diag); } // create a source range for the given file QFileInfo fi(fileName); CXFile f = clang_getFile(p->tu, fileName); CXSourceLocation fileBegin = clang_getLocationForOffset(p->tu, f, 0); CXSourceLocation fileEnd = clang_getLocationForOffset(p->tu, f, p->ufs[0].Length); CXSourceRange fileRange = clang_getRange(fileBegin, fileEnd); // produce a token stream for the file clang_tokenize(p->tu,fileRange,&p->tokens,&p->numTokens); // produce cursors for each token in the stream p->cursors=new CXCursor[p->numTokens]; clang_annotateTokens(p->tu,p->tokens,p->numTokens,p->cursors); } else { p->tokens = 0; p->numTokens = 0; p->cursors = 0; err("clang: Failed to parse translation unit %s\n",fileName); } }
/* This doesn't take a timestamp; instead, we let InputHandler::ButtonPressed figure * it out. Be sure to call InputHandler::Update() between each poll. */ void InputHandler_DInput::UpdatePolled(DIDevice &device, const RageTimer &tm) { if( device.type == device.KEYBOARD ) { unsigned char keys[256]; HRESULT hr = GetDeviceState(device.Device, 256, keys); if ( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED ) return; if ( hr != DI_OK ) { LOG->MapLog( "UpdatePolled", hr_ssprintf(hr, "Failures on polled keyboard update") ); return; } for( int k = 0; k < 256; ++k ) { const int key = device.Inputs[k].num; ButtonPressed(DeviceInput(device.dev, key), !!(keys[k] & 0x80)); } return; } DIJOYSTATE state; HRESULT hr = GetDeviceState(device.Device, sizeof(state), &state); if ( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED ) return; /* Set each known axis, button and POV. */ for(unsigned i = 0; i < device.Inputs.size(); ++i) { const input_t &in = device.Inputs[i]; const InputDevice dev = device.dev; switch(in.type) { case in.BUTTON: { DeviceInput di(dev, JOY_1 + in.num, -1, tm); ButtonPressed(di, !!state.rgbButtons[in.ofs - DIJOFS_BUTTON0]); break; } case in.AXIS: { JoystickButton neg = NUM_JOYSTICK_BUTTONS, pos = NUM_JOYSTICK_BUTTONS; int val = 0; switch(in.ofs) { case DIJOFS_X: neg = JOY_LEFT; pos = JOY_RIGHT; val = state.lX; break; case DIJOFS_Y: neg = JOY_UP; pos = JOY_DOWN; val = state.lY; break; case DIJOFS_Z: neg = JOY_Z_UP; pos = JOY_Z_DOWN; val = state.lZ; break; case DIJOFS_RX: neg = JOY_ROT_LEFT; pos = JOY_ROT_RIGHT; val = state.lRx; break; case DIJOFS_RY: neg = JOY_ROT_UP; pos = JOY_ROT_DOWN; val = state.lRy; break; case DIJOFS_RZ: neg = JOY_ROT_Z_UP; pos = JOY_ROT_Z_DOWN; val = state.lRz; break; case DIJOFS_SLIDER(0): neg = JOY_AUX_1; pos = JOY_AUX_2; val = state.rglSlider[0]; break; case DIJOFS_SLIDER(1): neg = JOY_AUX_3; pos = JOY_AUX_4; val = state.rglSlider[1]; break; default: LOG->MapLog("unknown input", "Controller '%s' is returning an unknown joystick offset, %i", device.JoystickInst.tszProductName, in.ofs ); continue; } if( neg != NUM_JOYSTICK_BUTTONS ) { float l = SCALE( int(val), 0.0f, 100.0f, 0.0f, 1.0f ); ButtonPressed(DeviceInput(dev, neg, max(-l,0), tm), val < -50); ButtonPressed(DeviceInput(dev, pos, max(+l,0), tm), val > 50); } break; } case in.HAT: if( in.num == 0 ) { const int pos = TranslatePOV(state.rgdwPOV[in.ofs - DIJOFS_POV(0)]); ButtonPressed(DeviceInput(dev, JOY_HAT_UP, -1, tm), !!(pos & HAT_UP_MASK)); ButtonPressed(DeviceInput(dev, JOY_HAT_DOWN, -1, tm), !!(pos & HAT_DOWN_MASK)); ButtonPressed(DeviceInput(dev, JOY_HAT_LEFT, -1, tm), !!(pos & HAT_LEFT_MASK)); ButtonPressed(DeviceInput(dev, JOY_HAT_RIGHT, -1, tm), !!(pos & HAT_RIGHT_MASK)); } break; } } }
void SE_StructItem::setDataItem(SE_VirtualData* data, int index) { SE_DataItem di(SE_DataItem::VIRTUALDATA_ITEM); di.data.virtualData = data; SET_DATA_ITEM(di, index); }
/** * Main. Creates Application window. * * Cleaning up #defines. */ int main(int argc, char** argv) { RS_DEBUG->setLevel(RS_Debug::D_WARNING); QCoreApplication::setApplicationName(XSTR(QC_APPNAME)); #if QT_VERSION < 0x040400 /* No such property in Qt 4.3 */ #else QCoreApplication::setApplicationVersion(XSTR(QC_VERSION)); #endif QApplication app(argc, argv); // for image mime resources from png files // TODO: kinda dirty to call that explicitly // QINITIMAGES_LIBRECAD(); #ifdef RS_SCRIPTING // qInitImages_librecad(); #endif const char *lpDebugSwitch = "--debug"; size_t iDebugSwitchLen = strlen(lpDebugSwitch); for (int i=0; i<argc; i++) { if ( ! strncmp( lpDebugSwitch, argv[i], iDebugSwitchLen)) { // to control the level of debugging output use --debug with level 0-6, e.g. --debug3 // for a list of debug levels use --debug? // if no level follows, the debugging level is set if( strlen( argv[i]) > iDebugSwitchLen) { switch( argv[i][iDebugSwitchLen]) { case '?' : RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); return 0; case '0' + RS_Debug::D_NOTHING : RS_DEBUG->setLevel( RS_Debug::D_NOTHING); ++i; break; case '0' + RS_Debug::D_CRITICAL : RS_DEBUG->setLevel( RS_Debug::D_CRITICAL); ++i; break; case '0' + RS_Debug::D_ERROR : RS_DEBUG->setLevel( RS_Debug::D_ERROR); ++i; break; case '0' + RS_Debug::D_WARNING : RS_DEBUG->setLevel( RS_Debug::D_WARNING); ++i; break; case '0' + RS_Debug::D_NOTICE : RS_DEBUG->setLevel( RS_Debug::D_NOTICE); ++i; break; case '0' + RS_Debug::D_INFORMATIONAL : RS_DEBUG->setLevel( RS_Debug::D_INFORMATIONAL); ++i; break; case '0' + RS_Debug::D_DEBUGGING : RS_DEBUG->setLevel( RS_Debug::D_DEBUGGING); ++i; break; default : RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); break; } } else { RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); } } } RS_DEBUG->print("param 0: %s", argv[0]); QFileInfo prgInfo( QFile::decodeName(argv[0]) ); QString prgDir(prgInfo.absolutePath()); RS_SETTINGS->init(XSTR(QC_COMPANYKEY), XSTR(QC_APPKEY)); RS_SYSTEM->init(XSTR(QC_APPNAME), XSTR(QC_VERSION), XSTR(QC_APPDIR), prgDir); RS_FileIO::instance()->registerFilter(&( RS_FilterLFF::createFilter)); RS_FileIO::instance()->registerFilter( &(RS_FilterDXFRW::createFilter)); RS_FileIO::instance()->registerFilter( &(RS_FilterCXF::createFilter)); RS_FileIO::instance()->registerFilter( &(RS_FilterJWW::createFilter)); RS_FileIO::instance()->registerFilter( &(RS_FilterDXF1::createFilter)); // parse command line arguments that might not need a launched program: QStringList fileList = handleArgs(argc, argv); QString lang; QString langCmd; QString unit; RS_SETTINGS->beginGroup("/Defaults"); #ifndef QC_PREDEFINED_UNIT unit = RS_SETTINGS->readEntry("/Unit", "Invalid"); #else unit = RS_SETTINGS->readEntry("/Unit", QC_PREDEFINED_UNIT); #endif RS_SETTINGS->endGroup(); // show initial config dialog: if (unit=="Invalid") { RS_DEBUG->print("main: show initial config dialog.."); QG_DlgInitial di(NULL); di.setText("<font size=\"+1\"><b>Welcome to " XSTR(QC_APPNAME) "</b></font>" "<br>" "Please choose the unit you want to use for new drawings and your " "preferred language.<br>" "You can changes these settings later in the " "Options Dialog of " XSTR(QC_APPNAME) "."); QPixmap pxm(":/main/intro_librecad.png"); di.setPixmap(pxm); if (di.exec()) { RS_SETTINGS->beginGroup("/Defaults"); unit = RS_SETTINGS->readEntry("/Unit", "None"); RS_SETTINGS->endGroup(); } RS_DEBUG->print("main: show initial config dialog: OK"); } #ifdef QSPLASHSCREEN_H RS_DEBUG->print("main: splashscreen.."); QPixmap* pixmap = new QPixmap(":/main/splash_librecad.png"); # endif RS_DEBUG->print("main: init fontlist.."); RS_FONTLIST->init(); RS_DEBUG->print("main: init fontlist: OK"); RS_DEBUG->print("main: init patternlist.."); RS_PATTERNLIST->init(); RS_DEBUG->print("main: init patternlist: OK"); RS_DEBUG->print("main: init scriptlist.."); RS_SCRIPTLIST->init(); RS_DEBUG->print("main: init scriptlist: OK"); RS_DEBUG->print("main: loading translation.."); RS_SETTINGS->beginGroup("/Appearance"); #ifdef QC_PREDEFINED_LOCALE lang = RS_SETTINGS->readEntry("/Language", ""); if (lang.isEmpty()) { lang=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/Language", lang); } langCmd = RS_SETTINGS->readEntry("/LanguageCmd", ""); if (langCmd.isEmpty()) { langCmd=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/LanguageCmd", langCmd); } #else lang = RS_SETTINGS->readEntry("/Language", "en"); langCmd = RS_SETTINGS->readEntry("/LanguageCmd", "en"); #endif RS_SETTINGS->endGroup(); RS_SYSTEM->loadTranslation(lang, langCmd); RS_DEBUG->print("main: loading translation: OK"); #ifdef QSPLASHSCREEN_H splash = new QSplashScreen(*pixmap); splash->show(); splash->showMessage(QObject::tr("Loading.."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: splashscreen: OK"); #endif //QApplication::setStyle(new QWindowsStyle()); //QApplication::setStyle(new QPlatinumStyle()); #ifdef QC_BUILTIN_STYLE //js: RS_DEBUG->print("main: applying built in style.."); applyBuiltinStyle(); #endif RS_DEBUG->print("main: creating main window.."); QC_ApplicationWindow * appWin = new QC_ApplicationWindow(); RS_DEBUG->print("main: setting caption"); appWin->setWindowTitle(XSTR(QC_APPNAME)); RS_DEBUG->print("main: show main window"); appWin->show(); RS_DEBUG->print("main: set focus"); appWin->setFocus(); RS_DEBUG->print("main: creating main window: OK"); #ifdef QSPLASHSCREEN_H if (splash) { RS_DEBUG->print("main: updating splash.."); splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: processing events"); qApp->processEvents(); RS_DEBUG->print("main: updating splash: OK"); } #endif // Set LC_NUMERIC so that enetring numeric values uses . as teh decimal seperator setlocale(LC_NUMERIC, "C"); RS_DEBUG->print("main: loading files.."); bool files_loaded = false; for (QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it ) { #ifdef QSPLASHSCREEN_H if (splash) { splash->showMessage(QObject::tr("Loading File %1..") .arg(QDir::toNativeSeparators(*it)), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); qApp->processEvents(); } #endif appWin->slotFileOpen(*it, RS2::FormatUnknown); files_loaded = true; } RS_DEBUG->print("main: loading files: OK"); #ifdef QSPLASHSCREEN_H # ifndef QC_DELAYED_SPLASH_SCREEN if (splash) { splash->finish(appWin); delete splash; splash = 0; } # endif delete pixmap; #endif //app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); RS_DEBUG->print("main: app.exec()"); if (!files_loaded) { appWin->slotFileNewNew(); } appWin->slotRunStartScript(); int r = app.exec(); RS_DEBUG->print("main: Temporary disabled delete appWin"); // delete appWin; RS_DEBUG->print("main: finished"); return r; }
void SE_StructItem::setDataItem(const SE_Matrix4f& v, int index) { SE_DataItem di(SE_DataItem::MATRIX4F_ITEM); di.data.mat4f = new SE_Matrix4f(v); SET_DATA_ITEM(di, index); }
void SE_StructItem::setDataItem(const SE_Quat& v, int index) { SE_DataItem di(SE_DataItem::QUAT_ITEM); di.data.quat = new SE_Quat(v); SET_DATA_ITEM(di, index); }
void SE_StructItem::setDataItem(const SE_Vector3i v, int index) { SE_DataItem di(SE_DataItem::VECTOR3I_ITEM); di.data.vec3i = new SE_Vector3i(v); SET_DATA_ITEM(di, index); }
Object c_DateInterval::ti_createfromdatestring(CStrRef time) { SmartObject<DateInterval> di(NEWOBJ(DateInterval)(time, true)); return c_DateInterval::wrap(di); }
void Install(bool& rebootReqd) { // retrieve the full path for our .inf std::wstring infPath; { auto pathLength = ::GetFullPathNameW(WINDTUNNEL_INF_NAME, 0, nullptr, nullptr); if (!pathLength) { throw nt::Win32Exception(::GetLastError(), L"Failed to find " WINDTUNNEL_INF_NAME, __FILE__, __LINE__); } auto buffer = std::unique_ptr<wchar_t[]>(new wchar_t[pathLength]); ::GetFullPathNameW(WINDTUNNEL_INF_NAME, pathLength, buffer.get(), nullptr); infPath = buffer.get(); _TRACE_T(L"INF file path: [%s]", infPath.c_str()); } // retrieve class GUID GUID classGUID; wchar_t className[MAX_CLASS_NAME_LEN]; if (!::SetupDiGetINFClassW(infPath.c_str(), &classGUID, className, _countof(className), nullptr)) { throw nt::Win32Exception(::GetLastError(), L"Failed to retrieve class GUID from " WINDTUNNEL_INF_NAME, __FILE__, __LINE__); } _TRACE_T(L"Class GUID: {%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", classGUID.Data1, classGUID.Data2, classGUID.Data3, classGUID.Data4[0], classGUID.Data4[1], classGUID.Data4[2], classGUID.Data4[3], classGUID.Data4[4], classGUID.Data4[5], classGUID.Data4[6], classGUID.Data4[7]); _TRACE_T(L"Class name: %s", className); nt::setup::DeviceInformationSet di(classGUID); auto deviceInfo = di.createDeviceInfo(className, classGUID, nullptr, DICD_GENERATE_ID); wchar_t hardwareIdList[LINE_LEN + 4] = { 0 }; ::StringCchCopyW(hardwareIdList, LINE_LEN, WINDTUNNEL_HWID); di.setDeviceRegistryProperty( deviceInfo, SPDRP_HARDWAREID, hardwareIdList, (::lstrlenW(hardwareIdList) + 2) * sizeof(wchar_t) // HW ID list must be terminated with \0\0 ); di.callClassInstaller(DIF_REGISTERDEVICE, deviceInfo); BOOL rebootRequired = FALSE; if (!::UpdateDriverForPlugAndPlayDevicesW(0, WINDTUNNEL_HWID, infPath.c_str(), INSTALLFLAG_FORCE, &rebootRequired)) { throw nt::Win32Exception(::GetLastError(), L"Failed to install " WINDTUNNEL_HWID, __FILE__, __LINE__); } RenameAudioEndpoints(); if (rebootRequired) { _TRACE_T("Reboot is required"); } rebootReqd = !!rebootRequired; }
void keyscan() { static int flag=0,flag_ymd=0; if(s1==0) //功能键s1 { delay(10); if(s1==0) { while(!s1); flag++; di(); if(flag==1) { flag_ds=1; write_com(0x80+0x40+10); write_com(0x0f); diii(); } if(flag==2) { write_com(0x80+0x40+7); } if(flag==3) { write_com(0x80+0x40+4); } if(flag==4)//week { write_com(0x80+12); flag_ymd=1; } if(flag==5) //day { write_com(0x80+9); flag_ymd=2; } if(flag==6) //moth { write_com(0x80+6); flag_ymd=3; } if(flag==7) //year { write_com(0x80+3); flag_ymd=4; } if(flag==8) { diii(); flag=0; flag_ds=0; flag_ymd=0; write_com(0x0c); write_ds(0,miao); write_ds(2,fen); write_ds(4,shi); write_ds(6,week); write_ds(7,day); write_ds(8,moth); write_ds(9,year); } } } if(flag!=0) { if(s2==0) //加数键s2 加数键s2 加数键s2 加数键s2 { delay(5); if(s2==0) { while(!s2); di(); if(flag_ymd==0) { /*****************************/ if(flag==1) { miao++; if(miao==60) { miao=0; } write_time(10,miao,2); write_com(0x80+0x40+10); } if(flag==2) { fen++; if(fen==60) { fen=0; } write_time(7,fen,2); write_com(0x80+0x40+7); } if(flag==3) { shi++; if(shi==24) { shi=0; } write_time(4,shi,2); write_com(0x80+0x40+4); } /**************************/ } if(flag_ymd==1) { week++; if(week==8) { week=1; } write_week(week); write_com(0x80+12); } if(flag_ymd==2) { day++; if(day==32) { day=1; } write_time(9,day,1); write_com(0x80+9); } if(flag_ymd==3) { moth++; if(moth==13) { moth=1; } write_time(6,moth,1); write_com(0x80+6); } if(flag_ymd==4) { year++; if(year==30) { year=1; } write_time(3,year,1); write_com(0x80+3); } } } //加数 if(s3==0) //减数键s3 减数键s3 减数键s3 减数键s3 { delay(5); if(s3==0) { while(!s3); di(); if(flag_ymd==0) { /*************************************/ if(flag==1) { miao--; if(miao==60||miao<0) { miao=0; } write_time(10,miao,2); write_com(0x80+0x40+10); } if(flag==2) { fen--; if(fen==60||fen<0) { fen=0; } write_time(7,fen,2); write_com(0x80+0x40+7); } if(flag==3) { shi--; if(shi==24||shi<0) { shi=0; } write_time(4,shi,2); write_com(0x80+0x40+4); } /*******************************************/ } if(flag_ymd==1) { week--; if(week==0) { week=7; } write_week(week); write_com(0x80+12); } if(flag_ymd==2) { day--; if(day==0) { day=31; } write_time(9,day,1); write_com(0x80+9); } if(flag_ymd==3) { moth--; if(moth==0) { moth=12; } write_time(6,moth,1); write_com(0x80+6); } if(flag_ymd==4) { year--; if(year==0) { year=30; } write_time(3,year,1); write_com(0x80+3); } } } //减数 } }
void Uninstall(bool& rebootReqd) { nt::setup::DeviceInformationSet di(DIGCF_PRESENT | DIGCF_ALLCLASSES); auto data = di.detailData(); auto deviceInfo = di.enumDeviceInfo(); for (const auto& devInfo : deviceInfo) { wchar_t devID[MAX_DEVICE_ID_LEN] = { 0 }; // determine instance ID ::CM_Get_Device_ID_ExW(devInfo.DevInst, devID, MAX_DEVICE_ID_LEN, 0, data.RemoteMachineHandle); bool match = false; std::vector<std::wstring> vHwIds; try { auto propHwIds = di.deviceRegistryProperty(devInfo, SPDRP_HARDWAREID); _ASSERT(propHwIds.first == REG_MULTI_SZ); ExpandMultiSz(propHwIds.second.get(), vHwIds); } catch (std::exception&) { } for (const auto& s : vHwIds) { if (!::_wcsicmp(s.c_str(), WINDTUNNEL_HWID)) { match = true; break; } } if (!match) { std::vector<std::wstring> vCompatibleIds; try { auto propCompatibleIds = di.deviceRegistryProperty(devInfo, SPDRP_COMPATIBLEIDS); _ASSERT(propCompatibleIds.first == REG_MULTI_SZ); ExpandMultiSz(propCompatibleIds.second.get(), vCompatibleIds); } catch (std::exception&) { } for (const auto& s : vCompatibleIds) { if (!::_wcsicmp(s.c_str(), WINDTUNNEL_HWID)) { match = true; break; } } } if (match) { return UninstallDevice(di, devInfo, rebootReqd); } } throw nt::Exception(L"Could not find hardware ID " WINDTUNNEL_HWID, __FILE__, __LINE__); }
/** * Main. Creates Application window. * * Cleaning up #defines. */ int main(int argc, char** argv) { RS_DEBUG->setLevel(RS_Debug::D_WARNING); QCoreApplication::setApplicationName(XSTR(QC_APPNAME)); #if QT_VERSION < 0x040400 /* No such property in Qt 4.3 */ #else QCoreApplication::setApplicationVersion(XSTR(QC_VERSION)); #endif QApplication app(argc, argv); #if defined(Q_OS_MAC) && QT_VERSION > 0x050000 //need stylesheet for Qt5 on mac app.setStyleSheet( "QToolButton:checked" "{" " background-color: rgb(160,160,160);" " border-style: inset;" "}" "" "QToolButton" "{" " background-color: transparent;" "}" "" "QToolButton:hover" "{" " background-color: rgb(255,255,255);" " border-style: outset;" "}" ); #endif // for image mime resources from png files // TODO: kinda dirty to call that explicitly // QINITIMAGES_LIBRECAD(); #ifdef RS_SCRIPTING // qInitImages_librecad(); #endif const QString lpDebugSwitch0("-d"),lpDebugSwitch1("--debug") ; const QString help0("-h"), help1("--help"); bool allowOptions=true; QList<int> argClean; for (int i=0; i<argc; i++) { QString argstr(argv[i]); if(allowOptions&&QString::compare("--", argstr)==0){ allowOptions=false; continue; } if (allowOptions&&( help0.compare(argstr, Qt::CaseInsensitive)==0 || help1.compare(argstr, Qt::CaseInsensitive)==0 ) ){//hep information qDebug()<<"librecad::usage: <options> <dxf file>"; qDebug()<<"-h, --help\tdisplay this message"; qDebug()<<""; qDebug()<<" --help\tdisplay this message"; qDebug()<<"-d, --debug <level>"; RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); exit(0); } if ( allowOptions&& ( argstr.startsWith(lpDebugSwitch0, Qt::CaseInsensitive)|| argstr.startsWith(lpDebugSwitch1, Qt::CaseInsensitive) ) ){ argClean<<i; // to control the level of debugging output use --debug with level 0-6, e.g. --debug3 // for a list of debug levels use --debug? // if no level follows, the debugging level is set argstr.remove(QRegExp("^"+lpDebugSwitch0)); argstr.remove(QRegExp("^"+lpDebugSwitch1)); char level; if(argstr.size()==0){ if(i+1<argc) { if(QRegExp("\\d*").exactMatch(argv[i+1])){ ++i; qDebug()<<"reading "<<argv[i]<<" as debugging level"; level=argv[i][0]; argClean<<i; }else level='3'; }else level='3'; //default to D_WARNING }else level=argstr.toStdString()[0]; // if( strlen( argv[i]) > iDebugSwitchLen) { switch(level) { case '?' : RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:"); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Nothing", RS_Debug::D_NOTHING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Critical", RS_Debug::D_CRITICAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Error", RS_Debug::D_ERROR); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Warning", RS_Debug::D_WARNING); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Notice", RS_Debug::D_NOTICE); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Informational", RS_Debug::D_INFORMATIONAL); RS_DEBUG->print( RS_Debug::D_NOTHING, " %d Debugging", RS_Debug::D_DEBUGGING); return 0; case '0' + RS_Debug::D_NOTHING : RS_DEBUG->setLevel( RS_Debug::D_NOTHING); ++i; break; case '0' + RS_Debug::D_CRITICAL : RS_DEBUG->setLevel( RS_Debug::D_CRITICAL); ++i; break; case '0' + RS_Debug::D_ERROR : RS_DEBUG->setLevel( RS_Debug::D_ERROR); ++i; break; case '0' + RS_Debug::D_WARNING : RS_DEBUG->setLevel( RS_Debug::D_WARNING); ++i; break; case '0' + RS_Debug::D_NOTICE : RS_DEBUG->setLevel( RS_Debug::D_NOTICE); ++i; break; case '0' + RS_Debug::D_INFORMATIONAL : RS_DEBUG->setLevel( RS_Debug::D_INFORMATIONAL); ++i; break; case '0' + RS_Debug::D_DEBUGGING : RS_DEBUG->setLevel( RS_Debug::D_DEBUGGING); ++i; break; default : RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); break; } // } // else { // RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); // } } } RS_DEBUG->print("param 0: %s", argv[0]); QFileInfo prgInfo( QFile::decodeName(argv[0]) ); QString prgDir(prgInfo.absolutePath()); RS_SETTINGS->init(XSTR(QC_COMPANYKEY), XSTR(QC_APPKEY)); RS_SYSTEM->init(XSTR(QC_APPNAME), XSTR(QC_VERSION), XSTR(QC_APPDIR), prgDir); // parse command line arguments that might not need a launched program: QStringList fileList = handleArgs(argc, argv, argClean); QString lang; QString langCmd; QString unit; RS_SETTINGS->beginGroup("/Defaults"); #ifndef QC_PREDEFINED_UNIT unit = RS_SETTINGS->readEntry("/Unit", "Invalid"); #else unit = RS_SETTINGS->readEntry("/Unit", QC_PREDEFINED_UNIT); #endif RS_SETTINGS->endGroup(); // show initial config dialog: if (unit=="Invalid") { RS_DEBUG->print("main: show initial config dialog.."); QG_DlgInitial di(NULL); di.setText("<font size=\"+1\"><b>Welcome to " XSTR(QC_APPNAME) "</b></font>" "<br>" "Please choose the unit you want to use for new drawings and your " "preferred language.<br>" "You can changes these settings later in the " "Options Dialog of " XSTR(QC_APPNAME) "."); QPixmap pxm(":/main/intro_librecad.png"); di.setPixmap(pxm); if (di.exec()) { RS_SETTINGS->beginGroup("/Defaults"); unit = RS_SETTINGS->readEntry("/Unit", "None"); RS_SETTINGS->endGroup(); } RS_DEBUG->print("main: show initial config dialog: OK"); } #ifdef QSPLASHSCREEN_H // RS_DEBUG->print("main: splashscreen.."); QPixmap* pixmap = new QPixmap(":/main/splash_librecad.png"); #endif RS_DEBUG->print("main: init fontlist.."); RS_FONTLIST->init(); RS_DEBUG->print("main: init fontlist: OK"); RS_DEBUG->print("main: init patternlist.."); RS_PATTERNLIST->init(); RS_DEBUG->print("main: init patternlist: OK"); RS_DEBUG->print("main: init scriptlist.."); RS_SCRIPTLIST->init(); RS_DEBUG->print("main: init scriptlist: OK"); RS_DEBUG->print("main: loading translation.."); RS_SETTINGS->beginGroup("/Appearance"); #ifdef QC_PREDEFINED_LOCALE lang = RS_SETTINGS->readEntry("/Language", ""); if (lang.isEmpty()) { lang=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/Language", lang); } langCmd = RS_SETTINGS->readEntry("/LanguageCmd", ""); if (langCmd.isEmpty()) { langCmd=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/LanguageCmd", langCmd); } #else lang = RS_SETTINGS->readEntry("/Language", "en"); langCmd = RS_SETTINGS->readEntry("/LanguageCmd", "en"); #endif RS_SETTINGS->endGroup(); RS_SYSTEM->loadTranslation(lang, langCmd); RS_DEBUG->print("main: loading translation: OK"); #ifdef QSPLASHSCREEN_H RS_SETTINGS->beginGroup("Appearance"); { bool showSplash=RS_SETTINGS->readNumEntry("/ShowSplash",1)==1; if(showSplash){ splash = new QSplashScreen(*pixmap); splash->show(); splash->showMessage(QObject::tr("Loading.."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: splashscreen: OK"); } } RS_SETTINGS->endGroup(); #endif //QApplication::setStyle(new QWindowsStyle()); //QApplication::setStyle(new QPlatinumStyle()); #ifdef QC_BUILTIN_STYLE //js: RS_DEBUG->print("main: applying built in style.."); applyBuiltinStyle(); #endif RS_DEBUG->print("main: creating main window.."); QC_ApplicationWindow * appWin = new QC_ApplicationWindow(); RS_DEBUG->print("main: setting caption"); appWin->setWindowTitle(XSTR(QC_APPNAME)); RS_DEBUG->print("main: show main window"); appWin->show(); RS_DEBUG->print("main: set focus"); appWin->setFocus(); RS_DEBUG->print("main: creating main window: OK"); #ifdef QSPLASHSCREEN_H if (splash) { RS_DEBUG->print("main: updating splash.."); splash->showMessage(QObject::tr("Loading..."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: processing events"); qApp->processEvents(); RS_DEBUG->print("main: updating splash: OK"); } #endif // Set LC_NUMERIC so that enetring numeric values uses . as teh decimal seperator setlocale(LC_NUMERIC, "C"); RS_DEBUG->print("main: loading files.."); bool files_loaded = false; for (QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it ) { #ifdef QSPLASHSCREEN_H if (splash) { splash->showMessage(QObject::tr("Loading File %1..") .arg(QDir::toNativeSeparators(*it)), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); qApp->processEvents(); } #endif appWin->slotFileOpen(*it, RS2::FormatUnknown); files_loaded = true; } RS_DEBUG->print("main: loading files: OK"); #ifdef QSPLASHSCREEN_H # ifndef QC_DELAYED_SPLASH_SCREEN if (splash) { splash->finish(appWin); delete splash; splash = nullptr; } # endif delete pixmap; #endif //app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); RS_DEBUG->print("main: app.exec()"); if (!files_loaded) { appWin->slotFileNewNew(); } appWin->slotRunStartScript(); int r = app.exec(); RS_DEBUG->print("main: Temporary disabled delete appWin"); // delete appWin; RS_DEBUG->print("main: finished"); return r; }
static modinfo check_mod(Relation &R, int o, bool tightmod) { // R must be a single conjunct modinfo m, badm; m.modbase = 0; m.input_var = 0; m.input_var_coef = 0; badm = m; if (tcodegen_debug) { fprintf(DebugFile, "%s%s%d%s\n", debug_mark_cp, "looking for mod substitution for output variable #", o, " in relation"); fprintf(DebugFile, "%s", debug_mark_cp); R.print_with_subs(DebugFile); } // look for: exists k s.t. 0 <= o < modbase && o = i + offset + k * modbase Variable_ID ov = R.output_var(o); Variable_ID k = 0; // Start by looking for // exists k s.t. o = i_coef * i + offset + k * modbase // We may also need to ignore "modbase * anything_else" terms, // which we call "junk terms". // This is most easily done if we just hunt down modbase first DNF_Iterator di(R.query_DNF()); for (EQ_Iterator ei = (*di)->EQs(); ei; ei++) { int o_coef = (*ei).get_coef(ov); if (o_coef != 0) { if (m.modbase != 0 || // there can be ... only one abs(o_coef) != 1) // above form requires this return badm; assert(m.input_var == 0); // First, just figure out what modbase is // Currently just find the (hopefully unique) wildcard/exists var. // This does not allow junk wildcard terms. for (Constr_Vars_Iter cvi(*ei); cvi; cvi++) { Variable_ID v = (*cvi).var; int v_coef = (*cvi).coef; if ((v->kind() == Wildcard_Var || v->kind() == Exists_Var)) { if (m.modbase == 0) { m.modbase = abs(v_coef); k = v; assert(m.modbase != 0); } else { if (tcodegen_debug) { fprintf(DebugFile, "%s%s\n", debug_mark_cp, "giving up on possible junk wildcard term --" " test, though simple, is not implemented"); } return badm; } } } if (m.modbase == 0) return badm; assert(k); { // extra braces apparently avoid Visual C++ bug for (Constr_Vars_Iter cvi(*ei); cvi; cvi++) { Variable_ID v = (*cvi).var; int v_coef = (*cvi).coef; // we could find i, k (again), ov (again), junk, or a problem // throw out junk terms first, in case of junk i before real i if ((v_coef % m.modbase) != 0) { if ((v->kind() == Input_Var) && // found i m.input_var == 0) // there can be ... only one { assert(v_coef); assert(abs(o_coef) == 1); m.input_var_coef = v_coef * -o_coef; m.input_var = v->get_position(); assert(m.input_var != 0); } else if (v != ov) { // Anything else is a legal junk term or "k" again // as long as its divisible by m.modbase. return badm; } } } } if (m.input_var == 0) // found eq, but not base return badm; m.offset = -o_coef * (*ei).get_const(); // now, as long as we don't find another eq, we should be set } } if (m.modbase == 0) // no eq involving ov return badm; // only that one eq should use k assert(k); bool k_used_already = false; { for (EQ_Iterator ei = (*di)->EQs(); ei; ei++) { if ((*ei).get_coef(k)) if (k_used_already) return badm; else k_used_already = true; } } // we've found the right eq, now check for the inequalities 0 <= o < modbase // also test for other (inappropriate) uses of k bool found_lb = false, found_ub = false; for (GEQ_Iterator gi = (*di)->GEQs(); gi; gi++) { int ov_coef = (*gi).get_coef(ov); if (ov_coef) { if (ov_coef > 0) // hope for ov >= 0 { if (ov_coef != 1 || (*gi).get_const() != 0) return badm; found_lb = true; } else // ov_coef < 0 hope for modbase-1 - ov >= 0 { if (ov_coef != -1) return badm; if (!( ((*gi).get_const() == m.modbase-1) // got it exactly // we'll settle for x-ov >= 0 for x<=modbase-1 if looking for "tight" mod || (tightmod && (*gi).get_const() <= m.modbase-1))) return badm; if (tcodegen_debug && (*gi).get_const() < m.modbase-1) { fprintf(DebugFile, "%s%s"coef_fmt"%s%d\n", debug_mark_cp, "found \"tight\" mod constraint output < ", (*gi).get_const(), " rather than output < ", m.modbase-1); } found_ub = true; } // all other coefficients must be 0 for this geq for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) { if ((*cvi).var != ov && (*cvi).coef) return badm; } } // also, k should not appear in any inequalities if ((*gi).get_coef(k)) return badm; } if (!found_lb || !found_ub) return badm; if (tcodegen_debug) { fprintf(DebugFile, "%s%s%d%s%d%s%d%s%d\n", debug_mark_cp, "found substitution: (", m.input_var_coef, "* input variable #", m.input_var, "+", m.offset, ") mod ", m.modbase); } #if ! defined NDEBUG if (m.modbase) { // build { [ ... i ... ] -> [ ... (ic * i + offset) mod modbase ... ] } // build { [ ... i ... ] -> [ ... o ... ] : exists k s.t. // 0 <= o < modbase && o = ic * i + offset + k * modbase } Relation checkmod(R.n_inp(), R.n_out()); Variable_ID ic = checkmod.input_var(m.input_var); Variable_ID oc = checkmod.output_var(o); F_Exists *exists_k = checkmod.add_exists(); Variable_ID k = exists_k->declare("o_div_modbase"); F_And *suchthat = exists_k->add_and(); // 0 <= o GEQ_Handle o_geq_0 = suchthat->add_GEQ(); o_geq_0.update_coef(oc,1); // o < modbase --> modbase-1-o >= 0 GEQ_Handle o_lt_checkmod = suchthat->add_GEQ(); o_lt_checkmod.update_coef(oc,-1); o_lt_checkmod.update_const(m.modbase-1); // ic * i + offset + k * modbase - o = 0 EQ_Handle o_eq = suchthat->add_EQ(); o_eq.update_coef(ic,m.input_var_coef); o_eq.update_const(m.offset); o_eq.update_coef(k,m.modbase); o_eq.update_coef(oc,-1); checkmod.finalize(); checkmod = Intersection(checkmod, copy(R)); // by definition, checkmod is a subset of R; // if the above mod constraint is redundant, R is a subset of checkmod assert(Must_Be_Subset(copy(checkmod),copy(R))); // the obvious one assert(Must_Be_Subset(copy(R),checkmod)); // mod constraint is redundant } #endif return m; }
void QgsGrassVectorMapLayer::load() { QgsDebugMsg( "entered" ); clear(); if ( !mMap ) { return; } // Attributes are not loaded for topo layers in which case field == 0 if ( mField == 0 ) { return; } QgsDebugMsg( QString( "cidxFieldIndex() = %1 cidxFieldNumCats() = %2" ).arg( cidxFieldIndex() ).arg( cidxFieldNumCats() ) ); mFieldInfo = Vect_get_field( mMap->map(), mField ); // should work also with field = 0 if ( !mFieldInfo ) { QgsDebugMsg( "No field info -> no attribute table" ); } else { QgsDebugMsg( "Field info found -> open database" ); QFileInfo di( mMap->grassObject().mapsetPath() + "/vector/" + mMap->grassObject().name() + "/dbln" ); mLastLoaded = di.lastModified(); QgsGrass::lock(); dbDriver *databaseDriver = 0; QString error = QString( "Cannot open database %1 by driver %2" ).arg( mFieldInfo->database ).arg( mFieldInfo->driver ); G_TRY { databaseDriver = db_start_driver_open_database( mFieldInfo->driver, mFieldInfo->database ); } G_CATCH( QgsGrass::Exception &e ) { QgsGrass::warning( error + " : " + e.what() ); } if ( !databaseDriver ) { QgsDebugMsg( error ); } else { QgsDebugMsg( "Database opened -> open select cursor" ); dbString dbstr; db_init_string( &dbstr ); db_set_string( &dbstr, ( char * )"select * from " ); db_append_string( &dbstr, mFieldInfo->table ); QgsDebugMsg( QString( "SQL: %1" ).arg( db_get_string( &dbstr ) ) ); dbCursor databaseCursor; if ( db_open_select_cursor( databaseDriver, &dbstr, &databaseCursor, DB_SCROLL ) != DB_OK ) { db_close_database_shutdown_driver( databaseDriver ); QgsGrass::warning( "Cannot select attributes from table '" + QString( mFieldInfo->table ) + "'" ); } else { #ifdef QGISDEBUG int nRecords = db_get_num_rows( &databaseCursor ); QgsDebugMsg( QString( "Number of records: %1" ).arg( nRecords ) ); #endif dbTable *databaseTable = db_get_cursor_table( &databaseCursor ); int nColumns = db_get_table_number_of_columns( databaseTable ); // Read columns' description for ( int i = 0; i < nColumns; i++ ) { QPair<double, double> minMax( DBL_MAX, -DBL_MAX ); dbColumn *column = db_get_table_column( databaseTable, i ); int ctype = db_sqltype_to_Ctype( db_get_column_sqltype( column ) ); QVariant::Type qtype = QVariant::String; //default to string QgsDebugMsg( QString( "column = %1 ctype = %2" ).arg( db_get_column_name( column ) ).arg( ctype ) ); QString ctypeStr; switch ( ctype ) { case DB_C_TYPE_INT: ctypeStr = "integer"; qtype = QVariant::Int; break; case DB_C_TYPE_DOUBLE: ctypeStr = "double"; qtype = QVariant::Double; break; case DB_C_TYPE_STRING: ctypeStr = "string"; qtype = QVariant::String; break; case DB_C_TYPE_DATETIME: ctypeStr = "datetime"; qtype = QVariant::String; break; } mTableFields.append( QgsField( db_get_column_name( column ), qtype, ctypeStr, db_get_column_length( column ), db_get_column_precision( column ) ) ); mMinMax << minMax; if ( G_strcasecmp( db_get_column_name( column ), mFieldInfo->key ) == 0 ) { mKeyColumn = i; } } if ( mKeyColumn < 0 ) { mTableFields.clear(); QgsGrass::warning( QObject::tr( "Key column '%1' not found in the table '%2'" ).arg( mFieldInfo->key ).arg( mFieldInfo->table ) ); } else { mHasTable = true; // Read attributes to the memory while ( true ) { int more; if ( db_fetch( &databaseCursor, DB_NEXT, &more ) != DB_OK ) { QgsDebugMsg( "Cannot fetch DB record" ); break; } if ( !more ) { break; // no more records } // Check cat value dbColumn *column = db_get_table_column( databaseTable, mKeyColumn ); dbValue *value = db_get_column_value( column ); if ( db_test_value_isnull( value ) ) { continue; } int cat = db_get_value_int( value ); if ( cat < 0 ) { continue; } QList<QVariant> values; for ( int i = 0; i < nColumns; i++ ) { column = db_get_table_column( databaseTable, i ); int sqltype = db_get_column_sqltype( column ); int ctype = db_sqltype_to_Ctype( sqltype ); value = db_get_column_value( column ); db_convert_value_to_string( value, sqltype, &dbstr ); QgsDebugMsgLevel( QString( "column = %1 value = %2" ).arg( db_get_column_name( column ) ).arg( db_get_string( &dbstr ) ), 3 ); QVariant variant; if ( !db_test_value_isnull( value ) ) { int iv; double dv; //layer.mAttributes[layer.nAttributes].values[i] = strdup( db_get_string( &dbstr ) ); switch ( ctype ) { case DB_C_TYPE_INT: iv = db_get_value_int( value ); variant = QVariant( iv ); mMinMax[i].first = qMin( mMinMax[i].first, ( double )iv ); mMinMax[i].second = qMin( mMinMax[i].second, ( double )iv ); break; case DB_C_TYPE_DOUBLE: dv = db_get_value_double( value ); variant = QVariant( dv ); mMinMax[i].first = qMin( mMinMax[i].first, dv ); mMinMax[i].second = qMin( mMinMax[i].second, dv ); break; case DB_C_TYPE_STRING: // Store as byte array so that codec may be used later variant = QVariant( QByteArray( db_get_value_string( value ) ) ); break; case DB_C_TYPE_DATETIME: variant = QVariant( QByteArray( db_get_string( &dbstr ) ) ); default: variant = QVariant( QByteArray( db_get_string( &dbstr ) ) ); } } QgsDebugMsgLevel( QString( "column = %1 variant = %2" ).arg( db_get_column_name( column ) ).arg( variant.toString() ), 3 ); values << variant; } mAttributes.insert( cat, values ); } } mValid = true; db_close_cursor( &databaseCursor ); db_close_database_shutdown_driver( databaseDriver ); db_free_string( &dbstr ); QgsDebugMsg( QString( "mTableFields.size = %1" ).arg( mTableFields.size() ) ); QgsDebugMsg( QString( "number of attributes = %1" ).arg( mAttributes.size() ) ); } } QgsGrass::unlock(); }
static String desperate_check_mod_kludge_for_time_skewing(Relation &R, int o) { Variable_ID Out_1, Out_3, In_4, In_8, alpha, v, k1, k2, k3, k4; int Out_1_coef, Out_3_coef, v_coef, const_term; int sign; F_Exists *exists_k1, *exists_k1k2, *exists_k3, *exists_k4; F_And *st_k1, *st_k1k2, *st_k3, *st_k4; GEQ_Handle geq_L_k1, geq_U_k1, geq_L_k3, geq_U_k3, geq_L_k4, geq_U_k4; EQ_Handle eq_k1, eq_k3, eq_k4; // R must be a single conjunct // PROBLEM: FOR SOME REASON, THE RELEVANT EQUALITY SHOWS UP AS // t8 == 7+8*xbmod2+8*t4+Out_3+16*alpha // note Out_1 is xbmod2 // WHEN WE DO PRINT_WITH SUBS, BUT THE "TRUE" FORM IS // 8*xbmod2+8*t4+t8 == 7+Out_3+16*alpha // AS EVIDENCED BY THIS prefix_print. // // IS THIS CORRECT? PRESUMABLY SO... // BASED ON AN UNDERSTANDING OF HOW ITS CORRECT, WE NEED TO // GENERALIZE OR CHANGE THE TEST BELOW. // R.prefix_print(stdout); if (tcodegen_debug) { fprintf(DebugFile, "%s%s\n", debug_mark_cp, "desperately looking for special case mod and div substitution."); } // check that the only EQ constraint using Out_1 and Out_3 is of the form // exists alpha : 8*Out_1 + 8*In_4 + In_8 == 7 + Out_3 + 16*alpha Out_1 = R.output_var(1); Out_3 = R.output_var(3); In_4=0, In_8=0, alpha=0; // look for these vars in the loop -- // In_4 must play the appropriate role // in the equality above, but may not // actually be the 4th input variable. DNF_Iterator di(R.query_DNF()); // This loop looks for any one equality of the right form. // We we find it, we break out of the loop with alpha, In_4, and In_8 set; // When we discover we've got the wrong form, we continue the loop. for (EQ_Iterator ei = (*di)->EQs(); ei; ei++, alpha = In_4 = In_8 = 0) { Out_1_coef = (*ei).get_coef(Out_1); Out_3_coef = (*ei).get_coef(Out_3); if (abs(Out_3_coef) == 1 && Out_1_coef * Out_3_coef == -8) { sign = Out_3_coef; const_term = -sign * (*ei).get_const(); for (Constr_Vars_Iter cvi(*ei); cvi; cvi++) { v = (*cvi).var; v_coef = (*cvi).coef; if (v->kind() == Wildcard_Var || v->kind() == Exists_Var) // must be alpha { if (alpha || v_coef != 16) goto continue_ei; alpha = v; } else if (v_coef % 16 == 0) // anything else doesn't matter continue; else if (v->kind() == Output_Var) // must be Out_3 or Out_1 { if (v != Out_1 && v != Out_3) goto continue_ei; } else if (v->kind() == Input_Var) // must be In_4 or In_8 { if (v_coef * sign == -1) { if (In_8) goto continue_ei; In_8 = v; } else if (v_coef * sign == -8) { if (In_4) goto continue_ei; In_4 = v; } else goto continue_ei; } else // some other kind of variable I haven't considered goto continue_ei; } // for all vars in constraint if (alpha && In_4 && In_8) break; } // end of "if Out and In have reasonable coefficients" continue_ei: ; } // end of equality iteration if (! (alpha && In_4 && In_8)) return ""; // if o=3, assert (and return) substitution (In_8-8In_4-7) mod 8 if (o == 3) { #if ! defined NDEBUG // DO AN ASSERTION THAT THIS IS CORRECT Relation checkmod(R.n_inp(),R.n_out()); assert(Out_1->kind() == Output_Var && Out_1->get_position() == 1); assert(Out_3->kind() == Output_Var && Out_3->get_position() == 3); assert(In_4->kind() == Input_Var); // Note then In_4 may not actually be input var #4. assert(In_8->kind() == Input_Var); //Variable_ID cm_out_1 = checkmod.output_var(Out_1->get_position()); Variable_ID cm_out_3 = checkmod.output_var(Out_3->get_position()); Variable_ID cm_in_4 = checkmod.input_var (In_4->get_position()); Variable_ID cm_in_8 = checkmod.input_var (In_8->get_position()); exists_k1=checkmod.add_exists(); k1=(*exists_k1).declare("k1_modbase"); st_k1=(*exists_k1).add_and(); geq_L_k1=(*st_k1).add_GEQ(); geq_L_k1.update_coef(cm_out_3,1); geq_U_k1=(*st_k1).add_GEQ(); geq_U_k1.update_coef(cm_out_3,-1); geq_U_k1.update_const(7); eq_k1=(*st_k1).add_EQ(); eq_k1.update_coef(cm_out_3,-1); eq_k1.update_coef(cm_in_8,1); eq_k1.update_coef(cm_in_4,-8); eq_k1.update_coef(k1,8); eq_k1.update_const(-7); checkmod.finalize(); checkmod = Intersection(checkmod, copy(R)); // by definition, checkmod is a subset of R; // if the above mod constraint is redundant, R is a subset of checkmod assert(Must_Be_Subset(copy(checkmod),copy(R))); // the obvious one assert(Must_Be_Subset(copy(R),checkmod)); // mod constraint is redundant #endif return (String) "intMod(" + In_8->char_name() + "-8*" + In_4->char_name() + "+" + itoS(const_term) + ",8)"; // return "intMod(t8-8*t4-7,8)"; } // if o=1, assert&return the sub ( (8*((In_8-8In_4-7) div 8)) mod 16 ) div 8 else if (o == 1) { #if ! defined NDEBUG Relation checkmod(R.n_inp(),R.n_out()); assert(Out_1->kind() == Output_Var && Out_1->get_position() == 1); assert(Out_3->kind() == Output_Var && Out_3->get_position() == 3); assert(In_4->kind() == Input_Var); // Note then In_4 may not actually be input var #4. assert(In_8->kind() == Input_Var); Variable_ID cm_out_1 = checkmod.output_var(Out_1->get_position()); //Variable_ID cm_out_3 = checkmod.output_var(Out_3->get_position()); Variable_ID cm_in_4 = checkmod.input_var (In_4->get_position()); Variable_ID cm_in_8 = checkmod.input_var (In_8->get_position()); exists_k1k2=checkmod.add_exists(); k1=(*exists_k1k2).declare("k1_modbase"); k2=(*exists_k1k2).declare("k2_modbase"); st_k1k2=(*exists_k1k2).add_and(); geq_L_k1=(*st_k1k2).add_GEQ(); geq_L_k1.update_coef(k1,1); geq_L_k1.update_coef(cm_in_8,-1); geq_L_k1.update_coef(cm_in_4,8); geq_L_k1.update_const(14); geq_U_k1=(*st_k1k2).add_GEQ(); geq_U_k1.update_coef(k1,-1); geq_U_k1.update_coef(cm_in_8,1); geq_U_k1.update_coef(cm_in_4,-8); geq_U_k1.update_const(-7); exists_k3=(*st_k1k2).add_exists(); k3=(*exists_k3).declare("k3_modbase"); st_k3=(*exists_k3).add_and(); geq_L_k3=(*st_k3).add_GEQ(); geq_L_k3.update_coef(k2,1); geq_U_k3=(*st_k3).add_GEQ(); geq_U_k3.update_coef(k2,-1); geq_U_k3.update_const(15); eq_k3=(*st_k3).add_EQ(); eq_k3.update_coef(k1,1); eq_k3.update_coef(k3,-8); exists_k4=(*st_k3).add_exists(); k4=(*exists_k4).declare("k4_modbase"); st_k4=(*exists_k4).add_and(); geq_L_k4=(*st_k4).add_GEQ(); geq_L_k4.update_coef(k2,1); geq_L_k4.update_coef(cm_out_1,-8); geq_U_k4=(*st_k4).add_GEQ(); geq_U_k4.update_coef(k2,-1); geq_U_k4.update_coef(cm_out_1,8); geq_U_k4.update_const(7); eq_k4=(*st_k4).add_EQ(); eq_k4.update_coef(k1,-1); eq_k4.update_coef(k2,1); eq_k4.update_coef(k4,16); checkmod.finalize(); checkmod = Intersection(checkmod, copy(R)); // by definition, checkmod is a subset of R; // if the above mod constraint is redundant, R is a subset of checkmod assert(Must_Be_Subset(copy(checkmod),copy(R))); // the obvious one assert(Must_Be_Subset(copy(R),checkmod)); // mod constraint is redundant #endif return (String) "intDiv(intMod(8*intDiv(" + (*In_8).char_name() + "-8*" + (*In_4).char_name() + "+" + itoS(const_term) + ",8),16),8)"; // return "intDiv(intMod(8*intDiv(t8-8*t4-7,8),16),8)"; } else return ""; }
ObserverDownloadInfo DownloadsObserver::GetInfo(IDownload* dl) { ObserverDownloadInfo di(dl); return di; }
void doexit(uint16_t val) { int16_t j; ptptr p; irqflags_t irq; #ifdef DEBUG kprintf("process %d exiting\n", udata.u_ptab->p_pid); kprintf ("udata.u_page %u, udata.u_ptab %x, udata.u_ptab->p_page %u\n", udata.u_page, udata.u_ptab, udata.u_ptab->p_page); #endif if (udata.u_ptab->p_pid == 1) panic(PANIC_KILLED_INIT); sync(); /* Not necessary, but a good idea. */ irq = di(); /* Discard our memory before we blow away and reuse the memory */ pagemap_free(udata.u_ptab); for (j = 0; j < UFTSIZE; ++j) { if (udata.u_files[j] != NO_FILE) doclose(j); } udata.u_ptab->p_exitval = val; i_deref(udata.u_cwd); i_deref(udata.u_root); /* Stash away child's execution tick counts in process table, * overlaying some no longer necessary stuff. * * Pedantically POSIX says we should do this at the point of wait() */ udata.u_utime += udata.u_cutime; udata.u_stime += udata.u_cstime; memcpy(&(udata.u_ptab->p_priority), &udata.u_utime, 2 * sizeof(clock_t)); for (p = ptab; p < ptab_end; ++p) { if (p->p_status == P_EMPTY || p == udata.u_ptab) continue; /* Set any child's parents to our parent */ /* FIXME: do we need to wakeup the parent if we do this ? */ if (p->p_pptr == udata.u_ptab) p->p_pptr = udata.u_ptab->p_pptr; /* Send SIGHUP to any pgrp members and remove them from our pgrp */ if (p->p_pgrp == udata.u_ptab->p_pid) { p->p_pgrp = 0; ssig(p, SIGHUP); ssig(p, SIGCONT); } } tty_exit(); irqrestore(irq); #ifdef DEBUG kprintf ("udata.u_page %u, udata.u_ptab %x, udata.u_ptab->p_page %u\n", udata.u_page, udata.u_ptab, udata.u_ptab->p_page); #endif #ifdef CONFIG_ACCT acctexit(p); #endif udata.u_page = 0xFFFFU; udata.u_page2 = 0xFFFFU; signal_parent(udata.u_ptab->p_pptr); nready--; nproc--; switchin(getproc()); panic(PANIC_DOEXIT); }
void UnitTestSTKParallelDistributedIndex::test_generate() { typedef stk::parallel::DistributedIndex PDIndex ; stk::ParallelMachine comm = MPI_COMM_WORLD ; int mpi_rank = stk::parallel_machine_rank(comm); // int mpi_size = stk::parallel_machine_size(comm); std::vector< PDIndex::KeySpan > partition_spans ; generate_test_spans_10x10000( partition_spans ); PDIndex di( comm , partition_spans ); std::vector<size_t> requests( partition_spans.size() , size_t(0) ); std::vector< std::vector<PDIndex::KeyType> > generated_keys ; std::vector<PDIndex::KeyProc> sharing_of_local_keys ; di.generate_new_keys( requests , generated_keys ); EXPECT_TRUE( di.m_key_usage.empty() ); ASSERT_EQ( generated_keys.size() , partition_spans.size() ); for ( size_t i = 0 ; i < generated_keys.size() ; ++i ) { EXPECT_TRUE( generated_keys[i].empty() ); } //---------------------------------------- size_t total = 0 ; for ( size_t i = 0 ; i < requests.size() ; ++i ) { requests[i] = i + mpi_rank ; total += requests[i] ; } di.generate_new_keys( requests , generated_keys ); ASSERT_EQ( generated_keys.size() , partition_spans.size() ); for ( size_t i = 0 ; i < generated_keys.size() ; ++i ) { EXPECT_EQ( generated_keys[i].size() , requests[i] ); for ( size_t j = 0 ; j < generated_keys[i].size() ; ++j ) { EXPECT_TRUE( partition_spans[i].first <= generated_keys[i][j] ); EXPECT_TRUE( generated_keys[i][j] <= partition_spans[i].second ); if ( 0 < j ) { EXPECT_TRUE( generated_keys[i][j-1] < generated_keys[i][j] ); } } } //---------------------------------------- di.query( sharing_of_local_keys ); EXPECT_EQ( sharing_of_local_keys.size() , total ); // Confirm global uniqueness for ( size_t i = 0 ; i < generated_keys.size() ; ++i ) { di.query( generated_keys[i] , sharing_of_local_keys ); EXPECT_EQ( generated_keys[i].size() , sharing_of_local_keys.size() ); for ( size_t j = 0 ; j < sharing_of_local_keys.size() ; ++j ) { EXPECT_EQ( sharing_of_local_keys[j].second , mpi_rank ); } } //---------------------------------------- // Double the number of keys di.generate_new_keys( requests , generated_keys ); ASSERT_EQ( generated_keys.size() , partition_spans.size() ); for ( size_t i = 0 ; i < generated_keys.size() ; ++i ) { EXPECT_EQ( generated_keys[i].size() , requests[i] ); for ( size_t j = 0 ; j < generated_keys[i].size() ; ++j ) { EXPECT_TRUE( partition_spans[i].first <= generated_keys[i][j] ); EXPECT_TRUE( generated_keys[i][j] <= partition_spans[i].second ); if ( 0 < j ) { EXPECT_TRUE( generated_keys[i][j-1] < generated_keys[i][j] ); } } } di.query( sharing_of_local_keys ); EXPECT_EQ( sharing_of_local_keys.size() , total * 2 ); }
//=============================================== //=============================================== //=============================================== //=============================================== void main(void) { t0_init(); ei(); PEIE=1; di(); ei(); TRISB=0x00; PORTB=0x00; PORTC|=(1<<led_ERR); sci_init(); while (1) { if(bRXIN) { bRXIN=0; UART_IN(); } if(bit_100Hz) { bit_100Hz=0; in_read(); step_contr(); mdvr_drv(); but_drv(); but_an(); } if(bit_10Hz) { bit_10Hz=0; // out_out(); led_out(); err_drv(); prog_drv(); // if(prog==p1) OUT(3,CMND,eeprom_read(DELAY1),eeprom_read(DELAY2)/*3,3*/,0,0,0); // else if(prog==p2) OUT(3,CMND,eeprom_read(DELAY3),eeprom_read(DELAY4),0,0,0); if(prog==p1) { if(!sub_ind)adress=DELAY1; else adress=DELAY2; } else if(prog==p2) { if(!sub_ind)adress=DELAY3; else adress=DELAY4; } OUT(3,CMND,/*prog*/eeprom_read(adress),sub_ind+1,0,0,0); } if(bit_1Hz) { bit_1Hz=0; } } }
void UnitTestSTKParallelDistributedIndex::test_generate_big() { typedef stk::parallel::DistributedIndex PDIndex ; stk::ParallelMachine comm = MPI_COMM_WORLD ; const int mpi_rank = stk::parallel_machine_rank(comm); const int mpi_size = stk::parallel_machine_size(comm); std::vector< PDIndex::KeySpan > partition_spans ; generate_test_spans_10x10000( partition_spans ); PDIndex di( comm , partition_spans ); std::vector<size_t> requests( partition_spans.size() , size_t(0) ); std::vector< std::vector<PDIndex::KeyType> > generated_keys ; //---------------------------------------- if ( mpi_rank == mpi_size - 1 ) { requests[5] = 5000 ; // Half } else { requests[5] = 0 ; } di.generate_new_keys( requests , generated_keys ); ASSERT_EQ( generated_keys.size() , partition_spans.size() ); for ( size_t i = 0 ; i < generated_keys.size() ; ++i ) { EXPECT_EQ( generated_keys[i].size() , requests[i] ); } //---------------------------------------- if ( mpi_rank == mpi_size - 1 ) { requests[5] = 4999 ; // Almost half again } else { requests[5] = 0 ; } di.generate_new_keys( requests , generated_keys ); ASSERT_EQ( generated_keys.size() , partition_spans.size() ); for ( size_t i = 0 ; i < generated_keys.size() ; ++i ) { EXPECT_EQ( generated_keys[i].size() , requests[i] ); } //---------------------------------------- // This should request generation of one too many keys. if ( mpi_rank == 0 ) { requests[5] = 2 ; // Exceed the total } else { requests[5] = 0 ; } ASSERT_THROW( di.generate_new_keys( requests , generated_keys ) , std::runtime_error ); }
void FBMReference::diagonalizeBlock( const unsigned int block, const TNT::Array2D<double> &hessian, const std::vector<Vec3> &positions, TNT::Array1D<double> &eval, TNT::Array2D<double> &evec ) { const unsigned int ConservedDegreesOfFreedom = 6; printf( "Diagonalizing Block: %d\n", block ); // 1. Determine the starting and ending index for the block // This means that the upper left corner of the block will be at (startatom, startatom) // And the lower right corner will be at (endatom, endatom) const int startatom = 3 * blockSizes[block]; int endatom = 3 * particleCount - 1 ; if( block != ( blockSizes.size() - 1 ) ) { endatom = 3 * blockSizes[block + 1] - 1; } const int size = endatom - startatom + 1; // 2. Get the block Hessian Hii // Right now I'm just doing a copy from the big Hessian // There's probably a more efficient way but for now I just want things to work.. TNT::Array2D<double> h_tilde( size, size, 0.0 ); for( int j = startatom; j <= endatom; j++ ) { for( int k = startatom; k <= endatom; k++ ) { h_tilde[k - startatom][j - startatom] = hessian[k][j]; } } // 3. Diagonalize the block Hessian only, and get eigenvectors TNT::Array1D<double> di( size, 0.0 ); TNT::Array2D<double> Qi( size, size, 0.0 ); diagonalizeSymmetricMatrix( h_tilde, di, Qi ); // sort eigenvalues by absolute magnitude std::vector<EigenvalueColumn> sortedPairs = sortEigenvalues( di ); // find geometric dof TNT::Array2D<double> Qi_gdof( size, size, 0.0 ); Vec3 pos_center( 0.0, 0.0, 0.0 ); double totalmass = 0.0; for( int j = startatom; j <= endatom; j += 3 ) { double mass = mParticleMass[ j / 3 ]; pos_center += positions[j / 3] * mass; totalmass += mass; } double norm = sqrt( totalmass ); // actual center pos_center *= 1.0 / totalmass; // create geometric dof vectors // iterating over rows and filling in values for 6 vectors as we go for( int j = 0; j < size; j += 3 ) { double atom_index = ( startatom + j ) / 3; double mass = mParticleMass[atom_index]; double factor = sqrt( mass ) / norm; // translational Qi_gdof[j][0] = factor; Qi_gdof[j + 1][1] = factor; Qi_gdof[j + 2][2] = factor; // rotational // cross product of rotation axis and vector to center of molecule // x-axis (b1=1) ja3-ka2 // y-axis (b2=1) ka1-ia3 // z-axis (b3=1) ia2-ja1 Vec3 diff = positions[atom_index] - pos_center; // x Qi_gdof[j + 1][3] = diff[2] * factor; Qi_gdof[j + 2][3] = -diff[1] * factor; // y Qi_gdof[j][4] = -diff[2] * factor; Qi_gdof[j + 2][4] = diff[0] * factor; // z Qi_gdof[j][5] = diff[1] * factor; Qi_gdof[j + 1][5] = -diff[0] * factor; } // normalize first rotational vector double rotnorm = 0.0; for( int j = 0; j < size; j++ ) { rotnorm += Qi_gdof[j][3] * Qi_gdof[j][3]; } rotnorm = 1.0 / sqrt( rotnorm ); for( int j = 0; j < size; j++ ) { Qi_gdof[j][3] = Qi_gdof[j][3] * rotnorm; } // orthogonalize rotational vectors 2 and 3 for( int j = 4; j < ConservedDegreesOfFreedom; j++ ) { // <-- vector we're orthogonalizing for( int k = 3; k < j; k++ ) { // <-- vectors we're orthognalizing against double dot_prod = 0.0; for( int l = 0; l < size; l++ ) { dot_prod += Qi_gdof[l][k] * Qi_gdof[l][j]; } for( int l = 0; l < size; l++ ) { Qi_gdof[l][j] = Qi_gdof[l][j] - Qi_gdof[l][k] * dot_prod; } } // normalize residual vector double rotnorm = 0.0; for( int l = 0; l < size; l++ ) { rotnorm += Qi_gdof[l][j] * Qi_gdof[l][j]; } rotnorm = 1.0 / sqrt( rotnorm ); for( int l = 0; l < size; l++ ) { Qi_gdof[l][j] = Qi_gdof[l][j] * rotnorm; } } // orthogonalize original eigenvectors against gdof // number of evec that survive orthogonalization int curr_evec = ConservedDegreesOfFreedom; for( int j = 0; j < size; j++ ) { // <-- vector we're orthogonalizing // to match ProtoMol we only include size instead of size + cdof vectors // Note: for every vector that is skipped due to a low norm, // we add an additional vector to replace it, so we could actually // use all size original eigenvectors if( curr_evec == size ) { break; } // orthogonalize original eigenvectors in order from smallest magnitude // eigenvalue to biggest int col = sortedPairs.at( j ).second; // copy original vector to Qi_gdof -- updated in place for( int l = 0; l < size; l++ ) { Qi_gdof[l][curr_evec] = Qi[l][col]; } // get dot products with previous vectors for( int k = 0; k < curr_evec; k++ ) { // <-- vector orthog against // dot product between original vector and previously // orthogonalized vectors double dot_prod = 0.0; for( int l = 0; l < size; l++ ) { dot_prod += Qi_gdof[l][k] * Qi[l][col]; } // subtract from current vector -- update in place for( int l = 0; l < size; l++ ) { Qi_gdof[l][curr_evec] = Qi_gdof[l][curr_evec] - Qi_gdof[l][k] * dot_prod; } } //normalize residual vector double norm = 0.0; for( int l = 0; l < size; l++ ) { norm += Qi_gdof[l][curr_evec] * Qi_gdof[l][curr_evec]; } // if norm less than 1/20th of original // continue on to next vector // we don't update curr_evec so this vector // will be overwritten if( norm < 0.05 ) { continue; } // scale vector norm = sqrt( norm ); for( int l = 0; l < size; l++ ) { Qi_gdof[l][curr_evec] = Qi_gdof[l][curr_evec] / norm; } curr_evec++; } // 4. Copy eigenpairs to big array // This is necessary because we have to sort them, and determine // the cutoff eigenvalue for everybody. // we assume curr_evec <= size for( int j = 0; j < curr_evec; j++ ) { int col = sortedPairs.at( j ).second; eval[startatom + j] = di[col]; // orthogonalized eigenvectors already sorted by eigenvalue for( int k = 0; k < size; k++ ) { evec[startatom + k][startatom + j] = Qi_gdof[k][j]; } } }
bool plAnimStealthNode::IsParentUsedInScene( void ) { if( GetParentMtl() == nil ) return false; // There are two possibilities: either a node uses us and thus has a ref to us, // or a multi-sub uses us that a node has a ref to us. // Note: we could do the loop as a helper function, but we only do it twice, // so it's not *really* worth the effort... //// NOTE: the following doesn't seem to work, but keeping here in case it ever does. //// What really actually finds something is the enum dependents loop below const char *mtlName = GetParentMtl()->GetName(); DependentIterator di(this); ReferenceMaker* item = di.Next(); while( item != nil ) { TSTR s; item->GetClassName( s ); if( item->SuperClassID() == BASENODE_CLASS_ID && !CanConvertToStealth( (INode *)( item ) ) ) return true; // Horray, a node has a ref to us! else if( item->ClassID() == Class_ID(MULTI_CLASS_ID,0) ) { // Multi-sub, run the refs on that guy (we only go one up) Mtl *multisub = (Mtl *)item; DependentIterator sub(multisub); ReferenceMaker* item2 = sub.Next(); while( item2 != nil ) { if( item2->SuperClassID() == BASENODE_CLASS_ID ) return true; // Horray, a node has a ref to us! item2 = sub.Next(); } // No go, keep trying } else if( item->SuperClassID() == MATERIAL_CLASS_ID ) { int q = 0; } item = di.Next(); } // Enum dependents plGetRefs callback; ENUMDEPENDENTS(GetParentMtl(), &callback); for(int i = 0; i < callback.fList.GetCount(); i++ ) { ReferenceMaker *maker = callback.fList[ i ]; TSTR s; maker->GetClassName( s ); if( maker->SuperClassID() == BASENODE_CLASS_ID && !CanConvertToStealth( (INode *)maker ) ) return true; // Horray, a node has a ref to us! } return false; }
void SE_StructItem::setUnicodeDataItem(wchar_t* v, int index) { SE_DataItem di(SE_DataItem::UNICODE_ITEM); di.data.unicode = v; SET_DATA_ITEM(di, index); }