void StateStack::pushBack(DynamicState * state) { if (!isStart()) return; //Õ»ÒѾÔËÐеÄÇé¿öÏÂÐèÒª¶ÔÕ»¶¥×´Ì¬½øÐÐÅųâ(+1) if (isRunning()) topExclusion(); _stack.push(state); //ջֹͣ״̬ÏÂÕ»¶¥½øÐÐÅųâ(+1) if (!isRunning()) topExclusion(); }
void StateStack::popBack() { if (!isStart()) return; if (_stack.size() > 0) { //ջֹͣµÄÇé¿öϽâ³ýÕ»¶¥Åųâ(-1) if (!isRunning()) topUnExclusion(); _stack.pop(); } //Õ»ÔËÐÐÇé¿öÏÂÕ»¶¥½Ó´¥Åųâ(-1) if (isRunning()) topUnExclusion(); }
DECLARE_EXPORT LoadPlan::~LoadPlan() { getResource()->setChanged(); LoadPlan *prevldplan = NULL; if (!isStart() && oper->getOperation() == OperationSetup::setupoperation) { for (TimeLine<LoadPlan>::const_iterator i = getResource()->getLoadPlans().begin(isStart() ? getOtherLoadPlan() : this); i != getResource()->getLoadPlans().end(); --i) { const LoadPlan *l = dynamic_cast<const LoadPlan*>(&*i); if (l && l->getOperationPlan() != getOperationPlan() && l->getOperationPlan() != getOperationPlan()->getOwner() && !l->isStart()) { prevldplan = const_cast<LoadPlan*>(l); break; } } if (!prevldplan) { for (TimeLine<LoadPlan>::const_iterator i = getResource()->getLoadPlans().begin(isStart() ? getOtherLoadPlan() : this); i != getResource()->getLoadPlans().end(); ++i) { const LoadPlan *l = dynamic_cast<const LoadPlan*>(&*i); if (l && l->getOperationPlan() != getOperationPlan() && l->getOperationPlan() != getOperationPlan()->getOwner() && !l->isStart()) { prevldplan = const_cast<LoadPlan*>(l); break; } } } } getResource()->loadplans.erase(this); if (prevldplan) getResource()->updateSetups(prevldplan); }
DECLARE_EXPORT void LoadPlan::update() { // Update the timeline data structure getResource()->getLoadPlans().update( this, ld->getLoadplanQuantity(this), ld->getLoadplanDate(this) ); // Review adjacent setups if (!isStart()) getResource()->updateSetups(this); // Mark the operation and resource as being changed. This will trigger // the recomputation of their problems getResource()->setChanged(); ld->getOperation()->setChanged(); }
bool WavReader::readBuf(void *pInL, void *pInR, quint32 FrameCount) { int i = 0; float *pL, *pR; QByteArray Buf; int step = wavHeader.channels*(wavHeader.bitsPerSample/8); int End; pL = (float*)pInL; pR = (float*)pInR; sample32 sampL, sampR; Buf = pDevice->read(FrameCount*wavHeader.channels*(wavHeader.bitsPerSample/8)); if(Buf.size() == (int)(FrameCount * step)) { for(i = 0; i < Buf.size(); i += step) { if(wavHeader.bitsPerSample == 16) { sampL.bytes.b0 = 0; sampL.bytes.b1 = 0; sampL.bytes.b2 = Buf.data()[i]; sampL.bytes.b3 = Buf.data()[i+1]; *pL++ = (float)(sampL.all/2147483647.0); sampR.bytes.b0 = 0; sampR.bytes.b1 = 0; sampR.bytes.b2 = Buf.data()[i+2]; sampR.bytes.b3 = Buf.data()[i+3]; *pR++ = (float)(sampR.all/2147483647.0); } else if(wavHeader.bitsPerSample == 24) { sampL.bytes.b0 = 0; sampL.bytes.b1 = Buf.data()[i]; sampL.bytes.b2 = Buf.data()[i+1]; sampL.bytes.b3 = Buf.data()[i+2]; *pL++ = (float)(sampL.all/2147483647.0); sampR.bytes.b0 = 0; sampR.bytes.b1 = Buf.data()[i+3]; sampR.bytes.b2 = Buf.data()[i+4]; sampR.bytes.b3 = Buf.data()[i+5]; *pR++ = (float)(sampR.all/2147483647.0); } else if(wavHeader.bitsPerSample == 32) { sampL.bytes.b0 = Buf.data()[i]; sampL.bytes.b1 = Buf.data()[i+1]; sampL.bytes.b2 = Buf.data()[i+2]; sampL.bytes.b3 = Buf.data()[i+3]; *pL++ = (float)(sampL.all/2147483647.0); sampR.bytes.b0 = Buf.data()[i+4]; sampR.bytes.b1 = Buf.data()[i+5]; sampR.bytes.b2 = Buf.data()[i+6]; sampR.bytes.b3 = Buf.data()[i+7]; *pR++ = (float)(sampR.all/2147483647.0); } } } else { for(i = 0; i < Buf.size(); i += step) { if(wavHeader.bitsPerSample == 16) { sampL.bytes.b0 = 0; sampL.bytes.b1 = 0; sampL.bytes.b2 = Buf.data()[i]; sampL.bytes.b3 = Buf.data()[i+1]; *pL++ = (float)(sampL.all/2147483647.0); sampR.bytes.b0 = 0; sampR.bytes.b1 = 0; sampR.bytes.b2 = Buf.data()[i+2]; sampR.bytes.b3 = Buf.data()[i+3]; *pR++ = (float)(sampR.all/2147483647.0); } else if(wavHeader.bitsPerSample == 24) { sampL.bytes.b0 = 0; sampL.bytes.b1 = Buf.data()[i]; sampL.bytes.b2 = Buf.data()[i+1]; sampL.bytes.b3 = Buf.data()[i+2]; *pL++ = (float)(sampL.all/2147483647.0); sampR.bytes.b0 = 0; sampR.bytes.b1 = Buf.data()[i+3]; sampR.bytes.b2 = Buf.data()[i+4]; sampR.bytes.b3 = Buf.data()[i+5]; *pR++ = (float)(sampR.all/2147483647.0); } else if(wavHeader.bitsPerSample == 32) { sampL.bytes.b0 = Buf.data()[i]; sampL.bytes.b1 = Buf.data()[i+1]; sampL.bytes.b2 = Buf.data()[i+2]; sampL.bytes.b3 = Buf.data()[i+3]; *pL++ = (float)(sampL.all/2147483647.0); sampR.bytes.b0 = Buf.data()[i+4]; sampR.bytes.b1 = Buf.data()[i+5]; sampR.bytes.b2 = Buf.data()[i+6]; sampR.bytes.b3 = Buf.data()[i+7]; *pR++ = (float)(sampR.all/2147483647.0); } } pDevice->seek(startPos); End = (FrameCount*wavHeader.channels*(wavHeader.bitsPerSample/8)) - Buf.size(); Buf = pDevice->read(End); if(loop) { while(i < End) { if(wavHeader.bitsPerSample == 16) { sampL.bytes.b0 = 0; sampL.bytes.b1 = 0; sampL.bytes.b2 = Buf.data()[i]; sampL.bytes.b3 = Buf.data()[i+1]; *pL++ = (float)(sampL.all/2147483647.0); sampR.bytes.b0 = 0; sampR.bytes.b1 = 0; sampR.bytes.b2 = Buf.data()[i+2]; sampR.bytes.b3 = Buf.data()[i+3]; *pR++ = (float)(sampR.all/2147483647.0); } else if(wavHeader.bitsPerSample == 24) { sampL.bytes.b0 = 0; sampL.bytes.b1 = Buf.data()[i]; sampL.bytes.b2 = Buf.data()[i+1]; sampL.bytes.b3 = Buf.data()[i+2]; *pL++ = (float)(sampL.all/2147483647.0); sampR.bytes.b0 = 0; sampR.bytes.b1 = Buf.data()[i+3]; sampR.bytes.b2 = Buf.data()[i+4]; sampR.bytes.b3 = Buf.data()[i+5]; *pR++ = (float)(sampR.all/2147483647.0); } else if(wavHeader.bitsPerSample == 32) { sampL.bytes.b0 = Buf.data()[i]; sampL.bytes.b1 = Buf.data()[i+1]; sampL.bytes.b2 = Buf.data()[i+2]; sampL.bytes.b3 = Buf.data()[i+3]; *pL++ = (float)(sampL.all/2147483647.0); sampR.bytes.b0 = Buf.data()[i+4]; sampR.bytes.b1 = Buf.data()[i+5]; sampR.bytes.b2 = Buf.data()[i+6]; sampR.bytes.b3 = Buf.data()[i+7]; *pR++ = (float)(sampR.all/2147483647.0); } i += step; } } else { while(i < End) { *pL++ = 0.0; *pR++ = 0.0; i += step; } emit isStart(false); } } return true; }
void AStarSearch::getRoute(MineMap* m, Point &start, Point &dest, list<Point> &route, TCheckFunction checkFunc, char* forbidCells) { list<Node>* frontier = new list<Node>(); if (lookupField == NULL) this->initLookupField(m->GetWidth(), m->GetHeight()); else this->eraseLookupField(); //Destination Node d = Node(dest.x, dest.y); //Start position Node s = Node(start.x, start.y); //Initialization s.heuristic = this->getManhattenDistance(s, d); d.heuristic = 0; //Add neighbors for start node this->addPossibleNeighbors(m, s, d, *frontier, checkFunc, forbidCells); lookupField[s.y][s.x] = s; lookupField[s.y][s.x].isDiscovered = true; bool frontierChanged = true; bool success = false; int prevSize = -1; int i = 0; while (frontier->size() && (frontierChanged)) { Node n = getOptimalNode(*frontier); if (!isDestination(n, d)) { prevSize = frontier->size(); //into frontier add possible neighbours bool isAdded = addPossibleNeighbors(m, n, d, *frontier, checkFunc, forbidCells); this->removeNodeFromFrontier(n, *frontier); bool isSizeChanged = prevSize != frontier->size(); frontierChanged = isAdded || isSizeChanged; } else { //We found our goal! d.cost = n.cost; d.heuristic = n.heuristic; d.father_x = n.father_x; d.father_y = n.father_y; success = true; break; } } if (success) { Node tmp = d; //Reconstructing path while(!isStart(tmp, s)) { route.push_front(Point(tmp.x, tmp.y)); tmp = lookupField[tmp.father_y][tmp.father_x]; } } frontier->clear(); delete frontier; }
DECLARE_EXPORT void LoadPlan::setResource(Resource* newres, bool check) { // Nothing to do if (res == newres) return; // Validate the argument if (!newres) throw DataException("Can't switch to NULL resource"); if (check) { // New resource must be a subresource of the load's resource. bool ok = false; for (const Resource* i = newres; i && !ok; i = i->getOwner()) if (i == getLoad()->getResource()) ok = true; if (!ok) throw DataException("Resource isn't matching the resource specified on the load"); // New resource must have the required skill if (getLoad()->getSkill()) { ok = false; for(Resource::skilllist::const_iterator s = newres->getSkills().begin(); s != newres->getSkills().end() && !ok; s++) if (s->getSkill() == getLoad()->getSkill()) ok = true; if (!ok) throw DataException("Resource misses the skill specified on the load"); } } // Mark entities as changed if (oper) oper->getOperation()->setChanged(); if (res && res!=newres) res->setChanged(); newres->setChanged(); // Update also the setup operationplans if (oper && oper->getOperation() != OperationSetup::setupoperation) { bool oldHasSetup = ld && !ld->getSetup().empty() // TODO not fully correct. If the load is changed, it is still possible that the old load had a setup, while ld doesn't have one any more... && res && res->getSetupMatrix(); bool newHasSetup = ld && !ld->getSetup().empty() && newres->getSetupMatrix(); OperationPlan *setupOpplan = NULL; if (oldHasSetup) { for (OperationPlan::iterator i(oper); i != oper->end(); ++i) if (i->getOperation() == OperationSetup::setupoperation) { setupOpplan = &*i; break; } if (!setupOpplan) oldHasSetup = false; } if (oldHasSetup) { if (newHasSetup) { // Case 1: Both the old and new load require a setup LoadPlan *setupLdplan = NULL; for (OperationPlan::LoadPlanIterator j = setupOpplan->beginLoadPlans(); j != setupOpplan->endLoadPlans(); ++j) if (j->getLoad() == ld) { setupLdplan = &*j; break; } if (!setupLdplan) throw LogicException("Can't find loadplan on setup operationplan"); // Update the loadplan setupOpplan->setEnd(setupOpplan->getDates().getEnd()); } else { // Case 2: Delete the old setup which is not required any more oper->eraseSubOperationPlan(setupOpplan); } } else { if (newHasSetup) { // Case 3: Create a new setup operationplan OperationSetup::setupoperation->createOperationPlan( 1, Date::infinitePast, oper->getDates().getEnd(), NULL, oper); } //else: // Case 4: No setup for the old or new load } } // Find the loadplan before the setup LoadPlan *prevldplan = NULL; if (getOperationPlan()->getOperation() == OperationSetup::setupoperation) { for (TimeLine<LoadPlan>::const_iterator i = getResource()->getLoadPlans().begin(isStart() ? getOtherLoadPlan() : this); i != getResource()->getLoadPlans().end(); --i) { const LoadPlan *l = dynamic_cast<const LoadPlan*>(&*i); if (l && l->getOperationPlan() != getOperationPlan() && l->getOperationPlan() != getOperationPlan()->getOwner() && !l->isStart()) { prevldplan = const_cast<LoadPlan*>(l); break; } } if (!prevldplan) { for (TimeLine<LoadPlan>::const_iterator i = getResource()->getLoadPlans().begin(isStart() ? getOtherLoadPlan() : this); i != getResource()->getLoadPlans().end(); ++i) { const LoadPlan *l = dynamic_cast<const LoadPlan*>(&*i); if (l && l->getOperationPlan() != getOperationPlan() && l->getOperationPlan() != getOperationPlan()->getOwner() && !l->isStart()) { prevldplan = const_cast<LoadPlan*>(l); break; } } } } // Change this loadplan and its brother for (LoadPlan *ldplan = getOtherLoadPlan(); true; ) { // Remove from the old resource, if there is one if (res) { res->loadplans.erase(ldplan); res->setChanged(); } // Insert in the new resource. // This code assumes the date and quantity of the loadplan don't change // when a new resource is assigned. ldplan->res = newres; newres->loadplans.insert( ldplan, ld->getLoadplanQuantity(ldplan), ld->getLoadplanDate(ldplan) ); // Repeat for the brother loadplan or exit if (ldplan != this) ldplan = this; else break; } // Update the setups on the old resource if (prevldplan) prevldplan->res->updateSetups(prevldplan); // Change the resource newres->setChanged(); }