예제 #1
0
//------------------------------------------------------------------------------
// Updates the value of the named NumericReadout type subcomponent
//------------------------------------------------------------------------------
bool SymbolLoader::updateSymbolText(const int idx, const char* name, const LCreal x)
{
    bool ok = false;

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

            // Get its graphical component
            Basic::Pair* p = (Basic::Pair*)symbols[i]->getSymbolPair();
            if (p != 0) {
                BasicGL::Graphic* g = dynamic_cast<BasicGL::Graphic*>(p->object());
                if (g != 0) {

                    // If we were passed a name then use it to find the subcomponent
                    // and change 'g' to point to the subcomponent instead.
                    if (name != 0) {
                        Basic::Pair* spair = g->findByName(name);
                        if (spair != 0) {
                            // subcomponent found by name
                            g = (BasicGL::Graphic*)(spair->object());
                        }
                        else {
                            // no subcomponent was found by that name
                            g = 0;
                        }
                    }

                    if (g != 0) {
                        // Have a graphic, but make sure it's a numeric readout
                        BasicGL::NumericReadout* text = dynamic_cast<BasicGL::NumericReadout*>(g);
                        if (text != 0) {
                            // It's a NumericReadout type, so update its value
                            text->setValue(x);
                            ok = true;
                        }
                    }

                }
            }

        }
    }
    return ok;
}
//------------------------------------------------------------------------------
// Updates the text of the named AsciiText type subcomponent
//------------------------------------------------------------------------------
bool SymbolLoader::updateSymbolText(const int idx, const char* name, const char newString[])
{
   bool ok = false;

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

         // Get its graphical component
         Basic::Pair* p = static_cast<Basic::Pair*>(symbols[i]->getSymbolPair());
         if (p != nullptr) {
            BasicGL::Graphic* g = static_cast<BasicGL::Graphic*>(p->object());
            if (g != nullptr) {

               // If we were passed a name then use it to find the subcomponent
               // and change 'g' to point to the subcomponent instead.
               if (name != nullptr) {
                  Basic::Pair* spair = g->findByName(name);
                  if (spair != nullptr) {
                     // subcomponent found by name
                     g = static_cast<BasicGL::Graphic*>(spair->object());
                  }
                  else {
                     // no subcomponent was found by that name
                     g = nullptr;
                  }
               }

               if (g != nullptr) {
                  // Have a graphic, but make sure it's an AsciiText
                  BasicGL::AsciiText* text = dynamic_cast<BasicGL::AsciiText*>(g);
                  if (text != nullptr) {
                     // It's an AsciiText, so change the its text string.
                     text->setText(newString);
                     ok = true;
                  }
               }

            }
         }

      }
   }
   return ok;
}
예제 #3
0
//------------------------------------------------------------------------------
// setSymbolVisible() - set symbol visible / invisible
//------------------------------------------------------------------------------
bool SymbolLoader:: setSymbolVisible(const int idx, const char* name, bool visibility)
{
    bool ok = false;

    // Find the symbol
    if (idx >= 1 && idx <= MAX_SYMBOLS) {
        const int i = (idx - 1);
        if (symbols[i] != 0) {
            // if no name is passed, the symbol is invisible, otherwise just
            // parts are
            if (name == 0) symbols[i]->setVisible(visibility);

            // Get its graphical component
            Basic::Pair* p = symbols[i]->getSymbolPair();
            if (p != 0) {
                BasicGL::Graphic* g = (BasicGL::Graphic*)(p->object());
                if (g != 0) {

                    // If we were passed a name then use it to find the subcomponent
                    // and change 'g' to point to the subcomponent instead.
                    if (name != 0) {
                        Basic::Pair* spair = g->findByName(name);
                        if (spair != 0) {
                            // subcomponent found by name
                            g = (BasicGL::Graphic*)(spair->object());
                        }
                        else {
                            // no subcomponent was found by that name
                            g = 0;
                        }
                    }

                    // Set the visibility (if we found one)
                    if (g != 0) ok = g->setVisibility(visibility);

                }

            }
        }
    }
    return ok;
}
예제 #4
0
//------------------------------------------------------------------------------
// update the symbol's color based on Identifier
//------------------------------------------------------------------------------
bool SymbolLoader::setSymbolColor(const int idx, const char* name, const Basic::Identifier* cname)
{
    bool ok = false;

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

            // Get its graphical component
            Basic::Pair* p = (Basic::Pair*)symbols[i]->getSymbolPair();
            if (p != 0) {
                BasicGL::Graphic* g = dynamic_cast<BasicGL::Graphic*>(p->object());
                if (g != 0) {

                    // If we were passed a name then use it to find the subcomponent
                    // and change 'g' to point to the subcomponent instead.
                    if (name != 0) {
                        Basic::Pair* spair = g->findByName(name);
                        if (spair != 0) {
                            // subcomponent found by name
                            g = (BasicGL::Graphic*)(spair->object());
                        }
                        else {
                            // no subcomponent was found by that name
                            g = 0;
                        }
                    }

                    // Set the color (if we found one)
                    if (g != 0) ok = g->setColor(cname);
                }
            }
        }
    }

    return ok;
}
//------------------------------------------------------------------------------
// setSymbolFlashRate() - set symbol and child components flashing
//------------------------------------------------------------------------------
bool SymbolLoader::setSymbolFlashRate(const int idx, const char* name, const LCreal flashRate )
{
   bool ok = false;

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

         // Get its graphical component
         Basic::Pair* p = symbols[i]->getSymbolPair();
         if (p != nullptr) {
            BasicGL::Graphic* g = static_cast<BasicGL::Graphic*>(p->object());
            if (g != nullptr) {

               // If we were passed a name then use it to find the subcomponent
               // and change 'g' to point to the subcomponent instead.
               if (name != nullptr) {
                  Basic::Pair* spair = g->findByName(name);
                  if (spair != nullptr) {
                     // subcomponent found by name
                     g = static_cast<BasicGL::Graphic*>(spair->object());
                  }
                  else {
                     // no subcomponent was found by that name
                     g = nullptr;
                  }
               }

               // Set the flash rate (if we found one)
               if (g != nullptr) ok = g->setFlashRate(flashRate);

            }
         }
      }
   }
   return ok;
}
예제 #6
0
//------------------------------------------------------------------------------
// draw() - draw the objects in their proper place
//------------------------------------------------------------------------------
void SymbolLoader::draw()
{
    if (isVisible()) {

        // Y Displacement (ie, decentered)
        LCreal displacement = 0;
        if (!getCentered()) displacement = getDisplacement();

        // Radius (ie., range)
        LCreal radius = 0;
        if (!getCentered()) radius = getOuterRadiusDC();
        else radius = getOuterRadius();
        LCreal radius2 = radius * radius;

        // ---
        // Setup the drawing parameters for all of our symbols ...
        // ---
        for (int i = 0; i < MAX_SYMBOLS; i++) {

            if (symbols[i] != 0) {

                // When the symbol visibility flag is true ...
                if (symbols[i]->isVisible()) {

                    // Get the pointer to the symbol's graphical component
                    Basic::Pair* p = symbols[i]->getSymbolPair();
                    BasicGL::Graphic* g = (BasicGL::Graphic*)p->object();

                    // We need the symbol's position in screen coordinates (inches) ...
                    LCreal xScn = (LCreal) symbols[i]->getScreenXPos();
                    LCreal yScn = (LCreal) symbols[i]->getScreenYPos();

                    if ( !(symbols[i]->isPositionScreen()) ) {

                        // But when we were not give screen coordinates,
                        // we'll need to compute them from A/C coordinates
                        LCreal acX = 0.0;
                        LCreal acY = 0.0;

                        // 1) when given A/C coordinates ...
                        if ( symbols[i]->isPositionAC() ) {
                            acX = (LCreal) symbols[i]->getXPosition();
                            acY = (LCreal) symbols[i]->getYPosition();
                        }

                        // 2) when given NED or L/L coordinates ..
                        else {
                            LCreal north = 0;
                            LCreal east  = 0;

                            if (symbols[i]->isPositionLL()) {
                                // 2a) we were give L/L so convert to NED coordinates
                                double lat = symbols[i]->getXPosition();
                                double lon = symbols[i]->getYPosition();
                                latLon2Earth(lat, lon, &north, &east);
                            }
                            else {
                                // 2b) we were give NED coordinates
                                north = (LCreal) symbols[i]->getXPosition();
                                east  = (LCreal) symbols[i]->getYPosition();
                            }

                            // 2c) convert the NED coordinates to aircraft coordinates
                            earth2Aircraft(north, east, &acX, &acY);
                        }

                        // 3) Convert the aircraft coordinates to screen coordinates
                        aircraft2Screen(acX, acY, &xScn, &yScn);

                        // 4) Save the screen coordinates (inches)
                        symbols[i]->setXScreenPos(xScn);
                        symbols[i]->setYScreenPos(yScn);
                    }

                    // In range?  Do we care?
                    bool inRange  = !showInRangeOnly || (((xScn * xScn) + (yScn * yScn)) <= radius2);

                    if (inRange) {

                        // set symbol's visibility
                        g->setVisibility(true);

                        // and set the symbol's position
                        g->lcSaveMatrix();
                        g->lcTranslate(xScn, yScn + displacement);

                        // pass the argument value to the symbol (if needed)
                        if (symbols[i]->getValue() != 0) {
                            g->event(UPDATE_VALUE, symbols[i]->getValue());
                        }

                        // rotate the symbol's heading subcomponent (if needed)
                        // -- sending a 'Z' rotation event to a component named 'hdg'
                        if (symbols[i]->isHeadingValid()) {
                            BasicGL::Graphic* phdg = symbols[i]->getHdgGraphics();
                            if (phdg == 0) {
                                Basic::Pair* hpair = (Basic::Pair*) g->findByName("hdg");
                                if (hpair != 0) {
                                    phdg = dynamic_cast<Graphic*>(hpair->object());
                                    symbols[i]->setHdgGraphics(phdg);
                                }
                            }
                            if (phdg != 0) {
                                Basic::Degrees* angObj = symbols[i]->getHdgAngleObj();
                                if (angObj == 0) {
                                    angObj = new Basic::Degrees();
                                    symbols[i]->setHdgAngleObj(angObj);
                                }
                                double relHeading = symbols[i]->getHeadingDeg() - getHeadingDeg();
                                angObj->set(-relHeading);
                                phdg->event(UPDATE_VALUE6, angObj);
                            }
                        }
                    }
                    else {
                        // out of range, so clear the graphical component's visibility flag
                        g->setVisibility(false);
                    }
                }

                // When the symbol visibility flag is false ...
                else {
                    Basic::Pair* p = symbols[i]->getSymbolPair();
                    BasicGL::Graphic* g = (BasicGL::Graphic*)p->object();
                    g->setVisibility(false);
                }
            }
        }

        // ---
        // Let our base class handle the drawing
        // ---
        BaseClass::draw();

        // ---
        // now restore the matrices on all of our graphical components
        // ---
        for (int i = 0; i < MAX_SYMBOLS; i++) {
            if (symbols[i] != 0) {
                Basic::Pair* p = symbols[i]->getSymbolPair();
                BasicGL::Graphic* g = (BasicGL::Graphic*)p->object();
                if (g->isVisible()) g->lcRestoreMatrix();
            }
        }

    }
}