示例#1
0
//------------------------------------------------------------------------------
// build() -- build the table in our components list
//------------------------------------------------------------------------------
void Table::build()
{
   Basic::PairStream* newList = 0;

   if (rows > 0 && columns != 0) {

      newList = new Basic::PairStream();

      // For each row: create a TableRow containing all the items in 'columns'
      for (unsigned int i = 1; i <= rows; i++) {

         // new row
         TableRow* row = new TableRow(); 
         row->container(this);

         const Basic::List::Item* item = columns->getFirstItem();
         while (item != 0) {
            const Basic::Pair* pair = static_cast<const Basic::Pair*>(item->getValue());
            const Basic::Object* obj = pair->object();
            if (obj->isClassType(typeid(BasicGL::Graphic))) {
               Basic::Pair* pp = pair->clone();
               BasicGL::Graphic* gobj = static_cast<BasicGL::Graphic*>(pp->object());
               gobj->container(row);
               row->put(pp);
               pp->unref();
            }

            item = item->getNext();
         }

         // put the row on our components list with a slotname equal to its row number
         {
            char cbuf[8];
            sprintf(cbuf,"%d",i);
            Basic::Pair* pp = new Basic::Pair(cbuf,row);
            newList->put(pp);
            pp->unref();
         }

         row->unref();
      }

      // Position our subcomponents
      position();
   }

   // These are new our subcomponents ...
   processComponents(newList,typeid(Basic::Component));
   if (newList != 0) newList->unref();
}
示例#2
0
// test station builder
static TestStation* builder(const char* const filename)
{
   // read configuration file
   int errors = 0;
   Basic::Object* obj = Basic::lcParser(filename, Factory::createObj, &errors);
   if (errors > 0) {
      std::cerr << "File: " << filename << ", errors: " << errors << std::endl;
      std::exit(EXIT_FAILURE);
   }

   // test to see if an object was created
   if (obj == nullptr) {
      std::cerr << "Invalid configuration file, no objects defined!" << std::endl;
      std::exit(EXIT_FAILURE);
   }

   // do we have a Basic::Pair, if so, point to object in Pair, not Pair itself
   Basic::Pair* pair = dynamic_cast<Basic::Pair*>(obj);
   if (pair != nullptr) {
      obj = pair->object();
      obj->ref();
      pair->unref();
   }

   // try to cast to proper object, and check
   TestStation* testStation = dynamic_cast<TestStation*>(obj);
   if (testStation == nullptr) {
      std::cerr << "Invalid configuration file!" << std::endl;
      std::exit(EXIT_FAILURE);
   }
   return testStation;
}
示例#3
0
//------------------------------------------------------------------------------
// addSymbol() - adds a symbol to our array list;
// -- return the symbol's index; range [ 1 .. getMaxSymbols() ]
//    or zero if not added.
//------------------------------------------------------------------------------
int SymbolLoader::addSymbol(const int nType, const char* const id, int specName)
{
    int idx = 0;

    if (templates != 0) {

        // Find the graphic template for this type symbol, and make
        // sure that the template is a BasicGL::Graphic, since it
        // will be use as the symbol's graphical component.
        Basic::Pair* tpair = templates->getPosition(nType);
        if (tpair != 0) {
            BasicGL::Graphic* tg = dynamic_cast<BasicGL::Graphic*>(tpair->object());
            if (tg != 0) {

                // Find an empty symbol slot in our master symbol table
                for (int i = 0; i < MAX_SYMBOLS && idx == 0; i++) {
                    if ( symbols[i] == 0 ) {

                        // Create a new SlSymbol object to manage this symbol.
                        symbols[i] = symbolFactory();

                        // Clone the graphic template and set it as the
                        // symbol's graphical component.
                        Basic::Pair* newPair = tpair->clone();
                        BasicGL::Graphic* newGraph = (BasicGL::Graphic*)(newPair->object());

                        // Set the new graphical component's select name
                        GLuint mySelName = 0;
                        if (specName > 0) mySelName = specName;
                        else mySelName = BasicGL::Graphic::getNewSelectName();
                        newGraph->setSelectName(mySelName);

                        // Add the symbol's graphical component to our component list.
                        {
                            Basic::PairStream* comp = getComponents();
                            Basic::Component::processComponents(comp, typeid(BasicGL::Graphic), newPair);
                            if (comp != 0) comp->unref();
                        }

                        // Set the symbol's graphical component pointer
                        symbols[i]->setSymbolPair( newPair );
                        newPair->unref(); // symbol[i] now owns it.

                        // Set the symbol's type and ID.
                        symbols[i]->setType( nType );
                        symbols[i]->setId( id );

                        // And this is the new symbol's index
                        idx = (i + 1);
                    }
                }
            }
        }
    }

    return idx;
}
示例#4
0
//------------------------------------------------------------------------------
// setSymbolType() - change an existing symbol type to another type
//------------------------------------------------------------------------------
bool SymbolLoader::setSymbolType(const int idx, const int nType)
{
    bool ok = false;

    // Find the symbol
    if (idx >= 1 && idx <= MAX_SYMBOLS) {
        const int i = (idx - 1);
        if (symbols[i] != 0) {

            // Find the graphic template for this type symbol, and make
            // sure that the template is a BasicGL::Graphic, since it
            // will be use as the symbol's graphical component.
            if (templates != 0) {
                Basic::Pair* tpair = templates->getPosition(nType);
                if (tpair != 0) {
                    BasicGL::Graphic* tg = dynamic_cast<BasicGL::Graphic*>(tpair->object());
                    if (tg != 0) {

                        // Get the symbol's old graphical component
                        Basic::Pair* oldPair = (Basic::Pair*) symbols[i]->getSymbolPair();
                        BasicGL::Graphic* oldG = (BasicGL::Graphic*) (oldPair->object());

                        // Clone the new graphical component from the template
                        Basic::Pair* newPair = tpair->clone();

                        // Set the new graphical component's select name using the old's
                        BasicGL::Graphic* newGraph = (BasicGL::Graphic*) newPair->object();
                        GLuint mySelName = oldG->getSelectName();
                        newGraph->setSelectName(mySelName);

                        // Add the new and remove the old components from our subcomponent list
                        {
                            Basic::PairStream* comp = getComponents();
                            Basic::Component::processComponents(comp, typeid(BasicGL::Graphic), newPair, oldG);
                            if (comp != 0) comp->unref();
                        }

                        // Set the symbol's graphical component pointer
                        symbols[i]->setSymbolPair( newPair );
                        newPair->unref(); // symbol[i] now owns it.

                        // Set new type
                        symbols[i]->setType( nType );

                        ok = true;
                    }

                }
            }
        }

    }
    return ok;
}
示例#5
0
//------------------------------------------------------------------------------
//  setSlotModeSingle() -- takes a single Mode and inits the mode list
//------------------------------------------------------------------------------
bool RfSensor::setSlotModeSingle(RfSensor* const obj)
{
    if (modes != 0) modes->unref();

    modes = new Basic::PairStream();

    Basic::Pair* p = new Basic::Pair("1",obj);
    modes->put( p );
    p->unref();

    return processModes();
}
void MultiActorAgent::setState(Basic::Ubf::State* const x)
{
   if (x == nullptr)
      return;
   if (state != nullptr)
      state->unref();
   state = x;
   state->ref();
   state->container(this);
   Basic::Pair* p = new Basic::Pair("", state);
   addComponent(p);
   p->unref();
}
示例#7
0
//------------------------------------------------------------------------------
// copyData() -- copy member data
//------------------------------------------------------------------------------
void SlSymbol::copyData(const SlSymbol& org, const bool cc)
{
    BaseClass::copyData(org);
    if (cc) initData();

    visibility = org.visibility;
    llFlg = org.llFlg;
    acFlg = org.acFlg;
    scrnFlg = org.scrnFlg;

    type = org.type;
    lcStrcpy(id, sizeof(id), org.id);

    xPos = org.xPos;
    yPos = org.yPos;

    xScreenPos = org.xScreenPos;
    yScreenPos = org.yScreenPos;

    hdg = org.hdg;
    hdgValid = org.hdgValid;
    setHdgGraphics(0);
    setHdgAngleObj(0);

    {
        Basic::Object* copy = 0;
        if (org.value != 0) copy = org.value->clone();
        setValue(copy);
        if (copy != 0) copy->unref();
    }

    {
        Basic::Pair* copy = 0;
        if (org.pntr != 0) copy = org.pntr->clone();
        setSymbolPair(copy);
        if (copy != 0) copy->unref();
    }
}
//------------------------------------------------------------------------------
// insertSteerpoint() -
//------------------------------------------------------------------------------
bool Route::insertSteerpoint(Steerpoint* const newStpt, const int pos)
{
    bool ok = false;
    unsigned int num = getNumberOfSteerpoints();
    // make a new character string
    char numString[10];

    // this tells us the number of the next steerpoint to be created in the slot list
    std::sprintf(numString,"%i",(num+1));

    // now we have the slot name, which is the next number in the steerpoint list
    // now create a new pair, and if we have a component list, add it to it, if
    // not, then create a new component list
    Basic::Pair* p = new Basic::Pair(numString, newStpt);
    if (p != nullptr) {

        // We're its container
        newStpt->container(this);

        // Get our steerpoints
        Basic::PairStream* steerpoints = getComponents();

        // now we have to add it to our component list
        if (steerpoints != nullptr && num != 0) {

            // Copy the current steerpoint list
            Basic::PairStream* tempList = new Basic::PairStream();
            {
               Basic::List::Item* item = steerpoints->getFirstItem();
               while (item != nullptr) {
                  Basic::Pair* pair = (Basic::Pair*) item->getValue();
                  tempList->put(pair);
                  item = item->getNext();
               }
            }

            if (pos == -1) {
               tempList->addHead(p);
               ok = true;
            }

            else if (pos == 0 || pos > num) {
               tempList->addTail(p);
               ok = true;
            }

            else if (pos > 0 && pos <= static_cast<int>(num)) {

                // count to our position, then insert it
                int counter = 1;
                Basic::List::Item* item = tempList->getFirstItem();
                while (counter < pos && item != nullptr) {
                    item = item->getNext();
                    counter++;
                }

                // now we should have the reference pair at the 'pos' position
                if (item != nullptr) {
                    Basic::List::Item* newItem = new Basic::List::Item;
                    newItem->value = p;
                    p->ref();
                    // insert 'newItem' just before 'item'
                    ok = tempList->insert(newItem, item);
                }
            }

            // swap our current steerpoint (components) list for this new one
            if (ok) {
               Basic::Component::processComponents(tempList,typeid(Steerpoint));
            }

            tempList->unref();
            tempList = nullptr;

        }

        // if we have no components, we need to start a new component list
        else {
            Basic::Component::processComponents(nullptr, typeid(Steerpoint), p);
            ok = true;
        }

        // Unref the original steerpoint list
        if (steerpoints != nullptr) {
            steerpoints->unref();
            steerpoints = nullptr;
        }

        p->unref();  // Our component list has it now.
    }

    // ---
    // Call directTo() to reset the steerpoint index, or if we were going nowhere
    // then go direct-to steerpoint one.
    // ---
    if (ok) {
       if (to != nullptr) {
         Steerpoint* sp = static_cast<Steerpoint*>(to->object());
         directTo(sp);
       }
       else {
         directTo(1);
       }
    }

    return ok;

}
示例#9
0
// Set the stores
bool Stores::setSlotStores(const Basic::PairStream* const msg)
{
   // ---
   // Quick out if the number of stations hasn't been set.
   // ---
   if (ns == 0 && msg != 0) {
      std::cerr << "Stores::setSlotStation() Number of stations is not set!" << std::endl;
      return false;
   }

   // ---
   // Clear the previous stores and assigned weapons
   // ---
   storesList = 0;
   for (unsigned int s = 1; s <= ns; s++) {
      assignWeaponToStation(s,0);
      assignExtStoreToStation(s,0);
   }
   numWpn = 0;
   numEs = 0;

   // ---
   // Quick out if 'msg' is zero 
   // ---
   if (msg == 0) return true;

   bool ok = true;

   // ---
   // Create the new external stores list
   //
   // For all items in the 'msg' list ...
   //   -- Make sure that it's a weapon or other type of external store, and
   //      that it has a valid station number.
   //   -- Clone the store and if it's a weapon then assign it to the station.
   // ---
   Basic::PairStream* newStores = new Basic::PairStream();

   const Basic::List::Item* item = msg->getFirstItem();
   while (item != 0) {

      const Basic::Pair* pair = static_cast<const Basic::Pair*>(item->getValue());
      const Basic::Component* p = static_cast<const Basic::Component*>(pair->object());
      if (p != 0) {

         // get the station number from the stores' slot name
         int stationNumber = 0;
         const Basic::Identifier* stationName = pair->slot();
         if (stationName->isInteger()) {
            stationNumber = stationName->getInteger();
         }

         if (stationNumber > 0 && stationNumber <= static_cast<int>(ns)) {

            // check the type of component
            bool isWpn = p->isClassType(typeid(Weapon));
            bool isEE  = p->isClassType(typeid(ExternalStore));

            if ( isWpn || isEE ) {
               // Clone the weapon pair and set us as its container
               Basic::Pair* cpair = pair->clone();
               Component* cp = static_cast<Component*>(cpair->object());
               cp->container(this);

               if ( isWpn ) {
                  // Weapon types ...

                  // Assign the weapon to the station
                  Weapon* cwpn = static_cast<Weapon*>( cpair->object() );
                  assignWeaponToStation(stationNumber, cwpn);

               }

               if ( isEE ) {
                  // External stores types ...

                  // Assign the external store to the station
                  ExternalStore* cwpn = static_cast<ExternalStore*>( cpair->object() );
                  assignExtStoreToStation(stationNumber, cwpn);
               }

               if (cpair != 0) {
                  // Add to the new stores list
                  newStores->put(cpair);
                  cpair->unref(); // the new list has it.
               }
            }
            else {
               std::cerr << "Stores::setSlotStores(): invalid external stores type; use Weapon or Stores classes" << std::endl;
               ok = false;
            }

         }
         else {
            std::cerr << "Stores::setSlotStores(): invalid station number from the store's slot name." << std::endl;
            ok = false;
         }
      }

      item = item->getNext();
   }

   // Make the new stores list the active list
   if (ok && newStores->entries() > 0) {
      storesList = newStores;
   }
   else {
      for (unsigned int s = 1; s <= ns; s++) {
         assignWeaponToStation(s,0);
      }
      numWpn = 0;
   }

   newStores->unref();

   return ok;
}