int get_processes ( List &processes , List &uptimes ) { PROCESSENTRY32 process; HANDLE handle; HANDLE phandle; int mypid; int ret = TRUE; /* Getting my process ID */ mypid = GetCurrentProcessId (); /* Cleaning list */ processes.Clear (); uptimes.Clear (); /* Getting process list */ handle = CreateToolhelp32Snapshot ( TH32CS_SNAPALL , 0 ); /* Initializing structure */ process.dwSize = sizeof ( PROCESSENTRY32 ); /* Getting first process */ Process32First ( handle , &process ); /* Adding the PID */ processes.Add ( ( void * ) process.th32ProcessID ); /* Getting the uptime of this process */ uptimes.Add ( ( void * ) get_process_uptime ( process.th32ProcessID ) ); /* Getting the rest of the processes */ while ( Process32Next ( handle , &process ) == TRUE ) { /* If it's not me */ if ( mypid != process.th32ProcessID ) { /* Adding the PID */ processes.Add ( ( void * ) process.th32ProcessID ); /* Getting the uptime of this process */ uptimes.Add ( ( void * ) get_process_uptime ( process.th32ProcessID ) ); } } /* Ordering process list */ processes.SortCouple ( uptimes ); /* Closing handle */ CloseHandle ( handle ); return ( ret ); }
int StepFileWriter::ExportCurveLoop(SBezierLoop *loop, bool inner) { if(loop->l.n < 1) oops(); List<int> listOfTrims; ZERO(&listOfTrims); SBezier *sb = &(loop->l.elem[loop->l.n - 1]); // Generate "exactly closed" contours, with the same vertex id for the // finish of a previous edge and the start of the next one. So we need // the finish of the last Bezier in the loop before we start our process. fprintf(f, "#%d=CARTESIAN_POINT('',(%.10f,%.10f,%.10f));\n", id, CO(sb->Finish())); fprintf(f, "#%d=VERTEX_POINT('',#%d);\n", id+1, id); int lastFinish = id + 1, prevFinish = lastFinish; id += 2; for(sb = loop->l.First(); sb; sb = loop->l.NextAfter(sb)) { int curveId = ExportCurve(sb); int thisFinish; if(loop->l.NextAfter(sb) != NULL) { fprintf(f, "#%d=CARTESIAN_POINT('',(%.10f,%.10f,%.10f));\n", id, CO(sb->Finish())); fprintf(f, "#%d=VERTEX_POINT('',#%d);\n", id+1, id); thisFinish = id + 1; id += 2; } else { thisFinish = lastFinish; } fprintf(f, "#%d=EDGE_CURVE('',#%d,#%d,#%d,%s);\n", id, prevFinish, thisFinish, curveId, ".T."); fprintf(f, "#%d=ORIENTED_EDGE('',*,*,#%d,.T.);\n", id+1, id); int oe = id+1; listOfTrims.Add(&oe); id += 2; prevFinish = thisFinish; } fprintf(f, "#%d=EDGE_LOOP('',(", id); int *oe; for(oe = listOfTrims.First(); oe; oe = listOfTrims.NextAfter(oe)) { fprintf(f, "#%d", *oe); if(listOfTrims.NextAfter(oe) != NULL) fprintf(f, ","); } fprintf(f, "));\n"); int fb = id + 1; fprintf(f, "#%d=%s('',#%d,.T.);\n", fb, inner ? "FACE_BOUND" : "FACE_OUTER_BOUND", id); id += 2; listOfTrims.Clear(); return fb; }
void GraphicsWindow::FixConstraintsForPointBeingDeleted(hEntity hpt) { List<hEntity> ld; ZERO(&ld); Constraint *c; SK.constraint.ClearTags(); for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) { if(c->type != Constraint::POINTS_COINCIDENT) continue; if(c->group.v != SS.GW.activeGroup.v) continue; if(c->ptA.v == hpt.v) { ld.Add(&(c->ptB)); c->tag = 1; } if(c->ptB.v == hpt.v) { ld.Add(&(c->ptA)); c->tag = 1; } } // These would get removed anyways when we regenerated, but do it now; // that way subsequent calls of this function (if multiple coincident // points are getting deleted) will work correctly. SK.constraint.RemoveTagged(); // If more than one point was constrained coincident with hpt, then // those two points were implicitly coincident with each other. By // deleting hpt (and all constraints that mention it), we will delete // that relationship. So put it back here now. int i; for(i = 1; i < ld.n; i++) { Constraint::ConstrainCoincident(ld.elem[i-1], ld.elem[i]); } ld.Clear(); }
void XElement::GetIntList(CTSTR lpName, List<int> &IntList) const { assert(lpName); IntList.Clear(); for(DWORD i=0; i<SubItems.Num(); i++) { if(!SubItems[i]->IsData()) continue; XDataItem *item = static_cast<XDataItem*>(SubItems[i]); if(item->strName.CompareI(lpName)) { CTSTR lpValue = item->strData; if( (*LPWORD(lpValue) == 'x0') || (*LPWORD(lpValue) == 'X0') ) { IntList << tstring_base_to_uint(lpValue+2, NULL, 16); } else if(scmpi(lpValue, TEXT("true")) == 0) IntList << 1; else if(scmpi(lpValue, TEXT("false")) == 0) IntList << 0; else IntList << tstring_base_to_uint(lpValue, NULL, 0); } } }
void ClearActions() { for(size_t i = 0; i < actions_.Count(); i++) { delete actions_[i]; } actions_.Clear(); }
void TestSerialization() { Stream stream(L"test.dat", true); List<int> l; l.Add(1); l.Add(2); l.Add(3); l.Serialize(stream); l.Clear(); stream.Close(); stream.Open(L"test.dat"); l.Deserialize(stream); List<Point> b; b.Add(Point(1, 2, 3)); b.Add(Point(4, 5, 6)); b.Add(Point(7, 8, 9)); stream.Close(); stream.Open(L"test.dat", true); b.Serialize(stream); stream.Close(); stream.Open(L"test.dat"); b.Deserialize(stream); }
bool GetVideoOutputTypes(const List<MediaOutputInfo> &outputList, UINT width, UINT height, UINT64 frameInterval, List<VideoOutputType> &types) { types.Clear(); UINT64 closestIntervalDifference = 0xFFFFFFFFFFFFFFFFLL; UINT64 bestFrameInterval = 0; for(UINT i=0; i<outputList.Num(); i++) { MediaOutputInfo &outputInfo = outputList[i]; VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(outputInfo.mediaType->pbFormat); if( outputInfo.minCX <= width && outputInfo.maxCX >= width && outputInfo.minCY <= height && outputInfo.maxCY >= height && outputInfo.minFrameInterval <= frameInterval && outputInfo.maxFrameInterval >= frameInterval) { int priority = inputPriority[(UINT)outputInfo.videoType]; if(priority == -1) continue; types.SafeAdd(outputInfo.videoType); } } return types.Num() != 0; }
bool StringPropertySet::Parse(const StringRef& str) { RETURN_TRUE_IF_EMPTY(str); //Key=Value,... List<StringRef> outPairs; StringParser::Split(str, ",", outPairs); List<StringRef> keyValuePair; for (auto& optionPair : outPairs) { keyValuePair.Clear(); StringParser::Split(optionPair, "=", keyValuePair); if (keyValuePair.Count() == 2) { Add(keyValuePair[0], keyValuePair[1]); } else if (keyValuePair.Count() == 1) { Add(keyValuePair[0], HeapString::Empty); } else { Log::FormatError("Invalid attribute str:{} in {}", optionPair.c_str(), str.c_str()); return false; } } return true; }
inline void ClearData() { for(UINT i=0; i<windowData.Num(); i++) windowData[i].strClass.Clear(); windowData.Clear(); adminWindows.Clear(); }
ECode CTextServicesManagerService::FinishSpellCheckerService( /* [in] */ ISpellCheckerSessionListener* listener) { if (!CalledFromValidUser()) { return NOERROR; } if (DBG) { Slogger::D(TAG, "FinishSpellCheckerService"); } { AutoLock lock(mSpellCheckerMapLock); List<AutoPtr<SpellCheckerBindGroup> > removeList; ManagedSpellCheckerBindGroupMapIt it = mSpellCheckerBindGroups.Begin(); for (; it != mSpellCheckerBindGroups.End(); ++it) { AutoPtr<SpellCheckerBindGroup> group = it->mSecond; if (group == NULL) continue; removeList.PushBack(group); } List<AutoPtr<SpellCheckerBindGroup> >::Iterator it2 = removeList.Begin(); for (; it2 != removeList.End(); ++it2) { ((*it2).Get())->RemoveListener(listener); } removeList.Clear(); } return NOERROR; }
static void Parse(const Regex& regexEec, vint order, const WString& electron, vint& notationOrder, WString& notationName, List<ElementElectron>& ecs) { if(order<=2) { notationOrder=0; notationName=L""; } else if(order<=10) { notationOrder=2; notationName=L"[He]"; } else if(order<=18) { notationOrder=10; notationName=L"[Ne]"; } else if(order<=36) { notationOrder=18; notationName=L"[Ar]"; } else if(order<=54) { notationOrder=36; notationName=L"[Kr]"; } else if(order<=86) { notationOrder=54; notationName=L"[Xe]"; } else { notationOrder=86; notationName=L"[Rn]"; } ecs.Clear(); RegexMatch::List matches; regexEec.Search(electron, matches); FOREACH(Ptr<RegexMatch>, match, matches) { ElementElectron ec; ec.level=wtoi(match->Groups()[L"level"].Get(0).Value()); ec.type=match->Groups()[L"type"].Get(0).Value()[0]; ec.count=wtoi(match->Groups()[L"count"].Get(0).Value()); ec.typeOrder=-1; switch(ec.type) { case L's': ec.typeOrder=0; break; case L'p': ec.typeOrder=1; break; case L'd': ec.typeOrder=2; break; case L'f': ec.typeOrder=3; break; } ecs.Add(ec); }
bool FileSystem::Initialize(CoderList readonlyPathCoder, CoderList writablePathCoder, const MemoryByteData& key /*= MemoryByteData::Empty*/) { //read only path StringRef readonlyPath = System::Instance().ReadonlyPath(); IPackage* readonlyDirectoryPackage = new DirectoryPackage(readonlyPath, PackagePriority::App, 0, true); readonlyDirectoryPackage->SetKey(key); readonlyDirectoryPackage->SetFlags(PackageFlags::Readonly); readonlyDirectoryPackage->SetCoders(readonlyPathCoder); readonlyDirectoryPackage->Initialize(); mPackages.Add(readonlyDirectoryPackage); //read only package List<HeapString> outFiles; Directory::GetFiles(readonlyPath, outFiles, true); for (HeapString& file : outFiles) { FileType fileType = FileInfo::ExtractType(file); if (PackageFactory::IsPackage(fileType)) { IPackage* package = PackageFactory::Create(fileType, file, PackagePriority::App, 0); package->SetKey(key); package->Initialize(); mPackages.Add(package); } } //writable path StringRef writablePath = System::Instance().WritablePath(); IPackage* writableDirectoryPackage = new DirectoryPackage(writablePath, PackagePriority::Downloaded, 0, true); writableDirectoryPackage->SetFlags(PackageFlags::None); writableDirectoryPackage->SetCoders(writablePathCoder); writableDirectoryPackage->SetKey(key); writableDirectoryPackage->Initialize(); mPackages.Add(writableDirectoryPackage); //writable package outFiles.Clear(); Directory::GetFiles(writablePath, outFiles, true); for (HeapString& file : outFiles) { FileType fileType = FileInfo::ExtractType(file); if (PackageFactory::IsPackage(fileType)) { IPackage* package = PackageFactory::Create(fileType, file, PackagePriority::Downloaded, 0); package->SetKey(key); package->Initialize(); mPackages.Add(package); } } ReloadTagItems(); ApplyTagHelper(PublishTarget::MatchAll); return true; }
void SBezier::MakePwlInto(SContour *sc, double chordTol) { List<Vector> lv; ZERO(&lv); MakePwlInto(&lv, chordTol); int i; for(i = 0; i < lv.n; i++) { sc->AddPoint(lv.elem[i]); } lv.Clear(); }
void SBezier::MakePwlInto(SEdgeList *sel, double chordTol) { List<Vector> lv; ZERO(&lv); MakePwlInto(&lv, chordTol); int i; for(i = 1; i < lv.n; i++) { sel->AddEdge(lv.elem[i-1], lv.elem[i]); } lv.Clear(); }
void Triangulator::DestroyChibiLoopTree(List<ChibiLoopNode> &LoopNodeList) { for(int i=0; i<LoopNodeList.Num(); i++) { ChibiLoopNode &loopNode = LoopNodeList[i]; if(loopNode.Children.Num()) DestroyChibiLoopTree(loopNode.Children); } LoopNodeList.Clear(); }
void VectorFileWriter::BezierAsPwl(SBezier *sb) { List<Vector> lv; ZERO(&lv); sb->MakePwlInto(&lv, SS.ChordTolMm() / SS.exportScale); int i; for(i = 1; i < lv.n; i++) { SBezier sb = SBezier::From(lv.elem[i-1], lv.elem[i]); Bezier(&sb); } lv.Clear(); }
void Reset() { currentAction_ = NULL; currentPosition_ = 0; currentStep_ = 0; // Remove all computed points in the current step. for(size_t i = 0; i < points_.Count(); i++) { delete points_[i]; } points_.Clear(); }
// tries moving checker from one cell to another (maybe with beats) // returns: NULL if failed, otherwise byte array to be sent to another player byte* Field::TryComplexMove(Cell from, Cell to, byte* prevBuffer) { // correctness checking if (!from.IsGood() || !to.IsGood()) return false; if (!from.IsBlack() || !to.IsBlack()) return false; if (!IsMyChecker(from) || !IsEmptyCell(to)) return false; // once preserve space enought to store info about all possible beats if (!prevBuffer) { if (!(prevBuffer = new byte[packetSize])) return NULL; for (int i = 0; i < packetSize; prevBuffer[i++] = 0); } byte* subResult; // if no beats before checker can simply move if (prevBuffer[0] == 0 && (subResult = TryMove(from, to))) return subResult; // try to beat enemy and land on "to" cell if (subResult = TryBeat(from, to, prevBuffer)) return subResult; // recursively beat enemy checkers List jumps = GetAvailableBeatJumps(from); int before; // for backup for (int i = 0; i < jumps.Count(); i++) { before = strlen(prevBuffer); if (TryBeat(from, *jumps[i], prevBuffer)) { // if we can beat, check for the next beat if (TryComplexMove(*jumps[i], to, prevBuffer)) return prevBuffer; else { // if recursive beats fails, restore backup info Cell beaten((max(from.row, jumps[i]->row) + min(from.row, jumps[i]->row)) / 2, (max(from.column, jumps[i]->column) + min(from.column, jumps[i]->column)) / 2); enemyCheckers.Add(beaten); myCheckers[*jumps[i]]->MoveChecker(from); for (int i = before, len = strlen(prevBuffer); i < len; prevBuffer[i++] = 0); } } } jumps.Clear(); if (!strlen(prevBuffer)) { delete [] prevBuffer; prevBuffer = NULL; } return NULL; }
void XElement::GetElementList(CTSTR lpName, List<XElement*> &Elements) const { Elements.Clear(); for(DWORD i=0; i<SubItems.Num(); i++) { if(!SubItems[i]->IsElement()) continue; XElement *element = static_cast<XElement*>(SubItems[i]); if(!lpName || element->strName.CompareI(lpName)) Elements << element; } }
void SBezier::MakePwlInto(List<SCurvePt> *l, double chordTol) { List<Vector> lv; ZERO(&lv); MakePwlInto(&lv, chordTol); int i; for(i = 0; i < lv.n; i++) { SCurvePt scpt; scpt.tag = 0; scpt.p = lv.elem[i]; scpt.vertex = (i == 0) || (i == (lv.n - 1)); l->Add(&scpt); } lv.Clear(); }
void OBS::GetGlobalSourceNames(List<CTSTR> &globalSourceNames) { globalSourceNames.Clear(); XElement *globals = scenesConfig.GetElement(TEXT("global sources")); if(globals) { UINT numSources = globals->NumElements(); for(UINT i=0; i<numSources; i++) { XElement *sourceElement = globals->GetElementByID(i); globalSourceNames << sourceElement->GetName(); } } }
void CGestureStore::ClearNamedGestures() { HashMap<String, List<IGesture*> *>::Iterator iter = mNamedGestures->Begin(); for (Int32 i=0; iter!=mNamedGestures->End(); ++iter, ++i) { List<IGesture *> *gestures = (iter->mSecond); Int32 count = gestures->GetSize(); for (Int32 j = 0; j < count; j++) { IGesture *gesture=(*gestures)[i]; gesture->Release(); } gestures->Clear(); delete gestures; } mNamedGestures->Clear(); }
int main() { std::vector<std::string> quote; quote.push_back("Knowing others is intelligence;"); quote.push_back("knowing yourself is true wisdom."); quote.push_back("Mastering others is strength;"); quote.push_back("mastering yourself is true power."); quote.push_back("If you realize that you have enough,"); quote.push_back("you are truly rich."); quote.push_back(" "); quote.push_back("-- Lao Tzu, Tao Te Ching \n\n\n"); List lst; for(unsigned i = 0; i < quote.size(); ++i) { lst.PushFront(quote[i]); } std::cout << "\n\nOutputting First list via Default constructor: \n"; lst.Display(); std::cout << "Outputting Second list via Copy Constructor: \n"; List lst2(lst); std::cout << "Made it past display" << std::endl; lst2.Display(); std::cout << "Made it past second lisr" << std::endl; std::cout << "Outputting Third list via Overload Assignment Operator: \n"; List lst3; lst3 = lst2; lst3.Display(); std::cout << "Erasing First List and outputting it: \n"; lst.Clear(); lst.Display(); std::cout << "Outputting Second list to prove deep copy was involved: \n"; lst2.Display(); std::cin.get(); return 0; }
bool MMDeviceAudioSource::GetBuffer(float **buffer, UINT *numFrames, QWORD targetTimestamp) { bool bSuccess = false; outputBuffer.Clear(); if(!bBrokenTimestamp) { while(audioSegments.Num()) { if(audioSegments[0].timestamp < targetTimestamp) { audioSegments[0].audioData.Clear(); audioSegments.Remove(0); } else break; } } if(audioSegments.Num()) { bool bUseSegment = false; AudioSegment &segment = audioSegments[0]; QWORD difference = (segment.timestamp-targetTimestamp); if(bBrokenTimestamp || difference <= 10) { //Log(TEXT("segment.timestamp: %llu, targetTimestamp: %llu"), segment.timestamp, targetTimestamp); outputBuffer.TransferFrom(segment.audioData); audioSegments.Remove(0); bSuccess = true; } } outputBuffer.SetSize(441*2); *buffer = outputBuffer.Array(); *numFrames = outputBuffer.Num()/2; return bSuccess; }
int main() { List lst; lst.PushFront(5); lst.PushBack(-7); lst.PushBack(44); lst.PushFront(-9); std::cout << "List size is: " << lst.Size() << std::endl; lst.Display(std::cout); lst.Clear(); std::cout << "\nList size is: " << lst.Size() << std::endl; lst.Display(std::cout); return 0; }
ECode CTextServicesManagerService::SpellCheckerBindGroup::RemoveListener( /* [in] */ ISpellCheckerSessionListener* listener) { /*if (CTextServicesManagerService::DBG) { Slogger::W(TAG, "remove listener: " + listener.hashCode()); }*/ { AutoLock lock(mOwner->mSpellCheckerMapLock); List<AutoPtr<InternalDeathRecipient> > removeList; ManagedInternalDeathRecipientListIt it = mListeners.Begin(); for (; it != mListeners.End(); ++it) { AutoPtr<InternalDeathRecipient> tempRecipient = (*it); if(tempRecipient->HasSpellCheckerListener(listener)) { if (CTextServicesManagerService::DBG) { Slogger::W(TAG, "found existing listener."); } removeList.PushBack(tempRecipient); } } ManagedInternalDeathRecipientListIt it2 = removeList.Begin(); for (Int32 i = 0; it2 != removeList.End(); ++it2, ++i) { if (CTextServicesManagerService::DBG) { Slogger::W(TAG, "SpellCheckerBindGroup::RemoveListener Remove %d", i); } AutoPtr<InternalDeathRecipient> idr = (*it2); AutoPtr<IProxy> proxy = (IProxy*)idr->mScListener->Probe(EIID_IProxy); if (proxy != NULL) { Boolean result; proxy->UnlinkToDeath(idr, 0, &result); } mListeners.Remove(idr); } CleanLocked(); removeList.Clear(); } return NOERROR; }
void Entity::GenerateEdges(SEdgeList *el, bool includingConstruction) { if(construction && !includingConstruction) return; SBezierList sbl; ZERO(&sbl); GenerateBezierCurves(&sbl); int i, j; for(i = 0; i < sbl.l.n; i++) { SBezier *sb = &(sbl.l.elem[i]); List<Vector> lv; ZERO(&lv); sb->MakePwlInto(&lv); for(j = 1; j < lv.n; j++) { el->AddEdge(lv.elem[j-1], lv.elem[j], style.v); } lv.Clear(); } sbl.Clear(); }
bool ScriptModule::NewObjects(StringRef className, size_t count, List<ScriptObject*>& outObjects) { outObjects.Clear(); asIObjectType* scriptObjectType = mScriptModule->GetObjectTypeByName(className.c_str()); RETURN_FALSE_IF_NULL(scriptObjectType); HeapString factoryName = className; factoryName += "@ "; factoryName += className; factoryName += "()"; asIScriptFunction* factory = scriptObjectType->GetFactoryByDecl(factoryName.c_str()); RETURN_FALSE_IF_NULL(factory); asIScriptContext* context = ScriptEngine::Instance().GetScriptContext(); List<ScriptObject*> result; FOR_EACH_SIZE(i, count) { context->Prepare(factory); context->Execute(); asIScriptObject* scriptObject = *(asIScriptObject**)context->GetAddressOfReturnValue(); ScriptObject* temp = new ScriptObject(scriptObject); outObjects.Add(temp); }
void Slvs_Solve(Slvs_System *ssys, Slvs_hGroup shg) { if(!IsInit) { InitHeaps(); IsInit = 1; } int i; for(i = 0; i < ssys->params; i++) { Slvs_Param *sp = &(ssys->param[i]); Param p; ZERO(&p); p.h.v = sp->h; p.val = sp->val; SK.param.Add(&p); if(sp->group == shg) { SYS.param.Add(&p); } } for(i = 0; i < ssys->entities; i++) { Slvs_Entity *se = &(ssys->entity[i]); EntityBase e; ZERO(&e); switch(se->type) { case SLVS_E_POINT_IN_3D: e.type = Entity::POINT_IN_3D; break; case SLVS_E_POINT_IN_2D: e.type = Entity::POINT_IN_2D; break; case SLVS_E_NORMAL_IN_3D: e.type = Entity::NORMAL_IN_3D; break; case SLVS_E_NORMAL_IN_2D: e.type = Entity::NORMAL_IN_2D; break; case SLVS_E_DISTANCE: e.type = Entity::DISTANCE; break; case SLVS_E_WORKPLANE: e.type = Entity::WORKPLANE; break; case SLVS_E_LINE_SEGMENT: e.type = Entity::LINE_SEGMENT; break; case SLVS_E_CUBIC: e.type = Entity::CUBIC; break; case SLVS_E_CIRCLE: e.type = Entity::CIRCLE; break; case SLVS_E_ARC_OF_CIRCLE: e.type = Entity::ARC_OF_CIRCLE; break; default: dbp("bad entity type %d", se->type); return; } e.h.v = se->h; e.group.v = se->group; e.workplane.v = se->wrkpl; e.point[0].v = se->point[0]; e.point[1].v = se->point[1]; e.point[2].v = se->point[2]; e.point[3].v = se->point[3]; e.normal.v = se->normal; e.distance.v = se->distance; e.param[0].v = se->param[0]; e.param[1].v = se->param[1]; e.param[2].v = se->param[2]; e.param[3].v = se->param[3]; SK.entity.Add(&e); } for(i = 0; i < ssys->constraints; i++) { Slvs_Constraint *sc = &(ssys->constraint[i]); ConstraintBase c; ZERO(&c); int t; switch(sc->type) { case SLVS_C_POINTS_COINCIDENT: t = Constraint::POINTS_COINCIDENT; break; case SLVS_C_PT_PT_DISTANCE: t = Constraint::PT_PT_DISTANCE; break; case SLVS_C_PT_PLANE_DISTANCE: t = Constraint::PT_PLANE_DISTANCE; break; case SLVS_C_PT_LINE_DISTANCE: t = Constraint::PT_LINE_DISTANCE; break; case SLVS_C_PT_FACE_DISTANCE: t = Constraint::PT_FACE_DISTANCE; break; case SLVS_C_PT_IN_PLANE: t = Constraint::PT_IN_PLANE; break; case SLVS_C_PT_ON_LINE: t = Constraint::PT_ON_LINE; break; case SLVS_C_PT_ON_FACE: t = Constraint::PT_ON_FACE; break; case SLVS_C_EQUAL_LENGTH_LINES: t = Constraint::EQUAL_LENGTH_LINES; break; case SLVS_C_LENGTH_RATIO: t = Constraint::LENGTH_RATIO; break; case SLVS_C_EQ_LEN_PT_LINE_D: t = Constraint::EQ_LEN_PT_LINE_D; break; case SLVS_C_EQ_PT_LN_DISTANCES: t = Constraint::EQ_PT_LN_DISTANCES; break; case SLVS_C_EQUAL_ANGLE: t = Constraint::EQUAL_ANGLE; break; case SLVS_C_EQUAL_LINE_ARC_LEN: t = Constraint::EQUAL_LINE_ARC_LEN; break; case SLVS_C_SYMMETRIC: t = Constraint::SYMMETRIC; break; case SLVS_C_SYMMETRIC_HORIZ: t = Constraint::SYMMETRIC_HORIZ; break; case SLVS_C_SYMMETRIC_VERT: t = Constraint::SYMMETRIC_VERT; break; case SLVS_C_SYMMETRIC_LINE: t = Constraint::SYMMETRIC_LINE; break; case SLVS_C_AT_MIDPOINT: t = Constraint::AT_MIDPOINT; break; case SLVS_C_HORIZONTAL: t = Constraint::HORIZONTAL; break; case SLVS_C_VERTICAL: t = Constraint::VERTICAL; break; case SLVS_C_DIAMETER: t = Constraint::DIAMETER; break; case SLVS_C_PT_ON_CIRCLE: t = Constraint::PT_ON_CIRCLE; break; case SLVS_C_SAME_ORIENTATION: t = Constraint::SAME_ORIENTATION; break; case SLVS_C_ANGLE: t = Constraint::ANGLE; break; case SLVS_C_PARALLEL: t = Constraint::PARALLEL; break; case SLVS_C_PERPENDICULAR: t = Constraint::PERPENDICULAR; break; case SLVS_C_ARC_LINE_TANGENT: t = Constraint::ARC_LINE_TANGENT; break; case SLVS_C_CUBIC_LINE_TANGENT: t = Constraint::CUBIC_LINE_TANGENT; break; case SLVS_C_EQUAL_RADIUS: t = Constraint::EQUAL_RADIUS; break; case SLVS_C_PROJ_PT_DISTANCE: t = Constraint::PROJ_PT_DISTANCE; break; case SLVS_C_WHERE_DRAGGED: t = Constraint::WHERE_DRAGGED; break; case SLVS_C_CURVE_CURVE_TANGENT:t = Constraint::CURVE_CURVE_TANGENT; break; default: dbp("bad constraint type %d", sc->type); return; } c.type = t; c.h.v = sc->h; c.group.v = sc->group; c.workplane.v = sc->wrkpl; c.valA = sc->valA; c.ptA.v = sc->ptA; c.ptB.v = sc->ptB; c.entityA.v = sc->entityA; c.entityB.v = sc->entityB; c.entityC.v = sc->entityC; c.entityD.v = sc->entityD; c.other = (sc->other) ? true : false; c.other2 = (sc->other2) ? true : false; SK.constraint.Add(&c); } for(i = 0; i < (int)arraylen(ssys->dragged); i++) { if(ssys->dragged[i]) { hParam hp = { ssys->dragged[i] }; SYS.dragged.Add(&hp); } } Group g; ZERO(&g); g.h.v = shg; List<hConstraint> bad; ZERO(&bad); // Now we're finally ready to solve! bool andFindBad = ssys->calculateFaileds ? true : false; int how = SYS.Solve(&g, &(ssys->dof), &bad, andFindBad, false); switch(how) { case System::SOLVED_OKAY: ssys->result = SLVS_RESULT_OKAY; break; case System::DIDNT_CONVERGE: ssys->result = SLVS_RESULT_DIDNT_CONVERGE; break; case System::SINGULAR_JACOBIAN: ssys->result = SLVS_RESULT_INCONSISTENT; break; case System::TOO_MANY_UNKNOWNS: ssys->result = SLVS_RESULT_TOO_MANY_UNKNOWNS; break; default: oops(); } // Write the new parameter values back to our caller. for(i = 0; i < ssys->params; i++) { Slvs_Param *sp = &(ssys->param[i]); hParam hp = { sp->h }; sp->val = SK.GetParam(hp)->val; } if(ssys->failed) { // Copy over any the list of problematic constraints. for(i = 0; i < ssys->faileds && i < bad.n; i++) { ssys->failed[i] = bad.elem[i].v; } ssys->faileds = bad.n; } bad.Clear(); SYS.param.Clear(); SYS.entity.Clear(); SYS.eq.Clear(); SYS.dragged.Clear(); SK.param.Clear(); SK.entity.Clear(); SK.constraint.Clear(); FreeAllTemporary(); }
inline void FreeData() {bones.Clear(); tris.Clear();}