Exemplo n.º 1
0
/**
 * Try to reserve a SECOND NEXT BLOCK if the train does not have to wait in the next block.
 *
 * @param inst      LcDriver instance
 * @param gotoBlock goto block ID
 */
void reserveSecondNextBlock( iOLcDriver inst, const char* gotoBlock, iIBlockBase fromBlock,
    iORoute fromRoute, iIBlockBase* toBlock, iORoute* toRoute, Boolean reverse, Boolean swapNext1Route ) {
  iOLcDriverData data = Data(inst);

  iORoute     nextRoute = NULL;
  iIBlockBase nextBlock = NULL;
  Boolean     fromto    = False;
  int         indelay   = 0;
  Boolean     oppwait   = True;

  /*Boolean direction = fromRoute->getDirection( fromRoute, fromBlock->getId(fromBlock), &fromto );*/
  /* TODO: use the right direction for finding the next block in the same direction */

  if( !fromBlock->wait( fromBlock, data->loc, reverse, &oppwait ) &&
      !fromBlock->isTerminalStation(fromBlock)  && data->run && !data->reqstop )
  {
    TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 4204,
                   "finding a second next block for [%s]", data->loc->getId( data->loc ) );

    if( data->schedule == NULL || StrOp.len( data->schedule ) == 0 ) {
      nextRoute = NULL;
      nextBlock = data->model->findDest( data->model, fromBlock->base.id(fromBlock), fromRoute->base.id(fromRoute),
                                         data->loc, &nextRoute, gotoBlock,
                                         fromRoute->isSwapPost( fromRoute ) ^ swapNext1Route, False, False, True );
    }
    else {
      /* find destination using schedule */
      int scheduleIdx = data->scheduleIdx;

      /* TODO: force same direction */
      nextRoute = data->model->calcRouteFromCurBlock( data->model,
          (iOList)NULL, data->schedule, &scheduleIdx,
          fromBlock->base.id(fromBlock), fromRoute->base.id(fromRoute), data->loc, fromRoute->isSwapPost( fromRoute ), &indelay, True );

      if( nextRoute != NULL ) {
        /* evaluate direction */
        if( StrOp.equals( nextRoute->getToBlock( nextRoute ), fromBlock->base.id(fromBlock) ) )
          nextBlock = data->model->getBlock( data->model, nextRoute->getFromBlock( nextRoute ) );
        else
          nextBlock = data->model->getBlock( data->model, nextRoute->getToBlock( nextRoute ) );
      }
    }

    if( nextBlock != NULL && nextRoute != NULL ) {
      if( data->curBlock == nextBlock || data->next1Block == nextBlock || data->next2Block == nextBlock || data->next3Block == nextBlock ) {
        TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 4204,
                       "ignoring second next block [%s] for [%s] because it is already reserved",
                       nextBlock->base.id(nextBlock), data->loc->getId( data->loc ) );
        nextBlock = NULL;
        *toBlock = NULL;
        *toRoute = NULL;
      }
    }

    if( nextBlock != NULL && nextRoute != NULL ) {
      Boolean fromto = True;
      TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 4204,
                   "second next block/route for [%s] is [%s]/[%s]",
                   data->loc->getId( data->loc ),
                   nextBlock->base.id(nextBlock), nextRoute->getId(nextRoute) );

      nextRoute->getDirection( nextRoute, fromBlock->base.id(fromBlock), &fromto );
      /* lock second next destination */
      if( initializeGroup( inst, nextBlock, NULL ) &&
          nextBlock->lock( nextBlock, data->loc->getId( data->loc ), fromBlock->base.id(fromBlock), nextRoute->base.id(nextRoute), False, True, !fromto, indelay, NULL, False ) )
      {
        if( nextRoute->lock( nextRoute, data->loc->getId( data->loc ), !fromto, True ) ) {
          *toBlock = nextBlock;
          *toRoute = nextRoute;
          /* TODO: test if this will not hold other actions... */
          /* TODO: check if the destination is the same before fire a go command for the street */
          nextRoute->go(nextRoute);
        }
        else {
          nextBlock->unLock( nextBlock, data->loc->getId( data->loc ), NULL );
          *toBlock = NULL;
          *toRoute = NULL;
          TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 4204,
                       "could not lock [%s]/[%s] for [%s]",
                       nextBlock->base.id(nextBlock), nextRoute->getId(nextRoute),
                       data->loc->getId( data->loc ) );
        }
      }

    }

  }
  else {
    TraceOp.trc( name, TRCLEVEL_USER1, __LINE__, 4204,
                 "second next block: wait in next block for [%s]", data->loc->getId( data->loc ) );
  }

}
Exemplo n.º 2
0
void ParameteredGroupObject::initialize()
{
	ParameteredObject::initialize();

	if(_inputs)
	{
		std::vector<VirtualInputSlot*> vinput=_inputs->getSlotVector();
		for(size_t i=0;i<vinput.size();i++)
		{
			VirtualInputSlot* in=vinput[i];
			_removeInputSlot(in->getName());
			Parameter<int> *par=_loopOutputNumber[i];
			_removeSomething("parameters",par->getName());
			delete par;
			breakLoop(i);
		}
	}
	_loopOutputNumber.clear();

	if(_outputs)
	{
		std::vector<VirtualOutputSlot*> voutput=_outputs->getSlotVector();
		for(size_t i=0;i<voutput.size();i++)
		{
			VirtualOutputSlot* out=voutput[i];
			_removeOutputSlot(out->getName());
		}
	}

	_inputs=0;
	_outputs=0;
	if (_pluginMan!=0) {
		_pluginMan->reset();
		delete _pluginMan;
		_pluginMan = 0;
	}

	_pluginMan = new PluginManager(pluginPaths(),debugSuffix());
	_pluginMan->loadParameterFile(workFlowFile());
	const std::map<std::string, ParameteredObject*>& objs=_pluginMan->getObjectList();

	std::map<std::string, ParameteredObject *>::const_iterator it=objs.begin();
	for(;it!=objs.end();it++)
	{
		ParameteredObject* obj=it->second;
		InputSlotBundleIntf* tinputs=dynamic_cast<InputSlotBundleIntf*>(obj);
		OutputSlotBundleIntf* toutputs=dynamic_cast<OutputSlotBundleIntf*>(obj);
		if(tinputs)
			_inputs=tinputs;
		if(toutputs)
			_outputs=toutputs;
	}

	if(_inputs)
	{
		std::vector<VirtualInputSlot*> vinput=_inputs->getSlotVector();
		for(size_t i=0;i<vinput.size();i++)
		{
			VirtualInputSlot* in=vinput[i];
            onAddInputSlot(in);
			Parameter<int> *par=new Parameter<int>(-1);
			std::stringstream pname;
			pname<<"loop_input_"<<i<<"_to_output";
			std::stringstream pdoc;
			pdoc<<"The input "<<i<<" gets the data of the given output after one iteration of a loop. To disable the connection, set to -1";
			_addParameter(*par,pname.str(),pdoc.str(),"int");
			_loopOutputNumber.push_back(par);
		}
	}
	if(_outputs)
	{
		std::vector<VirtualOutputSlot*> voutput=_outputs->getSlotVector();
		for(size_t i=0;i<voutput.size();i++)
		{
			VirtualOutputSlot* out=voutput[i];
            onAddOutputSlot(out);
		}
	}

	initializeGroup();

	#pragma message ("need to load slotbundle connections")
	//_inputs->loadConnection(ParameterFile(workFlowFile),_pluginMan);
	//_outputs->loadConnection(ParameterFile(workFlowFile),_pluginMan);
}