예제 #1
0
model* addConnect(model* _model, listModel* _listModel, char* _c1, char* _c2) {
  model* tmp = NULL;
  if(_model == NULL) {
    tmp = malloc(sizeof(model));
    tmp->attr = NULL;
    tmp->eq = NULL;
  } else {
    tmp = _model;
  }

  char* c1_token = strtok(_c1, ".");
  char* typeTmp1;
  attrModel* attrTmp1;
  model* modelTmp1 = tmp;
  while(c1_token != NULL) {
    attrTmp1 = findAttrModel(modelTmp1->attr, c1_token);
    typeTmp1 = attrTmp1->typeModel;
    modelTmp1 = findModel(_listModel, typeTmp1);
    c1_token = strtok(NULL, ".");
  }

  char* c2_token = strtok(_c2, ".");
  char* typeTmp2;
  attrModel* attrTmp2;
  model* modelTmp2 = tmp;
  while(c2_token != NULL) {
    attrTmp2 = findAttrModel(modelTmp2->attr, c2_token);
    typeTmp2 = attrTmp2->typeModel;
    modelTmp2 = findModel(_listModel, typeTmp2);
    c2_token = strtok(NULL, ".");
  }

  if(strcmp(typeTmp1, typeTmp2) != 0) {
    printf("Error : type are not the same\n");
    return NULL;
  }

  listAttrModel* listAttrTmp = modelTmp1->attr;
  char* stringTmp1;
  char* stringTmp2;

  while(listAttrTmp != NULL) {
    stringTmp1 = malloc(sizeof(_c1) + sizeof(char) + sizeof(listAttrTmp->attr->name));
    stringTmp2 = malloc(sizeof(_c2) + sizeof(char) + sizeof(listAttrTmp->attr->name));
    sprintf(stringTmp1, "%s.%s", _c1, listAttrTmp->attr->name);
    sprintf(stringTmp2, "%s.%s", _c2, listAttrTmp->attr->name);
    if(listAttrTmp->attr->flow == 1) {
      tmp = addEq(tmp, _listModel, makeEq(NULL, makeEq(NULL, makeEq(stringTmp1, NULL, '.', NULL), '+', makeEq(stringTmp2, NULL, '.', NULL)), '=', makeEq("0", NULL, '.', NULL)));
    } else {
      tmp = addEq(tmp, _listModel, makeEq(NULL, makeEq(stringTmp1, NULL, '.', NULL), '=', makeEq(stringTmp2, NULL, '.', NULL)));
    }
    listAttrTmp = listAttrTmp->next;
  }

  return tmp;
}
예제 #2
0
//------------------------------------------------------------------------------
// mapPlayers2ElevTable() - Map the player list to the model table
//------------------------------------------------------------------------------
void Otw::mapPlayers2ElevTable()
{
   // Set all entries as unciecked
   for (unsigned int i = 0; i < getElevationTableSize(); i++) {
      hotTbl[i]->setCheckedFlag(false);
   }

   // When we have a player list ...
   if (playerList != 0) {

      // ---
      // Find players that are alive and require terrain elevation from the visual system ...
      // ---
      Basic::List::Item* item = playerList->getFirstItem();
      while (item != 0) {

         // Get a pointer to the player, 'p'
         Basic::Pair* pair = dynamic_cast<Basic::Pair*>(item->getValue());
         Player* p = (Player*) pair->object();

         // Check if this player is alive and within range.
         if ( p->isActive() && p->isTerrainElevationRequired() ) {

            // Check if in-range
            bool inRange = computeRangeToPlayer(p) <= maxRange;
            
            if (inRange) {
            
               // Find the player's model entry (if any)
               OtwModel* model = findModel(p, HOT_TABLE);

               if (model != 0) {
                  // The player has a valid entry.
                  model->incReqCount();
               }
               else {
                  // Player doesn't have an entry, so create one.
                  model = newElevEntry(p);
               }
               if (model != 0) model->setCheckedFlag(true);
            }

         }

         //completed  = p->isNetworkedPlayer();
         item = item->getNext(); // Next player
      }
   }

   // ---
   // Remove unmatched model entries; their players are inactive or no longer
   // require terrain elevation
   // ---
   for (int i = getElevationTableSize(); i > 0; --i) {
      if ( hotTbl[i-1]->isNotChecked() ) {
         // Deleting this entry
         removeModelFromList( (i-1), HOT_TABLE);
      }
   }
}
예제 #3
0
void GraphicalArrayTest::test_removeItems()
{
  GraphicalArray * value = new GraphicalArray();
  QPushButton * button = findRemoveButton(value);
  QStringListModel * model = findModel(value);
  QListView * view = findListView(value);
  QItemSelectionModel::SelectionFlags flag = QItemSelectionModel::Select;

  model->setStringList( QStringList() << "Hello" << "World" << "and" << "Happy" << "New" << "Year!" );
  value->show();

  view->selectionModel()->select( model->index(0), flag ); // select "Hello"
  view->selectionModel()->select( model->index(1), flag ); // select "World"
  view->selectionModel()->select( model->index(3), flag ); // select "Happy"
  view->selectionModel()->select( model->index(5), flag ); // select "Year"

  // simulate a click on the 'Remove' button
  QTest::mouseClick( button, Qt::LeftButton );

  QStringList values = model->stringList();

  QCOMPARE( values.count(), 2 );
  QCOMPARE( values.at(0), QString("and") );
  QCOMPARE( values.at(1), QString("New") );

  delete value;
}
예제 #4
0
void GraphicalArrayTest::initTestCase()
{
  GraphicalArray * value = new GraphicalArray();

  QVERIFY( is_not_null( findLineEdit(value) ) );
  QVERIFY( is_not_null( findRemoveButton(value) ) );
  QVERIFY( is_not_null( findListView(value) ) );
  QVERIFY( is_not_null( findModel(value) ) );

  delete value;
}
예제 #5
0
void GraphicalArrayTest::test_signalEmmitting()
{
  GraphicalArray * value = new GraphicalArray();
  QLineEdit * lineEdit = findLineEdit(value);
  QStringListModel * model = findModel(value);
  QSignalSpy spy(value, SIGNAL(valueChanged()));

  //
  // 1. through setValue()
  //
  value->setValue( QString("Hello World") ); // when the value is a string
  value->setValue( QStringList() << "Hello" << "World" ); // when the value is a string list
  value->setValue( 42 ); // when the value is not valid (so signal emitted)

  // 2 signals should have been emitted
  QCOMPARE( spy.count(), 2 );

  spy.clear();

  // clear the model
  model->setStringList( QStringList() );

  //
  // 2. by simulating keyboard events
  //
  // note: when validating, we wait 25 ms (last parameter) to let the event being processed
//  lineEdit->clear();
//  value->show(); // make the value visible (it ignores keyboard events if not)
//  lineEdit->setFocus(Qt::PopupFocusReason);
//  QTest::keyClicks(lineEdit, "123" );
//  QTest::keyClick(value, Qt::Key_Enter, Qt::NoModifier); // validate by pressing the 'ENTER' key on the keypad
//  QTest::keyClicks(lineEdit, "156" );
//  QTest::keyClicks(lineEdit, "456" );
//  QTest::keyClick(value, Qt::Key_Return, Qt::NoModifier); // validate by pressing the 'Return' key

  // 2 signals should have been emitted (one per validation)
//  QCOMPARE( spy.count(), 2 );

//  QCOMPARE( model->stringList(), QStringList() << "123" << "156456");
//  QCOMPARE( lineEdit->text(), QString() );

  spy.clear();
  //
  // 3. when committing
  //
  value->commit();

  // 1 signal should have been emitted
  QCOMPARE( spy.count(), 1 );

  delete value;
}
예제 #6
0
CSMFModel *CModelManager::registerSMFModel(const std::string fname){
    CModel *found = findModel(fname);
    if(found)return static_cast<CSMFModel*>(found);

    gcon.printString("Loading SMF model " + fname + "\n");

	CSMFModelPtr model = new CSMFModel(this);
    
    model->load(fname, CEngine::getSingleton()->vfs);

    registerModel(model);

    return model;
}
예제 #7
0
OtwModel* Otw::findModel(const Player* const player, const TableType type)
{
   OtwModel* found = 0;
   if (player != 0) {
      // Get the player's IDs
      const Basic::String* fName = 0;
      if (player->isNetworkedPlayer()) {
         // If networked, used original IDs
         const Nib* pNib = player->getNib();
         fName = pNib->getFederateName();
      }
      // Now find the model using the player's IDs
      found = findModel(player->getID(), fName, type);
   }
   return found;
}
예제 #8
0
OtwModel* Otw::findModel(const simulation::AbstractPlayer* const player, const TableType type)
{
   OtwModel* found = nullptr;
   if (player != nullptr) {
      // Get the player's IDs
      const base::String* fName = nullptr;
      if (player->isNetworkedPlayer()) {
         // If networked, used original IDs
         const simulation::AbstractNib* pNib = player->getNib();
         fName = pNib->getFederateName();
      }
      // Now find the model using the player's IDs
      found = findModel(player->getID(), fName, type);
   }
   return found;
}
예제 #9
0
void GraphicalArrayTest::test_setValue()
{
  QString sep(";");
  GraphicalArray * value = new GraphicalArray( new QIntValidator(), sep );
  QLineEdit * lineEdit = findLineEdit(value);
  QStringListModel * model = findModel(value);

  QStringList validList;
  QStringList invalidList;

  validList << "42" << "15465" << "-145314" << "42"; // duplicates should be kept
  invalidList << "25" << "1" << "something" << "32" << "3.14" << "-54789";

  QVERIFY( is_not_null(lineEdit) );

  //
  // 1. check with strings
  //
  // 1a. list that only contains valid values
  QVERIFY( value->setValue( validList.join(sep) ) );
  QCOMPARE( model->stringList(), validList );

  // 1c. only one value
  QVERIFY( value->setValue( QString("1456789") ) );
  QCOMPARE( model->stringList().count(), 1 );
  QCOMPARE( model->stringList().at(0), QString("1456789") );

  // 1b. list that contains some invalid values
  QVERIFY( !value->setValue( invalidList.join(sep) ) );
  QStringList list = model->stringList();

  // "something" and "3.14" are invalid integers and so the value shouldn't have changed
  QCOMPARE( model->stringList().count(), 1 );
  QCOMPARE( model->stringList().at(0), QString("1456789") );

  //
  // 2. check with other types
  //
  QVERIFY( !value->setValue(true) );
  QCOMPARE( model->stringList().at(0), QString("1456789") );

  QVERIFY( !value->setValue(3.145) );
  QCOMPARE( model->stringList().at(0), QString("1456789") );

  delete value;
}
예제 #10
0
CSkelModel *CModelManager::registerSkelModel(const std::string fname){
    CModel *found = findModel(fname);
    if(found)return static_cast<CSkelModel *>(found);

    gcon.printString("Loading skeletal model " + fname + "\n");

    CSkelModelPtr model = new CSkelModel(this);
    
    try {
        model->load(fname, CEngine::getSingleton()->vfs);
	} catch (CException e) {
        CEngine::getSingleton()->con.printString("Failed to load : " + fname + "\n  ");
        CEngine::getSingleton()->con.printString(e.getExplanation() + "\n");
		return 0;
	}

    registerModel(model);

    return model;
}
예제 #11
0
void GraphicalArrayTest::test_value()
{
  GraphicalArray * value = new GraphicalArray();
  QStringListModel * model = findModel(value);
  QStringList stringList;
  QVariant theValue;

  stringList << "hello" << "world" << "!";

  theValue = value->value();
  QVERIFY( theValue.type() == QVariant::StringList );
  QCOMPARE( theValue.toStringList(), QStringList() );

  model->setStringList( stringList );

  theValue = value->value();
  QVERIFY( theValue.type() == QVariant::StringList );
  QCOMPARE( theValue.toStringList(), stringList );

  delete value;
}
예제 #12
0
void GraphicalArrayTest::test_constructor()
{
  GraphicalArray * value = new GraphicalArray();
  QStringListModel * model = findModel(value);

  // 1. value is empty, the line edit should be empty as well
  QVERIFY( is_not_null(model) );
  QVERIFY( model->stringList().empty() );

  delete value;

  QIntValidator * validator = new QIntValidator();
  value = new GraphicalArray( validator );
  QLineEdit * lineEdit = findLineEdit(value);

  // 2. validator objects should be the same
  QVERIFY( is_not_null(lineEdit) );
  QCOMPARE( lineEdit->validator(), validator );

  delete value;
  delete validator;
}
예제 #13
0
model* addAttr(model* _model, listModel* _listModel, int _flow, char* _type, char* _name) {
  model* tmp = NULL;
  if(_model == NULL) {
    tmp = malloc(sizeof(model));
    tmp->attr = NULL;
    tmp->eq = NULL;
  } else {
    tmp = _model;
  }
  attrModel* attr;
  if(!isUsualType(_type)) {
    model* mod = findModel(_listModel, _type);
    listAttrModel* list = mod->attr;
    while(list != NULL) {
      attr = malloc(sizeof(attrModel));
      attr->flow = _flow;
      attr->type = strdup(list->attr->type);
      attr->typeModel = strdup(mod->key);
      attr->name = malloc(sizeof(_name) + sizeof(list->attr->name) + sizeof(char));
      sprintf(attr->name, "%s.%s", _name, list->attr->name);
      tmp->attr = pushListAttrModel(tmp->attr, attr);
		  list = list->next;
    }
    listEqModel* listEq = mod->eq;
    while(listEq != NULL) {
      tmp->eq = pushListEqModel(tmp->eq, listEq->eq);
      listEq = listEq->next;
    }
  } else {
    attr = malloc(sizeof(attrModel));
    attr->flow = _flow;
    attr->type = strdup(_type);
    attr->name = strdup(_name);
    tmp->attr = pushListAttrModel(tmp->attr, attr);
  }

  return tmp;
}
예제 #14
0
void GraphicalArrayTest::test_isModified()
{
  GraphicalArray * value = new GraphicalArray();
  QStringListModel * model = findModel(value);

  // 1. initially, it's not modified
  QVERIFY( !value->isModified() );

  // 2. change the value
  model->setStringList( QStringList() << "Hello" << "World" );
  QVERIFY( value->isModified() );

  // 3. change the value and commit
  model->setStringList( QStringList() << "Hello" << "World" << "and" << "Happy" << "New" << "Year!" );
  QVERIFY( value->isModified() );
  value->commit();
  QVERIFY( !value->isModified() );

  // 4. set the same value
  model->setStringList( QStringList() << "Hello" << "World" << "and" << "Happy" << "New" << "Year!" );
  QVERIFY( !value->isModified() );

  delete value;
}
예제 #15
0
//------------------------------------------------------------------------------
// mapPlayerList2ModelTable() - Map the player list to the model table
//  
//  model states are:
//     INACTIVE     -- unused model entry
//     ACTIVE       -- player is alive and in-range
//     DEAD         -- player is dead or destoryed
//     OUT_OF_RANGE -- player is alive but out of range
//
//  Note: this routines will set model entries to DEAD and OUT_OF_RANGE, but the
//  derived class should handle the visual system unique termination sequences and
//  clear the model entry.
//------------------------------------------------------------------------------
void Otw::mapPlayerList2ModelTable()
{
   // ---
   // Check for reset
   // ---
   if (isResetInProgress()) {
      // Set all active models as Out-Of-Range so that sendOwnshipAndModels() can remove them
      for (unsigned int i = 0; i < getModelTableSize(); i++) {
         modelTbl[i]->setState( OtwModel::OUT_OF_RANGE );
      }
      return;
   }

   // ---
   // Remove all inactive, dead or out-of-range models
   //   -- These states were issued last pass, so the OTW system
   //       specific software should have handled them by now.
   //   -- As models are removed, the table above the model is shifted down.  
   //   -- We're also clearing the model's 'checked' flag
   // ---
   for (int i = getModelTableSize(); i > 0; --i) {
      if ( modelTbl[i-1]->isState(OtwModel::CLEARED) ) {
         // Deleting this model
         //std::cout << "Otw::mapPlayerList2ModelTable() cleanup: model = " << modelTbl[i] << std::endl;
         removeModelFromList( (i-1), MODEL_TABLE);
      }
   }
   for (unsigned int i = 0; i < getModelTableSize(); i++) {
      modelTbl[i]->setCheckedFlag(false);
   }
    
   if (playerList != 0) {
      // We must have a player list ...

      // ---
      // Find players that are alive and within range of the visual system ...
      // ---
      Basic::List::Item* item = playerList->getFirstItem();
      while (item != 0) {
    
         // Get a pointer to the player, 'p'
         Basic::Pair* pair = dynamic_cast<Basic::Pair*>(item->getValue());
         Player* p = (Player*) pair->object();

         bool dummy = false;
         const Weapon* wpn = dynamic_cast<const Weapon*>( p );
         if (wpn != 0) dummy = wpn->isDummy();

         if ( p != getOwnship() && !dummy ) {

            // Find the player's model entry (if any)
            OtwModel* model = findModel(p, MODEL_TABLE);

            // Check if in-range
            bool inRange = computeRangeToPlayer(p) <= maxRange;
         
            // Check if this player is alive and within range.
            if (p->isActive() && inRange) {
               // When alive and in range ...
               if (model != 0) {
                  // a) and it already has a model entry: make sure it's active ...
                  model->setState( OtwModel::ACTIVE );
               }
               else {
                  // b) and it doesn't have a model entry (new, in-range player) ...
                  model = newModelEntry(p);
               }
            }
            else if (p->isDead() && inRange) {
               // When player isn't alive and it had a model entry
               if (model != 0) {
                  // set state to dead
                  model->setState( OtwModel::DEAD );
               }
            }
            else {
               // When player is out-of-range and it had a model entry
               if (model != 0) {
                  // set state to out-of-range
                  model->setState( OtwModel::OUT_OF_RANGE );
               }
            }
            if (model != 0) model->setCheckedFlag(true);

         }

         item = item->getNext(); // Next player
      }

   }

   // ---
   // Any models not checked needs to be removed
   // ---
   for (unsigned int i = 0; i < getModelTableSize(); i++) {
      if ( modelTbl[i]->isNotChecked() ) {
         // Request removel; 
         // (note: the OTW system specific code now has one frame to cleanup it's own code
         //  before the model is dropped from the output list next frame -- see above)
         modelTbl[i]->setState( OtwModel::OUT_OF_RANGE );
      }
   }

}